tensor_amm/generated/instructions/
edit_pool.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use crate::generated::types::EditPoolConfig;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11use solana_program::pubkey::Pubkey;
12
13/// Accounts.
14pub struct EditPool {
15    /// The owner of the pool--must sign to edit the pool.
16    pub owner: solana_program::pubkey::Pubkey,
17    /// The pool to edit.
18    pub pool: solana_program::pubkey::Pubkey,
19    /// The Solana system program.
20    pub system_program: solana_program::pubkey::Pubkey,
21}
22
23impl EditPool {
24    pub fn instruction(
25        &self,
26        args: EditPoolInstructionArgs,
27    ) -> solana_program::instruction::Instruction {
28        self.instruction_with_remaining_accounts(args, &[])
29    }
30    #[allow(clippy::vec_init_then_push)]
31    pub fn instruction_with_remaining_accounts(
32        &self,
33        args: EditPoolInstructionArgs,
34        remaining_accounts: &[solana_program::instruction::AccountMeta],
35    ) -> solana_program::instruction::Instruction {
36        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
37        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
38            self.owner, true,
39        ));
40        accounts.push(solana_program::instruction::AccountMeta::new(
41            self.pool, false,
42        ));
43        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
44            self.system_program,
45            false,
46        ));
47        accounts.extend_from_slice(remaining_accounts);
48        let mut data = EditPoolInstructionData::new().try_to_vec().unwrap();
49        let mut args = args.try_to_vec().unwrap();
50        data.append(&mut args);
51
52        solana_program::instruction::Instruction {
53            program_id: crate::TENSOR_AMM_ID,
54            accounts,
55            data,
56        }
57    }
58}
59
60#[derive(BorshDeserialize, BorshSerialize)]
61pub struct EditPoolInstructionData {
62    discriminator: [u8; 8],
63}
64
65impl EditPoolInstructionData {
66    pub fn new() -> Self {
67        Self {
68            discriminator: [50, 174, 34, 36, 3, 166, 29, 204],
69        }
70    }
71}
72
73impl Default for EditPoolInstructionData {
74    fn default() -> Self {
75        Self::new()
76    }
77}
78
79#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
80#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
81pub struct EditPoolInstructionArgs {
82    pub new_config: Option<EditPoolConfig>,
83    pub cosigner: Option<Pubkey>,
84    pub maker_broker: Option<Pubkey>,
85    pub expire_in_sec: Option<u64>,
86    pub max_taker_sell_count: Option<u32>,
87    pub reset_price_offset: bool,
88}
89
90/// Instruction builder for `EditPool`.
91///
92/// ### Accounts:
93///
94///   0. `[signer]` owner
95///   1. `[writable]` pool
96///   2. `[optional]` system_program (default to `11111111111111111111111111111111`)
97#[derive(Clone, Debug, Default)]
98pub struct EditPoolBuilder {
99    owner: Option<solana_program::pubkey::Pubkey>,
100    pool: Option<solana_program::pubkey::Pubkey>,
101    system_program: Option<solana_program::pubkey::Pubkey>,
102    new_config: Option<EditPoolConfig>,
103    cosigner: Option<Pubkey>,
104    maker_broker: Option<Pubkey>,
105    expire_in_sec: Option<u64>,
106    max_taker_sell_count: Option<u32>,
107    reset_price_offset: Option<bool>,
108    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
109}
110
111impl EditPoolBuilder {
112    pub fn new() -> Self {
113        Self::default()
114    }
115    /// The owner of the pool--must sign to edit the pool.
116    #[inline(always)]
117    pub fn owner(&mut self, owner: solana_program::pubkey::Pubkey) -> &mut Self {
118        self.owner = Some(owner);
119        self
120    }
121    /// The pool to edit.
122    #[inline(always)]
123    pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
124        self.pool = Some(pool);
125        self
126    }
127    /// `[optional account, default to '11111111111111111111111111111111']`
128    /// The Solana system program.
129    #[inline(always)]
130    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
131        self.system_program = Some(system_program);
132        self
133    }
134    /// `[optional argument]`
135    #[inline(always)]
136    pub fn new_config(&mut self, new_config: EditPoolConfig) -> &mut Self {
137        self.new_config = Some(new_config);
138        self
139    }
140    /// `[optional argument]`
141    #[inline(always)]
142    pub fn cosigner(&mut self, cosigner: Pubkey) -> &mut Self {
143        self.cosigner = Some(cosigner);
144        self
145    }
146    /// `[optional argument]`
147    #[inline(always)]
148    pub fn maker_broker(&mut self, maker_broker: Pubkey) -> &mut Self {
149        self.maker_broker = Some(maker_broker);
150        self
151    }
152    /// `[optional argument]`
153    #[inline(always)]
154    pub fn expire_in_sec(&mut self, expire_in_sec: u64) -> &mut Self {
155        self.expire_in_sec = Some(expire_in_sec);
156        self
157    }
158    /// `[optional argument]`
159    #[inline(always)]
160    pub fn max_taker_sell_count(&mut self, max_taker_sell_count: u32) -> &mut Self {
161        self.max_taker_sell_count = Some(max_taker_sell_count);
162        self
163    }
164    #[inline(always)]
165    pub fn reset_price_offset(&mut self, reset_price_offset: bool) -> &mut Self {
166        self.reset_price_offset = Some(reset_price_offset);
167        self
168    }
169    /// Add an additional account to the instruction.
170    #[inline(always)]
171    pub fn add_remaining_account(
172        &mut self,
173        account: solana_program::instruction::AccountMeta,
174    ) -> &mut Self {
175        self.__remaining_accounts.push(account);
176        self
177    }
178    /// Add additional accounts to the instruction.
179    #[inline(always)]
180    pub fn add_remaining_accounts(
181        &mut self,
182        accounts: &[solana_program::instruction::AccountMeta],
183    ) -> &mut Self {
184        self.__remaining_accounts.extend_from_slice(accounts);
185        self
186    }
187    #[allow(clippy::clone_on_copy)]
188    pub fn instruction(&self) -> solana_program::instruction::Instruction {
189        let accounts = EditPool {
190            owner: self.owner.expect("owner is not set"),
191            pool: self.pool.expect("pool is not set"),
192            system_program: self
193                .system_program
194                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
195        };
196        let args = EditPoolInstructionArgs {
197            new_config: self.new_config.clone(),
198            cosigner: self.cosigner.clone(),
199            maker_broker: self.maker_broker.clone(),
200            expire_in_sec: self.expire_in_sec.clone(),
201            max_taker_sell_count: self.max_taker_sell_count.clone(),
202            reset_price_offset: self
203                .reset_price_offset
204                .clone()
205                .expect("reset_price_offset is not set"),
206        };
207
208        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
209    }
210}
211
212/// `edit_pool` CPI accounts.
213pub struct EditPoolCpiAccounts<'a, 'b> {
214    /// The owner of the pool--must sign to edit the pool.
215    pub owner: &'b solana_program::account_info::AccountInfo<'a>,
216    /// The pool to edit.
217    pub pool: &'b solana_program::account_info::AccountInfo<'a>,
218    /// The Solana system program.
219    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
220}
221
222/// `edit_pool` CPI instruction.
223pub struct EditPoolCpi<'a, 'b> {
224    /// The program to invoke.
225    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
226    /// The owner of the pool--must sign to edit the pool.
227    pub owner: &'b solana_program::account_info::AccountInfo<'a>,
228    /// The pool to edit.
229    pub pool: &'b solana_program::account_info::AccountInfo<'a>,
230    /// The Solana system program.
231    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
232    /// The arguments for the instruction.
233    pub __args: EditPoolInstructionArgs,
234}
235
236impl<'a, 'b> EditPoolCpi<'a, 'b> {
237    pub fn new(
238        program: &'b solana_program::account_info::AccountInfo<'a>,
239        accounts: EditPoolCpiAccounts<'a, 'b>,
240        args: EditPoolInstructionArgs,
241    ) -> Self {
242        Self {
243            __program: program,
244            owner: accounts.owner,
245            pool: accounts.pool,
246            system_program: accounts.system_program,
247            __args: args,
248        }
249    }
250    #[inline(always)]
251    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
252        self.invoke_signed_with_remaining_accounts(&[], &[])
253    }
254    #[inline(always)]
255    pub fn invoke_with_remaining_accounts(
256        &self,
257        remaining_accounts: &[(
258            &'b solana_program::account_info::AccountInfo<'a>,
259            bool,
260            bool,
261        )],
262    ) -> solana_program::entrypoint::ProgramResult {
263        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
264    }
265    #[inline(always)]
266    pub fn invoke_signed(
267        &self,
268        signers_seeds: &[&[&[u8]]],
269    ) -> solana_program::entrypoint::ProgramResult {
270        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
271    }
272    #[allow(clippy::clone_on_copy)]
273    #[allow(clippy::vec_init_then_push)]
274    pub fn invoke_signed_with_remaining_accounts(
275        &self,
276        signers_seeds: &[&[&[u8]]],
277        remaining_accounts: &[(
278            &'b solana_program::account_info::AccountInfo<'a>,
279            bool,
280            bool,
281        )],
282    ) -> solana_program::entrypoint::ProgramResult {
283        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
284        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
285            *self.owner.key,
286            true,
287        ));
288        accounts.push(solana_program::instruction::AccountMeta::new(
289            *self.pool.key,
290            false,
291        ));
292        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
293            *self.system_program.key,
294            false,
295        ));
296        remaining_accounts.iter().for_each(|remaining_account| {
297            accounts.push(solana_program::instruction::AccountMeta {
298                pubkey: *remaining_account.0.key,
299                is_signer: remaining_account.1,
300                is_writable: remaining_account.2,
301            })
302        });
303        let mut data = EditPoolInstructionData::new().try_to_vec().unwrap();
304        let mut args = self.__args.try_to_vec().unwrap();
305        data.append(&mut args);
306
307        let instruction = solana_program::instruction::Instruction {
308            program_id: crate::TENSOR_AMM_ID,
309            accounts,
310            data,
311        };
312        let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
313        account_infos.push(self.__program.clone());
314        account_infos.push(self.owner.clone());
315        account_infos.push(self.pool.clone());
316        account_infos.push(self.system_program.clone());
317        remaining_accounts
318            .iter()
319            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
320
321        if signers_seeds.is_empty() {
322            solana_program::program::invoke(&instruction, &account_infos)
323        } else {
324            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
325        }
326    }
327}
328
329/// Instruction builder for `EditPool` via CPI.
330///
331/// ### Accounts:
332///
333///   0. `[signer]` owner
334///   1. `[writable]` pool
335///   2. `[]` system_program
336#[derive(Clone, Debug)]
337pub struct EditPoolCpiBuilder<'a, 'b> {
338    instruction: Box<EditPoolCpiBuilderInstruction<'a, 'b>>,
339}
340
341impl<'a, 'b> EditPoolCpiBuilder<'a, 'b> {
342    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
343        let instruction = Box::new(EditPoolCpiBuilderInstruction {
344            __program: program,
345            owner: None,
346            pool: None,
347            system_program: None,
348            new_config: None,
349            cosigner: None,
350            maker_broker: None,
351            expire_in_sec: None,
352            max_taker_sell_count: None,
353            reset_price_offset: None,
354            __remaining_accounts: Vec::new(),
355        });
356        Self { instruction }
357    }
358    /// The owner of the pool--must sign to edit the pool.
359    #[inline(always)]
360    pub fn owner(&mut self, owner: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
361        self.instruction.owner = Some(owner);
362        self
363    }
364    /// The pool to edit.
365    #[inline(always)]
366    pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
367        self.instruction.pool = Some(pool);
368        self
369    }
370    /// The Solana system program.
371    #[inline(always)]
372    pub fn system_program(
373        &mut self,
374        system_program: &'b solana_program::account_info::AccountInfo<'a>,
375    ) -> &mut Self {
376        self.instruction.system_program = Some(system_program);
377        self
378    }
379    /// `[optional argument]`
380    #[inline(always)]
381    pub fn new_config(&mut self, new_config: EditPoolConfig) -> &mut Self {
382        self.instruction.new_config = Some(new_config);
383        self
384    }
385    /// `[optional argument]`
386    #[inline(always)]
387    pub fn cosigner(&mut self, cosigner: Pubkey) -> &mut Self {
388        self.instruction.cosigner = Some(cosigner);
389        self
390    }
391    /// `[optional argument]`
392    #[inline(always)]
393    pub fn maker_broker(&mut self, maker_broker: Pubkey) -> &mut Self {
394        self.instruction.maker_broker = Some(maker_broker);
395        self
396    }
397    /// `[optional argument]`
398    #[inline(always)]
399    pub fn expire_in_sec(&mut self, expire_in_sec: u64) -> &mut Self {
400        self.instruction.expire_in_sec = Some(expire_in_sec);
401        self
402    }
403    /// `[optional argument]`
404    #[inline(always)]
405    pub fn max_taker_sell_count(&mut self, max_taker_sell_count: u32) -> &mut Self {
406        self.instruction.max_taker_sell_count = Some(max_taker_sell_count);
407        self
408    }
409    #[inline(always)]
410    pub fn reset_price_offset(&mut self, reset_price_offset: bool) -> &mut Self {
411        self.instruction.reset_price_offset = Some(reset_price_offset);
412        self
413    }
414    /// Add an additional account to the instruction.
415    #[inline(always)]
416    pub fn add_remaining_account(
417        &mut self,
418        account: &'b solana_program::account_info::AccountInfo<'a>,
419        is_writable: bool,
420        is_signer: bool,
421    ) -> &mut Self {
422        self.instruction
423            .__remaining_accounts
424            .push((account, is_writable, is_signer));
425        self
426    }
427    /// Add additional accounts to the instruction.
428    ///
429    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
430    /// and a `bool` indicating whether the account is a signer or not.
431    #[inline(always)]
432    pub fn add_remaining_accounts(
433        &mut self,
434        accounts: &[(
435            &'b solana_program::account_info::AccountInfo<'a>,
436            bool,
437            bool,
438        )],
439    ) -> &mut Self {
440        self.instruction
441            .__remaining_accounts
442            .extend_from_slice(accounts);
443        self
444    }
445    #[inline(always)]
446    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
447        self.invoke_signed(&[])
448    }
449    #[allow(clippy::clone_on_copy)]
450    #[allow(clippy::vec_init_then_push)]
451    pub fn invoke_signed(
452        &self,
453        signers_seeds: &[&[&[u8]]],
454    ) -> solana_program::entrypoint::ProgramResult {
455        let args = EditPoolInstructionArgs {
456            new_config: self.instruction.new_config.clone(),
457            cosigner: self.instruction.cosigner.clone(),
458            maker_broker: self.instruction.maker_broker.clone(),
459            expire_in_sec: self.instruction.expire_in_sec.clone(),
460            max_taker_sell_count: self.instruction.max_taker_sell_count.clone(),
461            reset_price_offset: self
462                .instruction
463                .reset_price_offset
464                .clone()
465                .expect("reset_price_offset is not set"),
466        };
467        let instruction = EditPoolCpi {
468            __program: self.instruction.__program,
469
470            owner: self.instruction.owner.expect("owner is not set"),
471
472            pool: self.instruction.pool.expect("pool is not set"),
473
474            system_program: self
475                .instruction
476                .system_program
477                .expect("system_program is not set"),
478            __args: args,
479        };
480        instruction.invoke_signed_with_remaining_accounts(
481            signers_seeds,
482            &self.instruction.__remaining_accounts,
483        )
484    }
485}
486
487#[derive(Clone, Debug)]
488struct EditPoolCpiBuilderInstruction<'a, 'b> {
489    __program: &'b solana_program::account_info::AccountInfo<'a>,
490    owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
491    pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
492    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
493    new_config: Option<EditPoolConfig>,
494    cosigner: Option<Pubkey>,
495    maker_broker: Option<Pubkey>,
496    expire_in_sec: Option<u64>,
497    max_taker_sell_count: Option<u32>,
498    reset_price_offset: Option<bool>,
499    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
500    __remaining_accounts: Vec<(
501        &'b solana_program::account_info::AccountInfo<'a>,
502        bool,
503        bool,
504    )>,
505}