-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathdelegate_manually.sh
executable file
·79 lines (69 loc) · 2.09 KB
/
delegate_manually.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
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
usage() {
echo "Usage: $0 -p [file]" 1>&2
exit 1
}
while getopts ":p:" option; do
case "${option}" in
p)
p=${OPTARG}
if [[ ! -f "$p" ]]; then
usage
fi
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [[ -z "${p}" ]]; then
usage
fi
PROFILE_PATH="${p}"
source ${PROFILE_PATH}
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
fi
}
withdrawRewardsAction
sleep 15
delegateAction