Skip to content

fix: use Token-2022 positions for full rent recovery on close for Orca#600

Merged
rapcmia merged 1 commit intodevelopmentfrom
feat/orca-connector-feb-2026
Feb 16, 2026
Merged

fix: use Token-2022 positions for full rent recovery on close for Orca#600
rapcmia merged 1 commit intodevelopmentfrom
feat/orca-connector-feb-2026

Conversation

@mlguys
Copy link
Copy Markdown
Contributor

@mlguys mlguys commented Feb 11, 2026

Summary

Fixes #584 — Orca CLMM positions now use Token-2022 instructions instead of Metaplex, enabling full rent recovery when positions are closed.

Problem: The old Metaplex-based openPositionWithMetadataIx creates a mint account that cannot be closed. On position close, only the position data PDA and token ATA rent could be reclaimed (~0.006 SOL), but the mint account rent (~0.004 SOL) was permanently locked. This meant ~$1.89 was spent opening a position but only ~$0.74 was returned on close.

Solution: Switch to Token-2022's openPositionWithTokenExtensionsIx which creates mints with MintCloseAuthority extension, making all 3 position accounts (mint, PDA, ATA) fully reclaimable on close.

Changes

openPosition.ts

  • Replaced openPositionWithMetadataIx (Metaplex) with openPositionWithTokenExtensionsIx (Token-2022)
  • Position token account now derives with TOKEN_2022_PROGRAM_ID
  • Rent calculation uses direct getBalance() queries on the 3 position accounts instead of unreliable wallet SOL change extraction

executeSwap.ts

  • Replaced WhirlpoolIx.swapIx with WhirlpoolIx.swapV2Ix for Token-2022 compatibility

closePosition.ts

  • Rent refund calculation uses direct getBalance() queries on position accounts before the close TX (while accounts still exist)
  • Fee amounts use collectFeesQuote from on-chain position data instead of post-TX wallet SOL change extraction
  • Already had closePositionWithTokenExtensionsIx (backward compatible with legacy via isToken2022 check)

Tests

  • Updated openPosition.test.ts: mock connection.getBalance instead of extractBalanceChangesAndFee
  • Updated executeSwap.test.ts: mock swapV2Ix instead of swapIx

Switch from Metaplex-based openPositionWithMetadataIx to Token-2022
openPositionWithTokenExtensionsIx so position mint accounts have
MintCloseAuthority and can be fully closed, recovering all rent.

Changes:
- openPosition: use Token-2022 instructions and derive ATA with
  TOKEN_2022_PROGRAM_ID; calculate rent via direct getBalance queries
  on the 3 position accounts (mint, PDA, ATA)
- executeSwap: use swapV2Ix for Token-2022 token compatibility
- closePosition: calculate rent refund via direct getBalance queries
  before close TX; use collectFeesQuote for fee amounts instead of
  unreliable wallet SOL change extraction

Fixes #584
@mlguys mlguys changed the title fix(orca): use Token-2022 positions for full rent recovery on close fix: use Token-2022 positions for full rent recovery on close for Orca Feb 11, 2026
@rapcmia rapcmia requested a review from fengtality February 11, 2026 10:36
@rapcmia rapcmia added this to the v2.13 milestone Feb 11, 2026
@rapcmia rapcmia moved this to Backlog in Pull Request Board Feb 11, 2026
@rapcmia rapcmia self-requested a review February 11, 2026 10:36
Copy link
Copy Markdown
Contributor

@fengtality fengtality left a comment

Choose a reason for hiding this comment

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

Tested and reviewed code, LGTM

@rapcmia rapcmia moved this from Backlog to Under Review in Pull Request Board Feb 16, 2026
Copy link
Copy Markdown
Contributor

@rapcmia rapcmia left a comment

Choose a reason for hiding this comment

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

  • Setup on source ok
  • Use PYUSD/USDC, pool 9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B
  • ./connectors/orca/clmm routes ✅
    • /connectors/orca/clmm/{quote-swap, execute-swap}
    • /connectors/orca/clmm/{pool-info, quote-position, open-position, add-liquidity, position-info, positions-owned, collect-fees, close-position}
  • ./trading/clmm routes ✅
    • /trading/swap/{quote, execute}
    • /trading/clmm/{pool-info, open, add, remove, collect-fees, close}
      • /trading/clmm/{positions-owned, quote-position}

Test logs: 02162026.zip

@rapcmia rapcmia merged commit f5df19c into development Feb 16, 2026
5 checks passed
@rapcmia rapcmia deleted the feat/orca-connector-feb-2026 branch February 16, 2026 05:13
@rapcmia
Copy link
Copy Markdown
Contributor

rapcmia commented Feb 16, 2026

Merged to development and part of release version 2.13

@rapcmia rapcmia moved this from Under Review to Development v2.13.0 in Pull Request Board Feb 16, 2026
@rapcmia rapcmia moved this from Development v2.13.0 to Release v2.13.0 in Pull Request Board Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Release v2.13.0

Development

Successfully merging this pull request may close these issues.

3 participants