-
Notifications
You must be signed in to change notification settings - Fork 530
fix(abl-token): block wallets from sending, not just receiving #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NikkiAung
wants to merge
2
commits into
solana-foundation:main
Choose a base branch
from
NikkiAung:fix/abl-token-sender-block
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+397
−33
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...ook/allow-block-list-token/anchor/programs/abl-token/src/instructions/resize_meta_list.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| use anchor_lang::{ | ||
| prelude::*, solana_program::program::invoke, solana_program::system_instruction::transfer, | ||
| }; | ||
| use anchor_spl::{ | ||
| token_2022::Token2022, | ||
| token_interface::{transfer_hook_update, Mint, TransferHookUpdate}, | ||
| }; | ||
|
|
||
| use spl_tlv_account_resolution::state::ExtraAccountMetaList; | ||
| use spl_transfer_hook_interface::instruction::ExecuteInstruction; | ||
|
|
||
| use crate::{get_extra_account_metas, get_meta_list_size, META_LIST_ACCOUNT_SEED}; | ||
|
|
||
| /// Rewrites an existing mint's extra-metas account to the current | ||
| /// `get_extra_account_metas()` layout, reallocating it if the size changed. | ||
| /// | ||
| /// This exists because `extra_metas_account` is a fixed-size PDA created once | ||
| /// by `init_mint`/`attach_to_mint`: if the program's extra-account list is | ||
| /// ever extended (e.g. to add the source-wallet check), mints that were set | ||
| /// up under the old layout are left with a stale, undersized account and | ||
| /// their transfers start failing the hook's account-count check. Any mint | ||
| /// authority can call this to bring an existing mint's extra-metas account | ||
| /// back in sync after such an upgrade. | ||
| #[derive(Accounts)] | ||
| pub struct ResizeMetaList<'info> { | ||
| #[account(mut)] | ||
| pub payer: Signer<'info>, | ||
|
|
||
| #[account(mut, mint::token_program = token_program)] | ||
| pub mint: Box<InterfaceAccount<'info, Mint>>, | ||
|
|
||
| #[account( | ||
| mut, | ||
| seeds = [META_LIST_ACCOUNT_SEED, mint.key().as_ref()], | ||
| bump, | ||
| )] | ||
| /// CHECK: extra metas account | ||
| pub extra_metas_account: UncheckedAccount<'info>, | ||
|
|
||
| pub system_program: Program<'info, System>, | ||
|
|
||
| pub token_program: Program<'info, Token2022>, | ||
| } | ||
|
|
||
| impl ResizeMetaList<'_> { | ||
| pub fn resize_meta_list(&mut self) -> Result<()> { | ||
| // Re-setting the transfer hook to itself has no effect on the mint, | ||
| // but the CPI only succeeds if `payer` is the mint's current | ||
| // transfer-hook authority - the same check `attach_to_mint` relies | ||
| // on, reused here so this instruction can't be called by anyone | ||
| // other than whoever is already trusted to configure this mint's hook. | ||
| let tx_hook_accs = TransferHookUpdate { | ||
| token_program_id: self.token_program.to_account_info(), | ||
| mint: self.mint.to_account_info(), | ||
| authority: self.payer.to_account_info(), | ||
| }; | ||
| let ctx = CpiContext::new(self.token_program.key(), tx_hook_accs); | ||
| transfer_hook_update(ctx, Some(crate::ID_CONST))?; | ||
|
|
||
| let account_info = self.extra_metas_account.to_account_info(); | ||
| let new_size = get_meta_list_size()?; | ||
|
|
||
| let min_balance = Rent::get()?.minimum_balance(new_size); | ||
| if min_balance > account_info.lamports() { | ||
| invoke( | ||
| &transfer(&self.payer.key(), account_info.key, min_balance - account_info.lamports()), | ||
| &[self.payer.to_account_info(), account_info.clone(), self.system_program.to_account_info()], | ||
| )?; | ||
| } | ||
| account_info.resize(new_size)?; | ||
|
|
||
| let metas = get_extra_account_metas()?; | ||
| let mut data = account_info.try_borrow_mut_data()?; | ||
| ExtraAccountMetaList::update::<ExecuteInstruction>(&mut data, &metas) | ||
| .map_err(|_| ProgramError::InvalidAccountData)?; | ||
|
|
||
| Ok(()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If any mints retain metadata-list accounts initialized before this upgrade, those accounts still resolve only the destination wallet while the upgraded hook requires both wallet accounts, causing all transfers for those mints to fail. Both setup paths use
init, and there is no instruction to resize and rewrite an existing list.Knowledge Base Used: Tokens Directory Overview