-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutodelegate
158 lines (130 loc) · 4.52 KB
/
Autodelegate
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Cosmos-Autodelegate
install Tmux
sudo apt install tmux expect -y
Clone repository
git clone https://github.com/keupsonite/cosmos-autostaking.git $HOME/cosmos-autostaking && cd $HOME/cosmos-autostaking
allow delegation
chmod +x $HOME/cosmos-autostaking/*delegate*
_________________________
Edit
nano $HOME/cosmos-autostaking/profiles/.archway
# Archway Keyring Backend ("test", "file", "os" or "memory")
# Example: KEYRING_BACKEND="test"
# You can reimport your wallet with desired backend-type
# (`archwayd keys add name_wallet --recover`)
KEYRING_BACKEND="os"
# Password
# Required if keyring-backend is "file" or "os"
PASSWD=""
# Archway Wallet Name (`archwayd keys list`)
# Example: DELEGATOR_NAME="name_wallet"
DELEGATOR_NAME=""
# Archway Wallet Address (`archwayd keys show name_wallet -a`)
# Example: DELEGATOR="archway1le23uxah00r8aajzfhh30et5ek2kxvfpyqp5jd"
DELEGATOR=""
# Archway Validator Address
# Example: VALIDATOR="archwayvaloper1msnjlmuas6hxh5xml952snjayxlm4f2k3etu0v"
VALIDATOR=""
# Current Archway Chain ID
CHAIN_ID="torii-1"
#########################################################
# In case you customized the Archway Node configuration, #
# you will want to edit this below parameters. #
#########################################################
# The IP of your Archway Node
NODE_IP="127.0.0.1"
# The port of your Archway Node
NODE_PORT="26657"
# The home of your Archway Node
NODE_HOME="$HOME/.archway"
# The path to your Archway binary
# To get the full path to your archway binary you can use `whereis archwayd` and replace the below value by.
# Example: BINARY="$HOME/go/bin/archwayd"
BINARY=""
####################
# MODIFY FOR TESTS #
####################
# Time to sleep in sec between two delegations
# Example: SLEEPING_TIME=$((5*60))
# Example: SLEEPING_TIME="30"
SLEEPING_TIME=$((30*60))
DENOM="utorii"
GAS_PRICES="--fees 26${DENOM}"
##################
# DO NOT MODIFY! #
##################
# Depending on Cosmos SDK version
# - ACCOUNT $binary query account
# - BANK $binary query bank balances
BALANCES_FROM="BANK"
SDETAILS="--chain-id ${CHAIN_ID} --node tcp://${NODE_IP}:${NODE_PORT} --home ${NODE_HOME}"
DETAILS="${SDETAILS} --keyring-backend ${KEYRING_BACKEND}"
___________________________
Edit Delegate.sh
#!/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 ------"
haqqd tx distribution withdraw-all-rewards --from <wallet> --fees 500aISLM -y --gas=auto
}
delegateAction() {
balance=$(getDelegateBalance)
amountFinal=$(getFinalDelegateBalance ${balance})
echo "------ DELEGATE ------"
echo "Balance: ${balance}"
echo "Amount to delegate: ${amountFinal}"
if [[ ${amountFinal} > 0 ]]; then
haqqd tx staking delegate <valoper> 1ISLM --from <wallet> --fees 500aISLM -y --gas=auto
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
______________________________________
run
tmux new-session -s autoDelegate $HOME/cosmos-autostaking/auto_delegate.sh -p $HOME/cosmos-autostaking/profiles/.archway
CTRL+B D
logs
tail -f $HOME/cosmos-autostaking/auto_delegate.log
exit
tmux attach CTRL+C