Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK: all quotes, Query modifications #1716

Merged
merged 10 commits into from
Dec 27, 2023
Merged

SDK: all quotes, Query modifications #1716

merged 10 commits into from
Dec 27, 2023

Conversation

ChiTimesChi
Copy link
Collaborator

@ChiTimesChi ChiTimesChi commented Dec 26, 2023

Description
This PR aims to expand the bridge-related functionality:

  • Adds allBridgeQuotes() function that returns all quotes for bridging using all available bridge modules.
    • bridgeModuleName is included into each BridgeQuote object, allowing the consumer to do filtering on their side, if required.
    • The list of "bridge quotes" is sorted by the expected amount out on destination chain in descending order.

    Optional deadline parameter allows to set a default deadline for all returned bridge quotes.

  • Adds generic functions for modifying the Query object, which is required for every bridge or swap interaction:
    • modifyDeadline to set the query's deadline.
    • applySlippage and applySlippageInBips to apply the slippage to the query's "amount out"

    Both functions do NOT modify the input Query and instead return a new object. This allows consumer to fetch the bridge quote once and then additionally modify it as per user settings (which could as well be not static).

Additional context
#1695 will be rebased once this is merged into master.

Summary by CodeRabbit

  • New Features

    • Introduced new slippage and deadline modification functions for enhanced quote calculations.
    • Added functionality to retrieve and filter quotes from multiple bridge modules.
  • Enhancements

    • Implemented new test suite for validating multi-bridge quote retrieval.
  • Refactor

    • Removed the findBestRoute function to streamline the SDK's exposed functionality.
  • Bug Fixes

    • Adjusted quote functions to ensure accurate and reliable financial data.

Copy link
Contributor

coderabbitai bot commented Dec 26, 2023

Walkthrough

The updates involve enhancing the SDK router's functionality. New test cases and methods for slippage application and deadline modification have been introduced for RouterQuery structures. The findBestRoute function is no longer exported, indicating a possible refactoring or feature deprecation. The bridge operations now handle multiple bridge modules, suggesting expanded compatibility or improved quote retrieval. Additionally, the SynapseSDK class has been updated with methods corresponding to the new functionalities and a test suite for the allBridgeQuotes method.

Changes

File Path Change Summary
.../sdk-router/src/module/query.test.ts Added tests for modifyDeadline, applySlippage, and applySlippageInBips.
.../sdk-router/src/module/types.ts Removed findBestRoute from exports.
.../sdk-router/src/operations/bridge.ts Updated bridgeQuote and allBridgeQuotes for enhanced bridge module handling.
.../sdk-router/src/sdk.test.ts Added allBridgeQuotes test suite in the SynapseSDK block.
.../sdk-router/src/sdk.ts Added RouterSet, methods for slippage and deadline modification, allRouterSets property, and allBridgeQuotes method.

Poem

🐰✨
In the burrows of code, changes abound,
Slippage tweaked, and deadlines round.
Bridges span wider, quotes align,
SynapseSDK grows, by design. 🌉🔄

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file
    • @coderabbitai modularize this function
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Examples:
    • @coderabbitai gather interesting statistics about this repository and render them in a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai generate unit tests for the src/utils.ts file.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 225e70a and 43ed59f.
Files selected for processing (6)
  • packages/sdk-router/src/module/query.test.ts (2 hunks)
  • packages/sdk-router/src/module/query.ts (1 hunks)
  • packages/sdk-router/src/module/types.ts (1 hunks)
  • packages/sdk-router/src/operations/bridge.ts (2 hunks)
  • packages/sdk-router/src/sdk.test.ts (1 hunks)
  • packages/sdk-router/src/sdk.ts (3 hunks)
Files skipped from review due to trivial changes (1)
  • packages/sdk-router/src/sdk.test.ts
Additional comments: 13
packages/sdk-router/src/module/types.ts (1)
  • 76-78: The BridgeRoute type definition is consistent with the rest of the type definitions and includes all necessary properties for representing a bridge route. The addition of bridgeModuleName aligns with the PR's objective to allow filtering by bridge module.
packages/sdk-router/src/sdk.ts (4)
  • 2-24: The addition of allRouterSets as a public property in the SynapseSDK class is a significant change. It's important to ensure that this property is intended to be public and that its usage is secure and consistent with the SDK's design.
Verification successful

The search results indicate that the allRouterSets property is indeed used within the sdk.ts file and in the bridge.ts file under the operations directory. The property is initialized in the SynapseSDK class constructor and is used in an asynchronous map operation in bridge.ts. This suggests that allRouterSets is being used to iterate over router sets, likely as part of the functionality to handle bridge operations.

Based on the information provided, there are no immediate red flags regarding the security or correctness of the allRouterSets usage. However, without a broader view of the context in which it's used, especially in bridge.ts, it's not possible to fully assess the security implications or whether it adheres to best practices.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the allRouterSets property is used securely throughout the codebase.
rg --type typescript "allRouterSets"

