Skip to content

Commit

Permalink
audit nits
Browse files Browse the repository at this point in the history
  • Loading branch information
0xripleys committed Mar 13, 2023
1 parent e2e44ad commit 477d85d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
5 changes: 2 additions & 3 deletions token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ fn process_init_lending_market(
token_program_id: *token_program_id.key,
oracle_program_id: *oracle_program_id.key,
switchboard_oracle_program_id: *switchboard_oracle_program_id.key,
current_slot: Clock::get()?.slot,
});
LendingMarket::pack(lending_market, &mut lending_market_info.data.borrow_mut())?;

Expand Down Expand Up @@ -793,7 +792,7 @@ fn _redeem_reserve_collateral<'a>(
.rate_limiter
.update(
clock.slot,
reserve.market_value(Decimal::from(liquidity_amount))?,
reserve.market_value_upper_bound(Decimal::from(liquidity_amount))?,
)
.map_err(|err| {
msg!("Market outflow limit exceeded! Please try again later.");
Expand Down Expand Up @@ -2071,7 +2070,7 @@ fn process_update_reserve_config(
return Err(LendingError::InvalidMarketAuthority.into());
}

// if window duration and max outflow are different, then create a new rate limiter instance.
// if window duration or max outflow are different, then create a new rate limiter instance.
if rate_limiter_config != reserve.rate_limiter.config {
reserve.rate_limiter = RateLimiter::new(rate_limiter_config, Clock::get()?.slot);
}
Expand Down
2 changes: 2 additions & 0 deletions token-lending/program/tests/two_prices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ async fn test_withdraw() {

assert_eq!(balance_changes, expected_balance_changes);

test.advance_clock_by_slots(1).await;

// we shouldn't be able to withdraw anything else
for mint in [usdc_mint::id(), usdt_mint::id()] {
let err = lending_market
Expand Down
8 changes: 3 additions & 5 deletions token-lending/sdk/src/math/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Decimal {

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

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

#[test]
fn test_from_bps() {
let left = Decimal::from_bps(2000);
let right = Decimal::from_percent(20);

assert_eq!(left, right);
let left = Decimal::from_bps(190000);
assert_eq!(left, Decimal::from(19u64));
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions token-lending/sdk/src/oracles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub fn get_pyth_price(
let price_feed = price_account.to_price_feed(pyth_price_info.key);
// this can be unchecked bc the ema price is only used to _limit_ borrows and withdraws.
// ie staleness doesn't _really_ matter for this field.
//
// the pyth EMA is also updated every time the regular spot price is updated anyways so in
// reality the staleness should never be an issue.
let ema_price = price_feed.get_ema_price_unchecked();
pyth_price_to_decimal(&ema_price)?
};
Expand Down
2 changes: 0 additions & 2 deletions token-lending/sdk/src/state/lending_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ pub struct InitLendingMarketParams {
pub oracle_program_id: Pubkey,
/// Oracle (Switchboard) program id
pub switchboard_oracle_program_id: Pubkey,
/// Current slot
pub current_slot: u64,
}

impl Sealed for LendingMarket {}
Expand Down
3 changes: 1 addition & 2 deletions token-lending/sdk/src/state/obligation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ pub struct Obligation {
/// borrows and withdraws are disabled.
pub allowed_borrow_value: Decimal,
/// The dangerous borrow value at the weighted average liquidation threshold.
/// ie sum(d.deposited_amount * d.liquidation_threshold * min(d.current_spot_price, d.smoothed_price)
/// for d in deposits)
/// ie sum(d.deposited_amount * d.liquidation_threshold * d.current_spot_price for d in deposits)
/// if borrowed_value >= unhealthy_borrow_value, the obligation can be liquidated
pub unhealthy_borrow_value: Decimal,
}
Expand Down

0 comments on commit 477d85d

Please sign in to comment.