Skip to content

Commit

Permalink
Add Foundry config settings, test full deposit unstaking
Browse files Browse the repository at this point in the history
  • Loading branch information
DrZoltanFazekas committed Nov 20, 2024
1 parent 2383ca1 commit 9342976
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions src/LiquidDelegationV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/NonLiquidDelegationV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9342976

Please sign in to comment.