From fa1b1af142a88e536443a255f0633738e474e907 Mon Sep 17 00:00:00 2001 From: andreivladbrg Date: Thu, 10 Oct 2024 14:26:15 +0300 Subject: [PATCH] fix: use uint256 for scaledOngoingDebt fix: add notNull in isTransferable getter fix: use uint256 in depletionTimeOf --- src/SablierFlow.sol | 58 ++++++++++--------- src/abstracts/SablierFlowBase.sol | 2 +- src/interfaces/ISablierFlow.sol | 16 ++--- tests/fork/Flow.t.sol | 18 +++--- tests/integration/concrete/batch/batch.t.sol | 4 +- .../depletion-time-of/depletionTimeOf.t.sol | 6 +- .../deposit-and-pause/depositAndPause.t.sol | 2 +- .../ongoing-debt-of/ongoingDebtOf.t.sol | 6 +- tests/integration/concrete/pause/pause.t.sol | 2 +- .../refund-and-pause/refundAndPause.t.sol | 2 +- .../concrete/total-debt-of/totalDebtOf.t.sol | 8 +-- .../uncovered-debt-of/uncoveredDebtOf.t.sol | 6 +- tests/integration/concrete/void/void.t.sol | 4 +- .../withdraw-delay/withdrawDelay.t.sol | 4 +- .../concrete/withdraw/withdraw.t.sol | 8 +-- .../fuzz/adjustRatePerSecond.t.sol | 4 +- tests/integration/fuzz/coveredDebtOf.t.sol | 6 +- tests/integration/fuzz/depletionTimeOf.t.sol | 2 +- tests/integration/fuzz/ongoingDebtOf.t.sol | 10 ++-- tests/integration/fuzz/pause.t.sol | 2 +- tests/integration/fuzz/refund.t.sol | 4 +- .../integration/fuzz/refundableAmountOf.t.sol | 6 +- tests/integration/fuzz/totalDebtOf.t.sol | 6 +- tests/integration/fuzz/uncoveredDebtOf.t.sol | 10 ++-- tests/integration/fuzz/void.t.sol | 10 ++-- tests/integration/fuzz/withdraw.t.sol | 10 ++-- tests/integration/fuzz/withdrawMax.t.sol | 8 +-- tests/invariant/Flow.t.sol | 2 +- .../invariant/handlers/FlowCreateHandler.sol | 4 +- tests/invariant/handlers/FlowHandler.sol | 2 +- tests/invariant/stores/FlowStore.sol | 18 +++--- 31 files changed, 128 insertions(+), 122 deletions(-) diff --git a/src/SablierFlow.sol b/src/SablierFlow.sol index 1dac8e67..70091330 100644 --- a/src/SablierFlow.sol +++ b/src/SablierFlow.sol @@ -60,7 +60,7 @@ contract SablierFlow is override notNull(streamId) notPaused(streamId) - returns (uint40 depletionTime) + returns (uint256 depletionTime) { uint128 balance = _streams[streamId].balance; @@ -76,8 +76,8 @@ contract SablierFlow is return 0; } - uint8 tokenDecimals = _streams[streamId].tokenDecimals; - uint128 solvencyAmount; + uint256 tokenDecimals = _streams[streamId].tokenDecimals; + uint256 solvencyAmount; // Depletion time is defined as the UNIX timestamp beyond which the total debt exceeds stream balance. // So we calculate it by solving: debt at depletion time = stream balance + 1. This ensures that we find the @@ -87,16 +87,16 @@ contract SablierFlow is if (tokenDecimals == 18) { solvencyAmount = (balance - snapshotDebt + 1); } else { - uint128 scaleFactor = (10 ** (18 - tokenDecimals)).toUint128(); + uint256 scaleFactor = (10 ** (18 - tokenDecimals)); solvencyAmount = (balance - snapshotDebt + 1) * scaleFactor; } uint256 solvencyPeriod = solvencyAmount / _streams[streamId].ratePerSecond.unwrap(); - return _streams[streamId].snapshotTime + solvencyPeriod.toUint40(); + return _streams[streamId].snapshotTime + solvencyPeriod; } } /// @inheritdoc ISablierFlow - function ongoingDebtOf(uint256 streamId) external view override notNull(streamId) returns (uint128 ongoingDebt) { + function ongoingDebtOf(uint256 streamId) external view override notNull(streamId) returns (uint256 ongoingDebt) { ongoingDebt = _ongoingDebtOf(streamId); } @@ -141,7 +141,7 @@ contract SablierFlow is } /// @inheritdoc ISablierFlow - function totalDebtOf(uint256 streamId) external view override notNull(streamId) returns (uint128 totalDebt) { + function totalDebtOf(uint256 streamId) external view override notNull(streamId) returns (uint256 totalDebt) { totalDebt = _totalDebtOf(streamId); } @@ -151,7 +151,7 @@ contract SablierFlow is view override notNull(streamId) - returns (uint128 uncoveredDebt) + returns (uint256 uncoveredDebt) { uncoveredDebt = _uncoveredDebtOf(streamId); } @@ -437,30 +437,31 @@ contract SablierFlow is return 0; } - uint128 totalDebt = _totalDebtOf(streamId); + uint256 totalDebt = _totalDebtOf(streamId); // If the stream balance is less than or equal to the total debt, return the stream balance. if (balance < totalDebt) { return balance; } - return totalDebt; + // At this point, the total debt fits within `uint128`, as it is less than or equal to the balance. + return totalDebt.toUint128(); } /// @dev Calculates the ongoing debt accrued since last snapshot. Return 0 if the stream is paused or /// `block.timestamp` is less than or equal to snapshot time. - function _ongoingDebtOf(uint256 streamId) internal view returns (uint128 ongoingDebt) { + function _ongoingDebtOf(uint256 streamId) internal view returns (uint256 ongoingDebt) { uint40 blockTimestamp = uint40(block.timestamp); uint40 snapshotTime = _streams[streamId].snapshotTime; - uint128 ratePerSecond = _streams[streamId].ratePerSecond.unwrap(); + uint256 ratePerSecond = _streams[streamId].ratePerSecond.unwrap(); // Check:if the rate per second is zero or the `block.timestamp` is less than the `snapshotTime`. if (ratePerSecond == 0 || blockTimestamp <= snapshotTime) { return 0; } - uint128 elapsedTime; + uint256 elapsedTime; // Safe to use unchecked because subtraction cannot underflow. unchecked { @@ -468,10 +469,10 @@ contract SablierFlow is elapsedTime = blockTimestamp - snapshotTime; } - uint8 tokenDecimals = _streams[streamId].tokenDecimals; - // Calculate the ongoing debt accrued by multiplying the elapsed time by the rate per second. - uint128 scaledOngoingDebt = elapsedTime * ratePerSecond; + uint256 scaledOngoingDebt = elapsedTime * ratePerSecond; + + uint8 tokenDecimals = _streams[streamId].tokenDecimals; // If the token decimals are 18, return the scaled ongoing debt and the `block.timestamp`. if (tokenDecimals == 18) { @@ -480,7 +481,7 @@ contract SablierFlow is // Safe to use unchecked because we use {SafeCast}. unchecked { - uint128 scaleFactor = (10 ** (18 - tokenDecimals)).toUint128(); + uint256 scaleFactor = 10 ** (18 - tokenDecimals); // Since debt is denoted in token decimals, descale the amount. ongoingDebt = scaledOngoingDebt / scaleFactor; } @@ -494,16 +495,16 @@ contract SablierFlow is /// @notice Calculates the total debt. /// @dev The total debt is the sum of the snapshot debt and the ongoing debt. This value is independent of the /// stream's balance. - function _totalDebtOf(uint256 streamId) internal view returns (uint128) { + function _totalDebtOf(uint256 streamId) internal view returns (uint256) { // Calculate the total debt. return _streams[streamId].snapshotDebt + _ongoingDebtOf(streamId); } /// @dev Calculates the uncovered debt. - function _uncoveredDebtOf(uint256 streamId) internal view returns (uint128) { + function _uncoveredDebtOf(uint256 streamId) internal view returns (uint256) { uint128 balance = _streams[streamId].balance; - uint128 totalDebt = _totalDebtOf(streamId); + uint256 totalDebt = _totalDebtOf(streamId); if (balance < totalDebt) { return totalDebt - balance; @@ -523,7 +524,7 @@ contract SablierFlow is revert Errors.SablierFlow_RatePerSecondNotDifferent(streamId, newRatePerSecond); } - uint128 ongoingDebt = _ongoingDebtOf(streamId); + uint128 ongoingDebt = _ongoingDebtOf(streamId).toUint128(); // Update the snapshot debt only if the stream has ongoing debt. if (ongoingDebt > 0) { @@ -709,11 +710,12 @@ contract SablierFlow is revert Errors.SablierFlow_Unauthorized({ streamId: streamId, caller: msg.sender }); } - uint128 debtToWriteOff = _uncoveredDebtOf(streamId); + uint256 debtToWriteOff = _uncoveredDebtOf(streamId); // If the stream is solvent, update the total debt normally. if (debtToWriteOff == 0) { - uint128 ongoingDebt = _ongoingDebtOf(streamId); + // It is safe to downcast because if there is no uncovered debt, the ongoing debt fits within `uint128`. + uint128 ongoingDebt = _ongoingDebtOf(streamId).toUint128(); if (ongoingDebt > 0) { // Effect: Update the snapshot debt by adding the ongoing debt. _streams[streamId].snapshotDebt += ongoingDebt; @@ -764,7 +766,8 @@ contract SablierFlow is } // Calculate the total debt. - uint128 totalDebt = _totalDebtOf(streamId); + uint256 totalDebt = _totalDebtOf(streamId); + uint128 totalDebtU128; // Calculate the withdrawable amount. uint128 balance = _streams[streamId].balance; @@ -774,8 +777,11 @@ contract SablierFlow is // If the stream balance is less than the total debt, the withdrawable amount is the balance. withdrawableAmount = balance; } else { + // If the balance is greater than or equal to the total debt, it should fit within `uint128`. + totalDebtU128 = totalDebt.toUint128(); + // Otherwise, the withdrawable amount is the total debt. - withdrawableAmount = totalDebt; + withdrawableAmount = totalDebtU128; } // Check: the withdraw amount is not greater than the withdrawable amount. @@ -793,7 +799,7 @@ contract SablierFlow is // Else reduce the amount from the ongoing debt by setting snapshot time to `block.timestamp` and set the // snapshot debt to the remaining total debt. else { - _streams[streamId].snapshotDebt = totalDebt - amount; + _streams[streamId].snapshotDebt = totalDebtU128 - amount; // Effect: update the stream time. _streams[streamId].snapshotTime = uint40(block.timestamp); diff --git a/src/abstracts/SablierFlowBase.sol b/src/abstracts/SablierFlowBase.sol index f498fbe5..6c47446d 100644 --- a/src/abstracts/SablierFlowBase.sol +++ b/src/abstracts/SablierFlowBase.sol @@ -181,7 +181,7 @@ abstract contract SablierFlowBase is } /// @inheritdoc ISablierFlowBase - function isTransferable(uint256 streamId) external view override returns (bool result) { + function isTransferable(uint256 streamId) external view override notNull(streamId) returns (bool result) { result = _streams[streamId].isTransferable; } diff --git a/src/interfaces/ISablierFlow.sol b/src/interfaces/ISablierFlow.sol index 35a372ba..828cc55e 100644 --- a/src/interfaces/ISablierFlow.sol +++ b/src/interfaces/ISablierFlow.sol @@ -24,7 +24,7 @@ interface ISablierFlow is /// @param newRatePerSecond The new rate per second, denoted as a fixed-point number where 1e18 is 1 token /// per second. event AdjustFlowStream( - uint256 indexed streamId, uint128 totalDebt, UD21x18 oldRatePerSecond, UD21x18 newRatePerSecond + uint256 indexed streamId, uint256 totalDebt, UD21x18 oldRatePerSecond, UD21x18 newRatePerSecond ); /// @notice Emitted when a Flow stream is created. @@ -56,7 +56,7 @@ interface ISablierFlow is /// @param recipient The address of the stream's recipient. /// @param totalDebt The amount of tokens owed by the sender to the recipient, denoted in token's decimals. event PauseFlowStream( - uint256 indexed streamId, address indexed sender, address indexed recipient, uint128 totalDebt + uint256 indexed streamId, address indexed sender, address indexed recipient, uint256 totalDebt ); /// @notice Emitted when a sender is refunded from a stream. @@ -84,8 +84,8 @@ interface ISablierFlow is address indexed sender, address indexed recipient, address caller, - uint128 newTotalDebt, - uint128 writtenOffDebt + uint256 newTotalDebt, + uint256 writtenOffDebt ); /// @notice Emitted when tokens are withdrawn from a stream by a recipient or an approved operator. @@ -119,12 +119,12 @@ interface ISablierFlow is /// there already is uncovered debt, it returns zero. /// @dev Reverts if `streamId` references a paused or a null stream. /// @param streamId The stream ID for the query. - function depletionTimeOf(uint256 streamId) external view returns (uint40 depletionTime); + function depletionTimeOf(uint256 streamId) external view returns (uint256 depletionTime); /// @notice Returns the amount of debt accrued since the snapshot time until now, denoted in token's decimals. /// @dev Reverts if `streamId` references a null stream. /// @param streamId The stream ID for the query. - function ongoingDebtOf(uint256 streamId) external view returns (uint128 ongoingDebt); + function ongoingDebtOf(uint256 streamId) external view returns (uint256 ongoingDebt); /// @notice Returns the amount that the sender can be refunded from the stream, denoted in token's decimals. /// @dev Reverts if `streamId` references a null stream. @@ -139,12 +139,12 @@ interface ISablierFlow is /// @notice Returns the total amount owed by the sender to the recipient, denoted in token's decimals. /// @dev Reverts if `streamId` references a null stream. /// @param streamId The stream ID for the query. - function totalDebtOf(uint256 streamId) external view returns (uint128 totalDebt); + function totalDebtOf(uint256 streamId) external view returns (uint256 totalDebt); /// @notice Returns the amount of debt not covered by the stream balance, denoted in token's decimals. /// @dev Reverts if `streamId` references a null stream. /// @param streamId The stream ID for the query. - function uncoveredDebtOf(uint256 streamId) external view returns (uint128 uncoveredDebt); + function uncoveredDebtOf(uint256 streamId) external view returns (uint256 uncoveredDebt); /// @notice Calculates the amount that the recipient can withdraw from the stream, denoted in token decimals. This /// is an alias for `coveredDebtOf`. diff --git a/tests/fork/Flow.t.sol b/tests/fork/Flow.t.sol index beaaf4c4..95ab48e1 100644 --- a/tests/fork/Flow.t.sol +++ b/tests/fork/Flow.t.sol @@ -53,7 +53,7 @@ contract Flow_Fork_Test is Fork_Test { uint128 actualStreamBalance; uint256 actualStreamId; uint256 actualTokenBalance; - uint128 actualTotalDebt; + uint256 actualTotalDebt; // Expected values. uint256 expectedAggregateAmount; UD21x18 expectedRatePerSecond; @@ -62,7 +62,7 @@ contract Flow_Fork_Test is Fork_Test { uint128 expectedStreamBalance; uint256 expectedStreamId; uint256 expectedTokenBalance; - uint128 expectedTotalDebt; + uint256 expectedTotalDebt; } /*////////////////////////////////////////////////////////////////////////// @@ -252,8 +252,8 @@ contract Flow_Fork_Test is Fork_Test { } uint128 beforeSnapshotAmount = flow.getSnapshotDebt(streamId); - uint128 totalDebt = flow.totalDebtOf(streamId); - uint128 ongoingDebt = flow.ongoingDebtOf(streamId); + uint256 totalDebt = flow.totalDebtOf(streamId); + uint256 ongoingDebt = flow.ongoingDebtOf(streamId); // Compute the snapshot time that will be stored post withdraw. vars.expectedSnapshotTime = getBlockTimestamp(); @@ -274,7 +274,7 @@ contract Flow_Fork_Test is Fork_Test { // It should update snapshot debt. vars.actualSnapshotDebt = flow.getSnapshotDebt(streamId); - vars.expectedSnapshotDebt = ongoingDebt + beforeSnapshotAmount; + vars.expectedSnapshotDebt = uint128(ongoingDebt) + beforeSnapshotAmount; assertEq(vars.actualSnapshotDebt, vars.expectedSnapshotDebt, "AdjustRatePerSecond: snapshot debt"); // It should set the new rate per second @@ -443,7 +443,7 @@ contract Flow_Fork_Test is Fork_Test { // If the refundable amount less than 1, deposit some funds. if (flow.refundableAmountOf(streamId) <= 1) { uint128 depositAmount = - flow.uncoveredDebtOf(streamId) + getDefaultDepositAmount(flow.getTokenDecimals(streamId)); + uint128(flow.uncoveredDebtOf(streamId)) + getDefaultDepositAmount(flow.getTokenDecimals(streamId)); depositOnStream(streamId, depositAmount); } @@ -527,8 +527,8 @@ contract Flow_Fork_Test is Fork_Test { // Make sure the requirements are respected. address sender = flow.getSender(streamId); address recipient = flow.getRecipient(streamId); - uint128 uncoveredDebt = flow.uncoveredDebtOf(streamId); - uint128 expectedTotalDebt; + uint256 uncoveredDebt = flow.uncoveredDebtOf(streamId); + uint256 expectedTotalDebt; resetPrank({ msgSender: sender }); @@ -583,7 +583,7 @@ contract Flow_Fork_Test is Fork_Test { ); uint256 initialTokenBalance = token.balanceOf(address(flow)); - uint128 totalDebt = flow.totalDebtOf(streamId); + uint256 totalDebt = flow.totalDebtOf(streamId); vars.expectedSnapshotTime = withdrawAmount <= flow.getSnapshotDebt(streamId) ? flow.getSnapshotTime(streamId) : getBlockTimestamp(); diff --git a/tests/integration/concrete/batch/batch.t.sol b/tests/integration/concrete/batch/batch.t.sol index c3565c84..362fc109 100644 --- a/tests/integration/concrete/batch/batch.t.sol +++ b/tests/integration/concrete/batch/batch.t.sol @@ -227,8 +227,8 @@ contract Batch_Integration_Concrete_Test is Integration_Test { calls[0] = abi.encodeCall(flow.pause, (defaultStreamIds[0])); calls[1] = abi.encodeCall(flow.pause, (defaultStreamIds[1])); - uint128 previousTotalDebt0 = flow.totalDebtOf(defaultStreamId); - uint128 previousTotalDebt1 = flow.totalDebtOf(defaultStreamIds[1]); + uint256 previousTotalDebt0 = flow.totalDebtOf(defaultStreamId); + uint256 previousTotalDebt1 = flow.totalDebtOf(defaultStreamIds[1]); // It should emit 2 {PauseFlowStream}, 2 {MetadataUpdate} events. diff --git a/tests/integration/concrete/depletion-time-of/depletionTimeOf.t.sol b/tests/integration/concrete/depletion-time-of/depletionTimeOf.t.sol index f6ee0e92..e1723f89 100644 --- a/tests/integration/concrete/depletion-time-of/depletionTimeOf.t.sol +++ b/tests/integration/concrete/depletion-time-of/depletionTimeOf.t.sol @@ -16,20 +16,20 @@ contract DepletionTimeOf_Integration_Concrete_Test is Integration_Test { function test_GivenBalanceZero() external view givenNotNull givenNotPaused { // It should return 0 - uint40 depletionTime = flow.depletionTimeOf(defaultStreamId); + uint40 depletionTime = uint40(flow.depletionTimeOf(defaultStreamId)); assertEq(depletionTime, 0, "depletion time"); } function test_GivenUncoveredDebt() external givenNotNull givenNotPaused givenBalanceNotZero { vm.warp({ newTimestamp: WARP_SOLVENCY_PERIOD }); // It should return 0 - uint40 depletionTime = flow.depletionTimeOf(defaultStreamId); + uint40 depletionTime = uint40(flow.depletionTimeOf(defaultStreamId)); assertEq(depletionTime, 0, "depletion time"); } function test_GivenNoUncoveredDebt() external givenNotNull givenNotPaused givenBalanceNotZero { // It should return the time at which the stream depletes its balance - uint40 depletionTime = flow.depletionTimeOf(defaultStreamId); + uint40 depletionTime = uint40(flow.depletionTimeOf(defaultStreamId)); assertEq(depletionTime, WARP_SOLVENCY_PERIOD, "depletion time"); } } diff --git a/tests/integration/concrete/deposit-and-pause/depositAndPause.t.sol b/tests/integration/concrete/deposit-and-pause/depositAndPause.t.sol index 489c8e11..f088260c 100644 --- a/tests/integration/concrete/deposit-and-pause/depositAndPause.t.sol +++ b/tests/integration/concrete/deposit-and-pause/depositAndPause.t.sol @@ -56,7 +56,7 @@ contract DepositAndPause_Integration_Concrete_Test is Integration_Test { function test_WhenCallerSender() external whenNoDelegateCall givenNotNull givenNotPaused { uint128 previousStreamBalance = flow.getBalance(defaultStreamId); - uint128 previousTotalDebt = flow.totalDebtOf(defaultStreamId); + uint256 previousTotalDebt = flow.totalDebtOf(defaultStreamId); // It should emit 1 {Transfer}, 1 {DepositFlowStream}, 1 {PauseFlowStream}, 1 {MetadataUpdate} events vm.expectEmit({ emitter: address(usdc) }); diff --git a/tests/integration/concrete/ongoing-debt-of/ongoingDebtOf.t.sol b/tests/integration/concrete/ongoing-debt-of/ongoingDebtOf.t.sol index 20642b86..c5c25a92 100644 --- a/tests/integration/concrete/ongoing-debt-of/ongoingDebtOf.t.sol +++ b/tests/integration/concrete/ongoing-debt-of/ongoingDebtOf.t.sol @@ -13,7 +13,7 @@ contract OngoingDebtOf_Integration_Concrete_Test is Integration_Test { flow.pause(defaultStreamId); // It should return zero. - uint128 ongoingDebt = flow.ongoingDebtOf(defaultStreamId); + uint256 ongoingDebt = flow.ongoingDebtOf(defaultStreamId); assertEq(ongoingDebt, 0, "ongoing debt"); } @@ -22,13 +22,13 @@ contract OngoingDebtOf_Integration_Concrete_Test is Integration_Test { updateSnapshotTimeAndWarp(defaultStreamId); // It should return zero. - uint128 ongoingDebt = flow.ongoingDebtOf(defaultStreamId); + uint256 ongoingDebt = flow.ongoingDebtOf(defaultStreamId); assertEq(ongoingDebt, 0, "ongoing debt"); } function test_WhenSnapshotTimeInPast() external view givenNotNull givenNotPaused { // It should return the correct ongoing debt. - uint128 ongoingDebt = flow.ongoingDebtOf(defaultStreamId); + uint256 ongoingDebt = flow.ongoingDebtOf(defaultStreamId); assertEq(ongoingDebt, ONE_MONTH_DEBT_6D, "ongoing debt"); } } diff --git a/tests/integration/concrete/pause/pause.t.sol b/tests/integration/concrete/pause/pause.t.sol index fb9331f2..af02f9b4 100644 --- a/tests/integration/concrete/pause/pause.t.sol +++ b/tests/integration/concrete/pause/pause.t.sol @@ -66,7 +66,7 @@ contract Pause_Integration_Concrete_Test is Integration_Test { } function test_Pause() internal { - uint128 initialTotalDebt = flow.totalDebtOf(defaultStreamId); + uint256 initialTotalDebt = flow.totalDebtOf(defaultStreamId); // It should emit 1 {PauseFlowStream}, 1 {MetadataUpdate} events. vm.expectEmit({ emitter: address(flow) }); diff --git a/tests/integration/concrete/refund-and-pause/refundAndPause.t.sol b/tests/integration/concrete/refund-and-pause/refundAndPause.t.sol index 242c336f..9e55706a 100644 --- a/tests/integration/concrete/refund-and-pause/refundAndPause.t.sol +++ b/tests/integration/concrete/refund-and-pause/refundAndPause.t.sol @@ -54,7 +54,7 @@ contract RefundAndPause_Integration_Concrete_Test is Integration_Test { } function test_WhenCallerSender() external whenNoDelegateCall givenNotNull givenNotPaused { - uint128 previousTotalDebt = flow.totalDebtOf(defaultStreamId); + uint256 previousTotalDebt = flow.totalDebtOf(defaultStreamId); // It should emit 1 {Transfer}, 1 {RefundFromFlowStream}, 1 {PauseFlowStream}, 1 {MetadataUpdate} events vm.expectEmit({ emitter: address(usdc) }); diff --git a/tests/integration/concrete/total-debt-of/totalDebtOf.t.sol b/tests/integration/concrete/total-debt-of/totalDebtOf.t.sol index b5b50ba5..94af65d2 100644 --- a/tests/integration/concrete/total-debt-of/totalDebtOf.t.sol +++ b/tests/integration/concrete/total-debt-of/totalDebtOf.t.sol @@ -15,7 +15,7 @@ contract TotalDebtOf_Integration_Concrete_Test is Integration_Test { flow.pause(defaultStreamId); uint128 snapshotDebt = flow.getSnapshotDebt(defaultStreamId); - uint128 totalDebt = flow.totalDebtOf(defaultStreamId); + uint256 totalDebt = flow.totalDebtOf(defaultStreamId); assertEq(totalDebt, snapshotDebt, "total debt"); } @@ -25,15 +25,15 @@ contract TotalDebtOf_Integration_Concrete_Test is Integration_Test { flow.adjustRatePerSecond(defaultStreamId, ud21x18(RATE_PER_SECOND_U128 * 2)); uint128 snapshotDebt = flow.getSnapshotDebt(defaultStreamId); - uint128 totalDebt = flow.totalDebtOf(defaultStreamId); + uint256 totalDebt = flow.totalDebtOf(defaultStreamId); assertEq(totalDebt, snapshotDebt, "total debt"); } function test_WhenCurrentTimeGreaterThanSnapshotTime() external view givenNotNull givenNotPaused { uint128 snapshotDebt = flow.getSnapshotDebt(defaultStreamId); - uint128 ongoingDebt = flow.ongoingDebtOf(defaultStreamId); - uint128 totalDebt = flow.totalDebtOf(defaultStreamId); + uint256 ongoingDebt = flow.ongoingDebtOf(defaultStreamId); + uint256 totalDebt = flow.totalDebtOf(defaultStreamId); assertEq(snapshotDebt + ongoingDebt, totalDebt, "total debt"); } diff --git a/tests/integration/concrete/uncovered-debt-of/uncoveredDebtOf.t.sol b/tests/integration/concrete/uncovered-debt-of/uncoveredDebtOf.t.sol index 2ac128db..ad8dff0a 100644 --- a/tests/integration/concrete/uncovered-debt-of/uncoveredDebtOf.t.sol +++ b/tests/integration/concrete/uncovered-debt-of/uncoveredDebtOf.t.sol @@ -18,7 +18,7 @@ contract UncoveredDebtOf_Integration_Concrete_Test is Integration_Test { function test_WhenTotalDebtNotExceedBalance() external view givenNotNull { // It should return zero. - uint128 actualUncoveredDebt = flow.uncoveredDebtOf(defaultStreamId); + uint256 actualUncoveredDebt = flow.uncoveredDebtOf(defaultStreamId); assertEq(actualUncoveredDebt, 0, "uncovered debt"); } @@ -29,8 +29,8 @@ contract UncoveredDebtOf_Integration_Concrete_Test is Integration_Test { uint128 totalStreamed = getDescaledAmount(RATE_PER_SECOND_U128 * (SOLVENCY_PERIOD + ONE_MONTH), 6); // It should return non-zero value. - uint128 actualUncoveredDebt = flow.uncoveredDebtOf(defaultStreamId); - uint128 expectedUncoveredDebt = totalStreamed - DEPOSIT_AMOUNT_6D; + uint256 actualUncoveredDebt = flow.uncoveredDebtOf(defaultStreamId); + uint256 expectedUncoveredDebt = totalStreamed - DEPOSIT_AMOUNT_6D; assertEq(actualUncoveredDebt, expectedUncoveredDebt, "uncovered debt"); } } diff --git a/tests/integration/concrete/void/void.t.sol b/tests/integration/concrete/void/void.t.sol index 6fd1483f..44ca1ff3 100644 --- a/tests/integration/concrete/void/void.t.sol +++ b/tests/integration/concrete/void/void.t.sol @@ -110,8 +110,8 @@ contract Void_Integration_Concrete_Test is Integration_Test { } function _test_Void(address caller) private { - uint128 expectedTotalDebt; - uint128 uncoveredDebt = flow.uncoveredDebtOf(defaultStreamId); + uint256 expectedTotalDebt; + uint256 uncoveredDebt = flow.uncoveredDebtOf(defaultStreamId); if (uncoveredDebt > 0) { // Expect the total debt to be stream balance if there is uncovered debt. diff --git a/tests/integration/concrete/withdraw-delay/withdrawDelay.t.sol b/tests/integration/concrete/withdraw-delay/withdrawDelay.t.sol index a909ae5f..39375853 100644 --- a/tests/integration/concrete/withdraw-delay/withdrawDelay.t.sol +++ b/tests/integration/concrete/withdraw-delay/withdrawDelay.t.sol @@ -96,9 +96,9 @@ contract WithdrawDelay_Integration_Concrete_Test is Integration_Test { vm.warp(getBlockTimestamp() + 1 days - 10); // Find the time when the ongoing debt has increased by 38 - uint128 diff; + uint256 diff; while (diff != 39) { - uint128 beforeWarpOd = flow.ongoingDebtOf(streamId); + uint256 beforeWarpOd = flow.ongoingDebtOf(streamId); vm.warp(getBlockTimestamp() + 1 seconds); diff = flow.ongoingDebtOf(streamId) - beforeWarpOd; } diff --git a/tests/integration/concrete/withdraw/withdraw.t.sol b/tests/integration/concrete/withdraw/withdraw.t.sol index c64a4892..86940e9f 100644 --- a/tests/integration/concrete/withdraw/withdraw.t.sol +++ b/tests/integration/concrete/withdraw/withdraw.t.sol @@ -103,7 +103,7 @@ contract Withdraw_Integration_Concrete_Test is Integration_Test { whenAmountOverdraws { // Warp to the moment when stream accumulates uncovered debt. - vm.warp({ newTimestamp: flow.depletionTimeOf(defaultStreamId) }); + vm.warp({ newTimestamp: uint40(flow.depletionTimeOf(defaultStreamId)) }); uint128 overdrawAmount = flow.getBalance(defaultStreamId) + 1; vm.expectRevert( @@ -148,7 +148,7 @@ contract Withdraw_Integration_Concrete_Test is Integration_Test { to: users.recipient, depositAmount: DEPOSIT_AMOUNT_6D, feeAmount: 0, - withdrawAmount: flow.totalDebtOf(defaultStreamId) - 1 + withdrawAmount: uint128(flow.totalDebtOf(defaultStreamId)) - 1 }); } @@ -267,12 +267,12 @@ contract Withdraw_Integration_Concrete_Test is Integration_Test { struct Vars { IERC20 token; uint40 previousSnapshotTime; - uint128 previousTotalDebt; + uint256 previousTotalDebt; uint256 previousAggregateAmount; uint128 expectedProtocolRevenue; uint256 initialTokenBalance; uint40 expectedSnapshotTime; - uint128 expectedTotalDebt; + uint256 expectedTotalDebt; uint128 expectedStreamBalance; uint256 expectedTokenBalance; } diff --git a/tests/integration/fuzz/adjustRatePerSecond.t.sol b/tests/integration/fuzz/adjustRatePerSecond.t.sol index 5744c826..d7d43203 100644 --- a/tests/integration/fuzz/adjustRatePerSecond.t.sol +++ b/tests/integration/fuzz/adjustRatePerSecond.t.sol @@ -39,7 +39,7 @@ contract AdjustRatePerSecond_Integration_Fuzz_Test is Shared_Integration_Fuzz_Te // Simulate the passage of time. vm.warp({ newTimestamp: getBlockTimestamp() + timeJump }); - uint128 previousTotalDebt = flow.totalDebtOf(streamId); + uint256 previousTotalDebt = flow.totalDebtOf(streamId); // Expect the relevant error. vm.expectRevert(abi.encodeWithSelector(Errors.SablierFlow_StreamPaused.selector, streamId)); @@ -81,7 +81,7 @@ contract AdjustRatePerSecond_Integration_Fuzz_Test is Shared_Integration_Fuzz_Te // Simulate the passage of time. vm.warp({ newTimestamp: getBlockTimestamp() + timeJump }); - uint128 previousTotalDebt = flow.totalDebtOf(streamId); + uint256 previousTotalDebt = flow.totalDebtOf(streamId); UD21x18 currentRatePerSecond = flow.getRatePerSecond(streamId); if (newRatePerSecond.unwrap() == currentRatePerSecond.unwrap()) { diff --git a/tests/integration/fuzz/coveredDebtOf.t.sol b/tests/integration/fuzz/coveredDebtOf.t.sol index 66393cec..a7871656 100644 --- a/tests/integration/fuzz/coveredDebtOf.t.sol +++ b/tests/integration/fuzz/coveredDebtOf.t.sol @@ -20,7 +20,7 @@ contract CoveredDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { (streamId,,) = useFuzzedStreamOrCreate(streamId, decimals); // Bound the time jump so that it is less than the depletion timestamp. - warpTimestamp = boundUint40(warpTimestamp, getBlockTimestamp(), flow.depletionTimeOf(streamId) - 1); + warpTimestamp = boundUint40(warpTimestamp, getBlockTimestamp(), uint40(flow.depletionTimeOf(streamId)) - 1); // Simulate the passage of time. vm.warp({ newTimestamp: warpTimestamp }); @@ -55,7 +55,7 @@ contract CoveredDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { (streamId, decimals,) = useFuzzedStreamOrCreate(streamId, decimals); // Bound the time jump so that it is less than the depletion timestamp. - warpTimestamp = boundUint40(warpTimestamp, getBlockTimestamp(), flow.depletionTimeOf(streamId) - 1); + warpTimestamp = boundUint40(warpTimestamp, getBlockTimestamp(), uint40(flow.depletionTimeOf(streamId)) - 1); // Simulate the passage of time. vm.warp({ newTimestamp: warpTimestamp }); @@ -78,7 +78,7 @@ contract CoveredDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { (streamId,, depositedAmount) = useFuzzedStreamOrCreate(streamId, decimals); // Bound the time jump so it is greater than depletion timestamp. - warpTimestamp = boundUint40(warpTimestamp, flow.depletionTimeOf(streamId) + 1, UINT40_MAX); + warpTimestamp = boundUint40(warpTimestamp, uint40(flow.depletionTimeOf(streamId)) + 1, UINT40_MAX); // Simulate the passage of time. vm.warp({ newTimestamp: warpTimestamp }); diff --git a/tests/integration/fuzz/depletionTimeOf.t.sol b/tests/integration/fuzz/depletionTimeOf.t.sol index eb20de6c..6f589b65 100644 --- a/tests/integration/fuzz/depletionTimeOf.t.sol +++ b/tests/integration/fuzz/depletionTimeOf.t.sol @@ -33,7 +33,7 @@ contract DepletionTimeOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { vm.warp({ newTimestamp: getBlockTimestamp() + timeJump }); // Assert that depletion time equals expected value. - uint40 actualDepletionTime = flow.depletionTimeOf(streamId); + uint40 actualDepletionTime = uint40(flow.depletionTimeOf(streamId)); if (getBlockTimestamp() > OCT_1_2024 + solvencyPeriod) { assertEq(actualDepletionTime, 0, "depletion time"); diff --git a/tests/integration/fuzz/ongoingDebtOf.t.sol b/tests/integration/fuzz/ongoingDebtOf.t.sol index d360278c..c264843c 100644 --- a/tests/integration/fuzz/ongoingDebtOf.t.sol +++ b/tests/integration/fuzz/ongoingDebtOf.t.sol @@ -21,13 +21,13 @@ contract OngoingDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { // Pause the stream. flow.pause(streamId); - uint128 expectedOngoingDebt = flow.ongoingDebtOf(streamId); + uint256 expectedOngoingDebt = flow.ongoingDebtOf(streamId); // Simulate the passage of time after pause. vm.warp({ newTimestamp: getBlockTimestamp() + timeJump }); // Assert that the ongoing debt did not change. - uint128 actualOngoingDebt = flow.ongoingDebtOf(streamId); + uint256 actualOngoingDebt = flow.ongoingDebtOf(streamId); assertEq(actualOngoingDebt, expectedOngoingDebt, "ongoing debt"); } @@ -56,7 +56,7 @@ contract OngoingDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { updateSnapshotTimeAndWarp(streamId); // Assert that ongoing debt is zero. - uint128 actualOngoingDebt = flow.ongoingDebtOf(streamId); + uint256 actualOngoingDebt = flow.ongoingDebtOf(streamId); assertEq(actualOngoingDebt, 0, "ongoing debt"); } @@ -88,8 +88,8 @@ contract OngoingDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { uint128 ratePerSecond = flow.getRatePerSecond(streamId).unwrap(); // Assert that the ongoing debt equals the expected value. - uint128 actualOngoingDebt = flow.ongoingDebtOf(streamId); - uint128 expectedOngoingDebt = getDescaledAmount(ratePerSecond * timeJump, decimals); + uint256 actualOngoingDebt = flow.ongoingDebtOf(streamId); + uint256 expectedOngoingDebt = getDescaledAmount(ratePerSecond * timeJump, decimals); assertEq(actualOngoingDebt, expectedOngoingDebt, "ongoing debt"); } } diff --git a/tests/integration/fuzz/pause.t.sol b/tests/integration/fuzz/pause.t.sol index 0a73f4d4..8fcb5c65 100644 --- a/tests/integration/fuzz/pause.t.sol +++ b/tests/integration/fuzz/pause.t.sol @@ -73,7 +73,7 @@ contract Pause_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { streamId: streamId, sender: users.sender, recipient: users.recipient, - totalDebt: flow.totalDebtOf(streamId) + totalDebt: uint128(flow.totalDebtOf(streamId)) }); vm.expectEmit({ emitter: address(flow) }); diff --git a/tests/integration/fuzz/refund.t.sol b/tests/integration/fuzz/refund.t.sol index 744df1a4..b297f41d 100644 --- a/tests/integration/fuzz/refund.t.sol +++ b/tests/integration/fuzz/refund.t.sol @@ -32,7 +32,7 @@ contract Refund_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { (streamId,,) = useFuzzedStreamOrCreate(streamId, decimals); // Bound the time jump so it is greater than depletion timestamp. - uint40 depletionPeriod = flow.depletionTimeOf(streamId); + uint40 depletionPeriod = uint40(flow.depletionTimeOf(streamId)); timeJump = boundUint40(timeJump, depletionPeriod + 1, UINT40_MAX); // Simulate the passage of time. @@ -66,7 +66,7 @@ contract Refund_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { (streamId,,) = useFuzzedStreamOrCreate(streamId, decimals); // Bound the time jump so that it is less than the depletion timestamp. - uint40 depletionPeriod = flow.depletionTimeOf(streamId); + uint40 depletionPeriod = uint40(flow.depletionTimeOf(streamId)); timeJump = boundUint40(timeJump, getBlockTimestamp(), depletionPeriod - 1); // Simulate the passage of time. diff --git a/tests/integration/fuzz/refundableAmountOf.t.sol b/tests/integration/fuzz/refundableAmountOf.t.sol index 04c90d35..f6e3470f 100644 --- a/tests/integration/fuzz/refundableAmountOf.t.sol +++ b/tests/integration/fuzz/refundableAmountOf.t.sol @@ -19,7 +19,7 @@ contract RefundableAmountOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Tes { (streamId,, depositedAmount) = useFuzzedStreamOrCreate(streamId, decimals); - uint40 depletionPeriod = flow.depletionTimeOf(streamId); + uint40 depletionPeriod = uint40(flow.depletionTimeOf(streamId)); // Pause the stream. flow.pause(streamId); @@ -57,7 +57,7 @@ contract RefundableAmountOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Tes (streamId, decimals, depositedAmount) = useFuzzedStreamOrCreate(streamId, decimals); // Bound the time jump so that it is less than the depletion timestamp. - warpTimestamp = boundUint40(warpTimestamp, getBlockTimestamp(), flow.depletionTimeOf(streamId) - 1); + warpTimestamp = boundUint40(warpTimestamp, getBlockTimestamp(), uint40(flow.depletionTimeOf(streamId)) - 1); // Simulate the passage of time. vm.warp({ newTimestamp: warpTimestamp }); @@ -80,7 +80,7 @@ contract RefundableAmountOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Tes (streamId,,) = useFuzzedStreamOrCreate(streamId, decimals); // Bound the time jump so it is greater than depletion timestamp. - uint40 depletionPeriod = flow.depletionTimeOf(streamId); + uint40 depletionPeriod = uint40(flow.depletionTimeOf(streamId)); warpTimestamp = boundUint40(warpTimestamp, depletionPeriod + 1, UINT40_MAX); // Simulate the passage of time. diff --git a/tests/integration/fuzz/totalDebtOf.t.sol b/tests/integration/fuzz/totalDebtOf.t.sol index bd5f9482..0fe8589e 100644 --- a/tests/integration/fuzz/totalDebtOf.t.sol +++ b/tests/integration/fuzz/totalDebtOf.t.sol @@ -21,13 +21,13 @@ contract TotalDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { // Pause the stream. flow.pause(streamId); - uint128 expectedTotalDebt = flow.totalDebtOf(streamId); + uint256 expectedTotalDebt = flow.totalDebtOf(streamId); // Simulate the passage of time after pause. vm.warp({ newTimestamp: getBlockTimestamp() + timeJump }); // Assert that total debt is zero. - uint128 actualTotalDebt = flow.totalDebtOf(streamId); + uint256 actualTotalDebt = flow.totalDebtOf(streamId); assertEq(actualTotalDebt, expectedTotalDebt, "total debt"); } @@ -56,7 +56,7 @@ contract TotalDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { uint128 ratePerSecond = flow.getRatePerSecond(streamId).unwrap(); // Assert that total debt is the ongoing debt. - uint128 actualTotalDebt = flow.totalDebtOf(streamId); + uint256 actualTotalDebt = flow.totalDebtOf(streamId); uint128 expectedTotalDebt = getDescaledAmount(ratePerSecond * timeJump, decimals); assertEq(actualTotalDebt, expectedTotalDebt, "total debt"); } diff --git a/tests/integration/fuzz/uncoveredDebtOf.t.sol b/tests/integration/fuzz/uncoveredDebtOf.t.sol index 88b8abc7..09660924 100644 --- a/tests/integration/fuzz/uncoveredDebtOf.t.sol +++ b/tests/integration/fuzz/uncoveredDebtOf.t.sol @@ -21,13 +21,13 @@ contract UncoveredDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { // Pause the stream. flow.pause(streamId); - uint128 expectedUncoveredDebt = flow.uncoveredDebtOf(streamId); + uint256 expectedUncoveredDebt = flow.uncoveredDebtOf(streamId); // Simulate the passage of time after pause. vm.warp({ newTimestamp: getBlockTimestamp() + timeJump }); // Assert that uncovered debt equals expected value. - uint128 actualUncoveredDebt = flow.uncoveredDebtOf(streamId); + uint256 actualUncoveredDebt = flow.uncoveredDebtOf(streamId); assertEq(actualUncoveredDebt, expectedUncoveredDebt, "uncovered debt"); } @@ -51,7 +51,7 @@ contract UncoveredDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { (streamId,, depositedAmount) = useFuzzedStreamOrCreate(streamId, decimals); uint128 balance = flow.getBalance(streamId); - uint40 depletionTime = flow.depletionTimeOf(streamId); + uint40 depletionTime = uint40(flow.depletionTimeOf(streamId)); // Bound the time jump to provide a realistic time frame. timeJump = boundUint40(timeJump, 0 seconds, 100 weeks); @@ -62,8 +62,8 @@ contract UncoveredDebtOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { vm.warp({ newTimestamp: warpTimestamp }); // Assert that the uncovered debt equals expected value. - uint128 actualUncoveredDebt = flow.uncoveredDebtOf(streamId); - uint128 expectedUncoveredDebt; + uint256 actualUncoveredDebt = flow.uncoveredDebtOf(streamId); + uint256 expectedUncoveredDebt; if (warpTimestamp > depletionTime) { expectedUncoveredDebt = flow.totalDebtOf(streamId) - balance; } else { diff --git a/tests/integration/fuzz/void.t.sol b/tests/integration/fuzz/void.t.sol index 87fbe0a1..2e942b19 100644 --- a/tests/integration/fuzz/void.t.sol +++ b/tests/integration/fuzz/void.t.sol @@ -31,7 +31,7 @@ contract Void_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { (streamId,,) = useFuzzedStreamOrCreate(streamId, decimals); // Bound the time jump so that it does not exceed depletion timestamp. - uint40 depletionTime = flow.depletionTimeOf(streamId); + uint40 depletionTime = uint40(flow.depletionTimeOf(streamId)); timeJump = boundUint40(timeJump, getBlockTimestamp(), depletionTime); // Simulate the passage of time. @@ -66,7 +66,7 @@ contract Void_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { (streamId,, depositedAmount) = useFuzzedStreamOrCreate(streamId, decimals); // Bound the time jump so that it exceeds depletion timestamp. - uint40 depletionTime = flow.depletionTimeOf(streamId); + uint40 depletionTime = uint40(flow.depletionTimeOf(streamId)); timeJump = boundUint40(timeJump, depletionTime + 1, UINT40_MAX); // Simulate the passage of time. @@ -106,7 +106,7 @@ contract Void_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { (streamId,, depositedAmount) = useFuzzedStreamOrCreate(streamId, decimals); // Bound the time jump so that it exceeds depletion timestamp. - uint40 depletionTime = flow.depletionTimeOf(streamId); + uint40 depletionTime = uint40(flow.depletionTimeOf(streamId)); timeJump = boundUint40(timeJump, depletionTime + 1, UINT40_MAX); // Simulate the passage of time. @@ -122,7 +122,7 @@ contract Void_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { // Shared private function. function _test_Void(address caller, uint256 streamId) private { - uint128 debtToWriteOff = flow.uncoveredDebtOf(streamId); + uint256 debtToWriteOff = flow.uncoveredDebtOf(streamId); uint128 expectedTotalDebt; if (debtToWriteOff > 0) { @@ -130,7 +130,7 @@ contract Void_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { expectedTotalDebt = flow.getBalance(streamId); } else { // Otherwise, expect the total debt to remain same. - expectedTotalDebt = flow.totalDebtOf(streamId); + expectedTotalDebt = uint128(flow.totalDebtOf(streamId)); } // Expect the relevant events to be emitted. diff --git a/tests/integration/fuzz/withdraw.t.sol b/tests/integration/fuzz/withdraw.t.sol index 4bc06f4b..7109f738 100644 --- a/tests/integration/fuzz/withdraw.t.sol +++ b/tests/integration/fuzz/withdraw.t.sol @@ -126,8 +126,8 @@ contract Withdraw_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { uint128 feeAmount; uint256 previousAggregateAmount; uint256 previousTokenBalance; - uint128 previousOngoingDebt; - uint128 previousTotalDebt; + uint256 previousOngoingDebt; + uint256 previousTotalDebt; uint128 previousStreamBalance; uint256 actualAggregateAmount; uint256 expectedAggregateAmount; @@ -135,8 +135,8 @@ contract Withdraw_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { uint128 expectedProtocolRevenue; uint40 actualSnapshotTime; uint40 expectedSnapshotTime; - uint128 actualTotalDebt; - uint128 expectedTotalDebt; + uint256 actualTotalDebt; + uint256 expectedTotalDebt; uint128 actualStreamBalance; uint128 expectedStreamBalance; uint256 actualTokenBalance; @@ -163,7 +163,7 @@ contract Withdraw_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { // If the withdrawable amount is still zero, warp closely to depletion time. if (flow.withdrawableAmountOf(streamId) == 0) { - vm.warp({ newTimestamp: flow.depletionTimeOf(streamId) - 1 }); + vm.warp({ newTimestamp: uint40(flow.depletionTimeOf(streamId)) - 1 }); } // Bound the withdraw amount between the allowed range. diff --git a/tests/integration/fuzz/withdrawMax.t.sol b/tests/integration/fuzz/withdrawMax.t.sol index 180216c6..5b1489c1 100644 --- a/tests/integration/fuzz/withdrawMax.t.sol +++ b/tests/integration/fuzz/withdrawMax.t.sol @@ -86,11 +86,11 @@ contract WithdrawMax_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { function _test_WithdrawMax(address caller, address withdrawTo, uint256 streamId) private { // If the withdrawable amount is still zero, warp closely to depletion time. if (flow.withdrawableAmountOf(streamId) == 0) { - vm.warp({ newTimestamp: flow.depletionTimeOf(streamId) - 1 }); + vm.warp({ newTimestamp: uint40(flow.depletionTimeOf(streamId)) - 1 }); } uint256 previousAggregateAmount = flow.aggregateBalance(token); - uint128 totalDebt = flow.totalDebtOf(streamId); + uint256 totalDebt = flow.totalDebtOf(streamId); uint256 tokenBalance = token.balanceOf(address(flow)); uint128 streamBalance = flow.getBalance(streamId); @@ -124,8 +124,8 @@ contract WithdrawMax_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test { assertEq(flow.getSnapshotTime(streamId), expectedSnapshotTime, "snapshot time"); // It should decrease the total debt by the withdrawn value. - uint128 actualTotalDebt = flow.totalDebtOf(streamId); - uint128 expectedTotalDebt = totalDebt - withdrawAmount; + uint256 actualTotalDebt = flow.totalDebtOf(streamId); + uint256 expectedTotalDebt = totalDebt - withdrawAmount; assertEq(actualTotalDebt, expectedTotalDebt, "total debt"); // It should reduce the stream balance by the withdrawn amount. diff --git a/tests/invariant/Flow.t.sol b/tests/invariant/Flow.t.sol index c1c6d02b..9283a55f 100644 --- a/tests/invariant/Flow.t.sol +++ b/tests/invariant/Flow.t.sol @@ -376,7 +376,7 @@ contract Flow_Invariant_Test is Base_Test { FlowStore.Period memory period = flowStore.getPeriod(streamId, i); // If end time is 0, it means the current period is still active. - uint40 elapsed = period.end > 0 ? period.end - period.start : uint40(block.timestamp) - period.start; + uint128 elapsed = period.end > 0 ? period.end - period.start : uint40(block.timestamp) - period.start; // Calculate the total streamed amount for the current period. totalStreamedAmount += getDescaledAmount(period.ratePerSecond * elapsed, decimals); diff --git a/tests/invariant/handlers/FlowCreateHandler.sol b/tests/invariant/handlers/FlowCreateHandler.sol index 17cd473e..dc594ccb 100644 --- a/tests/invariant/handlers/FlowCreateHandler.sol +++ b/tests/invariant/handlers/FlowCreateHandler.sol @@ -137,11 +137,11 @@ contract FlowCreateHandler is BaseHandler { // For 18 decimal, check the rate per second is within a realistic range. if (decimals == 18) { - vm.assume(params.ratePerSecond > 0.00001e18 && params.ratePerSecond <= 1e18); + vm.assume(params.ratePerSecond > 0.00001e18 && params.ratePerSecond <= UINT128_MAX / 7 days); } // For all other decimals, choose the minimum rps such that it takes 100 seconds to stream 1 token. else { - vm.assume(params.ratePerSecond > mvt / 100 && params.ratePerSecond <= 1e18); + vm.assume(params.ratePerSecond > mvt / 100 && params.ratePerSecond <= UINT128_MAX / 7 days); } } } diff --git a/tests/invariant/handlers/FlowHandler.sol b/tests/invariant/handlers/FlowHandler.sol index b16c90e8..b81f3e39 100644 --- a/tests/invariant/handlers/FlowHandler.sol +++ b/tests/invariant/handlers/FlowHandler.sol @@ -183,7 +183,7 @@ contract FlowHandler is BaseHandler { updateFlowHandlerStates instrument(currentStreamId, "refund") { - uint128 refundableAmount = flow.refundableAmountOf(currentStreamId); + uint256 refundableAmount = flow.refundableAmountOf(currentStreamId); // The protocol doesn't allow zero refund amounts. vm.assume(refundableAmount > 0); diff --git a/tests/invariant/stores/FlowStore.sol b/tests/invariant/stores/FlowStore.sol index 85cd3e5d..9d2c4615 100644 --- a/tests/invariant/stores/FlowStore.sol +++ b/tests/invariant/stores/FlowStore.sol @@ -25,8 +25,8 @@ contract FlowStore { // Previous values mapping(uint256 streamId => uint40 snapshotTime) public previousSnapshotTime; - mapping(uint256 streamId => uint128 amount) public previousTotalDebtOf; - mapping(uint256 streamId => uint128 amount) public previousUncoveredDebtOf; + mapping(uint256 streamId => uint256 amount) public previousTotalDebtOf; + mapping(uint256 streamId => uint256 amount) public previousUncoveredDebtOf; /// @dev This struct represents a time period during which rate per second remains constant. /// @param typeOfPeriod The type of the period, which is the function name. @@ -111,15 +111,15 @@ contract FlowStore { } uint256 periodCount = periods[streamId].length - 1; - uint128 factor = uint128(10 ** (18 - decimals)); - uint40 blockTimestamp = uint40(block.timestamp); - uint40 start = periods[streamId][periodCount].start; + uint256 factor = uint128(10 ** (18 - decimals)); + uint256 blockTimestamp = uint40(block.timestamp); + uint256 start = periods[streamId][periodCount].start; - uint128 rescaledStreamedAmount = ratePerSecond * (blockTimestamp - start) / factor * factor; + uint256 rescaledStreamedAmount = ratePerSecond * (blockTimestamp - start) / factor * factor; uint40 delay; if (rescaledStreamedAmount > ratePerSecond) { - delay = blockTimestamp - start - uint40(rescaledStreamedAmount / ratePerSecond); + delay = uint40(blockTimestamp - start - (rescaledStreamedAmount / ratePerSecond)); // Since we are reverse engineering the delay, we need to subtract 1 from the delay, which would normally be // added in the constant interval calculation delay = delay > 1 ? delay - 1 : 0; @@ -131,8 +131,8 @@ contract FlowStore { function updatePreviousValues( uint256 streamId, uint40 snapshotTime, - uint128 totalDebtOf, - uint128 uncoveredDebtOf + uint256 totalDebtOf, + uint256 uncoveredDebtOf ) external {