Last active
May 26, 2023 09:44
-
-
Save Nuttymoon/89525d14ffc1fc53894bae86f399a6d9 to your computer and use it in GitHub Desktop.
Gather Avalanche Subnets stats using Ash CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export AVALANCHE_NETWORK="${AVALANCHE_NETWORK:-mainnet-ankr}" | |
echo "Avalanche Network: $AVALANCHE_NETWORK" | |
# Get the list of Subnets with at least one blockchain (exclude the Primary Network) | |
SUBNETS_W_CHAINS=$( | |
ash avalanche subnet list --json | | |
jq -r '.[] | | |
select(.id != "11111111111111111111111111111111LpoYY") | | |
select((.blockchains | length) > 0) | .id' | |
) | |
echo "Subnets with blockchains: $(echo "$SUBNETS_W_CHAINS" | wc -l)" | |
# Get the list of Subnets with at least one validator | |
SUBNETS_W_VALIDATORS=$(while read -r s; do | |
ash avalanche subnet info "$s" --json | | |
jq "{\"id\": \"$s\", \"validators_count\": (.validators | length), \"type\": .subnetType}" | |
done <<<"$SUBNETS_W_CHAINS" | jq -sc '.[] | select(.validators_count > 0)') | |
# Get the number of permissioned Subnets | |
PERMISSIONED_SUBNETS=$(echo "$SUBNETS_W_VALIDATORS" | jq -s '.[] | select(.type == "Permissioned")' | jq -s 'length') | |
echo "Subnets with validators: $(echo "$SUBNETS_W_VALIDATORS" | wc -l)" | |
echo "Permissioned / elastic: $PERMISSIONED_SUBNETS / $(($(echo "$SUBNETS_W_VALIDATORS" | wc -l) - $PERMISSIONED_SUBNETS))" | |
echo "Total Subnet validators: $(echo "$SUBNETS_W_VALIDATORS" | jq -s '. | map(.validators_count) | add')" | |
echo "Avg number of validators: $(echo "$SUBNETS_W_VALIDATORS" | jq -s '. | map(.validators_count) | (add / length)')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements
Picking the network
You can export
AVALANCHE_NETWORK
to choose another network (e.g.fuji
). It has to be in your Ash config (see Custom configuration).export AVALANCHE_NETWORK=fuji
Sample output