Skip to content

Conversation

@damodarnaik699
Copy link
Contributor

@damodarnaik699 damodarnaik699 commented Nov 6, 2025

Ticket: TMS-1502

Support parsing and validation of idempotent Associated Token Account (ATA)
creation instructions introduced in @solana/spl-token v0.4.1.

Background:

  • @solana/spl-token v0.4.1+ introduced createAssociatedTokenAccountIdempotentInstruction()
  • This new instruction uses a discriminator byte (Buffer.from([1])) to enable idempotent behavior
  • Unlike legacy ATA creation (empty data), idempotent instructions succeed even if the account exists
  • This prevents race condition errors in concurrent transaction scenarios

Technical Details:
The idempotent instruction is created via:
createAssociatedTokenAccountIdempotentInstruction()
→ buildAssociatedTokenAccountInstruction(..., Buffer.from([1]), ...)
→ TransactionInstruction { data: Buffer.from([1]) }

The discriminator byte (0x01) identifies the instruction variant:

  • data.length === 0: Legacy ATA creation (fails if account exists)
  • data.length === 1 && data[0] === 1: Idempotent ATA creation (succeeds regardless)

Changes:

  • Added isIdempotentAtaInstruction() helper to validate discriminator byte
  • Updated getInstructionType() to accept both legacy and idempotent ATA instructions
  • Both instruction types return 'InitializeAssociatedTokenAccount' for compatibility
  • Added comprehensive JSDoc explaining the idempotent behavior and use cases

Benefits:

  • Prevents "account already exists" errors in high-frequency scenarios
  • Enables safe concurrent ATA creation from multiple services
  • Backward compatible with legacy ATA instructions
  • Production-ready for automated trading systems

@damodarnaik699 damodarnaik699 marked this pull request as ready for review November 6, 2025 09:56
@damodarnaik699 damodarnaik699 requested a review from a team as a code owner November 6, 2025 09:56
sachushaji
sachushaji previously approved these changes Nov 6, 2025
@sachushaji sachushaji merged commit 1321a91 into master Nov 10, 2025
13 checks passed
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.

4 participants