recoverNested static method
Transfers from and closes a nested associated token account: an associated token account owned by an associated token account.
The tokens are moved from the nested associated token account to the wallet's associated token account, and the nested account lamports are moved to the wallet.
Note: Nested token accounts are an anti-pattern, and almost always created unintentionally, so this instruction should only be used to recover from errors.
Keys:
[w]
nestedAssociatedTokenAccount
- Nested associated token account, must be owned by[associatedTokenAccount]
.[]
nestedAssociatedTokenMint
- Token mint for the nested associated token account.[w]
nestedAssociatedTokenAccountOwner
- Wallet's associated token account.[]
associatedTokenAccount
- Owner associated token account address, must be owned by[associatedTokenAccountOwner]
.[]
associatedTokenMint
- Token mint for the owner associated token account.[w,s]
associatedTokenAccountOwner
- Wallet address for the owner associated token account.
Implementation
static TransactionInstruction recoverNested({
required final Pubkey nestedAssociatedTokenAccount,
required final Pubkey nestedAssociatedTokenMint,
required final Pubkey nestedAssociatedTokenAccountOwner,
required final Pubkey associatedTokenAccount,
required final Pubkey associatedTokenMint,
required final Pubkey associatedTokenAccountOwner,
}) {
// 0. `[w]` Nested associated token account, must be owned by `3`
// 1. `[]` Token mint for the nested associated token account
// 2. `[w]` Wallet's associated token account
// 3. `[]` Owner associated token account address, must be owned by `5`
// 4. `[]` Token mint for the owner associated token account
// 5. `[w,s]` Wallet address for the owner associated token account
// 6. `[]` SPL Token program
final List<AccountMeta> keys = [
AccountMeta.writable(nestedAssociatedTokenAccount),
AccountMeta(nestedAssociatedTokenMint),
AccountMeta.writable(nestedAssociatedTokenAccountOwner),
AccountMeta(associatedTokenAccount),
AccountMeta(associatedTokenMint),
AccountMeta.signerAndWritable(associatedTokenAccountOwner),
AccountMeta(TokenProgram.programId),
];
return _instance.createTransactionIntruction(
AssociatedTokenInstruction.recoverNested,
keys: keys,
);
}