Skip to content

fix(sdk-coin-sol): support Token-2022 close ATA - #9667

Merged
MohammedRyaan786 merged 1 commit into
masterfrom
CHALO-1417-close-ata-flow
Sep 5, 2026
Merged

fix(sdk-coin-sol): support Token-2022 close ATA#9667
MohammedRyaan786 merged 1 commit into
masterfrom
CHALO-1417-close-ata-flow

Conversation

@MohammedRyaan786

@MohammedRyaan786 MohammedRyaan786 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Ticket: CHALO-1417

This pull request enhances the Solana SDK's handling of closing associated token accounts (ATAs) by adding support for specifying a custom SPL token program (such as Token-2022) in both single and bulk close operations. It updates the builder, instruction factories, and related interfaces to allow for this flexibility and adds corresponding tests to ensure correct behavior.

Support for specifying SPL token program in ATA close operations:

  • The CloseAtaBuilder class and related interfaces now accept an optional programId parameter, allowing users to specify which SPL token program (legacy or Token-2022) should be used when closing ATAs. This applies to both single and bulk close scenarios. [1] [2] [3] [4] [5]

  • The closeATAInstruction function now uses the provided programId (if any) to determine which SPL token program to use for the close instruction, defaulting to the legacy program if not specified.

Instruction parsing and serialization improvements:

  • Instruction factories and parsers (instructionParamsFactory.ts) are updated to extract and serialize the programId when present, ensuring correct round-trip handling of instructions involving Token-2022 or other SPL token programs. [1] [2] [3] [4]

Expanded test coverage:

  • New and updated tests verify that close ATA instructions use the correct SPL token program when specified, including scenarios mixing legacy and Token-2022 program IDs in bulk operations. [1] [2]

These changes make the SDK more robust and future-proof by supporting multiple SPL token programs for ATA management.

@linear-code

linear-code Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

CHALO-1417

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

⚠️ Unit tests are failing on Node 26.x (Current release line, non-blocking). This is not an LTS version yet, so it does not block merge, but it signals an incompatibility to fix before Node 26.x becomes LTS.

View run

@MohammedRyaan786
MohammedRyaan786 marked this pull request as ready for review September 5, 2026 10:56
@MohammedRyaan786
MohammedRyaan786 requested a review from a team as a code owner September 5, 2026 10:56
@ArunBala-Bitgo

Copy link
Copy Markdown
Contributor

@claude review this PR

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Claude finished @ArunBala-Bitgo's task —— View job


PR Review for Token-2022 Close ATA Support

Reviewing PR #9667: Support for specifying SPL token program in ATA close operations

Todo List:

  • Read and analyze all changed files
  • Review interface changes and backward compatibility
  • Assess test coverage and quality
  • Check for potential issues and improvements
  • Provide comprehensive review feedback

Code Review Summary

This PR successfully adds support for specifying custom SPL token programs (like Token-2022) when closing associated token accounts. The implementation is well-structured and maintains backward compatibility.

Strengths ✅

1. Clean Architecture & API Design

  • Backward Compatible: The programId parameter is optional everywhere, maintaining compatibility with existing code
  • Consistent API: Both single-ATA and bulk APIs support the new programId parameter in the same way
  • Clear Separation: The existing API mode enforcement prevents mixing single and bulk APIs, which is preserved

2. Robust Implementation

  • Proper Validation: validateAddress is called on programId parameters (closeAtaBuilder.ts:82, closeAtaBuilder.ts:130)
  • Correct Defaults: Uses TOKEN_PROGRAM_ID when no programId is specified (solInstructionFactory.ts:584)
  • Instruction Parsing: Both parseSendInstructions and parseAtaCloseInstructions properly extract and preserve programId from parsed instructions

3. Good Test Coverage

  • Mixed Program Support: Test case validates mixing legacy SPL and Token-2022 programs in bulk operations (closeAtaBuilder.ts:224-239)
  • Instruction Factory Test: Verifies Token-2022 program is used when specified (solInstructionFactory.ts:42-54)
  • Round-trip Testing: Existing tests ensure proper serialization/deserialization

4. Type Safety & Documentation

  • Clear Interface: AtaClose interface properly documents the optional programId field (iface.ts:287-288)
  • JSDoc Comments: Good documentation for the bulk API parameters (closeAtaBuilder.ts:111-115)

Areas for Improvement 🔍

1. Minor: Method Name Consistency

The new programId() method on CloseAtaBuilder follows the existing pattern, but consider if a more descriptive name like splTokenProgram() would be clearer for API users.

2. Minor: Error Message Enhancement

The validation in closeAtaBuilder.ts:130 could provide more context about what programId represents when validation fails.

3. Optimization: Conditional Spread Usage

The conditional spread operators are used correctly (closeAtaBuilder.ts:186, instructionParamsFactory.ts:315-317), but they're consistent with the codebase style.

Technical Correctness ✅

1. Proper SPL Token Program Handling

  • Correctly uses createCloseAccountInstruction with the appropriate program ID
  • Properly handles both TOKEN_PROGRAM_ID (legacy) and TOKEN_2022_PROGRAM_ID
  • Instruction parsing correctly identifies Token-2022 vs legacy programs

2. State Management

  • The _closeAtaEntries array properly stores the programId for each entry
  • initBuilder correctly reconstructs state from parsed instructions including programId
  • API mode enforcement prevents corruption when mixing APIs

3. Instruction Building

  • solInstructionFactory.ts:584-590 properly constructs close instructions with the specified token program
  • The spread operator usage in closeAtaBuilder.ts:186 correctly includes programId only when present

Security Considerations ✅

  • Address Validation: All address parameters including programId are validated
  • No Privilege Escalation: The change doesn't introduce new security risks
  • Backward Compatible: Existing code paths remain secure

Performance Impact ✅

  • Minimal Overhead: Optional parameter adds negligible memory/processing overhead
  • No Breaking Changes: Existing code continues to work without modification

Test Quality ✅

The test coverage effectively validates:

  • Mixed program usage in bulk operations
  • Proper instruction factory behavior with Token-2022
  • Backward compatibility with existing single-ATA API
  • Round-trip serialization/parsing

Final Recommendation: APPROVE

This is a well-implemented enhancement that:

  • Maintains full backward compatibility
  • Follows existing code patterns and conventions
  • Has appropriate test coverage
  • Enables important Token-2022 functionality
  • Contains no security issues or breaking changes

The implementation correctly enables BitGoJS users to close Token-2022 ATAs while preserving all existing functionality for legacy SPL token accounts.


Branch: CHALO-1417-close-ata-flow
Job: View Workflow

@MohammedRyaan786
MohammedRyaan786 merged commit 4a45c72 into master Sep 5, 2026
26 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.

2 participants