-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathakash_reinvest.bat
92 lines (78 loc) · 3.18 KB
/
akash_reinvest.bat
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
@echo off
SETLOCAL
:: #### processing variables that can be changed
set akash_validator=akashvaloper...
set key_address=akash...
set key_name=my_demo
set /A reserve_amt=5000000
set /A threshold_amt=2000000
:: #### do not change any of the below settings unless directed ####
set /A akash_precision=1000000
set akash_chain_id=akashnet-2
set rpc_node=http://135.181.60.250:26657
set /A delay_secs=15
::###-- Start Processing Here -- ###
::# log some initial entries about the execution
CALL :log_data " ---------------------------------------------------- "
CALL :log_data " The Akash Reinvest application has started "
::# Check and withdraw any commissions & rewards
CALL :log_data " - Withdraw Rewards and Commissions Balances "
CALL :withdraw_rewards withdraw_hash
CALL :log_data " -- Transaction Hash is - " %withdraw_hash%
::# Check Wallet Balance for Amounts sufficient to Delegate
CALL :log_data " - Checking Wallet Balance "
CALL :wallet_balance akash_value
::# calculate values
set /A akash_decimals=%akash_value% %% %akash_precision%
set /A akash_net=((( %akash_value% / %akash_precision% )* %akash_precision% ) - %reserve_amt%)
::# echo the value to the console
CALL :log_data " -- Reserve Amount - " %reserve_amt%
CALL :log_data " -- Wallet Balance - " %akash_value%
CALL :log_data " -------- decimals -- " %akash_decimals%
CALL :log_data " ----- Net Balance - " %akash_net%
::# Delegate Net Balance to Validator
::# only delegate if amount >= than threshold_amt
if %akash_net% LSS %threshold_amt% GOTO :NOBAL
CALL :log_data " - Delegate Net Wallet Balance to Validator "
set akash_amt=%akash_net%uakt
CALL :delegate_net delegation_hash
CALL :log_data " --- Delegation Hash is - " %delegation_hash%
CALL :log_data " --- Amount Delegated - " %akash_amt%
GOTO :END
:NOBAL
CALL :log_data " - Insufficient Wallet Balance to Delegate "
:END
CALL :log_data " The Delegation Reinvestment Process has Completed! "
CALL :log_data " ---------------------------------------------------- "
EXIT /B 0
:log_data
::{
set log_date=%DATE%-%TIME%
echo %log_date% %~1 %~2
EXIT /B 0
::}
:withdraw_rewards
::{
::# withdraw the given amount
for /f %%i in ('akash.exe tx distribution withdraw-rewards %akash_validator% --fees 5000uakt --from %key_name% --keyring-backend test --keyring-dir .\keys --node %rpc_node% --chain-id %akash_chain_id% --yes ^| jq-win64 -r ".txhash"') do set withdraw_hash=%%i
timeout %delay_secs% > NUL
set "%~1 = %withdraw_hash%"
EXIT /B 0
::}
:wallet_balance
::{
::# get the akash value we have in the wallet
for /f %%i in ('akash.exe query bank balances %key_address% --node %rpc_node% -o json ^| jq-win64 -r ".balances[0].amount"') do set akash_value=%%i
timeout %delay_secs%-10 > NUL
set "%~1 = %akash_value%"
EXIT /B 0
::}
:delegate_net
::{
::# delegate the given amount
for /f %%i in ('akash.exe tx staking delegate %akash_validator% %akash_amt% --from %key_name% --fees 5000uakt --chain-id %akash_chain_id% --keyring-dir .\keys --keyring-backend test --node %rpc_node% --yes ^| jq-win64 -r ".txhash"') do set delegation_hash=%%i
timeout %delay_secs% > NUL
set "%~1 = %delegation_hash%"
EXIT /B 0
::}
ENDLOCAL