-
Notifications
You must be signed in to change notification settings - Fork 71
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
0xripleys outflow limits #125
0xripleys outflow limits #125
Conversation
@@ -659,7 +675,6 @@ fn process_redeem_reserve_collateral( | |||
} | |||
let token_program_id = next_account_info(account_info_iter)?; | |||
|
|||
_refresh_reserve_interest(program_id, reserve_info, clock)?; |
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.
since the lending market rate limiter is denominated in usd, we need an up-to-date price so i removed this function call
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## v2_upcoming #125 +/- ##
===============================================
+ Coverage 79.94% 80.86% +0.91%
===============================================
Files 40 42 +2
Lines 12712 13373 +661
===============================================
+ Hits 10163 10814 +651
- Misses 2549 2559 +10
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
let market_value = reserve | ||
.liquidity | ||
.market_price | ||
.try_mul(Decimal::from(liquidity_amount))?; |
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.
try_div(10**reserve.liquidity.mint_decimals)
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.
maybe call it redemption_value
let market_value = borrow_reserve | ||
.liquidity | ||
.market_price | ||
.try_mul(borrow_amount)?; |
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.
same divide needed
@@ -695,6 +702,10 @@ pub struct ReserveConfig { | |||
pub protocol_liquidation_fee: u8, | |||
/// Protocol take rate is the amount borrowed interest protocol recieves, as a percentage | |||
pub protocol_take_rate: u8, | |||
/// Rate limiter window size in slots | |||
pub window_duration: u64, |
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.
no duper pls
@@ -1477,6 +1520,37 @@ fn process_borrow_obligation_liquidity( | |||
|
|||
let cumulative_borrow_rate_wads = borrow_reserve.liquidity.cumulative_borrow_rate_wads; | |||
|
|||
// check outflow rate limits | |||
{ | |||
let borrow_value = borrow_reserve |
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.
maybe make borrow_reserve.market_value(liquidity_amount) method
|
||
// assume the prev_window's outflow is even distributed across the window | ||
// this isn't true, but it's a good enough approximation | ||
let prev_weight = Decimal::one().try_sub( |
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.
let prev_weight = Decimal::from(self.config.window_duration).try_sub(Decimal::from(cur_slot - self.window_start + 1)).try_div(self.config.window_duration)
token-lending/sdk/src/instruction.rs
Outdated
@@ -690,9 +709,11 @@ impl LendingInstruction { | |||
buf.extend_from_slice(owner.as_ref()); | |||
buf.extend_from_slice(quote_currency.as_ref()); | |||
} | |||
Self::SetLendingMarketOwner { new_owner } => { | |||
Self::SetLendingMarketOwnerAndConfig { new_owner, config } => { |
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.
rate limiter config
Use a sliding window rate limiter to limit borrows and withdraws at the lending pool owner's discretion.
* 0xripleys outflow limits (#125) Use a sliding window rate limiter to limit borrows and withdraws at the lending pool owner's discretion. * 0xripleys borrow coefficient (#127) Add a borrow weight to the Reserve * Two Prices PR (#129) - Add a smoothed_market_price to Reserve that is used to limit borrows and withdraws in cases where smoothed price and spot price diverge. - allowed_borrow_value now uses the min(smoothed_market_price, current spot price) - new field on obligation called borrowed_value_upper_bound that uses max(smoothed_market_price, current spot price) * audit nits * audit fixes pt 2 * disable rate limiter if window duration == 0 * cli changes for v2.0.1 (#133)
On any borrow or redeem instruction, we now check that the quantity outflowing doesn't exceed some specified amount per time.
Main Changes:
Other comments: