feat: migrate to ZetaChain CLI - #273
Conversation
📝 WalkthroughWalkthroughThe 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
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
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
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (2)
examples/hello/scripts/localnet.sh (1)
3-5: Removeset -xor mask sensitive data before the private-key step.With
set -xenabled 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 -xexamples/swap/scripts/localnet.sh (1)
50-57:--erc20flag still present but officially disabled – script will abort.The PR description states that
--erc20support 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 fixedEither 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=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266examples/hello/scripts/localnet.sh (2)
13-14: Fail fast when gateways are missing.If the
jqquery 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.jsoncouples 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 -xcan 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 forjqlook-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
⛔ Files ignored due to path filters (3)
examples/call/yarn.lockis excluded by!**/yarn.lock,!**/*.lockexamples/hello/yarn.lockis excluded by!**/yarn.lock,!**/*.lockexamples/swap/yarn.lockis 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 hardhattoyarn zetachaincommands 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.jsonThe 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.jsonand verify that the.addresses[].typefield 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.
| "@zetachain/protocol-contracts": "13.0.0", | ||
| "@zetachain/protocol-contracts-solana": "2.0.0-rc1", | ||
| "zetachain": "^3.0.0" | ||
| "zetachain": "^6.0.0" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Now using 6.0.1 on hello, call and swap: 14bee76
There was a problem hiding this comment.
You're right that 6.0.1 should be used as 6.0.0 is unreliable.
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
--erc20due to zeta-chain/toolkit#387Summary by CodeRabbit
Chores
Bug Fixes