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/zapper 2 #331

Merged
merged 67 commits into from
Sep 18, 2024
Merged

Feat/zapper 2 #331

merged 67 commits into from
Sep 18, 2024

Conversation

vuonghuuhung
Copy link
Member

@vuonghuuhung vuonghuuhung commented Sep 18, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a GitHub Actions workflow for automating the build and publishing process of the Oraiswap v3 package.
    • Added functionalities for managing liquidity operations through a new ZapConsumer class, enabling "zap in" and "zap out" operations.
    • Implemented new methods for liquidity tick management in the OraiswapV3Handler class.
  • Bug Fixes

    • Updated various package versions to improve stability and functionality.
  • Documentation

    • Enhanced TypeScript types and interfaces for better clarity and usability in liquidity management.
  • Chores

    • Updated .gitignore and added configuration files for improved project structure and dependency management.

Copy link

coderabbitai bot commented Sep 18, 2024

Warning

Rate limit exceeded

@vuonghuuhung has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 58 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 4b10b58 and 78f7a1b.

Walkthrough

This pull request introduces a new GitHub Actions workflow for automating the build and publication of the Oraiswap v3 package. It updates several configuration files, including .gitignore, .yarnrc, and package.json, reflecting changes in dependencies and version numbers. Additionally, new TypeScript files are added to enhance the functionality of the Oraiswap v3 protocol, particularly focusing on liquidity management and error handling. The updates also include new tests for the ZapConsumer class, ensuring comprehensive coverage of the new features.

Changes

File(s) Change Summary
.github/workflows/publish_oraiswap_v3.yml Added a GitHub Actions workflow for building and publishing the Oraiswap v3 package.
.gitignore Updated to ignore additional files and directories.
.yarnrc Introduced a new configuration file specifying the Yarn binary path.
package.json Updated version numbers for dependencies and modified build scripts.
packages/contracts-build/package.json Updated version number of @oraichain/oraidex-contracts-build.
packages/contracts-sdk/package.json Updated version number of @oraichain/oraidex-contracts-sdk.
packages/contracts-sdk/src/Zapper.client.ts Added TypeScript client for interacting with a smart contract on the CosmWasm blockchain.
packages/contracts-sdk/src/Zapper.types.ts Defined new types and interfaces for liquidity management and protocol fee handling.
packages/oraiswap-v3/package.json Updated version number and modified build/test scripts.
packages/oraiswap-v3/src/error.ts Introduced a new error class for handling routing errors.
packages/oraiswap-v3/src/handler.ts Added methods for managing liquidity ticks in the Oraiswap V3 protocol.
packages/oraiswap-v3/src/helpers.ts Expanded utility functions for liquidity and swap operations.
packages/oraiswap-v3/src/zap-consumer.ts Introduced ZapConsumer class for managing liquidity operations.
packages/oraiswap-v3/tests/zap-consumer.spec.ts Added a test suite for the ZapConsumer class.
packages/oraiswap-v3/tsconfig.json Adjusted TypeScript configuration, excluding src/main.ts.
packages/oraiswap-v3/tsconfig.test.json Introduced a new TypeScript configuration for testing.
packages/universal-swap/tests/index.spec.ts Corrected a typographical error in a test case name.

Possibly related PRs

Suggested reviewers

🐇 In the meadow where the bunnies play,
A new workflow hops in, brightening the day!
With Zappers and helpers, oh what a delight,
Liquidity dances, everything feels right.
So let’s cheer for the code, let it flourish and bloom,
In the world of Oraiswap, there's always more room! 🌼


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 generate interesting stats about this repository and render them as a table.
    -- @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

