Skip to content

Add Relay swap provider and client for evm chains#983

Merged
0xh3rman merged 22 commits intomainfrom
relay-evm
Mar 6, 2026
Merged

Add Relay swap provider and client for evm chains#983
0xh3rman merged 22 commits intomainfrom
relay-evm

Conversation

@0xh3rman
Copy link
Collaborator

@0xh3rman 0xh3rman commented Mar 4, 2026

No description provided.

@semanticdiff-com
Copy link

semanticdiff-com bot commented Mar 4, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  crates/swapper/src/relay/mod.rs  32% smaller
  crates/swapper/src/relay/chain.rs  12% smaller
  crates/swapper/src/relay/mapper.rs  8% smaller
  crates/swapper/src/relay/asset.rs  6% smaller
  crates/swapper/src/relay/model.rs  4% smaller
  crates/swapper/src/relay/testkit.rs  1% smaller
  crates/swapper/src/uniswap/v3/provider.rs  1% smaller
  crates/swapper/src/across/provider.rs  0% smaller
  crates/swapper/src/chainflip/provider.rs  0% smaller
  crates/swapper/src/fees.rs  0% smaller
  crates/swapper/src/hyperliquid/provider/bridge.rs  0% smaller
  crates/swapper/src/hyperliquid/provider/hyperliquid.rs  0% smaller
  crates/swapper/src/hyperliquid/provider/spot/provider.rs  0% smaller
  crates/swapper/src/jupiter/provider.rs  0% smaller
  crates/swapper/src/models.rs  0% smaller
  crates/swapper/src/near_intents/provider.rs  0% smaller
  crates/swapper/src/proxy/provider.rs  0% smaller
  crates/swapper/src/proxy/provider_factory.rs  0% smaller
  crates/swapper/src/relay/client.rs  0% smaller
  crates/swapper/src/relay/provider.rs  0% smaller
  crates/swapper/src/swapper.rs  0% smaller
  crates/swapper/src/swapper_trait.rs  0% smaller
  crates/swapper/src/testkit.rs  0% smaller
  crates/swapper/src/thorchain/provider.rs  0% smaller
  crates/swapper/src/uniswap/v4/provider.rs  0% smaller
  gemstone/src/gem_swapper/mod.rs  0% smaller
  gemstone/tests/ios/GemTest/GemTest/ViewModel.swift  0% smaller

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 Relay swap provider by introducing a dedicated client and provider implementation for EVM chains. The changes involve a major refactoring of the Relay integration, moving its logic into a new, self-contained module. This refactoring allows for more robust and independent management of Relay's functionalities, including asset mapping, quote fetching, and transaction handling, while also expanding its support to a wider array of EVM-compatible chains.

Highlights

  • New Relay Swap Provider and Client: A dedicated Relay swap provider and client have been introduced, moving the integration logic into its own module (crates/swapper/src/relay). This refactoring allows for independent management of Relay's functionalities.
  • Expanded EVM Chain Support: The Relay provider now supports a broader range of EVM chains and their associated assets, including Ethereum, SmartChain, Base, Arbitrum, Optimism, Polygon, AvalancheC, Linea, ZkSync, Hyperliquid, Berachain, Abstract, Mantle, Celo, and Stable.
  • Refactored Relay Integration: The previous Relay integration within crates/swapper/src/proxy/provider.rs has been removed, and its functionalities (fetching quotes, quote data, swap results, and vault addresses) are now handled by the new relay module.
  • Manta Chain Removal: The Manta chain was removed from the list of supported chains for the Relay provider in crates/swapper/src/models.rs.

