Skip to content

Conversation

0xh3rman
Copy link
Collaborator

@0xh3rman 0xh3rman commented Oct 3, 2025

No description provided.

Replaces passing AlienProvider as a method argument with a dedicated rpc_provider field in all swapper provider structs. Updates constructors and trait signatures to require rpc_provider on instantiation, simplifying method calls and improving consistency. Adjusts GemSwapper and related factory methods to propagate rpc_provider to all swappers. Updates tests and integration points accordingly.
This commit refactors swapper providers and clients (Cetus, Chainflip, Jupiter, etc.) to use generic HTTP and RPC client abstractions instead of direct AlienProvider usage. Adds default constructors for each swapper, updates method signatures, and improves error handling by mapping gem_client::ClientError to SwapperError. This enables easier integration and testing, and improves code modularity and maintainability.
Copy link

semanticdiff-com bot commented Oct 3, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  apps/daemon/src/consumers/mod.rs  100% smaller
  apps/daemon/src/worker/search/mod.rs  100% smaller
  apps/api/src/assets/cilent.rs  100% smaller
  crates/swapper/src/cetus/tx_builder.rs  62% smaller
  gemstone/src/gateway/mod.rs  61% smaller
  crates/swapper/src/chainflip/provider.rs  60% smaller
  crates/swapper/src/chainflip/broker/client.rs  56% smaller
  bin/gas-bench/src/client.rs  54% smaller
  crates/swapper/src/uniswap/v3/quoter_v2.rs  53% smaller
  crates/swapper/src/chainflip/tx_builder.rs  44% smaller
  crates/swapper/src/permit2_data.rs  42% smaller
  crates/swapper/src/alien/mock.rs  41% smaller
  crates/swapper/src/pancakeswap_aptos/mod.rs  35% smaller
  crates/swapper/src/thorchain/provider.rs  34% smaller
  crates/swapper/src/cetus/provider.rs  33% smaller
  crates/swapper/src/across/provider.rs  31% smaller
  gemstone/src/network/mod.rs  29% smaller
  crates/swapper/src/thorchain/mod.rs  28% smaller
  crates/swapper/src/jupiter/provider.rs  28% smaller
  crates/swapper/src/across/api.rs  28% smaller
  crates/swapper/src/uniswap/v4/provider.rs  27% smaller
  crates/swapper/src/hyperliquid/provider.rs  25% smaller
  crates/swapper/src/swapper.rs  24% smaller
  crates/swapper/src/proxy/provider.rs  24% smaller
  crates/swapper/src/approval/evm.rs  22% smaller
  crates/swapper/src/across/hubpool.rs  17% smaller
  crates/swapper/src/across/config_store.rs  17% smaller
  bin/gas-bench/src/main.rs  15% smaller
  crates/gem_evm/src/rpc/ankr/client.rs  15% smaller
  crates/swapper/src/error.rs  13% smaller
  gemstone/src/payment/mod.rs  12% smaller
  crates/swapper/src/uniswap/v3/provider.rs  11% smaller
  crates/swapper/tests/integration_test.rs  10% smaller
  crates/gem_jsonrpc/src/rpc.rs  9% smaller
  crates/gem_sui/src/rpc/client.rs  6% smaller
  gemstone/src/alien/mod.rs  6% smaller
  crates/gem_sui/src/models/inspect.rs  6% smaller
  crates/swapper/src/cetus/models.rs  6% smaller
  crates/swapper/src/uniswap/v3/path.rs  5% smaller
  gemstone/src/alien/target.rs  5% smaller
  gemstone/src/alien/reqwest_provider.rs  4% smaller
  gemstone/src/alien/error.rs  3% smaller
  gemstone/src/config/swap_config.rs  2% smaller
  crates/gem_evm/src/rpc/client.rs  1% smaller
  .github/workflows/ci.yml  0% smaller
  AGENTS.md Unsupported file format
  Cargo.lock Unsupported file format
  Cargo.toml Unsupported file format
  crates/gem_client/Cargo.toml Unsupported file format
  crates/gem_client/src/retry.rs  0% smaller
  crates/gem_evm/src/provider/preload.rs  0% smaller
  crates/gem_jsonrpc/Cargo.toml Unsupported file format
  crates/gem_jsonrpc/src/lib.rs  0% smaller
  crates/gem_sui/src/gas_budget.rs  0% smaller
  crates/gem_sui/src/lib.rs  0% smaller
  crates/gem_sui/src/models/coin_asset.rs  0% smaller
  crates/gem_sui/src/models/mod.rs  0% smaller
  crates/gem_tron/Cargo.toml Unsupported file format
  crates/gem_tron/src/models/mod.rs  0% smaller
  crates/gem_tron/src/rpc/client.rs  0% smaller
  crates/primitives/src/swap/approval.rs  0% smaller
  crates/swapper/Cargo.toml Unsupported file format
  crates/swapper/src/across/mod.rs  0% smaller
  crates/swapper/src/alien/error.rs  0% smaller
  crates/swapper/src/alien/mod.rs  0% smaller
  crates/swapper/src/alien/reqwest_provider.rs  0% smaller
  crates/swapper/src/approval/mod.rs  0% smaller
  crates/swapper/src/approval/tron.rs  0% smaller
  crates/swapper/src/asset.rs  0% smaller
  crates/swapper/src/cetus/api/client.rs  0% smaller
  crates/swapper/src/cetus/api/mod.rs  0% smaller
  crates/swapper/src/cetus/api/models.rs  0% smaller
  crates/swapper/src/cetus/api/test/stats_pool.json  0% smaller
  crates/swapper/src/cetus/default.rs  0% smaller
  crates/swapper/src/cetus/mod.rs  0% smaller
  crates/swapper/src/cetus/test/route_data.json  0% smaller
  crates/swapper/src/cetus/test/sui_all_coins.json  0% smaller
  crates/swapper/src/cetus/test/sui_dev_inspect.json  0% smaller
  crates/swapper/src/cetus/test/sui_suip_pool.json  0% smaller
  crates/swapper/src/cetus/test/sui_usdc_pool.json  0% smaller
  crates/swapper/src/chainflip/broker/mod.rs  0% smaller
  crates/swapper/src/chainflip/broker/model.rs  0% smaller
  crates/swapper/src/chainflip/capitalize.rs  0% smaller
  crates/swapper/src/chainflip/client/mod.rs  0% smaller
  crates/swapper/src/chainflip/client/model.rs  0% smaller
  crates/swapper/src/chainflip/client/swap.rs  0% smaller
  crates/swapper/src/chainflip/client/test/btc_eth_quote.json  0% smaller
  crates/swapper/src/chainflip/default.rs  0% smaller
  crates/swapper/src/chainflip/mod.rs  0% smaller
  crates/swapper/src/chainflip/model.rs  0% smaller
  crates/swapper/src/chainflip/price.rs  0% smaller
  crates/swapper/src/chainflip/seed.rs  0% smaller
  crates/swapper/src/chainflip/test/chainflip_boost_quotes.json  0% smaller
  crates/swapper/src/chainflip/test/chainflip_quotes.json  0% smaller
  crates/swapper/src/chainflip/test/chainflip_sol_arb_usdc_quote_data.json  0% smaller
  crates/swapper/src/chainlink.rs  0% smaller
  crates/swapper/src/client_factory.rs  0% smaller
  crates/swapper/src/config.rs  0% smaller
  crates/swapper/src/eth_address.rs  0% smaller
  crates/swapper/src/hyperliquid/mod.rs  0% smaller
  crates/swapper/src/jupiter/client.rs  0% smaller
  crates/swapper/src/jupiter/default.rs  0% smaller
  crates/swapper/src/jupiter/mod.rs  0% smaller
  crates/swapper/src/jupiter/model.rs  0% smaller
  crates/swapper/src/jupiter/token_account.rs  0% smaller
  crates/swapper/src/lib.rs  0% smaller
  crates/swapper/src/models.rs  0% smaller
  crates/swapper/src/pancakeswap_aptos/client.rs  0% smaller
  crates/swapper/src/pancakeswap_aptos/default.rs  0% smaller
  crates/swapper/src/pancakeswap_aptos/model.rs  0% smaller
  crates/swapper/src/proxy/client.rs  0% smaller
  crates/swapper/src/proxy/mayan/explorer.rs  0% smaller
  crates/swapper/src/proxy/mayan/mod.rs  0% smaller
  crates/swapper/src/proxy/mayan/model.rs  0% smaller
  crates/swapper/src/proxy/mod.rs  0% smaller
  crates/swapper/src/proxy/provider_factory.rs  0% smaller
  crates/swapper/src/proxy/symbiosis/mod.rs  0% smaller
  crates/swapper/src/proxy/symbiosis/model.rs  0% smaller
  crates/swapper/src/proxy/test/eth_to_sui_swift.json  0% smaller
  crates/swapper/src/proxy/test/mctp_pending.json  0% smaller
  crates/swapper/src/proxy/test/swift_refunded.json  0% smaller
  crates/swapper/src/slippage.rs  0% smaller
  crates/swapper/src/swapper_trait.rs  0% smaller
  crates/swapper/src/testkit.rs  0% smaller
  crates/swapper/src/thorchain/asset.rs  0% smaller
  crates/swapper/src/thorchain/chain.rs  0% smaller
  crates/swapper/src/thorchain/client.rs  0% smaller
  crates/swapper/src/thorchain/default.rs  0% smaller
  crates/swapper/src/thorchain/memo.rs  0% smaller
  crates/swapper/src/thorchain/model.rs  0% smaller
  crates/swapper/src/uniswap/deadline.rs  0% smaller
  crates/swapper/src/uniswap/default.rs  0% smaller
  crates/swapper/src/uniswap/fee_token.rs  0% smaller
  crates/swapper/src/uniswap/mod.rs  0% smaller
  crates/swapper/src/uniswap/quote_result.rs  0% smaller
  crates/swapper/src/uniswap/swap_route.rs  0% smaller
  crates/swapper/src/uniswap/universal_router/aerodrome.rs  0% smaller
  crates/swapper/src/uniswap/universal_router/mod.rs  0% smaller
  crates/swapper/src/uniswap/universal_router/oku.rs  0% smaller
  crates/swapper/src/uniswap/universal_router/pancakeswap.rs  0% smaller
  crates/swapper/src/uniswap/universal_router/uniswap_v3.rs  0% smaller
  crates/swapper/src/uniswap/universal_router/wagmi.rs  0% smaller
  crates/swapper/src/uniswap/v3/commands.rs  0% smaller
  crates/swapper/src/uniswap/v3/mod.rs  0% smaller
  crates/swapper/src/uniswap/v4/commands.rs  0% smaller
  crates/swapper/src/uniswap/v4/mod.rs  0% smaller
  crates/swapper/src/uniswap/v4/path.rs  0% smaller
  crates/swapper/src/uniswap/v4/quoter.rs  0% smaller
  gemstone/Cargo.toml Unsupported file format
  gemstone/src/alien/client.rs  0% smaller
  gemstone/src/alien/mime.rs  0% smaller
  gemstone/src/alien/provider.rs  0% smaller
  gemstone/src/block_explorer/mod.rs  0% smaller
  gemstone/src/ethereum/jsonrpc.rs  0% smaller
  gemstone/src/ethereum/mod.rs  0% smaller
  gemstone/src/gem_swapper/error.rs  0% smaller
  gemstone/src/gem_swapper/mod.rs  0% smaller
  gemstone/src/gem_swapper/permit2.rs  0% smaller
  gemstone/src/gem_swapper/remote_types.rs  0% smaller
  gemstone/src/lib.rs  0% smaller
  gemstone/src/models/custom_types.rs  0% smaller
  gemstone/src/network/alien_provider/mod.rs  0% smaller
  gemstone/src/payment/solana_pay.rs  0% smaller
  gemstone/src/sui/mod.rs  0% smaller
  gemstone/src/sui/rpc/client.rs  0% smaller
  gemstone/src/sui/rpc/mod.rs  0% smaller
  gemstone/src/swapper/approval/mod.rs  0% smaller
  gemstone/src/swapper/approval/tron.rs  0% smaller
  gemstone/src/swapper/cetus/api/client.rs  0% smaller
  gemstone/src/swapper/chainflip/broker/mod.rs  0% smaller
  gemstone/src/swapper/chainflip/client/swap.rs  0% smaller
  gemstone/src/swapper/chainlink.rs  0% smaller
  gemstone/src/swapper/custom_types.rs  0% smaller
  gemstone/src/swapper/jupiter/client.rs  0% smaller
  gemstone/src/swapper/pancakeswap_aptos/client.rs  0% smaller
  gemstone/src/swapper/proxy/client.rs  0% smaller
  gemstone/src/swapper/proxy/provider_factory.rs  0% smaller
  gemstone/src/swapper/remote_models.rs  0% smaller
  gemstone/src/swapper/thorchain/client.rs  0% smaller
  gemstone/src/swapper/uniswap/universal_router/mod.rs  0% smaller
  gemstone/src/tron/client.rs  0% smaller
  gemstone/src/tron/mod.rs  0% smaller
  gemstone/src/tron/model.rs  0% smaller
  gemstone/tests/ios/GemTest/GemTest/ContentView.swift  0% smaller
  gemstone/tests/ios/GemTest/GemTest/Extension/Gemstone+Extension.swift  0% smaller
  gemstone/tests/ios/GemTest/GemTest/ViewModel.swift  0% smaller
  justfile Unsupported file format

