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

feat: no longer interprete 0 as no debt limit #70

Merged
merged 1 commit into from
Feb 19, 2024
Merged
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
feat: no longer interprete 0 as no debt limit
It's legitimate to have tokens that cannot be borrowed, and `debt_limit`
is a good way to handle that. All tokens in production have a non-zero
`debt_limit` so this upgrade does not break anything.
  • Loading branch information
xJonathanLEI committed Feb 19, 2024
commit 41e142a3690219733a09db702f2bf0e4628e1f77
17 changes: 7 additions & 10 deletions src/market/internal.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -916,18 +916,15 @@ fn assert_reserve_enabled(self: @ContractState, token: ContractAddress) {
fn assert_debt_limit_satisfied(self: @ContractState, token: ContractAddress) {
let debt_limit = self.reserves.read_debt_limit(token);

// 0 means no limit
if debt_limit.is_non_zero() {
let raw_total_debt = self.reserves.read_raw_total_debt(token);
let raw_total_debt = self.reserves.read_raw_total_debt(token);

let debt_accumulator = view::get_debt_accumulator(self, token);
let scaled_debt = safe_decimal_math::mul(raw_total_debt, debt_accumulator);
let debt_accumulator = view::get_debt_accumulator(self, token);
let scaled_debt = safe_decimal_math::mul(raw_total_debt, debt_accumulator);

assert(
Into::<_, u256>::into(scaled_debt) <= Into::<_, u256>::into(debt_limit),
errors::DEBT_LIMIT_EXCEEDED
);
}
assert(
Into::<_, u256>::into(scaled_debt) <= Into::<_, u256>::into(debt_limit),
errors::DEBT_LIMIT_EXCEEDED
);
}

/// This function is called to distribute excessive reserve assets to depositors. Such extra balance
Expand Down
15 changes: 15 additions & 0 deletions tests/market.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ fn setup() -> Setup {
100000000000000000000000000, // liquidation_bonus
);

setup
.alice
.market_set_debt_limit(
setup.market.contract_address,
setup.token_a.contract_address, // token
999999999999999999999999999999 // limit
);
setup
.alice
.market_set_debt_limit(
setup.market.contract_address,
setup.token_b.contract_address, // token
999999999999999999999999999999 // limit
);

setup
.oracle
.set_price(
Expand Down
Loading