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

Fix Call example on localnet #510

Merged
merged 5 commits into from
Dec 5, 2024
Merged

Fix Call example on localnet #510

merged 5 commits into from
Dec 5, 2024

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Nov 28, 2024

Summary by CodeRabbit

  • New Features

    • Updated tutorials for creating contracts on ZetaChain, including accurate deployment commands and contract addresses.
    • Enhanced instructions for invoking the Connected contract, with improved examples for withdrawing tokens and making calls.
    • Introduced a new public swap function in the SwapToAnyToken contract for direct token swaps on ZetaChain.
    • Added flexibility to the SwapToAnyToken contract, allowing users to choose between withdrawing swapped tokens or retaining them on ZetaChain.
  • Bug Fixes

    • Corrected typos in deployment commands and updated contract addresses for clarity.
    • Clarified handling of gas fees and token approvals in the swap contract tutorial.

@fadeev fadeev requested review from bbbeeeee, brewmaster012 and a team as code owners November 28, 2024 10:44
Copy link

vercel bot commented Nov 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview Dec 5, 2024 5:08pm

Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces modifications to the tutorials for deploying contracts for cross-chain interactions using ZetaChain. Key updates include corrections to typos in deployment commands, accurate contract addresses for the Universal and Connected contracts, and enhanced instructions for invoking these contracts. Additionally, method signatures in the Connected and Universal contracts have been updated to include new parameters, ensuring that users have precise information for deploying and managing tokens across chains.

Changes

File Path Change Summary
src/pages/developers/tutorials/call.mdx Updated tutorial content for deploying Universal and Connected contracts, corrected typos, and provided clearer command examples with accurate contract addresses.
contracts/Connected.sol Updated method signatures for deposit, depositAndCall (overloaded), and withdrawAndCall to include new parameters (amount, asset, message).
contracts/Universal.sol Updated method signatures for withdrawAndCall to accommodate new parameters while maintaining overloads.
src/pages/developers/tutorials/swap-any.mdx Enhanced SwapToAnyToken contract functionality, added withdraw flag in Params, and updated swapAndWithdraw function to handle gas fees based on the withdraw option. Added new swap function for direct interactions.
src/pages/developers/tutorials/swap.mdx Updated deployment commands and swap instructions, including new parameters and correct ZRC-20 token addresses.

Possibly related PRs

  • Update Swap tutorial with better localnet support #490: Enhancements to the SwapToAnyToken contract for cross-chain swaps, related to the functionality of the Connected and Universal contracts.
  • Swap from ZetaChain tutorial #393: Modifications to the Swap contract, including updates to the swapAndWithdraw function, aligning with changes in the withdrawAndCall function in the Universal contract.
  • Overview doc and section description #375: Updates to documentation that may relate to the overall structure and functionality of contracts discussed in the main PR, particularly in cross-chain interactions.
  • Updated Localnet doc #481: Updates to Localnet documentation relevant to deployment and functionality of contracts in a cross-chain context, including local development setups.
  • localnet #443: Introduction of a localnet tutorial aligning with the main PR's focus on deploying contracts and interacting with them in a local environment.

Suggested reviewers

  • bbbeeeee
  • brewmaster012
  • andresaiello

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c9c4f12 and 3baabd8.

📒 Files selected for processing (2)
  • src/pages/developers/tutorials/swap-any.mdx (7 hunks)
  • src/pages/developers/tutorials/swap.mdx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pages/developers/tutorials/swap.mdx
🔇 Additional comments (4)
src/pages/developers/tutorials/swap-any.mdx (4)

273-277: LGTM: Well-structured deployment command

The command is clear, properly formatted, and includes all necessary parameters for local deployment.


286-286: LGTM: Clear example output

The example output clearly shows the deployed contract address format.


295-301: Consider improving command formatting for better readability

The commands are functionally correct but could benefit from consistent formatting. Consider using the multi-line format with line continuations for all commands to improve readability.

Example format:

npx hardhat swap-from-evm \
  --network localhost \
  --receiver 0xc351628EB244ec633d5f21fBD6621e1a683B1181 \
  --amount 1 \
  --target 0x05BA149A7bd6dC1F937fA9046A9e05C05f3b18b0 \
  --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
  --withdraw true

Also applies to: 321-327, 339-346, 355-362


378-378: Reference a specific commit or tag for stability

The source code URL points to the main branch, which may change over time. Consider referencing a specific commit hash or release tag to ensure users access the correct version of the code.


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

🧹 Outside diff range and nitpick comments (1)
src/pages/developers/tutorials/call.mdx (1)

461-461: Document the purpose of the arbitrary call flag.

The --call-options-is-arbitrary-call flag has been added, but its purpose and implications aren't explained in the tutorial. Consider adding a brief explanation of when and why this flag should be used.

Here's a suggested addition to the documentation:

  --network localhost \
