Skip to content

fix / use on-chain data for real-time Orca pool price#603

Merged
fengtality merged 6 commits intodevelopmentfrom
fix/orca-realtime-pool-price
Feb 20, 2026
Merged

fix / use on-chain data for real-time Orca pool price#603
fengtality merged 6 commits intodevelopmentfrom
fix/orca-realtime-pool-price

Conversation

@fengtality
Copy link
Contributor

@fengtality fengtality commented Feb 12, 2026

Summary

  • Fetch on-chain whirlpool data using getWhirlpool() for real-time price
  • Calculate price from sqrtPrice using PriceMath.sqrtPriceX64ToPrice() instead of relying on potentially stale API data
  • Fetch vault balances for accurate token amounts
  • Keep API data for analytics fields (tvlUsdc, yieldOverTvl)

Problem

The Orca API (api.orca.so/v2/solana/pools/search) can return stale price data, causing LP positions to be created with incorrect price bounds.

Solution

Fetch the whirlpool data directly from the blockchain and calculate the price from sqrtPrice for accurate real-time pricing.

Test plan

  • Verify pool-info endpoint returns accurate real-time price
  • Compare returned price with Orca.so website
  • Test LP position creation with new price data

🤖 Generated with Claude Code

The Orca API can return stale price data. This change fetches the
whirlpool data directly from the blockchain and calculates the price
from sqrtPrice for accurate real-time pricing.

- Fetch on-chain whirlpool data using getWhirlpool()
- Calculate price from sqrtPrice using PriceMath.sqrtPriceX64ToPrice()
- Fetch vault balances for accurate token amounts
- Keep API data for analytics fields (tvlUsdc, yieldOverTvl)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@fengtality fengtality requested a review from mlguys February 12, 2026 17:13
@fengtality
Copy link
Contributor Author

fengtality commented Feb 12, 2026

@mlguys I added this PR since I found that the Orca API pool prices may not reflect actual on-chain prices, resulting in incorrect positions placed.

Also, I think we should standardize the API pool data returned by this route. I saw that you added tvlUsdc, protocolFeeRate and yieldOverTvl which aren't defined in PoolInfoSchema in the CLMM Schema. I think these API data fields are helpful but ideally we add them to PoolInfoSchema and fetch for all available connectors. Let's discuss this on Fri or next Mon.

Update tests to mock new dependencies:
- Mock Solana.getInstance for connection access
- Mock getMint from @solana/spl-token for decimal info
- Mock PriceMath.sqrtPriceX64ToPrice for price calculation
- Mock getWhirlpool for on-chain pool data
- Use valid Solana base58 addresses for vault mocks
- Add proper beforeEach reset for mock isolation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rapcmia rapcmia self-requested a review February 13, 2026 02:09
@rapcmia rapcmia added this to the v2.13 milestone Feb 13, 2026
- Add _fetchTransactionWithRetry method with configurable retries
- Use retry logic in WebSocket and polling confirmation flows
- Use configurable timeout for WebSocket monitoring
- Apply retry to extractBalanceChangesAndFee for reliability

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rapcmia rapcmia moved this to Backlog in Pull Request Board Feb 13, 2026
@rapcmia rapcmia moved this from Backlog to Under Review in Pull Request Board Feb 16, 2026
@rapcmia rapcmia changed the title fix: use on-chain data for real-time Orca pool price fix / use on-chain data for real-time Orca pool price Feb 16, 2026
@rapcmia
Copy link
Contributor

rapcmia commented Feb 17, 2026

Commit 3d5510b

  • Setup on source with helius nodeURL
  • GET /connectors/orca/clmm/pool-info
  • When checking PYUSD-USDT 9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B getting TokenInvalidAccountOwnerError ❌
    #### run orca clmm pool-info
    curl -sS -X GET "http://localhost:15888/connectors/orca/clmm/pool-info?network=mainnet-beta&poolAddress=9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B" | jq
    {
      "statusCode": 500,
      "error": "InternalServerError",
      "message": "Internal server error"
    }
    logs: 2026-02-17 | TokenInvalidAccountOwnerError (from gateway logs)
    
    • compared with JUP-USDC and SOL-USDC, these markets works as expected ✅
    • compared with development branch commit 7bb5bd0460c98b2670c0d5f4964178f4a611e362
      curl -sS -X GET "http://localhost:15888/connectors/orca/clmm/pool-info?network=mainnet-beta&poolAddress=9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B" -H "X-Note: development" | jq
      {
        "address": "9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B",
        "baseTokenAddress": "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo",
        "quoteTokenAddress": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
        "feePct": 0.01,
        "price": 1.0000438650780092,
        "baseTokenAmount": 16826537.332925,
        "quoteTokenAmount": 14220697.597852,
        "activeBinId": 0,
        "liquidity": "43569222763129181",
        "sqrtPrice": "18447148653206777165",
        "tvlUsdc": 31045721.312200654,
        "protocolFeeRate": 0.13,
        "yieldOverTvl": 0.00000817197170889726,
        "binStep": 1
      }
      logs: route=GET /connectors/orca/clmm/pool-info (successful response)
      

Steps to reproduce:

  • Run pool-info for 9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B (PYUSD-USDT)

Replace getMint from @solana/spl-token with fetchAllMint from
@solana-program/token-2022 to support both standard SPL Token and
Token2022 (Token Extensions) programs.

This fixes TokenInvalidAccountOwnerError when querying pools with
Token2022 tokens like PYUSD.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rapcmia
Copy link
Contributor

rapcmia commented Feb 20, 2026

Commit a406998

  • Retry orca clmm pool-info PYUSD-USDC ✅
    curl -sS -X GET "http://localhost:15888/connectors/orca/clmm/pool-info?network=mainnet-beta&poolAddress=9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B" | jq
    {
      "address": "9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B",
      "baseTokenAddress": "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo",
      "quoteTokenAddress": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
      "feePct": 0.01,
      "price": 1.0000326159210677,
      "baseTokenAmount": 16409307.925614,
      "quoteTokenAmount": 14097461.496698,
      "activeBinId": 0,
      "liquidity": "24035345549335868",
      "sqrtPrice": "18447044900030971534",
      "tvlUsdc": 30504112.723103315,
      "protocolFeeRate": 0.13,
      "yieldOverTvl": 0.00000897263609017434,
      "binStep": 1
    }
    logs: route=GET /connectors/orca/clmm/pool-info (successful response)
    
  • Pool info validated 3/3 on PYUSD-USDC returning price around 1.00003 and compare with exchange’s current price
  • Use pool info price to setup LP bounds (upper and lower) to execute open-position and add-liqiduity
  • Checked position-info and positioned owned ok
  • Successfully removed position

@fengtality fengtality merged commit 188b14b into development Feb 20, 2026
5 checks passed
@fengtality fengtality deleted the fix/orca-realtime-pool-price branch February 20, 2026 13:53
@rapcmia rapcmia moved this from Under Review to Development v2.13.0 in Pull Request Board Feb 20, 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.

2 participants