|
7 | 7 |
|
8 | 8 | const SYSTEM_PROGRAM_ID: Pubkey = Pubkey::from_str_const("11111111111111111111111111111111"); |
9 | 9 |
|
| 10 | +#[cfg(feature = "borsh")] |
| 11 | +use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; |
| 12 | + |
| 13 | +/// Instructions supported by the `AssociatedTokenAccount` program |
| 14 | +#[derive(Clone, Debug, PartialEq)] |
| 15 | +#[cfg_attr( |
| 16 | + feature = "borsh", |
| 17 | + derive(BorshDeserialize, BorshSerialize, BorshSchema) |
| 18 | +)] |
| 19 | +pub enum AssociatedTokenAccountInstruction { |
| 20 | + /// Creates an associated token account for the given wallet address and |
| 21 | + /// token mint Returns an error if the account exists. |
| 22 | + /// |
| 23 | + /// 0. `[writeable,signer]` Funding account (must be a system account) |
| 24 | + /// 1. `[writeable]` Associated token account address to be created |
| 25 | + /// 2. `[]` Wallet address for the new associated token account |
| 26 | + /// 3. `[]` The token mint for the new associated token account |
| 27 | + /// 4. `[]` System program |
| 28 | + /// 5. `[]` SPL Token program |
| 29 | + Create, |
| 30 | + /// Creates an associated token account for the given wallet address and |
| 31 | + /// token mint, if it doesn't already exist. Returns an error if the |
| 32 | + /// account exists, but with a different owner. |
| 33 | + /// |
| 34 | + /// 0. `[writeable,signer]` Funding account (must be a system account) |
| 35 | + /// 1. `[writeable]` Associated token account address to be created |
| 36 | + /// 2. `[]` Wallet address for the new associated token account |
| 37 | + /// 3. `[]` The token mint for the new associated token account |
| 38 | + /// 4. `[]` System program |
| 39 | + /// 5. `[]` SPL Token program |
| 40 | + CreateIdempotent, |
| 41 | + /// Transfers from and closes a nested associated token account: an |
| 42 | + /// associated token account owned by an associated token account. |
| 43 | + /// |
| 44 | + /// The tokens are moved from the nested associated token account to the |
| 45 | + /// wallet's associated token account, and the nested account lamports are |
| 46 | + /// moved to the wallet. |
| 47 | + /// |
| 48 | + /// Note: Nested token accounts are an anti-pattern, and almost always |
| 49 | + /// created unintentionally, so this instruction should only be used to |
| 50 | + /// recover from errors. |
| 51 | + /// |
| 52 | + /// 0. `[writeable]` Nested associated token account, must be owned by `3` |
| 53 | + /// 1. `[]` Token mint for the nested associated token account |
| 54 | + /// 2. `[writeable]` Wallet's associated token account |
| 55 | + /// 3. `[]` Owner associated token account address, must be owned by `5` |
| 56 | + /// 4. `[]` Token mint for the owner associated token account |
| 57 | + /// 5. `[writeable, signer]` Wallet address for the owner associated token |
| 58 | + /// account |
| 59 | + /// 6. `[]` SPL Token program |
| 60 | + RecoverNested, |
| 61 | +} |
| 62 | + |
10 | 63 | fn build_associated_token_account_instruction( |
11 | 64 | funding_address: &Pubkey, |
12 | 65 | wallet_address: &Pubkey, |
|
0 commit comments