Skip to content

Commit 477d85d

Browse files
committed
audit nits
1 parent e2e44ad commit 477d85d

File tree

6 files changed

+11
-12
lines changed

6 files changed

+11
-12
lines changed

token-lending/program/src/processor.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ fn process_init_lending_market(
202202
token_program_id: *token_program_id.key,
203203
oracle_program_id: *oracle_program_id.key,
204204
switchboard_oracle_program_id: *switchboard_oracle_program_id.key,
205-
current_slot: Clock::get()?.slot,
206205
});
207206
LendingMarket::pack(lending_market, &mut lending_market_info.data.borrow_mut())?;
208207

@@ -793,7 +792,7 @@ fn _redeem_reserve_collateral<'a>(
793792
.rate_limiter
794793
.update(
795794
clock.slot,
796-
reserve.market_value(Decimal::from(liquidity_amount))?,
795+
reserve.market_value_upper_bound(Decimal::from(liquidity_amount))?,
797796
)
798797
.map_err(|err| {
799798
msg!("Market outflow limit exceeded! Please try again later.");
@@ -2071,7 +2070,7 @@ fn process_update_reserve_config(
20712070
return Err(LendingError::InvalidMarketAuthority.into());
20722071
}
20732072

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.
20752074
if rate_limiter_config != reserve.rate_limiter.config {
20762075
reserve.rate_limiter = RateLimiter::new(rate_limiter_config, Clock::get()?.slot);
20772076
}

token-lending/program/tests/two_prices.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ async fn test_withdraw() {
270270

271271
assert_eq!(balance_changes, expected_balance_changes);
272272

273+
test.advance_clock_by_slots(1).await;
274+
273275
// we shouldn't be able to withdraw anything else
274276
for mint in [usdc_mint::id(), usdt_mint::id()] {
275277
let err = lending_market

token-lending/sdk/src/math/decimal.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Decimal {
5757

5858
/// Create scaled decimal from bps value
5959
pub fn from_bps(bps: u64) -> Self {
60-
Self(U192::from(bps * BPS_SCALER))
60+
Self::from(bps).try_div(10_000).unwrap()
6161
}
6262

6363
/// Return raw scaled value if it fits within u128
@@ -248,10 +248,8 @@ mod test {
248248

249249
#[test]
250250
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));
255253
}
256254

257255
#[test]

token-lending/sdk/src/oracles.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub fn get_pyth_price(
5656
let price_feed = price_account.to_price_feed(pyth_price_info.key);
5757
// this can be unchecked bc the ema price is only used to _limit_ borrows and withdraws.
5858
// 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.
5962
let ema_price = price_feed.get_ema_price_unchecked();
6063
pyth_price_to_decimal(&ema_price)?
6164
};

token-lending/sdk/src/state/lending_market.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ pub struct InitLendingMarketParams {
6565
pub oracle_program_id: Pubkey,
6666
/// Oracle (Switchboard) program id
6767
pub switchboard_oracle_program_id: Pubkey,
68-
/// Current slot
69-
pub current_slot: u64,
7068
}
7169

7270
impl Sealed for LendingMarket {}

token-lending/sdk/src/state/obligation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ pub struct Obligation {
4949
/// borrows and withdraws are disabled.
5050
pub allowed_borrow_value: Decimal,
5151
/// 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)
5453
/// if borrowed_value >= unhealthy_borrow_value, the obligation can be liquidated
5554
pub unhealthy_borrow_value: Decimal,
5655
}

0 commit comments

Comments
 (0)