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

[WIP] Feat/universal swap ton #328

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

[WIP] Feat/universal swap ton #328

wants to merge 13 commits into from

Conversation

haunv3
Copy link
Contributor

@haunv3 haunv3 commented Sep 10, 2024

Summary by CodeRabbit

  • New Features

    • Integrated support for the TON blockchain, enabling token swaps between TON and other networks.
    • Added new functionalities for handling TON addresses and transactions in the Universal Swap feature.
  • Bug Fixes

    • Updated test cases to ensure consistent handling of minimum_receive values and inclusion of affiliates property.
  • Documentation

    • Enhanced comments in code to clarify the purpose of parameters in the buildUniversalSwapMemo function.
  • Chores

    • Updated dependencies and build scripts to streamline the build process across packages.

Copy link

coderabbitai bot commented Sep 10, 2024

Walkthrough

This pull request introduces several changes across multiple packages, primarily focusing on integrating support for the TON blockchain. Key modifications include updates to build scripts, the addition of new dependencies, and enhancements to various functionalities related to token swaps. The UniversalSwapHandler and UniversalSwapHelper have been updated to accommodate TON-specific operations, while new constants and types have been introduced to support the integration. Additionally, existing scripts have been streamlined to unify the build process, and test cases have been refined for better clarity.

Changes

Files Change Summary
package.json, packages/oraidex-common-ui/package.json, packages/oraidex-common/package.json, packages/universal-swap/package.json Updated build scripts to use tsconfig.json instead of tsconfig.test.json and added new dependencies related to TON.
packages/oraidex-common/src/alpha-network.ts, packages/oraidex-common/src/constant.ts, packages/oraidex-common/src/interface/wallet.ts, packages/oraidex-common/src/network.ts Introduced new constants and types for TON, including currency representations and network configurations.
packages/universal-swap/src/handler.ts, packages/universal-swap/src/helper.ts, packages/universal-swap/src/types.ts, packages/universal-swap/src/universal-demos/ton-to-others.ts Enhanced UniversalSwapHandler and UniversalSwapHelper to support TON swaps, including new methods and properties for handling TON addresses and transactions.
packages/universal-swap/tests/index.spec.ts Modified test cases to explicitly handle minimum_receive values and added affiliates property.

Possibly related PRs

Poem

🐇 In the meadow where swaps take flight,
A rabbit hops with pure delight.
With TON now joining the grand parade,
New routes and paths are deftly laid.
Through blockchain fields, we leap and bound,
In the world of swaps, new treasures found! 🌟

Tip

Announcements
  • The review status is no longer posted as a separate comment when there are no actionable or nitpick comments. In such cases, the review status is included in the walkthrough comment.
  • We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs: Walkthrough comment now includes a list of potentially related PRs to help you recall past context. Please share any feedback in the discussion post on our Discord.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs in the walkthrough comment. You can also provide custom labeling instructions in the UI or configuration file.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e02c87b and 89a3e14.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (14)
  • package.json (2 hunks)
  • packages/oraidex-common-ui/package.json (1 hunks)
  • packages/oraidex-common/package.json (1 hunks)
  • packages/oraidex-common/src/alpha-network.ts (1 hunks)
  • packages/oraidex-common/src/constant.ts (2 hunks)
  • packages/oraidex-common/src/interface/wallet.ts (1 hunks)
  • packages/oraidex-common/src/network.ts (6 hunks)
  • packages/universal-swap/package.json (1 hunks)
  • packages/universal-swap/src/handler.ts (13 hunks)
  • packages/universal-swap/src/helper.ts (10 hunks)
  • packages/universal-swap/src/proto/universal-swap-memo-proto-handler.ts (1 hunks)
  • packages/universal-swap/src/types.ts (4 hunks)
  • packages/universal-swap/src/universal-demos/ton-to-others.ts (1 hunks)
  • packages/universal-swap/tests/index.spec.ts (14 hunks)
