Skip to content
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

solana: support tokens with transfer hooks #1

Closed
wants to merge 7 commits into from
Closed

Conversation

kcsongor
Copy link
Collaborator

@kcsongor kcsongor commented May 3, 2024

This PR adds support for token2022 tokens with transfer hooks. For more details on transfer hooks, see https://solana.com/developers/guides/token-extensions/transfer-hook.

At a high level, a transfer hook is a program that is called (by the token program) each time a transfer (of a token of a specific mint) is made. The key difficulty is that the transfer hook program may require additional accounts, which need to be propagated through the instruction.

This PR modifies the on-chain code to call the appropriate helper function that propagates the necessary accounts, and also the off-chain code (ts sdk) that derives these account addresses based on the on-chain schema standard that token2022 introduces for transfer hooks. The rust tests (cargo test-sbf) still test against the legacy spl token, while in this PR I modified the typescript tests to test against a token with a transfer hook. This way, both paths are tested appropriately.

There is a dummy transfer hook in the test that bumps a counter on each transfer, and has a dummy account seeded by the owner field of the sender token account, which is just used to test that the account information is properly propagated.

Adding this was the motivation for wormhole-foundation#391, because the on-chain helper code is simply completely unusable (broken) in earlier sdk versions.

ABI changes

Breaking changes

This change is breaking, so it warrants a major ABI version upgrade (bumped the version to 2.0.0). This is because we now have to perform an extra transfer when burning and minting tokens in order to trigger any transfer hooks. This extra transfer in turn requires some additional accounts -- refer to the documentation in the transfer_burn and release_inbound_mint functions for more details.

New features

Also added an extra set of instructions to programmatically create/manage address lookup tables. These were necessary to add extra transaction size headroom for transfer hooks to be triggered. Without a lookup table, a transfer hook could use up to 2 custom accounts, but now there is space for 15+. See the documentation in lut.rs for more details.

(note: this PR is a copy of wormhole-foundation#404)

@kcsongor kcsongor closed this May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant