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

Feat/add pepe cat #334

Merged
merged 17 commits into from
Sep 24, 2024
Merged

Feat/add pepe cat #334

merged 17 commits into from
Sep 24, 2024

Conversation

haunv3
Copy link
Contributor

@haunv3 haunv3 commented Sep 24, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new constants for PEPE and CAT tokens, enhancing blockchain contract interactions.
    • Added a new function to facilitate token swaps from Oraichain to EVM-compatible chains.
  • Bug Fixes

    • Improved token retrieval logic for better accuracy and flexibility.
  • Documentation

    • Updated method signatures and deprecated older methods for clarity and improved functionality.
  • Chores

    • Version updates for packages to reflect the latest changes.

Copy link

coderabbitai bot commented Sep 24, 2024

Walkthrough

This pull request introduces several updates across multiple files, primarily focusing on version increments for the @oraichain/oraidex-common and @oraichain/oraidex-universal-swap packages. Additionally, new constants related to blockchain contracts are added, and the functionality of token retrieval methods is enhanced. The updates streamline token handling and balance checks in the UniversalSwapHandler class, while new demo functionality is introduced for token swaps between the Oraichain and EVM-compatible chains.

Changes

File Path Change Summary
packages/oraidex-common/package.json Version updated from 1.1.8 to 1.1.17.
packages/oraidex-common/src/constant.ts Added new constants for BSC and Ethereum contracts related to PEPE and CAT tokens.
packages/oraidex-common/src/helper.ts Modified getTokenOnOraichain function to filter tokens based on coingeckoId and isNative instead of decimals.
packages/oraidex-common/src/network.ts Updated network configurations with new token entries for PEPE and CAT, including contract addresses and minimal denominations.
packages/universal-swap/package.json Version updated from 1.1.5 to 1.1.6.
packages/universal-swap/src/handler.ts Updated UniversalSwapHandler class to include isNative parameter in getTokenOnOraichain method; modified balance checking logic.
packages/universal-swap/src/helper.ts Deprecated several methods; updated simulateSwapUsingSmartRoute to return Promise<SmartRouterResponse>.
packages/universal-swap/src/types.ts Updated SimulateResponse interface and added isCheckBalanceIbc to SwapOptions. Removed SmartRouteSwapAPIOperations type.
packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts Introduced a new function oraichainToEvm for swapping tokens from Oraichain to EVM chains.

Possibly related PRs

Suggested reviewers

  • trung2891
  • quangdz1704

Poem

🐇 In the fields where tokens play,
New paths for swaps have come our way.
With PEPE and CAT, we dance and cheer,
From Oraichain to EVM, we have no fear!
Hops of joy in code we weave,
Celebrating changes, we believe! 🌼


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

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

badge

Code Coverage Summary

