Skip to main content

klend_interface/instructions/
refresh.rs

1use borsh::BorshSerialize;
2use solana_instruction::{AccountMeta, Instruction};
3use solana_pubkey::Pubkey;
4
5use crate::{discriminators, util::*, KLEND_PROGRAM_ID};
6
7// ---------------------------------------------------------------------------
8// refresh_reserve
9// ---------------------------------------------------------------------------
10
11pub struct RefreshReserveAccounts {
12    pub reserve: Pubkey,
13    pub lending_market: Pubkey,
14    pub pyth_oracle: Option<Pubkey>,
15    pub switchboard_price_oracle: Option<Pubkey>,
16    pub switchboard_twap_oracle: Option<Pubkey>,
17    pub scope_prices: Option<Pubkey>,
18}
19
20pub fn refresh_reserve(accounts: RefreshReserveAccounts) -> Instruction {
21    let data = discriminators::REFRESH_RESERVE.to_vec();
22
23    Instruction {
24        program_id: KLEND_PROGRAM_ID,
25        accounts: vec![
26            writable(accounts.reserve),
27            readonly(accounts.lending_market),
28            optional_account(&KLEND_PROGRAM_ID, accounts.pyth_oracle, false),
29            optional_account(&KLEND_PROGRAM_ID, accounts.switchboard_price_oracle, false),
30            optional_account(&KLEND_PROGRAM_ID, accounts.switchboard_twap_oracle, false),
31            optional_account(&KLEND_PROGRAM_ID, accounts.scope_prices, false),
32        ],
33        data,
34    }
35}
36
37// ---------------------------------------------------------------------------
38// refresh_reserves_batch
39// ---------------------------------------------------------------------------
40
41pub fn refresh_reserves_batch(
42    skip_price_updates: bool,
43    remaining_accounts: Vec<AccountMeta>,
44) -> Instruction {
45    #[derive(BorshSerialize)]
46    struct Args {
47        skip_price_updates: bool,
48    }
49
50    let args = Args { skip_price_updates };
51    let mut data = discriminators::REFRESH_RESERVES_BATCH.to_vec();
52    args.serialize(&mut data).unwrap();
53
54    Instruction {
55        program_id: KLEND_PROGRAM_ID,
56        accounts: remaining_accounts,
57        data,
58    }
59}
60
61// ---------------------------------------------------------------------------
62// refresh_obligation
63// ---------------------------------------------------------------------------
64
65pub struct RefreshObligationAccounts {
66    pub lending_market: Pubkey,
67    pub obligation: Pubkey,
68}
69
70pub fn refresh_obligation(
71    accounts: RefreshObligationAccounts,
72    remaining_accounts: Vec<AccountMeta>,
73) -> Instruction {
74    let data = discriminators::REFRESH_OBLIGATION.to_vec();
75
76    let mut account_metas = vec![
77        readonly(accounts.lending_market),
78        writable(accounts.obligation),
79    ];
80    account_metas.extend(remaining_accounts);
81
82    Instruction {
83        program_id: KLEND_PROGRAM_ID,
84        accounts: account_metas,
85        data,
86    }
87}