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 9 commits into
base: devel
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions contracts/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
40 changes: 40 additions & 0 deletions contracts/sources/lending_market.move
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,30 @@ 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>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we need to know the reserve array indicies to set emode?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an obligation is a valid emode obligation if it has 1 or less deposits and 1 or less borrows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we call deposit for an emode obligation we need to be able to know what the corresponding borrow reserve is in order to get the respective emode ltv

lending_market: &mut LendingMarket<P>,
deposit_reserve_array_index: u64,
borrow_reserve_array_index: u64,
obligation_owner_cap: &ObligationOwnerCap<P>,
) {
assert!(lending_market.version == CURRENT_VERSION, EIncorrectVersion);

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

let deposit_reserve = vector::borrow(&lending_market.reserves, deposit_reserve_array_index);
let borrow_reserve = vector::borrow(&lending_market.reserves, borrow_reserve_array_index);

obligation::set_emode(
obligation,
deposit_reserve,
borrow_reserve,
);
}

public fun withdraw_ctokens<P, T>(
lending_market: &mut LendingMarket<P>,
Expand Down Expand Up @@ -819,6 +843,22 @@ module suilend::lending_market {
reserve::update_reserve_config<P>(reserve, config);
}

public fun set_emode_for_pair<P, T>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it makes sense to get the type argument for the pair reserve as well, just as a sanity check.

_: &LendingMarketOwnerCap<P>,
lending_market: &mut LendingMarket<P>,
reserve_array_index: u64,
pair_reserve_array_index: u64,
open_ltv_pct: u8,
close_ltv_pct: u8,
) {
assert!(lending_market.version == CURRENT_VERSION, EIncorrectVersion);

let reserve = vector::borrow_mut(&mut lending_market.reserves, reserve_array_index);
assert!(reserve::coin_type(reserve) == type_name::get<T>(), EWrongType);

reserve::set_emode_for_pair<P>(reserve, pair_reserve_array_index, open_ltv_pct, close_ltv_pct);
}

public fun add_pool_reward<P, RewardType>(
_: &LendingMarketOwnerCap<P>,
lending_market: &mut LendingMarket<P>,
Expand Down
Loading
Loading