github-actions bot commented Sep 18, 2024

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                                         162       0  100.00%
packages/oraidex-common/src/helper.ts                                           464     139  70.04%   141-142, 145-156, 159-169, 276-283, 286-299, 309-315, 325-340, 343-350, 353-383, 386-394, 397-399, 402-404, 408-417, 426-440, 446-448, 533-534, 559-562
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                                          968       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                                         1214     649  46.54%   81-82, 103-104, 119-121, 127-130, 141-143, 155-160, 181-203, 282-312, 369-374, 425-445, 496-501, 548-559, 583, 585-589, 602-613, 620-635, 638-696, 707-717, 720-730, 737-744, 758-835, 839-870, 874-893, 896-913, 917-968, 973-1055, 1061-1146, 1156-1161, 1191-1193, 1195-1196, 1202, 1216-1230, 1258-1261, 1295-1298, 1305-1315, 1320-1340, 1381-1382, 1395-1438, 1501-1502
packages/universal-swap/src/helper.ts                                           957     341  64.36%   88-90, 226-227, 273-278, 306-307, 341-353, 367-421, 462-464, 486-492, 516-518, 522-524, 531-558, 618-619, 652-659, 666-707, 719-787, 826-827, 842, 870, 877-898, 900-901, 934-935, 938-941, 951-993, 1001-1017, 1076-1086, 1097-1102, 1121, 1147-1159, 1277-1288
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-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                                                                         14770    5220  64.65%

Diff against main

Filename                                           Stmts    Miss  Cover
-----------------------------------------------  -------  ------  --------
packages/oraidex-common/src/constant.ts               +1       0  +100.00%
packages/oraiswap-v3/src/error.ts                     +5      +2  +60.00%
packages/oraiswap-v3/src/handler.ts                  +26     +22  -7.33%
packages/oraiswap-v3/src/helpers.ts                 +232    +224  -47.99%
packages/oraiswap-v3/src/index.ts                     +2       0  +100.00%
packages/oraiswap-v3/src/main.ts                     +37     +37  +100.00%
packages/oraiswap-v3/src/types.ts                    +13       0  +100.00%
packages/oraiswap-v3/src/zap-consumer.ts            +496    +478  +3.62%
packages/oraiswap-v3/tests/handler.spec.ts            -1       0  +100.00%
packages/oraiswap-v3/tests/zap-consumer.spec.ts      +50       0  +100.00%
TOTAL                                               +861    +763  -3.30%

Results for commit: 78f7a1b

Minimum allowed coverage is 0%

♻️ This comment has been updated with latest results

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: 7

Outside diff range and nitpick comments (4)
packages/oraiswap-v3/tests/zap-consumer.spec.ts (1)

1-61: LGTM! Consider adding more test cases.

The test suite is correctly setting up the DEX environment before each test and is using the Vitest testing framework. The code is well-structured and easy to understand.

However, the test suite currently has a single test case that logs "hello" to the console, which is a placeholder for future tests. Consider adding more test cases to ensure comprehensive coverage of the ZapConsumer class.

packages/oraiswap-v3/src/main.ts (3)

14-21: Consider removing the commented-out pool keys.

If the commented-out pool keys are no longer needed, it's best to remove them to keep the code clean and maintainable.


37-56: Consider removing the commented-out code or adding explanatory comments.

If the commented-out code is no longer needed, it's best to remove it to keep the code clean and maintainable. If the code is still relevant for future reference or development, consider adding comments to explain its purpose and why it's currently commented out.


13-70: LGTM, but consider adding more comments.

The main function provides a clear example of how to interact with the Oraichain DEX for liquidity management using the ZapConsumer class. The code is well-structured and uses appropriate naming conventions.

To further improve the code's readability and maintainability, consider adding more comments to explain the purpose of each code block and the significance of the chosen values for variables like tickSpacing and currentTick.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 98774d1 and 4b10b58.