Files skipped from review due to trivial changes (3)
  • packages/oraidex-common-ui/package.json
  • packages/oraidex-common/package.json
  • packages/universal-swap/src/proto/universal-swap-memo-proto-handler.ts
Additional context used
Gitleaks
packages/oraidex-common/src/constant.ts

122-122: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


127-127: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Biome
packages/universal-swap/src/handler.ts

[error] 240-240: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 980-980: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 981-989: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 991-991: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 995-995: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

Additional comments not posted (38)
packages/oraidex-common/src/interface/wallet.ts (1)

20-22: LGTM!

The addition of Ton and TonTestnet to the ChainIdEnum enumeration is a valid enhancement to support additional blockchain networks.

packages/universal-swap/package.json (1)

10-10: LGTM!

The changes in the package.json file are approved:

  • Using the same tsconfig.json for the build:test script is a good practice to simplify the build process and reduce configuration overhead.
  • Updating the version of @oraichain/oraidex-common dependency to ^1.1.3 is valid to leverage new features, bug fixes, or improvements.

Also applies to: 14-14

packages/universal-swap/src/universal-demos/ton-to-others.ts (1)

1-64: LGTM!

The code in the ton-to-others.ts file is well-structured and follows a logical flow for demonstrating a swap from TON to other tokens. The necessary imports, dependencies, and parameters are properly set up, and the UniversalSwapHandler is used to process the swap. Error handling is also implemented.

The code is approved as is.

packages/oraidex-common/src/alpha-network.ts (2)

68-79: LGTM!

The code segment correctly defines the TON currency representation as a new constant TonOsmosisToken of type BridgeAppCurrency. The properties are populated with appropriate values. This addition enhances the functionality of the module by allowing it to handle transactions involving the TON currency.


81-81: LGTM!

The code segment correctly modifies the existing listOsmosisToken array to include the newly defined TonOsmosisToken. This change is consistent with the addition of the TonOsmosisToken constant and integrates the TON currency into the list of available tokens.

package.json (2)

8-12: Verify the impact of the changes on the testing workflow and build process.

The changes to the test and build:test scripts indicate a shift in the build process prior to running tests and a consolidation of the testing build process into the main build command.

Please verify the following:

  • Ensure that the main build process completes successfully before tests are executed.
  • Confirm that the testing workflow and test results are not negatively impacted by these changes.
  • Verify that the consolidation of the testing build process into the main build command does not introduce any unintended consequences or side effects.

33-35: Verify the usage and impact of the new dependencies.

The addition of @oraichain/tonbridge-sdk and @ton/crypto dependencies indicates an expansion of the project's capabilities, potentially integrating new functionalities related to the TON blockchain and cryptography.

Please verify the following:

  • Ensure that the new dependencies are properly utilized and integrated into the codebase.
  • Confirm that the inclusion of these dependencies does not introduce any compatibility issues or conflicts with existing dependencies.
  • Verify that the new functionalities or features relying on these dependencies are thoroughly tested and documented.
packages/universal-swap/src/types.ts (5)

4-4: LGTM!

The import statement for TonWallet from @oraichain/tonbridge-sdk/build/wallet is consistent with the addition of the @oraichain/tonbridge-sdk dependency in the package.json file. This import enables the usage of the TonWallet type in the file, which is necessary for integrating TON blockchain functionality.


11-13: LGTM!

The addition of the string literals "oraichain-to-ton" and "ton-to-others" to the UniversalSwapType type expands the types of supported swaps to include transactions involving the TON blockchain. This change is consistent with the overall integration of TON blockchain functionality in the codebase.


36-36: LGTM!

The addition of the optional ton property of type string to the Sender interface allows for the specification of a TON wallet address alongside existing properties for other blockchain types. This change reflects an increased capability to handle transactions involving TON wallets and is consistent with the overall integration of TON blockchain functionality.


73-73: LGTM!

The addition of the optional tonWallet property of type TonWallet to the UniversalSwapConfig interface indicates that the configuration can now accommodate a wallet specifically for TON transactions. This change enhances the flexibility and interoperability of the swap functionality across different blockchain networks and is consistent with the overall integration of TON blockchain functionality.


