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

Solana and Sui support #232

Merged
merged 25 commits into from
Feb 19, 2025
Merged

Solana and Sui support #232

merged 25 commits into from
Feb 19, 2025

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Jan 31, 2025

  • Swap contract: fixed an issue that prevented swapping to WZETA. It was assumed that the target token is a ZRC-20 and it failed whenever the target was WZETA
  • Added Solana tests to Swap
  • Added Toolkit functions tests to Call
  • Fixed Swap Companion receiver formatting so that it swaps fine to Solana

Summary by CodeRabbit

  • Chores
    • Enhanced the testing workflow with new dependency installation steps.
    • Upgraded key dependencies and refined ignore lists to streamline version control.
  • New Features
    • Expanded local network testing with additional command flows, variables, and adjusted timing for improved interactions.
    • Introduced an optional withdrawal parameter for token swaps to enhance gas fee management.
  • Refactor
    • Modified smart contract functions and task configurations to support more robust transaction handling.
  • Bug Fixes
    • Implemented unconditional revert in the onCall function to prevent unauthorized execution.

Copy link

coderabbitai bot commented Jan 31, 2025

Warning

Rate limit exceeded

@fadeev has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 15 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 30437d3 and 6075698.

📒 Files selected for processing (1)
  • examples/swap/scripts/localnet.sh (5 hunks)
📝 Walkthrough

Walkthrough

This pull request introduces several updates across workflow configurations, project dependency versions, and scripts. A new GitHub Actions step has been added to install the Anchor framework for Solana development. Multiple examples have been updated to adjust dependency versions, ignore certain test files, and modify local network scripts. Additionally, changes to smart contracts introduce control flow modifications: one contract now reverts unconditionally on call, while the swap contract functions have been extended with a new parameter to handle gas fee withdrawals. Minor task modifications further adjust recipient validation and gas limit defaults.

Changes

File(s) Change Summary
.github/workflows/test.yaml Added new step “Install Anchor (Solana)” using metadaoproject/[email protected] in the test job.
examples/call/.gitignore, examples/hello/.gitignore, examples/nft/.gitignore, examples/token/.gitignore, examples/swap/.gitignore Added test-ledger entry; in swap/.gitignore, removed a negated .openzeppelin entry and added entries to ignore both test-ledger and .openzeppelin.
examples/call/package.json, examples/hello/package.json, examples/nft/package.json, examples/swap/package.json, examples/token/package.json Updated dependency versions for @zetachain/localnet and @zetachain/toolkit; removed @zetachain/networks in some projects; updated @zetachain/standard-contracts in nft/token projects.
examples/call/scripts/localnet.sh, examples/swap/scripts/localnet.sh Increased sleep duration; added new variables (e.g., ZRC20_SOL, WZETA) and additional npx hardhat commands; modified address extraction criteria and mnemonic configuration.
examples/hello/contracts/Universal.sol, examples/swap/contracts/Swap.sol In Universal.sol, added an unconditional revert(); in onCall; in Swap.sol, extended function signatures with a new withdraw parameter to alter gas fee management during swaps.
examples/swap/tasks/companionSwap.ts, examples/swap/tasks/evmSwap.ts Updated recipient parameter handling in companionSwap.ts and increased the default gasLimit in evmSwap.ts from 50,000 to 500,000.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as GitHub Runner
    participant Workflow as Test Workflow
    participant Anchor as Anchor Setup
    participant Test as Test Script

    Runner->>Workflow: Start Test Job
    Workflow->>Anchor: Execute "Install Anchor (Solana)" step
    Anchor-->>Workflow: Anchor environment set up
    Workflow->>Test: Run test script
    Test-->>Workflow: Return test results
Loading
sequenceDiagram
    participant User as End User
    participant Swap as Swap Contract
    participant Handler as Gas & Swap Handler

    User->>Swap: Call swap/onCall with `withdraw` flag
    Swap->>Handler: Invoke handleGasAndSwap(inputToken, amount, targetToken, withdraw)
    alt withdraw is true
        Handler-->>Swap: Process gas fee withdrawal logic
    else withdraw is false
        Handler-->>Swap: Execute standard swap logic
    end
    Swap-->>User: Return outcome
Loading

