Skip to content

fix(clients): default Token-2022-only instructions to the right program - #202

Draft
jackchuma wants to merge 1 commit into
mainfrom
jack/legacy-token-program-default
Draft

jackchuma wants to merge 1 commit into
mainfrom
jack/legacy-token-program-default

Conversation

@jackchuma

Copy link
Copy Markdown
Collaborator

Independent of the wrapped-token-uri stack (#199#200#201), though it touches the same generator file. See the note at the bottom.

The bug

Codama defaults any account named tokenProgram to the legacy SPL Token program, TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA. Three bridge instructions declare that account as Program<'info, Token2022> onchain:

Instruction Onchain type
wrap_token Program<'info, Token2022>
bridge_wrapped_token Program<'info, Token2022>
bridge_wrapped_token_with_buffered_call Program<'info, Token2022>

Anchor validates that account's key against the Token-2022 program ID, so the generated default can never work. Any caller who relies on it gets an instruction that fails. All three deal exclusively with wrapped mints, which are always Token-2022.

The two bridge_spl instructions also carry the legacy default and are deliberately left alone: they take Interface<'info, TokenInterface> and accept either program, so defaulting to legacy SPL Token is a reasonable choice there.

The fix

Pinned through a Codama setInstructionAccountDefaultValuesVisitor in generate-client.handler.ts rather than by editing the generated files, so it survives the next regeneration.

Verification

Confirmed before changing anything that regenerating main's client produces no diff, so everything here is attributable to this change. The resulting diff is exactly the program address in those three files and nothing else. Both the bridge and base-relayer clients regenerate cleanly, clients/ts builds, and scripts typechecks.

Note for whoever merges second

#200 pins the same default for wrapTokenV2 and so touches the same two regions of generate-client.handler.ts. Whichever lands second will conflict there. The resolution is to add "wrapTokenV2" to the TOKEN_2022_ONLY_INSTRUCTIONS list introduced here — one line, no second visitor block. Happy to rebase whichever way suits.

Codama defaults any account named `tokenProgram` to the legacy SPL Token
program. Three bridge instructions declare theirs as `Program<Token2022>`
onchain, so Anchor rejects that default and the instruction fails for any
caller who omits the account.

Pins the default through a generator visitor rather than editing the generated
files, so it survives regeneration. The `bridge_spl` instructions keep the
legacy default: they take `Interface<TokenInterface>` and accept either program.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

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.

2 participants