feat(program): publish transfer context for Token-2022 transfer hooks - #244
Open
dev-jodee wants to merge 1 commit into
Open
feat(program): publish transfer context for Token-2022 transfer hooks#244dev-jodee wants to merge 1 commit into
dev-jodee wants to merge 1 commit into
Conversation
Token-2022 only forwards the accounts an ExtraAccountMetaList can resolve, and none of the resolver's seed sources identify the delegate pulling from a user. A hook therefore sees the SubscriptionAuthority PDA as the transfer authority and nothing about who initiated the pull, which makes per-delegate policy unenforceable. Pulls against a mint with an active transfer hook now create a TransferContext PDA at ["TransferContext", subscription_authority], record the initiator, delegation, mint, amount and slot, and close it once the transfer CPI returns. Hooks resolve it as an external PDA and can seed their own policy accounts on its contents. Mints without a hook, and hooks that do not ask for the context, are unaffected.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Compute Unit Report
🔺 increase · 🔻 decrease · – unchanged · 🆕 new · 🗑 removed (vs Generated: 2026-08-25 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
TransferContextPDA at["TransferContext", subscription_authority], record the initiator, delegation, kind, mint, amount and slot, and close it after theTransferCheckedCPI. Rent round-trips through the initiator inside the transaction.Literal("TransferContext") + AccountKey(3)) and can seed their own policy accounts on its contents, e.g. an allowlist PDA over the initiator bytes at offset 3. Without this,spl-transfer-hook-interfaceforwards only accounts the validation list can resolve, and no seed source identifies the delegate.transferFixed/transferRecurring/transferSubscription, feeding the resolver the bytes the program is about to write since the account can't be fetched before it exists.docs/005-transfer-context.md.Closes TOO-671.
Test Plan
just unit-test— 59 passing.cargo test -p tests-subscriptions— 282 passing, 8 new intest_transfer_context.rs: allowlisted initiator pulls, blocked initiator rejected inside the hook, context closed and rent refunded, context omitted fails closed at resolution, prefunded context address still creates, recurring and subscription paths screened on their own initiator.pnpm vitest run test/transfer-context.test.ts— address derivation and initiator offset match the on-chain layout.just checkclean.Notes
find_program_addressplus the create CPI. Passing the bump in instruction data would trim it if it ever matters.slotis unknown client-side and encoded as zero in the pending bytes, so hook seeds overslotcan't be resolved off-chain.