diff --git a/README.md b/README.md index 3080a8f..0b7cf4e 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ function withdrawAllRewards() external returns(uint256 taxedRewards); function withdrawRewards(uint256 amount) external returns(uint256 taxedRewards); function stakeRewards() external; ``` -for the non-liquid variant. +and a few more for the non-liquid variant. To enable the tests included in this repository to interact with the Zilliqa 2.0 deposit contract, it must be compiled along with the test contracts. Specify the folder containing the `deposit.sol` file in `remappings.txt`: ``` diff --git a/claim.sh b/claim.sh index fa586bf..6129d1e 100755 --- a/claim.sh +++ b/claim.sh @@ -1,5 +1,7 @@ #!/bin/bash +url=http://localhost:4201 + if [ $# -ne 2 ]; then echo "Provide the delegation contract address and a staker private key as arguments." exit 1 @@ -7,26 +9,26 @@ fi staker=$(cast wallet address $2) -temp=$(forge script script/variant_Delegation.s.sol --rpc-url http://localhost:4201 --sig "run(address payable)" $1 | tail -n 1) +temp=$(forge script script/variant_Delegation.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 -forge script script/claim_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable)" $1 --private-key $2 -vvvv +forge script script/claim_Delegation.s.sol --rpc-url $url --broadcast --legacy --sig "run(address payable)" $1 --private-key $2 -vvvv -block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) +block=$(cast rpc eth_blockNumber --rpc-url $url) 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 rewardsAfterClaiming = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') if [[ "$variant" == "ILiquidDelegation" ]]; then - echo taxedRewardsAfterClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + echo taxedRewardsAfterClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') fi -stakerWeiAfter=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +stakerWeiAfter=$(cast rpc eth_getBalance $staker $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) -tmp=$(cast logs --from-block $block_num --to-block $block_num --address $1 "Claimed(address,uint256,bytes)" --rpc-url http://localhost:4201 | grep "data") +tmp=$(cast logs --from-block $block_num --to-block $block_num --address $1 "Claimed(address,uint256,bytes)" --rpc-url $url | grep "data") if [[ "$tmp" != "" ]]; then tmp=${tmp#*: } tmp=$(cast abi-decode --input "x(uint256,bytes)" $tmp | sed 's/\[[^]]*\]//g') @@ -43,12 +45,12 @@ 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 rewardsBeforeClaiming = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') if [[ "$variant" == "ILiquidDelegation" ]]; then - echo taxedRewardsBeforeClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + echo taxedRewardsBeforeClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') fi -stakerWeiBefore=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +stakerWeiBefore=$(cast rpc eth_getBalance $staker $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) echo claimed amount - gas fee = $(bc -l <<< "scale=18; $stakerWeiAfter-$stakerWeiBefore") wei diff --git a/stake.sh b/stake.sh index 04be27b..21ad08f 100755 --- a/stake.sh +++ b/stake.sh @@ -1,5 +1,7 @@ #!/bin/bash +url=http://localhost:4201 + if [ $# -ne 3 ]; then echo "Provide the delegation contract address, a staker private key and an amount in wei as arguments." exit 1 @@ -7,26 +9,26 @@ fi staker=$(cast wallet address $2) -temp=$(forge script script/variant_Delegation.s.sol --rpc-url http://localhost:4201 --sig "run(address payable)" $1 | tail -n 1) +temp=$(forge script script/variant_Delegation.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 -forge script script/stake_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable, uint256)" $1 $3 --private-key $2 +forge script script/stake_Delegation.s.sol --rpc-url $url --broadcast --legacy --sig "run(address payable, uint256)" $1 $3 --private-key $2 -block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) +block=$(cast rpc eth_blockNumber --rpc-url $url) 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 rewardsAfterStaking = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') if [[ "$variant" == "ILiquidDelegation" ]]; then - echo taxedRewardsAfterStaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + echo taxedRewardsAfterStaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') fi -stakerWeiAfter=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +stakerWeiAfter=$(cast rpc eth_getBalance $staker $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) -tmp=$(cast logs --from-block $block_num --to-block $block_num --address $1 "Staked(address,uint256,bytes)" --rpc-url http://localhost:4201 | grep "data") +tmp=$(cast logs --from-block $block_num --to-block $block_num --address $1 "Staked(address,uint256,bytes)" --rpc-url $url | grep "data") if [[ "$tmp" != "" ]]; then tmp=${tmp#*: } tmp=$(cast abi-decode --input "x(uint256,bytes)" $tmp | sed 's/\[[^]]*\]//g') @@ -42,28 +44,28 @@ echo $(date +"%T,%3N") $block_num block_num=$((block_num-1)) block=$(echo $block_num | cast to-hex --base-in 10) -rewardsBeforeStaking=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +rewardsBeforeStaking=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') echo rewardsBeforeStaking = $rewardsBeforeStaking -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') +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 - taxedRewardsBeforeStaking=$(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + taxedRewardsBeforeStaking=$(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') echo taxedRewardsBeforeStaking = $taxedRewardsBeforeStaking - lst=$(cast call $1 "getLST()(address)" --block $block_num --rpc-url http://localhost:4201) - symbol=$(cast call $lst "symbol()(string)" --block $block_num --rpc-url http://localhost:4201 | tr -d '"') + 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 '"') - totalSupply=$(cast call $lst "totalSupply()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + totalSupply=$(cast call $lst "totalSupply()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') price=$(bc -l <<< "scale=36; ($stake+$rewardsBeforeStaking-($rewardsBeforeStaking-$taxedRewardsBeforeStaking)*$commissionNumerator/$denominator)/$totalSupply") - price0=$(cast call $1 "getPrice()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + price0=$(cast call $1 "getPrice()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') echo $symbol price: $price \~ $(cast to-unit $price0 ether) echo staked ZIL shares: $(bc -l <<< "scale=18; $3/$price/10^18") $symbol fi -stakerWeiBefore=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +stakerWeiBefore=$(cast rpc eth_getBalance $staker $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) echo staked amount + gas fee = $(bc -l <<< "scale=18; $stakerWeiBefore-$stakerWeiAfter") wei if [[ "$tmp" != "" ]]; then echo event Staked\($staker, $d1, $d2\) emitted; fi diff --git a/stakeRewards.sh b/stakeRewards.sh index 07b955e..8ee0361 100755 --- a/stakeRewards.sh +++ b/stakeRewards.sh @@ -1,5 +1,7 @@ #!/bin/bash +url=http://localhost:4201 + if [ $# -lt 2 ]; then echo "Provide the delegation contract address and the validator or staker private key." exit 1 @@ -7,36 +9,36 @@ fi staker=$(cast wallet address $2) -temp=$(forge script script/variant_Delegation.s.sol --rpc-url http://localhost:4201 --sig "run(address payable)" $1 | tail -n 1) +temp=$(forge script script/variant_Delegation.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 -owner=$(cast call $1 "owner()(address)" --block latest --rpc-url http://localhost:4201) +owner=$(cast call $1 "owner()(address)" --block latest --rpc-url $url) if [ "$variant" == "ILiquidDelegation" ] && [ "$staker" != "$owner" ]; then echo Rewards must be staked by the validator and it is not $staker exit 1 fi -forge script script/stakeRewards_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable)" $1 --private-key $2 +forge script script/stakeRewards_Delegation.s.sol --rpc-url $url --broadcast --legacy --sig "run(address payable)" $1 --private-key $2 -block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) +block=$(cast rpc eth_blockNumber --rpc-url $url) block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16) -rewardsAfterStaking=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') -taxedRewardsAfterStaking=$(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') -depositAfterStaking=$(cast call $1 "getStake()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +rewardsAfterStaking=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') +taxedRewardsAfterStaking=$(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') +depositAfterStaking=$(cast call $1 "getStake()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') echo rewardsAfterStaking = $rewardsAfterStaking echo taxedRewardsAfterStaking = $taxedRewardsAfterStaking echo depositAfterStaking = $depositAfterStaking -stakerWeiAfter=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) -ownerWeiAfter=$(cast rpc eth_getBalance $owner $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +stakerWeiAfter=$(cast rpc eth_getBalance $staker $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) +ownerWeiAfter=$(cast rpc eth_getBalance $owner $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) -tmp1=$(cast logs --from-block $block_num --to-block $block_num --address $1 "CommissionPaid(address,uint256)" --rpc-url http://localhost:4201 | grep "data") +tmp1=$(cast logs --from-block $block_num --to-block $block_num --address $1 "CommissionPaid(address,uint256)" --rpc-url $url | grep "data") if [[ "$tmp1" != "" ]]; then tmp1=${tmp1#*: } tmp1=$(cast abi-decode --input "x(uint256)" $tmp1 | sed 's/\[[^]]*\]//g') @@ -50,16 +52,16 @@ echo $(date +"%T,%3N") $block_num block_num=$((block_num-1)) block=$(echo $block_num | cast to-hex --base-in 10) -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') +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') -stakerWeiBefore=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) -ownerWeiBefore=$(cast rpc eth_getBalance $owner $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +stakerWeiBefore=$(cast rpc eth_getBalance $staker $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) +ownerWeiBefore=$(cast rpc eth_getBalance $owner $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) -rewardsBeforeStaking=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') -taxedRewardsBeforeStaking=$(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') -depositBeforeStaking=$(cast call $1 "getStake()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +rewardsBeforeStaking=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') +taxedRewardsBeforeStaking=$(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') +depositBeforeStaking=$(cast call $1 "getStake()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') echo rewardsBeforeStaking = $rewardsBeforeStaking echo taxedRewardsBeforeStaking = $taxedRewardsBeforeStaking echo depositBeforeStaking = $depositBeforeStaking diff --git a/state.sh b/state.sh index bebb911..c834ec1 100755 --- a/state.sh +++ b/state.sh @@ -1,11 +1,13 @@ #!/bin/bash +url=http://localhost:4201 + 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/variant_Delegation.s.sol --rpc-url http://localhost:4201 --sig "run(address payable)" $1 | tail -n 1) +temp=$(forge script script/variant_Delegation.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 @@ -16,76 +18,76 @@ 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 http://localhost:4201) + 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 http://localhost:4201) +owner=$(cast call $1 "owner()(address)" --block $block_num --rpc-url $url) -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) +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 http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +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 http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +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 http://localhost:4201 | sed 's/\[[^]]*\]//g') + 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 http://localhost:4201) - symbol=$(cast call $lst "symbol()(string)" --block $block_num --rpc-url http://localhost:4201 | tr -d '"') - x=$(cast call $lst "balanceOf(address)(uint256)" $owner --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + 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 http://localhost:4201 | sed 's/\[[^]]*\]//g') + 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 http://localhost:4201 | sed 's/\[[^]]*\]//g') + 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 http://localhost:4201 | sed 's/\[[^]]*\]//g') + 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 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') +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 http://localhost:4201 | sed 's/\[[^]]*\]//g') + 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 http://localhost:4201 | sed 's/\[[^]]*\]//g') + 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 http://localhost:4201 | sed 's/\[[^]]*\]//g') + 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 http://localhost:4201 | sed 's/\[[^]]*\]//g') +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 http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +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 http://localhost:4201 | sed 's/\[[^]]*\]//g') +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 http://localhost:4201 | sed 's/\[[^]]*\]//g') +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 http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +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 diff --git a/unstake.sh b/unstake.sh index 13f0513..af64f3c 100755 --- a/unstake.sh +++ b/unstake.sh @@ -1,5 +1,7 @@ #!/bin/bash +url=http://localhost:4201 + if [ $# -lt 2 ]; then echo "Provide the delegation contract address, a staker private key and optionally how much to unstake as arguments." exit 1 @@ -13,24 +15,24 @@ fi staker=$(cast wallet address $2) -temp=$(forge script script/variant_Delegation.s.sol --rpc-url http://localhost:4201 --sig "run(address payable)" $1 | tail -n 1) +temp=$(forge script script/variant_Delegation.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 -forge script script/unstake_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable, uint256)" $1 $shares --private-key $2 +forge script script/unstake_Delegation.s.sol --rpc-url $url --broadcast --legacy --sig "run(address payable, uint256)" $1 $shares --private-key $2 -block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) +block=$(cast rpc eth_blockNumber --rpc-url $url) 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 rewardsAfterUnstaking = $(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') if [[ "$variant" == "ILiquidDelegation" ]]; then - echo taxedRewardsAfterUnstaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + echo taxedRewardsAfterUnstaking = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') fi -tmp=$(cast logs --from-block $block_num --to-block $block_num --address $1 "Unstaked(address,uint256,bytes)" --rpc-url http://localhost:4201 | grep "data") +tmp=$(cast logs --from-block $block_num --to-block $block_num --address $1 "Unstaked(address,uint256,bytes)" --rpc-url $url | grep "data") if [[ "$tmp" != "" ]]; then tmp=${tmp#*: } tmp=$(cast abi-decode --input "x(uint256,bytes)" $tmp | sed 's/\[[^]]*\]//g') @@ -46,20 +48,20 @@ 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') +rewardsBeforeUnstaking=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') echo rewardsBeforeUnstaking = $rewardsBeforeUnstaking -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') +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 - taxedRewardsBeforeUnstaking=$(cast call $1 "getTaxedRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + 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 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') + lst=$(cast call $1 "getLST()(address)" --block $block_num --rpc-url $url) + if [[ "$shares" == "0" ]]; then shares=$(cast call $lst "balanceOf(address)(uint256)" $staker --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g'); fi + totalSupply=$(cast call $lst "totalSupply()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') price=$(bc -l <<< "scale=36; ($stake+$rewardsBeforeUnstaking-($rewardsBeforeUnstaking-$taxedRewardsBeforeUnstaking)*$commissionNumerator/$denominator)/$totalSupply") - price0=$(cast call $1 "getPrice()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') + price0=$(cast call $1 "getPrice()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') echo LST price: $price \~ $(cast to-unit $price0 ether) echo unstaked LST value: $(bc -l <<< "scale=18; $shares*$price/10^18") ZIL fi diff --git a/withdrawRewards.sh b/withdrawRewards.sh index 6d3bb5b..201781b 100755 --- a/withdrawRewards.sh +++ b/withdrawRewards.sh @@ -1,5 +1,7 @@ #!/bin/bash +url=http://localhost:4201 + if [ $# -lt 2 ]; then echo "Provide the delegation contract address, a staker private key and optionally an amount and number of steps as arguments." exit 1 @@ -19,7 +21,7 @@ fi staker=$(cast wallet address $2) -temp=$(forge script script/variant_Delegation.s.sol --rpc-url http://localhost:4201 --sig "run(address payable)" $1 | tail -n 1) +temp=$(forge script script/variant_Delegation.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 @@ -30,20 +32,20 @@ if [[ "$variant" != "INonLiquidDelegation" ]]; then exit 1 fi -forge script script/withdrawRewards_Delegation.s.sol --rpc-url http://localhost:4201 --broadcast --legacy --sig "run(address payable, string, string)" $1 $amount $steps --private-key $2 +forge script script/withdrawRewards_Delegation.s.sol --rpc-url $url --broadcast --legacy --sig "run(address payable, string, string)" $1 $amount $steps --private-key $2 -block=$(cast rpc eth_blockNumber --rpc-url http://localhost:4201) +block=$(cast rpc eth_blockNumber --rpc-url $url) block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16) -owner=$(cast call $1 "owner()(address)" --block $block_num --rpc-url http://localhost:4201) +owner=$(cast call $1 "owner()(address)" --block $block_num --rpc-url $url) -rewardsAfterWithdrawal=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +rewardsAfterWithdrawal=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') echo rewardsAfterWithdrawal = $rewardsAfterWithdrawal -stakerWeiAfter=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) -ownerWeiAfter=$(cast rpc eth_getBalance $owner $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +stakerWeiAfter=$(cast rpc eth_getBalance $staker $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) +ownerWeiAfter=$(cast rpc eth_getBalance $owner $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) -tmp1=$(cast logs --from-block $block_num --to-block $block_num --address $1 "RewardPaid(address,uint256)" --rpc-url http://localhost:4201 | grep "data") +tmp1=$(cast logs --from-block $block_num --to-block $block_num --address $1 "RewardPaid(address,uint256)" --rpc-url $url | grep "data") if [[ "$tmp1" != "" ]]; then tmp1=${tmp1#*: } tmp1=$(cast abi-decode --input "x(uint256)" $tmp1 | sed 's/\[[^]]*\]//g') @@ -52,7 +54,7 @@ if [[ "$tmp1" != "" ]]; then #d1=$(echo $tmp | sed -n -e 1p | sed 's/\[[^]]*\]//g') fi -tmp2=$(cast logs --from-block $block_num --to-block $block_num --address $1 "CommissionPaid(address,uint256)" --rpc-url http://localhost:4201 | grep "data") +tmp2=$(cast logs --from-block $block_num --to-block $block_num --address $1 "CommissionPaid(address,uint256)" --rpc-url $url | grep "data") if [[ "$tmp2" != "" ]]; then tmp2=${tmp2#*: } tmp2=$(cast abi-decode --input "x(uint256)" $tmp2 | sed 's/\[[^]]*\]//g') @@ -61,7 +63,7 @@ if [[ "$tmp2" != "" ]]; then #d2=$(echo $tmp2 | sed -n -e 1p | sed 's/\[[^]]*\]//g') fi -x=$(cast call $1 "rewards()(uint256)" --from $staker --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +x=$(cast call $1 "rewards()(uint256)" --from $staker --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') staker_rewards_after_withdrawal=$(cast to-unit $x ether) echo $(date +"%T,%3N") $block_num @@ -69,17 +71,17 @@ echo $(date +"%T,%3N") $block_num block_num=$((block_num-1)) block=$(echo $block_num | cast to-hex --base-in 10) -rewardsBeforeWithdrawal=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +rewardsBeforeWithdrawal=$(cast call $1 "getRewards()(uint256)" --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') echo rewardsBeforeWithdrawal = $rewardsBeforeWithdrawal -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') +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') -stakerWeiBefore=$(cast rpc eth_getBalance $staker $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) -ownerWeiBefore=$(cast rpc eth_getBalance $owner $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +stakerWeiBefore=$(cast rpc eth_getBalance $staker $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) +ownerWeiBefore=$(cast rpc eth_getBalance $owner $block --rpc-url $url | tr -d '"' | cast to-dec --base-in 16) -x=$(cast call $1 "rewards()(uint256)" --from $staker --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') +x=$(cast call $1 "rewards()(uint256)" --from $staker --block $block_num --rpc-url $url | sed 's/\[[^]]*\]//g') staker_rewards_before_withdrawal=$(cast to-unit $x ether) echo staker rewards before withdrawal: $staker_rewards_before_withdrawal ZIL