Skip to content

Commit

Permalink
kamino: handle reserves with no price feed
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Apr 26, 2024
1 parent 39bc52b commit 6509eb3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/bin/sys-lend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ fn kamino_deposit(
Pubkey::find_program_address(&[b"lma", &lending_market.to_bytes()], &KAMINO_LEND_PROGRAM).0;

let reserve_farm_state = reserve.farm_collateral;
let scope_prices = reserve.config.token_info.scope_configuration.price_feed;
let reserve_liquidity_supply = reserve.liquidity.supply_vault;
let reserve_collateral_mint = reserve.collateral.mint_pubkey;
let reserve_destination_deposit_collateral = reserve.collateral.supply_vault;
Expand Down Expand Up @@ -605,7 +604,7 @@ fn kamino_deposit(

// Instruction: Kamino: Refresh Reserve

let mut refresh_reserves: Vec<(Pubkey, Pubkey)> = obligation_market_reserves
let mut refresh_reserves: Vec<(Pubkey, Pubkey, Pubkey)> = obligation_market_reserves
.iter()
.filter_map(|reserve_address| {
if *reserve_address != market_reserve_address {
Expand All @@ -617,7 +616,17 @@ fn kamino_deposit(

Some((
*reserve_address,
reserve.config.token_info.pyth_configuration.price,
if reserve.config.token_info.pyth_configuration.price == Pubkey::default() {
KAMINO_LEND_PROGRAM
} else {
reserve.config.token_info.pyth_configuration.price
},
if reserve.config.token_info.scope_configuration.price_feed == Pubkey::default()
{
KAMINO_LEND_PROGRAM
} else {
reserve.config.token_info.scope_configuration.price_feed
},
))
} else {
None
Expand All @@ -628,18 +637,19 @@ fn kamino_deposit(
refresh_reserves.push((
market_reserve_address,
reserve.config.token_info.pyth_configuration.price,
reserve.config.token_info.scope_configuration.price_feed,
));
for (refresh_reserve, pyth_oracle) in refresh_reserves.iter() {
for (reserve_address, pyth_oracle, scope_prices) in refresh_reserves {
instructions.push(Instruction::new_with_bytes(
KAMINO_LEND_PROGRAM,
&[0x02, 0xda, 0x8a, 0xeb, 0x4f, 0xc9, 0x19, 0x66],
vec![
// Reserve
AccountMeta::new(*refresh_reserve, false),
AccountMeta::new(reserve_address, false),
// Lending Market
AccountMeta::new_readonly(lending_market, false),
// Pyth Oracle
AccountMeta::new_readonly(*pyth_oracle, false),
AccountMeta::new_readonly(pyth_oracle, false),
AccountMeta::new_readonly(KAMINO_LEND_PROGRAM, false),
// Switchboard Twap Oracle
AccountMeta::new_readonly(KAMINO_LEND_PROGRAM, false),
Expand Down

0 comments on commit 6509eb3

Please sign in to comment.