1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct CreateVault {
13 pub vault: solana_program::pubkey::Pubkey,
15 pub creator: solana_program::pubkey::Pubkey,
17 pub base: solana_program::pubkey::Pubkey,
19 pub payer: solana_program::pubkey::Pubkey,
21 pub system_program: solana_program::pubkey::Pubkey,
23 pub sysvar_instructions: solana_program::pubkey::Pubkey,
25}
26
27impl CreateVault {
28 pub fn instruction(&self) -> solana_program::instruction::Instruction {
29 self.instruction_with_remaining_accounts(&[])
30 }
31 #[allow(clippy::vec_init_then_push)]
32 pub fn instruction_with_remaining_accounts(
33 &self,
34 remaining_accounts: &[solana_program::instruction::AccountMeta],
35 ) -> solana_program::instruction::Instruction {
36 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
37 accounts.push(solana_program::instruction::AccountMeta::new(
38 self.vault, false,
39 ));
40 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
41 self.creator,
42 true,
43 ));
44 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
45 self.base, true,
46 ));
47 accounts.push(solana_program::instruction::AccountMeta::new(
48 self.payer, true,
49 ));
50 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
51 self.system_program,
52 false,
53 ));
54 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
55 self.sysvar_instructions,
56 false,
57 ));
58 accounts.extend_from_slice(remaining_accounts);
59 let data = CreateVaultInstructionData::new().try_to_vec().unwrap();
60
61 solana_program::instruction::Instruction {
62 program_id: crate::MPL_VAULT_ID,
63 accounts,
64 data,
65 }
66 }
67}
68
69#[derive(BorshDeserialize, BorshSerialize)]
70struct CreateVaultInstructionData {
71 discriminator: u8,
72}
73
74impl CreateVaultInstructionData {
75 fn new() -> Self {
76 Self { discriminator: 1 }
77 }
78}
79
80#[derive(Default)]
91pub struct CreateVaultBuilder {
92 vault: Option<solana_program::pubkey::Pubkey>,
93 creator: Option<solana_program::pubkey::Pubkey>,
94 base: Option<solana_program::pubkey::Pubkey>,
95 payer: Option<solana_program::pubkey::Pubkey>,
96 system_program: Option<solana_program::pubkey::Pubkey>,
97 sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
98 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
99}
100
101impl CreateVaultBuilder {
102 pub fn new() -> Self {
103 Self::default()
104 }
105 #[inline(always)]
107 pub fn vault(&mut self, vault: solana_program::pubkey::Pubkey) -> &mut Self {
108 self.vault = Some(vault);
109 self
110 }
111 #[inline(always)]
113 pub fn creator(&mut self, creator: solana_program::pubkey::Pubkey) -> &mut Self {
114 self.creator = Some(creator);
115 self
116 }
117 #[inline(always)]
119 pub fn base(&mut self, base: solana_program::pubkey::Pubkey) -> &mut Self {
120 self.base = Some(base);
121 self
122 }
123 #[inline(always)]
125 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
126 self.payer = Some(payer);
127 self
128 }
129 #[inline(always)]
132 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
133 self.system_program = Some(system_program);
134 self
135 }
136 #[inline(always)]
139 pub fn sysvar_instructions(
140 &mut self,
141 sysvar_instructions: solana_program::pubkey::Pubkey,
142 ) -> &mut Self {
143 self.sysvar_instructions = Some(sysvar_instructions);
144 self
145 }
146 #[inline(always)]
148 pub fn add_remaining_account(
149 &mut self,
150 account: solana_program::instruction::AccountMeta,
151 ) -> &mut Self {
152 self.__remaining_accounts.push(account);
153 self
154 }
155 #[inline(always)]
157 pub fn add_remaining_accounts(
158 &mut self,
159 accounts: &[solana_program::instruction::AccountMeta],
160 ) -> &mut Self {
161 self.__remaining_accounts.extend_from_slice(accounts);
162 self
163 }
164 #[allow(clippy::clone_on_copy)]
165 pub fn instruction(&self) -> solana_program::instruction::Instruction {
166 let accounts = CreateVault {
167 vault: self.vault.expect("vault is not set"),
168 creator: self.creator.expect("creator is not set"),
169 base: self.base.expect("base is not set"),
170 payer: self.payer.expect("payer is not set"),
171 system_program: self
172 .system_program
173 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
174 sysvar_instructions: self.sysvar_instructions.unwrap_or(solana_program::pubkey!(
175 "Sysvar1nstructions1111111111111111111111111"
176 )),
177 };
178
179 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
180 }
181}
182
183pub struct CreateVaultCpiAccounts<'a, 'b> {
185 pub vault: &'b solana_program::account_info::AccountInfo<'a>,
187 pub creator: &'b solana_program::account_info::AccountInfo<'a>,
189 pub base: &'b solana_program::account_info::AccountInfo<'a>,
191 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
193 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
195 pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
197}
198
199pub struct CreateVaultCpi<'a, 'b> {
201 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
203 pub vault: &'b solana_program::account_info::AccountInfo<'a>,
205 pub creator: &'b solana_program::account_info::AccountInfo<'a>,
207 pub base: &'b solana_program::account_info::AccountInfo<'a>,
209 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
211 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
213 pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
215}
216
217impl<'a, 'b> CreateVaultCpi<'a, 'b> {
218 pub fn new(
219 program: &'b solana_program::account_info::AccountInfo<'a>,
220 accounts: CreateVaultCpiAccounts<'a, 'b>,
221 ) -> Self {
222 Self {
223 __program: program,
224 vault: accounts.vault,
225 creator: accounts.creator,
226 base: accounts.base,
227 payer: accounts.payer,
228 system_program: accounts.system_program,
229 sysvar_instructions: accounts.sysvar_instructions,
230 }
231 }
232 #[inline(always)]
233 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
234 self.invoke_signed_with_remaining_accounts(&[], &[])
235 }
236 #[inline(always)]
237 pub fn invoke_with_remaining_accounts(
238 &self,
239 remaining_accounts: &[(
240 &'b solana_program::account_info::AccountInfo<'a>,
241 bool,
242 bool,
243 )],
244 ) -> solana_program::entrypoint::ProgramResult {
245 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
246 }
247 #[inline(always)]
248 pub fn invoke_signed(
249 &self,
250 signers_seeds: &[&[&[u8]]],
251 ) -> solana_program::entrypoint::ProgramResult {
252 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
253 }
254 #[allow(clippy::clone_on_copy)]
255 #[allow(clippy::vec_init_then_push)]
256 pub fn invoke_signed_with_remaining_accounts(
257 &self,
258 signers_seeds: &[&[&[u8]]],
259 remaining_accounts: &[(
260 &'b solana_program::account_info::AccountInfo<'a>,
261 bool,
262 bool,
263 )],
264 ) -> solana_program::entrypoint::ProgramResult {
265 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
266 accounts.push(solana_program::instruction::AccountMeta::new(
267 *self.vault.key,
268 false,
269 ));
270 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
271 *self.creator.key,
272 true,
273 ));
274 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
275 *self.base.key,
276 true,
277 ));
278 accounts.push(solana_program::instruction::AccountMeta::new(
279 *self.payer.key,
280 true,
281 ));
282 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
283 *self.system_program.key,
284 false,
285 ));
286 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
287 *self.sysvar_instructions.key,
288 false,
289 ));
290 remaining_accounts.iter().for_each(|remaining_account| {
291 accounts.push(solana_program::instruction::AccountMeta {
292 pubkey: *remaining_account.0.key,
293 is_signer: remaining_account.1,
294 is_writable: remaining_account.2,
295 })
296 });
297 let data = CreateVaultInstructionData::new().try_to_vec().unwrap();
298
299 let instruction = solana_program::instruction::Instruction {
300 program_id: crate::MPL_VAULT_ID,
301 accounts,
302 data,
303 };
304 let mut account_infos = Vec::with_capacity(6 + 1 + remaining_accounts.len());
305 account_infos.push(self.__program.clone());
306 account_infos.push(self.vault.clone());
307 account_infos.push(self.creator.clone());
308 account_infos.push(self.base.clone());
309 account_infos.push(self.payer.clone());
310 account_infos.push(self.system_program.clone());
311 account_infos.push(self.sysvar_instructions.clone());
312 remaining_accounts
313 .iter()
314 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
315
316 if signers_seeds.is_empty() {
317 solana_program::program::invoke(&instruction, &account_infos)
318 } else {
319 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
320 }
321 }
322}
323
324pub struct CreateVaultCpiBuilder<'a, 'b> {
335 instruction: Box<CreateVaultCpiBuilderInstruction<'a, 'b>>,
336}
337
338impl<'a, 'b> CreateVaultCpiBuilder<'a, 'b> {
339 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
340 let instruction = Box::new(CreateVaultCpiBuilderInstruction {
341 __program: program,
342 vault: None,
343 creator: None,
344 base: None,
345 payer: None,
346 system_program: None,
347 sysvar_instructions: None,
348 __remaining_accounts: Vec::new(),
349 });
350 Self { instruction }
351 }
352 #[inline(always)]
354 pub fn vault(&mut self, vault: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
355 self.instruction.vault = Some(vault);
356 self
357 }
358 #[inline(always)]
360 pub fn creator(
361 &mut self,
362 creator: &'b solana_program::account_info::AccountInfo<'a>,
363 ) -> &mut Self {
364 self.instruction.creator = Some(creator);
365 self
366 }
367 #[inline(always)]
369 pub fn base(&mut self, base: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
370 self.instruction.base = Some(base);
371 self
372 }
373 #[inline(always)]
375 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
376 self.instruction.payer = Some(payer);
377 self
378 }
379 #[inline(always)]
381 pub fn system_program(
382 &mut self,
383 system_program: &'b solana_program::account_info::AccountInfo<'a>,
384 ) -> &mut Self {
385 self.instruction.system_program = Some(system_program);
386 self
387 }
388 #[inline(always)]
390 pub fn sysvar_instructions(
391 &mut self,
392 sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
393 ) -> &mut Self {
394 self.instruction.sysvar_instructions = Some(sysvar_instructions);
395 self
396 }
397 #[inline(always)]
399 pub fn add_remaining_account(
400 &mut self,
401 account: &'b solana_program::account_info::AccountInfo<'a>,
402 is_writable: bool,
403 is_signer: bool,
404 ) -> &mut Self {
405 self.instruction
406 .__remaining_accounts
407 .push((account, is_writable, is_signer));
408 self
409 }
410 #[inline(always)]
415 pub fn add_remaining_accounts(
416 &mut self,
417 accounts: &[(
418 &'b solana_program::account_info::AccountInfo<'a>,
419 bool,
420 bool,
421 )],
422 ) -> &mut Self {
423 self.instruction
424 .__remaining_accounts
425 .extend_from_slice(accounts);
426 self
427 }
428 #[inline(always)]
429 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
430 self.invoke_signed(&[])
431 }
432 #[allow(clippy::clone_on_copy)]
433 #[allow(clippy::vec_init_then_push)]
434 pub fn invoke_signed(
435 &self,
436 signers_seeds: &[&[&[u8]]],
437 ) -> solana_program::entrypoint::ProgramResult {
438 let instruction = CreateVaultCpi {
439 __program: self.instruction.__program,
440
441 vault: self.instruction.vault.expect("vault is not set"),
442
443 creator: self.instruction.creator.expect("creator is not set"),
444
445 base: self.instruction.base.expect("base is not set"),
446
447 payer: self.instruction.payer.expect("payer is not set"),
448
449 system_program: self
450 .instruction
451 .system_program
452 .expect("system_program is not set"),
453
454 sysvar_instructions: self
455 .instruction
456 .sysvar_instructions
457 .expect("sysvar_instructions is not set"),
458 };
459 instruction.invoke_signed_with_remaining_accounts(
460 signers_seeds,
461 &self.instruction.__remaining_accounts,
462 )
463 }
464}
465
466struct CreateVaultCpiBuilderInstruction<'a, 'b> {
467 __program: &'b solana_program::account_info::AccountInfo<'a>,
468 vault: Option<&'b solana_program::account_info::AccountInfo<'a>>,
469 creator: Option<&'b solana_program::account_info::AccountInfo<'a>>,
470 base: Option<&'b solana_program::account_info::AccountInfo<'a>>,
471 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
472 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
473 sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
474 __remaining_accounts: Vec<(
476 &'b solana_program::account_info::AccountInfo<'a>,
477 bool,
478 bool,
479 )>,
480}