-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #484 from lidofinance/feature/withdrawal_tests
- restore basic Withdrawal queue tests - fix a bug sneaked from WQv0 on request creation - fix a bug with shares precision calculation on finalization - unify assertReverts for custom error solutions
- Loading branch information
Showing
29 changed files
with
295 additions
and
476 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// SPDX-FileCopyrightText: 2022 Lido <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 Lido <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
/* See contracts/COMPILERS.md */ | ||
|
@@ -122,6 +122,8 @@ contract WithdrawalQueue { | |
*/ | ||
uint256 public constant MAX_STETH_WITHDRAWAL_AMOUNT = 1000 ether; | ||
|
||
uint256 public constant SHARE_RATE_PRECISION = 1e27; | ||
|
||
///! STRUCTURED STORAGE OF THE CONTRACT | ||
///! SLOT 0: uint128 lockedEtherAmount | ||
///! SLOT 1: uint256 finalizedRequestsCounter | ||
|
@@ -139,7 +141,7 @@ contract WithdrawalQueue { | |
uint256 public finalizedRequestsCounter = 0; | ||
|
||
/// @notice queue for withdrawal requests | ||
WithdrawalRequest[] public queue; | ||
WithdrawalRequest[] internal queue; | ||
|
||
/// @notice withdrawal requests mapped to the recipients | ||
mapping(address => uint256[]) public requestsByRecipient; | ||
|
@@ -311,7 +313,9 @@ contract WithdrawalQueue { | |
if (_lastIdToFinalize < finalizedRequestsCounter || _lastIdToFinalize >= queue.length) { | ||
revert InvalidFinalizationId(); | ||
} | ||
if (lockedEtherAmount + msg.value > address(this).balance) revert NotEnoughEther(); | ||
(uint128 ethToWithdraw, ) = _calculateDiscountedBatch(finalizedRequestsCounter, _lastIdToFinalize, _shareRate); | ||
|
||
if (msg.value < ethToWithdraw) revert NotEnoughEther(); | ||
|
||
_updateRateHistory(_shareRate, _lastIdToFinalize); | ||
|
||
|
@@ -331,7 +335,7 @@ contract WithdrawalQueue { | |
function calculateFinalizationParams( | ||
uint256 _lastIdToFinalize, | ||
uint256 _shareRate | ||
) external view returns (uint256 etherToLock, uint256 sharesToBurn) { | ||
) external view returns (uint128 etherToLock, uint128 sharesToBurn) { | ||
return _calculateDiscountedBatch(finalizedRequestsCounter, _lastIdToFinalize, _shareRate); | ||
} | ||
|
||
|
@@ -413,7 +417,7 @@ contract WithdrawalQueue { | |
shares -= queue[_firstId - 1].cumulativeShares; | ||
} | ||
|
||
eth = _min(eth, _toUint128((shares * _shareRate) / 1e9)); | ||
eth = _min(eth, _toUint128(shares * _shareRate / SHARE_RATE_PRECISION)); | ||
} | ||
|
||
/// @dev checks if provided request included in the rate hint boundaries | ||
|
@@ -498,7 +502,7 @@ contract WithdrawalQueue { | |
WithdrawalRequest memory prevRequest = queue[requestId - 1]; | ||
|
||
cumulativeShares += prevRequest.cumulativeShares; | ||
cumulativeShares += prevRequest.cumulativeEther; | ||
cumulativeEther += prevRequest.cumulativeEther; | ||
} | ||
|
||
queue.push( | ||
|
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
contracts/0.8.9/test_helpers/StETHMockForWithdrawalQueue.sol
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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
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
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
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
Oops, something went wrong.