use borsh::BorshSerialize;
use solana_program::instruction::AccountMeta;
use crate::anchor_traits::*;
use crate::prelude::*;
use crate::SYSTEM_PROGRAM_ID;
use crate::ADDRESS_LOOKUP_TABLE_PROGRAM_ID;
use crate::{cfg_client, solana_program, Pubkey};
pub struct OracleResetLut {}
#[derive(Clone, BorshSerialize, Debug)]
pub struct OracleResetLutParams {
pub recent_slot: u64,
}
impl InstructionData for OracleResetLutParams {}
impl Discriminator for OracleResetLut {
const DISCRIMINATOR: &'static [u8] = &[147, 244, 108, 198, 152, 219, 0, 22];
}
impl Discriminator for OracleResetLutParams {
const DISCRIMINATOR: &'static [u8] = OracleResetLut::DISCRIMINATOR;
}
pub struct OracleResetLutArgs {
pub oracle: Pubkey,
pub payer: Pubkey,
pub recent_slot: u64,
}
pub struct OracleResetLutAccounts {
pub oracle: Pubkey,
pub authority: Pubkey,
pub payer: Pubkey,
pub system_program: Pubkey,
pub state: Pubkey,
pub lut_signer: Pubkey,
pub lut: Pubkey,
pub address_lookup_table_program: Pubkey,
}
impl ToAccountMetas for OracleResetLutAccounts {
fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
let state_pubkey = State::get_pda();
vec![
AccountMeta::new(self.oracle, false),
AccountMeta::new_readonly(self.authority, true),
AccountMeta::new(self.payer, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID.to_bytes().into(), false),
AccountMeta::new_readonly(state_pubkey, false),
AccountMeta::new_readonly(self.lut_signer, false),
AccountMeta::new(self.lut, false),
AccountMeta::new_readonly(ADDRESS_LOOKUP_TABLE_PROGRAM_ID.to_bytes().into(), false),
]
}
}
cfg_client! {
use crate::solana_compat::solana_client::nonblocking::rpc_client::RpcClient;
use crate::derive_lookup_table_address;
use crate::get_sb_program_id;
use crate::find_lut_signer;
impl OracleResetLut {
pub async fn build_ix(client: &RpcClient, args: OracleResetLutArgs) -> Result<Instruction, OnDemandError> {
let oracle_data = OracleAccountData::fetch_async(client, args.oracle).await?;
let authority = oracle_data.authority;
let payer = oracle_data.authority;
let lut_signer: Pubkey = find_lut_signer(&args.oracle);
let lut = derive_lookup_table_address(&lut_signer.to_bytes().into(), args.recent_slot).0;
let address_lookup_table_program = crate::ADDRESS_LOOKUP_TABLE_PROGRAM_ID;
let pid = if crate::utils::is_devnet() {
get_sb_program_id("devnet")
} else {
get_sb_program_id("mainnet")
};
let ix = crate::utils::build_ix(
&pid,
&OracleResetLutAccounts {
oracle: args.oracle,
state: State::get_pda(),
authority,
lut_signer,
lut: lut.to_bytes().into(),
address_lookup_table_program,
payer,
system_program: SYSTEM_PROGRAM_ID.to_bytes().into(),
},
&OracleResetLutParams {
recent_slot: args.recent_slot,
}
);
Ok(ix)
}
}
}