Skip to content

Commit a4b751c

Browse files
spl: Add withdraw_withheld_tokens_from_accounts instruction (#3128)
Co-authored-by: acheron <[email protected]>
1 parent c5337c5 commit a4b751c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The minor version will be incremented upon a breaking change and the patch versi
1212

1313
### Features
1414

15+
- spl: Implemented `withdrawWithheldTokensFromAccounts` instruction ([#3128]([https://github.com/coral-xyz/anchor/pull/3128)).
1516
- ts: Add optional `commitment` parameter to `Program.addEventListener` ([#3052](https://github.com/coral-xyz/anchor/pull/3052)).
1617
- cli, idl: Pass `cargo` args to IDL generation when building program or IDL ([#3059](https://github.com/coral-xyz/anchor/pull/3059)).
1718
- cli: Add checks for incorrect usage of `idl-build` feature ([#3061](https://github.com/coral-xyz/anchor/pull/3061)).

spl/src/token_2022_extensions/transfer_fee.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,36 @@ pub struct WithdrawWithheldTokensFromMint<'info> {
158158
pub destination: AccountInfo<'info>,
159159
pub authority: AccountInfo<'info>,
160160
}
161+
162+
pub fn withdraw_withheld_tokens_from_accounts<'info>(
163+
ctx: CpiContext<'_, '_, '_, 'info, WithdrawWithheldTokensFromAccounts<'info>>,
164+
sources: Vec<AccountInfo<'info>>,
165+
) -> Result<()> {
166+
let ix = spl_token_2022::extension::transfer_fee::instruction::withdraw_withheld_tokens_from_accounts(
167+
ctx.accounts.token_program_id.key,
168+
ctx.accounts.mint.key,
169+
ctx.accounts.destination.key,
170+
ctx.accounts.authority.key,
171+
&[],
172+
sources.iter().map(|a| a.key).collect::<Vec<_>>().as_slice(),
173+
)?;
174+
175+
let mut account_infos = vec![
176+
ctx.accounts.token_program_id,
177+
ctx.accounts.mint,
178+
ctx.accounts.destination,
179+
ctx.accounts.authority,
180+
];
181+
account_infos.extend_from_slice(&sources);
182+
183+
anchor_lang::solana_program::program::invoke_signed(&ix, &account_infos, ctx.signer_seeds)
184+
.map_err(Into::into)
185+
}
186+
187+
#[derive(Accounts)]
188+
pub struct WithdrawWithheldTokensFromAccounts<'info> {
189+
pub token_program_id: AccountInfo<'info>,
190+
pub mint: AccountInfo<'info>,
191+
pub destination: AccountInfo<'info>,
192+
pub authority: AccountInfo<'info>,
193+
}

0 commit comments

Comments
 (0)