From 131567d8ac1a8dadc27f332ce7dfe6432859423d Mon Sep 17 00:00:00 2001 From: andreivladbrg Date: Mon, 22 Jan 2024 14:48:34 +0200 Subject: [PATCH] refactor: rename milestone to timestamp refactor: rename delta to duration --- script/Init.s.sol | 8 ++- src/SablierV2LockupDynamic.sol | 28 ++++---- src/interfaces/ISablierV2LockupDynamic.sol | 14 ++-- src/libraries/Errors.sol | 12 ++-- src/libraries/Helpers.sol | 66 ++++++++--------- src/types/DataTypes.sol | 16 ++--- test/fork/LockupDynamic.t.sol | 8 +-- .../createWithDurations.t.sol | 71 ++++++++++--------- .../createWithDurations.tree | 12 ++-- .../createWithTimestamps.t.sol | 62 ++++++++-------- .../createWithTimestamps.tree | 10 +-- .../streamed-amount-of/streamedAmountOf.t.sol | 10 +-- .../streamed-amount-of/streamedAmountOf.tree | 4 +- .../lockup-dynamic/createWithDurations.t.sol | 20 +++--- .../lockup-dynamic/createWithTimestamps.t.sol | 38 +++++----- .../lockup-dynamic/streamedAmountOf.t.sol | 24 +++---- .../fuzz/lockup-dynamic/withdraw.t.sol | 6 +- .../shared/lockup-dynamic/LockupDynamic.t.sol | 16 ++--- .../lockup-dynamic/createWithDurations.t.sol | 4 +- .../lockup-dynamic/createWithTimestamps.t.sol | 4 +- .../shared/lockup-linear/LockupLinear.t.sol | 9 +-- test/invariant/LockupDynamic.t.sol | 10 +-- .../handlers/LockupDynamicCreateHandler.sol | 8 +-- test/utils/Calculations.sol | 24 +++---- test/utils/Defaults.sol | 30 ++++---- test/utils/Fuzzers.sol | 68 +++++++++--------- test/utils/Utils.sol | 16 ++--- 27 files changed, 302 insertions(+), 296 deletions(-) diff --git a/script/Init.s.sol b/script/Init.s.sol index 3979c9bee..cf71876a2 100644 --- a/script/Init.s.sol +++ b/script/Init.s.sol @@ -78,9 +78,11 @@ contract Init is BaseScript { //////////////////////////////////////////////////////////////////////////*/ // Create the default lockupDynamic stream. - LockupDynamic.SegmentWithDelta[] memory segments = new LockupDynamic.SegmentWithDelta[](2); - segments[0] = LockupDynamic.SegmentWithDelta({ amount: 2500e18, exponent: ud2x18(3.14e18), delta: 1 hours }); - segments[1] = LockupDynamic.SegmentWithDelta({ amount: 7500e18, exponent: ud2x18(0.5e18), delta: 1 weeks }); + LockupDynamic.SegmentWithDuration[] memory segments = new LockupDynamic.SegmentWithDuration[](2); + segments[0] = + LockupDynamic.SegmentWithDuration({ amount: 2500e18, exponent: ud2x18(3.14e18), duration: 1 hours }); + segments[1] = + LockupDynamic.SegmentWithDuration({ amount: 7500e18, exponent: ud2x18(0.5e18), duration: 1 weeks }); lockupDynamic.createWithDurations( LockupDynamic.CreateWithDurations({ sender: sender, diff --git a/src/SablierV2LockupDynamic.sol b/src/SablierV2LockupDynamic.sol index 060b5aa9c..e44d6113b 100644 --- a/src/SablierV2LockupDynamic.sol +++ b/src/SablierV2LockupDynamic.sol @@ -273,8 +273,8 @@ contract SablierV2LockupDynamic is noDelegateCall returns (uint256 streamId) { - // Checks: check the deltas and generate the canonical segments. - LockupDynamic.Segment[] memory segments = Helpers.checkDeltasAndCalculateMilestones(params.segments); + // Checks: check the durations and generate the canonical segments. + LockupDynamic.Segment[] memory segments = Helpers.checkDurationsAndCalculateTimestamps(params.segments); // Checks, Effects and Interactions: create the stream. streamId = _createWithTimestamps( @@ -345,32 +345,32 @@ contract SablierV2LockupDynamic is // Sum the amounts in all segments that precede the current time. uint128 previousSegmentAmounts; - uint40 currentSegmentMilestone = stream.segments[0].milestone; + uint40 currentSegmentTimestamp = stream.segments[0].timestamp; uint256 index = 0; - while (currentSegmentMilestone < currentTime) { + while (currentSegmentTimestamp < currentTime) { previousSegmentAmounts += stream.segments[index].amount; index += 1; - currentSegmentMilestone = stream.segments[index].milestone; + currentSegmentTimestamp = stream.segments[index].timestamp; } // After exiting the loop, the current segment is at `index`. SD59x18 currentSegmentAmount = stream.segments[index].amount.intoSD59x18(); SD59x18 currentSegmentExponent = stream.segments[index].exponent.intoSD59x18(); - currentSegmentMilestone = stream.segments[index].milestone; + currentSegmentTimestamp = stream.segments[index].timestamp; - uint40 previousMilestone; + uint40 previousTimestamp; if (index > 0) { // When the current segment's index is greater than or equal to 1, it implies that the segment is not - // the first. In this case, use the previous segment's milestone. - previousMilestone = stream.segments[index - 1].milestone; + // the first. In this case, use the previous segment's timestamp. + previousTimestamp = stream.segments[index - 1].timestamp; } else { - // Otherwise, the current segment is the first, so use the start time as the previous milestone. - previousMilestone = stream.startTime; + // Otherwise, the current segment is the first, so use the start time as the previous timestamp. + previousTimestamp = stream.startTime; } // Calculate how much time has passed since the segment started, and the total time of the segment. - SD59x18 elapsedSegmentTime = (currentTime - previousMilestone).intoSD59x18(); - SD59x18 totalSegmentTime = (currentSegmentMilestone - previousMilestone).intoSD59x18(); + SD59x18 elapsedSegmentTime = (currentTime - previousTimestamp).intoSD59x18(); + SD59x18 totalSegmentTime = (currentSegmentTimestamp - previousTimestamp).intoSD59x18(); // Divide the elapsed segment time by the total duration of the segment. SD59x18 elapsedSegmentTimePercentage = elapsedSegmentTime.div(totalSegmentTime); @@ -567,7 +567,7 @@ contract SablierV2LockupDynamic is unchecked { // The segment count cannot be zero at this point. uint256 segmentCount = params.segments.length; - stream.endTime = params.segments[segmentCount - 1].milestone; + stream.endTime = params.segments[segmentCount - 1].timestamp; stream.startTime = params.startTime; // Effects: store the segments. Since Solidity lacks a syntax for copying arrays directly from diff --git a/src/interfaces/ISablierV2LockupDynamic.sol b/src/interfaces/ISablierV2LockupDynamic.sol index bf030bd99..8f646cec3 100644 --- a/src/interfaces/ISablierV2LockupDynamic.sol +++ b/src/interfaces/ISablierV2LockupDynamic.sol @@ -92,8 +92,8 @@ interface ISablierV2LockupDynamic is ISablierV2Lockup { //////////////////////////////////////////////////////////////////////////*/ /// @notice Creates a stream by setting the start time to `block.timestamp`, and the end time to the sum of - /// `block.timestamp` and all specified time deltas. The segment milestones are derived from these - /// deltas. The stream is funded by `msg.sender` and is wrapped in an ERC-721 NFT. + /// `block.timestamp` and all specified time durations. The segment timestamps are derived from these + /// durations. The stream is funded by `msg.sender` and is wrapped in an ERC-721 NFT. /// /// @dev Emits a {Transfer} and {CreateLockupDynamicStream} event. /// @@ -106,13 +106,13 @@ interface ISablierV2LockupDynamic is ISablierV2Lockup { external returns (uint256 streamId); - /// @notice Creates a stream with the provided segment milestones, implying the end time from the last milestone. + /// @notice Creates a stream with the provided segment timestamps, implying the end time from the last timestamp. /// The stream is funded by `msg.sender` and is wrapped in an ERC-721 NFT. /// /// @dev Emits a {Transfer} and {CreateLockupDynamicStream} event. /// /// Notes: - /// - As long as the segment milestones are arranged in ascending order, it is not an error for some + /// - As long as the segment timestamps are arranged in ascending order, it is not an error for some /// of them to be in the past. /// /// Requirements: @@ -120,9 +120,9 @@ interface ISablierV2LockupDynamic is ISablierV2Lockup { /// - `params.totalAmount` must be greater than zero. /// - If set, `params.broker.fee` must not be greater than `MAX_FEE`. /// - `params.segments` must have at least one segment, but not more than `MAX_SEGMENT_COUNT`. - /// - `params.startTime` must be less than the first segment's milestone. - /// - The segment milestones must be arranged in ascending order. - /// - The last segment milestone (i.e. the stream's end time) must be in the future. + /// - `params.startTime` must be less than the first segment's timestamp. + /// - The segment timestamps must be arranged in ascending order. + /// - The last segment timestamp (i.e. the stream's end time) must be in the future. /// - The sum of the segment amounts must equal the deposit amount. /// - `params.recipient` must not be the zero address. /// - `msg.sender` must have allowed this contract to spend at least `params.totalAmount` assets. diff --git a/src/libraries/Errors.sol b/src/libraries/Errors.sol index bf9548520..2efa5b8c3 100644 --- a/src/libraries/Errors.sol +++ b/src/libraries/Errors.sol @@ -97,15 +97,15 @@ library Errors { /// @notice Thrown when trying to create a stream with no segments. error SablierV2LockupDynamic_SegmentCountZero(); - /// @notice Thrown when trying to create a stream with unordered segment milestones. - error SablierV2LockupDynamic_SegmentMilestonesNotOrdered( - uint256 index, uint40 previousMilestone, uint40 currentMilestone + /// @notice Thrown when trying to create a stream with unordered segment timestampts. + error SablierV2LockupDynamic_SegmentTimestampsNotOrdered( + uint256 index, uint40 previousTimestamp, uint40 currentTimestamp ); /// @notice Thrown when trying to create a stream with a start time not strictly less than the first - /// segment milestone. - error SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentMilestone( - uint40 startTime, uint40 firstSegmentMilestone + /// segment timestamp. + error SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentTimestamp( + uint40 startTime, uint40 firstSegmentTimestamp ); /*////////////////////////////////////////////////////////////////////////// diff --git a/src/libraries/Helpers.sol b/src/libraries/Helpers.sol index 319cc28b9..73ee41f34 100644 --- a/src/libraries/Helpers.sol +++ b/src/libraries/Helpers.sol @@ -109,34 +109,34 @@ library Helpers { } } - /// @dev Checks that the segment array counts match, and then adjusts the segments by calculating the milestones. - function checkDeltasAndCalculateMilestones(LockupDynamic.SegmentWithDelta[] memory segments) + /// @dev Checks that the segment array counts match, and then adjusts the segments by calculating the timestamps. + function checkDurationsAndCalculateTimestamps(LockupDynamic.SegmentWithDuration[] memory segments) internal view - returns (LockupDynamic.Segment[] memory segmentsWithMilestones) + returns (LockupDynamic.Segment[] memory segmentsWithTimestamps) { uint256 segmentCount = segments.length; - segmentsWithMilestones = new LockupDynamic.Segment[](segmentCount); + segmentsWithTimestamps = new LockupDynamic.Segment[](segmentCount); // Make the current time the stream's start time. uint40 startTime = uint40(block.timestamp); - // It is safe to use unchecked arithmetic because {_createWithMilestone} will nonetheless check the soundness - // of the calculated segment milestones. + // It is safe to use unchecked arithmetic because {_createWithTimestamps} will nonetheless check the soundness + // of the calculated segment timestamps. unchecked { - // Precompute the first segment because of the need to add the start time to the first segment delta. - segmentsWithMilestones[0] = LockupDynamic.Segment({ + // Precompute the first segment because of the need to add the start time to the first segment duration. + segmentsWithTimestamps[0] = LockupDynamic.Segment({ amount: segments[0].amount, exponent: segments[0].exponent, - milestone: startTime + segments[0].delta + timestamp: startTime + segments[0].duration }); - // Copy the segment amounts and exponents, and calculate the segment milestones. + // Copy the segment amounts and exponents, and calculate the segment timestamps. for (uint256 i = 1; i < segmentCount; ++i) { - segmentsWithMilestones[i] = LockupDynamic.Segment({ + segmentsWithTimestamps[i] = LockupDynamic.Segment({ amount: segments[i].amount, exponent: segments[i].exponent, - milestone: segmentsWithMilestones[i - 1].milestone + segments[i].delta + timestamp: segmentsWithTimestamps[i - 1].timestamp + segments[i].duration }); } } @@ -148,9 +148,9 @@ library Helpers { /// @dev Checks that: /// - /// 1. The first milestone is strictly greater than the start time. - /// 2. The milestones are ordered chronologically. - /// 3. There are no duplicate milestones. + /// 1. The first timestamp is strictly greater than the start time. + /// 2. The timestamps are ordered chronologically. + /// 3. There are no duplicate timestamps. /// 4. The deposit amount is equal to the sum of all segment amounts. function _checkSegments( LockupDynamic.Segment[] memory segments, @@ -160,44 +160,44 @@ library Helpers { private view { - // Checks: the start time is strictly less than the first segment milestone. - if (startTime >= segments[0].milestone) { - revert Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentMilestone( - startTime, segments[0].milestone + // Checks: the start time is strictly less than the first segment timestamp. + if (startTime >= segments[0].timestamp) { + revert Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentTimestamp( + startTime, segments[0].timestamp ); } // Pre-declare the variables needed in the for loop. uint128 segmentAmountsSum; - uint40 currentMilestone; - uint40 previousMilestone; + uint40 currentTimestamp; + uint40 previousTimestamp; // Iterate over the segments to: // // 1. Calculate the sum of all segment amounts. - // 2. Check that the milestones are ordered. + // 2. Check that the timestamps are ordered. uint256 count = segments.length; for (uint256 index = 0; index < count; ++index) { // Add the current segment amount to the sum. segmentAmountsSum += segments[index].amount; - // Checks: the current milestone is strictly greater than the previous milestone. - currentMilestone = segments[index].milestone; - if (currentMilestone <= previousMilestone) { - revert Errors.SablierV2LockupDynamic_SegmentMilestonesNotOrdered( - index, previousMilestone, currentMilestone + // Checks: the current timestamp is strictly greater than the previous timestamp. + currentTimestamp = segments[index].timestamp; + if (currentTimestamp <= previousTimestamp) { + revert Errors.SablierV2LockupDynamic_SegmentTimestampsNotOrdered( + index, previousTimestamp, currentTimestamp ); } - // Make the current milestone the previous milestone of the next loop iteration. - previousMilestone = currentMilestone; + // Make the current timestamp the previous timestamp of the next loop iteration. + previousTimestamp = currentTimestamp; } - // Checks: the last milestone is in the future. - // When the loop exits, the current milestone is the last milestone, i.e. the stream's end time. + // Checks: the last timestamp is in the future. + // When the loop exits, the current timestamp is the last timestamp, i.e. the stream's end time. uint40 currentTime = uint40(block.timestamp); - if (currentTime >= currentMilestone) { - revert Errors.SablierV2Lockup_EndTimeNotInTheFuture(currentTime, currentMilestone); + if (currentTime >= currentTimestamp) { + revert Errors.SablierV2Lockup_EndTimeNotInTheFuture(currentTime, currentTimestamp); } // Checks: the deposit amount is equal to the segment amounts sum. diff --git a/src/types/DataTypes.sol b/src/types/DataTypes.sol index 1a9337a04..543e8de4e 100644 --- a/src/types/DataTypes.sol +++ b/src/types/DataTypes.sol @@ -79,8 +79,8 @@ library LockupDynamic { /// @param asset The contract address of the ERC-20 asset used for streaming. /// @param cancelable Indicates if the stream is cancelable. /// @param transferable Indicates if the stream NFT is transferable. - /// @param segments Segments with deltas used to compose the custom streaming curve. Milestones are calculated by - /// starting from `block.timestamp` and adding each delta to the previous milestone. + /// @param segments Segments with durations used to compose the custom streaming curve. Timestamps are calculated by + /// starting from `block.timestamp` and adding each duration to the previous timestamp. /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero. struct CreateWithDurations { @@ -90,7 +90,7 @@ library LockupDynamic { IERC20 asset; bool cancelable; bool transferable; - SegmentWithDelta[] segments; + SegmentWithDuration[] segments; Broker broker; } @@ -131,22 +131,22 @@ library LockupDynamic { /// @notice Segment struct used in the Lockup Dynamic stream. /// @param amount The amount of assets to be streamed in this segment, denoted in units of the asset's decimals. /// @param exponent The exponent of this segment, denoted as a fixed-point number. - /// @param milestone The Unix timestamp indicating this segment's end. + /// @param timestamp The Unix timestamp indicating this segment's end. struct Segment { // slot 0 uint128 amount; UD2x18 exponent; - uint40 milestone; + uint40 timestamp; } /// @notice Segment struct used at runtime in {SablierV2LockupDynamic.createWithDurations}. /// @param amount The amount of assets to be streamed in this segment, denoted in units of the asset's decimals. /// @param exponent The exponent of this segment, denoted as a fixed-point number. - /// @param delta The time difference in seconds between this segment and the previous one. - struct SegmentWithDelta { + /// @param duration The time difference in seconds between this segment and the previous one. + struct SegmentWithDuration { uint128 amount; UD2x18 exponent; - uint40 delta; + uint40 duration; } /// @notice Lockup Dynamic stream. diff --git a/test/fork/LockupDynamic.t.sol b/test/fork/LockupDynamic.t.sol index 4e7b0c2de..931e565a0 100644 --- a/test/fork/LockupDynamic.t.sol +++ b/test/fork/LockupDynamic.t.sol @@ -109,7 +109,7 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test { /// - Start time in the past /// - Start time in the present /// - Start time in the future - /// - Start time equal and not equal to the first segment milestone + /// - Start time equal and not equal to the first segment timestamp /// - Multiple values for the broker fee, including zero /// - Multiple values for the protocol fee, including zero /// - Multiple values for the withdraw amount, including zero @@ -122,8 +122,8 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test { params.startTime = boundUint40(params.startTime, 0, defaults.START_TIME()); params.transferable = true; - // Fuzz the segment milestones. - fuzzSegmentMilestones(params.segments, params.startTime); + // Fuzz the segment timestamps. + fuzzSegmentTimestamps(params.segments, params.startTime); // Fuzz the segment amounts and calculate the create amounts (total, deposit, protocol fee, and broker fee). Vars memory vars; @@ -156,7 +156,7 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test { vars.streamId = lockupDynamic.nextStreamId(); vars.range = - LockupDynamic.Range({ start: params.startTime, end: params.segments[params.segments.length - 1].milestone }); + LockupDynamic.Range({ start: params.startTime, end: params.segments[params.segments.length - 1].timestamp }); // Expect the relevant events to be emitted. vm.expectEmit({ emitter: address(lockupDynamic) }); diff --git a/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.t.sol b/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.t.sol index aeac29e30..bf8b3823c 100644 --- a/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.t.sol +++ b/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.t.sol @@ -34,81 +34,84 @@ contract CreateWithDurations_LockupDynamic_Integration_Concrete_Test is /// @dev it should revert. function test_RevertWhen_LoopCalculationOverflowsBlockGasLimit() external whenNotDelegateCalled { - LockupDynamic.SegmentWithDelta[] memory segments = new LockupDynamic.SegmentWithDelta[](250_000); + LockupDynamic.SegmentWithDuration[] memory segments = new LockupDynamic.SegmentWithDuration[](250_000); vm.expectRevert(bytes("")); - createDefaultStreamWithDeltas(segments); + createDefaultStreamWithDurations(segments); } - function test_RevertWhen_DeltasZero() + function test_RevertWhen_DurationsZero() external whenNotDelegateCalled whenLoopCalculationsDoNotOverflowBlockGasLimit { uint40 startTime = getBlockTimestamp(); - LockupDynamic.SegmentWithDelta[] memory segments = defaults.createWithDurationsLD().segments; - segments[1].delta = 0; + LockupDynamic.SegmentWithDuration[] memory segments = defaults.createWithDurationsLD().segments; + segments[1].duration = 0; uint256 index = 1; vm.expectRevert( abi.encodeWithSelector( - Errors.SablierV2LockupDynamic_SegmentMilestonesNotOrdered.selector, + Errors.SablierV2LockupDynamic_SegmentTimestampsNotOrdered.selector, index, - startTime + segments[0].delta, - startTime + segments[0].delta + startTime + segments[0].duration, + startTime + segments[0].duration ) ); - createDefaultStreamWithDeltas(segments); + createDefaultStreamWithDurations(segments); } - function test_RevertWhen_MilestonesCalculationsOverflows_StartTimeNotLessThanFirstSegmentMilestone() + function test_RevertWhen_TimestampsCalculationsOverflows_StartTimeNotLessThanFirstSegmentTimestamp() external whenNotDelegateCalled whenLoopCalculationsDoNotOverflowBlockGasLimit - whenDeltasNotZero + whenDurationsNotZero { unchecked { uint40 startTime = getBlockTimestamp(); - LockupDynamic.SegmentWithDelta[] memory segments = defaults.createWithDurationsLD().segments; - segments[0].delta = MAX_UINT40; + LockupDynamic.SegmentWithDuration[] memory segments = defaults.createWithDurationsLD().segments; + segments[0].duration = MAX_UINT40; vm.expectRevert( abi.encodeWithSelector( - Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentMilestone.selector, + Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentTimestamp.selector, startTime, - startTime + segments[0].delta + startTime + segments[0].duration ) ); - createDefaultStreamWithDeltas(segments); + createDefaultStreamWithDurations(segments); } } - function test_RevertWhen_MilestonesCalculationsOverflows_SegmentMilestonesNotOrdered() + function test_RevertWhen_TimestampsCalculationsOverflows_SegmentTimestampsNotOrdered() external whenNotDelegateCalled whenLoopCalculationsDoNotOverflowBlockGasLimit - whenDeltasNotZero + whenDurationsNotZero { unchecked { uint40 startTime = getBlockTimestamp(); - // Create new segments that overflow when the milestones are eventually calculated. - LockupDynamic.SegmentWithDelta[] memory segments = new LockupDynamic.SegmentWithDelta[](2); - segments[0] = - LockupDynamic.SegmentWithDelta({ amount: 0, exponent: ud2x18(1e18), delta: startTime + 1 seconds }); - segments[1] = defaults.segmentsWithDeltas()[0]; - segments[1].delta = MAX_UINT40; + // Create new segments that overflow when the timestamps are eventually calculated. + LockupDynamic.SegmentWithDuration[] memory segments = new LockupDynamic.SegmentWithDuration[](2); + segments[0] = LockupDynamic.SegmentWithDuration({ + amount: 0, + exponent: ud2x18(1e18), + duration: startTime + 1 seconds + }); + segments[1] = defaults.segmentsWithDurations()[0]; + segments[1].duration = MAX_UINT40; // Expect the relevant error to be thrown. uint256 index = 1; vm.expectRevert( abi.encodeWithSelector( - Errors.SablierV2LockupDynamic_SegmentMilestonesNotOrdered.selector, + Errors.SablierV2LockupDynamic_SegmentTimestampsNotOrdered.selector, index, - startTime + segments[0].delta, - startTime + segments[0].delta + segments[1].delta + startTime + segments[0].duration, + startTime + segments[0].duration + segments[1].duration ) ); // Create the stream. - createDefaultStreamWithDeltas(segments); + createDefaultStreamWithDurations(segments); } } @@ -116,8 +119,8 @@ contract CreateWithDurations_LockupDynamic_Integration_Concrete_Test is external whenNotDelegateCalled whenLoopCalculationsDoNotOverflowBlockGasLimit - whenDeltasNotZero - whenMilestonesCalculationsDoNotOverflow + whenDurationsNotZero + whenTimestampsCalculationsDoNotOverflow { // Make the Sender the stream's funder address funder = users.sender; @@ -131,10 +134,10 @@ contract CreateWithDurations_LockupDynamic_Integration_Concrete_Test is LockupDynamic.Range({ start: currentTime, end: currentTime + defaults.TOTAL_DURATION() }); // Adjust the segments. - LockupDynamic.SegmentWithDelta[] memory segmentsWithDeltas = defaults.segmentsWithDeltas(); + LockupDynamic.SegmentWithDuration[] memory segmentsWithDurations = defaults.segmentsWithDurations(); LockupDynamic.Segment[] memory segments = defaults.segments(); - segments[0].milestone = range.start + segmentsWithDeltas[0].delta; - segments[1].milestone = segments[0].milestone + segmentsWithDeltas[1].delta; + segments[0].timestamp = range.start + segmentsWithDurations[0].duration; + segments[1].timestamp = segments[0].timestamp + segmentsWithDurations[1].duration; // Expect the assets to be transferred from the funder to {SablierV2LockupDynamic}. expectCallToTransferFrom({ @@ -165,7 +168,7 @@ contract CreateWithDurations_LockupDynamic_Integration_Concrete_Test is }); // Create the stream. - createDefaultStreamWithDeltas(); + createDefaultStreamWithDurations(); // Assert that the stream has been created. LockupDynamic.Stream memory actualStream = lockupDynamic.getStream(streamId); diff --git a/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.tree b/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.tree index e3a5c988a..e1fa7ae20 100644 --- a/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.tree +++ b/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.tree @@ -5,15 +5,15 @@ createWithDurations.t.sol ├── when the loop calculations overflow the block gas limit │ └── it should revert └── when the loop calculations do not overflow the block gas limit - ├── when at least one of the deltas at index one or greater is zero + ├── when at least one of the durations at index one or greater is zero │ └── it should revert - └── when none of the deltas is zero - ├── when the segment milestone calculations overflow uint256 - │ ├── when the start time is not less than the first segment milestone + └── when none of the durations is zero + ├── when the segment timestamp calculations overflow uint256 + │ ├── when the start time is not less than the first segment timestamp │ │ └── it should revert - │ └── when the segment milestones are not ordered + │ └── when the segment timestamps are not ordered │ └── it should revert - └── when the segment milestone calculations do not overflow uint256 + └── when the segment timestamp calculations do not overflow uint256 ├── it should create the stream ├── it should bump the next stream id ├── it should record the protocol fee diff --git a/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.t.sol b/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.t.sol index b39b7251a..f7842897b 100644 --- a/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.t.sol +++ b/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.t.sol @@ -87,7 +87,7 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is createDefaultStreamWithSegments(segments); } - function test_RevertWhen_StartTimeGreaterThanFirstSegmentMilestone() + function test_RevertWhen_StartTimeGreaterThanFirstSegmentTimestamp() external whenNotDelegateCalled whenRecipientNonZeroAddress @@ -96,16 +96,16 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow { - // Change the milestone of the first segment. + // Change the timestamp of the first segment. LockupDynamic.Segment[] memory segments = defaults.segments(); - segments[0].milestone = defaults.START_TIME() - 1 seconds; + segments[0].timestamp = defaults.START_TIME() - 1 seconds; // Expect the relevant error to be thrown. vm.expectRevert( abi.encodeWithSelector( - Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentMilestone.selector, + Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentTimestamp.selector, defaults.START_TIME(), - segments[0].milestone + segments[0].timestamp ) ); @@ -113,7 +113,7 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is createDefaultStreamWithSegments(segments); } - function test_RevertWhen_StartTimeEqualToFirstSegmentMilestone() + function test_RevertWhen_StartTimeEqualToFirstSegmentTimestamp() external whenNotDelegateCalled whenRecipientNonZeroAddress @@ -122,16 +122,16 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow { - // Change the milestone of the first segment. + // Change the timestamp of the first segment. LockupDynamic.Segment[] memory segments = defaults.segments(); - segments[0].milestone = defaults.START_TIME(); + segments[0].timestamp = defaults.START_TIME(); // Expect the relevant error to be thrown. vm.expectRevert( abi.encodeWithSelector( - Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentMilestone.selector, + Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentTimestamp.selector, defaults.START_TIME(), - segments[0].milestone + segments[0].timestamp ) ); @@ -139,7 +139,7 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is createDefaultStreamWithSegments(segments); } - function test_RevertWhen_SegmentMilestonesNotOrdered() + function test_RevertWhen_SegmentTimestampsNotOrdered() external whenNotDelegateCalled whenRecipientNonZeroAddress @@ -147,20 +147,20 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone + whenStartTimeLessThanFirstSegmentTimestamp { - // Swap the segment milestones. + // Swap the segment timestamps. LockupDynamic.Segment[] memory segments = defaults.segments(); - (segments[0].milestone, segments[1].milestone) = (segments[1].milestone, segments[0].milestone); + (segments[0].timestamp, segments[1].timestamp) = (segments[1].timestamp, segments[0].timestamp); // Expect the relevant error to be thrown. uint256 index = 1; vm.expectRevert( abi.encodeWithSelector( - Errors.SablierV2LockupDynamic_SegmentMilestonesNotOrdered.selector, + Errors.SablierV2LockupDynamic_SegmentTimestampsNotOrdered.selector, index, - segments[0].milestone, - segments[1].milestone + segments[0].timestamp, + segments[1].timestamp ) ); @@ -176,8 +176,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered { uint40 endTime = defaults.END_TIME(); vm.warp({ timestamp: endTime }); @@ -193,8 +193,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture { // Disable both the protocol and the broker fee so that they don't interfere with the calculations. @@ -233,8 +233,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum { @@ -260,8 +260,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh @@ -279,8 +279,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh @@ -307,8 +307,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh @@ -326,8 +326,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh diff --git a/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.tree b/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.tree index 6debf4ca6..ee1418596 100644 --- a/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.tree +++ b/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.tree @@ -17,14 +17,14 @@ createWithTimestamps.t.sol ├── when the segment amounts sum overflows │ └── it should revert └── when the segment amounts sum does not overflow - ├── when the start time is greater than the first segment milestone + ├── when the start time is greater than the first segment timestamp │ └── it should revert - ├── when the start time is equal to the first segment milestone + ├── when the start time is equal to the first segment timestamp │ └── it should revert - └── when the start time is less than the first segment milestone - ├── when the segment milestones are not ordered + └── when the start time is less than the first segment timestamp + ├── when the segment timestamps are not ordered │ └── it should revert - └── when the segment milestones are ordered + └── when the segment timestamps are ordered ├── when the end time is not in the future │ └── it should revert └── when the end time is in the future diff --git a/test/integration/concrete/lockup-dynamic/streamed-amount-of/streamedAmountOf.t.sol b/test/integration/concrete/lockup-dynamic/streamed-amount-of/streamedAmountOf.t.sol index 040dd310b..f1d8ab14f 100644 --- a/test/integration/concrete/lockup-dynamic/streamed-amount-of/streamedAmountOf.t.sol +++ b/test/integration/concrete/lockup-dynamic/streamed-amount-of/streamedAmountOf.t.sol @@ -58,7 +58,7 @@ contract StreamedAmountOf_LockupDynamic_Integration_Concrete_Test is segments[0] = LockupDynamic.Segment({ amount: defaults.DEPOSIT_AMOUNT(), exponent: defaults.segments()[1].exponent, - milestone: defaults.END_TIME() + timestamp: defaults.END_TIME() }); // Create the stream. @@ -74,7 +74,7 @@ contract StreamedAmountOf_LockupDynamic_Integration_Concrete_Test is _; } - function test_StreamedAmountOf_CurrentMilestone1st() + function test_StreamedAmountOf_CurrentTimestamp1st() external givenNotNull givenStreamHasNotBeenCanceled @@ -91,18 +91,18 @@ contract StreamedAmountOf_LockupDynamic_Integration_Concrete_Test is assertEq(actualStreamedAmount, expectedStreamedAmount, "streamedAmount"); } - modifier givenCurrentMilestoneNot1st() { + modifier givenCurrentTimestampNot1st() { _; } - function test_StreamedAmountOf_CurrentMilestoneNot1st() + function test_StreamedAmountOf_CurrentTimestampNot1st() external givenNotNull givenStreamHasNotBeenCanceled givenStatusStreaming whenStartTimeInThePast givenMultipleSegments - givenCurrentMilestoneNot1st + givenCurrentTimestampNot1st { // Simulate the passage of time. 750 seconds is ~10% of the way in the second segment. vm.warp({ timestamp: defaults.START_TIME() + defaults.CLIFF_DURATION() + 750 seconds }); diff --git a/test/integration/concrete/lockup-dynamic/streamed-amount-of/streamedAmountOf.tree b/test/integration/concrete/lockup-dynamic/streamed-amount-of/streamedAmountOf.tree index 50815136d..8a231f4a0 100644 --- a/test/integration/concrete/lockup-dynamic/streamed-amount-of/streamedAmountOf.tree +++ b/test/integration/concrete/lockup-dynamic/streamed-amount-of/streamedAmountOf.tree @@ -8,7 +8,7 @@ streamedAmountOf.t.sol ├── given there is one segment │ └── it should return the correct streamed amount └── given there are multiple segments - ├── given the current milestone is the 1st in the array + ├── given the current timestamp is the 1st in the array │ └── it should return the correct streamed amount - └── given the current milestone is not the 1st in the array + └── given the current timestamp is not the 1st in the array └── it should return the correct streamed amount diff --git a/test/integration/fuzz/lockup-dynamic/createWithDurations.t.sol b/test/integration/fuzz/lockup-dynamic/createWithDurations.t.sol index 81d7ca19c..4285a8034 100644 --- a/test/integration/fuzz/lockup-dynamic/createWithDurations.t.sol +++ b/test/integration/fuzz/lockup-dynamic/createWithDurations.t.sol @@ -33,22 +33,22 @@ contract CreateWithDurations_LockupDynamic_Integration_Fuzz_Test is uint128 initialProtocolRevenues; bool isCancelable; bool isSettled; - LockupDynamic.Segment[] segmentsWithMilestones; + LockupDynamic.Segment[] segmentsWithTimestamps; uint128 totalAmount; } - function testFuzz_CreateWithDurations(LockupDynamic.SegmentWithDelta[] memory segments) + function testFuzz_CreateWithDurations(LockupDynamic.SegmentWithDuration[] memory segments) external whenNotDelegateCalled whenLoopCalculationsDoNotOverflowBlockGasLimit - whenDeltasNotZero - whenMilestonesCalculationsDoNotOverflow + whenDurationsNotZero + whenTimestampsCalculationsDoNotOverflow { vm.assume(segments.length != 0); - // Fuzz the deltas. + // Fuzz the durations. Vars memory vars; - fuzzSegmentDeltas(segments); + fuzzSegmentDurations(segments); // Fuzz the segment amounts and calculate the create amounts (total, deposit, protocol fee, and broker fee). (vars.totalAmount, vars.createAmounts) = fuzzDynamicStreamAmounts(segments); @@ -75,10 +75,10 @@ contract CreateWithDurations_LockupDynamic_Integration_Fuzz_Test is } // Create the range struct. - vars.segmentsWithMilestones = getSegmentsWithMilestones(segments); + vars.segmentsWithTimestamps = getSegmentsWithTimestamps(segments); LockupDynamic.Range memory range = LockupDynamic.Range({ start: getBlockTimestamp(), - end: vars.segmentsWithMilestones[vars.segmentsWithMilestones.length - 1].milestone + end: vars.segmentsWithTimestamps[vars.segmentsWithTimestamps.length - 1].timestamp }); // Expect the relevant event to be emitted. @@ -92,7 +92,7 @@ contract CreateWithDurations_LockupDynamic_Integration_Fuzz_Test is asset: dai, cancelable: true, transferable: true, - segments: vars.segmentsWithMilestones, + segments: vars.segmentsWithTimestamps, range: range, broker: users.broker }); @@ -118,7 +118,7 @@ contract CreateWithDurations_LockupDynamic_Integration_Fuzz_Test is assertEq(actualStream.isTransferable, true, "isTransferable"); assertEq(actualStream.isDepleted, false, "isDepleted"); assertEq(actualStream.isStream, true, "isStream"); - assertEq(actualStream.segments, vars.segmentsWithMilestones, "segments"); + assertEq(actualStream.segments, vars.segmentsWithTimestamps, "segments"); assertEq(actualStream.sender, users.sender, "sender"); assertEq(actualStream.startTime, range.start, "startTime"); assertEq(actualStream.wasCanceled, false, "wasCanceled"); diff --git a/test/integration/fuzz/lockup-dynamic/createWithTimestamps.t.sol b/test/integration/fuzz/lockup-dynamic/createWithTimestamps.t.sol index 0bf50c093..16909789f 100644 --- a/test/integration/fuzz/lockup-dynamic/createWithTimestamps.t.sol +++ b/test/integration/fuzz/lockup-dynamic/createWithTimestamps.t.sol @@ -58,7 +58,7 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Fuzz_Test is createDefaultStreamWithSegments(segments); } - function testFuzz_RevertWhen_StartTimeNotLessThanFirstSegmentMilestone(uint40 firstMilestone) + function testFuzz_RevertWhen_StartTimeNotLessThanFirstSegmentTimestamp(uint40 firstTimestamp) external whenNotDelegateCalled whenRecipientNonZeroAddress @@ -67,18 +67,18 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Fuzz_Test is whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow { - firstMilestone = boundUint40(firstMilestone, 0, defaults.START_TIME()); + firstTimestamp = boundUint40(firstTimestamp, 0, defaults.START_TIME()); - // Change the milestone of the first segment. + // Change the timestamp of the first segment. LockupDynamic.Segment[] memory segments = defaults.segments(); - segments[0].milestone = firstMilestone; + segments[0].timestamp = firstTimestamp; // Expect the relevant error to be thrown. vm.expectRevert( abi.encodeWithSelector( - Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentMilestone.selector, + Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentTimestamp.selector, defaults.START_TIME(), - segments[0].milestone + segments[0].timestamp ) ); @@ -94,8 +94,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Fuzz_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture { depositDiff = boundUint128(depositDiff, 100, defaults.TOTAL_AMOUNT()); @@ -136,8 +136,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Fuzz_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum { @@ -163,8 +163,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Fuzz_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh @@ -193,12 +193,12 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Fuzz_Test is /// @dev Given enough fuzz runs, all of the following scenarios will be fuzzed: /// /// - All possible permutations for the funder, sender, recipient, and broker - /// - Multiple values for the segment amounts, exponents, and milestones + /// - Multiple values for the segment amounts, exponents, and timestamps /// - Cancelable and not cancelable /// - Start time in the past /// - Start time in the present /// - Start time in the future - /// - Start time equal and not equal to the first segment milestone + /// - Start time equal and not equal to the first segment timestamp /// - Multiple values for the broker fee, including zero /// - Multiple values for the protocol fee, including zero function testFuzz_CreateWithTimestamps( @@ -213,8 +213,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Fuzz_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh @@ -229,8 +229,8 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Fuzz_Test is params.startTime = boundUint40(params.startTime, 0, defaults.START_TIME()); params.transferable = true; - // Fuzz the segment milestones. - fuzzSegmentMilestones(params.segments, params.startTime); + // Fuzz the segment timestamps. + fuzzSegmentTimestamps(params.segments, params.startTime); // Fuzz the segment amounts and calculate the create amounts (total, deposit, protocol fee, and broker fee). Vars memory vars; @@ -269,7 +269,7 @@ contract CreateWithTimestamps_LockupDynamic_Integration_Fuzz_Test is // Expect the relevant event to be emitted. vm.expectEmit({ emitter: address(lockupDynamic) }); LockupDynamic.Range memory range = - LockupDynamic.Range({ start: params.startTime, end: params.segments[params.segments.length - 1].milestone }); + LockupDynamic.Range({ start: params.startTime, end: params.segments[params.segments.length - 1].timestamp }); emit CreateLockupDynamicStream({ streamId: streamId, funder: funder, diff --git a/test/integration/fuzz/lockup-dynamic/streamedAmountOf.t.sol b/test/integration/fuzz/lockup-dynamic/streamedAmountOf.t.sol index 567b8f587..a0068d4e8 100644 --- a/test/integration/fuzz/lockup-dynamic/streamedAmountOf.t.sol +++ b/test/integration/fuzz/lockup-dynamic/streamedAmountOf.t.sol @@ -42,7 +42,7 @@ contract StreamedAmountOf_LockupDynamic_Integration_Fuzz_Test is whenStartTimeInThePast { vm.assume(segment.amount != 0); - segment.milestone = boundUint40(segment.milestone, defaults.CLIFF_TIME(), defaults.END_TIME()); + segment.timestamp = boundUint40(segment.timestamp, defaults.CLIFF_TIME(), defaults.END_TIME()); timeJump = boundUint40(timeJump, defaults.CLIFF_DURATION(), defaults.TOTAL_DURATION() * 2); // Create the single-segment array. @@ -73,7 +73,7 @@ contract StreamedAmountOf_LockupDynamic_Integration_Fuzz_Test is _; } - modifier whenCurrentMilestoneNot1st() { + modifier whenCurrentTimestampNot1st() { _; } @@ -94,12 +94,12 @@ contract StreamedAmountOf_LockupDynamic_Integration_Fuzz_Test is givenStreamHasNotBeenCanceled whenStartTimeInThePast givenMultipleSegments - whenCurrentMilestoneNot1st + whenCurrentTimestampNot1st { vm.assume(segments.length > 1); - // Fuzz the segment milestones. - fuzzSegmentMilestones(segments, defaults.START_TIME()); + // Fuzz the segment timestamps. + fuzzSegmentTimestamps(segments, defaults.START_TIME()); // Fuzz the segment amounts. (uint128 totalAmount,) = fuzzDynamicStreamAmounts({ @@ -110,8 +110,8 @@ contract StreamedAmountOf_LockupDynamic_Integration_Fuzz_Test is }); // Bound the time jump. - uint40 firstSegmentDuration = segments[1].milestone - segments[0].milestone; - uint40 totalDuration = segments[segments.length - 1].milestone - defaults.START_TIME(); + uint40 firstSegmentDuration = segments[1].timestamp - segments[0].timestamp; + uint40 totalDuration = segments[segments.length - 1].timestamp - defaults.START_TIME(); timeJump = boundUint40(timeJump, firstSegmentDuration, totalDuration + 100 seconds); // Mint enough assets to the Sender. @@ -145,12 +145,12 @@ contract StreamedAmountOf_LockupDynamic_Integration_Fuzz_Test is givenStreamHasNotBeenCanceled whenStartTimeInThePast givenMultipleSegments - whenCurrentMilestoneNot1st + whenCurrentTimestampNot1st { vm.assume(segments.length > 1); - // Fuzz the segment milestones. - fuzzSegmentMilestones(segments, defaults.START_TIME()); + // Fuzz the segment timestamps. + fuzzSegmentTimestamps(segments, defaults.START_TIME()); // Fuzz the segment amounts. (uint128 totalAmount,) = fuzzDynamicStreamAmounts({ @@ -161,8 +161,8 @@ contract StreamedAmountOf_LockupDynamic_Integration_Fuzz_Test is }); // Bound the time warps. - uint40 firstSegmentDuration = segments[1].milestone - segments[0].milestone; - uint40 totalDuration = segments[segments.length - 1].milestone - defaults.START_TIME(); + uint40 firstSegmentDuration = segments[1].timestamp - segments[0].timestamp; + uint40 totalDuration = segments[segments.length - 1].timestamp - defaults.START_TIME(); timeWarp0 = boundUint40(timeWarp0, firstSegmentDuration, totalDuration - 1); timeWarp1 = boundUint40(timeWarp1, timeWarp0, totalDuration); diff --git a/test/integration/fuzz/lockup-dynamic/withdraw.t.sol b/test/integration/fuzz/lockup-dynamic/withdraw.t.sol index 379e3bc08..6af9bcb96 100644 --- a/test/integration/fuzz/lockup-dynamic/withdraw.t.sol +++ b/test/integration/fuzz/lockup-dynamic/withdraw.t.sol @@ -56,14 +56,14 @@ contract Withdraw_LockupDynamic_Integration_Fuzz_Test is Vars memory vars; vars.funder = users.sender; - // Fuzz the segment milestones. - fuzzSegmentMilestones(params.segments, defaults.START_TIME()); + // Fuzz the segment timestamps. + fuzzSegmentTimestamps(params.segments, defaults.START_TIME()); // Fuzz the segment amounts. (vars.totalAmount, vars.createAmounts) = fuzzDynamicStreamAmounts(params.segments); // Bound the time jump. - vars.totalDuration = params.segments[params.segments.length - 1].milestone - defaults.START_TIME(); + vars.totalDuration = params.segments[params.segments.length - 1].timestamp - defaults.START_TIME(); params.timeJump = _bound(params.timeJump, 1 seconds, vars.totalDuration + 100 seconds); // Mint enough assets to the funder. diff --git a/test/integration/shared/lockup-dynamic/LockupDynamic.t.sol b/test/integration/shared/lockup-dynamic/LockupDynamic.t.sol index 046b1af22..b67bf3aa4 100644 --- a/test/integration/shared/lockup-dynamic/LockupDynamic.t.sol +++ b/test/integration/shared/lockup-dynamic/LockupDynamic.t.sol @@ -39,10 +39,10 @@ abstract contract LockupDynamic_Integration_Shared_Test is Lockup_Integration_Sh _params.createWithTimestamps.broker = defaults.broker(); // See https://github.com/ethereum/solidity/issues/12783 - LockupDynamic.SegmentWithDelta[] memory segmentsWithDeltas = defaults.segmentsWithDeltas(); + LockupDynamic.SegmentWithDuration[] memory segmentsWithDurations = defaults.segmentsWithDurations(); LockupDynamic.Segment[] memory segments = defaults.segments(); for (uint256 i = 0; i < defaults.SEGMENT_COUNT(); ++i) { - _params.createWithDurations.segments.push(segmentsWithDeltas[i]); + _params.createWithDurations.segments.push(segmentsWithDurations[i]); _params.createWithTimestamps.segments.push(segments[i]); } } @@ -66,13 +66,13 @@ abstract contract LockupDynamic_Integration_Shared_Test is Lockup_Integration_Sh streamId = lockupDynamic.createWithTimestamps(params); } - /// @dev Creates the default stream with deltas. - function createDefaultStreamWithDeltas() internal returns (uint256 streamId) { + /// @dev Creates the default stream with durations. + function createDefaultStreamWithDurations() internal returns (uint256 streamId) { streamId = lockupDynamic.createWithDurations(_params.createWithDurations); } - /// @dev Creates the default stream with the provided deltas. - function createDefaultStreamWithDeltas(LockupDynamic.SegmentWithDelta[] memory segments) + /// @dev Creates the default stream with the provided durations. + function createDefaultStreamWithDurations(LockupDynamic.SegmentWithDuration[] memory segments) internal returns (uint256 streamId) { @@ -84,7 +84,7 @@ abstract contract LockupDynamic_Integration_Shared_Test is Lockup_Integration_Sh /// @dev Creates the default stream with the provided end time. function createDefaultStreamWithEndTime(uint40 endTime) internal override returns (uint256 streamId) { LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; - params.segments[1].milestone = endTime; + params.segments[1].timestamp = endTime; streamId = lockupDynamic.createWithTimestamps(params); } @@ -106,7 +106,7 @@ abstract contract LockupDynamic_Integration_Shared_Test is Lockup_Integration_Sh function createDefaultStreamWithRange(LockupDynamic.Range memory range) internal returns (uint256 streamId) { LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.startTime = range.start; - params.segments[1].milestone = range.end; + params.segments[1].timestamp = range.end; streamId = lockupDynamic.createWithTimestamps(params); } diff --git a/test/integration/shared/lockup-dynamic/createWithDurations.t.sol b/test/integration/shared/lockup-dynamic/createWithDurations.t.sol index b9687b7a1..31460ec2b 100644 --- a/test/integration/shared/lockup-dynamic/createWithDurations.t.sol +++ b/test/integration/shared/lockup-dynamic/createWithDurations.t.sol @@ -18,11 +18,11 @@ contract CreateWithDurations_Integration_Shared_Test is LockupDynamic_Integratio _; } - modifier whenDeltasNotZero() { + modifier whenDurationsNotZero() { _; } - modifier whenMilestonesCalculationsDoNotOverflow() { + modifier whenTimestampsCalculationsDoNotOverflow() { _; } } diff --git a/test/integration/shared/lockup-dynamic/createWithTimestamps.t.sol b/test/integration/shared/lockup-dynamic/createWithTimestamps.t.sol index 3027fdb8e..574f79390 100644 --- a/test/integration/shared/lockup-dynamic/createWithTimestamps.t.sol +++ b/test/integration/shared/lockup-dynamic/createWithTimestamps.t.sol @@ -34,11 +34,11 @@ contract CreateWithTimestamps_Integration_Shared_Test is LockupDynamic_Integrati _; } - modifier whenStartTimeLessThanFirstSegmentMilestone() { + modifier whenStartTimeLessThanFirstSegmentTimestamp() { _; } - modifier whenSegmentMilestonesOrdered() { + modifier whenSegmentTimestampsOrdered() { _; } diff --git a/test/integration/shared/lockup-linear/LockupLinear.t.sol b/test/integration/shared/lockup-linear/LockupLinear.t.sol index 87315c0fa..1fe86adbf 100644 --- a/test/integration/shared/lockup-linear/LockupLinear.t.sol +++ b/test/integration/shared/lockup-linear/LockupLinear.t.sol @@ -79,13 +79,10 @@ abstract contract LockupLinear_Integration_Shared_Test is Lockup_Integration_Sha streamId = lockupLinear.createWithTimestamps(params); } - /// @dev Creates the default stream with the provided createWithTimestamps. - function createDefaultStreamWithRange(LockupLinear.Range memory createWithTimestamps) - internal - returns (uint256 streamId) - { + /// @dev Creates the default stream with the provided range. + function createDefaultStreamWithRange(LockupLinear.Range memory range) internal returns (uint256 streamId) { LockupLinear.CreateWithTimestamps memory params = _params.createWithTimestamps; - params.range = createWithTimestamps; + params.range = range; streamId = lockupLinear.createWithTimestamps(params); } diff --git a/test/invariant/LockupDynamic.t.sol b/test/invariant/LockupDynamic.t.sol index 31e3c0a57..811db9f30 100644 --- a/test/invariant/LockupDynamic.t.sol +++ b/test/invariant/LockupDynamic.t.sol @@ -79,16 +79,16 @@ contract LockupDynamic_Invariant_Test is Lockup_Invariant_Test { } } - /// @dev Unordered segment milestones are not allowed. - function invariant_SegmentMilestonesOrdered() external useCurrentTimestamp { + /// @dev Unordered segment timestamps are not allowed. + function invariant_SegmentTimestampsOrdered() external useCurrentTimestamp { uint256 lastStreamId = lockupStore.lastStreamId(); for (uint256 i = 0; i < lastStreamId; ++i) { uint256 streamId = lockupStore.streamIds(i); LockupDynamic.Segment[] memory segments = lockupDynamic.getSegments(streamId); - uint40 previousMilestone = segments[0].milestone; + uint40 previousTimestamp = segments[0].timestamp; for (uint256 j = 1; j < segments.length; ++j) { - assertGt(segments[j].milestone, previousMilestone, "Invariant violated: segment milestones not ordered"); - previousMilestone = segments[j].milestone; + assertGt(segments[j].timestamp, previousTimestamp, "Invariant violated: segment timestamps not ordered"); + previousTimestamp = segments[j].timestamp; } } } diff --git a/test/invariant/handlers/LockupDynamicCreateHandler.sol b/test/invariant/handlers/LockupDynamicCreateHandler.sol index 67af327ed..41eb5d3cf 100644 --- a/test/invariant/handlers/LockupDynamicCreateHandler.sol +++ b/test/invariant/handlers/LockupDynamicCreateHandler.sol @@ -68,8 +68,8 @@ contract LockupDynamicCreateHandler is BaseHandler { // Bound the broker fee. params.broker.fee = _bound(params.broker.fee, 0, MAX_FEE); - // Fuzz the deltas. - fuzzSegmentDeltas(params.segments); + // Fuzz the durations. + fuzzSegmentDurations(params.segments); // Fuzz the segment amounts and calculate the create amounts (total, deposit, protocol fee, and broker fee). (params.totalAmount,) = fuzzDynamicStreamAmounts({ @@ -116,8 +116,8 @@ contract LockupDynamicCreateHandler is BaseHandler { params.broker.fee = _bound(params.broker.fee, 0, MAX_FEE); params.startTime = boundUint40(params.startTime, 0, getBlockTimestamp()); - // Fuzz the segment milestones. - fuzzSegmentMilestones(params.segments, params.startTime); + // Fuzz the segment timestamps. + fuzzSegmentTimestamps(params.segments, params.startTime); // Fuzz the segment amounts and calculate the create amounts (total, deposit, protocol fee, and broker fee). (params.totalAmount,) = fuzzDynamicStreamAmounts({ diff --git a/test/utils/Calculations.sol b/test/utils/Calculations.sol index f1f3ceae7..abbf8562c 100644 --- a/test/utils/Calculations.sol +++ b/test/utils/Calculations.sol @@ -55,33 +55,33 @@ abstract contract Calculations { view returns (uint128) { - if (currentTime >= segments[segments.length - 1].milestone) { + if (currentTime >= segments[segments.length - 1].timestamp) { return depositAmount; } unchecked { uint128 previousSegmentAmounts; - uint40 currentSegmentMilestone = segments[0].milestone; + uint40 currentSegmentTimestamp = segments[0].timestamp; uint256 index = 0; - while (currentSegmentMilestone < currentTime) { + while (currentSegmentTimestamp < currentTime) { previousSegmentAmounts += segments[index].amount; index += 1; - currentSegmentMilestone = segments[index].milestone; + currentSegmentTimestamp = segments[index].timestamp; } SD59x18 currentSegmentAmount = segments[index].amount.intoSD59x18(); SD59x18 currentSegmentExponent = segments[index].exponent.intoSD59x18(); - currentSegmentMilestone = segments[index].milestone; + currentSegmentTimestamp = segments[index].timestamp; - uint40 previousMilestone; + uint40 previousTimestamp; if (index > 0) { - previousMilestone = segments[index - 1].milestone; + previousTimestamp = segments[index - 1].timestamp; } else { - previousMilestone = defaults.START_TIME(); + previousTimestamp = defaults.START_TIME(); } - SD59x18 elapsedSegmentTime = (currentTime - previousMilestone).intoSD59x18(); - SD59x18 totalSegmentTime = (currentSegmentMilestone - previousMilestone).intoSD59x18(); + SD59x18 elapsedSegmentTime = (currentTime - previousTimestamp).intoSD59x18(); + SD59x18 totalSegmentTime = (currentSegmentTimestamp - previousTimestamp).intoSD59x18(); SD59x18 elapsedSegmentTimePercentage = elapsedSegmentTime.div(totalSegmentTime); SD59x18 multiplier = elapsedSegmentTimePercentage.pow(currentSegmentExponent); @@ -99,12 +99,12 @@ abstract contract Calculations { view returns (uint128) { - if (currentTime >= segment.milestone) { + if (currentTime >= segment.timestamp) { return segment.amount; } unchecked { SD59x18 elapsedTime = (currentTime - defaults.START_TIME()).intoSD59x18(); - SD59x18 totalTime = (segment.milestone - defaults.START_TIME()).intoSD59x18(); + SD59x18 totalTime = (segment.timestamp - defaults.START_TIME()).intoSD59x18(); SD59x18 elapsedTimePercentage = elapsedTime.div(totalTime); SD59x18 multiplier = elapsedTimePercentage.pow(segment.exponent.intoSD59x18()); diff --git a/test/utils/Defaults.sol b/test/utils/Defaults.sol index 73af3e950..36bbe5faf 100644 --- a/test/utils/Defaults.sol +++ b/test/utils/Defaults.sol @@ -135,14 +135,14 @@ contract Defaults is Constants { uint128 amount = DEPOSIT_AMOUNT / uint128(MAX_SEGMENT_COUNT); UD2x18 exponent = ud2x18(2.71e18); - // Generate a bunch of segments with the same amount, same exponent, and with milestones evenly spread apart. + // Generate a bunch of segments with the same amount, same exponent, and with timestamps evenly spread apart. maxSegments_ = new LockupDynamic.Segment[](MAX_SEGMENT_COUNT); for (uint40 i = 0; i < MAX_SEGMENT_COUNT; ++i) { maxSegments_[i] = ( LockupDynamic.Segment({ amount: amount, exponent: exponent, - milestone: START_TIME + MAX_SEGMENT_DURATION * (i + 1) + timestamp: START_TIME + MAX_SEGMENT_DURATION * (i + 1) }) ); } @@ -151,28 +151,32 @@ contract Defaults is Constants { function segments() public view returns (LockupDynamic.Segment[] memory segments_) { segments_ = new LockupDynamic.Segment[](2); segments_[0] = ( - LockupDynamic.Segment({ amount: 2500e18, exponent: ud2x18(3.14e18), milestone: START_TIME + CLIFF_DURATION }) + LockupDynamic.Segment({ amount: 2500e18, exponent: ud2x18(3.14e18), timestamp: START_TIME + CLIFF_DURATION }) ); segments_[1] = ( - LockupDynamic.Segment({ amount: 7500e18, exponent: ud2x18(0.5e18), milestone: START_TIME + TOTAL_DURATION }) + LockupDynamic.Segment({ amount: 7500e18, exponent: ud2x18(0.5e18), timestamp: START_TIME + TOTAL_DURATION }) ); } - function segmentsWithDeltas() public view returns (LockupDynamic.SegmentWithDelta[] memory segmentsWithDeltas_) { + function segmentsWithDurations() + public + view + returns (LockupDynamic.SegmentWithDuration[] memory segmentsWithDurations_) + { LockupDynamic.Segment[] memory segments_ = segments(); - segmentsWithDeltas_ = new LockupDynamic.SegmentWithDelta[](2); - segmentsWithDeltas_[0] = ( - LockupDynamic.SegmentWithDelta({ + segmentsWithDurations_ = new LockupDynamic.SegmentWithDuration[](2); + segmentsWithDurations_[0] = ( + LockupDynamic.SegmentWithDuration({ amount: segments_[0].amount, exponent: segments_[0].exponent, - delta: 2500 seconds + duration: 2500 seconds }) ); - segmentsWithDeltas_[1] = ( - LockupDynamic.SegmentWithDelta({ + segmentsWithDurations_[1] = ( + LockupDynamic.SegmentWithDuration({ amount: segments_[1].amount, exponent: segments_[1].exponent, - delta: 7500 seconds + duration: 7500 seconds }) ); } @@ -189,7 +193,7 @@ contract Defaults is Constants { asset: asset, cancelable: true, transferable: true, - segments: segmentsWithDeltas(), + segments: segmentsWithDurations(), broker: broker() }); } diff --git a/test/utils/Fuzzers.sol b/test/utils/Fuzzers.sol index a42184ebd..dc61affb1 100644 --- a/test/utils/Fuzzers.sol +++ b/test/utils/Fuzzers.sol @@ -30,20 +30,20 @@ abstract contract Fuzzers is Constants, Utils { } /// @dev Just like {fuzzDynamicStreamAmounts} but with defaults. - function fuzzDynamicStreamAmounts(LockupDynamic.SegmentWithDelta[] memory segments) + function fuzzDynamicStreamAmounts(LockupDynamic.SegmentWithDuration[] memory segments) internal view returns (uint128 totalAmount, Lockup.CreateAmounts memory createAmounts) { - LockupDynamic.Segment[] memory segmentsWithMilestones = getSegmentsWithMilestones(segments); + LockupDynamic.Segment[] memory segmentsWithTimestamps = getSegmentsWithTimestamps(segments); (totalAmount, createAmounts) = fuzzDynamicStreamAmounts({ upperBound: MAX_UINT128, - segments: segmentsWithMilestones, + segments: segmentsWithTimestamps, protocolFee: defaults.PROTOCOL_FEE(), brokerFee: defaults.BROKER_FEE() }); - for (uint256 i = 0; i < segmentsWithMilestones.length; ++i) { - segments[i].amount = segmentsWithMilestones[i].amount; + for (uint256 i = 0; i < segmentsWithTimestamps.length; ++i) { + segments[i].amount = segmentsWithTimestamps[i].amount; } } @@ -51,7 +51,7 @@ abstract contract Fuzzers is Constants, Utils { /// fee). function fuzzDynamicStreamAmounts( uint128 upperBound, - LockupDynamic.SegmentWithDelta[] memory segments, + LockupDynamic.SegmentWithDuration[] memory segments, UD60x18 protocolFee, UD60x18 brokerFee ) @@ -59,11 +59,11 @@ abstract contract Fuzzers is Constants, Utils { view returns (uint128 totalAmount, Lockup.CreateAmounts memory createAmounts) { - LockupDynamic.Segment[] memory segmentsWithMilestones = getSegmentsWithMilestones(segments); + LockupDynamic.Segment[] memory segmentsWithTimestamps = getSegmentsWithTimestamps(segments); (totalAmount, createAmounts) = - fuzzDynamicStreamAmounts(upperBound, segmentsWithMilestones, protocolFee, brokerFee); - for (uint256 i = 0; i < segmentsWithMilestones.length; ++i) { - segments[i].amount = segmentsWithMilestones[i].amount; + fuzzDynamicStreamAmounts(upperBound, segmentsWithTimestamps, protocolFee, brokerFee); + for (uint256 i = 0; i < segmentsWithTimestamps.length; ++i) { + segments[i].amount = segmentsWithTimestamps[i].amount; } } @@ -115,47 +115,47 @@ abstract contract Fuzzers is Constants, Utils { segments[segments.length - 1].amount += (createAmounts.deposit - estimatedDepositAmount); } - /// @dev Fuzzes the deltas. - function fuzzSegmentDeltas(LockupDynamic.SegmentWithDelta[] memory segments) internal pure { + /// @dev Fuzzes the durations. + function fuzzSegmentDurations(LockupDynamic.SegmentWithDuration[] memory segments) internal pure { unchecked { - // Precompute the first segment delta. - segments[0].delta = uint40(_bound(segments[0].delta, 1, 100)); - - // Bound the deltas so that none is zero and the calculations don't overflow. - uint256 deltaCount = segments.length; - uint40 maxDelta = (MAX_UNIX_TIMESTAMP - segments[0].delta) / uint40(deltaCount); - for (uint256 i = 1; i < deltaCount; ++i) { - segments[i].delta = boundUint40(segments[i].delta, 1, maxDelta); + // Precompute the first segment duration. + segments[0].duration = uint40(_bound(segments[0].duration, 1, 100)); + + // Bound the durations so that none is zero and the calculations don't overflow. + uint256 durationCount = segments.length; + uint40 maxDuration = (MAX_UNIX_TIMESTAMP - segments[0].duration) / uint40(durationCount); + for (uint256 i = 1; i < durationCount; ++i) { + segments[i].duration = boundUint40(segments[i].duration, 1, maxDuration); } } } - /// @dev Fuzzes the segment milestones. - function fuzzSegmentMilestones(LockupDynamic.Segment[] memory segments, uint40 startTime) internal view { + /// @dev Fuzzes the segment timestamps. + function fuzzSegmentTimestamps(LockupDynamic.Segment[] memory segments, uint40 startTime) internal view { // Return here if there's only one segment to not run into division by zero. uint40 segmentCount = uint40(segments.length); if (segmentCount == 1) { // The end time must be in the future. uint40 currentTime = getBlockTimestamp(); - segments[0].milestone = (startTime < currentTime ? currentTime : startTime) + 2 days; + segments[0].timestamp = (startTime < currentTime ? currentTime : startTime) + 2 days; return; } - // The first milestones is precomputed to avoid an underflow in the first loop iteration. We have to - // add 1 because the first milestone must be greater than the start time. - segments[0].milestone = startTime + 1 seconds; + // The first timestamps is precomputed to avoid an underflow in the first loop iteration. We have to + // add 1 because the first timestamp must be greater than the start time. + segments[0].timestamp = startTime + 1 seconds; - // Fuzz the milestones while preserving their order in the array. For each milestone, set its initial guess - // as the sum of the starting milestone and the step size multiplied by the current index. This ensures that - // the initial guesses are evenly spaced. Next, we bound the milestone within a range of half the step size + // Fuzz the timestamps while preserving their order in the array. For each timestamp, set its initial guess + // as the sum of the starting timestamp and the step size multiplied by the current index. This ensures that + // the initial guesses are evenly spaced. Next, we bound the timestamp within a range of half the step size // around the initial guess. - uint256 start = segments[0].milestone; - uint40 step = (MAX_UNIX_TIMESTAMP - segments[0].milestone) / (segmentCount - 1); + uint256 start = segments[0].timestamp; + uint40 step = (MAX_UNIX_TIMESTAMP - segments[0].timestamp) / (segmentCount - 1); uint40 halfStep = step / 2; for (uint256 i = 1; i < segmentCount; ++i) { - uint256 milestone = start + i * step; - milestone = _bound(milestone, milestone - halfStep, milestone + halfStep); - segments[i].milestone = uint40(milestone); + uint256 timestamp = start + i * step; + timestamp = _bound(timestamp, timestamp - halfStep, timestamp + halfStep); + segments[i].timestamp = uint40(timestamp); } } } diff --git a/test/utils/Utils.sol b/test/utils/Utils.sol index 86db15427..4e4997f55 100644 --- a/test/utils/Utils.sol +++ b/test/utils/Utils.sol @@ -31,24 +31,24 @@ abstract contract Utils is StdUtils, PRBMathUtils { return uint40(block.timestamp); } - /// @dev Turns the segments with deltas into canonical segments, which have milestones. - function getSegmentsWithMilestones(LockupDynamic.SegmentWithDelta[] memory segments) + /// @dev Turns the segments with durations into canonical segments, which have timestamps. + function getSegmentsWithTimestamps(LockupDynamic.SegmentWithDuration[] memory segments) internal view - returns (LockupDynamic.Segment[] memory segmentsWithMilestones) + returns (LockupDynamic.Segment[] memory segmentsWithTimestamps) { unchecked { - segmentsWithMilestones = new LockupDynamic.Segment[](segments.length); - segmentsWithMilestones[0] = LockupDynamic.Segment({ + segmentsWithTimestamps = new LockupDynamic.Segment[](segments.length); + segmentsWithTimestamps[0] = LockupDynamic.Segment({ amount: segments[0].amount, exponent: segments[0].exponent, - milestone: getBlockTimestamp() + segments[0].delta + timestamp: getBlockTimestamp() + segments[0].duration }); for (uint256 i = 1; i < segments.length; ++i) { - segmentsWithMilestones[i] = LockupDynamic.Segment({ + segmentsWithTimestamps[i] = LockupDynamic.Segment({ amount: segments[i].amount, exponent: segments[i].exponent, - milestone: segmentsWithMilestones[i - 1].milestone + segments[i].delta + timestamp: segmentsWithTimestamps[i - 1].timestamp + segments[i].duration }); } }