278-278: LGTM!

The correction of the typographical error in the RouterConfigSmartRoute interface, where dontAllowSwapAfter was misspelled as dontAlowSwapAfter, improves the clarity and correctness of the code. This change does not affect the logic or functionality of the code.

packages/oraidex-common/src/constant.ts (3)

24-25: LGTM!

The MIN_TON_FOR_EXECUTE constant is well-defined with a clear purpose explained in the comment.


118-123: LGTM!

The TON-related contract and configuration constants are well-defined and serve the purpose of supporting TON integration.

Tools
Gitleaks

122-122: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


126-127: LGTM!

The TON_BRIDGE_ADAPTER_ORAICHAIN and TOKEN_FACTORY constants are correctly defined.

Tools
Gitleaks

127-127: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

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

57-59: LGTM!

The import of TON20_USDT_CONTRACT and TON_CONTRACT constants is correctly added to support TON integration.


75-76: LGTM!

The addition of "Ton" to the NetworkName type is correctly made to support TON integration.


94-94: LGTM!

The TonChainId type is correctly defined to represent the Ton network's chain ID.


96-96: LGTM!

The modification of the NetworkChainId type to incorporate TonChainId is correctly made to support TON integration.


123-123: LGTM!

The modification of the NetworkType type to include "ton" is correctly made to support TON integration.


157-157: LGTM!

The modification of the CoinType type to include the value 607 for the Ton network is correctly made to support TON integration.


514-563: LGTM!

The tonNetworkMainnet constant is correctly defined to represent the Ton network's mainnet configuration. It includes all the necessary properties and settings for the Ton network.

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

50-51: LGTM!

The import of TON_BRIDGE_ADAPTER_ORAICHAIN constant is correctly added to support TON integration.


83-83: LGTM!

The import of Memo_ContractCall type is correctly added to support the new logic for contract calls.


242-248: LGTM!

The modification of the routerConfig parameter to use the RouterConfigSmartRoute type is correctly made to support the new router configuration.


242-248: LGTM!

The new conditional logic in the getRoute method is correctly implemented to handle specific swap routes for TON integration. It correctly identifies the "oraichain-to-ton" and "ton-to-others" swap scenarios based on the chain IDs of the tokens involved.


346-350: LGTM!

The logging statements in the getRoute method are correctly added to aid in debugging and tracking the flow of data. They output the relevant swap route details, including swapRoute, universalSwapType, and isSmartRouter.


418-435: LGTM!

The modification of the memo construction for the universal swap is correctly implemented to support specific actions for the "ton" destination. The postActionContractCall variable is populated with the necessary contract call message details when the destination chain ID is "ton".


Line range hint 407-456: LGTM!

The refinement of post-action transfers handling is correctly implemented to accommodate the new logic for contract calls and IBC transfers. The postActionIbcWasmTransfer, postActionIbcTransfer, and postActionTransfer variables are defined based on the appropriate conditions and destination chain ID.

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

46-50: LGTM!

The additions of TON-related imports are necessary for integrating TON functionalities.


54-55: LGTM!

The imports of TonbridgeBridgeClient and TonBridgeHandler are necessary to facilitate the transfer of assets to the TON network.


71-74: LGTM!

The additions of TON-specific imports and buildUniversalSwapMemo are necessary for handling TON operations and building the universal swap memo.


103-108: LGTM!

The modifications to the getUniversalSwapToAddress method enhance its capability to handle TON addresses for swaps to the TON network.


1120-1180: LGTM!

The addition of the swapTonToOtherNetwork method enhances the functionality of the UniversalSwapHandler by enabling swaps from TON to other networks. The method ensures the availability of necessary wallet addresses, handles swap route creation, and incorporates error handling and minimum receive amount calculation.


Line range hint 1274-1291: LGTM!