@0xh3rman 0xh3rman marked this pull request as draft October 3, 2025 02:26
Copy link
Contributor

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 undertakes a substantial refactoring of the swapper infrastructure within the project. The primary objective is to enhance modularity, testability, and consistency by standardizing the way RPC clients are created and utilized across different blockchain integrations. This is achieved by abstracting client creation behind a new factory pattern and consolidating chain-specific RPC logic into dedicated crates, leading to a cleaner and more maintainable codebase for all supported swapper providers.

Highlights

  • Refactored RPC Client Handling: The core change involves a significant refactoring of how RPC clients are managed across various swapper implementations. This introduces a generic Client trait and an EvmRpcClientFactory to decouple swapper providers from direct AlienProvider usage for RPC calls, centralizing client instantiation.
  • Consolidated EVM and Sui RPC Logic: EVM-specific RPC client implementations and Sui RPC client logic have been moved from the gemstone crate into their respective gem_evm and gem_sui crates. This includes adding new methods like gas_price and estimate_gas_tx for EVM, and get_coin_assets, get_reference_gas_price_u64, and inspect_tx_block for Sui.
  • Updated Swapper Provider Interfaces: The Swapper trait methods (fetch_quote, fetch_permit2_for_quote, fetch_quote_data, get_swap_result) have been updated to remove the Arc<dyn AlienProvider> argument, indicating that swapper providers now internally manage their client factories.
  • Tron Integration Enhancements: Tron-related functionality has been enhanced with new alloy-primitives and alloy-sol-types dependencies, adding methods for token allowance checks and energy estimation, and improving error handling for contract calls.
  • New Default Constructors for Swappers: New default.rs modules have been introduced for several swapper providers (Across, Cetus, Chainflip, Jupiter, PancakeSwapAptos, ThorChain, Uniswap V3/V4) to provide standardized constructors using AlienClient and AlienEvmRpcFactory.
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
Contributor

