How to automatically withdraw rewards in Cosmos
There are two main types of rewards in Cosmos chains.
Block rewards are distributed proportionally to all validators relative to their voting power. This means that even though each validator gains chain tokens with each reward, all validators maintain equal weight over time.
For example, 10 validators have equal voting power and a commission rate of 1%. For this example, the reward for a block is 1000 TOKEN and each validator has 20% of self-bonded TOKEN. These tokens do not go directly to the proposer. Instead, the tokens are evenly spread among validators. So now each validator's pool has 100 TOKEN. These 100 TOKEN are distributed according to each participant's stake:
- Commission:
100*80%*1% = 0.8 TOKEN - Validator gets:
100\*20% + Commission = 20.8 TOKEN - All delegators get:
100\*80% - Commission = 79.2 TOKEN
Then, each delegator can claim their part of the 79.2 TOKEN in proportion to their stake in the validator's staking pool.
Fees are similarly distributed with the exception that the block proposer can get a bonus on the fees of the block they propose if the proposer includes more than the strict minimum of required precommits.
MANUAL WITHDRAWAL
# Get key name
$ {BINARY} keys list
# Get valoper address
$ {BINARY} keys show <YOUR_KEY_NAME> --bech val -a
# Withdraw rewards from a given validator address
$ {BINARY} tx distribution withdraw-rewards <YOUR_VALOPER_ADDRESS> \
--from <YOUR_KEY_NAME>
# Withdraw rewards from all validator addresses
$ {BINARY} tx distribution withdraw-all-rewards --from <YOUR_KEY_NAME>
# Withdraw rewards and commission for a given validator
$ {BINARY} tx distribution withdraw-rewards <YOUR_VALOPER_ADDRESS> \
--from <YOUR_KEY_NAME> --commissionAUTOMATICAL WITHDRAWAL
For this purpose we need a script created by one of the members of cosmos community. Don't forget to star this project.
$ tmux new -s delegate
Download the script and provide it execution permission.
$ cd $HOME $ wget https://raw.githubusercontent.com/Staketab/cosmos-tools/main/auto-withdraw-delegate/start.sh $ chmod +x start.sh
If you want to receive telegram notification every time the script runs do the following. Find @userinfobot and start it. Keep your user id, for me it's 316404976
Then we need to create a new bot that deliver notification to our user. Find @BotFather and start it.
Then follow the instructions from the screenshot below. Keep the bot token, for me it's
5182703632:AAGS5m5v6RJJdZ39FTeYeduBExohCcMS-rY
Then search for your bot in my case it's CosmosDelegatorHdmiimdhBot and start it otherwise it won't be able to deliver messages.
# YOUR_TIME_INTERVAL supports value in seconds(s), minutes(m), hours(h)
$ ./start.sh -b {BINARY} -k <KEY_NAME> -s <YOUR_TIME_INTERVAL> \
-t <TG_BOT_TOKEN> -c <TH_USER_ID># EXAMPLE OF THE COMPLETE COMMAND !!! USE YOUR DATA !!!
$ ./start.sh -b rizond -k wallet -s 24h \
-t 5182703632:AAGS5m5v6RJJdZ39FTeYeduBExohCcMS-rY -c 316404976
$ ./start.sh -b bcnad -k wallet -s 24h \
-t 5182703632:AAGS5m5v6RJJdZ39FTeYeduBExohCcMS-rY -c 316404976
You will need to enter KEY password and fee amount, make sure validator data is correct, then type yes.
Once the script completes you get telegram notification with all the details about the transaction.
Useful commands
# List all tmux sessions $ tmux ls # Connnect to the last tmux session $ tmux attach # Deattach from open tmux session Ctrl+b -> d # Enable scroll Ctrl+b -> [