From 79619d366cef7695a64648073d9795ed8736d56c Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 29 Oct 2024 10:44:02 +0100 Subject: [PATCH] add scripts --- v2/scripts/utils/compare_zrc20_info.sh | 62 ++++++++++++++++++++++++++ v2/scripts/utils/get_zrc20_info.sh | 44 ++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100755 v2/scripts/utils/compare_zrc20_info.sh create mode 100755 v2/scripts/utils/get_zrc20_info.sh diff --git a/v2/scripts/utils/compare_zrc20_info.sh b/v2/scripts/utils/compare_zrc20_info.sh new file mode 100755 index 00000000..d452d76e --- /dev/null +++ b/v2/scripts/utils/compare_zrc20_info.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# This script compares the attributes of two ZRC20 contracts on a blockchain. +# It takes two contract addresses and an RPC URL, fetches their values, and compares them. +# +# Usage: +# ./compare_zrc20_info.sh + + +# Check if cast is installed +if ! command -v cast &> /dev/null +then + echo "cast CLI could not be found. Please install it first." + exit 1 +fi + +# Check if the correct number of arguments is provided +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Get the contract addresses and RPC URL from the script arguments +CONTRACT_ADDRESS_1=$1 +CONTRACT_ADDRESS_2=$2 +RPC_URL=$3 + +# Function to fetch ZRC20 attributes +fetch_zrc20_info() { + local CONTRACT_ADDRESS=$1 + local RPC_URL=$2 + + SYSTEM_CONTRACT=$(cast call "$CONTRACT_ADDRESS" "SYSTEM_CONTRACT_ADDRESS()(address)" --rpc-url "$RPC_URL" | tr -d '\n') + ZRC20_NAME=$(cast call "$CONTRACT_ADDRESS" "name()(string)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/"//g') + ZRC20_SYMBOL=$(cast call "$CONTRACT_ADDRESS" "symbol()(string)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/"//g') + ZRC20_DECIMALS=$(cast call "$CONTRACT_ADDRESS" "decimals()(uint8)" --rpc-url "$RPC_URL" | tr -d '\n') + ZRC20_CHAIN_ID=$(cast call "$CONTRACT_ADDRESS" "CHAIN_ID()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n') + ZRC20_COIN_TYPE=$(cast call "$CONTRACT_ADDRESS" "COIN_TYPE()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n') + ZRC20_GAS_LIMIT=$(cast call "$CONTRACT_ADDRESS" "GAS_LIMIT()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/\[.*\]//g') + + echo "$SYSTEM_CONTRACT,$ZRC20_NAME,$ZRC20_SYMBOL,$ZRC20_DECIMALS,$ZRC20_CHAIN_ID,$ZRC20_COIN_TYPE,$ZRC20_GAS_LIMIT" +} + +# Fetch attributes for both contracts +INFO_1=$(fetch_zrc20_info $CONTRACT_ADDRESS_1 $RPC_URL) +INFO_2=$(fetch_zrc20_info $CONTRACT_ADDRESS_2 $RPC_URL) + +# Split the results into arrays +IFS=',' read -r -a VALUES_1 <<< "$INFO_1" +IFS=',' read -r -a VALUES_2 <<< "$INFO_2" + +# Attribute names for clarity +ATTRIBUTES=("SYSTEM_CONTRACT" "ZRC20_NAME" "ZRC20_SYMBOL" "ZRC20_DECIMALS" "ZRC20_CHAIN_ID" "ZRC20_COIN_TYPE" "ZRC20_GAS_LIMIT") + +# Compare values and output the result +for i in "${!ATTRIBUTES[@]}"; do + if [ "${VALUES_1[i]}" == "${VALUES_2[i]}" ]; then + echo -e "✓ ${ATTRIBUTES[i]} is the same: ${VALUES_1[i]}" + else + echo -e "✗ ${ATTRIBUTES[i]} is different: ${VALUES_1[i]} (Contract 1) vs ${VALUES_2[i]} (Contract 2)" + fi +done \ No newline at end of file diff --git a/v2/scripts/utils/get_zrc20_info.sh b/v2/scripts/utils/get_zrc20_info.sh new file mode 100755 index 00000000..095f0145 --- /dev/null +++ b/v2/scripts/utils/get_zrc20_info.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# This script retrieves various attributes of a ZRC20 contract on a blockchain. +# It takes the contract address and an RPC URL as inputs and calls several +# functions on the contract to obtain key information. These attributes +# are typically required when a clone of the contract is to be deployed. +# +# Usage: +# ./get_zrc20_info.sh + +# Check if cast is installed +if ! command -v cast &> /dev/null +then + echo "cast CLI could not be found. Please install it first." + exit 1 +fi + +# Check if the correct number of arguments is provided +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Get the contract address and RPC URL from the script arguments +CONTRACT_ADDRESS=$1 +RPC_URL=$2 + +# Run the cast commands and capture the outputs +SYSTEM_CONTRACT=$(cast call "$CONTRACT_ADDRESS" "SYSTEM_CONTRACT_ADDRESS()(address)" --rpc-url "$RPC_URL" | tr -d '\n') +ZRC20_NAME=$(cast call "$CONTRACT_ADDRESS" "name()(string)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/"//g') +ZRC20_SYMBOL=$(cast call "$CONTRACT_ADDRESS" "symbol()(string)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/"//g') +ZRC20_DECIMALS=$(cast call "$CONTRACT_ADDRESS" "decimals()(uint8)" --rpc-url "$RPC_URL" | tr -d '\n') +ZRC20_CHAIN_ID=$(cast call "$CONTRACT_ADDRESS" "CHAIN_ID()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/\[.*\]//g') +ZRC20_COIN_TYPE=$(cast call "$CONTRACT_ADDRESS" "COIN_TYPE()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n') +ZRC20_GAS_LIMIT=$(cast call "$CONTRACT_ADDRESS" "GAS_LIMIT()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/\[.*\]//g') + +# Output the final result string +echo "SYSTEM_CONTRACT=$SYSTEM_CONTRACT" +echo "ZRC20_NAME=$ZRC20_NAME" +echo "ZRC20_SYMBOL=$ZRC20_SYMBOL" +echo "ZRC20_DECIMALS=$ZRC20_DECIMALS" +echo "ZRC20_CHAIN_ID=$ZRC20_CHAIN_ID" +echo "ZRC20_COIN_TYPE=$ZRC20_COIN_TYPE" +echo "ZRC20_GAS_LIMIT=$ZRC20_GAS_LIMIT" \ No newline at end of file