Skip to content

Instantly share code, notes, and snippets.

@talalashraf
Last active November 15, 2024 16:50
Show Gist options
  • Save talalashraf/936036e5b1779def14f1d5203b141536 to your computer and use it in GitHub Desktop.
Save talalashraf/936036e5b1779def14f1d5203b141536 to your computer and use it in GitHub Desktop.
Helper scripts - Amplifier Deployments
#!/bin/bash
set -e
# Base URL
BASE_URL="https://static.axelar.network/releases/amplifier"
# Directory to save files
SAVE_DIR="cosmwasm-artifacts"
# Create directory if it doesn't exist
mkdir -p "$SAVE_DIR"
# Function to verify checksum
verify_checksum() {
local file=$1
local checksum_file=$2
local contract_name=$3
local expected_checksum=$(grep "${contract_name}.wasm" "$checksum_file" | head -n 1 | cut -d' ' -f1)
local computed_checksum=$(sha256sum "$file" | cut -d' ' -f1)
if [ "$computed_checksum" = "$expected_checksum" ]; then
echo "Checksum verification passed for ${file##*/}"
else
echo "Checksum verification failed for ${file##*/}"
fi
}
# Function to verify GPG signature
verify_signature() {
local file=$1
local sig_file=$2
echo "Verifying GPG signature for ${file##*/}"
echo "Signature file: ${sig_file}"
if gpg --verify "$sig_file" "$file" 2>/dev/null; then
echo "GPG signature verification passed for ${file##*/}"
else
echo "GPG signature verification failed for ${file##*/}"
echo "Run 'gpg --verify ${sig_file} ${file}' to verify the signature"
fi
}
# List of contracts and their versions
contracts="coordinator:1.0.0 gateway:1.0.0 multisig:1.0.0 multisig-prover:1.0.0 nexus-gateway:1.0.0 rewards:1.0.0 router:1.0.0 service-registry:1.0.0 voting-verifier:1.0.0"
# Download and verify each contract
for contract_info in $contracts; do
contract=$(echo $contract_info | cut -d':' -f1)
version=$(echo $contract_info | cut -d':' -f2)
echo "Processing $contract version $version"
# Construct URLs
WASM_URL="${BASE_URL}/${contract}/${version}/release-artifacts/${contract}.wasm"
SIG_URL="${WASM_URL}.asc"
CHECKSUM_URL="${BASE_URL}/${contract}/${version}/release-artifacts/checksums.txt"
# File paths
WASM_FILE="${SAVE_DIR}/${contract}.wasm"
SIG_FILE="${SAVE_DIR}/${contract}.wasm.asc"
CHECKSUM_FILE="${SAVE_DIR}/${contract}_checksums.txt"
# Download files
curl -s -o "$WASM_FILE" "$WASM_URL"
curl -s -o "$SIG_FILE" "$SIG_URL"
curl -s -o "$CHECKSUM_FILE" "$CHECKSUM_URL"
# Verify checksum
verify_checksum "$WASM_FILE" "$CHECKSUM_FILE" "$contract"
# Verify GPG signature
verify_signature "$WASM_FILE" "$SIG_FILE"
echo
done
echo "All contracts processed."
#!/bin/bash
set -ex
mkdir -p cosmwasm-artifacts
# Parse input argument
# First argument is the commit hash 7 characters long
COMMIT_HASH=$1
if [ -z "$COMMIT_HASH" ]; then
echo "Usage: $0 <commit_hash>"
exit 1
fi
echo "Downloading artifacts for commit hash $COMMIT_HASH"
contracts=(
"service_registry"
"router"
"nexus_gateway"
"rewards"
"coordinator"
"multisig"
"voting_verifier"
"gateway"
"multisig_prover"
)
for contract in "${contracts[@]}"; do
echo "Downloading $contract"
wget -O "cosmwasm-artifacts/$contract.wasm" "https://static.axelar.network/pre-releases/ampd/contracts/$COMMIT_HASH/$contract.wasm"
done
#!/bin/bash
# Function to check verifier status
check_verifier_status() {
local verifier=$1
local result=$(kubectl exec genesis-0 -n "${NAMESPACE}" -- axelard q wasm contract-state smart axelar1kmeeu05ajmzlxgnc4qsgqr6d2hr94q2pyu6cak8dp000waehu0csl6ctzq '{"verifier":{"service_name":"verifiers", "verifier":"'$verifier'"}}' --output json)
local auth_state=$(echo "$result" | jq -r '.data.authorization_state')
local bond_state=$(echo "$result" | jq -r '.data.bonding_state | keys[0]')
local bond_amount=$(echo "$result" | jq -r '.data.bonding_state.Bonded.amount // "0"')
echo "Verifier: $verifier"
echo " Authorized: $([ "$auth_state" == "Authorized" ] && echo "Yes" || echo "No")"
echo " Bonded: $([ "$bond_state" == "Bonded" ] && echo "Yes" || echo "No")"
if [ "$bond_state" == "Bonded" ]; then
echo " Bonded Amount: $bond_amount"
fi
echo "------------------------------"
}
# Function to check and set namespace
check_namespace() {
if [ -z "$1" ] || [ "$1" != "--namespace" ] || [ -z "$2" ]; then
echo "Namespace must be specified with --namespace <namespace>"
exit 1
fi
NAMESPACE="$2"
}
# Parse command line arguments
if [ "$1" == "--devnet-auto" ]; then
if [ "$#" -ne 3 ]; then
echo "Usage: $0 --devnet-auto --namespace <namespace>"
exit 1
fi
check_namespace "$2" "$3"
echo "Running in devnet-auto mode for namespace: $NAMESPACE"
# Get all pods with 'amplifier' in their name
PODS=$(kubectl get pods -n "$NAMESPACE" | grep amplifier | awk '{print $1}')
# Retrieve verifier addresses from each pod and check status
for POD in $PODS; do
ADDR=$(kubectl exec "$POD" -n "$NAMESPACE" -c ampd-verifier-address -- cat verifier-address)
check_verifier_status "$ADDR"
done
elif [ "$1" == "--manual" ]; then
if [ "$#" -ne 4 ]; then
echo "Usage: $0 --manual <verifier-address> --namespace <namespace>"
exit 1
fi
VERIFIER_ADDR="$2"
check_namespace "$3" "$4"
echo "Running in manual mode for namespace: $NAMESPACE"
check_verifier_status "$VERIFIER_ADDR"
else
echo "Invalid argument. Please use either --devnet-auto or --manual."
echo "For devnet-auto mode: $0 --devnet-auto --namespace <namespace>"
echo "For manual mode: $0 --manual <verifier-address> --namespace <namespace>"
exit 1
fi
#!/bin/bash
node cosmwasm/deploy-contract.js \
-c "NexusGateway" \
--instantiate2 \
--fetchCodeId \
-r <wasm-deployer-key>
node cosmwasm/deploy-contract.js \
-c "Router" \
--instantiate2 \
--fetchCodeId \
-r <wasm-deployer-key>
node cosmwasm/deploy-contract.js \
-c "ServiceRegistry" \
--instantiate2 \
--fetchCodeId \
-r <wasm-deployer-key>
node cosmwasm/deploy-contract.js \
-c "Rewards" \
--instantiate2 \
--fetchCodeId \
-r <wasm-deployer-key>
node cosmwasm/deploy-contract.js \
-c "Coordinator" \
--instantiate2 \
--fetchCodeId \
-r <wasm-deployer-key>
node cosmwasm/deploy-contract.js \
-c "Multisig" \
--instantiate2 \
--fetchCodeId \
-r <wasm-deployer-key>
#!/bin/bash
# Check if both arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <chain_name> <path_to_config_file>"
exit 1
fi
CHAIN=$1
CONFIG_FILE=$2
# Check if the config file exists
if [ ! -f "$CONFIG_FILE" ]; then
echo "Config file not found: $CONFIG_FILE"
exit 1
fi
# Change to the axelar-contract-deployments directory
cd ./axelar-contract-deployments
# Get contract addresses
ROUTER_ADDRESS=$(cat $CONFIG_FILE | jq -rM '.axelar.contracts.Router.address')
GATEWAY_ADDRESS=$(cat $CONFIG_FILE | jq -rM ".axelar.contracts.Gateway.\"$CHAIN\".address")
MULTISIG_ADDRESS=$(cat $CONFIG_FILE | jq -rM '.axelar.contracts.Multisig.address')
MULTISIG_PROVER_ADDRESS=$(cat $CONFIG_FILE | jq -rM ".axelar.contracts.MultisigProver.\"$CHAIN\".address")
COORDINATOR_ADDRESS=$(cat $CONFIG_FILE | jq -rM '.axelar.contracts.Coordinator.address')
# Print all addresses
echo "Contract Addresses:"
echo "Router Address: $ROUTER_ADDRESS"
echo "Gateway Address: $GATEWAY_ADDRESS"
echo "Multisig Address: $MULTISIG_ADDRESS"
echo "Multisig Prover Address: $MULTISIG_PROVER_ADDRESS"
echo "Coordinator Address: $COORDINATOR_ADDRESS"
echo
# Print the node submit-proposal commands with descriptions and verification steps
echo "Command 1: Register Gateway address at Router contract"
echo "This command registers the Gateway address for $CHAIN in the Router contract."
echo "node cosmwasm/submit-proposal.js \\"
echo " --proposalType execute \\"
echo " -c Router \\"
echo " -t \"Register Gateway for $CHAIN\" \\"
echo " -d \"Register Gateway address for $CHAIN at Router contract\" \\"
echo " --deposit 100000000 \\"
echo " --msg '{\"register_chain\":{\"chain\":\"$CHAIN\",\"gateway_address\":\"$GATEWAY_ADDRESS\",\"msg_id_format\":\"hex_tx_hash_and_event_index\"}}'"
echo
echo "Verification commands for Command 1:"
echo "axelard q wasm contract-state smart \\"
echo " $ROUTER_ADDRESS \\"
echo " '{\"chains\":{\"start_after\": null, \"limit\": null}}' \\"
echo " --output json | jq ."
echo
echo "axelard q wasm contract-state smart \\"
echo " $ROUTER_ADDRESS \\"
echo " '{\"chain_info\": \"$CHAIN\"}' \\"
echo " --output json | jq ."
echo
echo
echo "Command 2: Authorize Multisig Prover address at Multisig contract"
echo "This command authorizes the Multisig Prover address for $CHAIN in the Multisig contract."
echo "node cosmwasm/submit-proposal.js \\"
echo " --proposalType execute \\"
echo " -c Multisig \\"
echo " -t \"Authorize Multisig Prover for $CHAIN\" \\"
echo " -d \"Authorize Multisig Prover address for $CHAIN at Multisig contract\" \\"
echo " --deposit 100000000 \\"
echo " --msg '{\"authorize_callers\":{\"contracts\":{\"$MULTISIG_PROVER_ADDRESS\":\"$CHAIN\"}}}'"
echo
echo "Verification command for Command 3:"
echo "axelard q wasm contract-state smart \\"
echo " $MULTISIG_ADDRESS \\"
echo " '{\"is_caller_authorized\": {\"contract_address\": \"$MULTISIG_PROVER_ADDRESS\", \"chain_name\": \"$CHAIN\"}}' \\"
echo " --output json | jq ."
echo
echo "Command 3: Register Multisig Prover address at Coordinator contract"
echo "This command registers the Multisig Prover address for $CHAIN in the Coordinator contract."
echo "node cosmwasm/submit-proposal.js \\"
echo " --proposalType execute \\"
echo " -c Coordinator \\"
echo " -t \"Register Multisig Prover for $CHAIN\" \\"
echo " -d \"Register Multisig Prover address for $CHAIN at Coordinator contract\" \\"
echo " --deposit 100000000 \\"
echo " --msg '{\"register_prover_contract\":{\"chain_name\":\"$CHAIN\",\"new_prover_addr\":\"$MULTISIG_PROVER_ADDRESS\"}}'"
#!/bin/bash
# Commands to submit proposals for storing bytecodes
# Run individually. Ensure deposit and instantiate address are adjusted
node cosmwasm/submit-proposal.js --proposalType store \
-c Router \
-t "Deploy Router" \
-d "Deploy Router" \
--instantiateAddresses "<wasm-deployer-key>" \
--deposit 100000000
node cosmwasm/submit-proposal.js --proposalType store \
-c NexusGateway \
-t "Deploy Nexus Gateway" \
-d "Deploy Nexus Gateway" \
--instantiateAddresses "<wasm-deployer-key>" \
--deposit 100000000
node cosmwasm/submit-proposal.js --proposalType store \
-c ServiceRegistry \
-t "Deploy Service Registry" \
-d "Deploy Service Registry" \
--instantiateAddresses "<wasm-deployer-key>" \
--deposit 100000000
node cosmwasm/submit-proposal.js --proposalType store \
-c Rewards \
-t "Deploy Rewards" \
-d "Deploy Rewards" \
--instantiateAddresses "<wasm-deployer-key>" \
--deposit 100000000
node cosmwasm/submit-proposal.js --proposalType store \
-c Coordinator \
-t "Deploy Coordinator" \
-d "Deploy Coordinator" \
--instantiateAddresses "<wasm-deployer-key>" \
--deposit 100000000
node cosmwasm/submit-proposal.js --proposalType store \
-c Multisig \
-t "Deploy Multisig" \
-d "Deploy Multisig" \
--instantiateAddresses "<wasm-deployer-key>" \
--deposit 100000000
# Chain Specific Contracts
node cosmwasm/submit-proposal.js --proposalType store \
-c VotingVerifier \
-t "Deploy Voting Verifier" \
-d "Deploy Voting Verifier" \
--instantiateAddresses "<wasm-deployer-key>" \
--deposit 100000000
node cosmwasm/submit-proposal.js --proposalType store \
-c Gateway \
-t "Deploy Gateway" \
-d "Deploy Gateway" \
--instantiateAddresses "<wasm-deployer-key>" \
--deposit 100000000
node cosmwasm/submit-proposal.js --proposalType store \
-c MultisigProver \
-t "Deploy MultisigProver" \
-d "Deploy MultisigProver" \
--instantiateAddresses "<wasm-deployer-key>" \
--deposit 100000000
#!/bin/bash
# Check if required arguments are provided
if [ "$#" -ne 4 ]; then
echo "Usage: $0 <namespace> <asset_denom> <min_bond> <service_name>"
exit 1
fi
NAMESPACE="$1"
ASSET_DENOM="$2"
MIN_BOND="$3"
SERVICE_NAME="$4"
# Calculate the amount to send
AMOUNT=$((MIN_BOND * 1000000))
# Get all pods with 'amplifier' in their name
PODS=$(kubectl get pods -n "$NAMESPACE" | grep amplifier | awk '{print $1}')
# Arrays to store verifier addresses and balances
VERIFIER_ADDRS=()
VERIFIER_BALANCES=()
# Retrieve verifier addresses and balances from each pod
for POD in $PODS; do
ADDR=$(kubectl exec "$POD" -n "$NAMESPACE" -c ampd-verifier-address -- cat verifier-address)
BALANCE=$(kubectl exec genesis-0 -n "$NAMESPACE" -- axelard query bank balances "$ADDR" -o json | jq -r ".balances[] | select(.denom==\"$ASSET_DENOM\") | .amount")
# If balance is empty, set it to 0
BALANCE=${BALANCE:-0}
VERIFIER_ADDRS+=("$ADDR")
VERIFIER_BALANCES+=("$BALANCE")
done
# Print verifier addresses and balances
echo "Verifier Addresses and Balances:"
for i in "${!VERIFIER_ADDRS[@]}"; do
echo "Address: ${VERIFIER_ADDRS[$i]}, Balance: ${VERIFIER_BALANCES[$i]} $ASSET_DENOM"
done
# Print separator
printf '\n%s\n\n' "$(printf '=%.0s' {1..64})"
# Print kubectl commands
echo "fund-verifiers commands:"
for ADDR in "${VERIFIER_ADDRS[@]}"; do
echo "kubectl exec genesis-0 -n \"${NAMESPACE}\" -- axelard tx bank send amplifier \"$ADDR\" \"${AMOUNT}${ASSET_DENOM}\" --gas auto --gas-adjustment 1.3"
done
# Print separator
printf '\n%s\n\n' "$(printf '=%.0s' {1..64})"
# Print ampd bond commands
echo "ampd bond commands:"
for POD in $PODS; do
echo "kubectl exec -n \"${NAMESPACE}\" \"pod/$POD\" -c ampd-verifier-address -- ampd bond-verifier \"${SERVICE_NAME}\" ${MIN_BOND} \"${ASSET_DENOM}\""
done
# Print separator
printf '\n%s\n\n' "$(printf '=%.0s' {1..64})"
# Print register-public-key commands
echo "register-public-key commands:"
for POD in $PODS; do
echo "kubectl exec -n \"${NAMESPACE}\" \"$POD\" -c ampd-verifier-address -- ampd register-public-key ecdsa"
done
# Generate JSON output
JSON_OUTPUT=$(cat <<EOF
{
"authorize_verifiers": {
"verifiers": [
$(printf ' "%s",\n' "${VERIFIER_ADDRS[@]}" | sed '$s/,$//')
],
"service_name": "${SERVICE_NAME}"
}
}
EOF
)
# Print JSON to console
echo -e "\nJSON Output:"
echo "$JSON_OUTPUT"
# Save JSON to file
echo "$JSON_OUTPUT" > verifiers.json
echo "JSON saved to verifiers.json"
#!/bin/bash
# This script accepts proposal id as input and submits yes votes
# for all validators in the network
# set -e
# proposal id
if [ -z "$1" ]; then
echo "Usage: $0 <identifier> <proposal_id> <chain-id> <config-file>"
exit 1
fi
identifier="$1"
echo "Identifier: $identifier"
# identifier
if [ -z "$2" ]; then
echo "Usage: $0 <identifier> <proposal_id> <chain-id> <config-file>"
exit 1
fi
proposal_id="$2"
echo "Proposal id: $proposal_id"
# chain id
if [ -z "$3" ]; then
chain_id="$2"
echo "Chain id not provided, using namespace $chain_id as chain id"
else
chain_id="$3" # chain id
fi
echo "Chain id: $chain_id"
# config.json
if [ -z "$4" ]; then
config_file="axelar-chains-config/info/$4.json"
echo "Config file not provided, using $config_file"
else
config_file="axelar-chains-config/info/$4.json"
fi
echo "Config file: $config_file"
namespaces=$(kubectl get pods -A | grep "${identifier}-"validator | awk '{print $1}')
for ns in $namespaces; do
pod=$(kubectl get pods -n $ns | grep "axelar-core-node-validator" | awk '{print $1}')
echo "Submitting vote for proposal $proposal_id on pod $pod"
output=$(kubectl exec -n $ns -it $pod -c axelar-core-node -- /bin/sh -c "echo \"\$KEYRING_PASSWORD\" | axelard tx gov vote $proposal_id yes --from validator --chain-id $chain_id --gas auto --gas-adjustment 1.4")
echo "$output"
done
# retrieve rpc from json config file
rpc=$(cat $config_file | jq -r '.axelar.rpc')
echo "RPC: $rpc"
# wait for proposal to be approved
while true; do
if axelard q gov proposal "$proposal_id" --node $rpc | grep -q "status: PROPOSAL_STATUS_PASSED"; then
echo "Proposal passed"
break
fi
echo "Proposal not passed yet"
sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment