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
Open

Draft: eMode draft impl (WIP) #26

wants to merge 15 commits into from

Conversation

0xLendlord
Copy link
Contributor

No description provided.

- 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>(
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.

Copy link
Contributor Author

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 {}))
Copy link
Contributor

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?

@@ -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 {
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 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);
Copy link
Contributor

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?

assert!(vector::length(&obligation.borrows) <= 1, EEModeNotValidWithCrossMargin);
assert!(vector::length(&obligation.deposits) <= 1, EEModeNotValidWithCrossMargin);

if (vector::length(&obligation.deposits) == 1) {
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 this case is fine, right? we'd just end up using the base ltvs

Copy link
Contributor

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>(
Copy link
Contributor

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

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