Skip to content

tiago18c/pblock-list

Repository files navigation

Block List

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).

Operation Mode

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

Accounts

Config

  • Defines the block list authority.
  • Tracks the number of blocked wallets.

WalletBlock

  • Defines a wallet as blocked

Instructions

init

Initializes the global Config account with a given authority to control the block list.

block_wallet

Adds a given wallet address to the blocked wallets. This creates a WalletBlock reccord account.

unblock_wallet

Removes a given wallet address from the blocked wallets. This removes a WalletBlock reccord account.

setup_extra_metas

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.

tx_hook

The hook that is executed during token transfers.

Repo contents

Smart Contract

A pinocchio based Block List smart contract under the program folder.

SDKs

Codama generated rust and ts SDKs.

CLI

A rust CLI to interact with the contract.

Building

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

Setup

Block List

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>

Token Mint

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>

Devnet deployment

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).

DISCLAIMER

THIS CODE IS NOT AUDITED NOR REVIEWED. USE AT YOUR OWN DISCRETION.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published