Skip to content

Comments

Estimate compute limit for Orca/OKX#93

Merged
0xh3rman merged 3 commits intomainfrom
orca-estimate-limit
Feb 19, 2026
Merged

Estimate compute limit for Orca/OKX#93
0xh3rman merged 3 commits intomainfrom
orca-estimate-limit

Conversation

@0xh3rman
Copy link
Collaborator

No description provided.

Add compute unit estimation and apply it to Orca swaps. Introduces estimateComputeUnitLimit (uses MessageV0 + simulateTransaction) in tx_builder.ts and a small timedPromise debug helper. Update OrcaWhirlpoolProvider to fetch referral instruction concurrently, set initial compute budget with a default limit, replace the compute unit instruction with an estimated limit when available, and expose gasLimit in the returned swap payload. Also add necessary imports and wiring for compute unit limit creation.
Replace reliance on OKX getGasLimit with local Solana transaction simulation to estimate compute unit limits. OkxProvider now accepts a Solana RPC endpoint, creates a Connection, and decodes bs58 tx data into a VersionedTransaction to call the tx_builder simulation helper. Updated tx_builder to accept either Transaction or VersionedTransaction when estimating compute units. Adjusted imports/constructors across the app (apps/api passes the Solana RPC), updated OKX tests to provide the RPC and reflect the new simulation-based flow, and added a small debug eslint directive. This centralizes gas estimation locally and removes the SDK getGasLimit dependency.
@semanticdiff-com
Copy link

semanticdiff-com bot commented Feb 19, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  packages/swapper/src/orca/provider.ts  50% smaller
  packages/swapper/src/okx/provider.test.ts  41% smaller
  packages/swapper/src/okx/provider.ts  11% smaller
  apps/api/src/index.ts  0% smaller
  packages/swapper/src/chain/solana/tx_builder.ts  0% smaller
  packages/swapper/src/debug.ts  0% smaller
  packages/swapper/src/okx/integration.test.ts  0% smaller

@gemini-code-assist
Copy link

Summary of Changes

Hello @0xh3rman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the handling of Solana transaction compute limits by introducing a simulation-based estimation mechanism. This change allows both the Orca and OKX swap providers to dynamically determine and set more accurate compute unit limits for their transactions, moving away from static or external API-dependent methods. The overall impact is improved transaction reliability and efficiency on the Solana blockchain for these integrated services.

Highlights

  • Compute Unit Estimation: Introduced a new utility function estimateComputeUnitLimit in tx_builder.ts that simulates Solana transactions to accurately determine the consumed compute units, providing a more precise gas limit for transactions.
  • OKX Provider Integration: The OkxProvider has been updated to utilize the new estimateComputeUnitLimit function for calculating transaction gas limits, replacing its previous reliance on an external getGasLimit API call. Its constructor now also requires a Solana RPC endpoint.
  • Orca Provider Integration: The OrcaWhirlpoolProvider now dynamically estimates the compute unit limit for its swap transactions using the new simulation-based approach, ensuring more efficient and robust transaction processing.
  • Debugging Utility: Added a new timedPromise utility in debug.ts to easily measure the execution time of asynchronous operations, which can be useful for performance monitoring.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • apps/api/src/index.ts
    • Updated OkxProvider instantiation to pass the solanaRpc connection.
  • packages/swapper/src/chain/solana/tx_builder.ts
    • Added MessageV0 import from @solana/web3.js.
    • Implemented estimateComputeUnitLimit function to simulate transactions and return consumed compute units.
  • packages/swapper/src/debug.ts
    • Added timedPromise utility function for performance logging of promises.
  • packages/swapper/src/okx/integration.test.ts
    • Modified OkxProvider instantiation in integration tests to include a Solana RPC endpoint.
  • packages/swapper/src/okx/provider.test.ts
    • Refactored createProvider to remove the getGasLimit mock and related dependencies.
    • Updated tests to reflect the new compute unit estimation logic, expecting gasLimit to be undefined when simulation fails instead of relying on a mocked API response.
  • packages/swapper/src/okx/provider.ts
    • Imported Connection and VersionedTransaction from @solana/web3.js.
    • Removed TransactionData import and replaced COMPUTE_UNIT_MULTIPLIER with DEFAULT_COMMITMENT and simulateComputeUnits.
    • Modified the OkxProvider constructor to accept a solanaRpcEndpoint and initialize a Connection.
    • Rewrote estimateComputeUnitLimit to use the new simulateComputeUnits function, deserializing the transaction data.
    • Updated get_quote_data to pass the transaction data to the new estimateComputeUnitLimit and include the estimated gasLimit in the returned SwapQuoteData.
  • packages/swapper/src/orca/provider.ts
    • Imported createComputeUnitLimitInstruction, DEFAULT_COMPUTE_UNIT_LIMIT, and estimateComputeUnitLimit.
    • Modified get_quote_data to fetch blockhash and lastValidBlockHeight concurrently with other promises.
    • Integrated estimateComputeUnitLimit to dynamically set the compute unit limit for Orca swap transactions.
    • Included the estimated gasLimit in the SwapQuoteData returned by get_quote_data.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces compute unit estimation for Orca and OKX providers. The implementation is a good step forward. My review focuses on a few areas for improvement: handling of silent failures in error-catching blocks, the use of console.log in a new debug utility which is not ideal for a library, and a minor inconsistency in the returned gasLimit for the Orca provider. The provided suggestions aim to make the code more robust and maintainable.

@0xh3rman 0xh3rman merged commit e28975c into main Feb 19, 2026
4 checks passed
@0xh3rman 0xh3rman deleted the orca-estimate-limit branch February 19, 2026 11:45
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.

1 participant