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: nft testnet script #221

Merged
merged 2 commits into from
Dec 2, 2024
Merged

fix: nft testnet script #221

merged 2 commits into from
Dec 2, 2024

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Nov 26, 2024

Summary by CodeRabbit

  • New Features

    • Introduced an optional parameter for specifying deployment gas limits in the NFT contract deployment process.
    • Updated command names to better reflect contract roles in deployment scripts.
    • Increased deployment gas limits for various contracts to accommodate larger deployments.
  • Bug Fixes

    • Enhanced clarity in deployment commands to avoid confusion regarding contract functions.
  • Documentation

    • Improved script output format for deployment success messages, maintaining clarity for users.

Copy link

coderabbitai bot commented Nov 26, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces modifications to deployment scripts for smart contracts in the NFT example directory. Key changes include an adjustment to the deployment gas limit for the Universal contract, renaming commands to reflect updated terminology, and the addition of a new optional parameter for specifying the gas limit in the deployment task. These changes aim to enhance clarity and functionality in the deployment process.

Changes

File Path Change Summary
examples/nft/scripts/testnet.sh - Updated deployment command for Universal contract to use --deploy-gas-limit 10000000.
- Renamed command connected-set-counterparty to connected-set-universal.
- Renamed command universal-set-counterparty to universal-set-connected.
examples/nft/tasks/deploy.ts - Added optional parameter deployGasLimit with a default value of 5000000 to the deployment task.
- Included gasLimit option in deployment transaction options.
examples/nft/scripts/localnet.sh - Added --deploy-gas-limit 10000000 to deployment commands for ZetaChain, Ethereum, and BNB contracts.

Possibly related PRs

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 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 marked this pull request as ready for review November 26, 2024 16:15
@fadeev fadeev requested a review from andresaiello as a code owner November 26, 2024 16:15
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: 2

🧹 Outside diff range and nitpick comments (2)
examples/nft/scripts/testnet.sh (2)

8-8: Consider parameterizing contract addresses and optimizing gas limits

The deployment command contains hardcoded addresses and a high gas limit. Consider:

  1. Moving gateway and uniswap router addresses to environment variables or a config file
  2. Validating if 10M gas limit is necessary, as it could lead to higher deployment costs
-UNIVERSAL=$(npx hardhat deploy --name Universal --network zeta_testnet --deploy-gas-limit 10000000 --gateway 0x6c533f7fe93fae114d0954697069df33c9b74fd7 --uniswap-router 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --gas-limit 500000 --json | jq -r '.contractAddress')
+# Load configuration
+source .env.testnet
+
+UNIVERSAL=$(npx hardhat deploy \
+  --name Universal \
+  --network zeta_testnet \
+  --deploy-gas-limit "${DEPLOY_GAS_LIMIT:-5000000}" \
+  --gateway "${ZETA_GATEWAY_ADDRESS}" \
+  --uniswap-router "${ZETA_UNISWAP_ROUTER}" \
+  --gas-limit 500000 \
+  --json | jq -r '.contractAddress')

Line range hint 1-21: Consider restructuring for improved maintainability and reliability

This deployment script handles critical contract deployments and linking across multiple networks. Consider the following architectural improvements:

  1. Add a comprehensive header comment explaining the deployment flow
  2. Split the script into functions for each deployment phase
  3. Create a separate configuration file for network-specific addresses
  4. Add logging for better deployment tracking
  5. Implement rollback mechanisms for failed deployments

Would you like me to provide an example of this improved structure?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 02373a6 and c59bb65.

📒 Files selected for processing (2)
  • examples/nft/scripts/testnet.sh (1 hunks)
  • examples/nft/tasks/deploy.ts (2 hunks)
🔇 Additional comments (3)
examples/nft/scripts/testnet.sh (1)

9-10: Verify gateway addresses for different networks

The script uses the same gateway address (0x0c487a766110c85d301d96e33579c5b317fa4995) for both Base Sepolia and BSC testnet networks. This seems unusual and should be verified.

examples/nft/tasks/deploy.ts (2)

25-25: LGTM: Explicit gas limit in deployment options

The addition of an explicit gas limit in the deployment options enhances control over the deployment process.


Line range hint 1-72: Verify gas limit values across environments

The deployment gas limits should be verified across different networks to ensure they are sufficient for contract deployment.

✅ Verification successful

