Skip to content

Add support for new Token Program instructions and improve instruction sharing - #308

Open
wiyarmir wants to merge 2 commits into
update-solana-idlsfrom
claude/fix-pr-306-ci-DZpc0
Open

Add support for new Token Program instructions and improve instruction sharing#308
wiyarmir wants to merge 2 commits into
update-solana-idlsfrom
claude/fix-pr-306-ci-DZpc0

Conversation

@wiyarmir

@wiyarmir wiyarmir commented May 7, 2026

Copy link
Copy Markdown
Member

Summary

This PR adds support for three new Token Program instructions (withdrawExcessLamports, unwrapLamports, and batch), updates the syncNative instruction to include an optional rent sysvar parameter, and improves the code generation logic to properly handle instruction signature compatibility across multiple program implementations.

Key Changes

  • New Instructions: Added three new instruction definitions to the Token Program IDL:

    • withdrawExcessLamports (discriminator 38): Rescues excess SOL from TokenProgram-owned accounts
    • unwrapLamports (discriminator 45): Transfers lamports from native SOL accounts with optional amount parameter
    • batch (discriminator 255): Executes batches of instructions
  • Updated syncNative Instruction: Modified to include an optional rent sysvar account parameter with a default value, and changed the optional account strategy from programId to omitted

  • Improved Instruction Sharing Logic:

    • Added hasUnsupportedTypes() function to detect instructions with argument types that cannot be mapped to typed Kotlin (e.g., inline anonymous structs in arrays)
    • Added signaturesCompatible() function to determine if two instructions have compatible signatures for shared abstract method declarations
    • Updated computeSharedInstructionNames() to only treat instructions as "shared" if they exist in all implementing programs with compatible signatures
    • Instructions with unsupported types or divergent signatures are now generated as regular methods rather than abstract overrides
  • Code Generation Improvements:

    • Instructions with unsupported types are now skipped with a warning message
    • The base program's abstract method declarations only include truly shared instructions
    • Each program implementation can have its own version of non-shared instructions

Implementation Details

The changes ensure that:

  1. Instructions are only declared as abstract on the sealed parent class if they exist in all implementing programs with identical signatures
  2. Instructions with complex nested types (like structs inside arrays) are properly detected and skipped to prevent non-compiling generated code
  3. The syncNative instruction now properly includes the rent sysvar as an optional account parameter
  4. New instruction variants are properly enumerated and can be called on Token Program instances

https://claude.ai/code/session_014xdHvfVQqrfn4fnhY52vF1

@wiyarmir
wiyarmir changed the base branch from main to update-solana-idls May 7, 2026 09:49
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@wiyarmir
wiyarmir force-pushed the claude/fix-pr-306-ci-DZpc0 branch from f2b6605 to d0b63e2 Compare May 7, 2026 09:52
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

🥳 JUnit passed

Passed Failed Skipped
✅ 157 ❌ 0 ⚠️ 4

You can see the report here.

🥳 JUnit passed

Passed Failed Skipped
✅ 157 ❌ 0 ⚠️ 4

You can see the report here.

🥳 JUnit passed

Passed Failed Skipped
✅ 221 ❌ 0 ⚠️ 6

You can see the report here.

@wiyarmir
wiyarmir force-pushed the claude/fix-pr-306-ci-DZpc0 branch from d0b63e2 to ef59dbd Compare May 7, 2026 10:25
wiyarmir and others added 2 commits May 18, 2026 16:08
The base TokenProgram IDL diverged from token-2022.json: syncNative gained an
optional rent account, and a new batch instruction was added with an inline
anonymous struct in an array. The previous codegen made every base instruction
abstract on the sealed parent and called serialize() on a structTypeNode it
couldn't map (List<Any>), which produced code that didn't compile.

- Compute sharedInstructionNames as the intersection of compatible signatures
  across implementing programs, so abstracts/overrides are only emitted when
  every implementation matches.
- Skip generating instructions whose argument types contain inline anonymous
  structs inside arrays (currently unsupported), with a build-time warning.

Regenerate TokenProgram.kt and Token2022Program.kt accordingly.
@wiyarmir
wiyarmir force-pushed the claude/fix-pr-306-ci-DZpc0 branch from ef59dbd to 268e513 Compare May 18, 2026 16:09
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