+ # The --call-options-is-arbitrary-call flag indicates that this is an arbitrary cross-chain call
+ # rather than an authenticated call. This is required when calling specific functions on the target contract.
  --call-options-is-arbitrary-call \
  --types '["string"]' hello
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between df80461 and 8981fce.

📒 Files selected for processing (1)
  • src/pages/developers/tutorials/call.mdx (5 hunks)
🔇 Additional comments (2)
src/pages/developers/tutorials/call.mdx (2)

398-398: LGTM: Contract deployment commands and addresses are accurate.

The gateway addresses and deployment commands are correctly configured for the localnet environment.

Also applies to: 407-407, 411-412


426-427: LGTM: Contract interaction commands are properly structured.

The contract addresses are consistent with the deployment output, and the commands include all necessary parameters.

Also applies to: 441-442, 456-458

@fadeev
Copy link
Member Author

fadeev commented Nov 29, 2024

@bbbeeeee @brewmaster012 @zeta-chain/fullstack please, review.

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

🧹 Outside diff range and nitpick comments (2)
src/pages/developers/tutorials/swap-any.mdx (1)

291-297: Enhance example commands with varied scenarios

The example commands use identical addresses for the recipient across all scenarios. Consider:

  1. Using different recipient addresses to better illustrate real-world usage
  2. Adding comments explaining the expected token flows
  3. Including examples with different token amounts

Also applies to: 317-323, 335-342, 351-358

src/pages/developers/tutorials/swap.mdx (1)

326-331: Enhance command documentation with token details

The swap commands have been updated with new contract and token addresses. To improve clarity, consider:

  1. Adding comments to explain what each token address represents (e.g., which token is 0x05BA149A7bd6dC1F937fA9046A9e05C05f3b18b0)
  2. Including expected output or transaction results
  3. Adding error handling scenarios

Add a table or code comments in this format:

| Parameter | Value | Description |
|-----------|-------|-------------|
| --target | 0x05BA... | ZRC-20 USDC token on ZetaChain |
| --erc20 | 0xE6E3... | USDC token on the source chain |

Also applies to: 361-367

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8981fce and c9c4f12.

📒 Files selected for processing (2)
  • src/pages/developers/tutorials/swap-any.mdx (7 hunks)
  • src/pages/developers/tutorials/swap.mdx (6 hunks)
🔇 Additional comments (1)
src/pages/developers/tutorials/swap-any.mdx (1)

273-274: Verify gateway and router addresses for localnet deployment

The deployment command uses hardcoded addresses. While these may be correct for localnet, it's important to ensure they are properly validated.

✅ Verification successful

The gateway and router addresses are correctly documented for localnet deployment

The addresses used in the deployment command are consistent with the documented contract addresses in the localnet environment:

  • The Gateway EVM address (0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0) is documented in localnet.mdx
  • These addresses are consistently used across multiple tutorial files (swap.mdx, swap-any.mdx, hello.mdx, call.mdx)
  • The deployment command follows the established pattern used in other tutorial examples
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if the gateway and router addresses are valid contract addresses on localnet

# Check if the addresses contain contract code
for addr in "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707" "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"; do
  rg -l "address.*${addr}" || echo "Address ${addr} not found in codebase"
done

Length of output: 641


Script:

#!/bin/bash
# Let's search for any mentions of these addresses in the tutorial file and related files
rg -l "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707|0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" 

# Let's also check if there are any other deployment examples or address patterns in tutorials
fd . src/pages/developers/tutorials -t f -e mdx --exec rg -l "npx hardhat deploy.*--network localhost"

# Check if there's any documentation about these addresses
fd . -t f -e md -e mdx --exec rg -l "localnet.*address|localhost.*address"

Length of output: 697


Script:

#!/bin/bash
# Let's check the content of localnet.mdx to see if these addresses are documented
rg -A 5 -B 5 "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707|0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" src/pages/developers/tutorials/localnet.mdx

# Also check the context in other tutorial files
rg -A 5 -B 5 "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707|0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" src/pages/developers/tutorials/*.mdx

# Check if there's any explanation about default addresses
rg "default.*address.*local|localhost.*default.*address" src/pages/developers/tutorials/*.mdx

Length of output: 6050

src/pages/developers/tutorials/swap-any.mdx Show resolved Hide resolved
src/pages/developers/tutorials/swap.mdx Show resolved Hide resolved
src/pages/developers/tutorials/swap.mdx Outdated Show resolved Hide resolved
Copy link
Member

@hernan-clich hernan-clich left a comment

Choose a reason for hiding this comment

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

Tested ACK

src/pages/developers/tutorials/swap-any.mdx Outdated Show resolved Hide resolved
src/pages/developers/tutorials/swap.mdx Outdated Show resolved Hide resolved
@fadeev fadeev merged commit e15b128 into main Dec 5, 2024
5 checks passed
@fadeev fadeev deleted the fix-call-example-localnet branch December 5, 2024 17:33
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