Let me analyze the network configurations and gas limits to provide a comprehensive verification of the gas limit values across environments.


Let me analyze the configuration files and network settings to verify the gas limit values across different environments.


Gas limits are appropriately configured across environments

The verification reveals that gas limits are properly handled across different environments:

  • Default deployment gas limit is set to 1,000,000 units (line 53 in deploy.ts)
  • Network-specific gas limits are managed through:
    • Testnet deployments use explicit gas limits (e.g., 10,000,000 for zeta_testnet, 500,000 for other networks)
    • Local development uses configurable gas limits through CLI parameters
    • Production networks inherit configurations from @zetachain/networks package

The gas limit values are appropriately configured for different deployment scenarios and can be overridden when needed through command-line arguments, providing the necessary flexibility while maintaining safe defaults.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for gas limit configurations across deployment scripts

# Search for gas limit configurations in deployment scripts
echo "Searching for gas limit configurations in deployment scripts..."
rg -n "gasLimit|gas.*limit" --type ts

# Search for network-specific configurations
echo "Searching for network-specific configurations..."
fd -e json -e js -e ts --exec grep -l "network.*config" {}

Length of output: 4177


Script:

#!/bin/bash
# Let's check for network-specific configurations and hardhat config files
echo "Searching for hardhat config files..."
fd "hardhat.config" --type ts --type js

echo "Checking content of hardhat config files..."
for config in $(fd "hardhat.config" --type ts --type js); do
  echo "=== Content of $config ==="
  cat "$config"
done

echo "Searching for network-specific gas configurations..."
rg -n "networks.*gas" --type ts --type js

Length of output: 761


Script:

#!/bin/bash
# Let's try a different approach to find configuration files
echo "Searching for hardhat config files..."
find . -name "hardhat.config.*"

echo "Checking content of found config files..."
for config in $(find . -name "hardhat.config.*"); do
  echo "=== Content of $config ==="
  cat "$config"
done

# Let's also check for any network-specific settings in the examples
echo "Checking for network configurations in examples..."
rg -n "network" examples/ --type-not md

Length of output: 24519

Comment on lines 15 to 21
npx hardhat connected-set-universal --network base_sepolia --contract "$CONNECTED_BASE" --universal "$UNIVERSAL" --json

npx hardhat connected-set-counterparty --network bsc_testnet --contract "$CONNECTED_BNB" --counterparty "$UNIVERSAL" --json
npx hardhat connected-set-universal --network bsc_testnet --contract "$CONNECTED_BNB" --universal "$UNIVERSAL" --json

npx hardhat universal-set-counterparty --network zeta_testnet --contract "$UNIVERSAL" --counterparty "$CONNECTED_BASE" --zrc20 "$ZRC20_BASE" --json
npx hardhat universal-set-connected --network zeta_testnet --contract "$UNIVERSAL" --connected "$CONNECTED_BASE" --zrc20 "$ZRC20_BASE" --json

npx hardhat universal-set-counterparty --network zeta_testnet --contract "$UNIVERSAL" --counterparty "$CONNECTED_BNB" --zrc20 "$ZRC20_BNB" --json No newline at end of file
npx hardhat universal-set-connected --network zeta_testnet --contract "$UNIVERSAL" --connected "$CONNECTED_BNB" --zrc20 "$ZRC20_BNB" --json
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add deployment validation and error handling

The contract linking commands lack validation and error handling. Consider adding checks between steps to ensure successful deployment and linking.

+# Function to verify contract deployment
+verify_deployment() {
+  local contract_address=$1
+  local network=$2
+  
+  if [[ ! $contract_address =~ ^0x[a-fA-F0-9]{40}$ ]]; then
+    echo "Error: Invalid contract address for $network"
+    exit 1
+  fi
+}
+
+# Verify deployments
+verify_deployment "$CONNECTED_BASE" "base_sepolia"
+verify_deployment "$CONNECTED_BNB" "bsc_testnet"
+
 npx hardhat connected-set-universal --network base_sepolia --contract "$CONNECTED_BASE" --universal "$UNIVERSAL" --json
+
+# Verify successful linking
+if [ $? -ne 0 ]; then
+  echo "Error: Failed to link Base Sepolia contract"
+  exit 1
+fi

Also consider moving ZRC20 addresses to a configuration file for better maintainability.

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +68 to +72
.addOptionalParam(
"deployGasLimit",
"Gas limit for deploy transaction",
"5000000"
)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Convert deployGasLimit default value to number type

