-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathdelegate.sh
executable file
·66 lines (59 loc) · 2.1 KB
/
delegate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
source $1
if [[ -z "$TX_PASSWD_CONFIRMATIONS" ]]; then
TX_PASSWD_CONFIRMATIONS=1
fi
if [[ -z "$TX_PASSWD_PRHASE" ]]; then
TX_PASSWD_PRHASE="Enter keyring passphrase:"
fi
if [[ -z "$AMOUNT_TO_KEEP_AVAILABLE" ]]; then
AMOUNT_TO_KEEP_AVAILABLE=100000
fi
getDelegateBalanceFromAccount() {
coins=$(${BINARY} query account ${DELEGATOR} -o json ${SDETAILS} | jq '.value.coins | to_entries')
position=$(echo ${coins} | jq -r ".[] | select(.value.denom == \"${DENOM}\") | .key")
amount=$(echo ${coins} | jq -r ".[${position}].value.amount")
echo -n ${amount}
}
getDelegateBalanceFromBank() {
coins=$(${BINARY} query bank balances ${DELEGATOR} -o json ${SDETAILS} | jq '.balances | to_entries')
position=$(echo ${coins} | jq -r ".[] | select(.value.denom == \"${DENOM}\") | .key")
amount=$(echo ${coins} | jq -r ".[${position}].value.amount")
echo -n ${amount}
}
getDelegateBalance() {
amount=0
if [[ "$BALANCES_FROM" == "BANK" ]]; then
amount=$(getDelegateBalanceFromBank)
elif [[ "$BALANCES_FROM" == "ACCOUNT" ]]; then
amount=$(getDelegateBalanceFromAccount)
fi
echo -n ${amount}
}
getFinalDelegateBalance () {
amountFinal=$(bc <<< "${1} - ${AMOUNT_TO_KEEP_AVAILABLE}")
echo -n ${amountFinal}
}
withdrawRewardsAction() {
echo "------ REWARDS ------"
${BINARY} tx distribution withdraw-rewards ${VALIDATOR} --from ${DELEGATOR_NAME} --commission ${GAS_PRICES} ${DETAILS} -y
}
delegateAction() {
balance=$(getDelegateBalance)
amountFinal=$(getFinalDelegateBalance ${balance})
echo "------ DELEGATE ------"
echo "Balance: ${balance}"
echo "Amount to delegate: ${amountFinal}"
if [[ ${amountFinal} > 0 ]]; then
${BINARY} tx staking delegate ${VALIDATOR} ${amountFinal}${DENOM} --from ${DELEGATOR_NAME} ${GAS_PRICES} ${DETAILS} -y
elif [[ "$KEYRING_BACKEND" != "test" && "$KEYRING_BACKEND" != "memory" ]]; then
for (( i=1; i<=$TX_PASSWD_CONFIRMATIONS; i++ ))
do
echo -n "${TX_PASSWD_PRHASE}"
read answer
done
fi
}
withdrawRewardsAction
sleep 15
delegateAction