Files ignored due to path filters (2)
  • packages/contracts-build/data/zapper.wasm is excluded by !**/*.wasm
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (25)
  • .github/workflows/publish_oraiswap_v3.yml (1 hunks)
  • .gitignore (1 hunks)
  • .yarnrc (1 hunks)
  • package.json (1 hunks)
  • packages/contracts-build/package.json (1 hunks)
  • packages/contracts-build/src/index.ts (1 hunks)
  • packages/contracts-sdk/package.json (1 hunks)
  • packages/contracts-sdk/src/Zapper.client.ts (1 hunks)
  • packages/contracts-sdk/src/Zapper.types.ts (1 hunks)
  • packages/contracts-sdk/src/index.ts (1 hunks)
  • packages/oraidex-common/package.json (1 hunks)
  • packages/oraidex-common/src/constant.ts (1 hunks)
  • packages/oraiswap-v3/package.json (1 hunks)
  • packages/oraiswap-v3/src/error.ts (1 hunks)
  • packages/oraiswap-v3/src/handler.ts (3 hunks)
  • packages/oraiswap-v3/src/helpers.ts (3 hunks)
  • packages/oraiswap-v3/src/index.ts (1 hunks)
  • packages/oraiswap-v3/src/main.ts (1 hunks)
  • packages/oraiswap-v3/src/types.ts (2 hunks)
  • packages/oraiswap-v3/src/zap-consumer.ts (1 hunks)
  • packages/oraiswap-v3/tests/handler.spec.ts (1 hunks)
  • packages/oraiswap-v3/tests/zap-consumer.spec.ts (1 hunks)
  • packages/oraiswap-v3/tsconfig.json (1 hunks)
  • packages/oraiswap-v3/tsconfig.test.json (1 hunks)
  • packages/universal-swap/tests/index.spec.ts (1 hunks)
Files skipped from review due to trivial changes (7)
  • .yarnrc
  • packages/contracts-build/package.json
  • packages/contracts-sdk/package.json
  • packages/oraidex-common/package.json
  • packages/oraidex-common/src/constant.ts
  • packages/oraiswap-v3/tests/handler.spec.ts
  • packages/universal-swap/tests/index.spec.ts
Additional context used
Biome
packages/contracts-sdk/src/Zapper.types.ts

[error] 90-90: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)


[error] 86-86: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 88-88: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

packages/oraiswap-v3/src/zap-consumer.ts

[error] 189-189: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

actionlint
.github/workflows/publish_oraiswap_v3.yml

24-24: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


26-26: the runner of "actions/setup-node@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


31-31: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)

Additional comments not posted (67)
packages/oraiswap-v3/src/error.ts (1)

1-5: LGTM!

The RouteNotFoundError class is a well-designed custom error type that extends the built-in Error class. It provides a clear and specific error type for scenarios where a specified route cannot be found.

The constructor correctly calls the superclass constructor with a formatted error message that includes the route parameter, providing useful context about the error.

The class is exported, allowing it to be used in other parts of the codebase to throw and catch this specific error type, which enhances the clarity and maintainability of error management related to routing issues.

packages/oraiswap-v3/src/index.ts (2)

5-5: LGTM!

Exporting the ./zap-consumer module allows consumers of this package to access its functionality through the main entry point. This is a good practice for maintaining a clean public API.


6-6: LGTM!

Exporting the ./error module provides consumers of this package access to custom error classes and error handling utilities. This promotes consistent error handling across the application.

packages/oraiswap-v3/tsconfig.json (1)

1-11: LGTM! Verify the impact of excluding src/main.ts.

The changes in the tsconfig.json file are primarily formatting adjustments and the addition of an exclusion rule for src/main.ts. The exclusion suggests that src/main.ts may contain code that should not be included in the compiled output, such as development-specific or testing code, or that it is intended to be run directly by Node.js.

To verify the impact of excluding src/main.ts, consider the following:

  1. Review the contents of src/main.ts to understand its purpose and dependencies.
  2. Ensure that any necessary code from src/main.ts is properly imported or integrated into other parts of the project.
  3. Test the build process and the application's functionality to confirm that the exclusion of src/main.ts does not introduce any unintended consequences.

If you would like me to assist with this verification process, please provide the contents of src/main.ts and any additional relevant files.

packages/oraiswap-v3/tsconfig.test.json (1)

1-12: LGTM!

The TypeScript configuration file is well-structured and follows best practices:

  • Extending the base tsconfig.json file promotes configuration reuse and consistency across the project.
  • The compilerOptions section includes essential settings for TypeScript compilation, such as baseUrl, outDir, declaration, rootDir, and module.
  • The include and exclude arrays ensure that only relevant files are compiled, optimizing the build process.

The configuration is appropriate for a testing setup, as indicated by the file name tsconfig.test.json.

packages/oraiswap-v3/package.json (4)

3-3: LGTM!

The version increment from 0.1.6 to 0.1.8 is appropriate for a new release with backward-compatible changes.


10-10: LGTM!

Using a separate tsconfig.test.json file for tests is a good practice to keep the production and test configurations separate. This change improves the project's organization and maintainability.


15-15: LGTM!

Updating the @oraichain/oraidex-contracts-sdk dependency to version ^1.0.52 is a good practice to leverage potential new features, bug fixes, or performance improvements while maintaining backward compatibility.


16-16: LGTM!

Changing the @oraichain/oraidex-common dependency from latest to a specific version ^1.1.6 is a good practice for controlled dependency management. It ensures compatibility and stability with a known version while allowing for backward-compatible updates.

.gitignore (3)

38-38: LGTM!

Adding .nx/cache to .gitignore is a good practice to prevent the build cache from being tracked by Git. This keeps the repository clean and reduces its size.


39-39: LGTM!

Adding .nx/workspace-data to .gitignore is a good practice to prevent the workspace data from being tracked by Git. This keeps the repository clean and reduces its size.


41-41: LGTM!

Adding .yarn to .gitignore is a good practice to prevent the Yarn internal data from being tracked by Git. This keeps the repository clean and reduces its size.

packages/contracts-build/src/index.ts (1)

19-20: LGTM!

The addition of the new contract name "zapper" to the ContractName type is a valid change. It expands the set of recognized contract names, potentially allowing for new functionalities or integrations related to the "zapper" contract within the broader application context.

The change is consistent with the existing code style and structure and is unlikely to introduce any bugs or issues.

packages/contracts-sdk/src/index.ts (2)

33-33: LGTM!

The export statement follows the existing pattern and enhances the module's interface by providing access to Zapper-related types.


34-34: LGTM!

The export statement follows the existing pattern and enhances the module's interface by providing access to the Zapper client.

packages/contracts-sdk/src/Zapper.types.ts (14)

1-1: LGTM!

Using a type alias for string is a good practice to provide semantic meaning to the type.


2-6: LGTM!

The interface has descriptive property names and appropriate types. The required properties are clearly defined.


7-32: LGTM!

The union type has descriptive member names and appropriate types. The optional properties provide flexibility in contract interactions.


33-33: LGTM!

Using a type alias for string is a good practice to provide semantic meaning to the type. The type name suggests that it represents an unsigned 128-bit integer.


34-42: LGTM!

The union type has descriptive member names and appropriate types. The required properties are clearly defined for each member.


43-43: LGTM!

Using a type alias for string is a good practice to provide semantic meaning to the type. The type name suggests that it represents liquidity.


44-44: LGTM!

Using a type alias for number is a good practice to provide semantic meaning to the type. The type name suggests that it represents a percentage value.


45-55: LGTM!

The union type has descriptive member names and appropriate types. The required properties are clearly defined for each member.


56-64: LGTM!

The union type has descriptive member names and appropriate types. The required properties are clearly defined for each member.


65-65: LGTM!

Using a type alias for string is a good practice to provide semantic meaning to the type. The type name suggests that it represents a decimal value.


66-69: LGTM!

The interface has descriptive property names and appropriate types. The required properties are clearly defined.


70-74: LGTM!

The interface has descriptive property names and appropriate types. The required properties are clearly defined.


75-78: LGTM!

The interface has descriptive property names and appropriate types. The required properties are clearly defined.


79-84: LGTM!

The interface has descriptive property names and appropriate types. The required properties are clearly defined, and the optional property is marked as such.

.github/workflows/publish_oraiswap_v3.yml (1)

48-52: Good use of "continue-on-error" in the publishing steps.

The "continue-on-error" configuration allows the workflow to attempt publishing all components, even if one fails. This provides better visibility into the status of each component and prevents a single failure from halting the entire workflow.

Also applies to: 55-59, 62-66

package.json (1)

57-57: Verify compatibility and test workflows with the upgraded nx package version.

The upgrade from nx version 18.1.2 to 19.7.3 is a significant version jump. While this change is in the development dependencies and doesn't directly impact the production code, it's important to ensure that the new version is compatible with the project's current setup and doesn't introduce any breaking changes.

Please verify the following:

  1. Review the nx changelog and migration guides to identify any potential breaking changes or required adjustments to the project's nx configuration and workflows.
  2. Test the common development workflows (e.g., building, testing, linting) to ensure they work correctly with the new nx version.
  3. Verify that the project's monorepo structure and any custom nx plugins or scripts are compatible with the upgraded version.

If any issues are encountered during the verification process, please document them and consider if additional changes or configuration updates are necessary to maintain compatibility with the new nx version.

packages/oraiswap-v3/src/main.ts (1)

60-68: LGTM!

The usage of the processZapInPositionLiquidity method and its parameters looks good. The necessary pool key, input token, amount, and tick ranges are correctly provided.

packages/contracts-sdk/src/Zapper.client.ts (4)

10-14: LGTM!

The ZapperReadOnlyInterface is well-defined with appropriate method signatures and return types.


15-36: LGTM!

The ZapperQueryClient correctly implements the ZapperReadOnlyInterface and uses the CosmWasmClient to make the necessary contract queries.


37-78: LGTM!

The ZapperInterface is well-defined with appropriate method signatures, parameter types, and return types. The optional transaction metadata parameters provide flexibility for the client.


79-166: LGTM!

The ZapperClient correctly implements the ZapperInterface and uses the SigningCosmWasmClient to execute the necessary contract methods. The transaction metadata is handled appropriately.

packages/oraiswap-v3/src/types.ts (11)

189-196: LGTM!

The ZapConfig type is well-structured and includes all the necessary properties for configuring a zap operation. The property names are clear and descriptive, and the types are appropriate.


198-206: LGTM!

The ActionRoute type is well-structured and includes all the necessary properties for defining an action route in a zap operation. The property names are clear and descriptive, and the types are appropriate.


208-211: LGTM!

The Path type is well-structured and includes all the necessary properties for defining a path in a zap operation. The property names are clear and descriptive, and the types are appropriate.


213-225: LGTM!

The RouteResponse type is well-structured and includes all the necessary properties for defining a route response in a zap operation. The property names are clear and descriptive, and the types are appropriate. The paths property is an array of objects, which is a good way to represent multiple paths in a route response.


227-231: LGTM!

The SmartRouteResponse type is well-structured and includes all the necessary properties for defining a smart route response in a zap operation. The property names are clear and descriptive, and the types are appropriate. The routes property is an array of RouteResponse objects, which is a good way to represent multiple routes in a smart route response.


233-233: LGTM!

The Protocols type is well-defined and includes all the supported protocols for a zap operation. The use of a union type of string literals is a good way to restrict the possible values for the protocol property.


235-240: LGTM!

The SmartRouteConfig type is well-structured and includes all the necessary properties for configuring a smart route in a zap operation. The property names are clear and descriptive, and the types are appropriate. The swap options property is an object with properties for protocols and max splits, which is a good way to represent the options for a smart route.


248-267: LGTM!

The ZapInLiquidityResponse type is well-structured and includes all the necessary properties for defining a zap in liquidity response. The property names are clear and descriptive, and the types are appropriate. The result property is of type ZapInResult, which is an enum that defines the possible results of a zap in operation.


269-280: LGTM!

The ZapOutLiquidityResponse type is well-structured and includes all the necessary properties for defining a zap out liquidity response. The property names are clear and descriptive, and the types are appropriate. The result property is of type ZapOutResult, which is an enum that defines the possible results of a zap out operation.


282-296: LGTM!

The ZapInResult enum is well-structured and includes all the possible results of a zap in operation. The enum values are clear and descriptive, and they are grouped into error results and success results with different accuracy levels based on the position and route.


298-305: LGTM!

The ZapOutResult enum is well-structured and includes all the possible results of a zap out operation. The enum values are clear and descriptive, and they are grouped into error results and a success result.

packages/oraiswap-v3/src/handler.ts (2)

340-355: LGTM!

The getAllLiquidityTicks function correctly retrieves all liquidity ticks for a given pool key and tickmap. It efficiently iterates through the bitmap, identifies set bits, calculates tick indexes, and fetches the corresponding liquidity tick results.


357-366: LGTM!

The getFullTickmap function correctly generates a complete tickmap for a specified pool key. It efficiently calculates the minimum and maximum ticks, retrieves the tickmap data, and constructs a bitmap mapping each tick to its corresponding value.

packages/oraiswap-v3/src/helpers.ts (9)

282-287: LGTM!

The shiftDecimal function correctly shifts the decimal point of a bigint value by the specified number of places. The logic is sound and the implementation is clear.


289-297: LGTM!

The parseAsset function correctly parses a token and amount into an Asset object. It handles both cases of a token having a contract address or a denom. The logic is straightforward and the implementation is clean.


299-356: LGTM!

The generateMessageSwapOperation function correctly generates Route objects from SmartRouteResponse objects. It handles both OraiSwap and OraiSwapV3 swap operations and constructs the appropriate SwapOperation objects for each. The logic is complex but well-structured and the implementation is thorough.


366-376: LGTM!

The calculatePriceImpact function correctly calculates the price impact between two sqrt prices. The logic is sound and avoids floating point arithmetic by using a denominator. The implementation is clear and concise.


379-436: LGTM!

The getPriceImpactAfterSwap function correctly calculates the price impact of a swap route by simulating each swap operation and accumulating the price impacts. The logic is complex but well-structured and the implementation is thorough. The use of WASM functions for swap simulation is a good optimization.


438-447: LGTM!

The calculateRewardAmounts function correctly calculates the reward amounts for a liquidity position by calling calculateTokenAmounts and applying the zap fee percentage. The logic is straightforward and the implementation is clear.


449-481: LGTM!

The buildZapOutMessage function correctly builds a ZapOutLiquidityResponse message from a ZapOutResult and swap routes. It calculates the minimum receive amounts, generates the swap routes, calculates the total swap fee, and constructs the response object. The logic is clear and the implementation is straightforward.


483-497: LGTM!

The extractOraidexV3Actions function correctly extracts OraidexV3 actions from an array of RouteResponse objects. The logic is straightforward and the implementation is clear and concise.


499-523: LGTM!

The populateMessageZapIn function correctly populates a ZapInLiquidityResponse message with swap and liquidity data. It sets the asset in, amounts, pool key, sqrt price, tick indexes, and swap routes on the message object. The logic is clear and the implementation is straightforward.

packages/oraiswap-v3/src/zap-consumer.ts (9)

53-58: LGTM!

The constructor is correctly initializing the class properties using the provided config object.


64-98: LGTM!

The getPriceInfo method is correctly fetching price data for asset swaps and handling edge cases and errors.


100-143: LGTM!

The findRoute method is correctly identifying optimal routes for asset swaps and handling edge cases and errors.


145-165: LGTM!

The findZapOutRoutes method is correctly finding routes for zap out operations by concurrently calling findRoute for both token X and token Y.


167-186: LGTM!

The findZapInRoutes method is correctly finding routes for zap in operations by concurrently calling findRoute for both token X and token Y.


188-219: LGTM!

The simulateSwapOffChain method is correctly simulating swaps off-chain by fetching the necessary data and calling the WASM module.

Tools
Biome

[error] 189-189: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


221-331: LGTM!

The processZapInWithSingleSide method is correctly processing zap in with a single side by determining the token needed, finding the route, simulating the swap, and populating the zap in message.


333-567: LGTM!

The processZapInPositionLiquidity method is correctly processing zap in position liquidity by fetching the pool, calculating the token amounts, finding the routes, simulating the swap, and populating the zap in message.


569-608: LGTM!

The processZapOutPositionLiquidity method is correctly processing zap out position liquidity by fetching the position, calculating the reward amounts, finding the routes, and building the zap out message.

} | {
protocol_fee: {};
};
export interface MigrateMsg {}
Copy link

Choose a reason for hiding this comment

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

Use a type alias instead of an empty interface.

An empty interface is equivalent to {}, which means "any non-nullable value" and does not provide type safety. Consider using a type alias instead.

For example:

-export interface MigrateMsg {}
+export type MigrateMsg = Record<string, never>;
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 interface MigrateMsg {}
export type MigrateMsg = Record<string, never>;
Tools
Biome

[error] 90-90: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

Comment on lines +85 to +89
export type QueryMsg = {
config: {};
} | {
protocol_fee: {};
};
Copy link

Choose a reason for hiding this comment

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

Update the type definition to explicitly define the shape of the query messages.

Using {} as a type is not recommended because it means "any non-nullable value" and does not provide type safety. Consider updating the type definition to explicitly define the shape of the query messages.

For example:

-export type QueryMsg = {
-  config: {};
-} | {
-  protocol_fee: {};
-};
+export type QueryMsg = {
+  config: {
+    // Define the shape of the config query message
+  };
+} | {
+  protocol_fee: {
+    // Define the shape of the protocol_fee query message
+  };
+};

Committable suggestion was skipped due to low confidence.

Tools
Biome

[error] 86-86: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 88-88: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

node-version: ${{ matrix.node-version }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Copy link

Choose a reason for hiding this comment

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

Update the syntax for setting output variables.

The "set-output" command is deprecated and will be removed in the future. Please update to the new syntax to ensure future compatibility.

-run: echo "::set-output name=dir::$(yarn cache dir)"
+run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
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
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
Tools
actionlint

31-31: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)

access_token: ${{ github.token }}
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
Copy link

Choose a reason for hiding this comment

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

Update the "actions/setup-node" action to the latest version.

The current version of the "actions/setup-node" action is outdated and may cause compatibility issues. Please update to the latest version to ensure proper functionality.

-uses: actions/setup-node@v2
+uses: actions/setup-node@v3
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
uses: actions/setup-node@v2
uses: actions/setup-node@v3
Tools
actionlint

26-26: the runner of "actions/setup-node@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

uses: styfle/cancel-workflow-action@0.8.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
Copy link

Choose a reason for hiding this comment

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

Update the "actions/checkout" action to the latest version.

The current version of the "actions/checkout" action is outdated and may cause compatibility issues. Please update to the latest version to ensure proper functionality.

-uses: actions/checkout@v2
+uses: actions/checkout@v3

Committable suggestion was skipped due to low confidence.

Tools
actionlint

24-24: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Comment on lines +242 to +246
export type SmartRouteReponse = {
swapAmount: string;
returnAmount: string;
routes: any[];
};
Copy link

Choose a reason for hiding this comment

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

Consider changing the type of the routes property to a specific type.

The SmartRouteReponse type is well-structured and includes all the necessary properties for defining a smart route response in a zap operation. The property names are clear and descriptive, and the types are appropriate, except for the routes property.

The routes property is an array of any type, which is not a good practice. It should be an array of a specific type, such as RouteResponse or a new type that defines the structure of a route in a smart route response.

Consider changing the type of the routes property to a specific type, such as RouteResponse or a new type that defines the structure of a route in a smart route response:

export type SmartRouteReponse = {
  swapAmount: string;
  returnAmount: string;
- routes: any[];
+ routes: RouteResponse[];
};

Committable suggestion was skipped due to low confidence.

Comment on lines +358 to +364
export const getFeeRate = (operation: SwapOperation): number => {
if ("orai_swap" in operation) {
return 0.003;
} else {
return operation.swap_v3.pool_key.fee_tier.fee / 10 ** 12;
}
};
Copy link

Choose a reason for hiding this comment

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

Handle unknown operation types.

The getFeeRate function assumes that if the operation is not an OraiSwap operation, it must be an OraiSwapV3 operation. This could lead to errors if a new operation type is introduced in the future.

Consider adding a default case that throws an error for unknown operation types:

export const getFeeRate = (operation: SwapOperation): number => {
  if ("orai_swap" in operation) {
    return 0.003;
+ } else if ("swap_v3" in operation) {
+   return operation.swap_v3.pool_key.fee_tier.fee / 10 ** 12;
  } else {
-   return operation.swap_v3.pool_key.fee_tier.fee / 10 ** 12;
+   throw new Error(`Unknown swap operation type: ${JSON.stringify(operation)}`);
  }
};
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 getFeeRate = (operation: SwapOperation): number => {
if ("orai_swap" in operation) {
return 0.003;
} else {
return operation.swap_v3.pool_key.fee_tier.fee / 10 ** 12;
}
};
export const getFeeRate = (operation: SwapOperation): number => {
if ("orai_swap" in operation) {
return 0.003;
} else if ("swap_v3" in operation) {
return operation.swap_v3.pool_key.fee_tier.fee / 10 ** 12;
} else {
throw new Error(`Unknown swap operation type: ${JSON.stringify(operation)}`);
}
};

@vuonghuuhung vuonghuuhung merged commit 87032d5 into main Sep 18, 2024
3 of 4 checks passed
@vuonghuuhung vuonghuuhung deleted the feat/zapper-2 branch September 18, 2024 10:48
This was referenced Sep 19, 2024
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