Skip to content

Add provider prioritization and sorter + OKX x Base#1002

Merged
0xh3rman merged 11 commits intomainfrom
priority-swapper
Mar 13, 2026
Merged

Add provider prioritization and sorter + OKX x Base#1002
0xh3rman merged 11 commits intomainfrom
priority-swapper

Conversation

@0xh3rman
Copy link
Collaborator

Changes:

  • Introduce a PrioritizedProvider trait and a generic sort_by_priority_then_amount function in primitives::priority to centralize provider-priority-based sorting (with threshold override).
  • Wire the new sorter into fiat client and swapper quote sorting, and implement PrioritizedProvider for FiatProvider and SwapProvider.
  • Remove direct Cetus enum usages in favor of CetusAggregator where appropriate, add Base chain support for OKX in proxy provider, and export the new priority module from primitives.
  • Includes unit tests for priority sorting and provider behavior.

Introduce a PrioritizedProvider trait and a generic sort_by_priority_then_amount function in primitives::priority to centralize provider-priority-based sorting (with threshold override). Wire the new sorter into fiat client and swapper quote sorting, and implement PrioritizedProvider for FiatProvider and SwapProvider. Remove direct Cetus enum usages in favor of CetusAggregator where appropriate, add Base chain support for OKX in proxy provider, and export the new priority module from primitives. Includes unit tests for priority sorting and provider behavior.
@semanticdiff-com
Copy link

semanticdiff-com bot commented Mar 11, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  crates/swapper/src/models.rs  39% smaller
  gemstone/src/block_explorer/mod.rs  39% smaller
  crates/swapper/src/proxy/provider.rs  32% smaller
  crates/fiat/src/client.rs  8% smaller
  crates/primitives/src/swap_provider.rs  3% smaller
  crates/gem_sui/src/provider/transactions_mapper.rs  0% smaller
  crates/primitives/src/fiat_provider.rs  0% smaller
  crates/primitives/src/lib.rs  0% smaller
  crates/primitives/src/priority.rs  0% smaller
  crates/swapper/src/swapper.rs  0% smaller
  crates/swapper/src/testkit.rs  0% smaller
  gemstone/src/gem_swapper/remote_types.rs  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 refactors and enhances how providers are prioritized and sorted across the application, particularly for fiat and swap quotes. By introducing a generic PrioritizedProvider trait and a centralized sorting function, it streamlines the logic for determining the best provider based on configurable priority and amount thresholds. Additionally, it updates provider enumerations to use CetusAggregator consistently and expands OKX support to include the Base chain, improving flexibility and coverage.

Highlights

  • Centralized Provider Sorting: Introduced a new PrioritizedProvider trait and a generic sort_by_priority_then_amount function to centralize provider-priority-based sorting with configurable threshold overrides.
  • Integration and Trait Implementation: Integrated the new sorting mechanism into fiat client and swapper quote sorting, and implemented the PrioritizedProvider trait for both FiatProvider and SwapProvider.
  • Provider Updates and Chain Support: Replaced direct Cetus enum usages with CetusAggregator where appropriate and expanded OKX support to include the Base chain in the proxy provider.
  • New Module and Testing: Exported the new priority module from primitives and included comprehensive unit tests for the sorting logic and provider behavior.

🧠 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/fiat/src/client.rs
    • Removed the previously defined local sort_by_priority_then_amount and sort_by_priority_then_amount_order functions.
    • Updated fiat quote sorting functions to utilize the newly imported primitives::sort_by_priority_then_amount.
  • crates/gem_sui/src/provider/transactions_mapper.rs
    • Changed SwapProvider::Cetus to SwapProvider::CetusAggregator when mapping swap transactions.
  • crates/primitives/src/fiat_provider.rs
    • Imported the PrioritizedProvider trait.
    • Implemented the PrioritizedProvider trait for FiatProvider, defining provider_id, priority, and threshold_bps methods.
  • crates/primitives/src/lib.rs
    • Added a new priority module.
    • Exported PrioritizedProvider and sort_by_priority_then_amount from the priority module.
  • crates/primitives/src/priority.rs
    • Added a new file defining the PrioritizedProvider trait with methods for provider_id, priority, and threshold_bps.
    • Implemented the generic sort_by_priority_then_amount function which sorts based on provider priority, with an optional threshold override, and then by amount.
    • Included a helper function exceeds_threshold to check if an amount difference surpasses a provider's threshold.
    • Provided comprehensive unit tests for various sorting scenarios.
  • crates/primitives/src/swap_provider.rs
    • Imported the PrioritizedProvider trait.
    • Removed the Cetus variant from the SwapProvider enum.
    • Updated is_cross_chain and id implementations to remove references to Cetus and use CetusAggregator.
    • Added priority() and threshold_bps() methods to SwapProvider to define priority levels and default thresholds for different swap providers.
    • Implemented the PrioritizedProvider trait for SwapProvider.
    • Updated unit tests to include assertions for the new priority() and threshold_bps() methods.
  • crates/swapper/src/models.rs
    • Removed SwapperProvider::Cetus from the ProviderType matching logic.
  • crates/swapper/src/proxy/provider.rs
    • Added SwapperChainAsset::All(Chain::Base) to the list of supported chains for the "okx" provider.
  • crates/swapper/src/swapper.rs
    • Imported SwapProvider and sort_by_priority_then_amount.
    • Integrated the new sort_by_priority_then_amount function into the GemSwapper::get_quotes method to sort quotes based on provider priority and crypto amount.
  • gemstone/src/block_explorer/mod.rs
    • Removed SwapperProvider::Cetus from the Explorer matching logic.
  • gemstone/src/gem_swapper/remote_types.rs
    • Removed the Cetus variant from the SwapperProvider enum.
Activity
  • The author, 0xh3rman, created this pull request to introduce a centralized provider prioritization and sorting mechanism.
  • The changes include refactoring existing sorting logic, implementing a new trait for prioritized providers, and updating provider enumerations.
  • Unit tests were added to ensure the correctness of the new sorting logic.
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 robust and generic provider prioritization and sorting mechanism, which is a significant improvement for managing quote ordering in both fiat and swap functionalities. The new PrioritizedProvider trait and sort_by_priority_then_amount function centralize this logic, making the codebase more maintainable and extensible. The changes also correctly migrate from direct Cetus enum usages to CetusAggregator and add support for the Base chain to the OKX provider. However, there is a critical inconsistency identified in the SwapProvider's threshold_bps implementation and its corresponding unit tests that needs to be addressed.

Refactor primitives tests and provider threshold behavior.

- crates/primitives/src/priority.rs: compacted the sort_by_priority_then_amount signature, replaced MockProvider::new with two helpers (mock_id and mock_id_priority) and updated tests to use them; adjusted mock defaults and minor comment style.
- crates/primitives/src/swap_provider.rs: changed SwapProvider::threshold_bps() to return Some(200) (was 300) and updated tests to expect 200 for UniswapV3 and Okx.

These changes simplify test provider construction and align the threshold BPS values used in tests with the new default.
@0xh3rman 0xh3rman merged commit e9080c9 into main Mar 13, 2026
6 checks passed
@0xh3rman 0xh3rman deleted the priority-swapper branch March 13, 2026 10:08
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.

3 participants