Transfer-Hook Interface
Example program
Here is an example program that only implements the required "execute" instruction, assuming that the proper account data is already written to the appropriate program-derived address defined by the interface.
use ;
Motivation
Token creators may need more control over transfers of their token. The most prominent use case revolves around NFT royalties. Whenever a token is moved, the creator should be entitled to royalties, but due to the design of the current token program, it's impossible to stop a transfer at the protocol level.
Current solutions typically resort to perpetually freezing tokens, which requires a whole proxy layer to interact with the token. Wallets and marketplaces need to be aware of the proxy layer in order to properly use the token.
Worse still, different royalty systems have different proxy layers for using their token. All in all, these systems harm composability and make development harder.
Solution
To give more flexibility to token creators and improve the situation for everyone,
spl-transfer-hook-interface introduces the concept of an interface integrated
with spl-token-2022. A token creator must develop and deploy a program that
implements the interface and then configure their token mint to use their program.
During transfer, token-2022 calls into the program with the accounts specified at a well-defined program-derived address for that mint and program id. This call happens after all other transfer logic, so the accounts reflect the end state of the transfer.
A developer must implement the Execute instruction, and the
InitializeExtraAccountMetas instruction to write the required additional account
pubkeys into the program-derived address defined by the mint and program id.
Side note: it's technically not required to implement InitializeExtraAccountMetas
at that instruction descriminator. Your program may implement multiple interfaces,
so any other instruction in your program can create the account at the program-derived
address!
This library provides offchain and onchain helpers for resolving the additional accounts required. See invoke.rs for usage on-chain, and offchain.rs for fetching the additional required account metas.