Last active
March 15, 2022 10:51
-
-
Save anilcse/5461e95c64745f33015eeea0df6faa0f to your computer and use it in GitHub Desktop.
Cosmos SDK : Auto delegate rewards using authz + feegrant
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make public