-
Notifications
You must be signed in to change notification settings - Fork 10
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
Feat/add params smart route #325
Conversation
WalkthroughThe updates include version increments for two packages, 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? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 4
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- packages/oraidex-common/package.json (1 hunks)
- packages/oraidex-common/src/network.ts (1 hunks)
- packages/universal-swap/package.json (1 hunks)
- packages/universal-swap/src/handler.ts (16 hunks)
- packages/universal-swap/src/helper.ts (7 hunks)
- packages/universal-swap/src/types.ts (1 hunks)
- packages/universal-swap/src/universal-demos/alpha-smart-router.ts (3 hunks)
- packages/universal-swap/tests/index.spec.ts (4 hunks)
Files skipped from review due to trivial changes (3)
- packages/oraidex-common/package.json
- packages/oraidex-common/src/network.ts
- packages/universal-swap/package.json
Additional context used
Gitleaks
packages/universal-swap/src/universal-demos/alpha-smart-router.ts
484-484: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
493-493: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
498-498: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
514-514: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
523-523: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
528-528: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
533-533: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
Additional comments not posted (19)
packages/universal-swap/src/types.ts (1)
270-275
: LGTM! But verify the usage of the new interface.The new interface
RouterConfigSmartRoute
is well-defined. Ensure that the optional properties are correctly handled in the codebase.The code changes are approved.
Run the following script to verify the usage of the new interface:
Verification successful
Verification Successful: Optional Properties Handled Correctly
The
RouterConfigSmartRoute
interface is used in the codebase with consideration for its optional properties, as indicated by the usage of the?
operator. This confirms that the optional properties are being handled correctly. No further action is required.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of the new interface `RouterConfigSmartRoute`. # Test: Search for the interface usage. Expect: Correct handling of optional properties. rg --type typescript -A 5 $'RouterConfigSmartRoute'Length of output: 85
Script:
#!/bin/bash # Find all TypeScript files and search for the usage of the `RouterConfigSmartRoute` interface. fd --extension ts --exec rg 'RouterConfigSmartRoute' {}Length of output: 297
packages/universal-swap/src/universal-demos/alpha-smart-router.ts (3)
473-535
: LGTM! But verify the updated values and address potential security issues.The updated
swapAmount
andreturnAmount
values should be verified for correctness. Additionally, the flagged potential issues with generic API keys need to be addressed.The code changes are approved.
Run the following script to verify the updated values:
Address the flagged potential issues with generic API keys:
- tokenIn: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh", - tokenOut: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh", - poolId: "orai-orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh-3000000000-100", - tokenIn: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh", - tokenOut: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh", - poolId: "orai-orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd-3000000000-100", - tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", - poolId: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh-orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd-500000000-10", - tokenOut: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh"Verification successful
Verification Successful: Updated Values Confirmed
The
swapAmount
andreturnAmount
values have been successfully verified in thealpha-smart-router.ts
file. The changes align with the expected updates, and no discrepancies were found.
swapAmount: "88000000"
returnAmount: "521900530"
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the updated `swapAmount` and `returnAmount` values. # Test: Search for the updated values. Expect: Correct values in the codebase. rg --type typescript -A 5 $'swapAmount: "88000000"'Length of output: 87
Script:
#!/bin/bash # Description: Verify the updated `swapAmount` and `returnAmount` values in .ts files. # Test: Search for the updated values in .ts files. Expect: Correct values in the codebase. rg --glob '*.ts' -A 5 'swapAmount: "88000000"'Length of output: 580
Tools
Gitleaks
484-484: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
493-493: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
498-498: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
514-514: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
523-523: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
528-528: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
533-533: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
575-575
: LGTM! But verify the updated value.The updated
isIbcWasm
option should be verified for correctness.The code changes are approved.
Run the following script to verify the updated value:
Line range hint
547-571
: LGTM! But verify the updated values and test the changes.The updated values should be verified for correctness. Additionally, the changes should be tested to ensure they do not introduce any issues.
The code changes are approved.
Run the following script to verify the updated values:
Do you want me to generate the unit testing code or open a GitHub issue to track this task?
Verification successful
Verification Successful: Updated Values Confirmed
The updates to
originalToToken
anduserSlippage
in thealpha-smart-router.ts
file have been verified and are consistent with the intended changes. The modifications are correctly implemented.
originalToToken
is set to find a token withcoinGeckoId
as "tether" andchainId
as "0x38".userSlippage
is correctly set to1
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the updated values in the `alphaSwapToOraichain` function. # Test: Search for the updated values. Expect: Correct values in the codebase. rg --type typescript -A 5 $'fromAmount: 210'Length of output: 80
Script:
#!/bin/bash # Description: Verify the updated values in the `alphaSwapToOraichain` function. # Test: Search for the updated values. Expect: Correct values in the codebase. rg --type ts -A 5 $'fromAmount: 210'Length of output: 37
Script:
#!/bin/bash # Description: Verify the updated values in the `alphaSwapToOraichain` function by searching for related changes. # Test: Search for related updated values. Expect: Correct values in the codebase. rg --type ts -A 5 $'originalToToken: flattenTokens.find((t) => t.coinGeckoId === "tether" && t.chainId === "0x38")' rg --type ts -A 5 $'userSlippage: 1'Length of output: 2105
Script:
#!/bin/bash # Description: Verify the presence of the `originalToToken` update in the `alphaSwapToOraichain` function. # Test: Search for a broader pattern related to `originalToToken`. rg --type ts -A 5 $'originalToToken'Length of output: 41989
packages/universal-swap/src/helper.ts (7)
56-59
: LGTM!The new imports are necessary for the new functionality introduced in the file.
The code changes are approved.
Line range hint
534-545
: LGTM!The changes ensure that the new configuration option
dontAllowSwapAfter
is utilized in the routing logic.The code changes are approved.
564-568
: LGTM!The changes ensure that the new configuration option
dontAllowSwapAfter
is utilized in the routing logic.The code changes are approved.
625-625
: LGTM!The changes ensure that the new configuration option
RouterConfigSmartRoute
is utilized in the routing logic.The code changes are approved.
716-716
: LGTM!The changes ensure that the new configuration option
RouterConfigSmartRoute
is utilized in the routing logic.The code changes are approved.
1137-1137
: LGTM!The changes ensure type safety and improve code readability.
The code changes are approved.
1181-1232
: LGTM!The changes ensure type safety and improve code readability.
The code changes are approved.
packages/universal-swap/src/handler.ts (6)
74-75
: LGTM!The function correctly handles the optional
decimals
parameter and throws an error if the token is not found.The code changes are approved.
619-635
: LGTM!The function correctly constructs a message for converting tokens in the smart router context.
The code changes are approved.
Line range hint
1232-1254
: LGTM!The function correctly handles the logic for building swap messages from the smart route.
The code changes are approved.
1198-1198
: Improve error handling.The function correctly handles the logic for calculating the minimum receive amount. However, the error handling can be improved by providing more context.
Provide more context in the error message:
- if (!this.swapData.originalFromToken.feeCurrencies) - throw generateError( - `This token ${JSON.stringify( - this.swapData.originalFromToken - )} does not have fee currencies. getGasPriceFromToken is not called correctly` - ); + if (!this.swapData.originalFromToken.feeCurrencies) + throw generateError( + `This token ${JSON.stringify( + this.swapData.originalFromToken + )} does not have fee currencies. Ensure the token has fee currencies before calling getGasPriceFromToken.` + );Likely invalid or redundant comment.
1429-1429
: Improve error handling.The function correctly handles the logic for generating messages to transfer tokens using IBC Wasm contract. However, the error handling can be improved by providing more context.
Provide more context in the error message:
- if (!ibcWasmContractAddress) - throw generateError("IBC Wasm source port is invalid. Cannot transfer to the destination chain"); + if (!ibcWasmContractAddress) + throw generateError("IBC Wasm source port is invalid. Ensure the source port is correctly defined to transfer to the destination chain.");Likely invalid or redundant comment.
1270-1271
: Improve error handling.The function correctly handles the logic for generating swap messages. However, the error handling can be improved by providing more context.
Provide more context in the error message:
- if (!routes?.length) throw "Route not found"; + if (!routes?.length) throw generateError("Route not found. Ensure the routes are correctly defined.");Likely invalid or redundant comment.
packages/universal-swap/tests/index.spec.ts (2)
326-326
: LGTM!The constructor update enhances the flexibility of the configuration object by allowing additional properties to be included without losing the default wallet settings.
The code changes are approved.
1178-1178
: LGTM!The test now directly calls
UniversalSwapHelper.flattenSmartRouters
, indicating a shift towards a more modular design.The code changes are approved.
Code Coverage Summary
Diff against main
Results for commit: 181b5a4 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
Summary by CodeRabbit
New Features
@oraichain/oraidex-common
and@oraichain/oraidex-universal-swap
packages.UniversalSwapHandler
with a new method for converting tokens and improved token retrieval with optional decimal precision.RouterConfigSmartRoute
interface for better routing configuration.UniversalSwapHelper
for improved smart routing functionality.Bug Fixes
Documentation
alpha-smart-router
to reflect new transaction volumes and protocols.Tests