The default value for deployGasLimit is defined as a string "5000000", but should be a number for consistency with other gas-related parameters and to prevent potential type coercion issues.

Apply this change:

  .addOptionalParam(
    "deployGasLimit",
    "Gas limit for deploy transaction",
-   "5000000"
+   5000000,
+   types.int
  )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.addOptionalParam(
"deployGasLimit",
"Gas limit for deploy transaction",
"5000000"
)
.addOptionalParam(
"deployGasLimit",
"Gas limit for deploy transaction",
5000000,
types.int
)

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

🧹 Outside diff range and nitpick comments (1)
examples/nft/scripts/localnet.sh (1)

33-34: Consider using a variable for gas limit values.

The deployment gas limit is repeated across different commands. Consider defining it as a variable at the start of the script for better maintainability.

 #!/bin/bash
 
 set -e
 set -x
+DEPLOY_GAS_LIMIT=10000000
 if [ "$1" = "start" ]; then npx hardhat localnet --exit-on-error & sleep 10; fi

Then use it in the deployment commands:

-CONTRACT_ETHEREUM=$(npx hardhat deploy --name Connected --json --network localhost --deploy-gas-limit 10000000 --gateway "$GATEWAY_ETHEREUM" | jq -r '.contractAddress')
+CONTRACT_ETHEREUM=$(npx hardhat deploy --name Connected --json --network localhost --deploy-gas-limit $DEPLOY_GAS_LIMIT --gateway "$GATEWAY_ETHEREUM" | jq -r '.contractAddress')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c59bb65 and 6d042ac.

📒 Files selected for processing (1)
  • examples/nft/scripts/localnet.sh (1 hunks)
🔇 Additional comments (2)
examples/nft/scripts/localnet.sh (2)

36-37: Clarify the purpose of dual gas limit parameters.

The BNB contract deployment uses both --deploy-gas-limit 10000000 and --gas-limit 1000000. This dual configuration might cause confusion:

  • What's the difference between these parameters?
  • Why is this needed only for BNB chain deployment?

Consider adding comments to explain the purpose of each gas limit parameter.

Let's check if this pattern is documented or used elsewhere:


30-31: Verify the deployment gas limit value for ZetaChain contract.

The deployment gas limit of 10,000,000 seems high. While this might work, it's important to ensure this value is optimized for your contract size and complexity.

Let's analyze the contract size and complexity:

✅ Verification successful

The previous results show the contract structure, but we need to analyze the specific NFT contract being deployed and its deployment configuration to make a proper assessment of the gas limit. This will help us understand if 10M gas limit is justified.


The gas limit of 10,000,000 for NFT contract deployment is justified

The analysis reveals that the NFT contract is complex and requires a high gas limit due to:

  • Multiple inheritance from OpenZeppelin contracts (ERC721, ERC721Enumerable, ERC721URIStorage, ERC721Burnable)
  • Complex cross-chain functionality with gateway interactions
  • Storage initialization for mappings and state variables
  • Constructor parameters initialization and validation

The default deployment gas limit in the Hardhat task is 5,000,000, and given the contract's complexity, the increase to 10,000,000 is a reasonable safety margin to ensure successful deployment on ZetaChain.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check contract size and complexity
# Look for the contract file and analyze its size
fd -e sol | while read -r file; do
  echo "Analyzing $file..."
  # Count lines of code (excluding comments and empty lines)
  cat "$file" | grep -v '^[[:space:]]*$' | grep -v '^[[:space:]]*//' | wc -l
  # Look for potential complex operations that might require high gas
  rg -n "for|while|mapping|struct" "$file"
done

Length of output: 4098


Script:

#!/bin/bash
# Let's specifically analyze the NFT contracts that are being deployed
echo "Analyzing NFT contract content..."
cat examples/nft/contracts/Universal.sol

echo -e "\nChecking for complex operations in NFT contracts..."
rg -n "onZetaMessage|onZetaRevert|transfer|mint" examples/nft/contracts/Universal.sol

echo -e "\nChecking hardhat deploy task to understand gas usage..."
fd -e ts -e js | grep -i "deploy" | xargs cat

Length of output: 15494

@fadeev fadeev merged commit 5abb6f1 into main Dec 2, 2024
13 checks passed
@fadeev fadeev deleted the fix-testnet-script branch December 2, 2024 08:25
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