Filename                                                                      Stmts    Miss  Cover    Missing
--------------------------------------------------------------------------  -------  ------  -------  --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
docs/assets/main.js                                                              58      58  0.00%    1-58
docs/assets/search.js                                                             1       1  0.00%    1
packages/ibc-routing/hardhat.config.ts                                           59      59  0.00%    1-75
packages/ibc-routing/src/db.ts                                                  158     158  0.00%    1-263
packages/ibc-routing/src/event.ts                                                85      85  0.00%    1-122
packages/ibc-routing/src/index.ts                                                31      31  0.00%    1-56
packages/ibc-routing/src/machine.ts                                              30      30  0.00%    1-34
packages/ibc-routing/test/mock-eth-ws.ts                                         52      52  0.00%    1-55
packages/ibc-routing/test/mock-tendermint-ws.spec.ts                             25      17  32.00%   7-24
packages/oraidex-common/src/alpha-network.ts                                     61       0  100.00%
packages/oraidex-common/src/axios-request.ts                                     11      11  0.00%    1-20
packages/oraidex-common/src/bigdecimal.ts                                       139      50  64.02%   23-24, 30-33, 40-41, 45-54, 63-65, 71-73, 120-124, 127-146, 149-150, 153-154, 180-181, 184-185
packages/oraidex-common/src/constant.ts                                         168       0  100.00%
packages/oraidex-common/src/helper.ts                                           466     142  69.52%   141-142, 145-156, 159-169, 267-269, 286-293, 296-309, 319-325, 335-350, 353-360, 363-393, 396-404, 407-409, 412-414, 418-427, 436-450, 456-458, 543-544, 569-572
packages/oraidex-common/src/ibc-info.ts                                         183     183  0.00%    1-215
packages/oraidex-common/src/index.ts                                             13      13  0.00%    1-13
packages/oraidex-common/src/network.ts                                         1013       0  100.00%
packages/oraidex-common/src/pairs.ts                                            154       4  97.40%   151-152, 157-158
packages/oraidex-common/src/token.ts                                             71       0  100.00%
packages/oraidex-common/src/wallet.ts                                           146     146  0.00%    1-236
packages/oraidex-common/src/config/chainInfosWithIcon.ts                        196     196  0.00%    1-210
packages/oraidex-common/src/interface/index.ts                                    1       1  0.00%    1
packages/oraidex-common/src/interface/wallet.ts                                  19      19  0.00%    1-20
packages/oraidex-common/tests/bigdecimal.spec.ts                                220       0  100.00%
packages/oraidex-common/tests/helper.spec.ts                                    560       8  98.57%   97-98, 337-338, 628-629, 659-660
packages/oraidex-common/tests/pairs.spec.ts                                      24       0  100.00%
packages/oraiswap-v3/src/const.ts                                                11       0  100.00%
packages/oraiswap-v3/src/error.ts                                                 5       2  60.00%   3-4
packages/oraiswap-v3/src/handler.ts                                             292      28  90.41%   63-64, 100-101, 216-217, 341-355, 358-366
packages/oraiswap-v3/src/helpers.ts                                             444     234  47.29%   122-123, 133-134, 159-160, 188-189, 199-200, 283-287, 290-297, 300-356, 359-364, 367-376, 380-436, 439-447, 450-481, 484-497, 500-523, 526-532, 535-549
packages/oraiswap-v3/src/index.ts                                                 7       0  100.00%
packages/oraiswap-v3/src/main.ts                                                 37      37  0.00%    1-72
packages/oraiswap-v3/src/types.ts                                                13       0  100.00%
packages/oraiswap-v3/src/zap-consumer.ts                                        496     478  3.62%    54-58, 61-62, 65-98, 101-143, 146-165, 168-186, 189-219, 222-331, 334-567, 570-608
packages/oraiswap-v3/src/wasm/oraiswap_v3_wasm.d.ts                              32      32  0.00%    469-500
packages/oraiswap-v3/src/wasm/oraiswap_v3_wasm.js                              1543     710  53.98%   32-34, 92-94, 100-101, 103-108, 113-120, 136-145, 160-223, 233-255, 264-284, 293-313, 322-342, 351-371, 380-400, 409-429, 463-464, 480-502, 508-511, 518-530, 536-548, 555-558, 565-579, 587-590, 595-598, 611-614, 620-623, 636-639, 660-663, 668-671, 688-729, 736-754, 762-776, 783-786, 793-807, 817-838, 848-869, 884-885, 910-911, 929-953, 958-961, 966-969, 976-979, 984-987, 992-995, 1002-1005, 1010-1013, 1028-1031, 1036-1039, 1044-1047, 1062-1065, 1080-1083, 1088-1091, 1096-1099, 1106-1109, 1114-1117, 1122-1125, 1132-1135, 1149-1150, 1161-1164, 1170-1173, 1179-1182, 1188-1191, 1196-1199, 1204-1207, 1214-1217, 1219-1225, 1300-1301, 1329-1330, 1333-1335, 1356-1361, 1364-1365, 1368-1372, 1386-1387, 1390-1391, 1394-1395, 1398-1399, 1402-1403, 1406-1407, 1410-1413, 1416-1417, 1420-1421, 1424-1425, 1428-1431, 1434-1437, 1444, 1447-1448, 1451-1458, 1465-1466, 1469-1470, 1473-1474, 1477, 1480-1481, 1484-1491, 1500-1504, 1507, 1510-1511
packages/oraiswap-v3/tests/handler.spec.ts                                      276       0  100.00%
packages/oraiswap-v3/tests/helpers.spec.ts                                      577       0  100.00%
packages/oraiswap-v3/tests/test-common.ts                                        32       0  100.00%
packages/oraiswap-v3/tests/zap-consumer.spec.ts                                  50       0  100.00%
packages/universal-swap/src/handler.ts                                         1221     658  46.10%   81-82, 103-104, 119-121, 127-130, 152-157, 178-200, 279-309, 366-371, 422-442, 493-498, 545-556, 580, 582-586, 599-610, 617-632, 635-693, 704-714, 717-727, 734-741, 755-832, 836-867, 871-890, 893-910, 914-971, 976-1060, 1066-1151, 1161-1166, 1195-1196, 1198-1199, 1205, 1219-1243, 1270-1273, 1306-1309, 1316-1326, 1331-1351, 1392-1393, 1406-1449, 1512-1513
packages/universal-swap/src/helper.ts                                           941     325  65.46%   87-89, 225-226, 272-277, 305-306, 340-352, 366-420, 461-463, 488-494, 520-522, 526-528, 535-562, 624-625, 658-665, 672-713, 725-779, 818-819, 834, 862, 869-890, 892-893, 926-927, 930-933, 943-985, 993-1009, 1068-1078, 1089-1094, 1113, 1139-1151, 1269-1280
packages/universal-swap/src/index.ts                                              6       6  0.00%    1-6
packages/universal-swap/src/swap-filter.ts                                       40       0  100.00%
packages/universal-swap/src/types.ts                                             10       0  100.00%
packages/universal-swap/src/wrapper.ts                                           79      79  0.00%    1-117
packages/universal-swap/src/proto/index.ts                                        1       1  0.00%    1
packages/universal-swap/src/proto/universal-swap-memo-proto-handler.ts           66      60  9.09%    21-46, 50-91
packages/universal-swap/src/proto/universal_swap_memo.ts                        911     818  10.20%   110-112, 116-132, 135-183, 186-193, 196-213, 216-217, 219-230, 233-235, 239-243, 246-266, 269-274, 277-282, 285-286, 288-291, 294-296, 300-304, 307-327, 330-333, 336-341, 344-345, 347-350, 353-355, 359-366, 369-396, 399-405, 408-416, 419-420, 422-426, 429-431, 435-445, 448-482, 485-490, 493-504, 507-508, 510-515, 518-520, 524-534, 537-571, 574-583, 586-597, 600-601, 603-613, 616-618, 622-635, 638-679, 682-690, 693-707, 710-711, 713-727, 730-732, 736-752, 755-803, 806-813, 816-833, 836-837, 839-846, 849-851, 855-871, 874-922, 925-932, 935-952, 955-956, 958-965, 968-970, 974-981, 984-1011, 1014-1018, 1021-1029, 1032-1033, 1035-1039, 1042-1044, 1048-1052, 1055-1075, 1078-1079, 1082-1087, 1090-1091, 1093-1096, 1111-1119, 1122-1128
packages/universal-swap/src/universal-demos/alpha-smart-router.ts               114     114  0.00%    1-589
packages/universal-swap/src/universal-demos/evm-to-evm.ts                        52      52  0.00%    1-68
packages/universal-swap/src/universal-demos/from-cosmos-to-evm.ts                41      41  0.00%    1-53
packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts             43      43  0.00%    1-63
packages/universal-swap/src/universal-demos/from-oraichain-to-oraichain.ts       49      49  0.00%    1-66
packages/universal-swap/src/universal-demos/handle-simulate-swap.ts              32      32  0.00%    1-36
packages/universal-swap/src/universal-demos/ibc-hooks-demo.ts                    40      40  0.00%    1-55
packages/universal-swap/src/universal-demos/neutaro-ibc-demo.ts                  40      40  0.00%    1-47
packages/universal-swap/src/universal-demos/noble-ibc-demo.ts                    41      41  0.00%    1-45
packages/universal-swap/src/universal-demos/offline-wallet.ts                    19      19  0.00%    1-21
packages/universal-swap/tests/helper.spec.ts                                    697      24  96.55%   378, 947-969
packages/universal-swap/tests/index.spec.ts                                    1735      32  98.15%   240-243, 271-272, 283-284, 289-290, 292-293, 295-296, 1130-1149
packages/universal-swap/tests/smart-router-common.ts                            864       0  100.00%
packages/universal-swap/tests/test-common.ts                                     56       0  100.00%
TOTAL                                                                         14857    5259  64.60%

