From 57ceeb87aca74c023e9a9561136983f2708b1bf3 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Sat, 16 Nov 2024 19:48:47 +0300 Subject: [PATCH] rename test.sh to localnet.sh --- .github/workflows/test.yaml | 4 +- examples/call/contracts/Connected.sol | 16 ++-- examples/call/contracts/Universal.sol | 32 ++++---- .../call/scripts/{test.sh => localnet.sh} | 4 +- examples/hello/scripts/test.sh | 25 ------- examples/nft/scripts/test.sh | 73 ------------------ examples/swap/scripts/test.sh | 26 ------- examples/token/scripts/test.sh | 75 ------------------- 8 files changed, 28 insertions(+), 227 deletions(-) rename examples/call/scripts/{test.sh => localnet.sh} (95%) delete mode 100755 examples/hello/scripts/test.sh delete mode 100755 examples/nft/scripts/test.sh delete mode 100755 examples/swap/scripts/test.sh delete mode 100755 examples/token/scripts/test.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1fdd0546..5ebada78 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -39,5 +39,5 @@ jobs: run: | cd "${{ matrix.example-dir }}" yarn - chmod +x ./scripts/test.sh - ./scripts/test.sh localnet + chmod +x ./scripts/localnet.sh + ./scripts/localnet.sh start diff --git a/examples/call/contracts/Connected.sol b/examples/call/contracts/Connected.sol index c50afa76..5a9b57bb 100644 --- a/examples/call/contracts/Connected.sol +++ b/examples/call/contracts/Connected.sol @@ -22,6 +22,14 @@ contract Connected { gateway = GatewayEVM(gatewayAddress); } + function call( + address receiver, + bytes calldata message, + RevertOptions memory revertOptions + ) external { + gateway.call(receiver, message, revertOptions); + } + function deposit( address receiver, RevertOptions memory revertOptions @@ -60,14 +68,6 @@ contract Connected { gateway.depositAndCall(receiver, amount, asset, message, revertOptions); } - function call( - address receiver, - bytes calldata message, - RevertOptions memory revertOptions - ) external { - gateway.call(receiver, message, revertOptions); - } - function depositAndCall( address receiver, bytes calldata message, diff --git a/examples/call/contracts/Universal.sol b/examples/call/contracts/Universal.sol index a71e7245..5b9f6c05 100644 --- a/examples/call/contracts/Universal.sol +++ b/examples/call/contracts/Universal.sol @@ -22,6 +22,22 @@ contract Universal is UniversalContract { gateway = GatewayZEVM(gatewayAddress); } + function call( + bytes memory receiver, + address zrc20, + bytes calldata message, + CallOptions memory callOptions, + RevertOptions memory revertOptions + ) external { + (, uint256 gasFee) = IZRC20(zrc20).withdrawGasFeeWithGasLimit( + callOptions.gasLimit + ); + if (!IZRC20(zrc20).transferFrom(msg.sender, address(this), gasFee)) + revert TransferFailed(); + IZRC20(zrc20).approve(address(gateway), gasFee); + gateway.call(receiver, zrc20, message, callOptions, revertOptions); + } + function withdraw( bytes memory receiver, uint256 amount, @@ -46,22 +62,6 @@ contract Universal is UniversalContract { gateway.withdraw(receiver, amount, zrc20, revertOptions); } - function call( - bytes memory receiver, - address zrc20, - bytes calldata message, - CallOptions memory callOptions, - RevertOptions memory revertOptions - ) external { - (, uint256 gasFee) = IZRC20(zrc20).withdrawGasFeeWithGasLimit( - callOptions.gasLimit - ); - if (!IZRC20(zrc20).transferFrom(msg.sender, address(this), gasFee)) - revert TransferFailed(); - IZRC20(zrc20).approve(address(gateway), gasFee); - gateway.call(receiver, zrc20, message, callOptions, revertOptions); - } - function withdrawAndCall( bytes memory receiver, uint256 amount, diff --git a/examples/call/scripts/test.sh b/examples/call/scripts/localnet.sh similarity index 95% rename from examples/call/scripts/test.sh rename to examples/call/scripts/localnet.sh index 3435c5fa..bc49c87b 100755 --- a/examples/call/scripts/test.sh +++ b/examples/call/scripts/localnet.sh @@ -2,7 +2,7 @@ set -e -if [ "$1" = "localnet" ]; then npx hardhat localnet --exit-on-error & sleep 10; fi +if [ "$1" = "start" ]; then npx hardhat localnet --exit-on-error & sleep 10; fi echo -e "\nšŸš€ Compiling contracts..." npx hardhat compile --force --quiet @@ -105,4 +105,4 @@ npx hardhat universal-withdraw-and-call \ npx hardhat localnet-check -if [ "$1" = "localnet" ]; then npx hardhat localnet-stop; fi \ No newline at end of file +if [ "$1" = "start" ]; then npx hardhat localnet-stop; fi \ No newline at end of file diff --git a/examples/hello/scripts/test.sh b/examples/hello/scripts/test.sh deleted file mode 100755 index 733ec74f..00000000 --- a/examples/hello/scripts/test.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -set -e -set -x - -if [ "$1" = "localnet" ]; then npx hardhat localnet --exit-on-error & sleep 10; fi - -echo -e "\nšŸš€ Compiling contracts..." -npx hardhat compile --force --quiet - -GATEWAY_ETHEREUM=$(jq -r '.addresses[] | select(.type=="gatewayEVM" and .chain=="ethereum") | .address' localnet.json) -GATEWAY_ZETACHAIN=$(jq -r '.addresses[] | select(.type=="gatewayZEVM" and .chain=="zetachain") | .address' localnet.json) - -CONTRACT_ZETACHAIN=$(npx hardhat deploy --name Universal --network localhost --gateway "$GATEWAY_ZETACHAIN" --json | jq -r '.contractAddress') -echo -e "\nšŸš€ Deployed contract on ZetaChain: $CONTRACT_ZETACHAIN" - -npx hardhat evm-call \ - --gateway-evm "$GATEWAY_ETHEREUM" \ - --receiver "$CONTRACT_ZETACHAIN" \ - --network localhost \ - --types '["string"]' alice - -npx hardhat localnet-check - -if [ "$1" = "localnet" ]; then npx hardhat localnet-stop; fi \ No newline at end of file diff --git a/examples/nft/scripts/test.sh b/examples/nft/scripts/test.sh deleted file mode 100755 index b984f8b6..00000000 --- a/examples/nft/scripts/test.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash - -set -e -set -x - -if [ "$1" = "localnet" ]; then npx hardhat localnet --exit-on-error & sleep 10; fi - -function balance() { - local ZETACHAIN=$(cast call "$CONTRACT_ZETACHAIN" "balanceOf(address)(uint256)" "$SENDER") - local ETHEREUM=$(cast call "$CONTRACT_ETHEREUM" "balanceOf(address)(uint256)" "$SENDER") - local BNB=$(cast call "$CONTRACT_BNB" "balanceOf(address)(uint256)" "$SENDER") - echo -e "\nšŸ–¼ļø NFT Balance" - echo "---------------------------------------------" - echo "šŸŸ¢ ZetaChain: $ZETACHAIN" - echo "šŸ”µ Ethereum: $ETHEREUM" - echo "šŸŸ” BNB Chain: $BNB" - echo "---------------------------------------------" -} - -echo -e "\nšŸš€ Compiling contracts..." -npx hardhat compile --force --quiet - -ZRC20_ETHEREUM=$(jq -r '.addresses[] | select(.type=="ZRC-20 ETH on 5") | .address' localnet.json) -ZRC20_BNB=$(jq -r '.addresses[] | select(.type=="ZRC-20 BNB on 97") | .address' localnet.json) -GATEWAY_ETHEREUM=$(jq -r '.addresses[] | select(.type=="gatewayEVM" and .chain=="ethereum") | .address' localnet.json) -GATEWAY_BNB=$(jq -r '.addresses[] | select(.type=="gatewayEVM" and .chain=="bnb") | .address' localnet.json) -SENDER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 - -CONTRACT_ZETACHAIN=$(npx hardhat deploy --network localhost --gateway 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 --system-contract 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 --json --gas-limit 1000000 | jq -r '.contractAddress') -echo -e "\nšŸš€ Deployed NFT contract on ZetaChain: $CONTRACT_ZETACHAIN" - -CONTRACT_ETHEREUM=$(npx hardhat deploy --name Connected --json --network localhost --gas-limit 1000000 --gateway "$GATEWAY_ETHEREUM" | jq -r '.contractAddress') -echo -e "šŸš€ Deployed NFT contract on Ethereum: $CONTRACT_ETHEREUM" - -CONTRACT_BNB=$(npx hardhat deploy --name Connected --json --network localhost --gas-limit 1000000 --gateway "$GATEWAY_BNB" | jq -r '.contractAddress') -echo -e "šŸš€ Deployed NFT contract on BNB chain: $CONTRACT_BNB" - -echo -e "\nšŸ“® User Address: $SENDER" - -echo -e "\nšŸ”— Setting counterparty contracts..." -npx hardhat connected-set-counterparty --network localhost --contract "$CONTRACT_ETHEREUM" --counterparty "$CONTRACT_ZETACHAIN" --json &>/dev/null -npx hardhat connected-set-counterparty --network localhost --contract "$CONTRACT_BNB" --counterparty "$CONTRACT_ZETACHAIN" --json &>/dev/null -npx hardhat universal-set-counterparty --network localhost --contract "$CONTRACT_ZETACHAIN" --counterparty "$CONTRACT_ETHEREUM" --zrc20 "$ZRC20_ETHEREUM" --json &>/dev/null -npx hardhat universal-set-counterparty --network localhost --contract "$CONTRACT_ZETACHAIN" --counterparty "$CONTRACT_BNB" --zrc20 "$ZRC20_BNB" --json &>/dev/null - -npx hardhat localnet-check -balance - -NFT_ID=$(npx hardhat mint --network localhost --json --contract "$CONTRACT_ZETACHAIN" --token-uri https://example.com/nft/metadata/1 | jq -r '.tokenId') -echo -e "\nMinted NFT with ID: $NFT_ID on ZetaChain." - -npx hardhat localnet-check -balance - -echo -e "\nTransferring NFT: ZetaChain ā†’ Ethereum..." -npx hardhat transfer --network localhost --json --token-id "$NFT_ID" --from "$CONTRACT_ZETACHAIN" --to "$ZRC20_ETHEREUM" - -npx hardhat localnet-check -balance - -echo -e "\nTransferring NFT: Ethereum ā†’ BNB..." -npx hardhat transfer --network localhost --json --token-id "$NFT_ID" --from "$CONTRACT_ETHEREUM" --to "$ZRC20_BNB" --gas-amount 0.1 - -npx hardhat localnet-check -balance - -echo -e "\nTransferring NFT: BNB ā†’ ZetaChain..." -npx hardhat transfer --network localhost --json --token-id "$NFT_ID" --from "$CONTRACT_BNB" - -npx hardhat localnet-check -balance - -if [ "$1" = "localnet" ]; then npx hardhat localnet-stop; fi \ No newline at end of file diff --git a/examples/swap/scripts/test.sh b/examples/swap/scripts/test.sh deleted file mode 100755 index 461e6b6a..00000000 --- a/examples/swap/scripts/test.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -set -e - -if [ "$1" = "localnet" ]; then npx hardhat localnet --exit-on-error & sleep 10; fi - -echo -e "\nšŸš€ Compiling contracts..." -npx hardhat compile --force --quiet - -ZRC20_ETHEREUM=$(jq -r '.addresses[] | select(.type=="ZRC-20 ETH on 5") | .address' localnet.json) -ZRC20_USDC=$(jq -r '.addresses[] | select(.type=="ZRC-20 USDC on 97") | .address' localnet.json) -GATEWAY_ETHEREUM=$(jq -r '.addresses[] | select(.type=="gatewayEVM" and .chain=="ethereum") | .address' localnet.json) -GATEWAY_ZETACHAIN=$(jq -r '.addresses[] | select(.type=="gatewayZEVM" and .chain=="zetachain") | .address' localnet.json) -SENDER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 - -CONTRACT_ZETACHAIN=$(npx hardhat deploy --name Swap --network localhost --gateway "$GATEWAY_ZETACHAIN" --json | jq -r '.contractAddress') -echo -e "\nšŸš€ Deployed contract on ZetaChain: $CONTRACT_ZETACHAIN" - -npx hardhat swap-from-evm \ - --network localhost \ - --receiver "$CONTRACT_ZETACHAIN" \ - --amount 1 \ - --target "$ZRC20_USDC" \ - --recipient "$SENDER" - -if [ "$1" = "localnet" ]; then npx hardhat localnet-stop; fi \ No newline at end of file diff --git a/examples/token/scripts/test.sh b/examples/token/scripts/test.sh deleted file mode 100755 index 737b5031..00000000 --- a/examples/token/scripts/test.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -set -e - -if [ "$1" = "localnet" ]; then - npx hardhat localnet --exit-on-error & sleep 10 -fi - -function balance() { - echo -e "\nšŸ–¼ļø Balance" - echo "---------------------------------------------" - local ZETACHAIN=$(cast call "$CONTRACT_ZETACHAIN" "balanceOf(address)(uint256)" "$SENDER") - local ETHEREUM=$(cast call "$CONTRACT_ETHEREUM" "balanceOf(address)(uint256)" "$SENDER") - local BNB=$(cast call "$CONTRACT_BNB" "balanceOf(address)(uint256)" "$SENDER") - echo "šŸŸ¢ ZetaChain: $ZETACHAIN" - echo "šŸ”µ EVM Chain: $ETHEREUM" - echo "šŸŸ” BNB Chain: $BNB" - echo "---------------------------------------------" -} - -echo -e "\nšŸš€ Compiling contracts..." -npx hardhat compile --force --quiet - -ZRC20_ETHEREUM=$(jq -r '.addresses[] | select(.type=="ZRC-20 ETH on 5") | .address' localnet.json) -ZRC20_BNB=$(jq -r '.addresses[] | select(.type=="ZRC-20 BNB on 97") | .address' localnet.json) -GATEWAY_ETHEREUM=$(jq -r '.addresses[] | select(.type=="gatewayEVM" and .chain=="ethereum") | .address' localnet.json) -GATEWAY_BNB=$(jq -r '.addresses[] | select(.type=="gatewayEVM" and .chain=="bnb") | .address' localnet.json) -SENDER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 - - -CONTRACT_ZETACHAIN=$(npx hardhat deploy --network localhost --gas-limit 700000 --json | jq -r '.contractAddress') -echo -e "\nšŸš€ Deployed contract on ZetaChain: $CONTRACT_ZETACHAIN" - -CONTRACT_ETHEREUM=$(npx hardhat deploy --name Connected --json --network localhost --gateway "$GATEWAY_ETHEREUM" | jq -r '.contractAddress') -echo -e "šŸš€ Deployed contract on EVM chain: $CONTRACT_ETHEREUM" - -CONTRACT_BNB=$(npx hardhat deploy --name Connected --json --network localhost --gateway "$GATEWAY_BNB" | jq -r '.contractAddress') -echo -e "šŸš€ Deployed contract on BNB chain: $CONTRACT_BNB" - -echo -e "\nšŸ“® User Address: $SENDER" - -echo -e "\nšŸ”— Setting counterparty contracts..." -npx hardhat connected-set-counterparty --network localhost --contract "$CONTRACT_ETHEREUM" --counterparty "$CONTRACT_ZETACHAIN" --json &>/dev/null -npx hardhat connected-set-counterparty --network localhost --contract "$CONTRACT_BNB" --counterparty "$CONTRACT_ZETACHAIN" --json &>/dev/null -npx hardhat universal-set-counterparty --network localhost --contract "$CONTRACT_ZETACHAIN" --counterparty "$CONTRACT_ETHEREUM" --zrc20 "$ZRC20_ETHEREUM" --json &>/dev/null -npx hardhat universal-set-counterparty --network localhost --contract "$CONTRACT_ZETACHAIN" --counterparty "$CONTRACT_BNB" --zrc20 "$ZRC20_BNB" --json &>/dev/null - -npx hardhat localnet-check -balance - -TOKEN=$(npx hardhat mint --network localhost --json --contract "$CONTRACT_ZETACHAIN" --to "$SENDER" --amount 10 | jq -r '.contractAddress') -echo -e "\nMinted tokens: $TOKEN on ZetaChain." - -npx hardhat localnet-check -balance - -echo -e "\nTransferring token: ZetaChain ā†’ Ethereum..." -npx hardhat transfer --network localhost --json --amount 10 --from "$CONTRACT_ZETACHAIN" --to "$ZRC20_ETHEREUM" - -npx hardhat localnet-check -balance - -echo -e "\nTransferring token: Ethereum ā†’ BNB..." -npx hardhat transfer --network localhost --json --amount 10 --from "$CONTRACT_ETHEREUM" --to "$ZRC20_BNB" --gas-amount 1 - -npx hardhat localnet-check -balance - -echo -e "\nTransferring token: BNB ā†’ ZetaChain..." -npx hardhat transfer --network localhost --json --amount 10 --from "$CONTRACT_BNB" - -npx hardhat localnet-check -balance - -npx hardhat localnet-stop \ No newline at end of file