The destructuring of ton from this.swapData.sender allows the processUniversalSwap method to access the TON sender address from the swap data.


1325-1331: LGTM!

The addition of the "ton-to-others" case in the processUniversalSwap method enables handling swaps from TON to other networks by invoking the swapTonToOtherNetwork method.

packages/universal-swap/tests/index.spec.ts (2)

312-313: Verify the impact of using toDisplay for fromAmount.

The change in setting the fromAmount property using the toDisplay function suggests a shift in how the value is represented.

Ensure that this change is thoroughly tested and validated to confirm that it does not introduce any unintended consequences or inconsistencies in the codebase. Verify that the toDisplay function is the appropriate choice for representing the fromAmount value and that it aligns with the expected data type and format used throughout the system.


421-422: Verify the impact of setting minimum_receive to a string "0".

The change in setting the minimum_receive property to a string "0" instead of the variable minimumReceive suggests a shift in how the value is represented.

Ensure that this change is thoroughly tested and validated to confirm that it does not introduce any unintended consequences or inconsistencies in the codebase. Verify that using a hardcoded string "0" is the appropriate choice for representing the minimum_receive value and that it aligns with the expected data type and format used throughout the system.


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>.
    • 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 show all the console.log statements in this repository.
    • @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

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e02c87b and 89a3e14.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (14)
  • package.json (2 hunks)
  • packages/oraidex-common-ui/package.json (1 hunks)
  • packages/oraidex-common/package.json (1 hunks)
  • packages/oraidex-common/src/alpha-network.ts (1 hunks)
  • packages/oraidex-common/src/constant.ts (2 hunks)
  • packages/oraidex-common/src/interface/wallet.ts (1 hunks)
  • packages/oraidex-common/src/network.ts (6 hunks)
  • packages/universal-swap/package.json (1 hunks)
  • packages/universal-swap/src/handler.ts (13 hunks)
  • packages/universal-swap/src/helper.ts (10 hunks)
  • packages/universal-swap/src/proto/universal-swap-memo-proto-handler.ts (1 hunks)
  • packages/universal-swap/src/types.ts (4 hunks)
  • packages/universal-swap/src/universal-demos/ton-to-others.ts (1 hunks)
  • packages/universal-swap/tests/index.spec.ts (14 hunks)
Files skipped from review due to trivial changes (3)
  • packages/oraidex-common-ui/package.json
  • packages/oraidex-common/package.json
  • packages/universal-swap/src/proto/universal-swap-memo-proto-handler.ts
Additional context used
Gitleaks
packages/oraidex-common/src/constant.ts

122-122: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


127-127: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Biome
packages/universal-swap/src/handler.ts

[error] 240-240: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 980-980: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 981-989: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 991-991: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 995-995: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

Additional comments not posted (38)
packages/oraidex-common/src/interface/wallet.ts (1)

20-22: LGTM!

The addition of Ton and TonTestnet to the ChainIdEnum enumeration is a valid enhancement to support additional blockchain networks.

packages/universal-swap/package.json (1)

10-10: LGTM!

The changes in the package.json file are approved:

  • Using the same tsconfig.json for the build:test script is a good practice to simplify the build process and reduce configuration overhead.
  • Updating the version of @oraichain/oraidex-common dependency to ^1.1.3 is valid to leverage new features, bug fixes, or improvements.

Also applies to: 14-14

packages/universal-swap/src/universal-demos/ton-to-others.ts (1)

1-64: LGTM!

The code in the ton-to-others.ts file is well-structured and follows a logical flow for demonstrating a swap from TON to other tokens. The necessary imports, dependencies, and parameters are properly set up, and the UniversalSwapHandler is used to process the swap. Error handling is also implemented.

The code is approved as is.

packages/oraidex-common/src/alpha-network.ts (2)

68-79: LGTM!

The code segment correctly defines the TON currency representation as a new constant TonOsmosisToken of type BridgeAppCurrency. The properties are populated with appropriate values. This addition enhances the functionality of the module by allowing it to handle transactions involving the TON currency.


