tensor_escrow/generated/instructions/
init_update_tswap.rs

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