Diff against main

Filename                                                                Stmts    Miss  Cover
--------------------------------------------------------------------  -------  ------  --------
packages/oraidex-common/src/constant.ts                                    +6       0  +100.00%
packages/oraidex-common/src/helper.ts                                      +2      +3  -0.52%
packages/oraidex-common/src/network.ts                                    +45       0  +100.00%
packages/universal-swap/src/handler.ts                                     +7      +9  -0.44%
packages/universal-swap/src/helper.ts                                     -16     -16  +1.10%
packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts      +43     +43  +100.00%
TOTAL                                                                     +87     +39  -0.05%

Results for commit: d4105d7

Minimum allowed coverage is 0%

♻️ This comment has been updated with latest results

Copy link
Contributor

@trung2891 trung2891 left a comment

Choose a reason for hiding this comment

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

lgtm

@haunv3 haunv3 merged commit 325645f into main Sep 24, 2024
3 of 4 checks passed
Copy link

@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.

Actionable comments posted: 12

Outside diff range and nitpick comments (12)
packages/universal-swap/src/types.ts (2)

21-21: Approve change and suggest review of property duplication

The change from SmartRouteSwapAPIOperations to SmartRouterResponse for the routes property is consistent with the removal of the SmartRouteSwapAPIOperations type. This change likely reflects an update in the API response structure.

However, I noticed that both routes and routeSwapOps properties exist with different types. Consider reviewing if both properties are necessary or if one should be removed to avoid potential confusion or inconsistencies in the future.


92-92: Approve new property and suggest adding a comment

The addition of the isCheckBalanceIbc optional boolean property to the SwapOptions interface is approved. This change maintains backward compatibility and follows the existing naming convention.

To improve code clarity and maintainability, consider adding a brief comment explaining the purpose and usage of this new option. For example:

/**
 * If true, checks the IBC balance before proceeding with the swap.
 */
isCheckBalanceIbc?: boolean;
packages/oraidex-common/src/constant.ts (1)

100-101: LGTM with a minor suggestion: PEPE_ORAICHAIN_EXT_DENOM constant added correctly.

The constant follows the established naming convention and value format for Oraichain external denominations. However, for consistency with other constants in this file, consider placing the entire declaration on a single line:

export const PEPE_ORAICHAIN_EXT_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extPEPE";
packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts (3)

22-28: Remove or clarify commented-out code

There's a block of commented-out code related to simulateSwapUsingSmartRoute. If this code is no longer needed, consider removing it to keep the codebase clean. If it's intended for future use or debugging, add a comment explaining its purpose.


34-37: Remove or clarify commented-out relayer fee code

The relayerFee code is commented out. If it's not necessary, you might remove it to reduce clutter. If it's planned for future implementation, consider adding a comment explaining its intended use.


61-63: Simplify the function invocation

Wrapping the function call in an IIFE (Immediately Invoked Function Expression) may be unnecessary here. You can directly invoke oraichainToEvm() without wrapping it in an arrow function.

Apply this diff to simplify the function call:

 (() => {
-  return oraichainToEvm();
-})();
+oraichainToEvm();
packages/oraidex-common/src/helper.ts (2)

255-260: Enhance JSDoc comments for clarity and consistency

Consider improving the documentation to provide clearer descriptions and maintain consistency with standard JSDoc practices.

