Skip to content

feat: migrate to ZetaChain CLI - #273

Merged
fadeev merged 12 commits into
mainfrom
update-cli
Jul 14, 2025
Merged

feat: migrate to ZetaChain CLI#273
fadeev merged 12 commits into
mainfrom
update-cli

Conversation

@fadeev

@fadeev fadeev commented Jul 10, 2025

Copy link
Copy Markdown
Member

Updated contracts to use latest ZetaChain CLI v6 except NFT and Token, because they need to be updated it standard contracts repo.

Call example: disabled calls with --erc20 due to zeta-chain/toolkit#387

Summary by CodeRabbit

  • Chores

    • Updated the "zetachain" dependency to version 6.0.1 in example projects.
    • Modernized and unified localnet startup scripts, now launching all supported chains and updating command-line tool usage.
    • Simplified address extraction and gateway selection in scripts, and included private key usage for signing transactions.
    • Removed deprecated or commented-out commands from swap example scripts.
  • Bug Fixes

    • Corrected the handling of boolean parameters in swap task scripts for accurate transaction encoding.

@coderabbitai

coderabbitai Bot commented Jul 10, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The updates focus on synchronizing the Zetachain dependency to version 6.0.1 across multiple example projects and modernizing the associated shell scripts. Notable changes include revised chain IDs, unified gateway type queries, removal of chain skipping during localnet startup, and enhanced authentication via extracted private keys. Some outdated or redundant commands were removed or commented out.

Changes

File(s) Change Summary
examples/call/package.json
examples/hello/package.json
examples/swap/package.json
Zetachain dependency version updated from ^3.0.0 to 6.0.1; removal of @zetachain/localnet devDependency.
examples/call/scripts/localnet.sh
examples/hello/scripts/localnet.sh
examples/swap/scripts/localnet.sh
Localnet startup no longer skips chains; unified gateway queries; updated chain IDs; switched to yarn zetachain CLI; added private key usage; removed or commented out outdated commands.
examples/swap/tasks/evmSwap.ts Changed evmDepositAndCall argument: passes args.withdraw as a boolean instead of a JSON string.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ShellScript
    participant ZetachainCLI
    participant Localnet
    participant Anvil
    participant Contract

    User->>ShellScript: Run localnet.sh
    ShellScript->>ZetachainCLI: Start localnet (no chains skipped)
    ZetachainCLI->>Localnet: Initialize all chains
    ShellScript->>Anvil: Extract private key from anvil.json
    ShellScript->>ZetachainCLI: Deploy contract (with private key)
    ZetachainCLI->>Contract: Deploy
    ShellScript->>ZetachainCLI: Call contract (with --rpc, --types, --values, --private-key)
    ZetachainCLI->>Contract: Execute call
    ShellScript->>ZetachainCLI: Stop localnet
    ZetachainCLI->>Localnet: Shutdown
Loading
sequenceDiagram
    participant User
    participant evmSwap.ts
    participant Contract

    User->>evmSwap.ts: Call evmDepositAndCall(args)
    evmSwap.ts->>Contract: Send args.withdraw as boolean
    Contract-->>evmSwap.ts: Process boolean withdraw param
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a9ac24 and 14bee76.

⛔ Files ignored due to path filters (3)
  • examples/call/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • examples/hello/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • examples/swap/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • examples/call/package.json (1 hunks)
  • examples/hello/package.json (1 hunks)
  • examples/swap/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • examples/swap/package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • examples/hello/package.json
  • examples/call/package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: test (examples/call)
  • GitHub Check: test (examples/token)
  • GitHub Check: test (examples/hello)
  • GitHub Check: test (examples/nft)
  • GitHub Check: test (examples/swap)
  • GitHub Check: test (examples/swap)
  • GitHub Check: test (examples/token)
  • GitHub Check: test (examples/nft)
  • GitHub Check: test (examples/call)
  • GitHub Check: test (examples/hello)
  • GitHub Check: slither (examples/swap, swap.sarif)
  • GitHub Check: slither (examples/call, call.sarif)
  • GitHub Check: slither (examples/hello, hello.sarif)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@fadeev fadeev changed the title feat: migrate to using ZetaChain CLI feat: migrate to ZetaChain CLI Jul 10, 2025
