Skip to content

Stream swap quotes#1769

Draft
0xh3rman wants to merge 1 commit intomainfrom
stream-quote
Draft

Stream swap quotes#1769
0xh3rman wants to merge 1 commit intomainfrom
stream-quote

Conversation

@0xh3rman
Copy link
Contributor

@0xh3rman 0xh3rman commented Mar 5, 2026

Changes

  • Stream swap quotes progressively instead of waiting for all providers to finish
  • Add getProvidersForRequest to Rust core to get eligible providers upfront
  • Fetch quotes per-provider concurrently via TaskGroup + AsyncStream, yielding results as they arrive
  • Sort accumulated quotes by best rate and always select the top quote
  • Move SwapQuoteInput to SwapService for reuse across layers
  • Handle InputAmountError prioritization (pick lowest min amount) on the iOS side

@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 refactors the swap quote fetching mechanism to provide a more responsive and robust user experience. By streaming quotes progressively and processing them concurrently, the application can display available swap options faster. It also introduces improved error handling for input amounts and centralizes key data structures for better maintainability.

Highlights

  • Progressive Swap Quote Streaming: Implemented progressive streaming of swap quotes, allowing the UI to update as quotes become available from different providers, rather than waiting for all providers to respond.
  • Rust Core Integration for Providers: Added a new getProvidersForRequest function to the Rust core, enabling the upfront retrieval of eligible swap providers for a given request.
  • Concurrent Quote Fetching: Utilized Swift's TaskGroup and AsyncStream to fetch quotes concurrently from each provider, yielding results as they are received.
  • Best Rate Quote Selection: Quotes are now accumulated, sorted by the best rate (highest toValue), and the top quote is automatically selected and applied.
  • SwapQuoteInput Centralization: The SwapQuoteInput struct was moved to the SwapService package to promote reuse and better architectural organization across different layers.
  • InputAmountError Prioritization: Enhanced error handling on the iOS side to prioritize and display the lowest minimum amount requirement when multiple InputAmountError instances are encountered.

🧠 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
  • Features/Swap/Sources/Types/SwapFetchTrigger.swift
    • Imported SwapService to access shared swap functionalities.
  • Features/Swap/Sources/Types/SwapQuoteInput.swift
    • Removed the local definition of SwapQuoteInput as it was moved to SwapService.
  • Features/Swap/Sources/ViewModels/SwapSceneViewModel.swift
    • Refactored fetchQuotes to use an AsyncStream for progressive quote updates.
    • Added logic to accumulate, sort, and select the best swap quote as they arrive.
    • Implemented prioritizedSwapError to handle and prioritize InputAmountError instances.
    • Updated the usage of GemSwapperMock to align with new fetchQuotes signature.
  • Features/Swap/Tests/SwapTests/SwapQuoteInputTests.swift
    • Imported SwapService to resolve dependencies for SwapQuoteInput.
  • Features/Swap/Tests/SwapTests/SwapSceneViewModelTests.swift
    • Adjusted GemSwapperMock initialization to use quoteByProvider instead of quotes.
  • Packages/FeatureServices/SwapService/SwapQuoteInput.swift
    • Added the SwapQuoteInput struct, centralizing its definition for reuse.
  • Packages/FeatureServices/SwapService/SwapQuotesProvider.swift
    • Modified fetchQuotes to return an AsyncStream of Result<SwapperQuote, Error>.
    • Introduced fetchFromProviders to concurrently fetch quotes from multiple providers using TaskGroup.
    • Updated imports to include SwapperProviderType and remove BigInt.
  • Packages/FeatureServices/SwapService/SwapService.swift
    • Imported SwapperProvider and SwapperProviderType for provider-specific operations.
    • Added getProvidersForQuote to retrieve eligible providers for a given swap request.
    • Implemented getQuoteByProvider to fetch a quote from a specific provider.
    • Created buildRequest as a private helper to construct SwapperQuoteRequest objects.
    • Removed the previous getQuotes method that returned an array of quotes.
    • Updated getQuoteData to call swapper.getQuoteData instead of swapper.fetchQuoteData.
  • Packages/FeatureServices/SwapService/TestKit/GemSwapperMock.swift
    • Removed the quotes property and related initializers.
    • Updated fetchQuote to getQuote and fetchQuoteData to getQuoteData to match new protocol.
    • Added a mock implementation for getProvidersForRequest.
    • Enhanced fetchQuoteByProvider to include delay and error handling.
  • core
    • Updated the core subproject commit to 4069ddaba46315f7db84597d59495c7e5684ec11.
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 refactors the swap quote fetching mechanism to use a streaming approach with AsyncStream and TaskGroup, aiming to significantly improve the user experience by displaying quotes as they arrive. However, a critical resource leak has been identified in the SwapQuotesProvider.fetchQuotes method where the background task responsible for fetching quotes is not cancelled when the stream terminates, potentially leading to unnecessary resource consumption. Additionally, a couple of suggestions have been made in SwapSceneViewModel.swift to enhance code clarity and maintainability.

@0xh3rman 0xh3rman marked this pull request as draft March 5, 2026 06:02
@0xh3rman 0xh3rman force-pushed the stream-quote branch 2 times, most recently from 0d43b4d to c4ebc9f Compare March 5, 2026 06:15
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