81-81: LGTM!

The code segment correctly modifies the existing listOsmosisToken array to include the newly defined TonOsmosisToken. This change is consistent with the addition of the TonOsmosisToken constant and integrates the TON currency into the list of available tokens.

package.json (2)

8-12: Verify the impact of the changes on the testing workflow and build process.

The changes to the test and build:test scripts indicate a shift in the build process prior to running tests and a consolidation of the testing build process into the main build command.

Please verify the following:

  • Ensure that the main build process completes successfully before tests are executed.
  • Confirm that the testing workflow and test results are not negatively impacted by these changes.
  • Verify that the consolidation of the testing build process into the main build command does not introduce any unintended consequences or side effects.

33-35: Verify the usage and impact of the new dependencies.

The addition of @oraichain/tonbridge-sdk and @ton/crypto dependencies indicates an expansion of the project's capabilities, potentially integrating new functionalities related to the TON blockchain and cryptography.

Please verify the following:

  • Ensure that the new dependencies are properly utilized and integrated into the codebase.
  • Confirm that the inclusion of these dependencies does not introduce any compatibility issues or conflicts with existing dependencies.
  • Verify that the new functionalities or features relying on these dependencies are thoroughly tested and documented.
packages/universal-swap/src/types.ts (5)

4-4: LGTM!

The import statement for TonWallet from @oraichain/tonbridge-sdk/build/wallet is consistent with the addition of the @oraichain/tonbridge-sdk dependency in the package.json file. This import enables the usage of the TonWallet type in the file, which is necessary for integrating TON blockchain functionality.


11-13: LGTM!

The addition of the string literals "oraichain-to-ton" and "ton-to-others" to the UniversalSwapType type expands the types of supported swaps to include transactions involving the TON blockchain. This change is consistent with the overall integration of TON blockchain functionality in the codebase.


36-36: LGTM!

The addition of the optional ton property of type string to the Sender interface allows for the specification of a TON wallet address alongside existing properties for other blockchain types. This change reflects an increased capability to handle transactions involving TON wallets and is consistent with the overall integration of TON blockchain functionality.


73-73: LGTM!

The addition of the optional tonWallet property of type TonWallet to the UniversalSwapConfig interface indicates that the configuration can now accommodate a wallet specifically for TON transactions. This change enhances the flexibility and interoperability of the swap functionality across different blockchain networks and is consistent with the overall integration of TON blockchain functionality.


278-278: LGTM!

The correction of the typographical error in the RouterConfigSmartRoute interface, where dontAllowSwapAfter was misspelled as dontAlowSwapAfter, improves the clarity and correctness of the code. This change does not affect the logic or functionality of the code.

packages/oraidex-common/src/constant.ts (3)

24-25: LGTM!

The MIN_TON_FOR_EXECUTE constant is well-defined with a clear purpose explained in the comment.


118-123: LGTM!

The TON-related contract and configuration constants are well-defined and serve the purpose of supporting TON integration.

Tools
Gitleaks

122-122: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


126-127: LGTM!

The TON_BRIDGE_ADAPTER_ORAICHAIN and TOKEN_FACTORY constants are correctly defined.

Tools
Gitleaks

127-127: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

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

57-59: LGTM!

The import of TON20_USDT_CONTRACT and TON_CONTRACT constants is correctly added to support TON integration.


75-76: LGTM!

The addition of "Ton" to the NetworkName type is correctly made to support TON integration.


94-94: LGTM!

The TonChainId type is correctly defined to represent the Ton network's chain ID.


96-96: LGTM!

The modification of the NetworkChainId type to incorporate TonChainId is correctly made to support TON integration.


123-123: LGTM!

The modification of the NetworkType type to include "ton" is correctly made to support TON integration.


157-157: LGTM!

The modification of the CoinType type to include the value 607 for the Ton network is correctly made to support TON integration.


514-563: LGTM!

The tonNetworkMainnet constant is correctly defined to represent the Ton network's mainnet configuration. It includes all the necessary properties and settings for the Ton network.

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

50-51: LGTM!

The import of TON_BRIDGE_ADAPTER_ORAICHAIN constant is correctly added to support TON integration.


83-83: LGTM!

The import of Memo_ContractCall type is correctly added to support the new logic for contract calls.


242-248: LGTM!

The modification of the routerConfig parameter to use the RouterConfigSmartRoute type is correctly made to support the new router configuration.


242-248: LGTM!

The new conditional logic in the getRoute method is correctly implemented to handle specific swap routes for TON integration. It correctly identifies the "oraichain-to-ton" and "ton-to-others" swap scenarios based on the chain IDs of the tokens involved.


346-350: LGTM!

The logging statements in the getRoute method are correctly added to aid in debugging and tracking the flow of data. They output the relevant swap route details, including swapRoute, universalSwapType, and isSmartRouter.


418-435: LGTM!

The modification of the memo construction for the universal swap is correctly implemented to support specific actions for the "ton" destination. The postActionContractCall variable is populated with the necessary contract call message details when the destination chain ID is "ton".


Line range hint 407-456: LGTM!

The refinement of post-action transfers handling is correctly implemented to accommodate the new logic for contract calls and IBC transfers. The postActionIbcWasmTransfer, postActionIbcTransfer, and postActionTransfer variables are defined based on the appropriate conditions and destination chain ID.

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

46-50: LGTM!

The additions of TON-related imports are necessary for integrating TON functionalities.


54-55: LGTM!

The imports of TonbridgeBridgeClient and TonBridgeHandler are necessary to facilitate the transfer of assets to the TON network.


71-74: LGTM!

The additions of TON-specific imports and buildUniversalSwapMemo are necessary for handling TON operations and building the universal swap memo.


103-108: LGTM!

The modifications to the getUniversalSwapToAddress method enhance its capability to handle TON addresses for swaps to the TON network.


1120-1180: LGTM!

The addition of the swapTonToOtherNetwork method enhances the functionality of the UniversalSwapHandler by enabling swaps from TON to other networks. The method ensures the availability of necessary wallet addresses, handles swap route creation, and incorporates error handling and minimum receive amount calculation.


Line range hint 1274-1291: LGTM!

The destructuring of ton from this.swapData.sender allows the processUniversalSwap method to access the TON sender address from the swap data.


1325-1331: LGTM!

The addition of the "ton-to-others" case in the processUniversalSwap method enables handling swaps from TON to other networks by invoking the swapTonToOtherNetwork method.

packages/universal-swap/tests/index.spec.ts (2)

312-313: Verify the impact of using toDisplay for fromAmount.

The change in setting the fromAmount property using the toDisplay function suggests a shift in how the value is represented.

Ensure that this change is thoroughly tested and validated to confirm that it does not introduce any unintended consequences or inconsistencies in the codebase. Verify that the toDisplay function is the appropriate choice for representing the fromAmount value and that it aligns with the expected data type and format used throughout the system.


421-422: Verify the impact of setting minimum_receive to a string "0".

The change in setting the minimum_receive property to a string "0" instead of the variable minimumReceive suggests a shift in how the value is represented.

Ensure that this change is thoroughly tested and validated to confirm that it does not introduce any unintended consequences or inconsistencies in the codebase. Verify that using a hardcoded string "0" is the appropriate choice for representing the minimum_receive value and that it aligns with the expected data type and format used throughout the system.

Comment on lines +977 to +997
case "oraichain-to-ton":
if (!this.config.tonWallet)
throw generateError("Cannot transfer and swap if the ton wallet is not initialized");
const wasmBridge = new TonbridgeBridgeClient(client, oraiAddress, TON_BRIDGE_ADAPTER_ORAICHAIN);
const handler = await TonBridgeHandler.create({
wasmBridge,
tonBridge: TON_BRIDGE_ADAPTER,
tonSender: this.config.tonWallet.sender,
tonClientParameters: {
endpoint: "https://toncenter.com/api/v2/jsonRPC"
// apiKey: process.env.TON_API_KEY
}
});

