diff --git a/foundry.toml b/foundry.toml index 8676616..07a7550 100644 --- a/foundry.toml +++ b/foundry.toml @@ -3,5 +3,7 @@ src = "src" out = "out" libs = ["lib"] evm_version = 'shanghai' +via_ir = true +gas_limit = 10000000000 # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/src/LiquidDelegationV2.sol b/src/LiquidDelegationV2.sol index 5181c66..cb89ab5 100644 --- a/src/LiquidDelegationV2.sol +++ b/src/LiquidDelegationV2.sol @@ -107,6 +107,31 @@ contract LiquidDelegationV2 is BaseDelegation, ILiquidDelegation { emit Staked(_msgSender(), msg.value, abi.encode(shares)); } + //TODO: remove the whole function, was added temporarily for testing if the + // validator can unstake its entire deposit to remove itself from the committee, + // returns the amount to be paid, the contract's balance, + // the gap to be withdrawn from the deposit and the contract's deposit + function unstake2(uint256 shares) public view returns(uint256, uint256, int256, uint256) { + uint256 amount; + LiquidDelegationStorage storage $ = _getLiquidDelegationStorage(); + // before calculating the amount deduct the commission from the yet untaxed rewards + //taxRewards(); + uint256 rewards = getRewards(); + uint256 commission = (rewards - $.taxedRewards) * getCommissionNumerator() / DENOMINATOR; + uint256 taxedRewards = rewards - commission; + if (NonRebasingLST($.lst).totalSupply() == 0) + amount = shares; + else + amount = (getStake() + taxedRewards) * shares / NonRebasingLST($.lst).totalSupply(); + //_enqueueWithdrawal(amount); + // maintain a balance that is always sufficient to cover the claims + //if (address(this).balance < getTotalWithdrawals()) + // _decreaseDeposit(getTotalWithdrawals() - address(this).balance); + return (amount, address(this).balance - commission, int256(getTotalWithdrawals()) + int256(amount) - int256(address(this).balance - commission), getStake()); + //NonRebasingLST($.lst).burn(_msgSender(), shares); + //emit Unstaked(_msgSender(), amount, abi.encode(shares)); + } + function unstake(uint256 shares) public override whenNotPaused { uint256 amount; LiquidDelegationStorage storage $ = _getLiquidDelegationStorage(); diff --git a/src/NonLiquidDelegationV2.sol b/src/NonLiquidDelegationV2.sol index 1c93ab8..3cd0e6c 100644 --- a/src/NonLiquidDelegationV2.sol +++ b/src/NonLiquidDelegationV2.sol @@ -287,13 +287,13 @@ contract NonLiquidDelegationV2 is BaseDelegation, INonLiquidDelegation { } // all rewards recorded in the stakings were taken into account if (index == $.stakings.length) { - // ensure that the next time the function is called the last index + // ensure that the next time we call withdrawRewards() the last index // representing the rewards accrued since the last staking are not // included in the result any more - however, what if there have // been no stakings i.e. the last index remains the same, but there // have been additional rewards - how can we determine the amount of - // rewards added since we called _withdrawRewards() last time? - index++; + // rewards added since we called withdrawRewards() last time? + // index++; // the last step is to add the rewards accrued since the last staking if (total > 0) result += (int256(getRewards()) - $.totalRewards).toUint256() * amount / total; diff --git a/state.sh b/state.sh index c9c5ff7..41674c6 100755 --- a/state.sh +++ b/state.sh @@ -70,5 +70,7 @@ fi claimable=$(cast call $1 "getClaimable()(uint256)" --from $2 --block $block_num --rpc-url http://localhost:4201 | sed 's/\[[^]]*\]//g') echo staker claimable: $(cast to-unit $claimable ether) ZIL -echo validator stake: $(cast to-unit $stake ether) ZIL +echo validator deposit: $(cast to-unit $stake ether) ZIL +balance=$(cast rpc eth_getBalance $1 $block --rpc-url http://localhost:4201 | tr -d '"' | cast to-dec --base-in 16) +echo validator balance: $(cast to-unit $balance 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