Allow Fallback for TokenTransferHookAccountDataNotFound in SPL Token JS #212
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.
To the Solana SDK Team,
We are the Fragmetric team, leveraging Token 2022 Transfer Hooks to improve transparency in yield distribution on De-Fi protocol. Our system tracks all transfer transactions using the transfer hook mechanism to adjust reward accrual efficiently.
1. Issue Overview
While integrating transfer hooks, we encountered a limitation in metadata resolution within SPL Token JS that prevents seamless transfers when the destination token account is missing.
How This Issue Arises
Our extra account meta references
destination_token_account.owner
to handle recipient-related updates.If the destination token account does not exist, SPL Token JS throws a
TokenTransferHookAccountDataNotFound
error (reference: https://github.com/solana-program/token-2022/blob/main/clients/js-legacy/src/extensions/transferHook/seeds.ts#L74).This means that while we can transfer to an already created ATA, if the ATA does not exist, we are forced to send two separate transactions:
While this is manageable operationally, it disrupts wallet integrations and end-user experience, making it impossible to handle transfers seamlessly in one atomic transaction.
A Possible Solution
We propose introducing a fallback mechanism in SPL Token JS to allow unresolved accounts to be replaced by a placeholder (such as PublicKey.default). This enables on-chain programs to handle missing accounts gracefully instead of outright failing.
2. Implementation Detail
To address this, we have implemented an optional flag:
When set to true, this allows unresolved extra accounts to fall back to
PublicKey.default
instead of failing withTokenTransferHookAccountDataNotFound
.Our implementation modifies
resolveExtraAccountMeta()
in SPL Token JS as follows:3. Why This Change Matters
This simple fallback mechanism does not break any existing on-chain use cases and does not affect transaction simulation results, but it expands the utility of transfer hooks in the following ways:
https://solana.stackexchange.com/questions/12797/transfer-hook-how-to-get-destination-ata-owner-public-key
4. Request
Would it be possible to merge this change into SPL Token JS or consider a similar fallback mechanism for handling missing accounts in transfer hooks? We believe this enhancement will greatly improve the flexibility of Token 2022 adoption, particularly in DeFi applications like us trying to resolve challenging problem utilizing token extensions.
Looking forward to your feedback!
Best,
Fragmetric Team