diff --git a/benchmark/Flow.Gas.t.sol b/benchmark/Flow.Gas.t.sol index b422c4fd..c36879bb 100644 --- a/benchmark/Flow.Gas.t.sol +++ b/benchmark/Flow.Gas.t.sol @@ -89,7 +89,7 @@ contract Flow_Gas_Test is Integration_Test { ); // Deposit amount on an incremented stream ID to make stream solvent. - deposit(++streamId, flow.uncoveredDebtOf(streamId) + DEPOSIT_AMOUNT_6D); + deposit(++streamId, uint128(flow.uncoveredDebtOf(streamId)) + DEPOSIT_AMOUNT_6D); // {flow.withdraw} (on a solvent stream). computeGas( diff --git a/benchmark/results/SablierFlow.md b/benchmark/results/SablierFlow.md index b10a9f05..4a88ae74 100644 --- a/benchmark/results/SablierFlow.md +++ b/benchmark/results/SablierFlow.md @@ -2,15 +2,15 @@ | Function | Gas Usage | | ----------------------------- | --------- | -| `adjustRatePerSecond` | 44009 | -| `create` | 113794 | -| `deposit` | 30152 | -| `depositViaBroker` | 22142 | -| `pause` | 9340 | -| `refund` | 11671 | -| `restart` | 7106 | -| `void (solvent stream)` | 10389 | -| `void (insolvent stream)` | 36795 | -| `withdraw (insolvent stream)` | 57634 | -| `withdraw (solvent stream)` | 40047 | -| `withdrawMax` | 52200 | +| `adjustRatePerSecond` | 43628 | +| `create` | 113659 | +| `deposit` | 30035 | +| `depositViaBroker` | 21953 | +| `pause` | 8983 | +| `refund` | 11534 | +| `restart` | 7031 | +| `void (solvent stream)` | 9517 | +| `void (insolvent stream)` | 36241 | +| `withdraw (insolvent stream)` | 57034 | +| `withdraw (solvent stream)` | 39502 | +| `withdrawMax` | 51379 | diff --git a/src/SablierFlow.sol b/src/SablierFlow.sol index 1dac8e67..849b9fce 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; @@ -69,15 +69,15 @@ contract SablierFlow is return 0; } - uint128 snapshotDebt = _streams[streamId].snapshotDebt; + uint256 snapshotDebt = _streams[streamId].snapshotDebt; // If the stream has uncovered debt, return zero. - if (snapshotDebt + _ongoingDebtOf(streamId) >= balance) { + if (snapshotDebt + _ongoingDebtOf(streamId) > balance) { 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); + uint256 ongoingDebt = _ongoingDebtOf(streamId); // Update the snapshot debt only if the stream has ongoing debt. if (ongoingDebt > 0) { @@ -709,11 +710,11 @@ 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); + uint256 ongoingDebt = _ongoingDebtOf(streamId); if (ongoingDebt > 0) { // Effect: Update the snapshot debt by adding the ongoing debt. _streams[streamId].snapshotDebt += ongoingDebt; @@ -764,7 +765,7 @@ contract SablierFlow is } // Calculate the total debt. - uint128 totalDebt = _totalDebtOf(streamId); + uint256 totalDebt = _totalDebtOf(streamId); // Calculate the withdrawable amount. uint128 balance = _streams[streamId].balance; @@ -775,7 +776,7 @@ contract SablierFlow is withdrawableAmount = balance; } else { // Otherwise, the withdrawable amount is the total debt. - withdrawableAmount = totalDebt; + withdrawableAmount = totalDebt.toUint128(); } // Check: the withdraw amount is not greater than the withdrawable amount. diff --git a/src/abstracts/SablierFlowBase.sol b/src/abstracts/SablierFlowBase.sol index f498fbe5..d6bf5b06 100644 --- a/src/abstracts/SablierFlowBase.sol +++ b/src/abstracts/SablierFlowBase.sol @@ -139,7 +139,7 @@ abstract contract SablierFlowBase is view override notNull(streamId) - returns (uint128 snapshotDebt) + returns (uint256 snapshotDebt) { snapshotDebt = _streams[streamId].snapshotDebt; } @@ -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/src/interfaces/ISablierFlowBase.sol b/src/interfaces/ISablierFlowBase.sol index d5958c42..d6411b7d 100644 --- a/src/interfaces/ISablierFlowBase.sol +++ b/src/interfaces/ISablierFlowBase.sol @@ -87,7 +87,7 @@ interface ISablierFlowBase is /// @notice Retrieves the snapshot debt of the stream, denoted in token's decimals. /// @dev Reverts if `streamId` references a null stream. /// @param streamId The stream ID for the query. - function getSnapshotDebt(uint256 streamId) external view returns (uint128 snapshotDebt); + function getSnapshotDebt(uint256 streamId) external view returns (uint256 snapshotDebt); /// @notice Retrieves the snapshot time of the stream, which is a Unix timestamp. /// @dev Reverts if `streamId` references a null stream. diff --git a/src/types/DataTypes.sol b/src/types/DataTypes.sol index 42234f16..fa4806f1 100644 --- a/src/types/DataTypes.sol +++ b/src/types/DataTypes.sol @@ -72,6 +72,6 @@ library Flow { IERC20 token; uint8 tokenDecimals; // slot 3 - uint128 snapshotDebt; + uint256 snapshotDebt; } } diff --git a/tests/fork/Flow.t.sol b/tests/fork/Flow.t.sol index beaaf4c4..eb927e4d 100644 --- a/tests/fork/Flow.t.sol +++ b/tests/fork/Flow.t.sol @@ -49,20 +49,20 @@ contract Flow_Fork_Test is Fork_Test { uint256 actualAggregateAmount; UD21x18 actualRatePerSecond; uint40 actualSnapshotTime; - uint128 actualSnapshotDebt; + uint256 actualSnapshotDebt; uint128 actualStreamBalance; uint256 actualStreamId; uint256 actualTokenBalance; - uint128 actualTotalDebt; + uint256 actualTotalDebt; // Expected values. uint256 expectedAggregateAmount; UD21x18 expectedRatePerSecond; uint40 expectedSnapshotTime; - uint128 expectedSnapshotDebt; + uint256 expectedSnapshotDebt; uint128 expectedStreamBalance; uint256 expectedStreamId; uint256 expectedTokenBalance; - uint128 expectedTotalDebt; + uint256 expectedTotalDebt; } /*////////////////////////////////////////////////////////////////////////// @@ -251,9 +251,9 @@ contract Flow_Fork_Test is Fork_Test { newRatePerSecond = ud21x18(newRatePerSecond.unwrap() + 1); } - uint128 beforeSnapshotAmount = flow.getSnapshotDebt(streamId); - uint128 totalDebt = flow.totalDebtOf(streamId); - uint128 ongoingDebt = flow.ongoingDebtOf(streamId); + uint256 beforeSnapshotAmount = flow.getSnapshotDebt(streamId); + uint256 totalDebt = flow.totalDebtOf(streamId); + uint256 ongoingDebt = flow.ongoingDebtOf(streamId); // Compute the snapshot time that will be stored post withdraw. vars.expectedSnapshotTime = getBlockTimestamp(); @@ -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/adjust-rate-per-second/adjustRatePerSecond.t.sol b/tests/integration/concrete/adjust-rate-per-second/adjustRatePerSecond.t.sol index a58cfa40..65b952f5 100644 --- a/tests/integration/concrete/adjust-rate-per-second/adjustRatePerSecond.t.sol +++ b/tests/integration/concrete/adjust-rate-per-second/adjustRatePerSecond.t.sol @@ -95,7 +95,7 @@ contract AdjustRatePerSecond_Integration_Concrete_Test is Integration_Test { uint40 expectedSnapshotTime = getBlockTimestamp() - ONE_MONTH; assertEq(actualSnapshotTime, expectedSnapshotTime, "snapshot time"); - uint128 actualSnapshotDebt = flow.getSnapshotDebt(defaultStreamId); + uint256 actualSnapshotDebt = flow.getSnapshotDebt(defaultStreamId); uint128 expectedSnapshotDebt = 0; assertEq(actualSnapshotDebt, expectedSnapshotDebt, "snapshot debt"); 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..35caf97d 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); + uint256 depletionTime = flow.depletionTimeOf(defaultStreamId); assertEq(depletionTime, 0, "depletion time"); } function test_GivenUncoveredDebt() external givenNotNull givenNotPaused givenBalanceNotZero { - vm.warp({ newTimestamp: WARP_SOLVENCY_PERIOD }); + vm.warp({ newTimestamp: WARP_SOLVENCY_PERIOD + 1 }); // It should return 0 - uint40 depletionTime = flow.depletionTimeOf(defaultStreamId); + uint256 depletionTime = 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/depletion-time-of/depletionTimeOf.tree b/tests/integration/concrete/depletion-time-of/depletionTimeOf.tree index 9e83a71c..35c32dcf 100644 --- a/tests/integration/concrete/depletion-time-of/depletionTimeOf.tree +++ b/tests/integration/concrete/depletion-time-of/depletionTimeOf.tree @@ -11,4 +11,4 @@ DepletionTimeOf_Integration_Concrete_Test ├── given uncovered debt │ └── it should return 0 └── given no uncovered debt - └── it should return the time at which the stream depletes its balance + └── it should return the time at which the stream depletes its balance \ No newline at end of file diff --git a/tests/integration/concrete/deposit-and-pause/depositAndPause.t.sol b/tests/integration/concrete/deposit-and-pause/depositAndPause.t.sol index 489c8e11..2c7db077 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) }); @@ -98,7 +98,7 @@ contract DepositAndPause_Integration_Concrete_Test is Integration_Test { assertEq(actualRatePerSecond, 0, "rate per second"); // It should update the snapshot debt - uint128 actualSnapshotDebt = flow.getSnapshotDebt(defaultStreamId); + uint256 actualSnapshotDebt = flow.getSnapshotDebt(defaultStreamId); assertEq(actualSnapshotDebt, previousTotalDebt, "snapshot debt"); } } 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..e0ce7cee 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) }); @@ -90,7 +90,7 @@ contract Pause_Integration_Concrete_Test is Integration_Test { assertEq(actualRatePerSecond, 0, "rate per second"); // It should update the snapshot debt. - uint128 actualSnapshotDebt = flow.getSnapshotDebt(defaultStreamId); + uint256 actualSnapshotDebt = flow.getSnapshotDebt(defaultStreamId); assertEq(actualSnapshotDebt, initialTotalDebt, "snapshot debt"); } } diff --git a/tests/integration/concrete/refund-and-pause/refundAndPause.t.sol b/tests/integration/concrete/refund-and-pause/refundAndPause.t.sol index 242c336f..9bc8cc14 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) }); @@ -96,7 +96,7 @@ contract RefundAndPause_Integration_Concrete_Test is Integration_Test { assertEq(actualRatePerSecond, 0, "rate per second"); // It should update the snapshot debt - uint128 actualSnapshotDebt = flow.getSnapshotDebt(defaultStreamId); + uint256 actualSnapshotDebt = flow.getSnapshotDebt(defaultStreamId); assertEq(actualSnapshotDebt, previousTotalDebt, "snapshot debt"); } } diff --git a/tests/integration/concrete/total-debt-of/totalDebtOf.t.sol b/tests/integration/concrete/total-debt-of/totalDebtOf.t.sol index b5b50ba5..0dda0a9d 100644 --- a/tests/integration/concrete/total-debt-of/totalDebtOf.t.sol +++ b/tests/integration/concrete/total-debt-of/totalDebtOf.t.sol @@ -14,8 +14,8 @@ contract TotalDebtOf_Integration_Concrete_Test is Integration_Test { function test_GivenPaused() external givenNotNull { flow.pause(defaultStreamId); - uint128 snapshotDebt = flow.getSnapshotDebt(defaultStreamId); - uint128 totalDebt = flow.totalDebtOf(defaultStreamId); + uint256 snapshotDebt = flow.getSnapshotDebt(defaultStreamId); + uint256 totalDebt = flow.totalDebtOf(defaultStreamId); assertEq(totalDebt, snapshotDebt, "total debt"); } @@ -24,16 +24,16 @@ contract TotalDebtOf_Integration_Concrete_Test is Integration_Test { // Set the snapshot time to the current time by changing rate per second. flow.adjustRatePerSecond(defaultStreamId, ud21x18(RATE_PER_SECOND_U128 * 2)); - uint128 snapshotDebt = flow.getSnapshotDebt(defaultStreamId); - uint128 totalDebt = flow.totalDebtOf(defaultStreamId); + uint256 snapshotDebt = flow.getSnapshotDebt(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 snapshotDebt = flow.getSnapshotDebt(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-max/withdrawMax.t.sol b/tests/integration/concrete/withdraw-max/withdrawMax.t.sol index 6ea866cc..feef2377 100644 --- a/tests/integration/concrete/withdraw-max/withdrawMax.t.sol +++ b/tests/integration/concrete/withdraw-max/withdrawMax.t.sol @@ -71,7 +71,7 @@ contract WithdrawMax_Integration_Concrete_Test is Integration_Test { assertEq(actualStreamBalance, expectedStreamBalance, "stream balance"); // It should set the snapshot debt to zero. - uint128 actualSnapshotDebt = flow.getSnapshotDebt(defaultStreamId); + uint256 actualSnapshotDebt = flow.getSnapshotDebt(defaultStreamId); assertEq(actualSnapshotDebt, 0, "snapshot debt"); if (flow.getRatePerSecond(defaultStreamId).unwrap() > 0) { 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..11e63ba7 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); + uint256 actualDepletionTime = 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/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 {