create_account_with_seed.rs 16 KB

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