instruction.rs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. //! Instruction types
  2. use crate::error::TokenError;
  3. use solana_sdk::{
  4. instruction::{AccountMeta, Instruction},
  5. program_error::ProgramError,
  6. pubkey::Pubkey,
  7. };
  8. use std::mem::size_of;
  9. /// Minimum number of multisignature signers (min N)
  10. pub const MIN_SIGNERS: usize = 1;
  11. /// Maximum number of multisignature signers (max N)
  12. pub const MAX_SIGNERS: usize = 11;
  13. /// Instructions supported by the token program.
  14. #[repr(C)]
  15. #[derive(Clone, Debug, PartialEq)]
  16. pub enum TokenInstruction {
  17. /// Initializes a new mint and optionally deposits all the newly minted tokens in an account.
  18. ///
  19. /// The `InitializeMint` instruction requires no signers and MUST be included within
  20. /// the same Transaction as the system program's `CreateInstruction` that creates the account
  21. /// being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  22. ///
  23. /// Accounts expected by this instruction:
  24. ///
  25. /// 0. `[writable]` The mint to initialize.
  26. /// 1.
  27. /// * If supply is non-zero: `[writable]` The account to hold all the newly minted tokens.
  28. /// * If supply is zero: `[]` The owner/multisignature of the mint.
  29. /// 2. `[]` (optional) The owner/multisignature of the mint if supply is non-zero, if
  30. /// present then further minting is supported.
  31. ///
  32. InitializeMint {
  33. /// Initial amount of tokens to mint.
  34. amount: u64,
  35. /// Number of base 10 digits to the right of the decimal place.
  36. decimals: u8,
  37. },
  38. /// Initializes a new account to hold tokens. If this account is associated with the native mint
  39. /// then the token balance of the initialized account will be equal to the amount of SOL in the account.
  40. ///
  41. /// The `InitializeAccount` instruction requires no signers and MUST be included within
  42. /// the same Transaction as the system program's `CreateInstruction` that creates the account
  43. /// being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  44. ///
  45. /// Accounts expected by this instruction:
  46. ///
  47. /// 0. `[writable]` The account to initialize.
  48. /// 1. `[]` The mint this account will be associated with.
  49. /// 2. `[]` The new account's owner/multisignature.
  50. InitializeAccount,
  51. /// Initializes a multisignature account with N provided signers.
  52. ///
  53. /// Multisignature accounts can used in place of any single owner/delegate accounts in any
  54. /// token instruction that require an owner/delegate to be present. The variant field represents the
  55. /// number of signers (M) required to validate this multisignature account.
  56. ///
  57. /// The `InitializeMultisig` instruction requires no signers and MUST be included within
  58. /// the same Transaction as the system program's `CreateInstruction` that creates the account
  59. /// being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  60. ///
  61. /// Accounts expected by this instruction:
  62. ///
  63. /// 0. `[writable]` The multisignature account to initialize.
  64. /// 1. ..1+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
  65. InitializeMultisig {
  66. /// The number of signers (M) required to validate this multisignature account.
  67. m: u8,
  68. },
  69. /// Transfers tokens from one account to another either directly or via a delegate. If this
  70. /// account is associated with the native mint then equal amounts of SOL and Tokens will be
  71. /// transferred to the destination account.
  72. ///
  73. /// Accounts expected by this instruction:
  74. ///
  75. /// * Single owner/delegate
  76. /// 0. `[writable]` The source account.
  77. /// 1. `[writable]` The destination account.
  78. /// 2. '[signer]' The source account's owner/delegate.
  79. ///
  80. /// * Multisignature owner/delegate
  81. /// 0. `[writable]` The source account.
  82. /// 1. `[writable]` The destination account.
  83. /// 2. '[]' The source account's multisignature owner/delegate.
  84. /// 3. ..3+M '[signer]' M signer accounts.
  85. Transfer {
  86. /// The amount of tokens to transfer.
  87. amount: u64,
  88. },
  89. /// Approves a delegate. A delegate is given the authority over
  90. /// tokens on behalf of the source account's owner.
  91. /// Accounts expected by this instruction:
  92. ///
  93. /// * Single owner
  94. /// 0. `[writable]` The source account.
  95. /// 1. `[]` The delegate.
  96. /// 2. `[signer]` The source account owner.
  97. ///
  98. /// * Multisignature owner
  99. /// 0. `[writable]` The source account.
  100. /// 1. `[]` The delegate.
  101. /// 2. '[]' The source account's multisignature owner.
  102. /// 3. ..3+M '[signer]' M signer accounts
  103. Approve {
  104. /// The amount of tokens the delegate is approved for.
  105. amount: u64,
  106. },
  107. /// Revokes the delegate's authority.
  108. ///
  109. /// Accounts expected by this instruction:
  110. ///
  111. /// * Single owner
  112. /// 0. `[writable]` The source account.
  113. /// 1. `[signer]` The source account owner.
  114. ///
  115. /// * Multisignature owner
  116. /// 0. `[writable]` The source account.
  117. /// 1. '[]' The source account's multisignature owner.
  118. /// 2. ..2+M '[signer]' M signer accounts
  119. Revoke,
  120. /// Sets a new owner of a mint or account.
  121. ///
  122. /// Accounts expected by this instruction:
  123. ///
  124. /// * Single owner
  125. /// 0. `[writable]` The mint or account to change the owner of.
  126. /// 1. `[]` The new owner/delegate/multisignature.
  127. /// 2. `[signer]` The owner of the mint or account.
  128. ///
  129. /// * Multisignature owner
  130. /// 0. `[writable]` The mint or account to change the owner of.
  131. /// 1. `[]` The new owner/delegate/multisignature.
  132. /// 2. `[]` The mint's or account's multisignature owner.
  133. /// 3. ..3+M '[signer]' M signer accounts
  134. SetOwner,
  135. /// Mints new tokens to an account. The native mint does not support minting.
  136. ///
  137. /// Accounts expected by this instruction:
  138. ///
  139. /// * Single owner
  140. /// 0. `[writable]` The mint.
  141. /// 1. `[writable]` The account to mint tokens to.
  142. /// 2. `[signer]` The mint's owner.
  143. ///
  144. /// * Multisignature owner
  145. /// 0. `[writable]` The mint.
  146. /// 1. `[writable]` The account to mint tokens to.
  147. /// 2. `[]` The mint's multisignature owner.
  148. /// 3. ..3+M '[signer]' M signer accounts.
  149. MintTo {
  150. /// The amount of new tokens to mint.
  151. amount: u64,
  152. },
  153. /// Burns tokens by removing them from an account. `Burn` does not support accounts
  154. /// associated with the native mint, use `CloseAccount` instead.
  155. ///
  156. /// Accounts expected by this instruction:
  157. ///
  158. /// * Single owner/delegate
  159. /// 0. `[writable]` The account to burn from.
  160. /// 1. `[signer]` The account's owner/delegate.
  161. ///
  162. /// * Multisignature owner/delegate
  163. /// 0. `[writable]` The account to burn from.
  164. /// 1. `[]` The account's multisignature owner/delegate.
  165. /// 2. ..2+M '[signer]' M signer accounts.
  166. Burn {
  167. /// The amount of tokens to burn.
  168. amount: u64,
  169. },
  170. /// Close an account by transferring all its SOL to the destination account.
  171. /// Non-native accounts may only be closed if its token amount is zero.
  172. ///
  173. /// Accounts expected by this instruction:
  174. ///
  175. /// * Single owner
  176. /// 0. `[writable]` The account to close.
  177. /// 1. '[writable]' The destination account.
  178. /// 2. `[signer]` The account's owner.
  179. ///
  180. /// * Multisignature owner
  181. /// 0. `[writable]` The account to close.
  182. /// 1. '[writable]' The destination account.
  183. /// 2. `[]` The account's multisignature owner.
  184. /// 3. ..3+M '[signer]' M signer accounts.
  185. CloseAccount,
  186. }
  187. impl TokenInstruction {
  188. /// Unpacks a byte buffer into a [TokenInstruction](enum.TokenInstruction.html).
  189. pub fn unpack(input: &[u8]) -> Result<Self, ProgramError> {
  190. if input.len() < size_of::<u8>() {
  191. return Err(TokenError::InvalidInstruction.into());
  192. }
  193. Ok(match input[0] {
  194. 0 => {
  195. if input.len() < size_of::<u8>() + size_of::<u64>() + size_of::<u8>() {
  196. return Err(TokenError::InvalidInstruction.into());
  197. }
  198. #[allow(clippy::cast_ptr_alignment)]
  199. let amount = unsafe { *(&input[size_of::<u8>()] as *const u8 as *const u64) };
  200. let decimals =
  201. unsafe { *(&input[size_of::<u8>() + size_of::<u64>()] as *const u8) };
  202. Self::InitializeMint { amount, decimals }
  203. }
  204. 1 => Self::InitializeAccount,
  205. 2 => {
  206. if input.len() < size_of::<u8>() + size_of::<u8>() {
  207. return Err(TokenError::InvalidInstruction.into());
  208. }
  209. #[allow(clippy::cast_ptr_alignment)]
  210. let m = unsafe { *(&input[1] as *const u8) };
  211. Self::InitializeMultisig { m }
  212. }
  213. 3 => {
  214. if input.len() < size_of::<u8>() + size_of::<u64>() {
  215. return Err(TokenError::InvalidInstruction.into());
  216. }
  217. #[allow(clippy::cast_ptr_alignment)]
  218. let amount = unsafe { *(&input[size_of::<u8>()] as *const u8 as *const u64) };
  219. Self::Transfer { amount }
  220. }
  221. 4 => {
  222. if input.len() < size_of::<u8>() + size_of::<u64>() {
  223. return Err(TokenError::InvalidInstruction.into());
  224. }
  225. #[allow(clippy::cast_ptr_alignment)]
  226. let amount = unsafe { *(&input[size_of::<u8>()] as *const u8 as *const u64) };
  227. Self::Approve { amount }
  228. }
  229. 5 => Self::Revoke,
  230. 6 => Self::SetOwner,
  231. 7 => {
  232. if input.len() < size_of::<u8>() + size_of::<u64>() {
  233. return Err(TokenError::InvalidInstruction.into());
  234. }
  235. #[allow(clippy::cast_ptr_alignment)]
  236. let amount = unsafe { *(&input[size_of::<u8>()] as *const u8 as *const u64) };
  237. Self::MintTo { amount }
  238. }
  239. 8 => {
  240. if input.len() < size_of::<u8>() + size_of::<u64>() {
  241. return Err(TokenError::InvalidInstruction.into());
  242. }
  243. #[allow(clippy::cast_ptr_alignment)]
  244. let amount = unsafe { *(&input[size_of::<u8>()] as *const u8 as *const u64) };
  245. Self::Burn { amount }
  246. }
  247. 9 => Self::CloseAccount,
  248. _ => return Err(TokenError::InvalidInstruction.into()),
  249. })
  250. }
  251. /// Packs a [TokenInstruction](enum.TokenInstruction.html) into a byte buffer.
  252. pub fn pack(self: &Self) -> Result<Vec<u8>, ProgramError> {
  253. let mut output = vec![0u8; size_of::<TokenInstruction>()];
  254. match self {
  255. Self::InitializeMint { amount, decimals } => {
  256. output[0] = 0;
  257. #[allow(clippy::cast_ptr_alignment)]
  258. let value = unsafe { &mut *(&mut output[size_of::<u8>()] as *mut u8 as *mut u64) };
  259. *value = *amount;
  260. let value =
  261. unsafe { &mut *(&mut output[size_of::<u8>() + size_of::<u64>()] as *mut u8) };
  262. *value = *decimals;
  263. }
  264. Self::InitializeAccount => output[0] = 1,
  265. Self::InitializeMultisig { m } => {
  266. output[0] = 2;
  267. #[allow(clippy::cast_ptr_alignment)]
  268. let value = unsafe { &mut *(&mut output[size_of::<u8>()] as *mut u8 as *mut u8) };
  269. *value = *m;
  270. }
  271. Self::Transfer { amount } => {
  272. output[0] = 3;
  273. #[allow(clippy::cast_ptr_alignment)]
  274. let value = unsafe { &mut *(&mut output[size_of::<u8>()] as *mut u8 as *mut u64) };
  275. *value = *amount;
  276. }
  277. Self::Approve { amount } => {
  278. output[0] = 4;
  279. #[allow(clippy::cast_ptr_alignment)]
  280. let value = unsafe { &mut *(&mut output[size_of::<u8>()] as *mut u8 as *mut u64) };
  281. *value = *amount;
  282. }
  283. Self::Revoke => output[0] = 5,
  284. Self::SetOwner => output[0] = 6,
  285. Self::MintTo { amount } => {
  286. output[0] = 7;
  287. #[allow(clippy::cast_ptr_alignment)]
  288. let value = unsafe { &mut *(&mut output[size_of::<u8>()] as *mut u8 as *mut u64) };
  289. *value = *amount;
  290. }
  291. Self::Burn { amount } => {
  292. output[0] = 8;
  293. #[allow(clippy::cast_ptr_alignment)]
  294. let value = unsafe { &mut *(&mut output[size_of::<u8>()] as *mut u8 as *mut u64) };
  295. *value = *amount;
  296. }
  297. Self::CloseAccount => output[0] = 9,
  298. }
  299. Ok(output)
  300. }
  301. }
  302. /// Creates a 'InitializeMint' instruction.
  303. pub fn initialize_mint(
  304. token_program_id: &Pubkey,
  305. mint_pubkey: &Pubkey,
  306. account_pubkey: Option<&Pubkey>,
  307. owner_pubkey: Option<&Pubkey>,
  308. amount: u64,
  309. decimals: u8,
  310. ) -> Result<Instruction, ProgramError> {
  311. let data = TokenInstruction::InitializeMint { amount, decimals }.pack()?;
  312. let mut accounts = vec![AccountMeta::new(*mint_pubkey, false)];
  313. if amount != 0 {
  314. match account_pubkey {
  315. Some(pubkey) => accounts.push(AccountMeta::new(*pubkey, false)),
  316. None => {
  317. return Err(ProgramError::NotEnoughAccountKeys);
  318. }
  319. }
  320. }
  321. match owner_pubkey {
  322. Some(pubkey) => accounts.push(AccountMeta::new_readonly(*pubkey, false)),
  323. None => {
  324. if amount == 0 {
  325. return Err(TokenError::OwnerRequiredIfNoInitialSupply.into());
  326. }
  327. }
  328. }
  329. Ok(Instruction {
  330. program_id: *token_program_id,
  331. accounts,
  332. data,
  333. })
  334. }
  335. /// Creates a `InitializeAccount` instruction.
  336. pub fn initialize_account(
  337. token_program_id: &Pubkey,
  338. account_pubkey: &Pubkey,
  339. mint_pubkey: &Pubkey,
  340. owner_pubkey: &Pubkey,
  341. ) -> Result<Instruction, ProgramError> {
  342. let data = TokenInstruction::InitializeAccount.pack()?;
  343. let accounts = vec![
  344. AccountMeta::new(*account_pubkey, false),
  345. AccountMeta::new_readonly(*mint_pubkey, false),
  346. AccountMeta::new_readonly(*owner_pubkey, false),
  347. ];
  348. Ok(Instruction {
  349. program_id: *token_program_id,
  350. accounts,
  351. data,
  352. })
  353. }
  354. /// Creates a `InitializeMultisig` instruction.
  355. pub fn initialize_multisig(
  356. token_program_id: &Pubkey,
  357. multisig_pubkey: &Pubkey,
  358. signer_pubkeys: &[&Pubkey],
  359. m: u8,
  360. ) -> Result<Instruction, ProgramError> {
  361. if !is_valid_signer_index(m as usize)
  362. || !is_valid_signer_index(signer_pubkeys.len())
  363. || m as usize > signer_pubkeys.len()
  364. {
  365. return Err(ProgramError::MissingRequiredSignature);
  366. }
  367. let data = TokenInstruction::InitializeMultisig { m }.pack()?;
  368. let mut accounts = Vec::with_capacity(1 + signer_pubkeys.len());
  369. accounts.push(AccountMeta::new(*multisig_pubkey, false));
  370. for signer_pubkey in signer_pubkeys.iter() {
  371. accounts.push(AccountMeta::new_readonly(**signer_pubkey, false));
  372. }
  373. Ok(Instruction {
  374. program_id: *token_program_id,
  375. accounts,
  376. data,
  377. })
  378. }
  379. /// Creates a `Transfer` instruction.
  380. pub fn transfer(
  381. token_program_id: &Pubkey,
  382. source_pubkey: &Pubkey,
  383. destination_pubkey: &Pubkey,
  384. authority_pubkey: &Pubkey,
  385. signer_pubkeys: &[&Pubkey],
  386. amount: u64,
  387. ) -> Result<Instruction, ProgramError> {
  388. let data = TokenInstruction::Transfer { amount }.pack()?;
  389. let mut accounts = Vec::with_capacity(3 + signer_pubkeys.len());
  390. accounts.push(AccountMeta::new(*source_pubkey, false));
  391. accounts.push(AccountMeta::new(*destination_pubkey, false));
  392. accounts.push(AccountMeta::new_readonly(
  393. *authority_pubkey,
  394. signer_pubkeys.is_empty(),
  395. ));
  396. for signer_pubkey in signer_pubkeys.iter() {
  397. accounts.push(AccountMeta::new(**signer_pubkey, true));
  398. }
  399. Ok(Instruction {
  400. program_id: *token_program_id,
  401. accounts,
  402. data,
  403. })
  404. }
  405. /// Creates an `Approve` instruction.
  406. pub fn approve(
  407. token_program_id: &Pubkey,
  408. source_pubkey: &Pubkey,
  409. delegate_pubkey: &Pubkey,
  410. owner_pubkey: &Pubkey,
  411. signer_pubkeys: &[&Pubkey],
  412. amount: u64,
  413. ) -> Result<Instruction, ProgramError> {
  414. let data = TokenInstruction::Approve { amount }.pack()?;
  415. let mut accounts = Vec::with_capacity(3 + signer_pubkeys.len());
  416. accounts.push(AccountMeta::new(*source_pubkey, false));
  417. accounts.push(AccountMeta::new_readonly(*delegate_pubkey, false));
  418. accounts.push(AccountMeta::new_readonly(
  419. *owner_pubkey,
  420. signer_pubkeys.is_empty(),
  421. ));
  422. for signer_pubkey in signer_pubkeys.iter() {
  423. accounts.push(AccountMeta::new(**signer_pubkey, true));
  424. }
  425. Ok(Instruction {
  426. program_id: *token_program_id,
  427. accounts,
  428. data,
  429. })
  430. }
  431. /// Creates a `Revoke` instruction.
  432. pub fn revoke(
  433. token_program_id: &Pubkey,
  434. source_pubkey: &Pubkey,
  435. owner_pubkey: &Pubkey,
  436. signer_pubkeys: &[&Pubkey],
  437. ) -> Result<Instruction, ProgramError> {
  438. let data = TokenInstruction::Revoke.pack()?;
  439. let mut accounts = Vec::with_capacity(2 + signer_pubkeys.len());
  440. accounts.push(AccountMeta::new_readonly(*source_pubkey, false));
  441. accounts.push(AccountMeta::new_readonly(
  442. *owner_pubkey,
  443. signer_pubkeys.is_empty(),
  444. ));
  445. for signer_pubkey in signer_pubkeys.iter() {
  446. accounts.push(AccountMeta::new(**signer_pubkey, true));
  447. }
  448. Ok(Instruction {
  449. program_id: *token_program_id,
  450. accounts,
  451. data,
  452. })
  453. }
  454. /// Creates a `SetOwner` instruction.
  455. pub fn set_owner(
  456. token_program_id: &Pubkey,
  457. owned_pubkey: &Pubkey,
  458. new_owner_pubkey: &Pubkey,
  459. owner_pubkey: &Pubkey,
  460. signer_pubkeys: &[&Pubkey],
  461. ) -> Result<Instruction, ProgramError> {
  462. let data = TokenInstruction::SetOwner.pack()?;
  463. let mut accounts = Vec::with_capacity(3 + signer_pubkeys.len());
  464. accounts.push(AccountMeta::new(*owned_pubkey, false));
  465. accounts.push(AccountMeta::new_readonly(*new_owner_pubkey, false));
  466. accounts.push(AccountMeta::new_readonly(
  467. *owner_pubkey,
  468. signer_pubkeys.is_empty(),
  469. ));
  470. for signer_pubkey in signer_pubkeys.iter() {
  471. accounts.push(AccountMeta::new(**signer_pubkey, true));
  472. }
  473. Ok(Instruction {
  474. program_id: *token_program_id,
  475. accounts,
  476. data,
  477. })
  478. }
  479. /// Creates a `MintTo` instruction.
  480. pub fn mint_to(
  481. token_program_id: &Pubkey,
  482. mint_pubkey: &Pubkey,
  483. account_pubkey: &Pubkey,
  484. owner_pubkey: &Pubkey,
  485. signer_pubkeys: &[&Pubkey],
  486. amount: u64,
  487. ) -> Result<Instruction, ProgramError> {
  488. let data = TokenInstruction::MintTo { amount }.pack()?;
  489. let mut accounts = Vec::with_capacity(3 + signer_pubkeys.len());
  490. accounts.push(AccountMeta::new(*mint_pubkey, false));
  491. accounts.push(AccountMeta::new(*account_pubkey, false));
  492. accounts.push(AccountMeta::new_readonly(
  493. *owner_pubkey,
  494. signer_pubkeys.is_empty(),
  495. ));
  496. for signer_pubkey in signer_pubkeys.iter() {
  497. accounts.push(AccountMeta::new(**signer_pubkey, true));
  498. }
  499. Ok(Instruction {
  500. program_id: *token_program_id,
  501. accounts,
  502. data,
  503. })
  504. }
  505. /// Creates a `Burn` instruction.
  506. pub fn burn(
  507. token_program_id: &Pubkey,
  508. account_pubkey: &Pubkey,
  509. authority_pubkey: &Pubkey,
  510. signer_pubkeys: &[&Pubkey],
  511. amount: u64,
  512. ) -> Result<Instruction, ProgramError> {
  513. let data = TokenInstruction::Burn { amount }.pack()?;
  514. let mut accounts = Vec::with_capacity(2 + signer_pubkeys.len());
  515. accounts.push(AccountMeta::new(*account_pubkey, false));
  516. accounts.push(AccountMeta::new_readonly(
  517. *authority_pubkey,
  518. signer_pubkeys.is_empty(),
  519. ));
  520. for signer_pubkey in signer_pubkeys.iter() {
  521. accounts.push(AccountMeta::new(**signer_pubkey, true));
  522. }
  523. Ok(Instruction {
  524. program_id: *token_program_id,
  525. accounts,
  526. data,
  527. })
  528. }
  529. /// Creates a `CloseAccount` instruction.
  530. pub fn close_account(
  531. token_program_id: &Pubkey,
  532. account_pubkey: &Pubkey,
  533. destination_pubkey: &Pubkey,
  534. owner_pubkey: &Pubkey,
  535. signer_pubkeys: &[&Pubkey],
  536. ) -> Result<Instruction, ProgramError> {
  537. let data = TokenInstruction::CloseAccount.pack()?;
  538. let mut accounts = Vec::with_capacity(3 + signer_pubkeys.len());
  539. accounts.push(AccountMeta::new(*account_pubkey, false));
  540. accounts.push(AccountMeta::new(*destination_pubkey, false));
  541. accounts.push(AccountMeta::new_readonly(
  542. *owner_pubkey,
  543. signer_pubkeys.is_empty(),
  544. ));
  545. for signer_pubkey in signer_pubkeys.iter() {
  546. accounts.push(AccountMeta::new(**signer_pubkey, true));
  547. }
  548. Ok(Instruction {
  549. program_id: *token_program_id,
  550. accounts,
  551. data,
  552. })
  553. }
  554. /// Utility function that checks index is between MIN_SIGNERS and MAX_SIGNERS
  555. pub fn is_valid_signer_index(index: usize) -> bool {
  556. !(index < MIN_SIGNERS || index > MAX_SIGNERS)
  557. }