Skip to content

Commit

Permalink
Fix bc scale in bash scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
DrZoltanFazekas committed Oct 21, 2024
1 parent 087f58d commit 7389500
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion claim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ echo taxedRewardsBeforeClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --

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
echo claimed amount - gas fee = $(bc -l <<< "scale=18; $staker_wei_after-$staker_wei_before") wei
if [[ "$tmp" != "" ]]; then echo event Claimed\($staker, $d1\) emitted; fi
echo $(date +"%T,%3N") $block_num
2 changes: 1 addition & 1 deletion stake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ echo taxedRewardsBeforeStaking = $(cast call $1 "getTaxedRewards()(uint256)" --b

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
echo staked amount + gas fee = $(bc -l <<< "scale=18; $staker_wei_before-$staker_wei_after") wei
if [[ "$tmp" != "" ]]; then echo event Staked\($staker, $d1, $d2\) emitted; fi
echo $(date +"%T,%3N") $block_num
4 changes: 2 additions & 2 deletions state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ totalSupply=$(cast call $lst "totalSupply()(uint256)" --block $block_num --rpc-u
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)
price=$(bc -l <<< "scale=36; ($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 staker LST value: $(bc -l <<< "scale=18; $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
4 changes: 2 additions & 2 deletions unstake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ totalSupply=$(cast call $lst "totalSupply()(uint256)" --block $block_num --rpc-u
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)
price=$(bc -l <<< "scale=36; ($stake+$rewardsBeforeUnstaking-($rewardsBeforeUnstaking-$taxedRewardsBeforeUnstaking)*$commissionNumerator/$denominator)/$totalSupply")

echo LST price: $price
echo unstaked LST value: $(bc -l <<< $shares*$price/10^18) ZIL
echo unstaked LST value: $(bc -l <<< "scale=18; $shares*$price/10^18") ZIL

if [[ "$tmp" != "" ]]; then echo event Unstaked\($staker, $d1, $d2\) emitted; fi

Expand Down

0 comments on commit 7389500

Please sign in to comment.