From db0e0cbc00dc62f65624e736b33d1b4eae2e3a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= Date: Sun, 28 Jul 2024 15:14:54 +0800 Subject: [PATCH 1/6] Added WithdrawWithheldTokensFromAccounts IX --- spl/src/token_2022_extensions/transfer_fee.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spl/src/token_2022_extensions/transfer_fee.rs b/spl/src/token_2022_extensions/transfer_fee.rs index e68926c2e8..a5f0999bb6 100644 --- a/spl/src/token_2022_extensions/transfer_fee.rs +++ b/spl/src/token_2022_extensions/transfer_fee.rs @@ -158,3 +158,32 @@ pub struct WithdrawWithheldTokensFromMint<'info> { pub destination: AccountInfo<'info>, pub authority: AccountInfo<'info>, } + + +pub fn withdraw_withheld_tokens_from_accounts<'info>( + ctx: CpiContext<'_, '_, '_, 'info, WithdrawWithheldTokensFromAccounts<'info>>, + sources: Vec>, +) -> Result<()> { + let ix = spl_token_2022::extension::transfer_fee::instruction::withdraw_withheld_tokens_from_accounts( + ctx.accounts.token_program_id.key, + ctx.accounts.mint.key, + ctx.accounts.destination.key, + ctx.accounts.authority.key, + &[], + sources.iter().map(|a| a.key).collect::>().as_slice(), + )?; + + let mut account_infos = vec![ctx.accounts.token_program_id, ctx.accounts.mint, ctx.accounts.destination, ctx.accounts.authority]; + account_infos.extend_from_slice(&sources); + + anchor_lang::solana_program::program::invoke_signed(&ix, &account_infos, ctx.signer_seeds) + .map_err(Into::into) +} + +#[derive(Accounts)] +pub struct WithdrawWithheldTokensFromAccounts<'info> { + pub token_program_id: AccountInfo<'info>, + pub mint: AccountInfo<'info>, + pub destination: AccountInfo<'info>, + pub authority: AccountInfo<'info>, +} \ No newline at end of file From b2f60a581e5fe533e0344f64819bee93dd02e794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Sun, 28 Jul 2024 16:46:42 +0800 Subject: [PATCH 2/6] Update CHANGELOG.md Added Changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e22b2dc27e..435f26e086 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 The minor version will be incremented upon a breaking change and the patch version will be incremented for features. ## [Unreleased] +- spl: Implemented `withdrawWithheldTokensFromAccounts` instruction ([#3128]([https://github.com/coral-xyz/anchor/pull/3128)). ### Features From e84398959f782bdc41e80df48c41694ad6b41e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= Date: Sun, 28 Jul 2024 15:14:54 +0800 Subject: [PATCH 3/6] Added WithdrawWithheldTokensFromAccounts IX --- spl/src/token_2022_extensions/transfer_fee.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spl/src/token_2022_extensions/transfer_fee.rs b/spl/src/token_2022_extensions/transfer_fee.rs index e68926c2e8..a5f0999bb6 100644 --- a/spl/src/token_2022_extensions/transfer_fee.rs +++ b/spl/src/token_2022_extensions/transfer_fee.rs @@ -158,3 +158,32 @@ pub struct WithdrawWithheldTokensFromMint<'info> { pub destination: AccountInfo<'info>, pub authority: AccountInfo<'info>, } + + +pub fn withdraw_withheld_tokens_from_accounts<'info>( + ctx: CpiContext<'_, '_, '_, 'info, WithdrawWithheldTokensFromAccounts<'info>>, + sources: Vec>, +) -> Result<()> { + let ix = spl_token_2022::extension::transfer_fee::instruction::withdraw_withheld_tokens_from_accounts( + ctx.accounts.token_program_id.key, + ctx.accounts.mint.key, + ctx.accounts.destination.key, + ctx.accounts.authority.key, + &[], + sources.iter().map(|a| a.key).collect::>().as_slice(), + )?; + + let mut account_infos = vec![ctx.accounts.token_program_id, ctx.accounts.mint, ctx.accounts.destination, ctx.accounts.authority]; + account_infos.extend_from_slice(&sources); + + anchor_lang::solana_program::program::invoke_signed(&ix, &account_infos, ctx.signer_seeds) + .map_err(Into::into) +} + +#[derive(Accounts)] +pub struct WithdrawWithheldTokensFromAccounts<'info> { + pub token_program_id: AccountInfo<'info>, + pub mint: AccountInfo<'info>, + pub destination: AccountInfo<'info>, + pub authority: AccountInfo<'info>, +} \ No newline at end of file From e1431ac00cf58d8f4beb249d1cb75afa3e7ee739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Sun, 28 Jul 2024 16:46:42 +0800 Subject: [PATCH 4/6] Update CHANGELOG.md Added Changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcab69a022..73e4958937 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 The minor version will be incremented upon a breaking change and the patch version will be incremented for features. ## [Unreleased] +- spl: Implemented `withdrawWithheldTokensFromAccounts` instruction ([#3128]([https://github.com/coral-xyz/anchor/pull/3128)). ### Features From 9455ab03579d2168f67b139c345f82b6029362df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= Date: Mon, 29 Jul 2024 00:37:21 +0800 Subject: [PATCH 5/6] Rebased from master --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73e4958937..e6b15c769b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 The minor version will be incremented upon a breaking change and the patch version will be incremented for features. ## [Unreleased] -- spl: Implemented `withdrawWithheldTokensFromAccounts` instruction ([#3128]([https://github.com/coral-xyz/anchor/pull/3128)). ### Features +- spl: Implemented `withdrawWithheldTokensFromAccounts` instruction ([#3128]([https://github.com/coral-xyz/anchor/pull/3128)). - ts: Add optional `commitment` parameter to `Program.addEventListener` ([#3052](https://github.com/coral-xyz/anchor/pull/3052)). - cli, idl: Pass `cargo` args to IDL generation when building program or IDL ([#3059](https://github.com/coral-xyz/anchor/pull/3059)). - cli: Add checks for incorrect usage of `idl-build` feature ([#3061](https://github.com/coral-xyz/anchor/pull/3061)). From a178359b9b9ea4cb650b69f29d32191e43a723ec Mon Sep 17 00:00:00 2001 From: acheron <98934430+acheroncrypto@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:12:46 +0200 Subject: [PATCH 6/6] Fix formatting --- spl/src/token_2022_extensions/transfer_fee.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spl/src/token_2022_extensions/transfer_fee.rs b/spl/src/token_2022_extensions/transfer_fee.rs index a5f0999bb6..708d905d30 100644 --- a/spl/src/token_2022_extensions/transfer_fee.rs +++ b/spl/src/token_2022_extensions/transfer_fee.rs @@ -159,7 +159,6 @@ pub struct WithdrawWithheldTokensFromMint<'info> { pub authority: AccountInfo<'info>, } - pub fn withdraw_withheld_tokens_from_accounts<'info>( ctx: CpiContext<'_, '_, '_, 'info, WithdrawWithheldTokensFromAccounts<'info>>, sources: Vec>, @@ -173,7 +172,12 @@ pub fn withdraw_withheld_tokens_from_accounts<'info>( sources.iter().map(|a| a.key).collect::>().as_slice(), )?; - let mut account_infos = vec![ctx.accounts.token_program_id, ctx.accounts.mint, ctx.accounts.destination, ctx.accounts.authority]; + let mut account_infos = vec![ + ctx.accounts.token_program_id, + ctx.accounts.mint, + ctx.accounts.destination, + ctx.accounts.authority, + ]; account_infos.extend_from_slice(&sources); anchor_lang::solana_program::program::invoke_signed(&ix, &account_infos, ctx.signer_seeds) @@ -186,4 +190,4 @@ pub struct WithdrawWithheldTokensFromAccounts<'info> { pub mint: AccountInfo<'info>, pub destination: AccountInfo<'info>, pub authority: AccountInfo<'info>, -} \ No newline at end of file +}