@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 a significant and well-executed refactoring of the swapper providers. The main goal of decoupling providers from AlienProvider and using a generic Client or client factories has been achieved, which will improve testability and modularity. The changes are extensive and touch many parts of the gemstone and related crates.

My review focuses on a few key areas where I've identified potential issues: an incorrect gas budget calculation in the Sui provider, a potential silent error in Tron's energy estimation, and the removal of some tests in the Chainflip provider.

Overall, this is a great improvement to the codebase architecture. Addressing the points below will help ensure the correctness and robustness of the new implementation.

Moved Sui and Tron RPC client implementations from gemstone to gem_sui and gem_tron crates, introducing network/sui.rs and network/tron.rs for unified client creation. Updated Across, Cetus, and approval logic to use new client interfaces. Added new models and methods for Sui coin assets and Tron contract calls. Removed obsolete gemstone/src/ethereum/jsonrpc.rs and gemstone/src/sui/rpc modules. Updated dependencies and feature flags for gem_tron. Refactored swapper providers to use new client patterns and improved error handling.
Removes unnecessary `#![cfg(feature = "rpc")]` attributes from model files and updates imports in Cetus provider tests to use gem_sui models. Adds a Default implementation for HyperCoreBridge to simplify instantiation.
@0xh3rman 0xh3rman force-pushed the swapper-gem-client branch from 56c916b to a8696ca Compare October 6, 2025 05:13
@0xh3rman 0xh3rman marked this pull request as ready for review October 7, 2025 13:53
@0xh3rman 0xh3rman changed the title Swapper Refactoring Add gem_swapper crate Oct 7, 2025
@0xh3rman 0xh3rman changed the title Add gem_swapper crate Move swapper out of gemstone Oct 8, 2025
@0xh3rman 0xh3rman merged commit eca3249 into main Oct 8, 2025
5 checks passed
@0xh3rman 0xh3rman deleted the swapper-gem-client branch October 8, 2025 02:54
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