1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use borsh::BorshSerialize;
use solana_program::instruction::AccountMeta;
use switchboard_common::cfg_client;
use crate::anchor_traits::*;
use crate::prelude::*;
use crate::solana_compat::SYSTEM_PROGRAM_ID;
use crate::{find_lut_signer, solana_program, Pubkey};
/// Queue address lookup table reset instruction
pub struct QueueResetLut {}
/// Parameters for queue address lookup table reset instruction
#[derive(Clone, BorshSerialize, Debug)]
pub struct QueueResetLutParams {
/// Recent slot number for the reset
pub recent_slot: u64,
}
impl InstructionData for QueueResetLutParams {}
const DISCRIMINATOR: &[u8] = &[126, 234, 176, 75, 38, 211, 204, 53];
impl Discriminator for QueueResetLut {
const DISCRIMINATOR: &[u8] = DISCRIMINATOR;
}
impl Discriminator for QueueResetLutParams {
const DISCRIMINATOR: &[u8] = DISCRIMINATOR;
}
/// Arguments for building a queue address lookup table reset instruction
#[derive(Clone, Debug)]
pub struct QueueResetLutArgs {
/// Queue account public key
pub queue: Pubkey,
/// Authority account public key
pub authority: Pubkey,
/// Payer account public key
pub payer: Pubkey,
/// Recent slot number for the reset
pub recent_slot: u64,
}
/// Account metas for queue address lookup table reset instruction
pub struct QueueResetLutAccounts {
/// Queue account public key
pub queue: Pubkey,
/// Authority account public key
pub authority: Pubkey,
/// Payer account public key
pub payer: Pubkey,
/// Recent slot number for the reset
pub recent_slot: u64,
}
impl ToAccountMetas for QueueResetLutAccounts {
fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
let program_state = State::get_pda();
let system_program = SYSTEM_PROGRAM_ID;
let address_lookup_table_program = ADDRESS_LOOKUP_TABLE_PROGRAM_ID;
let lut_signer = find_lut_signer(&self.queue);
fn derive_lookup_table_address(
authority_address: &Pubkey,
recent_block_slot: u64,
) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[authority_address.as_ref(), &recent_block_slot.to_le_bytes()],
&ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
)
}
vec![
AccountMeta::new(self.queue, false),
AccountMeta::new_readonly(self.authority, true),
AccountMeta::new(self.payer, true),
AccountMeta::new_readonly(system_program.to_bytes().into(), false),
AccountMeta::new_readonly(program_state, false),
AccountMeta::new_readonly(lut_signer, false),
AccountMeta::new(
derive_lookup_table_address(&lut_signer, self.recent_slot).0,
false,
),
AccountMeta::new_readonly(address_lookup_table_program.to_bytes().into(), false),
]
}
}
cfg_client! {
use anchor_client::solana_client::nonblocking::rpc_client::RpcClient;
// use crate::get_sb_program_id; // Commented out due to unused import
#[cfg(not(feature = "anchor"))]
use spl_associated_token_account::solana_program::address_lookup_table::AddressLookupTableAccount;
#[cfg(feature = "anchor")]
use spl_associated_token_account::solana_program::address_lookup_table::AddressLookupTableAccount;
// fn derive_lookup_table_address(authority_address: &Pubkey, recent_block_slot: u64) -> (Pubkey, u8) {
// Pubkey::find_program_address(
// &[authority_address.as_ref(), &recent_block_slot.to_le_bytes()],
// &solana_program::address_lookup_table::program::id(),
// )
// }
impl QueueResetLut {
// TODO: Fix serialization errors - commented out due to missing trait implementations
/*
pub async fn build_ix(client: &RpcClient, args: QueueResetLutArgs) -> Result<Instruction, OnDemandError> {
let pid = if crate::utils::is_devnet() {
get_sb_program_id("devnet")
} else {
get_sb_program_id("mainnet")
};
let lut_signer = find_lut_signer(&args.queue);
let (lut_address, _) = derive_lookup_table_address(&lut_signer, args.recent_slot);
let program_state = State::get_pda();
let system_program = SYSTEM_PROGRAM_ID;
let address_lookup_table_program = ADDRESS_LOOKUP_TABLE_PROGRAM_ID;
let accounts = vec![
AccountMeta::new(args.queue, false),
AccountMeta::new_readonly(args.authority, true),
AccountMeta::new(args.payer, true),
AccountMeta::new_readonly(system_program.to_bytes().into(), false),
AccountMeta::new_readonly(program_state, false),
AccountMeta::new_readonly(lut_signer, false),
AccountMeta::new(lut_address, false),
AccountMeta::new_readonly(address_lookup_table_program.to_bytes().into(), false),
];
Ok(Instruction {
program_id: pid,
accounts,
data: [
QueueResetLut::DISCRIMINATOR,
&QueueResetLutParams {
recent_slot: args.recent_slot,
}.try_to_vec().map_err(|_| OnDemandError::SerializationError)?
].concat(),
})
}
*/
pub async fn fetch_luts(client: &RpcClient, args: QueueResetLutArgs) -> Result<Vec<AddressLookupTableAccount>, OnDemandError> {
let queue_data = QueueAccountData::fetch_async(client, args.queue).await?;
let queue_lut = queue_data.fetch_lut(&args.queue, client).await?;
Ok(vec![queue_lut])
}
}
}