Apply this diff to enhance the JSDoc comments:

 /**
- * This function get token on oraichain from coingeckoId
+ * Retrieves a token on Oraichain by its CoinGecko ID.
  * @param coingeckoId - coingeckoId of tokenInOraichain
- * @param isNative - isNative token
+ * @param isNative - Optional boolean indicating whether to return a native token (`true`) or an EVM token (`false`). Defaults to `false`.
  * @returns token on Oraichain

262-269: Set default value for isNative parameter

Explicitly setting a default value for isNative enhances code readability and prevents potential bugs due to undefined values.

Apply this diff to set a default value:

-export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative?: boolean) => {
+export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative: boolean = false) => {
packages/oraidex-common/src/network.ts (1)

336-342: Add clarification for commented-out CAT token configuration

The CAT token configuration is commented out. If this is intentional for future use, consider adding a TODO comment explaining the reason and when it should be revisited. This aids in code maintainability and team awareness.

packages/universal-swap/src/helper.ts (1)

Line range hint 548-550: Typo in property name 'dontAlowSwapAfter'.

In the swapOptions object, the property dontAlowSwapAfter is misspelled. It should be dontAllowSwapAfter to match the expected parameter name.

Please apply the following fix:

 swapOptions: {
   protocols: routerConfig.protocols,
-  dontAlowSwapAfter: routerConfig.dontAllowSwapAfter
+  dontAllowSwapAfter: routerConfig.dontAllowSwapAfter
 }
packages/universal-swap/src/handler.ts (2)

280-280: Remove the unused constant IBC_DECIMALS

The constant IBC_DECIMALS is declared but not used in the code. Removing it will clean up the code and prevent confusion.

Apply this diff to remove the unused constant:

-          const IBC_DECIMALS = 18;

1235-1236: Make the hardcoded URL configurable

The URL "https://osor.oraidex.io" is hardcoded in the routerConfig. To improve maintainability and flexibility, consider making this URL configurable through the config object.

Apply this diff:

-                url: "https://osor.oraidex.io",
+                url: this.config.routerConfig.url,

Ensure that routerConfig.url is provided in the config object.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 87032d5 and e1fab51.

Files selected for processing (9)
  • packages/oraidex-common/package.json (1 hunks)
  • packages/oraidex-common/src/constant.ts (3 hunks)
  • packages/oraidex-common/src/helper.ts (1 hunks)
  • packages/oraidex-common/src/network.ts (6 hunks)
  • packages/universal-swap/package.json (1 hunks)
  • packages/universal-swap/src/handler.ts (8 hunks)
  • packages/universal-swap/src/helper.ts (8 hunks)
  • packages/universal-swap/src/types.ts (3 hunks)
  • packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/universal-swap/package.json
Additional comments not posted (26)
packages/oraidex-common/package.json (2)

Line range hint 1-39: Clarify the discrepancy between PR title and changes

The PR title "Feat/add pepe cat" suggests the addition of a new feature, but the only change in this file is a version bump. There seems to be a discrepancy between the PR title and the actual changes.

Could you please clarify if there are other files changed in this PR that implement the "pepe cat" feature? If not, consider updating the PR title to accurately reflect the version bump.

#!/bin/bash
# Description: Check for other changed files in the PR

# Test: List all changed files in this PR
gh pr view 334 --json files --jq '.files[].path'

# Test: Search for "pepe" or "cat" in recent commits
git log -n 10 --grep="pepe\|cat" --oneline

3-3: Verify the significant version bump

The package version has been updated from 1.1.8 to 1.1.17, which is a significant jump of 9 minor versions. Please ensure that this version bump accurately reflects the changes made to the package since the last release.

Could you provide more context on the changes that warrant this version increase? It's unusual to see such a large version jump without corresponding changes in the package.json file.

packages/universal-swap/src/types.ts (2)

Line range hint 1-265: Summary of changes and suggestions

The changes in this file primarily involve simplifying and updating type definitions, which should improve code clarity and maintainability. Key points:

  1. The SimulateResponse interface has been updated to use SmartRouterResponse instead of SmartRouteSwapAPIOperations.
  2. A new isCheckBalanceIbc option has been added to SwapOptions.
  3. The SmartRouterResponse type has been simplified to use only Route[] for its routes property.

These changes appear to be part of a larger refactoring effort to streamline the API and type definitions. To ensure a smooth transition:

  1. Review the necessity of keeping both routes and routeSwapOps in the SimulateResponse interface.
  2. Add a comment explaining the purpose of the new isCheckBalanceIbc option.
  3. Verify that all code using SmartRouterResponse has been updated to work with the new Route[] type.

Overall, these changes should positively impact the codebase by reducing complexity and improving type safety.


128-128: Approve type simplification and suggest code update verification

The simplification of the routes property type from (SmartRouteSwapAPIOperations | Route)[] to Route[] is approved. This change is consistent with the removal of the SmartRouteSwapAPIOperations type and simplifies the type definition.

To ensure the change doesn't introduce any issues:

  1. Verify that all code consuming the SmartRouterResponse type has been updated to work with the new Route[] type.
  2. Update any documentation or comments referencing the old type structure.
packages/oraidex-common/src/constant.ts (5)

56-56: LGTM: PEPE_BSC_CONTRACT constant added correctly.

The constant follows the established naming convention for BSC contracts and contains a valid Ethereum address format.


57-57: LGTM: CAT_BSC_CONTRACT constant added correctly.

The constant adheres to the established naming convention for BSC contracts and contains a valid Ethereum address format.


72-72: LGTM: PEPE_ETH_CONTRACT constant added correctly.

The constant follows the established naming convention for ETH contracts, contains a valid Ethereum address format, and is appropriately placed among other ETH contract constants.


102-102: LGTM: CAT_ORAICHAIN_EXT_DENOM constant added correctly.

The constant adheres to the established naming convention and value format for Oraichain external denominations, and its declaration style is consistent with other constants in the file.


56-57: Summary: New constants for PEPE and CAT tokens added successfully.

The changes introduce constants for PEPE and CAT tokens across BSC, ETH, and Oraichain networks. These additions are consistent with the existing structure and naming conventions in the file.

To ensure these changes are fully integrated:

Please run the following script to check for any references to these new token constants in the codebase:

This will help identify any areas in the codebase where these new constants should be used or where they might need to be added.

Also applies to: 72-72, 100-102

Verification successful

Verified: New PEPE and CAT token constants are properly integrated.

All new constants for PEPE and CAT tokens are correctly referenced within the codebase, and no hardcoded addresses were found outside of constant.ts. The additions maintain consistency and align with existing patterns.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for references to new PEPE and CAT token constants

echo "Checking for references to new token constants:"
rg --type typescript "PEPE_BSC_CONTRACT|CAT_BSC_CONTRACT|PEPE_ETH_CONTRACT|PEPE_ORAICHAIN_EXT_DENOM|CAT_ORAICHAIN_EXT_DENOM" -g '!constant.ts'

echo "Checking for hardcoded addresses that might need to use these constants:"
rg --type typescript "0x25d887Ce7a35172C62FeBFD67a1856F20FaEbB00|0x6894CDe390a3f51155ea41Ed24a33A4827d3063D|0x6982508145454Ce325dDbE47a25d4ec3d2311933" -g '!constant.ts'

echo "Checking for potential places to use these new constants:"
rg --type typescript "BSC_CONTRACT|ETH_CONTRACT|ORAICHAIN_EXT_DENOM" -g '!constant.ts'

Length of output: 895


Script:

#!/bin/bash
# Description: Check for references to new PEPE and CAT token constants

echo "Checking for references to new token constants:"
rg "PEPE_BSC_CONTRACT|CAT_BSC_CONTRACT|PEPE_ETH_CONTRACT|PEPE_ORAICHAIN_EXT_DENOM|CAT_ORAICHAIN_EXT_DENOM" -g '*.ts'

echo "Checking for hardcoded addresses that might need to use these constants:"
rg "0x25d887Ce7a35172C62FeBFD67a1856F20FaEbB00|0x6894CDe390a3f51155ea41Ed24a33A4827d3063D|0x6982508145454Ce325dDbE47a25d4ec3d2311933" -g '*.ts'

echo "Checking for potential places to use these new constants:"
rg "BSC_CONTRACT|ETH_CONTRACT|ORAICHAIN_EXT_DENOM" -g '*.ts'

Length of output: 15415

packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts (1)

41-41: Verify the user slippage value

The userSlippage is set to 1. Depending on how slippage is calculated in your application, this might represent 1% or 1. Ensure that this value aligns with the expected slippage tolerance in your swap operations.

Please confirm that 1 is the intended slippage value. Adjust if necessary.

packages/oraidex-common/src/helper.ts (1)

262-269: ⚠️ Potential issue

Address potential breaking change due to function signature update

The function getTokenOnOraichain has changed its signature by replacing the optional decimals parameter with isNative. This modification may introduce breaking changes in parts of the codebase where this function is called with the decimals parameter.

Run the following script to identify all usages of getTokenOnOraichain that may need updating:

Verification successful

No Breaking Changes Detected

All usages of getTokenOnOraichain have been updated to use the isNative parameter. No outdated calls with the decimals parameter were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to `getTokenOnOraichain` with two arguments, indicating potential outdated usage.

# Search for function calls with two arguments
ast-grep --lang typescript --pattern 'getTokenOnOraichain($_, $_)'

# Expected Result: All occurrences where `getTokenOnOraichain` is called with two arguments. Verify that these calls have been updated to use `isNative` instead of `decimals`.

Length of output: 182

packages/oraidex-common/src/network.ts (5)

58-62: Verify imported constants are defined correctly

The constants PEPE_ORAICHAIN_EXT_DENOM, CAT_ORAICHAIN_EXT_DENOM, PEPE_ETH_CONTRACT, PEPE_BSC_CONTRACT, and CAT_BSC_CONTRACT are being imported from "./constant". Please ensure that these constants are correctly defined and exportable in the "./constant" module to prevent any import errors.


122-123: Confirm accuracy of added CoinGecko IDs

The CoinGecko IDs "pepe" and "simon-s-cat" have been added to the CoinGeckoId type. Verify that these IDs exactly match the identifiers used by CoinGecko to ensure accurate price retrieval.


989-996: Ensure consistent prefixToken usage in EVM token configurations

In the Ethereum PEPE token configuration, the prefixToken field is included, but verify that it aligns with other EVM token configurations for consistency.


675-681: ⚠️ Potential issue

Missing prefixToken in PEPE Ethereum token configuration

The PEPE token entry for Ethereum does not include the prefixToken field, which may lead to inconsistent token handling. Including prefixToken ensures proper denomination prefixes are applied.

Include prefixToken in the configuration:

{
  coinDenom: "PEPE",
  coinMinimalDenom: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX + PEPE_ETH_CONTRACT,
  bridgeNetworkIdentifier: "0x01",
  coinDecimals: 18,
  coinGeckoId: "pepe",
+ prefixToken: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX,
  coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776"
}

Likely invalid or redundant comment.


663-672: 🛠️ Refactor suggestion

Consistent use of prefixToken across token configurations

In the PEPE token configurations, the prefixToken field is used inconsistently. Ensure that prefixToken is included where necessary to maintain consistency and avoid potential issues with token denomination prefixes.

Add prefixToken to maintain consistency:

{
  coinDenom: "PEPE",
  coinMinimalDenom: ORAI_BRIDGE_EVM_DENOM_PREFIX + PEPE_BSC_CONTRACT,
  bridgeNetworkIdentifier: "0x38",
  coinDecimals: 18,
  coinGeckoId: "pepe",
+ prefixToken: ORAI_BRIDGE_EVM_DENOM_PREFIX,
  coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776"
},

Likely invalid or redundant comment.

packages/universal-swap/src/helper.ts (7)

330-330: Usage of optional chaining is correct.

The addition of swapOption?.isSourceReceiverTest safely accesses the property and prevents runtime errors if swapOption is undefined.


468-470: Deprecation notice for 'generateSwapRoute' method added appropriately.

The method generateSwapRoute is correctly marked as deprecated with a reference to use UniversalSwapHelper.generateMsgsSmartRouterV2withV3 instead.


505-507: Deprecation notice for 'generateSwapOperationMsgs' method added appropriately.

The method generateSwapOperationMsgs is correctly marked as deprecated, advising to use UniversalSwapHelper.generateMsgsSmartRouterV2withV3 instead.


593-595: Deprecation notice for 'simulateSwap' method added appropriately.

The method simulateSwap is correctly marked as deprecated, suggesting to use UniversalSwapHelper.handleSimulateSwap instead.


747-752: Initialization of default router configuration is correct.

The routerConfigDefault object is properly set up using nullish coalescing to provide default values when necessary.


765-771: Function call to 'simulateSwapUsingSmartRoute' is correctly updated.

The parameters passed to simulateSwapUsingSmartRoute are appropriate, and the use of routerConfigDefault ensures consistency in configuration.


772-777: 'displayAmount' is calculated using the correct decimals.

The displayAmount is accurately computed using toInfo.decimals, which ensures the return value has the correct precision.

packages/universal-swap/src/handler.ts (3)

140-140: Confirm the isNative parameter usage for special chains

In this line, getTokenOnOraichain is called with isNative set to true. Ensure that this aligns with the intended logic for handling special chains and CoinGecko IDs, and that it correctly fetches native tokens when required.


957-967: Repeated logical error in balance checking condition

Similar to the previous comment, the condition if (!this.config?.swapOptions?.isCheckBalanceIbc) is used here. Verify if the negation is needed or if it should be removed to align with the intended logic.


1036-1058: Repeated logical error in balance checking condition

This condition if (!this.config?.swapOptions?.isCheckBalanceIbc) appears again. Please ensure that the balance checking logic is consistent throughout the codebase and correct the condition if necessary.


const oraichainToEvm = async () => {
const chainId = "Oraichain";
const wallet = new CosmosWalletImpl(process.env.MNEMONIC);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for undefined mnemonic

The process.env.MNEMONIC might be undefined or not properly set. It's advisable to add a check to ensure that the mnemonic is available before initializing the wallet to prevent runtime errors.

Apply this diff to add error handling:

 const wallet = new CosmosWalletImpl(process.env.MNEMONIC);
+if (!process.env.MNEMONIC) {
+  throw new Error("MNEMONIC environment variable is not defined");
+}

Committable suggestion was skipped due to low confidence.


const sender = await wallet.getKeplrAddr(chainId);
const fromAmount = 100;
let originalFromToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === "pepe");
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid hardcoding token identifiers

Hardcoding coinGeckoId as "pepe" reduces the flexibility of your function. Consider parameterizing the token identifiers or retrieving them from a configuration to enhance reusability and maintainability.

For example, modify the code to accept token identifiers as parameters:

 const fromAmount = 100;
-let originalFromToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === "pepe");
+const fromCoinGeckoId = "pepe"; // This could be a parameter or from config
+let originalFromToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === fromCoinGeckoId);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let originalFromToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === "pepe");
const fromAmount = 100;
const fromCoinGeckoId = "pepe"; // This could be a parameter or from config
let originalFromToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === fromCoinGeckoId);

{
originalFromToken,
originalToToken,
sender: { cosmos: sender, evm: "0x8c7E0A841269a01c0Ab389Ce8Fb3Cf150A94E797" },
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid hardcoding EVM addresses

Hardcoding the EVM address "0x8c7E0A841269a01c0Ab389Ce8Fb3Cf150A94E797" can lead to security issues and reduces flexibility. Consider retrieving the address dynamically or passing it as a parameter.

Example modification:

 sender: { cosmos: sender, evm: "0x8c7E0A841269a01c0Ab389Ce8Fb3Cf150A94E797" },
+// Replace hardcoded address with a variable or input parameter
+const evmAddress = process.env.EVM_ADDRESS; // Ensure this is securely managed
+sender: { cosmos: sender, evm: evmAddress },

Also, include error handling for cases where evmAddress may be undefined.

Committable suggestion was skipped due to low confidence.

const fromAmount = 100;
let originalFromToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === "pepe");

let originalToToken = flattenTokens.find((t) => t.chainId === "0x38" && t.coinGeckoId === "pepe");
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid hardcoding chain IDs and token identifiers

The chain ID "0x38" (which represents BSC) and coinGeckoId "pepe" are hardcoded. This can make future maintenance difficult if these values change. Consider using constants, configurations, or function parameters to make the code more adaptable.

Example adjustment:

 const chainId = "Oraichain";
+const toChainId = "0x38"; // This could be a parameter or from config
+const toCoinGeckoId = "pepe"; // This could be a parameter or from config
-let originalToToken = flattenTokens.find((t) => t.chainId === "0x38" && t.coinGeckoId === "pepe");
+let originalToToken = flattenTokens.find((t) => t.chainId === toChainId && t.coinGeckoId === toCoinGeckoId);

Committable suggestion was skipped due to low confidence.

Comment on lines +262 to 269
export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative?: boolean) => {
const filterOraichainToken = oraichainTokens.filter((orai) => orai.coinGeckoId === coingeckoId);
if (!filterOraichainToken.length) return undefined;
if (filterOraichainToken.length === 1) return filterOraichainToken[0];

const oraichainToken = filterOraichainToken.find((token) => (isNative ? !token.evmDenoms : token.evmDenoms));
return oraichainToken;
};
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize the token filtering logic

Refactor the conditional logic to improve readability and efficiency by directly using the filter method instead of find.

Apply this diff to simplify the code:

-export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative?: boolean) => {
-  const filterOraichainToken = oraichainTokens.filter((orai) => orai.coinGeckoId === coingeckoId);
-  if (!filterOraichainToken.length) return undefined;
-  if (filterOraichainToken.length === 1) return filterOraichainToken[0];

-  const oraichainToken = filterOraichainToken.find((token) => (isNative ? !token.evmDenoms : token.evmDenoms));
-  return oraichainToken;
+export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative: boolean = false) => {
+  const tokens = oraichainTokens.filter(
+    (token) =>
+      token.coinGeckoId === coingeckoId &&
+      (isNative ? !token.evmDenoms : token.evmDenoms)
+  );
+  return tokens.length > 0 ? tokens[0] : undefined;
 };
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative?: boolean) => {
const filterOraichainToken = oraichainTokens.filter((orai) => orai.coinGeckoId === coingeckoId);
if (!filterOraichainToken.length) return undefined;
if (filterOraichainToken.length === 1) return filterOraichainToken[0];
const oraichainToken = filterOraichainToken.find((token) => (isNative ? !token.evmDenoms : token.evmDenoms));
return oraichainToken;
};
export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative: boolean = false) => {
const tokens = oraichainTokens.filter(
(token) =>
token.coinGeckoId === coingeckoId &&
(isNative ? !token.evmDenoms : token.evmDenoms)
);
return tokens.length > 0 ? tokens[0] : undefined;
};

⚠️ Potential issue

Ensure correct logic in token selection based on isNative flag

The current logic may not correctly handle cases where multiple tokens share the same coingeckoId. If no token matches the condition in the find method, oraichainToken will be undefined.

Consider providing a default behavior or handling the case when oraichainToken is undefined. Apply this diff to add a fallback:

 const oraichainToken = filterOraichainToken.find((token) => (isNative ? !token.evmDenoms : token.evmDenoms));
+if (!oraichainToken) {
+  // Fallback to the first token or handle the undefined case appropriately
+  return filterOraichainToken[0];
+}
 return oraichainToken;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative?: boolean) => {
const filterOraichainToken = oraichainTokens.filter((orai) => orai.coinGeckoId === coingeckoId);
if (!filterOraichainToken.length) return undefined;
if (filterOraichainToken.length === 1) return filterOraichainToken[0];
const oraichainToken = filterOraichainToken.find((token) => (isNative ? !token.evmDenoms : token.evmDenoms));
return oraichainToken;
};
export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative?: boolean) => {
const filterOraichainToken = oraichainTokens.filter((orai) => orai.coinGeckoId === coingeckoId);
if (!filterOraichainToken.length) return undefined;
if (filterOraichainToken.length === 1) return filterOraichainToken[0];
const oraichainToken = filterOraichainToken.find((token) => (isNative ? !token.evmDenoms : token.evmDenoms));
if (!oraichainToken) {
// Fallback to the first token or handle the undefined case appropriately
return filterOraichainToken[0];
}
return oraichainToken;
};

Comment on lines +1120 to +1126
coinDenom: "PEPE",
coinMinimalDenom: "bep20_pepe",
contractAddress: PEPE_BSC_CONTRACT,
coinDecimals: 18,
coinGeckoId: "pepe",
bridgeTo: ["Oraichain"],
coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Include prefixToken in PEPE BSC token configuration

The PEPE token entry for BSC lacks the prefixToken field, which could cause inconsistencies in token identification. Adding this field will harmonize the configuration with other tokens.

Modify the entry to include prefixToken:

{
  coinDenom: "PEPE",
  coinMinimalDenom: "bep20_pepe",
  contractAddress: PEPE_BSC_CONTRACT,
  coinDecimals: 18,
  coinGeckoId: "pepe",
  bridgeTo: ["Oraichain"],
+ prefixToken: ORAI_BRIDGE_EVM_DENOM_PREFIX,
  coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776"
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
coinDenom: "PEPE",
coinMinimalDenom: "bep20_pepe",
contractAddress: PEPE_BSC_CONTRACT,
coinDecimals: 18,
coinGeckoId: "pepe",
bridgeTo: ["Oraichain"],
coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776"
coinDenom: "PEPE",
coinMinimalDenom: "bep20_pepe",
contractAddress: PEPE_BSC_CONTRACT,
coinDecimals: 18,
coinGeckoId: "pepe",
bridgeTo: ["Oraichain"],
prefixToken: ORAI_BRIDGE_EVM_DENOM_PREFIX,
coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776"

Comment on lines +328 to +334
coinDenom: "PEPE",
coinGeckoId: "pepe",
coinMinimalDenom: PEPE_ORAICHAIN_DENOM,
bridgeTo: ["0x38", "0x01"],
coinDecimals: 6,
coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776"
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential mismatch in coinDecimals for PEPE token

The PEPE token is set with coinDecimals: 6. Typically, PEPE token operates with 18 decimals on Ethereum and BSC networks. Using an incorrect decimal value may lead to misrepresentation of token balances and transaction amounts.

Update the coinDecimals to 18 to align with the standard:

{
  coinDenom: "PEPE",
  coinGeckoId: "pepe",
  coinMinimalDenom: PEPE_ORAICHAIN_DENOM,
  bridgeTo: ["0x38", "0x01"],
- coinDecimals: 6,
+ coinDecimals: 18,
  coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776"
},
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
coinDenom: "PEPE",
coinGeckoId: "pepe",
coinMinimalDenom: PEPE_ORAICHAIN_DENOM,
bridgeTo: ["0x38", "0x01"],
coinDecimals: 6,
coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776"
},
coinDenom: "PEPE",
coinGeckoId: "pepe",
coinMinimalDenom: PEPE_ORAICHAIN_DENOM,
bridgeTo: ["0x38", "0x01"],
coinDecimals: 18,
coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776"
},

Comment on lines +762 to +764
if (!fromInfo || !toInfo)
throw new Error(`Cannot find token on Oraichain for token ${fromInfo.coinGeckoId} and ${toInfo.coinGeckoId}`);

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential runtime error when accessing properties of undefined variables.

If fromInfo or toInfo is undefined, accessing fromInfo.coinGeckoId or toInfo.coinGeckoId will result in a runtime error.

Please modify the error handling to prevent this:

 if (!fromInfo || !toInfo)
-  throw new Error(`Cannot find token on Oraichain for token ${fromInfo.coinGeckoId} and ${toInfo.coinGeckoId}`);
+  throw new Error(`Cannot find token on Oraichain for tokens: fromInfo=${fromInfo?.coinGeckoId}, toInfo=${toInfo?.coinGeckoId}`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!fromInfo || !toInfo)
throw new Error(`Cannot find token on Oraichain for token ${fromInfo.coinGeckoId} and ${toInfo.coinGeckoId}`);
if (!fromInfo || !toInfo)
throw new Error(`Cannot find token on Oraichain for tokens: fromInfo=${fromInfo?.coinGeckoId}, toInfo=${toInfo?.coinGeckoId}`);

Comment on lines +937 to +950
if (!this.config?.swapOptions?.isCheckBalanceIbc) {
const routerClient = new OraiswapRouterQueryClient(client, network.mixer_router);
const isSufficient = await UniversalSwapHelper.checkFeeRelayer({
originalFromToken: this.swapData.originalFromToken,
fromAmount: this.swapData.fromAmount,
relayerFee: this.swapData.relayerFee,
routerClient
});
if (!isSufficient)
throw generateError(
`Your swap amount ${this.swapData.fromAmount} cannot cover the fees for this transaction. Please try again with a higher swap amount`
);
}

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential logical error in balance checking condition

The condition if (!this.config?.swapOptions?.isCheckBalanceIbc) may be incorrect. Currently, balance checks are performed when isCheckBalanceIbc is false or undefined. If the intention is to perform balance checks only when isCheckBalanceIbc is true, consider removing the negation.

Apply this diff to correct the condition:

-        if (!this.config?.swapOptions?.isCheckBalanceIbc) {
+        if (this.config?.swapOptions?.isCheckBalanceIbc) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!this.config?.swapOptions?.isCheckBalanceIbc) {
const routerClient = new OraiswapRouterQueryClient(client, network.mixer_router);
const isSufficient = await UniversalSwapHelper.checkFeeRelayer({
originalFromToken: this.swapData.originalFromToken,
fromAmount: this.swapData.fromAmount,
relayerFee: this.swapData.relayerFee,
routerClient
});
if (!isSufficient)
throw generateError(
`Your swap amount ${this.swapData.fromAmount} cannot cover the fees for this transaction. Please try again with a higher swap amount`
);
}
if (this.config?.swapOptions?.isCheckBalanceIbc) {
const routerClient = new OraiswapRouterQueryClient(client, network.mixer_router);
const isSufficient = await UniversalSwapHelper.checkFeeRelayer({
originalFromToken: this.swapData.originalFromToken,
fromAmount: this.swapData.fromAmount,
relayerFee: this.swapData.relayerFee,
routerClient
});
if (!isSufficient)
throw generateError(
`Your swap amount ${this.swapData.fromAmount} cannot cover the fees for this transaction. Please try again with a higher swap amount`
);
}

Comment on lines +74 to +75
private getTokenOnOraichain(coinGeckoId: CoinGeckoId, isNative?: boolean): TokenItemType {
const fromTokenOnOrai = getTokenOnOraichain(coinGeckoId, isNative);
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Some calls to getTokenOnOraichain are not updated to the new signature with the isNative parameter. Please update these usages accordingly:

  • packages/universal-swap/tests/helper.spec.ts
    • Multiple instances without the isNative parameter.
  • packages/oraidex-common/tests/helper.spec.ts
    • Calls missing the isNative parameter.
  • packages/universal-swap/src/helper.ts
    • Several occurrences without the updated parameter.
  • packages/universal-swap/src/handler.ts
    • Multiple lines need to include the isNative parameter.
  • packages/universal-swap/src/universal-demos/ibc-hooks-demo.ts
    • Missing isNative parameter in calls.
Analysis chain

Ensure all calls to getTokenOnOraichain are updated to the new signature

The method getTokenOnOraichain now accepts isNative?: boolean instead of decimals?: number. Please verify that all usages of this method have been updated accordingly and that the isNative parameter is correctly provided where necessary.

Run the following script to find all usages of getTokenOnOraichain:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to 'getTokenOnOraichain' and display the lines with context

rg --type typescript "getTokenOnOraichain\(" -A 1

Length of output: 86


Script:

#!/bin/bash
# Description: Find all calls to 'getTokenOnOraichain' within TypeScript files and display the lines with context

rg "getTokenOnOraichain\(" --glob "*.ts" --glob "*.tsx" -A 1

Length of output: 6000

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