@fadeev
fadeev marked this pull request as ready for review July 11, 2025 07:20
@fadeev
fadeev requested a review from a team as a code owner July 11, 2025 07:20

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (2)
examples/hello/scripts/localnet.sh (1)

3-5: Remove set -x or mask sensitive data before the private-key step.

With set -x enabled every command – including the line that embeds $PRIVATE_KEY – is echoed to stdout.
If CI logs are public this will leak a live dev key and render the entire example insecure.

-set -x
+# Uncomment locally for troubleshooting only.
+# set -x
examples/swap/scripts/localnet.sh (1)

50-57: --erc20 flag still present but officially disabled – script will abort.

The PR description states that --erc20 support is temporarily disabled (see toolkit #387). These two invocations will now exit with an error and halt the pipeline.

-  --erc20 "$USDC_ETHEREUM" \
+# --erc20 "$USDC_ETHEREUM" \  # Disabled until toolkit#387 is fixed

Either comment them out or gate behind a version check.

Also applies to: 98-103

🧹 Nitpick comments (6)
examples/call/scripts/localnet.sh (2)

15-15: Address unused variable flagged by static analysis.

The ZRC20_BNB variable is defined but never used in the script. Consider removing it if not needed or add a comment explaining its purpose.

-ZRC20_BNB=$(jq -r '.addresses[] | select(.type=="ZRC-20 BNB on 98") | .address' localnet.json)

18-19: Address unused variable and approve private key extraction.

The SENDER variable is flagged as unused by static analysis. The private key extraction is a good addition for automated authentication.

-SENDER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
examples/hello/scripts/localnet.sh (2)

13-14: Fail fast when gateways are missing.

If the jq query returns an empty string the subsequent deployment call silently uses an empty --gateway, producing a cryptic revert later. Add a guard:

: "${GATEWAY_ZETACHAIN:?gateway not found}"
: "${GATEWAY_ETHEREUM:?gateway not found}"

19-28: Avoid hard-coded key path & prefer CLI export to keep home folders clean.

Relying on ~/.zetachain/localnet/anvil.json couples the example to a specific host layout.
Use the CLI export that already understands the running localnet and returns keys in a temp file:

-PRIVATE_KEY=$(jq -r '.private_keys[0]' ~/.zetachain/localnet/anvil.json)
+PRIVATE_KEY=$(yarn zetachain localnet export-keys --json | jq -r '.private_keys[0]')
examples/swap/scripts/localnet.sh (2)

4-7: set -x can be noisy; consider conditional debugging.

No secret is exposed here, yet the log volume is significant (>1 000 lines).
Wrap it with an env flag for cleaner CI runs.

[ -n "$DEBUG" ] && set -x

13-19: Add null-checks for jq look-ups.

A typo in chain IDs (e.g. future test-nets) would propagate empty strings into later swap calls and waste debugging time. Recommend the same guard pattern used above.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69bd3f9 and 8497106.

⛔ Files ignored due to path filters (3)
  • examples/call/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • examples/hello/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • examples/swap/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (7)
  • examples/call/package.json (1 hunks)
  • examples/call/scripts/localnet.sh (2 hunks)
  • examples/hello/package.json (1 hunks)
  • examples/hello/scripts/localnet.sh (1 hunks)
  • examples/swap/package.json (1 hunks)
  • examples/swap/scripts/localnet.sh (1 hunks)
  • examples/swap/tasks/evmSwap.ts (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
examples/call/scripts/localnet.sh

[warning] 15-15: ZRC20_BNB appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 18-18: SENDER appears unused. Verify use (or export if used externally).

(SC2034)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: Cursor BugBot
  • GitHub Check: slither (examples/swap, swap.sarif)
  • GitHub Check: slither (examples/call, call.sarif)
  • GitHub Check: slither (examples/hello, hello.sarif)
  • GitHub Check: test (examples/hello)
  • GitHub Check: test (examples/token)
  • GitHub Check: test (examples/call)
  • GitHub Check: test (examples/swap)
  • GitHub Check: test (examples/nft)
  • GitHub Check: test (examples/call)
  • GitHub Check: test (examples/hello)
  • GitHub Check: test (examples/nft)
  • GitHub Check: test (examples/token)
  • GitHub Check: test (examples/swap)
  • GitHub Check: slither (examples/swap, swap.sarif)
  • GitHub Check: slither (examples/call, call.sarif)
  • GitHub Check: slither (examples/hello, hello.sarif)
🔇 Additional comments (8)
examples/call/package.json (1)

64-64: LGTM: Dependency update aligns with migration objectives.

The zetachain dependency upgrade to version ^6.0.0 is consistent with the PR's goal to migrate to the latest ZetaChain CLI.

examples/hello/package.json (1)

61-61: LGTM: Consistent dependency update across examples.

The zetachain dependency upgrade maintains consistency with other example projects in the migration to CLI version 6.

examples/swap/package.json (1)

62-62: LGTM: Dependency update maintains consistency.

The zetachain dependency upgrade to ^6.0.0 completes the consistent migration pattern across all example projects.

examples/call/scripts/localnet.sh (4)

7-7: LGTM: Simplified localnet startup process.

Removing the chain skipping option allows testing across all supported chains, providing more comprehensive coverage.


16-17: LGTM: Unified gateway type queries improve consistency.

The standardization to "gateway" type simplifies the address resolution logic and aligns with the updated CLI structure.


124-190: LGTM: Comprehensive CLI migration with proper issue handling.

The migration from npx hardhat to yarn zetachain commands is well-executed, with appropriate parameter updates (--gateway-evm → --gateway, --network localhost → --rpc http://localhost:8545) and the addition of --yes and --private-key flags for automation. The commenting out of ERC-20 related commands with reference to the toolkit fix demonstrates proper issue tracking.


13-13: Confirm ZRC-20 ETH chain-ID labeling in generated localnet.json

The jq selector in examples/call/scripts/localnet.sh (line 13) now reads:

ZRC20_ETHEREUM=$(jq -r '.addresses[] | select(.type=="ZRC-20 ETH on 11155112") | .address' localnet.json)

• Please run your updated CLI/localnet startup to produce a fresh localnet.json and verify that the .addresses[].type field exactly matches "ZRC-20 ETH on 11155112" (it was previously …on 5).
• If the label emitted by the CLI differs, adjust this selector to the correct string.

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

67-67: LGTM: Improved parameter handling with direct boolean value.

The change from JSON.stringify(args.withdraw) to args.withdraw reflects an API improvement in the updated zetachain package, providing better type safety by accepting the boolean value directly.

Comment thread examples/hello/scripts/localnet.sh

@hernan-clich hernan-clich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Concept ACK

Comment thread examples/call/package.json Outdated
"@zetachain/protocol-contracts": "13.0.0",
"@zetachain/protocol-contracts-solana": "2.0.0-rc1",
"zetachain": "^3.0.0"
"zetachain": "^6.0.0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems like we're using 6.0.0 here and 6.0.1 on hello, is that intentional? In any case, I would suggest removing the carets to pin the lib version.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Now using 6.0.1 on hello, call and swap: 14bee76

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right that 6.0.1 should be used as 6.0.0 is unreliable.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

6.0.1 for Hello looks good 👌

@s2imonovic s2imonovic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good

@fadeev
fadeev merged commit a8de3b1 into main Jul 14, 2025
20 checks passed
@fadeev
fadeev deleted the update-cli branch July 14, 2025 18:09
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