Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: eMode draft impl (WIP) #26

Open
wants to merge 15 commits into
base: devel
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
contracts/suilend/build
suilend-cli/node_modules
contracts/oracle/build
contracts/oracle/build
contracts/suilend/build
4 changes: 4 additions & 0 deletions contracts/suilend/sources/cell.move
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ module suilend::cell {
public fun get<Element>(cell: &Cell<Element>): &Element {
option::borrow(&cell.element)
}

public fun get_mut<Element>(cell: &mut Cell<Element>): &mut Element {
option::borrow_mut(&mut cell.element)
}

public fun destroy<Element>(cell: Cell<Element>): Element {
let Cell { element } = cell;
Expand Down
24 changes: 23 additions & 1 deletion contracts/suilend/sources/lending_market.move
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ module suilend::lending_market {

let (receive_balance, borrow_amount_with_fees) = reserve::borrow_liquidity<P, T>(reserve, amount);
let origination_fee_amount = borrow_amount_with_fees - balance::value(&receive_balance);
obligation::borrow<P>(obligation, reserve, clock, borrow_amount_with_fees);
obligation::borrow<P>(obligation, &mut lending_market.reserves, reserve_array_index, clock, borrow_amount_with_fees);

let reserve = vector::borrow_mut(&mut lending_market.reserves, reserve_array_index);

let borrow_value = reserve::market_value_upper_bound(reserve, decimal::from(borrow_amount_with_fees));
rate_limiter::process_qty(
Expand All @@ -377,6 +379,26 @@ module suilend::lending_market {
obligation::zero_out_rewards_if_looped(obligation, &mut lending_market.reserves, clock);
coin::from_balance(receive_balance, ctx)
}

/// Set emode for obligation - T is the deposit coin type
public fun set_emode<P>(
lending_market: &mut LendingMarket<P>,
obligation_owner_cap: &ObligationOwnerCap<P>,
clock: &Clock
) {
assert!(lending_market.version == CURRENT_VERSION, EIncorrectVersion);

let obligation = object_table::borrow_mut(
&mut lending_market.obligations,
obligation_owner_cap.obligation_id
);

obligation::set_emode(
obligation,
&mut lending_market.reserves,
clock,
);
}

public fun withdraw_ctokens<P, T>(
lending_market: &mut LendingMarket<P>,
Expand Down
Loading
Loading