🧠 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
  • crates/swapper/src/models.rs
    • Removed Manta from the Relay provider's supported chains.
  • crates/swapper/src/near_intents/provider.rs
    • Removed unused SwapStatus import.
  • crates/swapper/src/proxy/provider.rs
    • Removed relay module import and ClientExt from gem_client.
    • Removed the new_relay constructor function.
    • Removed Relay-specific logic for get_swap_result and get_vault_addresses.
    • Removed TransactionSwapMetadata import.
  • crates/swapper/src/proxy/provider_factory.rs
    • Removed the new_relay function.
  • crates/swapper/src/relay/asset.rs
    • Added LazyLock for SUPPORTED_CHAINS.
    • Added an extensive list of SUPPORTED_CHAINS for Relay, including various EVM chains and their stablecoin assets.
    • Added asset_to_currency function to map AssetId to Relay's currency string format for EVM chains.
    • Added unit tests for asset_to_currency.
  • crates/swapper/src/relay/chain.rs
    • Added chain_id, from_chain, to_chain, and is_evm methods to RelayChain.
    • Added unit tests for from_chain.
  • crates/swapper/src/relay/client.rs
    • Added RelayClient struct for interacting with the Relay API.
    • Implemented methods for get_quote, get_request, and get_chains.
  • crates/swapper/src/relay/mapper.rs
    • Added constants STEP_SWAP, STEP_DEPOSIT, STEP_APPROVE.
    • Added get_step_data function to extract relevant step data from Relay API responses.
    • Added gas_fee_amount function to extract gas fee.
    • Added map_quote_data function to transform Relay quote responses into SwapperQuoteData.
    • Added unit tests for map_evm_quote_data and get_step_data.
    • Imported ApprovalData from primitives::swap.
  • crates/swapper/src/relay/mod.rs
    • Added client and provider modules.
    • Defined DEFAULT_GAS_LIMIT.
    • Introduced Relay struct as the main provider, holding ProviderType, RpcProvider, and RelayClient.
    • Implemented with_client constructor for Relay.
  • crates/swapper/src/relay/model.rs
    • Added relay_trade_type function to map SwapMode to Relay's trade type string.
    • Defined new structs for RelayQuoteRequest, RelayAppFee, RelayQuoteResponse, RelayFees, RelayFeeAmount, Step, StepItem, StepData, QuoteDetails, SwapImpact, and CurrencyAmount for handling Relay API requests and responses.
    • Implemented helper methods for QuoteDetails (e.g., time_estimate_u32, slippage_bps) and Step (step_data).
    • Added Serialize derive to existing RelayQuoteResponse and related structs.
  • crates/swapper/src/relay/provider.rs
    • Implemented the Swapper trait for Relay.
    • Provided new constructor for Relay.
    • Implemented provider, supported_assets, fetch_quote, fetch_quote_data, get_swap_result, and get_vault_addresses methods.
    • Added check_evm_approval helper function for EVM chain approvals.
    • Included an integration test for test_relay_eth_to_base.
  • crates/swapper/src/relay/testkit.rs
    • Added mock implementations for Step, StepData, and StepItem for testing purposes.
  • crates/swapper/src/swapper.rs
    • Updated GemSwapper to use the new relay::Relay::new instead of provider_factory::new_relay.
    • Updated relay module import.
Activity
  • The pull request introduces a new Relay swap provider and client.
  • It refactors the existing Relay integration by moving it into a dedicated module.
  • The Relay provider now supports a wider range of EVM chains and assets.
  • Manta chain support was removed from the Relay provider.
  • Unit and integration tests were added for the new Relay provider functionality.
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 new swap provider for Relay, focusing on EVM chains, and removes the old proxy-based implementation. A critical security vulnerability was found in the RelayClient::get_request method, where unvalidated user input in URL construction could lead to query string injection or path traversal. Further improvements are needed in error handling, logical correctness of transaction parameter mapping, and ensuring consistent support across non-EVM chains.

@0xh3rman 0xh3rman requested a review from gemcoder21 March 5, 2026 08:16
Add two unit tests to crates/swapper/src/relay/mapper.rs that exercise map_swap_result using RelayRequestsResponse fixtures for Base USDC -> Ethereum USDC and Base USDC -> Solana USDT. The tests assert SwapStatus::Completed and validate metadata fields (from_asset/from_value and to_asset/to_value). Add the corresponding JSON fixtures under crates/swapper/src/relay/testdata/ (request_base_usdc_to_eth_usdc.json and request_base_usdc_to_sol_usdt.json).
@0xh3rman 0xh3rman merged commit 0e8b0e3 into main Mar 6, 2026
5 of 6 checks passed
@0xh3rman 0xh3rman deleted the relay-evm branch March 6, 2026 10:29
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