Skip to content

Instantly share code, notes, and snippets.

@0xd18b

0xd18b/reinvest.md

Last active May 14, 2021
Embed
What would you like to do?
Reinvesting BLD Rewards

Compounding gains are a marvelous thing. Here is a simple script to claim and reinvest your BLD stake.

On your validator machine:

touch ~/reinvest.sh
chmod +x ~/reinvest.sh
vi ~/reinvest.sh

And add the following:

#!/bin/bash

set -e

VAL_ADDRESS=$1
DEL_ADDRESS=$2
CHAIN_ID=$3

ag-cosmos-helper tx distribution withdraw-rewards ${VAL_ADDRESS} --commission --chain-id=${CHAIN_ID} --gas=auto --keyring-backend=test -y
BLD=$(ag-cosmos-helper query bank balances ${DEL_ADDRESS} --denom ubld -o json | jq .amount)
BLD="${BLD%\"}"
BLD="${BLD#\"}"
echo "reinvesting ${BLD}ubld on $(date)"
ag-cosmos-helper tx staking delegate ${VAL_ADDRESS} ${BLD}ubld --chain-id=${CHAIN_ID} --gas=auto --keyring-backend=test -y

Then:

./reinvest.sh agoricvaloper1zdfv0v74pjnupn05htn9lsrtqgd7mepw80atm0 agoric1zdfv0v74pjnupn05htn9lsrtqgd7mepwhhwz8w agorictest-12

There is a tradeoff between running this so often that you spend too much gas, and as often as possible to shrink your compounding window. That calculation includes the price of RUN with respect to BLD, the validator reward rate, and the validator's commission rate. In the agorictest-12 network gas was free, so no downside! :D

Once you've found that balance, use crontab to run the above script on some interval:

crontab -e

Add a new entry:

* * * * 0 ./reinvest.sh agoricvaloper1zdfv0v74pjnupn05htn9lsrtqgd7mepw80atm0 agoric1zdfv0v74pjnupn05htn9lsrtqgd7mepwhhwz8w agorictest-12 > ~/reinvest.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment