Skip to content

Instantly share code, notes, and snippets.

@Reecepbcups
Last active June 25, 2024 13:46
Show Gist options
  • Save Reecepbcups/05750b3c7b9dbae54ccd6da44471a4e7 to your computer and use it in GitHub Desktop.
Save Reecepbcups/05750b3c7b9dbae54ccd6da44471a4e7 to your computer and use it in GitHub Desktop.
Script to query a Cosmos chains values and return the staking APY
#!/bin/bash
LCD_URL="https://juno-api.polkachu.com"
DENOM="ujuno"
# {"pool":{"not_bonded_tokens":"2431244061010","bonded_tokens":"58093075821304"}}
BONDED=$(curl -s $LCD_URL/cosmos/staking/v1beta1/pool | jq -r '.pool.bonded_tokens') && echo $BONDED
# {"inflation":"0.100000000000000000"}
INFLATION=$(curl -s $LCD_URL/cosmos/mint/v1beta1/inflation | jq -r '.inflation') && echo $INFLATION
# {"params": {"community_tax": "0.100000000000000000"}}
CP_TAX=$(curl -s $LCD_URL/cosmos/distribution/v1beta1/params | jq -r '.params.community_tax') && echo $CP_TAX
# {"amount":{"denom":"ujuno","amount":"109245071619644"}}
SUPPLY=$(curl -s $LCD_URL/cosmos/bank/v1beta1/supply/by_denom?denom=$DENOM | jq -r '.amount.amount') && echo $SUPPLY
# Rate of tokens bonded vs supply
BONDED_RATE=$(echo "scale=3; ($BONDED / $SUPPLY)" | bc) && echo $BONDED_RATE
APY=$(echo "scale=2; (($INFLATION / $BONDED_RATE) * (1 - $CP_TAX)) * 100" | bc) && echo $APY
echo "Staking APY: $APY%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment