Support Token-2022 in the test CLI - #134
Draft
kaze-cow wants to merge 1 commit into
Draft
Conversation
Token resolution now reports which token program owns the mint it resolved, and every instruction the CLI builds against a resolved token is issued against that program instead of assuming the legacy one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Teaches the test CLI to work with Token-2022 mints. Split out of #120, which it stacks on.
What changes
ResolvedTokengains atoken_programfield: whichever of the two supported programs owns the mint and its token account. Everything the CLI builds against a resolved token —Approve,SyncNative, the ATA creation instruction, the associated token address derivation — is now issued against that program instead of assuming the legacy one.Decoding moves to
StateWithExtensions, so a mint or token account carrying Token-2022 extension data decodes instead of being rejected for having the wrong length.interpret_token_from_user_inputtries the token account before the mint, since an extended mint can be as long as a token account and only the trailing account-type byte tells the two apart; there are unit tests pinning both directions of that.The three resolution paths (
"SOL"/"WSOL", a known alias, a base58 mint) all funnel through oneresolve_from_minthelper that fetches the mint once and derives the ATA under the owning program.determine_create_atanow takes the token account address the caller already derived, rather than re-deriving it from the mint under the legacy program. Under the old code an ATA on a non-legacy program was looked up at the wrong address and would always be reported as missing.settlegroups the buffers it needs to create by token program and emits oneCreateBuffersper group, since a single instruction only accepts buffers for one program.WSOL
SOL/WSOLnow resolves the Token-2022 native mint (9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP) instead of the legacy one. The two are equivalent for the CLI's purposes — wrap, sync, settle — and this exercises the Token-2022 path by default on every smoke test. Say the word if you'd rather keep the legacy mint and reach Token-2022 only through an explicit mint address.Dependencies
test-climoves fromspl-token-interfacetospl-token-2022-interface, which drops the last user of the legacy interface: the workspace entry #120 left in place for exactly this reason goes away here.Out of scope
Integration tests covering Token-2022 across the settlement flow are in #121.
Test plan
just lintandjust testare clean. The token module's new unit tests cover extension-aware decoding, mint/token-account disambiguation, and token program validation.Manual smoke test against devnet is still worth doing:
cargo run -p cow-test-cli -- sell --helpandcargo run -p cow-test-cli -- settle --help, settling one order whose buy token is a Token-2022 mint and whose sell token is a legacy mint, which should produce twoCreateBuffersinstructions.🤖 Generated with Claude Code