-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstate.sh
executable file
·93 lines (77 loc) · 4.93 KB
/
state.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
url=$RPC_URL
if [ $# -lt 2 ]; then
echo "Provide the delegation contract address, a staker address and optionally, a block number as arguments."
exit 1
fi
temp=$(forge script script/CheckVariant.s.sol --rpc-url $url --sig "run(address payable)" $1 | tail -n 1)
variant=$(sed -E 's/\s\s([a-zA-Z0-9]+)/\1/' <<< "$temp")
if [[ "$variant" == "$temp" ]]; then
echo Incompatible delegation contract at $1
exit 1
fi
if [ $# -eq 3 ]; then
block_num=$3
block=$(echo $block_num | cast to-hex --base-in 10)
else
block=$(cast rpc eth_blockNumber --rpc-url $url)
block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16)
fi
echo $(date +"%T,%3N") $block_num
owner=$(cast call $1 "owner()(address)" --block $block_num --rpc-url $url)
rewardsBeforeUnstaking=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
#rewardsBeforeUnstaking=$(cast rpc eth_getBalance $1 $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16)
echo rewardsBeforeUnstaking = $rewardsBeforeUnstaking
x=$(cast rpc eth_getBalance $owner $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16)
owner_zil=$(cast to-unit $x ether)
x=$(cast rpc eth_getBalance $2 $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16)
staker_zil=$(cast to-unit $x ether)
if [[ "$variant" == "ILiquidDelegation" ]]; then
taxedRewardsBeforeUnstaking=$(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
echo taxedRewardsBeforeUnstaking = $taxedRewardsBeforeUnstaking
lst=$(cast call $1 "getLST()(address)" --block $block_num --rpc-url $url)
symbol=$(cast call $lst "symbol()(string)" --block $block_num --rpc-url $url | tr -d '"')
x=$(cast call $lst "balanceOf(address)(uint256)" $owner --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
owner_lst=$(cast to-unit $x ether)
x=$(cast call $lst "balanceOf(address)(uint256)" $2 --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
staker_lst=$(cast to-unit $x ether)
echo owner: $owner_lst $symbol && echo owner: $owner_zil ZIL unstaked
echo staker: $staker_lst $symbol && echo staker: $staker_zil ZIL unstaked
else
x=$(cast call $1 "getDelegatedStake()(uint256)" --from $owner --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
owner_staked=$(cast to-unit $x ether)
x=$(cast call $1 "getDelegatedStake()(uint256)" --from $2 --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
staker_staked=$(cast to-unit $x ether)
echo owner: $owner_staked ZIL staked && echo owner: $owner_zil ZIL unstaked
echo staker: $staker_staked ZIL staked && echo staker: $staker_zil ZIL unstaked
fi
stake=$(cast call $1 "getStake()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
commissionNumerator=$(cast call $1 "getCommissionNumerator()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
denominator=$(cast call $1 "DENOMINATOR()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
if [[ "$variant" == "ILiquidDelegation" ]]; then
totalSupply=$(cast call $lst "totalSupply()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
if [[ $totalSupply -ne 0 ]]; then
price=$(bc -l <<< "scale=36; ($stake+$rewardsBeforeUnstaking-($rewardsBeforeUnstaking-$taxedRewardsBeforeUnstaking)*$commissionNumerator/$denominator)/$totalSupply")
else
price=$(bc -l <<< "scale=36; 1/1")
fi
price0=$(cast call $1 "getPrice()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
echo $symbol supply: $(cast to-unit $totalSupply ether)
echo $symbol price: $price \~ $(cast to-unit $price0 ether) ZIL
echo staker $symbol value: $(bc -l <<< "scale=18; $staker_lst*$price") ZIL
else
x=$(cast call $1 "rewards()(uint256)" --from $2 --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
staker_rewards=$(cast to-unit $x ether)
echo staker rewards: $staker_rewards ZIL
fi
claimable=$(cast call $1 "getClaimable()(uint256)" --from $2 --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
echo staker claimable: $(cast to-unit $claimable ether) ZIL
echo validator deposit: $(cast to-unit $stake ether) ZIL
validatorBalance=$(cast rpc eth_getBalance $1 $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16)
echo validator balance: $(cast to-unit $validatorBalance ether) ZIL
pendingWithdrawals=$(cast call $1 "getTotalWithdrawals()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
echo pending withdrawals: $(cast to-unit $pendingWithdrawals ether) ZIL
totalStake=$(cast call 0x00000000005A494C4445504F53495450524F5859 "getFutureTotalStake()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g')
echo total stake: $(cast to-unit $totalStake ether) ZIL
depositBalance=$(cast rpc eth_getBalance 0x00000000005A494C4445504F53495450524F5859 $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16)
echo deposit balance: $(cast to-unit $depositBalance ether) ZIL