Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions common/src/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ pub struct Accumulator<T: AssetClass> {
pub pending_estimate: FungibleAssetAmount<T>,
}

impl<T: AssetClass> Default for Accumulator<T> {
fn default() -> Self {
Self {
total: 0.into(),
fraction_as_u128_dividend: U128(0),
next_snapshot_index: 0,
pending_estimate: 0.into(),
}
}
}

impl<T: AssetClass> Accumulator<T> {
pub fn new(next_snapshot_index: u32) -> Self {
Self {
Expand Down Expand Up @@ -84,6 +95,14 @@ impl<T: AssetClass> AccumulationRecord<T> {
mod tests {
use super::*;

#[test]
fn default_accumulator() {
let a = Accumulator::<crate::asset::BorrowAsset>::default();

assert_eq!(a.get_total(), 0.into());
assert_eq!(a.get_next_snapshot_index(), 0);
}

#[test]
fn fraction() {
let mut a = Accumulator::<crate::asset::BorrowAsset>::new(1);
Expand Down
4 changes: 4 additions & 0 deletions common/src/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ pub enum LiquidationReason {
pub struct BorrowPosition {
pub started_at_block_timestamp_ms: Option<U64>,
pub collateral_asset_deposit: CollateralAssetAmount,
#[serde(default)]
borrow_asset_principal: BorrowAssetAmount,
#[serde(default)]
pub interest: Accumulator<BorrowAsset>,
#[serde(default)]
pub fees: BorrowAssetAmount,
#[serde(default)]
borrow_asset_in_flight: BorrowAssetAmount,
#[serde(default)]
collateral_asset_in_flight: CollateralAssetAmount,
#[serde(default)]
pub liquidation_lock: CollateralAssetAmount,
}

Expand Down
Loading