Skip to content

Instantly share code, notes, and snippets.

@larry0x
Created February 13, 2023 01:16
Show Gist options
  • Save larry0x/4f449179623bdd59f5ee927c2dfa7792 to your computer and use it in GitHub Desktop.
Save larry0x/4f449179623bdd59f5ee927c2dfa7792 to your computer and use it in GitHub Desktop.
#!/bin/zsh
set -e
# change this to your address!
delegator="mars1..."
append-msg() {
tx=$1
msgs=$(echo $tx | jq ".body.messages")
if [ -f "./tx.json" ]; then
jq ".body.messages += $msgs" tx.json | sponge tx.json
else
echo "$tx" > tx.json
fi
}
if [ -f "./tx.json" ]; then
rm ./tx.json
fi
printf "πŸ”‘ Enter marsd keyring password: "
read -s password
echo ""
echo "πŸ€– Querying restakeable rewards..."
rewards=$(marsd q distribution rewards $delegator --output json | jq '.rewards')
echo "πŸ€– Composing tx..."
for row in $(echo $rewards | jq -c '.[]'); do
validatorAddress=$(echo $row | jq -r '.validator_address')
amountDec=$(echo $row | jq -r '.reward[0].amount')
if (( $amountDec > 0 )); then
amount=${amountDec%.*}
append-msg $(marsd tx staking delegate $validatorAddress ${amount}umars --from $delegator --generate-only)
echo "validator $validatorAddress: $amount umars"
fi
done
jq '.auth_info.fee.gas_limit = "2000000"' tx.json | sponge tx.json
jq '.auth_info.fee.amount = []' tx.json | sponge tx.json
echo "πŸ€– Signing tx..."
echo $password | marsd tx sign tx.json --from $delegator --output-document tx.json -y
echo "πŸ€– Broadcasting tx..."
marsd tx broadcast tx.json
echo "βœ… Tx successfully broadcasted!"
rm tx.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment