Skip to content

Conversation

@fadeev
Copy link
Member

@fadeev fadeev commented Oct 8, 2024

Task to swap from EVM using evmDepositAndCall from the toolkit.

EVM → ZetaChain → EVM:

npx hardhat swap-from-evm --network localhost --receiver 0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E --amount 1 --target 0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --withdraw true

ZetaChain → EVM:

npx hardhat swap-from-zetachain --network localhost --contract 0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E --amount 1 --target 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --zrc20 0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c --withdraw true

Summary by CodeRabbit

  • New Features
    • Introduced a new Hardhat task for swapping tokens from the Ethereum Virtual Machine to ZetaChain.
    • Updated existing swap task to enhance functionality and clarity.
  • Dependency Updates
    • Updated versions of @zetachain/localnet and @zetachain/toolkit for improved performance and features.

@fadeev fadeev marked this pull request as ready for review October 14, 2024 11:25
@fadeev fadeev requested a review from andresaiello as a code owner October 14, 2024 11:25
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces modifications to the Hardhat configuration and related task files for the swap functionality. The hardhat.config.ts file updates import statements to include new tasks for swapping tokens from ZetaChain and EVM. Additionally, the package.json file reflects dependency version updates. New task files are introduced, with swapFromEVM.ts defining a task for EVM token swaps, and swapFromZetaChain.ts refining the existing swap task with updated parameters.

Changes

File Path Change Summary
examples/swap/hardhat.config.ts Removed import of swap, added imports for swapFromZetaChain and swapFromEVM.
examples/swap/package.json Updated dependencies: @zetachain/localnet from ^3.0.4 to ^3.3.0, @zetachain/toolkit from 13.0.0-rc4 to 13.0.0-rc5.
examples/swap/tasks/swapFromEVM.ts Introduced swap-from-evm task with evmDepositAndCall function for EVM to ZetaChain swaps.
examples/swap/tasks/swapFromZetaChain.ts Updated task name from swap to swap-from-zetachain, refined parameters including zrc20.

Possibly related PRs

Suggested reviewers

  • andresaiello: Suggested for review based on expertise in the relevant areas of the codebase.

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
Contributor

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

🧹 Outside diff range and nitpick comments (2)
examples/swap/tasks/swapFromZetaChain.ts (1)

21-25: Swap function parameter updates: Approved with suggestion

The modifications to the swap function parameters effectively align the function call with the updated task parameters. The use of args.zrc20 and args.target improves clarity. Converting the recipient to an array of bytes enhances cross-chain compatibility.

However, parsing args.withdraw as JSON may be redundant, given that it's defined as a boolean type in the task definition. Consider simplifying this to:

args.withdraw

This change would maintain type consistency and reduce unnecessary parsing.

examples/swap/tasks/swapFromEVM.ts (1)

41-41: Clarify the distinction between 'receiver' and 'recipient' parameters

Both receiver (line 41) and recipient (line 76) are addresses, which may cause confusion. Ensure that their purposes are clearly documented, and consider renaming one for clarity.

Also applies to: 76-76

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2f1b130 and 23fb660.

⛔ Files ignored due to path filters (1)
  • examples/swap/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • examples/swap/hardhat.config.ts (1 hunks)
  • examples/swap/package.json (2 hunks)
  • examples/swap/tasks/swapFromEVM.ts (1 hunks)
  • examples/swap/tasks/swapFromZetaChain.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (7)
examples/swap/tasks/swapFromZetaChain.ts (4)

1-1: Import statement update: Approved

The addition of types from 'hardhat/config' is a prudent change that enhances type safety and code clarity. This import is utilized effectively in the task definition, contributing to a more robust implementation.


13-15: ZRC20 contract instantiation: Approved

The introduction of the ZRC20 contract instantiation is a crucial addition that facilitates direct interaction with the token contract. This change is necessary for the approval process prior to the swap operation. The implementation adheres to best practices by utilizing ethers.Contract.


32-32: Task name and description update: Approved

The modification of the task name to "swap-from-zetachain" and the updated description "Swap tokens from ZetaChain" significantly enhance clarity. These changes provide a more accurate representation of the task's functionality, which will improve usability for developers interacting with the Hardhat task system.


36-44: Task parameter updates: Approved

The modifications to the task parameters are well-considered and enhance the overall functionality and usability of the task:

  1. The addition of the zrc20 parameter provides necessary flexibility for specifying the input token address.
  2. Renaming targetToken to target maintains consistency with the swap function update.
  3. The withdraw parameter's transformation into an optional parameter with a default value of true and explicit types.boolean type improves usability while ensuring type safety.

These changes collectively contribute to a more robust and developer-friendly task definition.

examples/swap/package.json (2)

60-60: Caution: Update to pre-release version of @zetachain/toolkit.

The "@zetachain/toolkit" package has been updated from "13.0.0-rc4" to "13.0.0-rc5". This update involves a change between release candidate versions, which may introduce breaking changes or significant alterations in functionality.

To ensure the stability and compatibility of this update, please execute the following verification steps:

#!/bin/bash
# Description: Verify the impact of updating @zetachain/toolkit

# Test: Check for breaking changes or new features in the changelog
rg --type md -i '(breaking changes?|new features?)' $(fd -t f -e md CHANGELOG)

# Test: Verify that all imports from @zetachain/toolkit are still valid
rg --type typescript 'from\s+[\'"]@zetachain/toolkit[\'"]'

# Test: Run the test suite to catch any potential issues
npm test

Please review the results carefully and address any breaking changes or failed tests. Consider documenting any new features or changes in behavior that this update introduces.


31-31: Verify compatibility with updated @zetachain/localnet version.

The "@zetachain/localnet" package has been updated from "^3.0.4" to "^3.3.0". While this is a minor version update, it's crucial to ensure that this change doesn't introduce any breaking changes or incompatibilities with the rest of the project.

To verify the impact of this update, please run the following script:

If any breaking changes are found or if the build fails, please review and address them accordingly.

examples/swap/tasks/swapFromEVM.ts (1)

28-29: Ensure 'args.recipient' matches the expected 'bytes' type

The parameter args.recipient is likely an address, but the corresponding type is specified as bytes. If args.recipient should be a byte array, consider encoding it appropriately using ethers.utils.toUtf8Bytes or a similar method.

@Drowzilla

This comment was marked as spam.

@fadeev fadeev merged commit 7cec245 into main Oct 30, 2024
7 checks passed
@fadeev fadeev deleted the swap-from-evm branch October 30, 2024 06:08
@coderabbitai coderabbitai bot mentioned this pull request Oct 30, 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.

4 participants