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

EMode (1) #37

Open
wants to merge 7 commits into
base: devel
Choose a base branch
from
Open

EMode (1) #37

wants to merge 7 commits into from

Conversation

0xLendlord
Copy link
Contributor

  • reserve config module
  • lending_market::set_emode_status
  • obligation::refresh

- lending_market::set_emode_status
- obligation::refresh
while (vector::length(&keys) > 0) {
let emode = vec_map::get(emode_ltvs, &vector::pop_back(&mut keys));

assert!(config.open_ltv_pct < emode.open_ltv_pct, ENormalOpenLtvBetterThanEModeLtvs);
Copy link
Contributor

Choose a reason for hiding this comment

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

<=.

refresh(obligation, reserves, clock);

};
refresh(obligation, reserves, clock);

df::add(&mut obligation.id, EModeFlag {}, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to refresh after adding the flag for this to be correct

public fun set_emode<P>(
lending_market: &mut LendingMarket<P>,
obligation_owner_cap: &ObligationOwnerCap<P>,
clock: &Clock
Copy link
Contributor

Choose a reason for hiding this comment

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

ability to toggle emode is still missing

@@ -169,7 +194,11 @@ module suilend::obligation {
let mut deposited_value_usd = decimal::from(0);
let mut allowed_borrow_value_usd = decimal::from(0);
let mut unhealthy_borrow_value_usd = decimal::from(0);
let is_emode = is_emode(obligation);
if (is_emode) {
obligation.refresh_emode(reserves, is_emode, clock)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: just return immediately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

assigned it to a variable to avoid borrow-checker error

Copy link
Contributor

@0xripleys 0xripleys Nov 8, 2024

Choose a reason for hiding this comment

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

if (is_emode) {
        obligation.refresh_emode(reserves, is_emode, clock)
        return;
}

};
}

fun refresh_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 think you can simplify this function to not use a while loops at all, and the variables on 303-305 aren't necessary either because the while loop will only iterate at most 1 time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified

borrow.market_value = market_value;
unweighted_borrowed_value_usd = add(unweighted_borrowed_value_usd, market_value);

let borrow_weight = if (is_emode) {
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 even if obligation is emode, if there's no corresponding emode entry, then the borrow weight has to be the one stored on the reserve (ie not 1).

example: say user is depositing usdc and borrowing FUD. fud has a borrow weight of 2. the (usdc, fud) pair does not have a corresponding emode entry. then, if the user sets their obligation to emode, then the borrow weight being used is 1, which lets them borrow more fud than we intended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Refactored

// check_normal_ltv_against_emode_ltvs
let borrow_reserve_index = get_single_borrow_array_reserve_if_any(obligation);

assert!(
Copy link
Contributor

Choose a reason for hiding this comment

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

we never want this assert to get tripped because then obligation::refresh can abort, which would be very bad.

Copy link
Contributor

Choose a reason for hiding this comment

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

in this case we still want to return the base ltvs, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's right! Refactored

- Refresh after adding the emode flag
- Ability to toggle emode on and off
- Simplified refresh emode
- Fixed borrow weight when no emode pair
- Do not fail when getting ltvs
- Simplied get_ltvs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants