Skip to main content

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