Skip to content

Instantly share code, notes, and snippets.

@anilcse
Last active March 15, 2022 10:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anilcse/5461e95c64745f33015eeea0df6faa0f to your computer and use it in GitHub Desktop.
Save anilcse/5461e95c64745f33015eeea0df6faa0f to your computer and use it in GitHub Desktop.
Cosmos SDK : Auto delegate rewards using authz + feegrant
# all the below params are required.
granter=
grantee=
fee_payer=
validator=cosmosvaloper1ddle9tczl87gsvmeva3c48nenyng4n56nghmjk
maintenance_balance=1000000 # minimum balance to maintain in the granter account
while true
do
echo "About to withdraw commission and reward"
gaiad tx distribution withdraw-rewards $validator --from $granter --chain-id cosmoshub-4 -y --generate-only > rewards.json
gaiad tx authz exec rewards.json --chain-id cosmoshub-4 --node https://rpc.cosmoshub.forbole.com:443 --fees 200uatom --fee-account $fee_payer --from $grantee -y
echo "Sleeping for 30s"
sleep 30s
amount=$(gaiad query bank balances $granter --chain-id=cosmoshub-4 --node https://rpc.cosmoshub.forbole.com:443 -o json | jq -r '.balances[0].amount')
echo "amount after withdraw rewards: $amount"
amount=$(($amount - $maintenance_balance))
if [[ $amount > 0 && $amount != "null" ]]; then
echo "About to stake ${amount} uATOM"
gaiad tx staking delegate $validator ${amount}uatom --chain-id=cosmoshub-4 --from $granter --gas-adjustment 1.1 -y --generate-only > stake.json
gaiad tx authz exec stake.json --chain-id cosmoshub-4 --node https://rpc.cosmoshub.forbole.com:443 --fees 200uatom --fee-account $fee_payer --from $grantee -y
fi
sleep 3600s
done
@anilcse
Copy link
Author

anilcse commented Mar 15, 2022

make public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment