meteora_sol/instructions/
migrate_bin_array.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11#[derive(Debug)]
13pub struct MigrateBinArray {
14 pub lb_pair: solana_pubkey::Pubkey,
15}
16
17impl MigrateBinArray {
18 pub fn instruction(&self) -> solana_instruction::Instruction {
19 self.instruction_with_remaining_accounts(&[])
20 }
21 #[allow(clippy::arithmetic_side_effects)]
22 #[allow(clippy::vec_init_then_push)]
23 pub fn instruction_with_remaining_accounts(
24 &self,
25 remaining_accounts: &[solana_instruction::AccountMeta],
26 ) -> solana_instruction::Instruction {
27 let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
28 accounts.push(solana_instruction::AccountMeta::new_readonly(
29 self.lb_pair,
30 false,
31 ));
32 accounts.extend_from_slice(remaining_accounts);
33 let data = borsh::to_vec(&MigrateBinArrayInstructionData::new()).unwrap();
34
35 solana_instruction::Instruction {
36 program_id: crate::LB_CLMM_ID,
37 accounts,
38 data,
39 }
40 }
41}
42
43#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
44#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
45pub struct MigrateBinArrayInstructionData {
46 discriminator: [u8; 8],
47}
48
49impl MigrateBinArrayInstructionData {
50 pub fn new() -> Self {
51 Self {
52 discriminator: [17, 23, 159, 211, 101, 184, 41, 241],
53 }
54 }
55}
56
57impl Default for MigrateBinArrayInstructionData {
58 fn default() -> Self {
59 Self::new()
60 }
61}
62
63#[derive(Clone, Debug, Default)]
69pub struct MigrateBinArrayBuilder {
70 lb_pair: Option<solana_pubkey::Pubkey>,
71 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
72}
73
74impl MigrateBinArrayBuilder {
75 pub fn new() -> Self {
76 Self::default()
77 }
78 #[inline(always)]
79 pub fn lb_pair(&mut self, lb_pair: solana_pubkey::Pubkey) -> &mut Self {
80 self.lb_pair = Some(lb_pair);
81 self
82 }
83 #[inline(always)]
85 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
86 self.__remaining_accounts.push(account);
87 self
88 }
89 #[inline(always)]
91 pub fn add_remaining_accounts(
92 &mut self,
93 accounts: &[solana_instruction::AccountMeta],
94 ) -> &mut Self {
95 self.__remaining_accounts.extend_from_slice(accounts);
96 self
97 }
98 #[allow(clippy::clone_on_copy)]
99 pub fn instruction(&self) -> solana_instruction::Instruction {
100 let accounts = MigrateBinArray {
101 lb_pair: self.lb_pair.expect("lb_pair is not set"),
102 };
103
104 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
105 }
106}
107
108pub struct MigrateBinArrayCpiAccounts<'a, 'b> {
110 pub lb_pair: &'b solana_account_info::AccountInfo<'a>,
111}
112
113pub struct MigrateBinArrayCpi<'a, 'b> {
115 pub __program: &'b solana_account_info::AccountInfo<'a>,
117
118 pub lb_pair: &'b solana_account_info::AccountInfo<'a>,
119}
120
121impl<'a, 'b> MigrateBinArrayCpi<'a, 'b> {
122 pub fn new(
123 program: &'b solana_account_info::AccountInfo<'a>,
124 accounts: MigrateBinArrayCpiAccounts<'a, 'b>,
125 ) -> Self {
126 Self {
127 __program: program,
128 lb_pair: accounts.lb_pair,
129 }
130 }
131 #[inline(always)]
132 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
133 self.invoke_signed_with_remaining_accounts(&[], &[])
134 }
135 #[inline(always)]
136 pub fn invoke_with_remaining_accounts(
137 &self,
138 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
139 ) -> solana_program_entrypoint::ProgramResult {
140 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
141 }
142 #[inline(always)]
143 pub fn invoke_signed(
144 &self,
145 signers_seeds: &[&[&[u8]]],
146 ) -> solana_program_entrypoint::ProgramResult {
147 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
148 }
149 #[allow(clippy::arithmetic_side_effects)]
150 #[allow(clippy::clone_on_copy)]
151 #[allow(clippy::vec_init_then_push)]
152 pub fn invoke_signed_with_remaining_accounts(
153 &self,
154 signers_seeds: &[&[&[u8]]],
155 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
156 ) -> solana_program_entrypoint::ProgramResult {
157 let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
158 accounts.push(solana_instruction::AccountMeta::new_readonly(
159 *self.lb_pair.key,
160 false,
161 ));
162 remaining_accounts.iter().for_each(|remaining_account| {
163 accounts.push(solana_instruction::AccountMeta {
164 pubkey: *remaining_account.0.key,
165 is_signer: remaining_account.1,
166 is_writable: remaining_account.2,
167 })
168 });
169 let data = borsh::to_vec(&MigrateBinArrayInstructionData::new()).unwrap();
170
171 let instruction = solana_instruction::Instruction {
172 program_id: crate::LB_CLMM_ID,
173 accounts,
174 data,
175 };
176 let mut account_infos = Vec::with_capacity(2 + remaining_accounts.len());
177 account_infos.push(self.__program.clone());
178 account_infos.push(self.lb_pair.clone());
179 remaining_accounts
180 .iter()
181 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
182
183 if signers_seeds.is_empty() {
184 solana_cpi::invoke(&instruction, &account_infos)
185 } else {
186 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
187 }
188 }
189}
190
191#[derive(Clone, Debug)]
197pub struct MigrateBinArrayCpiBuilder<'a, 'b> {
198 instruction: Box<MigrateBinArrayCpiBuilderInstruction<'a, 'b>>,
199}
200
201impl<'a, 'b> MigrateBinArrayCpiBuilder<'a, 'b> {
202 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
203 let instruction = Box::new(MigrateBinArrayCpiBuilderInstruction {
204 __program: program,
205 lb_pair: None,
206 __remaining_accounts: Vec::new(),
207 });
208 Self { instruction }
209 }
210 #[inline(always)]
211 pub fn lb_pair(&mut self, lb_pair: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
212 self.instruction.lb_pair = Some(lb_pair);
213 self
214 }
215 #[inline(always)]
217 pub fn add_remaining_account(
218 &mut self,
219 account: &'b solana_account_info::AccountInfo<'a>,
220 is_writable: bool,
221 is_signer: bool,
222 ) -> &mut Self {
223 self.instruction
224 .__remaining_accounts
225 .push((account, is_writable, is_signer));
226 self
227 }
228 #[inline(always)]
233 pub fn add_remaining_accounts(
234 &mut self,
235 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
236 ) -> &mut Self {
237 self.instruction
238 .__remaining_accounts
239 .extend_from_slice(accounts);
240 self
241 }
242 #[inline(always)]
243 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
244 self.invoke_signed(&[])
245 }
246 #[allow(clippy::clone_on_copy)]
247 #[allow(clippy::vec_init_then_push)]
248 pub fn invoke_signed(
249 &self,
250 signers_seeds: &[&[&[u8]]],
251 ) -> solana_program_entrypoint::ProgramResult {
252 let instruction = MigrateBinArrayCpi {
253 __program: self.instruction.__program,
254
255 lb_pair: self.instruction.lb_pair.expect("lb_pair is not set"),
256 };
257 instruction.invoke_signed_with_remaining_accounts(
258 signers_seeds,
259 &self.instruction.__remaining_accounts,
260 )
261 }
262}
263
264#[derive(Clone, Debug)]
265struct MigrateBinArrayCpiBuilderInstruction<'a, 'b> {
266 __program: &'b solana_account_info::AccountInfo<'a>,
267 lb_pair: Option<&'b solana_account_info::AccountInfo<'a>>,
268 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
270}