diff --git a/test/unit/libraries/AssetsAccounting.t.sol b/test/unit/libraries/AssetsAccounting.t.sol index f41865cc..408d4674 100644 --- a/test/unit/libraries/AssetsAccounting.t.sol +++ b/test/unit/libraries/AssetsAccounting.t.sol @@ -17,7 +17,7 @@ import { import {UnitTest, Duration} from "test/utils/unit-test.sol"; contract AssetsAccountingUnitTests is UnitTest { - AssetsAccounting.Context private _accountingState; + AssetsAccounting.Context private _accountingContext; // --- // accountStETHSharesLock() @@ -34,19 +34,21 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue shares = SharesValues.from(sharesAmount); - _accountingState.stETHTotals.lockedShares = totalLockedShares; - _accountingState.assets[holder].stETHLockedShares = holderLockedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.assets[holder].stETHLockedShares = holderLockedShares; vm.expectEmit(); emit AssetsAccounting.StETHSharesLocked(holder, shares); - AssetsAccounting.accountStETHSharesLock(_accountingState, holder, shares); + AssetsAccounting.accountStETHSharesLock(_accountingContext, holder, shares); - checkAccountingStateTotalCounters(totalLockedShares + shares, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO); - assert(_accountingState.assets[holder].stETHLockedShares == holderLockedShares + shares); - assert(_accountingState.assets[holder].unstETHLockedShares == SharesValues.ZERO); - assert(_accountingState.assets[holder].lastAssetsLockTimestamp <= Timestamps.now()); - assert(_accountingState.assets[holder].unstETHIds.length == 0); + checkAccountingContextTotalCounters( + totalLockedShares + shares, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO + ); + assert(_accountingContext.assets[holder].stETHLockedShares == holderLockedShares + shares); + assert(_accountingContext.assets[holder].unstETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].lastAssetsLockTimestamp <= Timestamps.now()); + assert(_accountingContext.assets[holder].unstETHIds.length == 0); } function testFuzz_accountStETHSharesLock_RevertWhen_ZeroSharesProvided(address holder) external { @@ -54,7 +56,7 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectRevert(abi.encodeWithSelector(AssetsAccounting.InvalidSharesValue.selector, shares)); - AssetsAccounting.accountStETHSharesLock(_accountingState, holder, shares); + AssetsAccounting.accountStETHSharesLock(_accountingContext, holder, shares); } function testFuzz_accountStETHSharesLock_WhenNoSharesWereLockedBefore( @@ -68,20 +70,20 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue shares = SharesValues.from(sharesAmount); - _accountingState.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; vm.expectEmit(); emit AssetsAccounting.StETHSharesLocked(stranger, shares); - AssetsAccounting.accountStETHSharesLock(_accountingState, stranger, shares); + AssetsAccounting.accountStETHSharesLock(_accountingContext, stranger, shares); - assert(_accountingState.stETHTotals.lockedShares == totalLockedShares + shares); - assert(_accountingState.assets[stranger].stETHLockedShares == shares); - assert(_accountingState.assets[stranger].lastAssetsLockTimestamp <= Timestamps.now()); + assert(_accountingContext.stETHTotals.lockedShares == totalLockedShares + shares); + assert(_accountingContext.assets[stranger].stETHLockedShares == shares); + assert(_accountingContext.assets[stranger].lastAssetsLockTimestamp <= Timestamps.now()); } // --- - // accountStETHSharesUnlock(State storage self, address holder, SharesValue shares) + // accountStETHSharesUnlock(Context storage self, address holder, SharesValue shares) // --- function testFuzz_accountStETHSharesUnlock_happyPath( @@ -98,19 +100,21 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderLockedShares = SharesValues.from(holderSharesAmount); SharesValue totalLockedShares = totalLockedSharesWithoutHolder + holderLockedShares; - _accountingState.stETHTotals.lockedShares = totalLockedShares; - _accountingState.assets[holder].stETHLockedShares = holderLockedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.assets[holder].stETHLockedShares = holderLockedShares; vm.expectEmit(); emit AssetsAccounting.StETHSharesUnlocked(holder, shares); - AssetsAccounting.accountStETHSharesUnlock(_accountingState, holder, shares); + AssetsAccounting.accountStETHSharesUnlock(_accountingContext, holder, shares); - checkAccountingStateTotalCounters(totalLockedShares - shares, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO); - assert(_accountingState.assets[holder].stETHLockedShares == holderLockedShares - shares); - assert(_accountingState.assets[holder].unstETHLockedShares == SharesValues.ZERO); - assert(_accountingState.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); - assert(_accountingState.assets[holder].unstETHIds.length == 0); + checkAccountingContextTotalCounters( + totalLockedShares - shares, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO + ); + assert(_accountingContext.assets[holder].stETHLockedShares == holderLockedShares - shares); + assert(_accountingContext.assets[holder].unstETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); + assert(_accountingContext.assets[holder].unstETHIds.length == 0); } function testFuzz_accountStETHSharesUnlock_RevertOn_ZeroSharesProvided(address holder) external { @@ -118,7 +122,7 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectRevert(abi.encodeWithSelector(AssetsAccounting.InvalidSharesValue.selector, shares)); - AssetsAccounting.accountStETHSharesUnlock(_accountingState, holder, shares); + AssetsAccounting.accountStETHSharesUnlock(_accountingContext, holder, shares); } function testFuzz_accountStETHSharesUnlock_RevertWhen_HolderHaveLessSharesThanProvided( @@ -135,12 +139,12 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderLockedShares = SharesValues.from(holderSharesAmount); SharesValue totalLockedShares = totalLockedSharesWithoutHolder + holderLockedShares; - _accountingState.stETHTotals.lockedShares = totalLockedShares; - _accountingState.assets[holder].stETHLockedShares = holderLockedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.assets[holder].stETHLockedShares = holderLockedShares; vm.expectRevert(abi.encodeWithSelector(AssetsAccounting.InvalidSharesValue.selector, shares)); - AssetsAccounting.accountStETHSharesUnlock(_accountingState, holder, shares); + AssetsAccounting.accountStETHSharesUnlock(_accountingContext, holder, shares); } function testFuzz_accountStETHSharesUnlock_RevertOn_AccountingError_TotalLockedSharesCounterIsLessThanProvidedSharesAmount( @@ -155,12 +159,12 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderLockedShares = SharesValues.from(sharesAmount); SharesValue totalLockedShares = SharesValues.from(totalSharesAmount); - _accountingState.stETHTotals.lockedShares = totalLockedShares; - _accountingState.assets[holder].stETHLockedShares = holderLockedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.assets[holder].stETHLockedShares = holderLockedShares; vm.expectRevert(stdError.arithmeticError); - AssetsAccounting.accountStETHSharesUnlock(_accountingState, holder, shares); + AssetsAccounting.accountStETHSharesUnlock(_accountingContext, holder, shares); } function testFuzz_accountStETHSharesUnlock_RevertWhen_NoSharesWereLockedBefore( @@ -173,11 +177,11 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectRevert(abi.encodeWithSelector(AssetsAccounting.InvalidSharesValue.selector, shares)); - AssetsAccounting.accountStETHSharesUnlock(_accountingState, stranger, shares); + AssetsAccounting.accountStETHSharesUnlock(_accountingContext, stranger, shares); } // --- - // accountStETHSharesUnlock(State storage self, address holder) + // accountStETHSharesUnlock(Context storage self, address holder) // --- function testFuzz_accountStETHSharesUnlock_simple_happyPath(address holder, uint128 holderSharesAmount) external { @@ -188,28 +192,28 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderLockedShares = SharesValues.from(holderSharesAmount); SharesValue totalLockedShares = totalLockedSharesWithoutHolder + holderLockedShares; - _accountingState.stETHTotals.lockedShares = totalLockedShares; - _accountingState.assets[holder].stETHLockedShares = holderLockedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.assets[holder].stETHLockedShares = holderLockedShares; vm.expectEmit(); emit AssetsAccounting.StETHSharesUnlocked(holder, holderLockedShares); - SharesValue unlockedShares = AssetsAccounting.accountStETHSharesUnlock(_accountingState, holder); + SharesValue unlockedShares = AssetsAccounting.accountStETHSharesUnlock(_accountingContext, holder); assert(unlockedShares == holderLockedShares); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( totalLockedShares - holderLockedShares, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO ); - assert(_accountingState.assets[holder].stETHLockedShares == holderLockedShares - holderLockedShares); - assert(_accountingState.assets[holder].unstETHLockedShares == SharesValues.ZERO); - assert(_accountingState.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); - assert(_accountingState.assets[holder].unstETHIds.length == 0); + assert(_accountingContext.assets[holder].stETHLockedShares == holderLockedShares - holderLockedShares); + assert(_accountingContext.assets[holder].unstETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); + assert(_accountingContext.assets[holder].unstETHIds.length == 0); } function testFuzz_accountStETHSharesUnlock_simple_RevertWhen_NoSharesWereLockedBefore(address stranger) external { vm.expectRevert(abi.encodeWithSelector(AssetsAccounting.InvalidSharesValue.selector, SharesValues.ZERO)); - AssetsAccounting.accountStETHSharesUnlock(_accountingState, stranger); + AssetsAccounting.accountStETHSharesUnlock(_accountingContext, stranger); } // --- @@ -230,9 +234,9 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue totalLockedShares = SharesValues.from(totalLockedSharesAmount); ETHValue totalClaimedETH = ETHValues.from(totalClaimedETHAmount); - _accountingState.assets[holder].stETHLockedShares = holderLockedShares; - _accountingState.stETHTotals.lockedShares = totalLockedShares; - _accountingState.stETHTotals.claimedETH = totalClaimedETH; + _accountingContext.assets[holder].stETHLockedShares = holderLockedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.stETHTotals.claimedETH = totalClaimedETH; ETHValue expectedETHWithdrawn = ETHValues.from((uint256(totalClaimedETHAmount) * holderLockedSharesAmount) / totalLockedSharesAmount); @@ -240,20 +244,20 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectEmit(); emit AssetsAccounting.ETHWithdrawn(holder, holderLockedShares, expectedETHWithdrawn); - ETHValue ethWithdrawn = AssetsAccounting.accountStETHSharesWithdraw(_accountingState, holder); + ETHValue ethWithdrawn = AssetsAccounting.accountStETHSharesWithdraw(_accountingContext, holder); assert(ethWithdrawn == expectedETHWithdrawn); - checkAccountingStateTotalCounters(totalLockedShares, totalClaimedETH, SharesValues.ZERO, ETHValues.ZERO); - assert(_accountingState.assets[holder].stETHLockedShares == SharesValues.ZERO); - assert(_accountingState.assets[holder].unstETHLockedShares == SharesValues.ZERO); - assert(_accountingState.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); - assert(_accountingState.assets[holder].unstETHIds.length == 0); + checkAccountingContextTotalCounters(totalLockedShares, totalClaimedETH, SharesValues.ZERO, ETHValues.ZERO); + assert(_accountingContext.assets[holder].stETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].unstETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); + assert(_accountingContext.assets[holder].unstETHIds.length == 0); } function testFuzz_accountStETHSharesWithdraw_RevertWhen_HolderHaveZeroShares(address stranger) external { vm.expectRevert(abi.encodeWithSelector(AssetsAccounting.InvalidSharesValue.selector, SharesValues.ZERO)); - AssetsAccounting.accountStETHSharesWithdraw(_accountingState, stranger); + AssetsAccounting.accountStETHSharesWithdraw(_accountingContext, stranger); } function testFuzz_accountStETHSharesWithdraw_RevertOn_AccountingError_TotalLockedSharesCounterIsZero( @@ -266,13 +270,13 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderLockedShares = SharesValues.from(holderLockedSharesAmount); ETHValue totalClaimedETH = ETHValues.from(totalClaimedETHAmount); - _accountingState.assets[holder].stETHLockedShares = holderLockedShares; - _accountingState.stETHTotals.lockedShares = SharesValues.ZERO; - _accountingState.stETHTotals.claimedETH = totalClaimedETH; + _accountingContext.assets[holder].stETHLockedShares = holderLockedShares; + _accountingContext.stETHTotals.lockedShares = SharesValues.ZERO; + _accountingContext.stETHTotals.claimedETH = totalClaimedETH; vm.expectRevert(stdError.divisionError); - AssetsAccounting.accountStETHSharesWithdraw(_accountingState, holder); + AssetsAccounting.accountStETHSharesWithdraw(_accountingContext, holder); } function testFuzz_accountStETHSharesWithdraw_AccountingError_WithdrawAmountMoreThanTotalClaimedETH( @@ -289,9 +293,9 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue totalLockedShares = SharesValues.from(totalLockedSharesAmount); ETHValue totalClaimedETH = ETHValues.from(totalClaimedETHAmount); - _accountingState.assets[holder].stETHLockedShares = holderLockedShares; - _accountingState.stETHTotals.lockedShares = totalLockedShares; - _accountingState.stETHTotals.claimedETH = totalClaimedETH; + _accountingContext.assets[holder].stETHLockedShares = holderLockedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.stETHTotals.claimedETH = totalClaimedETH; ETHValue expectedETHWithdrawn = ETHValues.from((uint256(totalClaimedETHAmount) * holderLockedSharesAmount) / totalLockedSharesAmount); @@ -299,11 +303,11 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectEmit(); emit AssetsAccounting.ETHWithdrawn(holder, holderLockedShares, expectedETHWithdrawn); - ETHValue ethWithdrawn = AssetsAccounting.accountStETHSharesWithdraw(_accountingState, holder); + ETHValue ethWithdrawn = AssetsAccounting.accountStETHSharesWithdraw(_accountingContext, holder); assert(ethWithdrawn == expectedETHWithdrawn); assert(ethWithdrawn.toUint256() >= totalClaimedETHAmount); - assert(_accountingState.assets[holder].stETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].stETHLockedShares == SharesValues.ZERO); } function testFuzz_accountStETHSharesWithdraw_RevertOn_AccountingError_WithdrawAmountOverflow(address holder) @@ -313,13 +317,13 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue totalLockedShares = SharesValues.from(1); ETHValue totalClaimedETH = ETHValues.from(type(uint96).max); - _accountingState.assets[holder].stETHLockedShares = holderLockedShares; - _accountingState.stETHTotals.lockedShares = totalLockedShares; - _accountingState.stETHTotals.claimedETH = totalClaimedETH; + _accountingContext.assets[holder].stETHLockedShares = holderLockedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.stETHTotals.claimedETH = totalClaimedETH; vm.expectRevert(ETHValueOverflow.selector); - AssetsAccounting.accountStETHSharesWithdraw(_accountingState, holder); + AssetsAccounting.accountStETHSharesWithdraw(_accountingContext, holder); } // --- @@ -333,14 +337,14 @@ contract AssetsAccountingUnitTests is UnitTest { ETHValue amount = ETHValues.from(ethAmount); ETHValue totalClaimedETH = ETHValues.from(totalClaimedETHAmount); - _accountingState.stETHTotals.claimedETH = totalClaimedETH; + _accountingContext.stETHTotals.claimedETH = totalClaimedETH; vm.expectEmit(); emit AssetsAccounting.ETHClaimed(amount); - AssetsAccounting.accountClaimedStETH(_accountingState, amount); + AssetsAccounting.accountClaimedStETH(_accountingContext, amount); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( SharesValues.ZERO, totalClaimedETH + amount, SharesValues.ZERO, ETHValues.ZERO ); } @@ -363,9 +367,9 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); uint256 expectedTotalUnstETHLockedAmount = 0; - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.assets[holder].unstETHIds.push(genRandomUnstEthId(1024)); - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.assets[holder].unstETHIds.push(genRandomUnstEthId(1024)); + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; WithdrawalRequestStatus[] memory withdrawalRequestStatuses = new WithdrawalRequestStatus[](amountsOfShares.length); @@ -376,33 +380,33 @@ contract AssetsAccountingUnitTests is UnitTest { withdrawalRequestStatuses[i].amountOfShares = amountsOfShares[i]; withdrawalRequestStatuses[i].isFinalized = false; withdrawalRequestStatuses[i].isClaimed = false; - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.NotLocked; + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.NotLocked; expectedTotalUnstETHLockedAmount += amountsOfShares[i]; } vm.expectEmit(); emit AssetsAccounting.UnstETHLocked(holder, unstETHIds, SharesValues.from(expectedTotalUnstETHLockedAmount)); - AssetsAccounting.accountUnstETHLock(_accountingState, holder, unstETHIds, withdrawalRequestStatuses); + AssetsAccounting.accountUnstETHLock(_accountingContext, holder, unstETHIds, withdrawalRequestStatuses); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( SharesValues.ZERO, ETHValues.ZERO, initialTotalUnfinalizedShares + SharesValues.from(expectedTotalUnstETHLockedAmount), ETHValues.ZERO ); - assert(_accountingState.assets[holder].stETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].stETHLockedShares == SharesValues.ZERO); assert( - _accountingState.assets[holder].unstETHLockedShares + _accountingContext.assets[holder].unstETHLockedShares == holderUnstETHLockedShares + SharesValues.from(expectedTotalUnstETHLockedAmount) ); - assert(_accountingState.assets[holder].lastAssetsLockTimestamp <= Timestamps.now()); - assert(_accountingState.assets[holder].unstETHIds.length == amountsOfShares.length + 1); + assert(_accountingContext.assets[holder].lastAssetsLockTimestamp <= Timestamps.now()); + assert(_accountingContext.assets[holder].unstETHIds.length == amountsOfShares.length + 1); for (uint256 i = 0; i < unstETHIds.length; ++i) { - assert(_accountingState.unstETHRecords[unstETHIds[i]].lockedBy == holder); - assert(_accountingState.unstETHRecords[unstETHIds[i]].status == UnstETHRecordStatus.Locked); - assert(_accountingState.unstETHRecords[unstETHIds[i]].index.toZeroBasedValue() == i + 1); - assert(_accountingState.unstETHRecords[unstETHIds[i]].shares == SharesValues.from(amountsOfShares[i])); - assert(_accountingState.unstETHRecords[unstETHIds[i]].claimableAmount == ETHValues.ZERO); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].lockedBy == holder); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].status == UnstETHRecordStatus.Locked); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].index.toZeroBasedValue() == i + 1); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].shares == SharesValues.from(amountsOfShares[i])); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].claimableAmount == ETHValues.ZERO); } } @@ -414,7 +418,7 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectRevert(); - AssetsAccounting.accountUnstETHLock(_accountingState, holder, unstETHIds, withdrawalRequestStatuses); + AssetsAccounting.accountUnstETHLock(_accountingContext, holder, unstETHIds, withdrawalRequestStatuses); } function testFuzz_accountUnstETHLock_RevertOn_WithdrawalRequestStatusIsFinalized( @@ -429,8 +433,8 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderUnstETHLockedShares = SharesValues.from(holderUnstETHLockedSharesAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; WithdrawalRequestStatus[] memory withdrawalRequestStatuses = new WithdrawalRequestStatus[](amountsOfShares.length); @@ -441,7 +445,7 @@ contract AssetsAccountingUnitTests is UnitTest { withdrawalRequestStatuses[i].amountOfShares = amountsOfShares[i]; withdrawalRequestStatuses[i].isFinalized = false; withdrawalRequestStatuses[i].isClaimed = false; - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.NotLocked; + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.NotLocked; } withdrawalRequestStatuses[withdrawalRequestStatuses.length - 1].isFinalized = true; @@ -454,7 +458,7 @@ contract AssetsAccountingUnitTests is UnitTest { ) ); - AssetsAccounting.accountUnstETHLock(_accountingState, holder, unstETHIds, withdrawalRequestStatuses); + AssetsAccounting.accountUnstETHLock(_accountingContext, holder, unstETHIds, withdrawalRequestStatuses); } function testFuzz_accountUnstETHLock_RevertOn_WithdrawalRequestStatusIsClaimed( @@ -469,8 +473,8 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderUnstETHLockedShares = SharesValues.from(holderUnstETHLockedSharesAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; WithdrawalRequestStatus[] memory withdrawalRequestStatuses = new WithdrawalRequestStatus[](amountsOfShares.length); @@ -481,14 +485,14 @@ contract AssetsAccountingUnitTests is UnitTest { withdrawalRequestStatuses[i].amountOfShares = amountsOfShares[i]; withdrawalRequestStatuses[i].isFinalized = false; withdrawalRequestStatuses[i].isClaimed = false; - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.NotLocked; + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.NotLocked; } withdrawalRequestStatuses[withdrawalRequestStatuses.length - 1].isClaimed = true; vm.expectRevert(); - AssetsAccounting.accountUnstETHLock(_accountingState, holder, unstETHIds, withdrawalRequestStatuses); + AssetsAccounting.accountUnstETHLock(_accountingContext, holder, unstETHIds, withdrawalRequestStatuses); } function testFuzz_accountUnstETHLock_RevertOn_UnstETHRecordStatusIsNot_NotLocked( @@ -503,8 +507,8 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderUnstETHLockedShares = SharesValues.from(holderUnstETHLockedSharesAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; WithdrawalRequestStatus[] memory withdrawalRequestStatuses = new WithdrawalRequestStatus[](amountsOfShares.length); @@ -515,10 +519,10 @@ contract AssetsAccountingUnitTests is UnitTest { withdrawalRequestStatuses[i].amountOfShares = amountsOfShares[i]; withdrawalRequestStatuses[i].isFinalized = false; withdrawalRequestStatuses[i].isClaimed = false; - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.NotLocked; + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.NotLocked; } - _accountingState.unstETHRecords[unstETHIds[unstETHIds.length - 1]].status = UnstETHRecordStatus.Withdrawn; + _accountingContext.unstETHRecords[unstETHIds[unstETHIds.length - 1]].status = UnstETHRecordStatus.Withdrawn; vm.expectRevert( abi.encodeWithSelector( @@ -528,7 +532,7 @@ contract AssetsAccountingUnitTests is UnitTest { ) ); - AssetsAccounting.accountUnstETHLock(_accountingState, holder, unstETHIds, withdrawalRequestStatuses); + AssetsAccounting.accountUnstETHLock(_accountingContext, holder, unstETHIds, withdrawalRequestStatuses); } function testFuzz_accountUnstETHLock_RevertWhen_DuplicatingUnstETHIdsProvided( @@ -543,8 +547,8 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderUnstETHLockedShares = SharesValues.from(holderUnstETHLockedSharesAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; WithdrawalRequestStatus[] memory withdrawalRequestStatuses = new WithdrawalRequestStatus[](amountsOfShares.length); @@ -555,7 +559,7 @@ contract AssetsAccountingUnitTests is UnitTest { withdrawalRequestStatuses[i].amountOfShares = amountsOfShares[i]; withdrawalRequestStatuses[i].isFinalized = false; withdrawalRequestStatuses[i].isClaimed = false; - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.NotLocked; + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.NotLocked; } unstETHIds[unstETHIds.length - 1] = unstETHIds[unstETHIds.length - 2]; @@ -568,7 +572,7 @@ contract AssetsAccountingUnitTests is UnitTest { ) ); - AssetsAccounting.accountUnstETHLock(_accountingState, holder, unstETHIds, withdrawalRequestStatuses); + AssetsAccounting.accountUnstETHLock(_accountingContext, holder, unstETHIds, withdrawalRequestStatuses); } // TODO: is it expected behavior? @@ -580,23 +584,23 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderUnstETHLockedShares = SharesValues.from(holderUnstETHLockedSharesAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; WithdrawalRequestStatus[] memory withdrawalRequestStatuses = new WithdrawalRequestStatus[](0); uint256[] memory unstETHIds = new uint256[](0); vm.expectEmit(); emit AssetsAccounting.UnstETHLocked(holder, unstETHIds, SharesValues.ZERO); - AssetsAccounting.accountUnstETHLock(_accountingState, holder, unstETHIds, withdrawalRequestStatuses); + AssetsAccounting.accountUnstETHLock(_accountingContext, holder, unstETHIds, withdrawalRequestStatuses); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( SharesValues.ZERO, ETHValues.ZERO, initialTotalUnfinalizedShares, ETHValues.ZERO ); - assert(_accountingState.assets[holder].stETHLockedShares == SharesValues.ZERO); - assert(_accountingState.assets[holder].unstETHLockedShares == holderUnstETHLockedShares); - assert(_accountingState.assets[holder].lastAssetsLockTimestamp <= Timestamps.now()); - assert(_accountingState.assets[holder].unstETHIds.length == 0); + assert(_accountingContext.assets[holder].stETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].unstETHLockedShares == holderUnstETHLockedShares); + assert(_accountingContext.assets[holder].lastAssetsLockTimestamp <= Timestamps.now()); + assert(_accountingContext.assets[holder].unstETHIds.length == 0); } function testFuzz_accountUnstETHLock_AccountingError_WithdrawalRequestStatusAmountOfSharesOverflow( @@ -607,8 +611,8 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderUnstETHLockedShares = SharesValues.from(holderUnstETHLockedSharesAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; WithdrawalRequestStatus[] memory withdrawalRequestStatuses = new WithdrawalRequestStatus[](1); uint256[] memory unstETHIds = new uint256[](1); @@ -617,11 +621,11 @@ contract AssetsAccountingUnitTests is UnitTest { withdrawalRequestStatuses[0].amountOfShares = uint256(type(uint128).max) + 1; withdrawalRequestStatuses[0].isFinalized = false; withdrawalRequestStatuses[0].isClaimed = false; - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.NotLocked; + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.NotLocked; vm.expectRevert(SharesValueOverflow.selector); - AssetsAccounting.accountUnstETHLock(_accountingState, holder, unstETHIds, withdrawalRequestStatuses); + AssetsAccounting.accountUnstETHLock(_accountingContext, holder, unstETHIds, withdrawalRequestStatuses); } function testFuzz_accountUnstETHLock_AccountingError_HolderUnstETHLockedSharesOverflow( @@ -631,8 +635,8 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderUnstETHLockedShares = SharesValues.from(type(uint128).max / 2 + 1); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; WithdrawalRequestStatus[] memory withdrawalRequestStatuses = new WithdrawalRequestStatus[](1); uint256[] memory unstETHIds = new uint256[](1); @@ -641,11 +645,11 @@ contract AssetsAccountingUnitTests is UnitTest { withdrawalRequestStatuses[0].amountOfShares = uint128(type(uint128).max / 2) + 1; withdrawalRequestStatuses[0].isFinalized = false; withdrawalRequestStatuses[0].isClaimed = false; - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.NotLocked; + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.NotLocked; vm.expectRevert(stdError.arithmeticError); - AssetsAccounting.accountUnstETHLock(_accountingState, holder, unstETHIds, withdrawalRequestStatuses); + AssetsAccounting.accountUnstETHLock(_accountingContext, holder, unstETHIds, withdrawalRequestStatuses); } function testFuzz_accountUnstETHLock_AccountingError_TotalUnfinalizedSharesOverflow( @@ -655,8 +659,8 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue holderUnstETHLockedShares = SharesValues.from(holderUnstETHLockedSharesAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(type(uint128).max / 2 + 1); - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; WithdrawalRequestStatus[] memory withdrawalRequestStatuses = new WithdrawalRequestStatus[](1); uint256[] memory unstETHIds = new uint256[](1); @@ -665,11 +669,11 @@ contract AssetsAccountingUnitTests is UnitTest { withdrawalRequestStatuses[0].amountOfShares = uint128(type(uint128).max / 2) + 1; withdrawalRequestStatuses[0].isFinalized = false; withdrawalRequestStatuses[0].isClaimed = false; - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.NotLocked; + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.NotLocked; vm.expectRevert(stdError.arithmeticError); - AssetsAccounting.accountUnstETHLock(_accountingState, holder, unstETHIds, withdrawalRequestStatuses); + AssetsAccounting.accountUnstETHLock(_accountingContext, holder, unstETHIds, withdrawalRequestStatuses); } // --- @@ -694,19 +698,19 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); uint256 expectedTotalSharesUnlockedAmount = 0; - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.finalizedETH = initialTotalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.finalizedETH = initialTotalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; uint256[] memory unstETHIds = new uint256[](amountsOfShares.length); for (uint256 i = 0; i < amountsOfShares.length; ++i) { unstETHIds[i] = genRandomUnstEthId(i); - _accountingState.unstETHRecords[unstETHIds[i]].lockedBy = holder; - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Locked; - _accountingState.unstETHRecords[unstETHIds[i]].shares = SharesValues.from(amountsOfShares[i]); - _accountingState.unstETHRecords[unstETHIds[i]].index = IndicesOneBased.fromOneBasedValue(i + 1); - _accountingState.assets[holder].unstETHIds.push(unstETHIds[i]); + _accountingContext.unstETHRecords[unstETHIds[i]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[i]].shares = SharesValues.from(amountsOfShares[i]); + _accountingContext.unstETHRecords[unstETHIds[i]].index = IndicesOneBased.fromOneBasedValue(i + 1); + _accountingContext.assets[holder].unstETHIds.push(unstETHIds[i]); expectedTotalSharesUnlockedAmount += amountsOfShares[i]; } @@ -715,23 +719,23 @@ contract AssetsAccountingUnitTests is UnitTest { holder, unstETHIds, SharesValues.from(expectedTotalSharesUnlockedAmount), ETHValues.ZERO ); - AssetsAccounting.accountUnstETHUnlock(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHUnlock(_accountingContext, holder, unstETHIds); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( SharesValues.ZERO, ETHValues.ZERO, initialTotalUnfinalizedShares - SharesValues.from(expectedTotalSharesUnlockedAmount), initialTotalFinalizedETH ); - assert(_accountingState.assets[holder].stETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].stETHLockedShares == SharesValues.ZERO); assert( - _accountingState.assets[holder].unstETHLockedShares + _accountingContext.assets[holder].unstETHLockedShares == holderUnstETHLockedShares - SharesValues.from(expectedTotalSharesUnlockedAmount) ); - assert(_accountingState.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); - assert(_accountingState.assets[holder].unstETHIds.length == 0); + assert(_accountingContext.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); + assert(_accountingContext.assets[holder].unstETHIds.length == 0); for (uint256 i = 0; i < unstETHIds.length; ++i) { - assert(_accountingState.unstETHRecords[unstETHIds[i]].shares == SharesValues.ZERO); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].shares == SharesValues.ZERO); } } @@ -753,20 +757,20 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); uint256 expectedTotalSharesUnlockedAmount = 0; - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.finalizedETH = initialTotalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.finalizedETH = initialTotalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; uint256[] memory unstETHIds = new uint256[](amountsOfShares.length); for (uint256 i = 0; i < amountsOfShares.length; ++i) { unstETHIds[i] = genRandomUnstEthId(i); - _accountingState.unstETHRecords[unstETHIds[i]].lockedBy = holder; - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Finalized; - _accountingState.unstETHRecords[unstETHIds[i]].shares = SharesValues.from(amountsOfShares[i]); - _accountingState.unstETHRecords[unstETHIds[i]].claimableAmount = ETHValues.from(amountsOfShares[i]); - _accountingState.unstETHRecords[unstETHIds[i]].index = IndicesOneBased.fromOneBasedValue(i + 1); - _accountingState.assets[holder].unstETHIds.push(unstETHIds[i]); + _accountingContext.unstETHRecords[unstETHIds[i]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Finalized; + _accountingContext.unstETHRecords[unstETHIds[i]].shares = SharesValues.from(amountsOfShares[i]); + _accountingContext.unstETHRecords[unstETHIds[i]].claimableAmount = ETHValues.from(amountsOfShares[i]); + _accountingContext.unstETHRecords[unstETHIds[i]].index = IndicesOneBased.fromOneBasedValue(i + 1); + _accountingContext.assets[holder].unstETHIds.push(unstETHIds[i]); expectedTotalSharesUnlockedAmount += amountsOfShares[i]; } @@ -778,23 +782,23 @@ contract AssetsAccountingUnitTests is UnitTest { ETHValues.from(expectedTotalSharesUnlockedAmount) ); - AssetsAccounting.accountUnstETHUnlock(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHUnlock(_accountingContext, holder, unstETHIds); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( SharesValues.ZERO, ETHValues.ZERO, initialTotalUnfinalizedShares, initialTotalFinalizedETH - ETHValues.from(expectedTotalSharesUnlockedAmount) ); - assert(_accountingState.assets[holder].stETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].stETHLockedShares == SharesValues.ZERO); assert( - _accountingState.assets[holder].unstETHLockedShares + _accountingContext.assets[holder].unstETHLockedShares == holderUnstETHLockedShares - SharesValues.from(expectedTotalSharesUnlockedAmount) ); - assert(_accountingState.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); - assert(_accountingState.assets[holder].unstETHIds.length == 0); + assert(_accountingContext.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); + assert(_accountingContext.assets[holder].unstETHIds.length == 0); for (uint256 i = 0; i < unstETHIds.length; ++i) { - assert(_accountingState.unstETHRecords[unstETHIds[i]].shares == SharesValues.ZERO); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].shares == SharesValues.ZERO); } } @@ -808,7 +812,7 @@ contract AssetsAccountingUnitTests is UnitTest { abi.encodeWithSelector(AssetsAccounting.InvalidUnstETHHolder.selector, unstETHIds[0], holder, address(0x0)) ); - AssetsAccounting.accountUnstETHUnlock(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHUnlock(_accountingContext, holder, unstETHIds); } function testFuzz_accountUnstETHUnlock_RevertWhen_UnstETHRecordDoesNotBelongToCurrent( @@ -819,20 +823,20 @@ contract AssetsAccountingUnitTests is UnitTest { uint256[] memory unstETHIds = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(1234); - _accountingState.unstETHRecords[unstETHIds[0]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[0]].lockedBy = holder; vm.expectRevert( abi.encodeWithSelector(AssetsAccounting.InvalidUnstETHHolder.selector, unstETHIds[0], current, holder) ); - AssetsAccounting.accountUnstETHUnlock(_accountingState, current, unstETHIds); + AssetsAccounting.accountUnstETHUnlock(_accountingContext, current, unstETHIds); } function testFuzz_accountUnstETHUnlock_RevertWhen_UnstETHRecordStatusInvalid(address holder) external { uint256[] memory unstETHIds = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(1234); - _accountingState.unstETHRecords[unstETHIds[0]].lockedBy = holder; - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.NotLocked; + _accountingContext.unstETHRecords[unstETHIds[0]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.NotLocked; vm.expectRevert( abi.encodeWithSelector( @@ -840,21 +844,21 @@ contract AssetsAccountingUnitTests is UnitTest { ) ); - AssetsAccounting.accountUnstETHUnlock(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHUnlock(_accountingContext, holder, unstETHIds); } function testFuzz_accountUnstETHUnlock_RevertWhen_UnstETHRecordIndexInvalid_OOB(address holder) external { uint256[] memory unstETHIds = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(1234); - _accountingState.unstETHRecords[unstETHIds[0]].lockedBy = holder; - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; - _accountingState.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(1234); - _accountingState.unstETHRecords[unstETHIds[0]].index = IndicesOneBased.fromOneBasedValue(10); - _accountingState.assets[holder].unstETHIds.push(unstETHIds[0]); + _accountingContext.unstETHRecords[unstETHIds[0]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(1234); + _accountingContext.unstETHRecords[unstETHIds[0]].index = IndicesOneBased.fromOneBasedValue(10); + _accountingContext.assets[holder].unstETHIds.push(unstETHIds[0]); vm.expectRevert(stdError.indexOOBError); - AssetsAccounting.accountUnstETHUnlock(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHUnlock(_accountingContext, holder, unstETHIds); } // TODO: is it expected behavior? @@ -871,81 +875,81 @@ contract AssetsAccountingUnitTests is UnitTest { ETHValue initialTotalFinalizedETH = ETHValues.from(initialTotalFinalizedETHAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; - _accountingState.unstETHTotals.finalizedETH = initialTotalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.assets[holder].unstETHLockedShares = holderUnstETHLockedShares; + _accountingContext.unstETHTotals.finalizedETH = initialTotalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; uint256[] memory unstETHIds = new uint256[](0); vm.expectEmit(); emit AssetsAccounting.UnstETHUnlocked(holder, unstETHIds, SharesValues.ZERO, ETHValues.ZERO); - AssetsAccounting.accountUnstETHUnlock(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHUnlock(_accountingContext, holder, unstETHIds); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( SharesValues.ZERO, ETHValues.ZERO, initialTotalUnfinalizedShares, initialTotalFinalizedETH ); - assert(_accountingState.assets[holder].stETHLockedShares == SharesValues.ZERO); - assert(_accountingState.assets[holder].unstETHLockedShares == holderUnstETHLockedShares); - assert(_accountingState.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); - assert(_accountingState.assets[holder].unstETHIds.length == 0); + assert(_accountingContext.assets[holder].stETHLockedShares == SharesValues.ZERO); + assert(_accountingContext.assets[holder].unstETHLockedShares == holderUnstETHLockedShares); + assert(_accountingContext.assets[holder].lastAssetsLockTimestamp == Timestamps.ZERO); + assert(_accountingContext.assets[holder].unstETHIds.length == 0); } function testFuzz_accountUnstETHUnlock_RevertOn_AccountingError_HolderUnstETHLockedSharesUnderflow(address holder) external { - _accountingState.assets[holder].unstETHLockedShares = SharesValues.from(5); + _accountingContext.assets[holder].unstETHLockedShares = SharesValues.from(5); uint256[] memory unstETHIds = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(1234); - _accountingState.unstETHRecords[unstETHIds[0]].lockedBy = holder; - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; - _accountingState.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(10); - _accountingState.unstETHRecords[unstETHIds[0]].index = IndicesOneBased.fromOneBasedValue(1); - _accountingState.assets[holder].unstETHIds.push(unstETHIds[0]); + _accountingContext.unstETHRecords[unstETHIds[0]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(10); + _accountingContext.unstETHRecords[unstETHIds[0]].index = IndicesOneBased.fromOneBasedValue(1); + _accountingContext.assets[holder].unstETHIds.push(unstETHIds[0]); vm.expectRevert(stdError.arithmeticError); - AssetsAccounting.accountUnstETHUnlock(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHUnlock(_accountingContext, holder, unstETHIds); } function testFuzz_accountUnstETHUnlock_RevertOn_AccountingError_TotalFinalizedETHUnderflow(address holder) external { - _accountingState.assets[holder].unstETHLockedShares = SharesValues.from(10); - _accountingState.unstETHTotals.finalizedETH = ETHValues.from(5); + _accountingContext.assets[holder].unstETHLockedShares = SharesValues.from(10); + _accountingContext.unstETHTotals.finalizedETH = ETHValues.from(5); uint256[] memory unstETHIds = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(1234); - _accountingState.unstETHRecords[unstETHIds[0]].lockedBy = holder; - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Finalized; - _accountingState.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(5); - _accountingState.unstETHRecords[unstETHIds[0]].index = IndicesOneBased.fromOneBasedValue(1); - _accountingState.unstETHRecords[unstETHIds[0]].claimableAmount = ETHValues.from(10); - _accountingState.assets[holder].unstETHIds.push(unstETHIds[0]); + _accountingContext.unstETHRecords[unstETHIds[0]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Finalized; + _accountingContext.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(5); + _accountingContext.unstETHRecords[unstETHIds[0]].index = IndicesOneBased.fromOneBasedValue(1); + _accountingContext.unstETHRecords[unstETHIds[0]].claimableAmount = ETHValues.from(10); + _accountingContext.assets[holder].unstETHIds.push(unstETHIds[0]); vm.expectRevert(ETHValueUnderflow.selector); - AssetsAccounting.accountUnstETHUnlock(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHUnlock(_accountingContext, holder, unstETHIds); } function testFuzz_accountUnstETHUnlock_RevertOn_AccountingError_TotalUnfinalizedSharesUnderflow(address holder) external { - _accountingState.assets[holder].unstETHLockedShares = SharesValues.from(10); - _accountingState.unstETHTotals.unfinalizedShares = SharesValues.from(5); + _accountingContext.assets[holder].unstETHLockedShares = SharesValues.from(10); + _accountingContext.unstETHTotals.unfinalizedShares = SharesValues.from(5); uint256[] memory unstETHIds = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(1234); - _accountingState.unstETHRecords[unstETHIds[0]].lockedBy = holder; - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; - _accountingState.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(10); - _accountingState.unstETHRecords[unstETHIds[0]].index = IndicesOneBased.fromOneBasedValue(1); - _accountingState.assets[holder].unstETHIds.push(unstETHIds[0]); + _accountingContext.unstETHRecords[unstETHIds[0]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(10); + _accountingContext.unstETHRecords[unstETHIds[0]].index = IndicesOneBased.fromOneBasedValue(1); + _accountingContext.assets[holder].unstETHIds.push(unstETHIds[0]); vm.expectRevert(stdError.arithmeticError); - AssetsAccounting.accountUnstETHUnlock(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHUnlock(_accountingContext, holder, unstETHIds); } // --- @@ -967,17 +971,17 @@ contract AssetsAccountingUnitTests is UnitTest { uint256 expectedTotalSharesFinalized = 0; uint256 expectedTotalAmountFinalized = 0; - _accountingState.unstETHTotals.finalizedETH = initialTotalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.unstETHTotals.finalizedETH = initialTotalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; uint256[] memory unstETHIds = new uint256[](claimableAmounts.length); uint256[] memory claimableAmountsPrepared = new uint256[](claimableAmounts.length); for (uint256 i = 0; i < claimableAmounts.length; ++i) { unstETHIds[i] = genRandomUnstEthId(i); - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Locked; uint256 sharesAmount = 5 * uint256(claimableAmounts[i]); - _accountingState.unstETHRecords[unstETHIds[i]].shares = SharesValues.from(sharesAmount); + _accountingContext.unstETHRecords[unstETHIds[i]].shares = SharesValues.from(sharesAmount); expectedTotalSharesFinalized += sharesAmount; expectedTotalAmountFinalized += claimableAmounts[i]; claimableAmountsPrepared[i] = claimableAmounts[i]; @@ -988,9 +992,9 @@ contract AssetsAccountingUnitTests is UnitTest { unstETHIds, SharesValues.from(expectedTotalSharesFinalized), ETHValues.from(expectedTotalAmountFinalized) ); - AssetsAccounting.accountUnstETHFinalized(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHFinalized(_accountingContext, unstETHIds, claimableAmountsPrepared); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( SharesValues.ZERO, ETHValues.ZERO, initialTotalUnfinalizedShares - SharesValues.from(expectedTotalSharesFinalized), @@ -1009,7 +1013,7 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectRevert(stdError.assertionError); - AssetsAccounting.accountUnstETHFinalized(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHFinalized(_accountingContext, unstETHIds, claimableAmountsPrepared); } function testFuzz_accountUnstETHFinalized_When_NoClaimableAmountsProvided( @@ -1021,8 +1025,8 @@ contract AssetsAccountingUnitTests is UnitTest { ETHValue initialTotalFinalizedETH = ETHValues.from(initialTotalFinalizedETHAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.unstETHTotals.finalizedETH = initialTotalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.unstETHTotals.finalizedETH = initialTotalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; uint256[] memory unstETHIds = new uint256[](0); uint256[] memory claimableAmountsPrepared = new uint256[](0); @@ -1030,9 +1034,9 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectEmit(); emit AssetsAccounting.UnstETHFinalized(unstETHIds, SharesValues.from(0), ETHValues.from(0)); - AssetsAccounting.accountUnstETHFinalized(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHFinalized(_accountingContext, unstETHIds, claimableAmountsPrepared); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( SharesValues.ZERO, ETHValues.ZERO, initialTotalUnfinalizedShares, initialTotalFinalizedETH ); } @@ -1047,8 +1051,8 @@ contract AssetsAccountingUnitTests is UnitTest { ETHValue initialTotalFinalizedETH = ETHValues.from(initialTotalFinalizedETHAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.unstETHTotals.finalizedETH = initialTotalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.unstETHTotals.finalizedETH = initialTotalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; uint256[] memory unstETHIds = new uint256[](1); uint256[] memory claimableAmountsPrepared = new uint256[](1); @@ -1059,9 +1063,9 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectEmit(); emit AssetsAccounting.UnstETHFinalized(unstETHIds, SharesValues.from(0), ETHValues.from(0)); - AssetsAccounting.accountUnstETHFinalized(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHFinalized(_accountingContext, unstETHIds, claimableAmountsPrepared); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( SharesValues.ZERO, ETHValues.ZERO, initialTotalUnfinalizedShares, initialTotalFinalizedETH ); } @@ -1075,23 +1079,23 @@ contract AssetsAccountingUnitTests is UnitTest { ETHValue initialTotalFinalizedETH = ETHValues.from(initialTotalFinalizedETHAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.unstETHTotals.finalizedETH = initialTotalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.unstETHTotals.finalizedETH = initialTotalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; uint256[] memory unstETHIds = new uint256[](1); uint256[] memory claimableAmountsPrepared = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(9876); - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; - _accountingState.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(123); + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(123); claimableAmountsPrepared[0] = 0; vm.expectEmit(); emit AssetsAccounting.UnstETHFinalized(unstETHIds, SharesValues.from(0), ETHValues.from(0)); - AssetsAccounting.accountUnstETHFinalized(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHFinalized(_accountingContext, unstETHIds, claimableAmountsPrepared); - checkAccountingStateTotalCounters( + checkAccountingContextTotalCounters( SharesValues.ZERO, ETHValues.ZERO, initialTotalUnfinalizedShares, initialTotalFinalizedETH ); } @@ -1105,20 +1109,20 @@ contract AssetsAccountingUnitTests is UnitTest { ETHValue initialTotalFinalizedETH = ETHValues.from(initialTotalFinalizedETHAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.unstETHTotals.finalizedETH = initialTotalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.unstETHTotals.finalizedETH = initialTotalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; uint256[] memory unstETHIds = new uint256[](1); uint256[] memory claimableAmountsPrepared = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(9876); - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; - _accountingState.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(123); + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(123); claimableAmountsPrepared[0] = uint256(type(uint128).max) + 1; vm.expectRevert(ETHValueOverflow.selector); - AssetsAccounting.accountUnstETHFinalized(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHFinalized(_accountingContext, unstETHIds, claimableAmountsPrepared); } function testFuzz_accountUnstETHFinalized_RevertOn_TotalFinalizedETHOverflow( @@ -1130,20 +1134,20 @@ contract AssetsAccountingUnitTests is UnitTest { ETHValue initialTotalFinalizedETH = ETHValues.from(initialTotalFinalizedETHAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.unstETHTotals.finalizedETH = initialTotalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.unstETHTotals.finalizedETH = initialTotalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; uint256[] memory unstETHIds = new uint256[](1); uint256[] memory claimableAmountsPrepared = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(9876); - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; - _accountingState.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(123); + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(123); claimableAmountsPrepared[0] = uint256(type(uint128).max - 2); vm.expectRevert(stdError.arithmeticError); - AssetsAccounting.accountUnstETHFinalized(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHFinalized(_accountingContext, unstETHIds, claimableAmountsPrepared); } function testFuzz_accountUnstETHFinalized_RevertOn_TotalUnfinalizedSharesUnderflow( @@ -1155,20 +1159,20 @@ contract AssetsAccountingUnitTests is UnitTest { ETHValue initialTotalFinalizedETH = ETHValues.from(initialTotalFinalizedETHAmount); SharesValue initialTotalUnfinalizedShares = SharesValues.from(initialTotalUnfinalizedSharesAmount); - _accountingState.unstETHTotals.finalizedETH = initialTotalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; + _accountingContext.unstETHTotals.finalizedETH = initialTotalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = initialTotalUnfinalizedShares; uint256[] memory unstETHIds = new uint256[](1); uint256[] memory claimableAmountsPrepared = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(9876); - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; - _accountingState.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(type(uint64).max); + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[0]].shares = SharesValues.from(type(uint64).max); claimableAmountsPrepared[0] = 1; vm.expectRevert(stdError.arithmeticError); - AssetsAccounting.accountUnstETHFinalized(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHFinalized(_accountingContext, unstETHIds, claimableAmountsPrepared); } // --- @@ -1187,7 +1191,7 @@ contract AssetsAccountingUnitTests is UnitTest { for (uint256 i = 0; i < claimableAmounts.length; ++i) { unstETHIds[i] = genRandomUnstEthId(i); - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Locked; expectedTotalAmountClaimed += claimableAmounts[i]; claimableAmountsPrepared[i] = claimableAmounts[i]; } @@ -1195,14 +1199,14 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectEmit(); emit AssetsAccounting.UnstETHClaimed(unstETHIds, ETHValues.from(expectedTotalAmountClaimed)); - AssetsAccounting.accountUnstETHClaimed(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHClaimed(_accountingContext, unstETHIds, claimableAmountsPrepared); - checkAccountingStateTotalCounters(SharesValues.ZERO, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO); + checkAccountingContextTotalCounters(SharesValues.ZERO, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO); for (uint256 i = 0; i < unstETHIds.length; ++i) { assert( - _accountingState.unstETHRecords[unstETHIds[i]].claimableAmount == ETHValues.from(claimableAmounts[i]) + _accountingContext.unstETHRecords[unstETHIds[i]].claimableAmount == ETHValues.from(claimableAmounts[i]) ); - assert(_accountingState.unstETHRecords[unstETHIds[i]].status == UnstETHRecordStatus.Claimed); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].status == UnstETHRecordStatus.Claimed); } } @@ -1218,13 +1222,13 @@ contract AssetsAccountingUnitTests is UnitTest { for (uint256 i = 0; i < claimableAmounts.length; ++i) { unstETHIds[i] = genRandomUnstEthId(i); - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Locked; claimableAmountsPrepared[i] = claimableAmounts[i]; } vm.expectRevert(stdError.indexOOBError); - AssetsAccounting.accountUnstETHClaimed(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHClaimed(_accountingContext, unstETHIds, claimableAmountsPrepared); } function test_accountUnstETHClaimed_WhenNoUnstETHIdsProvided() external { @@ -1236,9 +1240,9 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectEmit(); emit AssetsAccounting.UnstETHClaimed(unstETHIds, ETHValues.from(expectedTotalAmountClaimed)); - AssetsAccounting.accountUnstETHClaimed(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHClaimed(_accountingContext, unstETHIds, claimableAmountsPrepared); - checkAccountingStateTotalCounters(SharesValues.ZERO, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO); + checkAccountingContextTotalCounters(SharesValues.ZERO, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO); } function testFuzz_accountUnstETHClaimed_RevertWhen_UnstETHRecordNotFoundOrHasWrongStatus( @@ -1261,7 +1265,7 @@ contract AssetsAccountingUnitTests is UnitTest { ) ); - AssetsAccounting.accountUnstETHClaimed(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHClaimed(_accountingContext, unstETHIds, claimableAmountsPrepared); } function testFuzz_accountUnstETHClaimed_RevertWhen_UnstETHRecordIsFinalizedAndClaimableAmountIsIncorrect( @@ -1275,8 +1279,8 @@ contract AssetsAccountingUnitTests is UnitTest { for (uint256 i = 0; i < claimableAmounts.length; ++i) { unstETHIds[i] = genRandomUnstEthId(i); - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Finalized; - _accountingState.unstETHRecords[unstETHIds[i]].claimableAmount = + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Finalized; + _accountingContext.unstETHRecords[unstETHIds[i]].claimableAmount = ETHValues.from(uint256(claimableAmounts[i]) + 1); claimableAmountsPrepared[i] = claimableAmounts[i]; } @@ -1290,7 +1294,7 @@ contract AssetsAccountingUnitTests is UnitTest { ) ); - AssetsAccounting.accountUnstETHClaimed(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHClaimed(_accountingContext, unstETHIds, claimableAmountsPrepared); } function testFuzz_accountUnstETHClaimed_When_UnstETHRecordIsFinalizedAndClaimableAmountIsCorrect( @@ -1306,8 +1310,8 @@ contract AssetsAccountingUnitTests is UnitTest { for (uint256 i = 0; i < claimableAmounts.length; ++i) { unstETHIds[i] = genRandomUnstEthId(i); - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Finalized; - _accountingState.unstETHRecords[unstETHIds[i]].claimableAmount = ETHValues.from(claimableAmounts[i]); + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Finalized; + _accountingContext.unstETHRecords[unstETHIds[i]].claimableAmount = ETHValues.from(claimableAmounts[i]); claimableAmountsPrepared[i] = claimableAmounts[i]; expectedTotalAmountClaimed += claimableAmounts[i]; } @@ -1315,14 +1319,14 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectEmit(); emit AssetsAccounting.UnstETHClaimed(unstETHIds, ETHValues.from(expectedTotalAmountClaimed)); - AssetsAccounting.accountUnstETHClaimed(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHClaimed(_accountingContext, unstETHIds, claimableAmountsPrepared); - checkAccountingStateTotalCounters(SharesValues.ZERO, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO); + checkAccountingContextTotalCounters(SharesValues.ZERO, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO); for (uint256 i = 0; i < unstETHIds.length; ++i) { assert( - _accountingState.unstETHRecords[unstETHIds[i]].claimableAmount == ETHValues.from(claimableAmounts[i]) + _accountingContext.unstETHRecords[unstETHIds[i]].claimableAmount == ETHValues.from(claimableAmounts[i]) ); - assert(_accountingState.unstETHRecords[unstETHIds[i]].status == UnstETHRecordStatus.Claimed); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].status == UnstETHRecordStatus.Claimed); } } @@ -1331,12 +1335,12 @@ contract AssetsAccountingUnitTests is UnitTest { uint256[] memory claimableAmountsPrepared = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(1); - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Locked; claimableAmountsPrepared[0] = uint256(type(uint128).max) + 1; vm.expectRevert(ETHValueOverflow.selector); - AssetsAccounting.accountUnstETHClaimed(_accountingState, unstETHIds, claimableAmountsPrepared); + AssetsAccounting.accountUnstETHClaimed(_accountingContext, unstETHIds, claimableAmountsPrepared); } // --- @@ -1354,26 +1358,26 @@ contract AssetsAccountingUnitTests is UnitTest { for (uint256 i = 0; i < claimableAmounts.length; ++i) { unstETHIds[i] = genRandomUnstEthId(i); - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Claimed; - _accountingState.unstETHRecords[unstETHIds[i]].lockedBy = holder; - _accountingState.unstETHRecords[unstETHIds[i]].claimableAmount = ETHValues.from(claimableAmounts[i]); + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Claimed; + _accountingContext.unstETHRecords[unstETHIds[i]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[i]].claimableAmount = ETHValues.from(claimableAmounts[i]); expectedAmountWithdrawn += claimableAmounts[i]; } vm.expectEmit(); emit AssetsAccounting.UnstETHWithdrawn(unstETHIds, ETHValues.from(expectedAmountWithdrawn)); - ETHValue amountWithdrawn = AssetsAccounting.accountUnstETHWithdraw(_accountingState, holder, unstETHIds); + ETHValue amountWithdrawn = AssetsAccounting.accountUnstETHWithdraw(_accountingContext, holder, unstETHIds); assert(amountWithdrawn == ETHValues.from(expectedAmountWithdrawn)); - checkAccountingStateTotalCounters(SharesValues.ZERO, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO); + checkAccountingContextTotalCounters(SharesValues.ZERO, ETHValues.ZERO, SharesValues.ZERO, ETHValues.ZERO); for (uint256 i = 0; i < unstETHIds.length; ++i) { assert( - _accountingState.unstETHRecords[unstETHIds[i]].claimableAmount == ETHValues.from(claimableAmounts[i]) + _accountingContext.unstETHRecords[unstETHIds[i]].claimableAmount == ETHValues.from(claimableAmounts[i]) ); - assert(_accountingState.unstETHRecords[unstETHIds[i]].status == UnstETHRecordStatus.Withdrawn); - assert(_accountingState.unstETHRecords[unstETHIds[i]].lockedBy == holder); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].status == UnstETHRecordStatus.Withdrawn); + assert(_accountingContext.unstETHRecords[unstETHIds[i]].lockedBy == holder); } } @@ -1383,7 +1387,7 @@ contract AssetsAccountingUnitTests is UnitTest { vm.expectEmit(); emit AssetsAccounting.UnstETHWithdrawn(unstETHIds, ETHValues.ZERO); - ETHValue amountWithdrawn = AssetsAccounting.accountUnstETHWithdraw(_accountingState, holder, unstETHIds); + ETHValue amountWithdrawn = AssetsAccounting.accountUnstETHWithdraw(_accountingContext, holder, unstETHIds); assert(amountWithdrawn == ETHValues.ZERO); } @@ -1407,7 +1411,7 @@ contract AssetsAccountingUnitTests is UnitTest { ) ); - AssetsAccounting.accountUnstETHWithdraw(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHWithdraw(_accountingContext, holder, unstETHIds); } function testFuzz_accountUnstETHWithdraw_RevertWhen_UnstETHRecordDoesNotBelongToCurrent( @@ -1419,15 +1423,15 @@ contract AssetsAccountingUnitTests is UnitTest { uint256[] memory unstETHIds = new uint256[](1); unstETHIds[0] = genRandomUnstEthId(567); - _accountingState.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Claimed; - _accountingState.unstETHRecords[unstETHIds[0]].lockedBy = holder; - _accountingState.unstETHRecords[unstETHIds[0]].claimableAmount = ETHValues.from(123); + _accountingContext.unstETHRecords[unstETHIds[0]].status = UnstETHRecordStatus.Claimed; + _accountingContext.unstETHRecords[unstETHIds[0]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[0]].claimableAmount = ETHValues.from(123); vm.expectRevert( abi.encodeWithSelector(AssetsAccounting.InvalidUnstETHHolder.selector, unstETHIds[0], current, holder) ); - AssetsAccounting.accountUnstETHWithdraw(_accountingState, current, unstETHIds); + AssetsAccounting.accountUnstETHWithdraw(_accountingContext, current, unstETHIds); } function testFuzz_accountUnstETHWithdraw_RevertOn_WithdrawnAmountOverflow(address holder) external { @@ -1435,15 +1439,15 @@ contract AssetsAccountingUnitTests is UnitTest { for (uint256 i = 0; i < unstETHIds.length; ++i) { unstETHIds[i] = genRandomUnstEthId(i); - _accountingState.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Claimed; - _accountingState.unstETHRecords[unstETHIds[i]].lockedBy = holder; - _accountingState.unstETHRecords[unstETHIds[i]].claimableAmount = + _accountingContext.unstETHRecords[unstETHIds[i]].status = UnstETHRecordStatus.Claimed; + _accountingContext.unstETHRecords[unstETHIds[i]].lockedBy = holder; + _accountingContext.unstETHRecords[unstETHIds[i]].claimableAmount = ETHValues.from(uint256(type(uint128).max) / 2 + 1); } vm.expectRevert(stdError.arithmeticError); - AssetsAccounting.accountUnstETHWithdraw(_accountingState, holder, unstETHIds); + AssetsAccounting.accountUnstETHWithdraw(_accountingContext, holder, unstETHIds); } // --- @@ -1459,12 +1463,12 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue totalUnfinalizedShares = SharesValues.from(totalUnfinalizedSharesAmount); SharesValue totalLockedShares = SharesValues.from(totalLockedSharesAmount); - _accountingState.unstETHTotals.finalizedETH = totalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = totalUnfinalizedShares; - _accountingState.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.unstETHTotals.finalizedETH = totalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = totalUnfinalizedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; (SharesValue unfinalizedShares, ETHValue finalizedETH) = - AssetsAccounting.getLockedAssetsTotals(_accountingState); + AssetsAccounting.getLockedAssetsTotals(_accountingContext); assert(unfinalizedShares == totalLockedShares + totalUnfinalizedShares); assert(finalizedETH == totalFinalizedETH); @@ -1475,12 +1479,12 @@ contract AssetsAccountingUnitTests is UnitTest { SharesValue totalUnfinalizedShares = SharesValues.from(type(uint128).max - 1); SharesValue totalLockedShares = SharesValues.from(type(uint128).max - 1); - _accountingState.unstETHTotals.finalizedETH = totalFinalizedETH; - _accountingState.unstETHTotals.unfinalizedShares = totalUnfinalizedShares; - _accountingState.stETHTotals.lockedShares = totalLockedShares; + _accountingContext.unstETHTotals.finalizedETH = totalFinalizedETH; + _accountingContext.unstETHTotals.unfinalizedShares = totalUnfinalizedShares; + _accountingContext.stETHTotals.lockedShares = totalLockedShares; vm.expectRevert(stdError.arithmeticError); - AssetsAccounting.getLockedAssetsTotals(_accountingState); + AssetsAccounting.getLockedAssetsTotals(_accountingContext); } // --- @@ -1489,22 +1493,22 @@ contract AssetsAccountingUnitTests is UnitTest { function testFuzz_checkMinAssetsLockDurationPassed_happyPath(address holder) external { Duration minAssetsLockDuration = Durations.from(0); - _accountingState.assets[holder].lastAssetsLockTimestamp = Timestamps.from(Timestamps.now().toSeconds() - 1); + _accountingContext.assets[holder].lastAssetsLockTimestamp = Timestamps.from(Timestamps.now().toSeconds() - 1); - AssetsAccounting.checkMinAssetsLockDurationPassed(_accountingState, holder, minAssetsLockDuration); + AssetsAccounting.checkMinAssetsLockDurationPassed(_accountingContext, holder, minAssetsLockDuration); } function testFuzz_checkMinAssetsLockDurationPassed_RevertOn_MinAssetsLockDurationNotPassed(address holder) external { Duration minAssetsLockDuration = Durations.from(1); - _accountingState.assets[holder].lastAssetsLockTimestamp = Timestamps.from(Timestamps.now().toSeconds() - 1); + _accountingContext.assets[holder].lastAssetsLockTimestamp = Timestamps.from(Timestamps.now().toSeconds() - 1); vm.expectRevert( abi.encodeWithSelector(AssetsAccounting.MinAssetsLockDurationNotPassed.selector, Timestamps.now()) ); - AssetsAccounting.checkMinAssetsLockDurationPassed(_accountingState, holder, minAssetsLockDuration); + AssetsAccounting.checkMinAssetsLockDurationPassed(_accountingContext, holder, minAssetsLockDuration); } // --- @@ -1515,15 +1519,15 @@ contract AssetsAccountingUnitTests is UnitTest { return uint256(keccak256(abi.encodePacked(block.timestamp, salt))); // random id } - function checkAccountingStateTotalCounters( + function checkAccountingContextTotalCounters( SharesValue lockedShares, ETHValue claimedETH, SharesValue unfinalizedShares, ETHValue finalizedETH ) internal view { - assert(_accountingState.stETHTotals.lockedShares == lockedShares); - assert(_accountingState.stETHTotals.claimedETH == claimedETH); - assert(_accountingState.unstETHTotals.unfinalizedShares == unfinalizedShares); - assert(_accountingState.unstETHTotals.finalizedETH == finalizedETH); + assert(_accountingContext.stETHTotals.lockedShares == lockedShares); + assert(_accountingContext.stETHTotals.claimedETH == claimedETH); + assert(_accountingContext.unstETHTotals.unfinalizedShares == unfinalizedShares); + assert(_accountingContext.unstETHTotals.finalizedETH == finalizedETH); } }