-
Notifications
You must be signed in to change notification settings - Fork 32
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
Conversation
WalkthroughThe updates involve enhancing the SDK router's functionality. New test cases and methods for slippage application and deadline modification have been introduced for Changes
Poem
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? TipsChat with CodeRabbit Bot (
|
There was a problem hiding this 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
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 ofbridgeModuleName
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 theSynapseSDK
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 thesdk.ts
file and in thebridge.ts
file under theoperations
directory. The property is initialized in theSynapseSDK
class constructor and is used in an asynchronous map operation inbridge.ts
. This suggests thatallRouterSets
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 inbridge.ts
, it's not possible to fully assess the security implications or whether it adheres to best practices.* 51-51: The initialization of `allRouterSets` with both `synapseRouterSet` and `synapseCCTPRouterSet` is consistent with the PR's objectives to enhance bridge functionality.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 tsLength of output: 297
- 57-57: The
allBridgeQuotes
method is added to theSynapseSDK
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:
- The method is assigned to the
SynapseSDK
class inpackages/sdk-router/src/sdk.ts
.- There are tests written for
allBridgeQuotes
inpackages/sdk-router/src/sdk.test.ts
.- The actual implementation of the
allBridgeQuotes
function is inpackages/sdk-router/src/operations/bridge.ts
.This confirms that the
allBridgeQuotes
method is present in theSynapseSDK
class, has an associated test suite, and the implementation is located in theoperations/bridge.ts
file. The method appears to be correctly implemented and securely added to the class, as per the PR's objectives.* 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.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
packages/sdk-router/src/module/query.ts (3)
113-117: The
modifyDeadline
function correctly creates a newQuery
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 theminAmountOut
of a query and returns a newQuery
object. The use ofinvariant
ensures that the slippage parameters are valid before applying them.162-166: The
applySlippageInBips
function is a specialized version ofapplySlippage
that uses basis points. It reuses theapplySlippage
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 newallBridgeQuotes
function to retrieve and sort quotes, and then select the best quote based on theexcludeCCTP
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 bymaxAmountOut
. 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 theminAmountOut
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 withapplySlippage
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.
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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
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 withapplySlippage
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.
Description
This PR aims to expand the bridge-related functionality:
allBridgeQuotes()
function that returns all quotes for bridging using all available bridge modules.bridgeModuleName
is included into eachBridgeQuote
object, allowing the consumer to do filtering on their side, if required.Query
object, which is required for every bridge or swap interaction:modifyDeadline
to set the query's deadline.applySlippage
andapplySlippageInBips
to apply the slippage to the query's "amount out"Additional context
#1695 will be rebased once this is merged into master.
Summary by CodeRabbit
New Features
Enhancements
Refactor
findBestRoute
function to streamline the SDK's exposed functionality.Bug Fixes