Skip to content

fix / extract positionRent from transaction balances for Orca CLMM#610

Open
mlguys wants to merge 1 commit intodevelopmentfrom
feat/orca-fix-rent-608
Open

fix / extract positionRent from transaction balances for Orca CLMM#610
mlguys wants to merge 1 commit intodevelopmentfrom
feat/orca-fix-rent-608

Conversation

@mlguys
Copy link
Contributor

@mlguys mlguys commented Feb 25, 2026

Summary

Fixes #608 — Orca CLMM connector was reporting incorrect positionRent / positionRentRefunded values and incorrect baseFeeAmountCollected on close.

Related fix: #591 (same approach applied to Meteora, commit e9b15fb)

Key Changes

  • Correct rent calculation on open — Previously only summed rent for 3 position accounts (~0.002 SOL), missing tick array initialization rent (~0.013 SOL each). Now extracts rent from the confirmed transaction's postBalances for ALL newly-created accounts (position mint + PDA + ATA + tick arrays).

  • Correct rent refund on close — Extracts rent refund from the transaction's preBalances for closed position accounts. Tick arrays are shared resources and not closed, so their rent is correctly excluded.

  • Correct fee calculation on close — Previously used collectFeesQuote() which reads position data BEFORE the updateFeesAndRewards instruction executes on-chain, returning stale/incorrect values. Now derives fees from actual balance changes: fees = totalReceived - liquidityRemoved.

  • Refactored initializeTickArrays() — Now returns PublicKey[] of newly-created tick array accounts so their rent can be tracked.

Files Modified

  • src/connectors/orca/clmm-routes/openPosition.ts — Rent from TX postBalances, token amounts from extractBalanceChangesAndFee()
  • src/connectors/orca/clmm-routes/closePosition.ts — Rent refund from TX preBalances, fee derivation from actual balance changes
  • test/connectors/orca/clmm-routes/openPosition.test.ts — Updated mocks for new getTransaction / extractBalanceChangesAndFee calls

@mlguys mlguys requested a review from fengtality February 25, 2026 10:54
@rapcmia rapcmia added this to the v2.13 milestone Feb 25, 2026
@rapcmia rapcmia moved this to Under Review in Pull Request Board Feb 25, 2026
@rapcmia rapcmia changed the title fix: extract positionRent from transaction balances for Orca CLMM fix / extract positionRent from transaction balances for Orca CLMM Feb 25, 2026
Copy link
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 with hummingbot development branch on source
  • Setup with Helius nodeURL (free ver) and tested with {PYUSD, SOL}-USDC pair
  • Successfully open and close LP positions
  • Compared logs from recent gateway logs (archived files)
  • Observed print rent-breakdown in addtiion to existing position rent summary
  • Also added rent refund when closing position ok
  • Tests on PYUSD-USDC returned 0 fees because no active occured from the time it was open to close
  • Had SOL-USDC LP closed with some swaps happened while it was active:
    2026-02-25 05:43:49 | info |    🚀 Sent transaction 5LRg6fe81eVoweaUZsZHYEFeE1eYoYyqhL1iQWQeS7fAv5iDXs1gLNyCYFneFu99Y7q3N65Gbemz2mvyNJCJD2ZM, polling for confirmation...
    2026-02-25 05:43:51 | info |    ✅ Transaction 5LRg6fe81eVoweaUZsZHYEFeE1eYoYyqhL1iQWQeS7fAv5iDXs1gLNyCYFneFu99Y7q3N65Gbemz2mvyNJCJD2ZM confirmed after 2 attempts
    2026-02-25 05:43:51 | info |    Transaction 5LRg6fe81eVoweaUZsZHYEFeE1eYoYyqhL1iQWQeS7fAv5iDXs1gLNyCYFneFu99Y7q3N65Gbemz2mvyNJCJD2ZM confirmed with total fee: 0.000016 SOL
    2026-02-25 05:43:51 | info |    Rent refunded from BLtNrQVacaw3Fq2Km8DMHvLSCoP7HKDwHTdwJ21vX41G: 4029840 lamports
    2026-02-25 05:43:51 | info |    Rent refunded from EpCnP5h2bJudWDufQuFx12snRVB4DzvmddjvVm2fAfGA: 3953280 lamports
    2026-02-25 05:43:51 | info |    Rent refunded from FR2vbpkuaee8ffNheMg3EMGpzT4Cxgpi2mdApzqVcJyx: 2074080 lamports
    2026-02-25 05:43:51 | info |    Position closed: removed=0.000000 tokenA + 5.870924 tokenB, fees=0.000024 tokenA + 0.003026 tokenB, rent refunded=0.010057 SOL
    

Copy link
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.

Looks like position rent and refunds are now correct. However, the fee field only contains base fee, but not priority fees paid.

Open tx: https://solscan.io/tx/4mELKQadVieTjBcxSajYp3Ht74LX2EkT4Loou9uJqw6hmAiYvuEk3AKFpEEa81nL7gWdyeYXXhz1Ha2dqjEUvCT6

Fees from tx

  • Fee: 0.000025619 SOL
  • Priority Fee: 0.000015619 SOL

Gateway response:

{
  "signature": "4mELKQadVieTjBcxSajYp3Ht74LX2EkT4Loou9uJqw6hmAiYvuEk3AKFpEEa81nL7gWdyeYXXhz1Ha2dqjEUvCT6",
  "status": 1,
  "data": {
    "fee": 0.000025619000000000003,
    "positionAddress": "AQspembSyEkUMym88XQzwYFPZNbVM9xoaYEgWMKsM2wR",
    "positionRent": 0.0100572,
    "baseTokenAmountAdded": 0.099515736,
    "quoteTokenAmountAdded": 8.887790999999998
  }
}

Close tx:
https://solscan.io/tx/u5MqJrhnkea63AXDcZtm8pQZ6GJWNyy4qAhs2XFrA29Y7Vn3zMw6eiDjxWXPLjA4TuKhGuEhjR83uTFoA88u98e

Fees from tx:

  • Fee: 0.000016117 SOL
  • Priority Fee: 0.000011117 SOL

Gateway response:

{
  "signature": "u5MqJrhnkea63AXDcZtm8pQZ6GJWNyy4qAhs2XFrA29Y7Vn3zMw6eiDjxWXPLjA4TuKhGuEhjR83uTFoA88u98e",
  "status": 1,
  "data": {
    "fee": 0.000016117000000000002,
    "positionRentRefunded": 0.0100572,
    "baseTokenAmountRemoved": 0.09392957,
    "quoteTokenAmountRemoved": 9.361866,
    "baseFeeAmountCollected": 0,
    "quoteFeeAmountCollected": 0.007337000000001481
  }
}

In addition to tx fees, it looks like the base and quote fees collected weren't exactly what the transaction returned (0.000002059 SOL and 0.000344 USDC)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Under Review

Development

Successfully merging this pull request may close these issues.

3 participants