-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix share calculation and increase / decrease deposit on staking / un…
…staking (#3) * removed logging * removed logging * implemented commission * Implement getCommission() and extend readme * Implement getCommissionAddress() * Introduce script params * Implement claiming after unbonding period * Implement deposit increase and decrease * Modify order of staking and unstaking steps * Create bash scripts for staking, unstaking, claiming tests * Improve bash and foundry scripts * Fix price calculation and commission formatting * Fix bc scale in bash scripts * Fix tests, add getPrice() and getClaimable() * Improve staking script
- Loading branch information
1 parent
5bcd747
commit f0cfcb6
Showing
19 changed files
with
1,792 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "Provide the delegation contract address and a staker private key as arguments." | ||
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) | ||
|
||
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 <<< "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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity ^0.8.26; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {DelegationV2} from "src/DelegationV2.sol"; | ||
import "forge-std/console.sol"; | ||
|
||
contract Claim is Script { | ||
function run(address payable proxy) external { | ||
|
||
address staker = msg.sender; | ||
|
||
DelegationV2 delegation = DelegationV2( | ||
proxy | ||
); | ||
|
||
console.log("Running version: %s", | ||
delegation.version() | ||
); | ||
|
||
console.log("Staker balance before: %s wei", | ||
staker.balance | ||
); | ||
|
||
vm.broadcast(); | ||
|
||
delegation.claim(); | ||
|
||
console.log("Staker balance after: %s wei", | ||
staker.balance | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
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 { | ||
function run(address payable proxy, uint16 commissionNumerator) external { | ||
|
||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
|
||
DelegationV2 delegation = DelegationV2( | ||
proxy | ||
); | ||
|
||
console.log("Running version: %s", | ||
delegation.version() | ||
); | ||
|
||
NonRebasingLST lst = NonRebasingLST(delegation.getLST()); | ||
console.log("LST address: %s", | ||
address(lst) | ||
); | ||
|
||
Console.log("Old commission rate: %s.%s%s%%", | ||
delegation.getCommissionNumerator(), | ||
2 | ||
); | ||
|
||
vm.broadcast(deployerPrivateKey); | ||
|
||
delegation.setCommissionNumerator(commissionNumerator); | ||
|
||
Console.log("New commission rate: %s.%s%s%%", | ||
delegation.getCommissionNumerator(), | ||
2 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.