Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 36 additions & 0 deletions contract/market/src/impl_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,40 @@ impl Contract {
borrow_position.record_collateral_asset_deposit(amount);
}
}

#[private]
pub fn withdraw_static_yield_01_finalize(
&mut self,
account_id: AccountId,
borrow_asset_amount: BorrowAssetAmount,
collateral_asset_amount: CollateralAssetAmount,
) {
let mut static_yield = self.static_yield.get(&account_id).unwrap_or_else(|| {
env::panic_str("Invariant violation: static yield entry must exist during callback")
});
let mut i = 0;

if !borrow_asset_amount.is_zero() {
if matches!(env::promise_result(i), PromiseResult::Failed) {
static_yield
.borrow_asset
.join(borrow_asset_amount)
.unwrap_or_else(|| {
env::panic_str("Borrow asset static yield returned overflows")
});
}
i += 1;
}

if !collateral_asset_amount.is_zero()
&& matches!(env::promise_result(i), PromiseResult::Failed)
{
static_yield
.collateral_asset
.join(collateral_asset_amount)
.unwrap_or_else(|| {
env::panic_str("Collateral asset static yield returned overflows")
});
}
}
}
9 changes: 8 additions & 1 deletion contract/market/src/impl_market_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ impl MarketExternalInterface for Contract {
(Some(b), Some(c)) => b.and(c),
(Some(p), _) | (_, Some(p)) => p,
_ => env::panic_str("No yield to withdraw"),
} // TODO: Check for success
}
.then(
Self::ext(env::current_account_id()).withdraw_static_yield_01_finalize(
predecessor,
borrow_asset_amount,
collateral_asset_amount,
),
)
}
}