Skip to content

feat(token): add p-token (SIMD-0266) and missing SPL Token instructions#366

Open
hxuan190 wants to merge 3 commits into
solana-foundation:mainfrom
hxuan190:feat/ptoken-instructions
Open

feat(token): add p-token (SIMD-0266) and missing SPL Token instructions#366
hxuan190 wants to merge 3 commits into
solana-foundation:mainfrom
hxuan190:feat/ptoken-instructions

Conversation

@hxuan190
Copy link
Copy Markdown

Add support for 7 missing token instructions to the SPL Token program:

Instructions 21-24 (existing on-chain, missing from solana-go):

  • GetAccountDataSize (ID 21)
  • InitializeImmutableOwner (ID 22)
  • AmountToUiAmount (ID 23)
  • UiAmountToAmount (ID 24)

P-token exclusive instructions (SIMD-0266 / Pinocchio):

  • WithdrawExcessLamports (ID 38)
  • UnwrapLamports (ID 45)
  • Batch (ID 255)

Updated instructions.go with new constants, InstructionIDToName entries, extended InstructionImplDef for IDs 0-24, and added pTokenInstructionMap with custom DecodeInstruction dispatch for non-contiguous p-token IDs.

Verified on Solana testnet (SIMD-0266 feature gate activated at slot 396236256, address ptokFjwyJtrwCa9Kgo9xoDS59V4QccBGEaRFnRPnSdP):

Simulation tests (IDs 20-24):

  • InitializeMint2: 364 CUs
  • GetAccountDataSize: 179 CUs
  • AmountToUiAmount: 615 CUs
  • UiAmountToAmount: 589 CUs

Send+confirm tests (p-token exclusive):

  • WithdrawExcessLamports (ID 38): 3C9iNnUPPaqRCA1RSD5tXDpD7ZW72VQYsKYm1j3voEYcH4UCfzKURan63Df2jdfX3gzPzEHZDu6eFfnTf2K4H98d
  • UnwrapLamports partial (ID 45): zPrV9K6wLqnES4RBDAQs15S8MgvC48QjsLZAmPoimvY6vmQkh8yi3XBJYqQBkpo28HpiNdhuPL3N65Dqf1ovhWn
  • UnwrapLamports all (ID 45): 5VVDC6PeWo5sAAUhbc3xRRiZDMo1t5Y6c1VDktBqLLhXZtri1HshL9y7TmEu9BBZEpiQCdAmULazfNjTfeHd5ujH
  • Batch with 2 transfers (ID 255): 2y1jC5rXbQvvym1bM5ukRcQfiovUQPi4fbcryixXpjTe5fc2UDGvvgurZqLNx7DEYd7NHHwEnEt6oPX4anV9kXnh

@hxuan190 hxuan190 marked this pull request as draft March 23, 2026 19:49
@hxuan190 hxuan190 marked this pull request as ready for review March 23, 2026 21:06
@hxuan190 hxuan190 force-pushed the feat/ptoken-instructions branch from 332a19a to 133fb4c Compare May 13, 2026 14:02
hxuan190 added 2 commits May 13, 2026 21:06
Add support for 7 missing token instructions to the SPL Token program:

Instructions 21-24 (existing on-chain, missing from solana-go):
- GetAccountDataSize (ID 21)
- InitializeImmutableOwner (ID 22)
- AmountToUiAmount (ID 23)
- UiAmountToAmount (ID 24)

P-token exclusive instructions (SIMD-0266 / Pinocchio):
- WithdrawExcessLamports (ID 38)
- UnwrapLamports (ID 45)
- Batch (ID 255)

Updated instructions.go with new constants, InstructionIDToName entries,
extended InstructionImplDef for IDs 0-24, and added pTokenInstructionMap
with custom DecodeInstruction dispatch for non-contiguous p-token IDs.

Verified on Solana testnet (SIMD-0266 feature gate activated at slot
396236256, address ptokFjwyJtrwCa9Kgo9xoDS59V4QccBGEaRFnRPnSdP):

Simulation tests (IDs 20-24):
- InitializeMint2: 364 CUs
- GetAccountDataSize: 179 CUs
- AmountToUiAmount: 615 CUs
- UiAmountToAmount: 589 CUs

Send+confirm tests (p-token exclusive):
- WithdrawExcessLamports (ID 38):
  3C9iNnUPPaqRCA1RSD5tXDpD7ZW72VQYsKYm1j3voEYcH4UCfzKURan63Df2jdfX3gzPzEHZDu6eFfnTf2K4H98d
- UnwrapLamports partial (ID 45):
  zPrV9K6wLqnES4RBDAQs15S8MgvC48QjsLZAmPoimvY6vmQkh8yi3XBJYqQBkpo28HpiNdhuPL3N65Dqf1ovhWn
- UnwrapLamports all (ID 45):
  5VVDC6PeWo5sAAUhbc3xRRiZDMo1t5Y6c1VDktBqLLhXZtri1HshL9y7TmEu9BBZEpiQCdAmULazfNjTfeHd5ujH
- Batch with 2 transfers (ID 255):
  2y1jC5rXbQvvym1bM5ukRcQfiovUQPi4fbcryixXpjTe5fc2UDGvvgurZqLNx7DEYd7NHHwEnEt6oPX4anV9kXnh

All 68 tests pass (30 existing + 38 new), zero regressions.

Made-with: Cursor
@hxuan190 hxuan190 force-pushed the feat/ptoken-instructions branch from 133fb4c to 4fbf100 Compare May 13, 2026 14:13
@hxuan190
Copy link
Copy Markdown
Author

This feature is live on mainnet & made some test on devnet with test keypair Ct1DVKNkhZV5qvXqu5Hr7rN9NfVDWpVQFxaUqHjhfpG2

Copy link
Copy Markdown
Contributor

@sonicfromnewyoke sonicfromnewyoke left a comment

Choose a reason for hiding this comment

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

Overall looks good, left some comments after addressing them and adding some tests it will be nice to add it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this instruction delivesr their result via sol_get_return_data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this instruction delivesr their result via sol_get_return_data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this instruction delivesr their result via sol_get_return_data

@hxuan190
Copy link
Copy Markdown
Author

@sonicfromnewyoke can you tell me more information about your review? confused a little bit

@sonicfromnewyoke
Copy link
Copy Markdown
Contributor

sonicfromnewyoke commented May 14, 2026

@sonicfromnewyoke can you tell me more information about your review? confused a little bit

sorry, my inline notes were too terse... i meant the next one:

there is no Go-side helper for the return-data instructions. Marked ixns deliver their result via sol_get_return_data. The struct builders here only handle the request side - so a caller still has to hand-roll the LE-u64 / UTF-8 decoding after sim txn. That was the point of my three inline comments: there we eaither need a small ParseReturnData helper per instruction (or a single typed dispatcher) so the SDK is symmetric or simply drop those inxns because not so many guys are using them this way.

Batch.UnmarshalWithDecoder drops accountCount- the whole reason the on-chain format encodes per sub-ix is so a decoder can slice the flat account list back into per-sub-ix accounts.

also, the novel logic has no test, for example round-trip fuzz tests for Batc missing - the file only asserts ID constants

despite comments above, this is a solid PR overall 💪

Comment thread programs/token/Batch.go
})
}

func (obj Batch) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Batch.MarshalWithEncoder silently truncates if a sub-instruction has > 255 accounts or > 255 bytes of data — please return an explicit error.

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.

3 participants