-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: devel
Are you sure you want to change the base?
Conversation
…ccount for emode - Public function to toggle emode for a given obligation
- Increase test coverage
@@ -819,6 +843,22 @@ module suilend::lending_market { | |||
reserve::update_reserve_config<P>(reserve, config); | |||
} | |||
|
|||
public fun set_emode_for_pair<P, T>( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added both:
public fun set_emode_for_pair<P, Deposit, Borrow>(
_: &LendingMarketOwnerCap<P>,
lending_market: &mut LendingMarket<P>,
deposit_reserve_array_index: u64,
borrow_reserve_array_index: u64,
open_ltv_pct: u8,
close_ltv_pct: u8,
) {
assert!(lending_market.version == CURRENT_VERSION, EIncorrectVersion);
let borrow_reserve = vector::borrow_mut(&mut lending_market.reserves, borrow_reserve_array_index);
assert!(reserve::coin_type(borrow_reserve) == type_name::get<Borrow>(), EWrongType);
let deposit_reserve = vector::borrow_mut(&mut lending_market.reserves, deposit_reserve_array_index);
assert!(reserve::coin_type(deposit_reserve) == type_name::get<Deposit>(), EWrongType);
reserve::set_emode_for_pair<P>(deposit_reserve, borrow_reserve_array_index, open_ltv_pct, close_ltv_pct);
}
@@ -293,6 +401,10 @@ module suilend::reserve_config { | |||
set_open_attributed_borrow_limit_usd(&mut builder, config.open_attributed_borrow_limit_usd); | |||
set_close_attributed_borrow_limit_usd(&mut builder, config.close_attributed_borrow_limit_usd); | |||
|
|||
if (bag::contains(&config.additional_fields, EModeKey {})) { | |||
set_emode_ltv_for_borrow(&mut builder, *bag::borrow(&config.additional_fields, EModeKey {})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems wrong. set_emode_ltv_for_borrow
is expecting EmodeData
. but bag::borrow(&config.additional_fields, EModeKey {})
is of type VecMap?
contracts/sources/cell.move
Outdated
@@ -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 { |
There was a problem hiding this comment.
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 this anymore?
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, this is to fix the borrow checker error?
contracts/sources/obligation.move
Outdated
assert!(vector::length(&obligation.borrows) <= 1, EEModeNotValidWithCrossMargin); | ||
assert!(vector::length(&obligation.deposits) <= 1, EEModeNotValidWithCrossMargin); | ||
|
||
if (vector::length(&obligation.deposits) == 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this case is fine, right? we'd just end up using the base ltvs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(talking about the assertion below )
@@ -379,6 +381,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>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also need the ability to unset emode. maybe call this function `set_emode_flag', which also accepts a boolean which indicates whether the obligation is emode or not
No description provided.