File tree Expand file tree Collapse file tree 6 files changed +11
-12
lines changed Expand file tree Collapse file tree 6 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -202,7 +202,6 @@ fn process_init_lending_market(
202
202
token_program_id : * token_program_id. key ,
203
203
oracle_program_id : * oracle_program_id. key ,
204
204
switchboard_oracle_program_id : * switchboard_oracle_program_id. key ,
205
- current_slot : Clock :: get ( ) ?. slot ,
206
205
} ) ;
207
206
LendingMarket :: pack ( lending_market, & mut lending_market_info. data . borrow_mut ( ) ) ?;
208
207
@@ -793,7 +792,7 @@ fn _redeem_reserve_collateral<'a>(
793
792
. rate_limiter
794
793
. update (
795
794
clock. slot ,
796
- reserve. market_value ( Decimal :: from ( liquidity_amount) ) ?,
795
+ reserve. market_value_upper_bound ( Decimal :: from ( liquidity_amount) ) ?,
797
796
)
798
797
. map_err ( |err| {
799
798
msg ! ( "Market outflow limit exceeded! Please try again later." ) ;
@@ -2071,7 +2070,7 @@ fn process_update_reserve_config(
2071
2070
return Err ( LendingError :: InvalidMarketAuthority . into ( ) ) ;
2072
2071
}
2073
2072
2074
- // if window duration and max outflow are different, then create a new rate limiter instance.
2073
+ // if window duration or max outflow are different, then create a new rate limiter instance.
2075
2074
if rate_limiter_config != reserve. rate_limiter . config {
2076
2075
reserve. rate_limiter = RateLimiter :: new ( rate_limiter_config, Clock :: get ( ) ?. slot ) ;
2077
2076
}
Original file line number Diff line number Diff line change @@ -270,6 +270,8 @@ async fn test_withdraw() {
270
270
271
271
assert_eq ! ( balance_changes, expected_balance_changes) ;
272
272
273
+ test. advance_clock_by_slots ( 1 ) . await ;
274
+
273
275
// we shouldn't be able to withdraw anything else
274
276
for mint in [ usdc_mint:: id ( ) , usdt_mint:: id ( ) ] {
275
277
let err = lending_market
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ impl Decimal {
57
57
58
58
/// Create scaled decimal from bps value
59
59
pub fn from_bps ( bps : u64 ) -> Self {
60
- Self ( U192 :: from ( bps * BPS_SCALER ) )
60
+ Self :: from ( bps) . try_div ( 10_000 ) . unwrap ( )
61
61
}
62
62
63
63
/// Return raw scaled value if it fits within u128
@@ -248,10 +248,8 @@ mod test {
248
248
249
249
#[ test]
250
250
fn test_from_bps ( ) {
251
- let left = Decimal :: from_bps ( 2000 ) ;
252
- let right = Decimal :: from_percent ( 20 ) ;
253
-
254
- assert_eq ! ( left, right) ;
251
+ let left = Decimal :: from_bps ( 190000 ) ;
252
+ assert_eq ! ( left, Decimal :: from( 19u64 ) ) ;
255
253
}
256
254
257
255
#[ test]
Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ pub fn get_pyth_price(
56
56
let price_feed = price_account. to_price_feed ( pyth_price_info. key ) ;
57
57
// this can be unchecked bc the ema price is only used to _limit_ borrows and withdraws.
58
58
// ie staleness doesn't _really_ matter for this field.
59
+ //
60
+ // the pyth EMA is also updated every time the regular spot price is updated anyways so in
61
+ // reality the staleness should never be an issue.
59
62
let ema_price = price_feed. get_ema_price_unchecked ( ) ;
60
63
pyth_price_to_decimal ( & ema_price) ?
61
64
} ;
Original file line number Diff line number Diff line change @@ -65,8 +65,6 @@ pub struct InitLendingMarketParams {
65
65
pub oracle_program_id : Pubkey ,
66
66
/// Oracle (Switchboard) program id
67
67
pub switchboard_oracle_program_id : Pubkey ,
68
- /// Current slot
69
- pub current_slot : u64 ,
70
68
}
71
69
72
70
impl Sealed for LendingMarket { }
Original file line number Diff line number Diff line change @@ -49,8 +49,7 @@ pub struct Obligation {
49
49
/// borrows and withdraws are disabled.
50
50
pub allowed_borrow_value : Decimal ,
51
51
/// The dangerous borrow value at the weighted average liquidation threshold.
52
- /// ie sum(d.deposited_amount * d.liquidation_threshold * min(d.current_spot_price, d.smoothed_price)
53
- /// for d in deposits)
52
+ /// ie sum(d.deposited_amount * d.liquidation_threshold * d.current_spot_price for d in deposits)
54
53
/// if borrowed_value >= unhealthy_borrow_value, the obligation can be liquidated
55
54
pub unhealthy_borrow_value : Decimal ,
56
55
}
You can’t perform that action at this time.
0 commit comments