const tonReceiveAddress = await this.config.tonWallet.sender.address.toString();
if (!tonReceiveAddress) throw generateError("Please login ton wallet!");

// TODO: need check TON_CONTRACT or Address of Token In Token
const result = await handler.sendToTon(tonReceiveAddress, toNano(3), TON_CONTRACT);

return result;
Copy link

Choose a reason for hiding this comment

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

LGTM, but fix the switch declaration issue.

The addition of the new case to handle swaps from Oraichain to TON is approved.

However, the declarations inside the switch case can be erroneously accessed by other cases.

Wrap the declarations (wasmBridge, handler, tonReceiveAddress, and result) inside the switch case in a block to restrict their access:

case "oraichain-to-ton":
+  {
    if (!this.config.tonWallet)
      throw generateError("Cannot transfer and swap if the ton wallet is not initialized");
    const wasmBridge = new TonbridgeBridgeClient(client, oraiAddress, TON_BRIDGE_ADAPTER_ORAICHAIN);
    const handler = await TonBridgeHandler.create({
      wasmBridge,
      tonBridge: TON_BRIDGE_ADAPTER,
      tonSender: this.config.tonWallet.sender,
      tonClientParameters: {
        endpoint: "https://toncenter.com/api/v2/jsonRPC"
        //  apiKey: process.env.TON_API_KEY  
      }
    });

    const tonReceiveAddress = await this.config.tonWallet.sender.address.toString();
    if (!tonReceiveAddress) throw generateError("Please login ton wallet!");

    //  TODO: need check TON_CONTRACT or Address of Token In Token
    const result = await handler.sendToTon(tonReceiveAddress, toNano(3), TON_CONTRACT);

    return result;
+  }
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
case "oraichain-to-ton":
if (!this.config.tonWallet)
throw generateError("Cannot transfer and swap if the ton wallet is not initialized");
const wasmBridge = new TonbridgeBridgeClient(client, oraiAddress, TON_BRIDGE_ADAPTER_ORAICHAIN);
const handler = await TonBridgeHandler.create({
wasmBridge,
tonBridge: TON_BRIDGE_ADAPTER,
tonSender: this.config.tonWallet.sender,
tonClientParameters: {
endpoint: "https://toncenter.com/api/v2/jsonRPC"
// apiKey: process.env.TON_API_KEY
}
});
const tonReceiveAddress = await this.config.tonWallet.sender.address.toString();
if (!tonReceiveAddress) throw generateError("Please login ton wallet!");
// TODO: need check TON_CONTRACT or Address of Token In Token
const result = await handler.sendToTon(tonReceiveAddress, toNano(3), TON_CONTRACT);
return result;
case "oraichain-to-ton":
{
if (!this.config.tonWallet)
throw generateError("Cannot transfer and swap if the ton wallet is not initialized");
const wasmBridge = new TonbridgeBridgeClient(client, oraiAddress, TON_BRIDGE_ADAPTER_ORAICHAIN);
const handler = await TonBridgeHandler.create({
wasmBridge,
tonBridge: TON_BRIDGE_ADAPTER,
tonSender: this.config.tonWallet.sender,
tonClientParameters: {
endpoint: "https://toncenter.com/api/v2/jsonRPC"
// apiKey: process.env.TON_API_KEY
}
});
const tonReceiveAddress = await this.config.tonWallet.sender.address.toString();
if (!tonReceiveAddress) throw generateError("Please login ton wallet!");
// TODO: need check TON_CONTRACT or Address of Token In Token
const result = await handler.sendToTon(tonReceiveAddress, toNano(3), TON_CONTRACT);
return result;
}
Tools
Biome

[error] 980-980: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 981-989: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 991-991: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 995-995: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

@haunv3 haunv3 changed the title Feat/universal swap ton [WIP] Feat/universal swap ton Oct 3, 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.

2 participants