This is a Block List program that implements the Token2022 Transfer-hook execute instruction. It allows a centralized authority to defined a block list - a collection of wallets that are blocked. Token issuers (transfer-hook extension authorities), can then setup this program as the hook to be used and choose an operation mode (either filter source wallet, or both source and destination).
The Block list has different operation modes depending whether the block list is empty or not and the issuer choice. These modes are achieved by building a different extra-account-metas
account for the token mint (see setup_extra_metas
bellow). When the list gets the first blocked wallet, the issuer needs to re-set the extra-account-metas
.
The modes are the following:
- Empty extra metas - default behaviour when config account counter is 0
- Check Source - default behaviour when config account counter is above 0
- Check both source and destination - optional behaviour when config account counter is above 0
- Defines the block list authority.
- Tracks the number of blocked wallets.
- Defines a wallet as blocked
Initializes the global Config
account with a given authority to control the block list.
Adds a given wallet address to the blocked wallets. This creates a WalletBlock
reccord account.
Removes a given wallet address from the blocked wallets. This removes a WalletBlock
reccord account.
Sets up the extra-account-metas
account dependency for the Transfer-Hook extension. Receives an optional bool value to switch operation modes when the blocked wallet counter is non zero.
Note: once wallets are added to the block list, the issuer needs to call this method again to setup one of the blocking modes.
The hook that is executed during token transfers.
A pinocchio based Block List smart contract under the program folder.
Codama generated rust and ts SDKs.
A rust CLI to interact with the contract.
First install dependencies:
pnpm install
To build the smart contract:
cd program
cargo build-sbf
To deploy the smart contract:
solana program deploy --program-id <your_program_keypair.json> target/deploy/block_list.so
To generate the SDKs:
pnpm run generate-sdks
To build the CLI:
cd cli
cargo build
Initialize the block list and defined the authority:
target/debug/block-list-cli init
Add a wallet to the block list:
target/debug/block-list-cli block-wallet <wallet_address>
Remove a wallet from the block list:
target/debug/block-list-cli unblock-wallet <wallet_address>
Initialize a new token mint:
spl-token create-token --program-2022 --transfer-hook BLoCKLSG2qMQ9YxEyrrKKAQzthvW4Lu8Eyv74axF6mf
Initialize the extra account metas:
target/debug/block-list-cli setup-extra-metas <wallet_address>
Change the extra account metas to filter both source and destination token account wallets:
target/debug/block-list-cli setup-extra-metas --check-both-wallets <wallet_address>
Smart contract was deployed to devnet at address BLoCKLSG2qMQ9YxEyrrKKAQzthvW4Lu8Eyv74axF6mf
.
Test transfer with empty block list here.
Test transfer with non empty block list only checking source TA here.
Test transfer with non empty block list checking both source and destination TAs here.
Simulated transaction that fails due to destination TA owner being blocked here (press simulate to see logs).
Simulated transaction that fails due to source TA owner being blocked here (press simulate to see logs).
THIS CODE IS NOT AUDITED NOR REVIEWED. USE AT YOUR OWN DISCRETION.