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