Skip to content

chore: use @solana-program/token parseBatchInstruction for batch feature#947

Open
askov wants to merge 6 commits intosolana-foundation:masterfrom
hoodieshq:chore/update-token-batch-impl
Open

chore: use @solana-program/token parseBatchInstruction for batch feature#947
askov wants to merge 6 commits intosolana-foundation:masterfrom
hoodieshq:chore/update-token-batch-impl

Conversation

@askov
Copy link
Copy Markdown
Contributor

@askov askov commented Apr 14, 2026

Description

  • Upgrade @solana/kit 2.3→6.5 and all @solana-program/* packages to kit@6-compatible versions, enabling use of @solana-program/token@0.13.0
  • Replace the manual batch wire-format parser and per-instruction decoders with the SDK's parseBatchInstruction, which returns fully typed inner instructions
  • Add app/shared/lib/web3js-compat.ts as a shared bridge from web3.js v1 TransactionInstruction to @solana/kit Instruction types

Type of change

  • Other (please describe): chore/improvement

Testing

Manual testing checklist — packages upgrade

Related Issues

Closes HOO-403

Checklist

  • My code follows the project's style guidelines
  • I have added tests that prove my fix/feature works
  • All tests pass locally and in CI
  • I have run build:info script to update build information
  • CI/CD checks pass

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

@askov is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 14, 2026

Greptile Summary

This PR replaces the hand-rolled SPL Token batch wire-format parser (decode-sub-instruction.ts, manual parseBatchInstruction) with the SDK's parseBatchInstruction from @solana-program/token@0.13.0, accompanied by a major version bump of @solana/kit (2.3 → 6.5) and all @solana-program/* packages. A new web3js-compat.ts bridge converts web3.js v1 TransactionInstruction objects to the kit-typed format expected by the SDK.

The refactor is a clear correctness win — it eliminates ~200 lines of manual wire-format parsing and the separate per-instruction decoder in favour of SDK-provided typed ParsedTokenInstruction objects — but two minor UX regressions are worth confirming are intentional:

  • Multisig co-signer accounts not displayed (format-sub-instruction.ts): extra accounts beyond the named typed fields (multisig co-signers) are no longer labeled or shown; the covering test was removed.
  • RawContent fallback simplified (SubInstructionRow.tsx): for instruction types formatByType returns undefined for, the old fallback showed hex data and all unlabeled accounts; the new one only shows the type name string.

Confidence Score: 5/5

  • Safe to merge; all remaining findings are P2 UX regressions worth confirming are intentional rather than blocking defects.
  • No P0 or P1 issues found. The core parsing logic is cleanly delegated to a well-tested SDK, the type conversion bridge is straightforward, and mint resolution logic is now more correct (named account fields replace fragile positional index lookups). The two P2 notes (multisig signer display, RawContent fallback content) are informational regressions that do not affect data correctness or security.
  • app/features/token-batch/lib/format-sub-instruction.ts and app/features/token-batch/ui/SubInstructionRow.tsx — confirm the multisig co-signer and RawContent fallback regressions are intentional.

Important Files Changed

Filename Overview
app/features/token-batch/lib/batch-parser.ts Parser simplified to a 3-line wrapper around sdkParseBatch; correctly gates on hasBatchDiscriminator and delegates to toKitInstruction for the type conversion.
app/shared/lib/web3js-compat.ts New bridge file; correctly maps web3.js AccountMeta roles and address types to @solana/kit equivalents. Buffer (web3.js) assigned directly to ReadonlyUint8Array works at runtime since Buffer extends Uint8Array.
app/features/token-batch/lib/format-sub-instruction.ts Rewritten to consume SDK-typed ParsedTokenInstruction; covers 13 instruction types correctly, but labelMetas only maps named typed accounts — extra multisig co-signers are silently dropped.
app/features/token-batch/ui/SubInstructionRow.tsx Updated to accept ParsedTokenInstruction; RawContent fallback now only shows the type name, removing the hex data view and unlabeled account list that existed before.
app/features/token-batch/model/use-sub-instruction-mint-info.ts Lookup logic now uses SDK typed account names (accounts.source, accounts.mint) instead of positional array indexing — more robust and readable; CloseAccount and Revoke lookups correctly ported.
app/features/token-batch/lib/tests/batch-parser.spec.ts Tests updated to new API with good coverage of common decode cases; truncated-data, insufficient-accounts, and multisig-signer tests were removed without equivalent replacements.
.npmrc Adds minimum-release-age-exclude for @solana-program/token and @solana/kit, bypassing the 14-day freshness policy to allow recently-released versions needed by this PR.
package.json Major version bumps for all @solana-program/* packages and @solana/kit (2.3→6.5); the @solana/addresses override removed as it is now resolved transitively.

Sequence Diagram

sequenceDiagram
    participant TC as TokenBatchCard
    participant BP as batch-parser
    participant WC as web3js-compat
    participant SDK as @solana-program/token<br/>parseBatchInstruction
    participant FR as format-sub-instruction
    participant MI as use-sub-instruction-mint-info
    participant RPC as AccountsProvider (RPC)

    TC->>BP: parseBatchInstruction(ix: TransactionInstruction)
    BP->>BP: hasBatchDiscriminator(ix.data)?
    BP->>WC: toKitInstruction(ix)
    WC-->>BP: KitInstruction (accounts mapped to AccountRole)
    BP->>SDK: sdkParseBatch(kitIx)
    SDK-->>BP: "{ instructions: ParsedTokenInstruction[] }"
    BP-->>TC: ParsedBatchResult

    loop for each ParsedTokenInstruction
        TC->>MI: useSubInstructionMintInfo(parsed)
        MI->>RPC: useAccountQuery(tokenAccount) — Hop 1
        RPC-->>MI: mintAddress
        MI->>RPC: useAccountQuery(mint) — Hop 2
        RPC-->>MI: decimals
        MI-->>TC: "MintInfo { mint, decimals }"
        TC->>FR: formatParsedInstruction(parsed, mintInfo)
        FR-->>TC: "DecodedParams { fields, accounts }"
    end
Loading

Reviews (1): Last reviewed commit: "chore: use @solana-program/token parseBa..." | Re-trigger Greptile

Comment thread app/features/token-batch/lib/format-sub-instruction.ts
Comment thread app/features/token-batch/ui/SubInstructionRow.tsx Outdated
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
explorer Ready Ready Preview, Comment Apr 23, 2026 11:55am

Request Review

Comment thread app/features/token-batch/lib/format-sub-instruction.ts
Comment thread app/features/token-batch/lib/format-sub-instruction.ts
Copy link
Copy Markdown
Contributor

@rogaldh rogaldh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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