Length of output: 71



Script:

#!/bin/bash
# Verify that the allRouterSets property is used securely throughout the codebase.
rg "allRouterSets" --type ts

Length of output: 297

* 51-51: The initialization of `allRouterSets` with both `synapseRouterSet` and `synapseCCTPRouterSet` is consistent with the PR's objectives to enhance bridge functionality.
  • 57-57: The allBridgeQuotes method is added to the SynapseSDK class. It's crucial to ensure that this method is implemented correctly and securely, as it's a key part of the PR's objectives.
Verification successful

The search for the allBridgeQuotes method in the codebase has produced several results:

  1. The method is assigned to the SynapseSDK class in packages/sdk-router/src/sdk.ts.
  2. There are tests written for allBridgeQuotes in packages/sdk-router/src/sdk.test.ts.
  3. The actual implementation of the allBridgeQuotes function is in packages/sdk-router/src/operations/bridge.ts.

This confirms that the allBridgeQuotes method is present in the SynapseSDK class, has an associated test suite, and the implementation is located in the operations/bridge.ts file. The method appears to be correctly implemented and securely added to the class, as per the PR's objectives.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the implementation of the allBridgeQuotes method.
rg --type typescript "allBridgeQuotes"

Length of output: 73



Script:

#!/bin/bash
# Verify the implementation of the allBridgeQuotes method without specifying file type.
rg "allBridgeQuotes"

Length of output: 538

* 79-81: The addition of `applySlippage`, `applySlippageInBips`, and `modifyDeadline` methods to the `SynapseSDK` class is consistent with the PR's objectives to allow for more granular control over query parameters.
packages/sdk-router/src/module/query.ts (3)
  • 113-117: The modifyDeadline function correctly creates a new Query object with an updated deadline, adhering to the principle of immutability by not modifying the original object.

  • 131-148: The applySlippage function correctly applies slippage to the minAmountOut of a query and returns a new Query object. The use of invariant ensures that the slippage parameters are valid before applying them.

  • 162-166: The applySlippageInBips function is a specialized version of applySlippage that uses basis points. It reuses the applySlippage function, which is good practice to avoid code duplication.

packages/sdk-router/src/operations/bridge.ts (2)
  • 89-108: The bridgeQuote function has been modified to use the new allBridgeQuotes function to retrieve and sort quotes, and then select the best quote based on the excludeCCTP parameter. This change aligns with the PR's objectives and appears to be implemented correctly.

  • 122-157: The allBridgeQuotes function fetches quotes from multiple bridge modules, filters them, and sorts them by maxAmountOut. This implementation is consistent with the PR's objectives to provide comprehensive bridge quotes.

packages/sdk-router/src/module/query.test.ts (3)
  • 79-127: The tests for modifyDeadline correctly check that the deadline is modified and that the original query object remains unchanged. This is good practice to ensure immutability of function inputs.

  • 129-285: The tests for applySlippage cover a range of slippage percentages and ensure that the function correctly applies slippage to the minAmountOut property. The tests also verify that the original query object is not mutated, which is a good practice for functional programming.

  • 287-339: The tests for applySlippageInBips check for parity with applySlippage and include validation for negative and excessively high basis points, which could indicate potential misuse of the function. These tests are important for ensuring that the function behaves as expected in various scenarios.

Copy link

codecov bot commented Dec 26, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a96ebb3) 51.38047% compared to head (479efe7) 51.42416%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #1716         +/-   ##
===================================================
+ Coverage   51.38047%   51.42416%   +0.04368%     
===================================================
  Files            360         360                 
  Lines          24593       24611         +18     
  Branches         290         290                 
===================================================
+ Hits           12636       12656         +20     
  Misses         10722       10722                 
+ Partials        1235        1233          -2     
Flag Coverage Δ
packages 91.95710% <100.00000%> (+0.47357%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 43ed59f and 479efe7.
Files selected for processing (1)
  • packages/sdk-router/src/module/query.test.ts (2 hunks)
Additional comments: 3
packages/sdk-router/src/module/query.test.ts (3)
  • 79-127: The tests for modifyDeadline correctly check that the deadline is modified and that the original query object remains unchanged. This is good practice for ensuring immutability in functional programming.

  • 129-312: The tests for applySlippage cover a range of slippage percentages and check for immutability. They also include error handling for invalid slippage values. This thorough testing ensures the function behaves as expected under various conditions.

  • 315-381: The tests for applySlippageInBips ensure that it behaves consistently with applySlippage and that it handles edge cases such as negative basis points and values exceeding 100%. These tests are crucial for validating the correctness of slippage calculations.

@ChiTimesChi ChiTimesChi merged commit b5bf2b5 into master Dec 27, 2023
35 checks passed
@ChiTimesChi ChiTimesChi deleted the sdk/additional-utils branch December 27, 2023 11:17
@ChiTimesChi ChiTimesChi mentioned this pull request Dec 27, 2023
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants