From 087f58dd8d5e90253cb96351ccb91f803ed698a0 Mon Sep 17 00:00:00 2001 From: DrZoltanFazekas Date: Mon, 21 Oct 2024 19:37:51 +0200 Subject: [PATCH] Fix price calculation and commission formatting --- claim.sh | 45 +++++++++++++------ script/commission_Delegation.s.sol | 15 +++---- src/Console.sol | 26 +++++++++++ stake.sh | 47 ++++++++++++++------ state.sh | 64 +++++++++++++++------------ test/Delegation.t.sol | 25 ++--------- unstake.sh | 69 +++++++++++++++++++++--------- 7 files changed, 188 insertions(+), 103 deletions(-) create mode 100644 src/Console.sol diff --git a/claim.sh b/claim.sh index d0f9021..d1306ba 100755 --- a/claim.sh +++ b/claim.sh @@ -5,18 +5,37 @@ if [ $# -ne 2 ]; then exit 1 fi -staker=$(cast wallet address $2) && \ -forge script script/claim_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable)" $1 --private-key $2 -vvvv && \ -block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) && \ -block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16) && \ -echo rewardsAfterClaiming = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -echo taxedRewardsAfterClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -staker_wei_after=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) && \ -echo $(date +"%T,%3N") $block_num && \ -block_num=$((block_num-1)) && \ -block=$(echo $block_num | cast to-hex --base-in 10) && \ -echo rewardsBeforeClaiming = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -echo taxedRewardsBeforeClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -staker_wei_before=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) && \ +staker=$(cast wallet address $2) + +forge script script/claim_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable)" $1 --private-key $2 -vvvv + +block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) +block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16) + +echo rewardsAfterClaiming = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +echo taxedRewardsAfterClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + +staker_wei_after=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) + +tmp=$(cast logs --from-block $block_num --to-block $block_num --address $1 "Claimed(address,uint256)" --rpc-url http://localhost:4201 | grep "data") +if [[ "$tmp" != "" ]]; then + tmp=${tmp#*: } + tmp=$(cast abi-decode --input "x(uint256)" $tmp | sed 's/\[[^]]*\]//g') + tmp=(${tmp}) + d1=${tmp[0]} + #d1=$(echo $tmp | sed -n -e 1p | sed 's/\[[^]]*\]//g') +fi + +echo $(date +"%T,%3N") $block_num + +block_num=$((block_num-1)) +block=$(echo $block_num | cast to-hex --base-in 10) + +echo rewardsBeforeClaiming = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +echo taxedRewardsBeforeClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + +staker_wei_before=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) + echo claimed amount - gas fee = $(bc -l <<< $staker_wei_after-$staker_wei_before) wei +if [[ "$tmp" != "" ]]; then echo event Claimed\($staker, $d1\) emitted; fi echo $(date +"%T,%3N") $block_num diff --git a/script/commission_Delegation.s.sol b/script/commission_Delegation.s.sol index fad63f1..0d14727 100644 --- a/script/commission_Delegation.s.sol +++ b/script/commission_Delegation.s.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.26; import {Script} from "forge-std/Script.sol"; import {NonRebasingLST} from "src/NonRebasingLST.sol"; import {DelegationV2} from "src/DelegationV2.sol"; +import {Console} from "src/Console.sol"; import "forge-std/console.sol"; contract Stake is Script { @@ -24,20 +25,18 @@ contract Stake is Script { address(lst) ); - console.log("Old commission rate: %s.%s%%", - uint256(delegation.getCommissionNumerator()) * 100 / uint256(delegation.DENOMINATOR()), - //TODO: check if the decimals are printed correctly e.g. 12.01% vs 12.1% - uint256(delegation.getCommissionNumerator()) % (uint256(delegation.DENOMINATOR()) / 100) + Console.log("Old commission rate: %s.%s%s%%", + delegation.getCommissionNumerator(), + 2 ); vm.broadcast(deployerPrivateKey); delegation.setCommissionNumerator(commissionNumerator); - console.log("New commission rate: %s.%s%%", - uint256(delegation.getCommissionNumerator()) * 100 / uint256(delegation.DENOMINATOR()), - //TODO: check if the decimals are printed correctly e.g. 12.01% vs 12.1% - uint256(delegation.getCommissionNumerator()) % (uint256(delegation.DENOMINATOR()) / 100) + Console.log("New commission rate: %s.%s%s%%", + delegation.getCommissionNumerator(), + 2 ); } } \ No newline at end of file diff --git a/src/Console.sol b/src/Console.sol new file mode 100644 index 0000000..ab394a0 --- /dev/null +++ b/src/Console.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity ^0.8.26; + +import "forge-std/console.sol"; + +library Console { + function log(string memory format, uint256 amount, uint8 precision) pure internal { + string memory zeros = ""; + uint256 decimals = amount % 10**precision; + while (decimals > 0 && decimals < 10**(precision - 1)) { + //console.log("%s %s", zeros, decimals); + zeros = string.concat(zeros, "0"); + decimals *= 10; + } + console.log( + format, + amount / 10**precision, + zeros, + amount % 10**precision + ); + } + + function log(string memory format, uint256 amount) pure internal { + return log(format, amount, 18); + } +} \ No newline at end of file diff --git a/stake.sh b/stake.sh index 1b0139f..678498b 100755 --- a/stake.sh +++ b/stake.sh @@ -5,18 +5,39 @@ if [ $# -ne 3 ]; then exit 1 fi -staker=$(cast wallet address $2) && \ -forge script script/stake_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable, uint256)" $1 $3 --private-key $2 && \ -block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) && \ -block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16) && \ -echo rewardsAfterStaking = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -echo taxedRewardsAfterStaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -staker_wei_after=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) && \ -echo $(date +"%T,%3N") $block_num && \ -block_num=$((block_num-1)) && \ -block=$(echo $block_num | cast to-hex --base-in 10) && \ -echo rewardsBeforeStaking = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -echo taxedRewardsBeforeStaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -staker_wei_before=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) && \ +staker=$(cast wallet address $2) + +forge script script/stake_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable, uint256)" $1 $3 --private-key $2 + +block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) +block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16) + +echo rewardsAfterStaking = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +echo taxedRewardsAfterStaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + +staker_wei_after=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) + +tmp=$(cast logs --from-block $block_num --to-block $block_num --address $1 "Staked(address,uint256,uint256)" --rpc-url http://localhost:4201 | grep "data") +if [[ "$tmp" != "" ]]; then + tmp=${tmp#*: } + tmp=$(cast abi-decode --input "x(uint256,uint256)" $tmp | sed 's/\[[^]]*\]//g') + tmp=(${tmp}) + d1=${tmp[0]} + d2=${tmp[1]} + #d1=$(echo $tmp | sed -n -e 1p | sed 's/\[[^]]*\]//g') + #d2=$(echo $tmp | sed -n -e 2p | sed 's/\[[^]]*\]//g') +fi + +echo $(date +"%T,%3N") $block_num + +block_num=$((block_num-1)) +block=$(echo $block_num | cast to-hex --base-in 10) + +echo rewardsBeforeStaking = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +echo taxedRewardsBeforeStaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + +staker_wei_before=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) + echo staked amount + gas fee = $(bc -l <<< $staker_wei_before-$staker_wei_after) wei +if [[ "$tmp" != "" ]]; then echo event Staked\($staker, $d1, $d2\) emitted; fi echo $(date +"%T,%3N") $block_num \ No newline at end of file diff --git a/state.sh b/state.sh index 1eaf673..99b028a 100755 --- a/state.sh +++ b/state.sh @@ -5,30 +5,40 @@ if [ $# -ne 2 ]; then exit 1 fi -block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) && \ -block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16) && \ -echo $(date +"%T,%3N") $block_num && \ -owner=$(cast call $1 "owner()(address)" --block $block_num --rpc-url http://localhost:4201) && \ -lst=$(cast call $1 "getLST()(address)" --block $block_num --rpc-url http://localhost:4201) && \ -echo rewardsBeforeUnstaking = $(cast rpc eth_getBalance $1 $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) && \ -x=$(cast call $lst "balanceOf(address)(uint256)" $owner --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -owner_lst=$(cast to-unit $x ether) && \ -x=$(cast rpc eth_getBalance $owner $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) && \ -owner_zil=$(cast to-unit $x ether) && \ -echo owner: $owner_lst LST && echo owner: $owner_zil ZIL && \ -x=$(cast call $lst "balanceOf(address)(uint256)" $2 --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -staker_lst=$(cast to-unit $x ether) && \ -x=$(cast rpc eth_getBalance $2 $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) && \ -staker_zil=$(cast to-unit $x ether) && \ -echo staker: $staker_lst LST && echo staker: $staker_zil ZIL && \ -x=$(cast call $lst "totalSupply()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -y=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -z=$(cast call $1 "getStake()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -price=$(bc -l <<< \($y+$z\)/$x) && \ -echo LST supply: $(cast to-unit $x ether) && \ -echo LST price: $price && \ -echo staker LST value: $(bc -l <<< $staker_lst*$price) ZIL && \ -echo getStake = $z && \ -echo getRewards = $y && \ -echo getTaxedRewards = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -echo getTotalWithdrawals = $(cast call $1 "getTotalWithdrawals()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') \ No newline at end of file +block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) +block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16) +echo $(date +"%T,%3N") $block_num + +owner=$(cast call $1 "owner()(address)" --block $block_num --rpc-url http://localhost:4201) +lst=$(cast call $1 "getLST()(address)" --block $block_num --rpc-url http://localhost:4201) + +rewardsBeforeUnstaking=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +#rewardsBeforeUnstaking=$(cast rpc eth_getBalance $1 $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +taxedRewardsBeforeUnstaking=$(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +echo rewardsBeforeUnstaking = $rewardsBeforeUnstaking +echo taxedRewardsBeforeUnstaking = $taxedRewardsBeforeUnstaking + +x=$(cast call $lst "balanceOf(address)(uint256)" $owner --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +owner_lst=$(cast to-unit $x ether) +x=$(cast rpc eth_getBalance $owner $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +owner_zil=$(cast to-unit $x ether) +echo owner: $owner_lst LST && echo owner: $owner_zil ZIL + +x=$(cast call $lst "balanceOf(address)(uint256)" $2 --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +staker_lst=$(cast to-unit $x ether) +x=$(cast rpc eth_getBalance $2 $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +staker_zil=$(cast to-unit $x ether) +echo staker: $staker_lst LST && echo staker: $staker_zil ZIL + +totalSupply=$(cast call $lst "totalSupply()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +stake=$(cast call $1 "getStake()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +commissionNumerator=$(cast call $1 "getCommissionNumerator()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +denominator=$(cast call $1 "DENOMINATOR()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +price=$(bc -l <<< \($stake+$rewardsBeforeUnstaking-\($rewardsBeforeUnstaking-$taxedRewardsBeforeUnstaking\)*$commissionNumerator/$denominator\)/$totalSupply) + +echo LST supply: $(cast to-unit $totalSupply ether) ZIL +echo LST price: $price +echo staker LST value: $(bc -l <<< $staker_lst*$price) ZIL + +echo validator stake: $(cast to-unit $stake ether) ZIL +echo pending withdrawals: $(cast call $1 "getTotalWithdrawals()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') wei \ No newline at end of file diff --git a/test/Delegation.t.sol b/test/Delegation.t.sol index 60c6c44..5959f8d 100644 --- a/test/Delegation.t.sol +++ b/test/Delegation.t.sol @@ -1,32 +1,15 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.26; -import {Delegation} from "src/Delegation.sol"; -import {DelegationV2} from "src/DelegationV2.sol"; +import {Delegation} from "src/Delegation.sol"; +import {DelegationV2} from "src/DelegationV2.sol"; import {NonRebasingLST} from "src/NonRebasingLST.sol"; -import {Deposit} from "src/Deposit.sol"; +import {Deposit} from "src/Deposit.sol"; +import {Console} from "src/Console.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {Test, Vm} from "forge-std/Test.sol"; import "forge-std/console.sol"; -library Console { - function log(string memory format, uint256 amount) external { - string memory zeros = ""; - uint256 decimals = amount % 10**18; - while (decimals > 0 && decimals < 10**17) { - //console.log("%s %s", zeros, decimals); - zeros = string.concat(zeros, "0"); - decimals *= 10; - } - console.log( - format, - amount / 10**18, - zeros, - amount % 10**18 - ); - } -} - contract DelegationTest is Test { address payable proxy; address owner; diff --git a/unstake.sh b/unstake.sh index 78740b9..383d00b 100755 --- a/unstake.sh +++ b/unstake.sh @@ -6,28 +6,55 @@ if [ $# -lt 2 ]; then fi if [ $# -eq 3 ]; then - amount="$3" + shares="$3" else - amount=0 + shares=0 fi -staker=$(cast wallet address $2) && \ -forge script script/unstake_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable, uint256)" $1 $amount --private-key $2 && \ -block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) && \ -block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16) && \ -echo rewardsAfterUnstaking = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -echo taxedRewardsAfterUnstaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -echo $(date +"%T,%3N") $block_num && \ -block_num=$((block_num-1)) && \ -block=$(echo $block_num | cast to-hex --base-in 10) && \ -echo rewardsBeforeUnstaking = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -echo taxedRewardsBeforeUnstaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -lst=$(cast call $1 "getLST()(address)" --block $block_num --rpc-url http://localhost:4201) && \ -if [[ "$amount" == "0" ]]; then amount=$(cast call $lst "balanceOf(address)(uint256)" $staker --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g'); fi && \ -x=$(cast call $lst "totalSupply()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -y=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -z=$(cast call $1 "getStake()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') && \ -price=$(bc -l <<< \($y+$z\)/$x) && \ -echo LST price: $price && \ -echo unstaked LST value: $(bc -l <<< $amount*$price/10^18) ZIL && \ +staker=$(cast wallet address $2) + +forge script script/unstake_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable, uint256)" $1 $shares --private-key $2 + +block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) +block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16) + +echo rewardsAfterUnstaking = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +echo taxedRewardsAfterUnstaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + +tmp=$(cast logs --from-block $block_num --to-block $block_num --address $1 "Unstaked(address,uint256,uint256)" --rpc-url http://localhost:4201 | grep "data") +if [[ "$tmp" != "" ]]; then + tmp=${tmp#*: } + tmp=$(cast abi-decode --input "x(uint256,uint256)" $tmp | sed 's/\[[^]]*\]//g') + tmp=(${tmp}) + d1=${tmp[0]} + d2=${tmp[1]} + #d1=$(echo $tmp | sed -n -e 1p | sed 's/\[[^]]*\]//g') + #d2=$(echo $tmp | sed -n -e 2p | sed 's/\[[^]]*\]//g') +fi + +echo $(date +"%T,%3N") $block_num + +block_num=$((block_num-1)) +block=$(echo $block_num | cast to-hex --base-in 10) + +rewardsBeforeUnstaking=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +taxedRewardsBeforeUnstaking=$(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +echo rewardsBeforeUnstaking = $rewardsBeforeUnstaking +echo taxedRewardsBeforeUnstaking = $taxedRewardsBeforeUnstaking + +lst=$(cast call $1 "getLST()(address)" --block $block_num --rpc-url http://localhost:4201) + +if [[ "$shares" == "0" ]]; then shares=$(cast call $lst "balanceOf(address)(uint256)" $staker --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g'); fi + +totalSupply=$(cast call $lst "totalSupply()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +stake=$(cast call $1 "getStake()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +commissionNumerator=$(cast call $1 "getCommissionNumerator()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +denominator=$(cast call $1 "DENOMINATOR()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +price=$(bc -l <<< \($stake+$rewardsBeforeUnstaking-\($rewardsBeforeUnstaking-$taxedRewardsBeforeUnstaking\)*$commissionNumerator/$denominator\)/$totalSupply) + +echo LST price: $price +echo unstaked LST value: $(bc -l <<< $shares*$price/10^18) ZIL + +if [[ "$tmp" != "" ]]; then echo event Unstaked\($staker, $d1, $d2\) emitted; fi + echo $(date +"%T,%3N") $block_num \ No newline at end of file