-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
transfer hook: add new offchain helper #6099
transfer hook: add new offchain helper #6099
Conversation
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
21f958e
to
15ddbc8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just a few nits to clean up, but feel free to merge after they're addressed
Pull request has been modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bah the embed isn't working: https://media.giphy.com/media/H4zaKzL5e7ypqn10zi/giphy.gif
262663a
to
3700ef4
Compare
Pull request has been modified.
Merge activity
|
This PR adds a new offchain helper for creating a `TransferChecked` instruction with the necessary accounts metas for a transfer hook `ExecuteInstruction` to Token2022, deprecating the old one. As described in #6064, the original offchain helper in Token2022 was being used incorrectly to resolve extra account metas. Rather than providing the SPL Transfer Hook interface helper with a valid `ExecuteInstruction`, the original Token2022 helper was actually providing it with a transfer instruction, causing erroneous account resolution. Taking advantage of the more secure SPL Transfer Hook interface offchain helper provided in #6099, this new offchain helper creates a `TransferChecked` instruction and calls `add_extra_account_metas_for_execute(..)`, providing the keys used to build the transfer instruction. Note: unlike the deprecated helper in #6099, the deprecated offchain helper in Token2022 *is* in fact inaccurately resolving account metas for certain use cases, thus it should be vigilantly avoided.
Following up from the new helpers added in #6099 and #6100, there's a transfer hook test in `program-2022-test` that's using the now-deprecated helper to build a swap instruction for the test program. This PR replaces that bit of code to use the new helper from `spl_transfer_hook_interface`. Note: The test in question is designed to test Token2022's `invoke_transfer_checked(..)` on-chain helper, *not* the offchain helpers. So, it's appropriate to use the offchain helper directly from the interface crate for this step.
This PR adds a new offchain helper for adding the necessary account metas for an
ExecuteInstruction
to the SPL Transfer Hook interface, deprecating the oldone.
As described in #6064, the offchain helper in Token2022 was using the original
offchain helper from the SPL Transfer Hook interface incorrectly when resolving
extra account metas for a transfer.
In order to provide a safer, more robust helper, this new function takes the
instruction, fetch account data function, as well as the individual arguments
for
instruction::execute(..)
. This will help to ensure Token2022 as well asanyone else using the helpers from the SPL Transfer Hook interface are properly
resolving the necessary additional accounts.
Note: Although deprecated, the original helper in the SPL Transfer Hook
interface is not broken. It's just less safe to use than this new helper, since
it can easily be misused.