Suggested Reviewers

  • andresaiello

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 closed this Feb 11, 2025
@fadeev fadeev reopened this Feb 11, 2025
@fadeev fadeev changed the title solana localnet Solana and Sui support Feb 12, 2025
@@ -179,33 +181,34 @@
function handleGasAndSwap(
address inputToken,
uint256 amount,
address targetToken
address targetToken,
bool withdraw

Check notice

Code scanning / Slither

Local variable shadowing Low

@fadeev fadeev linked an issue Feb 14, 2025 that may be closed by this pull request
@fadeev fadeev marked this pull request as ready for review February 18, 2025 11:08
@fadeev fadeev requested a review from a team as a code owner February 18, 2025 11:08
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: 0

♻️ Duplicate comments (1)
examples/swap/contracts/Swap.sol (1)

185-185: 🛠️ Refactor suggestion

Avoid parameter name shadowing.
The parameter bool withdraw in handleGasAndSwap shadows the function name withdraw(...) declared at lines 227-271. This might lead to confusion or unintended issues.

Below is a suggested rename to disambiguate:

- function handleGasAndSwap(address inputToken, uint256 amount, address targetToken, bool withdraw)
+ function handleGasAndSwap(address inputToken, uint256 amount, address targetToken, bool shouldWithdraw)
     ...
- if (withdraw) {
+ if (shouldWithdraw) {
🧰 Tools
🪛 GitHub Check: Slither

[notice] 185-185: Local variable shadowing
Swap.handleGasAndSwap(address,uint256,address,bool).withdraw (contracts/Swap.sol#185) shadows:
- Swap.withdraw(Swap.Params,address,uint256,address,uint256,address) (contracts/Swap.sol#227-271) (function)

🧹 Nitpick comments (4)
examples/swap/contracts/Swap.sol (1)

189-211: Enhance revert messages to aid debugging.
When reverting due to insufficient input, consider including the computed minInput in the revert message to help users diagnose failures more quickly.

For example, you might need to import Strings from OpenZeppelin and show the minimum required amount in the revert message:

- revert InsufficientAmount(
-   "The input amount is less than the min amount required to cover the withdraw gas fee"
- );
+ revert InsufficientAmount(
+   string(
+     abi.encodePacked(
+       "The input amount (", Strings.toString(amount),
+       ") is less than the min required (", Strings.toString(minInput),
+       ") to cover the withdraw gas fee"
+     )
+   )
+ );
examples/swap/scripts/localnet.sh (2)

22-22: Addition of DEFAULT_MNEMONIC.
A new variable DEFAULT_MNEMONIC is declared. However, static analysis indicates that it appears unused. Please verify whether this variable is meant to be exported for external use or if it can be removed to avoid confusion.

🧰 Tools
🪛 Shellcheck (0.10.0)

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

(SC2034)


120-144: Commented-Out Revert Test Commands.
Several blocks of commented-out test commands for handling reverts are present. While it is acceptable to disable tests temporarily, please confirm that these lines are either slated for future refinement or removed if no longer needed. Their presence might confuse future maintainers if left without context.

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

14-14: Unused Variable Notice for ZRC20_BNB.
Static analysis has flagged that ZRC20_BNB appears unused in this script. If this variable is not needed, please consider removing it to maintain code clarity. Alternatively, if it is intended for future use, a comment indicating so would be beneficial.

🧰 Tools
🪛 Shellcheck (0.10.0)

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

(SC2034)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 67911fb and 046c1e3.

⛔ Files ignored due to path filters (5)
  • examples/call/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • examples/hello/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • examples/nft/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • examples/swap/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • examples/token/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (17)
  • .github/workflows/test.yaml (1 hunks)
  • examples/call/.gitignore (1 hunks)
  • examples/call/package.json (2 hunks)
  • examples/call/scripts/localnet.sh (2 hunks)
  • examples/hello/.gitignore (1 hunks)
  • examples/hello/contracts/Universal.sol (1 hunks)
  • examples/hello/package.json (2 hunks)
  • examples/nft/.gitignore (1 hunks)
  • examples/nft/package.json (2 hunks)
  • examples/swap/.gitignore (1 hunks)
  • examples/swap/contracts/Swap.sol (4 hunks)
  • examples/swap/package.json (2 hunks)
  • examples/swap/scripts/localnet.sh (5 hunks)
  • examples/swap/tasks/companionSwap.ts (3 hunks)
  • examples/swap/tasks/evmSwap.ts (1 hunks)
  • examples/token/.gitignore (1 hunks)
  • examples/token/package.json (2 hunks)
✅ Files skipped from review due to trivial changes (4)
  • examples/call/.gitignore
  • examples/hello/.gitignore
  • examples/token/.gitignore
  • examples/nft/.gitignore
🧰 Additional context used
🪛 Shellcheck (0.10.0)
examples/call/scripts/localnet.sh

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

(SC2034)

examples/swap/scripts/localnet.sh

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

(SC2034)

🪛 GitHub Check: Slither
examples/swap/contracts/Swap.sol

[notice] 185-185: Local variable shadowing
Swap.handleGasAndSwap(address,uint256,address,bool).withdraw (contracts/Swap.sol#185) shadows:
- Swap.withdraw(Swap.Params,address,uint256,address,uint256,address) (contracts/Swap.sol#227-271) (function)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: slither (examples/swap, swap.sarif)
  • GitHub Check: slither (examples/call, call.sarif)
  • GitHub Check: slither (examples/hello, hello.sarif)
🔇 Additional comments (33)
examples/swap/.gitignore (1)

21-23: Enhanced Ignore Patterns for Test Artifacts and Dependencies

The addition of the test-ledger and .openzeppelin entries ensures that temporary test artifacts and dependency folders are consistently excluded from version control. This update aligns well with the broader repository convention observed in other examples and promotes a cleaner workspace.

examples/swap/contracts/Swap.sol (3)

115-116: Looks good to me.
The added bool withdraw parameter in the function call allows fine-grained control of swap logic. This change appears consistent with the broader refactor to handle withdrawals.


150-155: Parameter alignment is consistent.
Passing the withdrawFlag parameter to handleGasAndSwap follows the same pattern used in onCall, ensuring consistent swap logic across functions.


283-287: Confirm forced withdrawal on revert.
Here, onRevert always passes true for the withdraw parameter to handleGasAndSwap. Ensure that a forced withdrawal on every revert scenario is intended. Consider making it conditional if some reverts should not withdraw tokens automatically.

examples/hello/contracts/Universal.sol (1)

27-27: Double-check the necessity of unconditional revert.
The newly added revert(); ensures this function will never successfully execute its intended logic (e.g., emitting HelloEvent). Confirm this is intentional, as it effectively disables the function.

examples/swap/tasks/companionSwap.ts (3)

13-15: Recipient parameter handling is correct.
Converting non-Ethereum address recipients to UTF-8 bytes ensures broader compatibility. This usage seems appropriate for scenarios involving cross-chain or arbitrary identifiers.


46-47: Recipient parameter well-applied for ERC20 swaps.
Replacing args.recipient with the new recipient variable is consistent with the logic above, which handles address vs. UTF-8 bytes.


56-57: Recipient parameter well-applied for native gas swaps.
Likewise, the same approach for handling the recipient variable ensures consistent behavior across ERC20 and native gas swaps.

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

98-103:

✅ Verification successful

Verify the increased gas limit for complex swap operations.

The gas limit has been increased by 10x, which could be necessary for complex swap operations with Solana. However, let's verify this is not excessive.


🏁 Script executed:

#!/bin/bash
# Description: Check gas usage patterns in swap transactions

# Search for gas usage patterns in tests and contracts
rg -A 5 "gasLimit|gas limit" .

# Search for any gas-related comments or discussions
rg -A 5 "gas consumption|out of gas" .

Length of output: 14339


Gas Limit Increase Verified

The gas limit in examples/swap/tasks/evmSwap.ts has been increased to 500000, which aligns with similar configurations in other tasks throughout the codebase. This change appears consistent with the requirements for supporting complex swap operations (including Solana support). The additional parameter for the revert transaction (set at 50000) remains distinct and intentional.

  • Confirm that the 500000 gas limit is in line with other modules (e.g., in universalCall, connectedDeposit).
  • Ensure that comprehensive testing validates that the increased gas limit does not lead to any unexpected resource consumption issues.
.github/workflows/test.yaml (1)

38-40: LGTM! Well-placed Anchor installation step.

The addition of the Anchor installation step is appropriate for Solana support and uses a pinned version for reproducibility.

examples/swap/package.json (1)

32-32:

❓ Verification inconclusive

Verify compatibility with updated ZetaChain dependencies.

The updates to ZetaChain packages are significant version jumps. Please ensure:

  1. Compatibility between localnet 6.0.0-rc8 and toolkit 13.0.0-rc17
  2. No breaking changes affecting the swap functionality

Also applies to: 60-60


🌐 Web query:

What are the breaking changes in @zetachain/toolkit version 13.0.0-rc17?

💡 Result:

The @zetachain/toolkit v13.0.0-rc17 introduces several breaking changes developers need to address:

Breaking Changes

  1. Removed getGasPrice from EVM module
    The deprecated getGasPrice helper function has been permanently removed from the EVM utilities[1][2]. Use provider-specific gas price estimation instead.

  2. Deprecated LegacyFeeCalculator
    The LegacyFeeCalculator class has been replaced by DynamicFeeCalculator[1][2]. Update imports and instantiate with:

    import { DynamicFeeCalculator } from '@zetachain/toolkit';
    const feeCalculator = new DynamicFeeCalculator();
  3. Environment variable renaming
    ZETA_NETWORK environment variable has been renamed to NETWORK[1][2]. Update your .env files and deployment scripts accordingly.

  4. Transaction parameter changes
    The sendTransaction method now requires parameters as a single object instead of positional arguments[1][2]. Migrate from:

    sendTransaction(signer, contractAddress, abi, methodName, params)

    To:

    sendTransaction({
      signer,
      contractAddress,
      abi,
      methodName,
      params
    })

These changes aim to improve API consistency and prepare for mainnet compatibility[1][2]. Developers should test thoroughly before deploying updates, as some error handling patterns might require adjustment due to underlying Ethers.js updates[1][2].


Verify ZetaChain Dependency Compatibility & Breaking Changes Adjustments

The update to ZetaChain dependencies, notably moving to @zetachain/localnet 6.0.0-rc8 and @zetachain/toolkit 13.0.0-rc17, introduces several breaking changes that could affect the swap functionality:

  • EVM Module Adjustment: The removal of getGasPrice now requires provider-specific gas price estimation.
  • Fee Calculation Update: Replace any usage of the deprecated LegacyFeeCalculator with the new DynamicFeeCalculator.
  • Environment Variable Changes: Update references from ZETA_NETWORK to NETWORK in your configuration files and deployment scripts.
  • Transaction Parameter Update: Modify calls to sendTransaction to pass parameters as a single object rather than as positional arguments.

Please confirm that:

  • The swap functionality has been tested for compatibility with these changes.
  • All instances in the code (or in related modules) that interact with these APIs have been appropriately updated. For example, consider updating:
    - sendTransaction(signer, contractAddress, abi, methodName, params)
    + sendTransaction({ signer, contractAddress, abi, methodName, params })
  • There are no unintended side effects resulting from the removal of older dependencies (e.g., @zetachain/networks) or the inclusion of new Solana-related dependencies.

Kindly review these points to ensure that the integration with updated ZetaChain modules is robust and production-grade.

examples/hello/package.json (1)

31-32: LGTM! Consistent dependency versions.

The dependency versions are kept consistent with other projects in the repository, which is a good practice for maintaining compatibility.

examples/call/package.json (1)

31-32: Dependency Version Upgrades.
The versions for both @zetachain/localnet (updated to 6.0.0-rc8) and @zetachain/toolkit (updated to 13.0.0-rc17) have been upgraded. These changes are consistent with coordinated updates across the repository. Please ensure that any breaking changes in these new versions are accounted for during integration and testing.

examples/token/package.json (2)

31-31: DevDependency Version Upgrade.
The @zetachain/localnet version has been updated to 6.0.0-rc8 in the devDependencies section. This update aligns with similar changes in other examples, ensuring consistency across the project.


61-62: Dependency Updates and Removal.
The dependency @zetachain/standard-contracts has been updated to 1.0.0-rc6 and @zetachain/toolkit to 13.0.0-rc17. Additionally, the removal of @zetachain/networks (as noted in the summary) helps streamline dependency management. Verify that no parts of the project still rely on the removed package.

examples/nft/package.json (2)

31-31: DevDependency Version Upgrade for Localnet.
The update of @zetachain/localnet to version 6.0.0-rc8 is applied here as well. This consistent change across examples reinforces the standardized dependency strategy.


61-62: Dependency Updates and Streamlining.
Both @zetachain/standard-contracts and @zetachain/toolkit have been upgraded to 1.0.0-rc6 and 13.0.0-rc17, respectively. Also, the removal of @zetachain/networks from dependencies further streamlines the setup. Ensure that these changes do not remove any required functionality.

examples/swap/scripts/localnet.sh (14)

7-7: Extended Sleep Duration for Localnet Startup.
The startup command now includes a sleep duration of 15 seconds (increased from 10 seconds) to allow sufficient time for the local network to initialize. This change should help avoid race conditions during deployment.


13-13: Refined USDC Address Selection.
The extraction filter for USDC_ETHEREUM now specifically selects entries with .type=="ERC-20 USDC" and .chain=="ethereum", ensuring greater accuracy when picking the correct address.


16-17: Introduction of New Variables for Enhanced Targeting.
New variables ZRC20_SOL and WZETA have been added to extract specific addresses from localnet.json. This improves the clarity and precision when targeting SOL and the wrapped ZETA token, respectively.


27-35: New EVM Swap Command for WZETA.
A new block invoking npx hardhat evm-swap targets the WZETA address with a reduced swap amount (0.1). This command now explicitly disables withdrawal (--withdraw false) and specifies the recipient. Verify that these parameters correctly reflect the intended behavior of swapping to WZETA.


36-37: Consistent Post-Command Validation.
The immediate call to npx hardhat localnet-check following the swap command ensures that the state is validated. This is a good practice for ensuring transactional integrity.


38-45: Additional EVM Swap Operation.
This subsequent swap command targets the ZRC20_USDC token with similar parameters (amount 0.1, skip checks, designated recipient). The consistency in command structure is commendable; please verify that the adjusted targets deliver expected outcomes.


48-56: Companion-Swap Command for SOL Target.
The npx hardhat companion-swap command now includes an updated --target parameter pointing to ZRC20_SOL and uses a fixed amount of 0.1. This enhances cross-chain operation testing. Ensure that the provided recipient address meets the expected format.


57-57: State Verification After Swap.
The subsequent npx hardhat localnet-check call validates the state post companion-swap. This helps catch potential issues immediately after deployment commands.


59-63: Solana Deposit-and-Call Operation.
The addition of the npx hardhat localnet:solana-deposit-and-call command further tests cross-chain interactions by depositing and calling on Solana with the specified types and parameters. Confirm that the type definitions and argument ordering match the contract expectations.


66-75: Companion-Swap Command for BNB Target.
An additional companion-swap is executed targeting ZRC20_BNB with a swap amount of 0.1. This block is similar in structure to previous swap commands but focuses on a different token. Ensure that token-specific logic (if any) is correctly handled.


77-86: Companion-Swap Using ERC20 Flag.
This companion-swap command includes the --erc20 flag and similarly targets ZRC20_BNB. The explicit adoption of ERC-20 parameters here helps test alternative transaction flows. Validate that this command does not conflict with non-ERC20 operations.


89-97: Standard EVM Swap Execution.
A further npx hardhat evm-swap is performed targeting ZRC20_BNB, maintaining consistency in swap commands while varying parameters like the withdrawal option.


99-107: EVM Swap Command with Explicit No Withdrawal.
This swap command reiterates the no-withdrawal condition (--withdraw false) while targeting ZRC20_BNB. Double-check that disabling withdrawal aligns with test expectations and that downstream logic does not inadvertently rely on a withdrawal flag.


110-117: ZetaChain Swap Invocation.
The npx hardhat zetachain-swap command tests the swap from ZetaChain by targeting ZRC20_ETHEREUM with a fixed amount. The switch to a dedicated ZetaChain swap command should provide broader test coverage across chains.

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

7-7: Localnet Startup Update with Extended Delay.
The startup condition now includes a sleep period of 15 seconds. This additional delay can help ensure that the local network is fully ready before subsequent commands execute.


15-15: Addition of ZRC20_SOL Variable.
A new variable ZRC20_SOL has been introduced to retrieve the SOL token address from localnet.json. This update mirrors similar changes in the swap script and enhances consistency across scripts.

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

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

22-22: Unused DEFAULT_MNEMONIC Variable.
The DEFAULT_MNEMONIC is defined but not referenced elsewhere in the script. Consider exporting it for downstream use or removing it to prevent confusion.

🧰 Tools
🪛 Shellcheck (0.10.0)

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

(SC2034)


55-58: Companion-swap Invocation for SOL Target.
The companion-swap command now targets $ZRC20_SOL with a hardcoded recipient address. While this supports the new Solana swapping flow, consider parameterizing the recipient for greater flexibility in production environments.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 046c1e3 and 30437d3.

📒 Files selected for processing (2)
  • examples/swap/scripts/localnet.sh (5 hunks)
  • examples/swap/tasks/evmSwap.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/swap/tasks/evmSwap.ts
🧰 Additional context used
🪛 Shellcheck (0.10.0)
examples/swap/scripts/localnet.sh

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

(SC2034)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test (examples/call)
🔇 Additional comments (22)
examples/swap/scripts/localnet.sh (22)

7-7: Localnet Startup with Increased Sleep Duration.
The command conditionally starts the local network when invoked with "start" and now includes a 15‑second sleep to accommodate network initialization, aligning with the PR objectives.


13-13: Refined Address Extraction for USDC on Ethereum.
The updated jq filter now selects addresses with type "ERC-20 USDC" and chain "ethereum", ensuring more precise extraction.


16-17: New Address Variables for Solana and WZETA.
The introduction of ZRC20_SOL and WZETA with their respective filters supports the enhanced Solana functionality and proper differentiation of token types.


27-35: Configuring evm-swap for WZETA Transactions.
This evm-swap command is now set to target $WZETA with an amount of 0.1 and includes necessary flags like --gateway-evm and --withdraw false. The configuration aligns with the PR’s objective to resolve previous swap issues.


37-38: Post-Swap Network Check.
The added npx hardhat localnet-check invocation verifies the network’s state immediately after initiating the swap, enhancing operational stability.


39-47: Additional evm-swap for USDC Swap.
This command adjusts the swap parameters to target $ZRC20_USDC, consistent with the refined address extraction logic. It ensures that swaps for USDC are processed correctly on the Ethereum network.


48-48: Immediate Network Health Verification.
The repeated localnet-check call helps confirm network integrity following the previous swap operations.


59-60: Subsequent Network Verification Post Companion-swap.
The following localnet-check confirms that the network remains stable after the companion-swap execution.


61-65: Introduced Solana Deposit-and-Call Operation.
The new npx hardhat localnet:solana-deposit-and-call command facilitates cross-chain interactions by passing explicit parameters (including types, addresses, and flags), enhancing the testing framework.


66-67: Additional Localnet Health Check.
The inclusion of another localnet-check call further reinforces the reliability of the network state after the Solana operation.


68-73: Companion-swap Configuration for BNB Target.
This companion-swap segment initiates a swap targeting $ZRC20_BNB, with the amount explicitly set to 0.1. Though lines 74–75 aren’t marked as changed, the block maintains consistency in the overall swap strategy.


84-84: Companion-swap Enhancement with ERC20 Specification.
The addition of the --erc20 "$USDC_ETHEREUM" flag refines the swap command by explicitly designating the ERC-20 token, which supports accurate transaction processing.


95-95: Uniform evm-swap Parameters for BNB.
The evm-swap command targeting $ZRC20_BNB now explicitly sets the amount to 0.1, matching the consistency observed in other swap operations.


105-105: Explicit No-Withdrawal Behavior.
The inclusion of --withdraw false ensures that no unintended withdrawal occurs, aligning with updated swap flows and providing greater control over transaction behavior.


115-115: Consistent Amount Setting in zetachain-swap.
The parameter setting of --amount 0.1 in the zetachain-swap operation maintains uniformity across all swap commands, thereby supporting a consistent user experience across chains.


122-122: Designation for Revert Testing Section.
The comment # TESTING REVERTS clearly demarcates the section for potential revert test cases, aiding in future troubleshooting and testing efforts.


124-131: Commented-out Revert Test Block for Companion-swap.
This block serves as a reference for testing revert scenarios without interfering with standard operations. Its presence facilitates future debugging when testing error conditions.


132-132: Supplementary Commented-out Network Check for Reverts.
The commented localnet-check call supports the revert testing configuration and is appropriately disabled to prevent accidental execution.


134-138: Optional Solana Deposit-and-Call Revert Test Example.
The commented section provides an alternative test case for simulating reverts in solana deposit-and-call operations, useful for further validation if needed.


141-144: Placeholder for Solana Deposit Revert Testing.
This commented-out block is retained as a potential test scenario for the solana deposit feature, without impacting the current script flow.


145-146: Additional Commented-out localnet-check After Deposit.
This final commented-out check hints at further testing possibilities post-deposit, reinforcing a robust testing strategy.


147-147: Conditional Localnet Shutdown.
The script conditionally stops the local network if it was initiated with the "start" argument, ensuring a clean environment shutdown after operations.

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

utACK

@fadeev fadeev merged commit 15371fc into main Feb 19, 2025
12 checks passed
@fadeev fadeev deleted the solana-localnet branch February 19, 2025 13:12
@coderabbitai coderabbitai bot mentioned this pull request Feb 24, 2025
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.

3 participants