Skip to content

Commit

Permalink
additional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jtfirek committed Oct 3, 2024
1 parent 620f823 commit 601ff25
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/LiquidityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL

emit Rebase(getTotalPooledEther(), eETH.totalShares());
}

/// @notice pay protocol fees including 5% to treaury, 5% to node operator and ethfund bnft holders
/// @param _protocolFees The amount of protocol fees to pay in ether
function payProtocolFees(uint128 _protocolFees) external {
Expand Down
4 changes: 4 additions & 0 deletions src/WithdrawRequestNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ contract WithdrawRequestNFT is ERC721Upgradeable, UUPSUpgradeable, OwnableUpgrad
/// @param lastRequestId the id of the last request to finalize in this batch, will update `lastFinalizedRequestId` value
function finalizeRequests(uint32 lastRequestId) external {
if (!roleRegistry.hasRole(WITHDRAW_NFT_ADMIN_ROLE, msg.sender)) revert IncorrectRole();
require(lastRequestId >= lastFinalizedRequestId, "Invalid lastRequestId submitted");

// No new requests have been finalized since the last oracle report
if (lastRequestId == lastFinalizedRequestId) { return; }

uint256 totalAmount = uint256(calculateTotalPendingAmount(lastRequestId));
_finalizeRequests(lastRequestId, totalAmount);
Expand Down
23 changes: 23 additions & 0 deletions test/WithdrawRequestNFT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,23 @@ contract WithdrawRequestNFTTest is TestSetup {
// Within `LP.requestWithdraw`
// - `share` is calculated by `sharesForAmount` as (9 * 98) / 100 = 8.82 ---> (rounded down to) 8

uint256 dustSharesBefore = withdrawRequestNFTInstance.getAccumulatedDustEEthAmount();
console.log("dustSharesBefore: ", dustSharesBefore);

vm.prank(address(membershipManagerInstance));
liquidityPoolInstance.rebase(2);

_finalizeWithdrawalRequest(requestId);

uint256 dustSharesAfter = withdrawRequestNFTInstance.getAccumulatedDustEEthAmount();
console.log("dustSharesAfter: ", dustSharesAfter);

vm.prank(bob);
withdrawRequestNFTInstance.claimWithdraw(requestId, 1);

uint256 dustSharesAfter2 = withdrawRequestNFTInstance.getAccumulatedDustEEthAmount();
console.log("dustSharesAfter2: ", dustSharesAfter2);

// Within `claimWithdraw`,
// - `request.amountOfEEth` is 9
// - `amountForShares` is (8 * 100) / 98 = 8.16 ---> (rounded down to) 8
Expand Down Expand Up @@ -452,7 +463,19 @@ contract WithdrawRequestNFTTest is TestSetup {
liquidityPoolInstance.rebase(50 ether);

// finalize the requests in multiple batches

_finalizeWithdrawalRequest(5);

uint256 dustShares1 = withdrawRequestNFTInstance.getAccumulatedDustEEthAmount();

// no new NFTs where finalized during this period
_finalizeWithdrawalRequest(5);
// dust should remain the same amount
assertEq(dustShares1, withdrawRequestNFTInstance.getAccumulatedDustEEthAmount());

vm.expectRevert("Invalid lastRequestId submitted");
_finalizeWithdrawalRequest(4);

_finalizeWithdrawalRequest(11);
_finalizeWithdrawalRequest(17);
_finalizeWithdrawalRequest(23);
Expand Down

0 comments on commit 601ff25

Please sign in to comment.