Skip to content

Commit

Permalink
forgot to update smoothed price with price scale in switchboard case
Browse files Browse the repository at this point in the history
  • Loading branch information
0xripleys committed Dec 13, 2023
1 parent e53ede1 commit 6e5d7d3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ fn _refresh_reserve<'a>(
// currently there's no way to support two prices without a pyth oracle. So if a reserve
// only supports switchboard, reserve.smoothed_market_price == reserve.market_price
if reserve.liquidity.pyth_oracle_pubkey == solend_program::NULL_PUBKEY {
reserve.liquidity.smoothed_market_price = market_price;
reserve.liquidity.smoothed_market_price = market_price.try_mul(reserve.price_scale())?;
}

Reserve::pack(reserve, &mut reserve_info.data.borrow_mut())?;
Expand Down
44 changes: 44 additions & 0 deletions token-lending/program/tests/refresh_reserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,48 @@ async fn test_use_price_weight() {
wsol_reserve.account.liquidity.smoothed_market_price,
Decimal::from(16u64)
);

// check we do same thing for switchboard
let switchboard_feed_pubkey = Some(test.init_switchboard_feed(&wsol_mint::id()).await);
test.set_switchboard_price(
&wsol_mint::id(),
SwitchboardPriceArgs { price: 30, expo: 0 },
)
.await;

// update reserve so the switchboard feed is not NULL_PUBKEY
lending_market
.update_reserve_config(
&mut test,
&lending_market_owner,
&wsol_reserve,
wsol_reserve.account.config,
wsol_reserve.account.rate_limiter.config,
Some(&Oracle {
pyth_price_pubkey: NULL_PUBKEY,
pyth_product_pubkey: NULL_PUBKEY,
switchboard_feed_pubkey,
}),
)
.await
.unwrap();

test.advance_clock_by_slots(1).await;

let wsol_reserve = test.load_account::<Reserve>(reserves[0].pubkey).await;
lending_market
.refresh_reserve(&mut test, &wsol_reserve)
.await
.unwrap();

let wsol_reserve = test.load_account::<Reserve>(reserves[0].pubkey).await;
assert_eq!(
wsol_reserve.account.liquidity.market_price,
Decimal::from(24u64)
);

assert_eq!(
wsol_reserve.account.liquidity.smoothed_market_price,
Decimal::from(24u64)
);
}

0 comments on commit 6e5d7d3

Please sign in to comment.