diff --git a/script/Init.s.sol b/script/Init.s.sol index 4186ac3e0..cf71876a2 100644 --- a/script/Init.s.sol +++ b/script/Init.s.sol @@ -78,11 +78,13 @@ 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.createWithDeltas( - LockupDynamic.CreateWithDeltas({ + 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, recipient: recipient, totalAmount: 10_000e18, diff --git a/src/SablierV2LockupDynamic.sol b/src/SablierV2LockupDynamic.sol index 03fc8c8d5..e44d6113b 100644 --- a/src/SablierV2LockupDynamic.sol +++ b/src/SablierV2LockupDynamic.sol @@ -267,18 +267,18 @@ contract SablierV2LockupDynamic is //////////////////////////////////////////////////////////////////////////*/ /// @inheritdoc ISablierV2LockupDynamic - function createWithDeltas(LockupDynamic.CreateWithDeltas calldata params) + function createWithDurations(LockupDynamic.CreateWithDurations calldata params) external override 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 = _createWithMilestones( - LockupDynamic.CreateWithMilestones({ + streamId = _createWithTimestamps( + LockupDynamic.CreateWithTimestamps({ sender: params.sender, recipient: params.recipient, totalAmount: params.totalAmount, @@ -293,14 +293,14 @@ contract SablierV2LockupDynamic is } /// @inheritdoc ISablierV2LockupDynamic - function createWithMilestones(LockupDynamic.CreateWithMilestones calldata params) + function createWithTimestamps(LockupDynamic.CreateWithTimestamps calldata params) external override noDelegateCall returns (uint256 streamId) { // Checks, Effects and Interactions: create the stream. - streamId = _createWithMilestones(params); + streamId = _createWithTimestamps(params); } /*////////////////////////////////////////////////////////////////////////// @@ -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); @@ -537,7 +537,7 @@ contract SablierV2LockupDynamic is } /// @dev See the documentation for the user-facing functions that call this internal function. - function _createWithMilestones(LockupDynamic.CreateWithMilestones memory params) + function _createWithTimestamps(LockupDynamic.CreateWithTimestamps memory params) internal returns (uint256 streamId) { @@ -550,7 +550,7 @@ contract SablierV2LockupDynamic is Helpers.checkAndCalculateFees(params.totalAmount, protocolFee, params.broker.fee, MAX_FEE); // Checks: validate the user-provided parameters. - Helpers.checkCreateWithMilestones(createAmounts.deposit, params.segments, MAX_SEGMENT_COUNT, params.startTime); + Helpers.checkCreateWithTimestamps(createAmounts.deposit, params.segments, MAX_SEGMENT_COUNT, params.startTime); // Load the stream id in a variable. streamId = nextStreamId; @@ -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/SablierV2LockupLinear.sol b/src/SablierV2LockupLinear.sol index 56fe191c9..a1eb4f98f 100644 --- a/src/SablierV2LockupLinear.sol +++ b/src/SablierV2LockupLinear.sol @@ -261,15 +261,15 @@ contract SablierV2LockupLinear is range.start = uint40(block.timestamp); // Calculate the cliff time and the end time. It is safe to use unchecked arithmetic because - // {_createWithRange} will nonetheless check that the end time is greater than the cliff time, + // {_createWithTimestamps} will nonetheless check that the end time is greater than the cliff time, // and also that the cliff time is greater than or equal to the start time. unchecked { range.cliff = range.start + params.durations.cliff; range.end = range.start + params.durations.total; } // Checks, Effects and Interactions: create the stream. - streamId = _createWithRange( - LockupLinear.CreateWithRange({ + streamId = _createWithTimestamps( + LockupLinear.CreateWithTimestamps({ sender: params.sender, recipient: params.recipient, totalAmount: params.totalAmount, @@ -283,14 +283,14 @@ contract SablierV2LockupLinear is } /// @inheritdoc ISablierV2LockupLinear - function createWithRange(LockupLinear.CreateWithRange calldata params) + function createWithTimestamps(LockupLinear.CreateWithTimestamps calldata params) external override noDelegateCall returns (uint256 streamId) { // Checks, Effects and Interactions: create the stream. - streamId = _createWithRange(params); + streamId = _createWithTimestamps(params); } /*////////////////////////////////////////////////////////////////////////// @@ -452,7 +452,10 @@ contract SablierV2LockupLinear is } /// @dev See the documentation for the user-facing functions that call this internal function. - function _createWithRange(LockupLinear.CreateWithRange memory params) internal returns (uint256 streamId) { + function _createWithTimestamps(LockupLinear.CreateWithTimestamps memory params) + internal + returns (uint256 streamId) + { // Safe Interactions: query the protocol fee. This is safe because it's a known Sablier contract that does // not call other unknown contracts. UD60x18 protocolFee = comptroller.protocolFees(params.asset); @@ -462,7 +465,7 @@ contract SablierV2LockupLinear is Helpers.checkAndCalculateFees(params.totalAmount, protocolFee, params.broker.fee, MAX_FEE); // Checks: validate the user-provided parameters. - Helpers.checkCreateWithRange(createAmounts.deposit, params.range); + Helpers.checkCreateWithTimestamps(createAmounts.deposit, params.range); // Load the stream id. streamId = nextStreamId; diff --git a/src/interfaces/ISablierV2LockupDynamic.sol b/src/interfaces/ISablierV2LockupDynamic.sol index e60cb3fee..8f646cec3 100644 --- a/src/interfaces/ISablierV2LockupDynamic.sol +++ b/src/interfaces/ISablierV2LockupDynamic.sol @@ -92,25 +92,27 @@ 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. /// /// Requirements: - /// - All requirements in {createWithMilestones} must be met for the calculated parameters. + /// - All requirements in {createWithTimestamps} must be met for the calculated parameters. /// /// @param params Struct encapsulating the function parameters, which are documented in {DataTypes}. /// @return streamId The id of the newly created stream. - function createWithDeltas(LockupDynamic.CreateWithDeltas calldata params) external returns (uint256 streamId); + function createWithDurations(LockupDynamic.CreateWithDurations calldata params) + 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: @@ -118,16 +120,16 @@ 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. /// /// @param params Struct encapsulating the function parameters, which are documented in {DataTypes}. /// @return streamId The id of the newly created stream. - function createWithMilestones(LockupDynamic.CreateWithMilestones calldata params) + function createWithTimestamps(LockupDynamic.CreateWithTimestamps calldata params) external returns (uint256 streamId); } diff --git a/src/interfaces/ISablierV2LockupLinear.sol b/src/interfaces/ISablierV2LockupLinear.sol index 95ecd1f16..a8f066896 100644 --- a/src/interfaces/ISablierV2LockupLinear.sol +++ b/src/interfaces/ISablierV2LockupLinear.sol @@ -92,7 +92,7 @@ interface ISablierV2LockupLinear is ISablierV2Lockup { /// @dev Emits a {Transfer} and {CreateLockupLinearStream} event. /// /// Requirements: - /// - All requirements in {createWithRange} must be met for the calculated parameters. + /// - All requirements in {createWithTimestamps} must be met for the calculated parameters. /// /// @param params Struct encapsulating the function parameters, which are documented in {DataTypes}. /// @return streamId The id of the newly created stream. @@ -120,5 +120,7 @@ interface ISablierV2LockupLinear is ISablierV2Lockup { /// /// @param params Struct encapsulating the function parameters, which are documented in {DataTypes}. /// @return streamId The id of the newly created stream. - function createWithRange(LockupLinear.CreateWithRange calldata params) external returns (uint256 streamId); + function createWithTimestamps(LockupLinear.CreateWithTimestamps calldata params) + external + returns (uint256 streamId); } diff --git a/src/libraries/Errors.sol b/src/libraries/Errors.sol index d410a9255..278c43f8b 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 cfc9e2d54..73ee41f34 100644 --- a/src/libraries/Helpers.sol +++ b/src/libraries/Helpers.sol @@ -55,8 +55,8 @@ library Helpers { amounts.deposit = totalAmount - amounts.protocolFee - amounts.brokerFee; } - /// @dev Checks the parameters of the {SablierV2LockupDynamic-_createWithMilestones} function. - function checkCreateWithMilestones( + /// @dev Checks the parameters of the {SablierV2LockupDynamic-_createWithTimestamps} function. + function checkCreateWithTimestamps( uint128 depositAmount, LockupDynamic.Segment[] memory segments, uint256 maxSegmentCount, @@ -85,8 +85,8 @@ library Helpers { _checkSegments(segments, depositAmount, startTime); } - /// @dev Checks the parameters of the {SablierV2LockupLinear-_createWithRange} function. - function checkCreateWithRange(uint128 depositAmount, LockupLinear.Range memory range) internal view { + /// @dev Checks the parameters of the {SablierV2LockupLinear-_createWithTimestamps} function. + function checkCreateWithTimestamps(uint128 depositAmount, LockupLinear.Range memory range) internal view { // Checks: the deposit amount is not zero. if (depositAmount == 0) { revert Errors.SablierV2Lockup_DepositAmountZero(); @@ -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 ce6366ed5..543e8de4e 100644 --- a/src/types/DataTypes.sol +++ b/src/types/DataTypes.sol @@ -70,7 +70,7 @@ library Lockup { /// @notice Namespace for the structs used in {SablierV2LockupDynamic}. library LockupDynamic { - /// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithDeltas} function. + /// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithDurations} function. /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the /// same as `msg.sender`. /// @param recipient The address receiving the assets. @@ -79,22 +79,22 @@ 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 CreateWithDeltas { + struct CreateWithDurations { address sender; address recipient; uint128 totalAmount; IERC20 asset; bool cancelable; bool transferable; - SegmentWithDelta[] segments; + SegmentWithDuration[] segments; Broker broker; } - /// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithMilestones} + /// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithTimestamps} /// function. /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the /// same as `msg.sender`. @@ -108,7 +108,7 @@ library LockupDynamic { /// @param segments Segments used to compose the custom streaming curve. /// @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 CreateWithMilestones { + struct CreateWithTimestamps { address sender; address recipient; uint128 totalAmount; @@ -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.createWithDeltas}. + /// @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. @@ -207,7 +207,7 @@ library LockupLinear { Broker broker; } - /// @notice Struct encapsulating the parameters for the {SablierV2LockupLinear.createWithRange} function. + /// @notice Struct encapsulating the parameters for the {SablierV2LockupLinear.createWithTimestamps} function. /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the /// same as `msg.sender`. /// @param recipient The address receiving the assets. @@ -220,7 +220,7 @@ library LockupLinear { /// timestamps. /// @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 CreateWithRange { + struct CreateWithTimestamps { address sender; address recipient; uint128 totalAmount; diff --git a/test/fork/LockupDynamic.t.sol b/test/fork/LockupDynamic.t.sol index ea1f40f5a..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) }); @@ -177,8 +177,8 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test { }); // Create the stream. - lockupDynamic.createWithMilestones( - LockupDynamic.CreateWithMilestones({ + lockupDynamic.createWithTimestamps( + LockupDynamic.CreateWithTimestamps({ sender: params.sender, recipient: params.recipient, totalAmount: vars.totalAmount, diff --git a/test/fork/LockupLinear.t.sol b/test/fork/LockupLinear.t.sol index 7207590fd..d390e49d0 100644 --- a/test/fork/LockupLinear.t.sol +++ b/test/fork/LockupLinear.t.sol @@ -179,8 +179,8 @@ abstract contract LockupLinear_Fork_Test is Fork_Test { }); // Create the stream. - lockupLinear.createWithRange( - LockupLinear.CreateWithRange({ + lockupLinear.createWithTimestamps( + LockupLinear.CreateWithTimestamps({ sender: params.sender, recipient: params.recipient, totalAmount: params.totalAmount, diff --git a/test/integration/concrete/lockup-dynamic/create-with-deltas/createWithDeltas.t.sol b/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.t.sol similarity index 66% rename from test/integration/concrete/lockup-dynamic/create-with-deltas/createWithDeltas.t.sol rename to test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.t.sol index 4affdbb97..bf8b3823c 100644 --- a/test/integration/concrete/lockup-dynamic/create-with-deltas/createWithDeltas.t.sol +++ b/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.t.sol @@ -7,116 +7,120 @@ import { ISablierV2LockupDynamic } from "src/interfaces/ISablierV2LockupDynamic. import { Errors } from "src/libraries/Errors.sol"; import { Lockup, LockupDynamic } from "src/types/DataTypes.sol"; -import { CreateWithDeltas_Integration_Shared_Test } from "../../../shared/lockup-dynamic/createWithDeltas.t.sol"; +import { CreateWithDurations_Integration_Shared_Test } from "../../../shared/lockup-dynamic/createWithDurations.t.sol"; import { LockupDynamic_Integration_Concrete_Test } from "../LockupDynamic.t.sol"; -contract CreateWithDeltas_LockupDynamic_Integration_Concrete_Test is +contract CreateWithDurations_LockupDynamic_Integration_Concrete_Test is LockupDynamic_Integration_Concrete_Test, - CreateWithDeltas_Integration_Shared_Test + CreateWithDurations_Integration_Shared_Test { function setUp() public virtual - override(LockupDynamic_Integration_Concrete_Test, CreateWithDeltas_Integration_Shared_Test) + override(LockupDynamic_Integration_Concrete_Test, CreateWithDurations_Integration_Shared_Test) { LockupDynamic_Integration_Concrete_Test.setUp(); - CreateWithDeltas_Integration_Shared_Test.setUp(); + CreateWithDurations_Integration_Shared_Test.setUp(); streamId = lockupDynamic.nextStreamId(); } /// @dev it should revert. function test_RevertWhen_DelegateCalled() external { - bytes memory callData = abi.encodeCall(ISablierV2LockupDynamic.createWithDeltas, defaults.createWithDeltas()); + bytes memory callData = + abi.encodeCall(ISablierV2LockupDynamic.createWithDurations, defaults.createWithDurationsLD()); (bool success, bytes memory returnData) = address(lockupDynamic).delegatecall(callData); expectRevertDueToDelegateCall(success, returnData); } /// @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.createWithDeltas().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.createWithDeltas().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); } } - function test_CreateWithDeltas() + function test_CreateWithDurations() external whenNotDelegateCalled whenLoopCalculationsDoNotOverflowBlockGasLimit - whenDeltasNotZero - whenMilestonesCalculationsDoNotOverflow + whenDurationsNotZero + whenTimestampsCalculationsDoNotOverflow { // Make the Sender the stream's funder address funder = users.sender; @@ -130,10 +134,10 @@ contract CreateWithDeltas_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({ @@ -164,7 +168,7 @@ contract CreateWithDeltas_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-deltas/createWithDeltas.tree b/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.tree similarity index 70% rename from test/integration/concrete/lockup-dynamic/create-with-deltas/createWithDeltas.tree rename to test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.tree index 3824747f3..e1fa7ae20 100644 --- a/test/integration/concrete/lockup-dynamic/create-with-deltas/createWithDeltas.tree +++ b/test/integration/concrete/lockup-dynamic/create-with-durations/createWithDurations.tree @@ -1,19 +1,19 @@ -createWithDeltas.t.sol +createWithDurations.t.sol ├── when delegate called │ └── it should revert └── when not delegate called ├── 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-milestones/createWithMilestones.t.sol b/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.t.sol similarity index 83% rename from test/integration/concrete/lockup-dynamic/create-with-milestones/createWithMilestones.t.sol rename to test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.t.sol index 5a7b028b6..f7842897b 100644 --- a/test/integration/concrete/lockup-dynamic/create-with-milestones/createWithMilestones.t.sol +++ b/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.t.sol @@ -9,25 +9,25 @@ import { ISablierV2LockupDynamic } from "src/interfaces/ISablierV2LockupDynamic. import { Errors } from "src/libraries/Errors.sol"; import { Broker, Lockup, LockupDynamic } from "src/types/DataTypes.sol"; -import { CreateWithMilestones_Integration_Shared_Test } from "../../../shared/lockup-dynamic/createWithMilestones.t.sol"; +import { CreateWithTimestamps_Integration_Shared_Test } from "../../../shared/lockup-dynamic/createWithTimestamps.t.sol"; import { LockupDynamic_Integration_Concrete_Test } from "../LockupDynamic.t.sol"; -contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is +contract CreateWithTimestamps_LockupDynamic_Integration_Concrete_Test is LockupDynamic_Integration_Concrete_Test, - CreateWithMilestones_Integration_Shared_Test + CreateWithTimestamps_Integration_Shared_Test { function setUp() public virtual - override(LockupDynamic_Integration_Concrete_Test, CreateWithMilestones_Integration_Shared_Test) + override(LockupDynamic_Integration_Concrete_Test, CreateWithTimestamps_Integration_Shared_Test) { LockupDynamic_Integration_Concrete_Test.setUp(); - CreateWithMilestones_Integration_Shared_Test.setUp(); + CreateWithTimestamps_Integration_Shared_Test.setUp(); } function test_RevertWhen_DelegateCalled() external { bytes memory callData = - abi.encodeCall(ISablierV2LockupDynamic.createWithMilestones, defaults.createWithMilestones()); + abi.encodeCall(ISablierV2LockupDynamic.createWithTimestamps, defaults.createWithTimestampsLD()); (bool success, bytes memory returnData) = address(lockupDynamic).delegatecall(callData); expectRevertDueToDelegateCall(success, returnData); } @@ -87,7 +87,7 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is createDefaultStreamWithSegments(segments); } - function test_RevertWhen_StartTimeGreaterThanFirstSegmentMilestone() + function test_RevertWhen_StartTimeGreaterThanFirstSegmentTimestamp() external whenNotDelegateCalled whenRecipientNonZeroAddress @@ -96,16 +96,16 @@ contract CreateWithMilestones_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 CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is createDefaultStreamWithSegments(segments); } - function test_RevertWhen_StartTimeEqualToFirstSegmentMilestone() + function test_RevertWhen_StartTimeEqualToFirstSegmentTimestamp() external whenNotDelegateCalled whenRecipientNonZeroAddress @@ -122,16 +122,16 @@ contract CreateWithMilestones_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 CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is createDefaultStreamWithSegments(segments); } - function test_RevertWhen_SegmentMilestonesNotOrdered() + function test_RevertWhen_SegmentTimestampsNotOrdered() external whenNotDelegateCalled whenRecipientNonZeroAddress @@ -147,20 +147,20 @@ contract CreateWithMilestones_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 CreateWithMilestones_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 CreateWithMilestones_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. @@ -208,7 +208,7 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is uint128 depositAmount = defaultDepositAmount + 100; // Prepare the params. - LockupDynamic.CreateWithMilestones memory params = defaults.createWithMilestones(); + LockupDynamic.CreateWithTimestamps memory params = defaults.createWithTimestampsLD(); params.broker = Broker({ account: address(0), fee: brokerFee }); params.totalAmount = depositAmount; @@ -222,7 +222,7 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is ); // Create the stream. - lockupDynamic.createWithMilestones(params); + lockupDynamic.createWithTimestamps(params); } function test_RevertGiven_ProtocolFeeTooHigh() @@ -233,8 +233,8 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum { @@ -260,8 +260,8 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh @@ -279,8 +279,8 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh @@ -299,7 +299,7 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is createDefaultStreamWithAsset(IERC20(nonContract)); } - function test_CreateWithMilestones_AssetMissingReturnValue() + function test_CreateWithTimestamps_AssetMissingReturnValue() external whenNotDelegateCalled whenRecipientNonZeroAddress @@ -307,18 +307,18 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh whenBrokerFeeNotTooHigh whenAssetContract { - testCreateWithMilestones(address(usdt)); + testCreateWithTimestamps(address(usdt)); } - function test_CreateWithMilestones() + function test_CreateWithTimestamps() external whenNotDelegateCalled whenRecipientNonZeroAddress @@ -326,8 +326,8 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh @@ -335,11 +335,11 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is whenAssetContract whenAssetERC20 { - testCreateWithMilestones(address(dai)); + testCreateWithTimestamps(address(dai)); } - /// @dev Shared logic between {test_CreateWithMilestones_AssetMissingReturnValue} and {test_CreateWithMilestones}. - function testCreateWithMilestones(address asset) internal { + /// @dev Shared logic between {test_CreateWithTimestamps_AssetMissingReturnValue} and {test_CreateWithTimestamps}. + function testCreateWithTimestamps(address asset) internal { // Make the Sender the stream's funder. address funder = users.sender; diff --git a/test/integration/concrete/lockup-dynamic/create-with-milestones/createWithMilestones.tree b/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.tree similarity index 94% rename from test/integration/concrete/lockup-dynamic/create-with-milestones/createWithMilestones.tree rename to test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.tree index c90aecfc5..ee1418596 100644 --- a/test/integration/concrete/lockup-dynamic/create-with-milestones/createWithMilestones.tree +++ b/test/integration/concrete/lockup-dynamic/create-with-timestamps/createWithTimestamps.tree @@ -1,4 +1,4 @@ -createWithMilestones.t.sol +createWithTimestamps.t.sol ├── when delegate called │ └── it should revert └── when not delegate called @@ -17,14 +17,14 @@ createWithMilestones.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/concrete/lockup-linear/create-with-durations/createWithDurations.t.sol b/test/integration/concrete/lockup-linear/create-with-durations/createWithDurations.t.sol index f01eb9415..835b7af64 100644 --- a/test/integration/concrete/lockup-linear/create-with-durations/createWithDurations.t.sol +++ b/test/integration/concrete/lockup-linear/create-with-durations/createWithDurations.t.sol @@ -23,7 +23,7 @@ contract CreateWithDurations_LockupLinear_Integration_Concrete_Test is function test_RevertWhen_DelegateCalled() external { bytes memory callData = - abi.encodeCall(ISablierV2LockupLinear.createWithDurations, defaults.createWithDurations()); + abi.encodeCall(ISablierV2LockupLinear.createWithDurations, defaults.createWithDurationsLL()); (bool success, bytes memory returnData) = address(lockupLinear).delegatecall(callData); expectRevertDueToDelegateCall(success, returnData); } diff --git a/test/integration/concrete/lockup-linear/create-with-range/createWithRange.t.sol b/test/integration/concrete/lockup-linear/create-with-timestamps/createWithTimestamps.t.sol similarity index 90% rename from test/integration/concrete/lockup-linear/create-with-range/createWithRange.t.sol rename to test/integration/concrete/lockup-linear/create-with-timestamps/createWithTimestamps.t.sol index 14c5f4018..1cc002290 100644 --- a/test/integration/concrete/lockup-linear/create-with-range/createWithRange.t.sol +++ b/test/integration/concrete/lockup-linear/create-with-timestamps/createWithTimestamps.t.sol @@ -8,24 +8,25 @@ import { ISablierV2LockupLinear } from "src/interfaces/ISablierV2LockupLinear.so import { Errors } from "src/libraries/Errors.sol"; import { Broker, Lockup, LockupLinear } from "src/types/DataTypes.sol"; -import { CreateWithRange_Integration_Shared_Test } from "../../../shared/lockup-linear/createWithRange.t.sol"; +import { CreateWithTimestamps_Integration_Shared_Test } from "../../../shared/lockup-linear/createWithTimestamps.t.sol"; import { LockupLinear_Integration_Concrete_Test } from "../LockupLinear.t.sol"; -contract CreateWithRange_LockupLinear_Integration_Concrete_Test is +contract CreateWithTimestamps_LockupLinear_Integration_Concrete_Test is LockupLinear_Integration_Concrete_Test, - CreateWithRange_Integration_Shared_Test + CreateWithTimestamps_Integration_Shared_Test { function setUp() public virtual - override(LockupLinear_Integration_Concrete_Test, CreateWithRange_Integration_Shared_Test) + override(LockupLinear_Integration_Concrete_Test, CreateWithTimestamps_Integration_Shared_Test) { LockupLinear_Integration_Concrete_Test.setUp(); - CreateWithRange_Integration_Shared_Test.setUp(); + CreateWithTimestamps_Integration_Shared_Test.setUp(); } function test_RevertWhen_DelegateCalled() external { - bytes memory callData = abi.encodeCall(ISablierV2LockupLinear.createWithRange, defaults.createWithRange()); + bytes memory callData = + abi.encodeCall(ISablierV2LockupLinear.createWithTimestamps, defaults.createWithTimestampsLL()); (bool success, bytes memory returnData) = address(lockupLinear).delegatecall(callData); expectRevertDueToDelegateCall(success, returnData); } @@ -146,7 +147,7 @@ contract CreateWithRange_LockupLinear_Integration_Concrete_Test is createDefaultStreamWithAsset(IERC20(nonContract)); } - function test_CreateWithRange_AssetMissingReturnValue() + function test_CreateWithTimestamps_AssetMissingReturnValue() external whenNotDelegateCalled whenRecipientNonZeroAddress @@ -158,10 +159,10 @@ contract CreateWithRange_LockupLinear_Integration_Concrete_Test is whenBrokerFeeNotTooHigh whenAssetContract { - testCreateWithRange(address(usdt)); + testCreateWithTimestamps(address(usdt)); } - function test_CreateWithRange() + function test_CreateWithTimestamps() external whenNotDelegateCalled whenDepositAmountNotZero @@ -173,11 +174,11 @@ contract CreateWithRange_LockupLinear_Integration_Concrete_Test is whenAssetContract whenAssetERC20 { - testCreateWithRange(address(dai)); + testCreateWithTimestamps(address(dai)); } - /// @dev Shared logic between {test_CreateWithRange_AssetMissingReturnValue} and {test_CreateWithRange}. - function testCreateWithRange(address asset) internal { + /// @dev Shared logic between {test_CreateWithTimestamps_AssetMissingReturnValue} and {test_CreateWithTimestamps}. + function testCreateWithTimestamps(address asset) internal { // Make the Sender the stream's funder. address funder = users.sender; diff --git a/test/integration/concrete/lockup-linear/create-with-range/createWithRange.tree b/test/integration/concrete/lockup-linear/create-with-timestamps/createWithTimestamps.tree similarity index 99% rename from test/integration/concrete/lockup-linear/create-with-range/createWithRange.tree rename to test/integration/concrete/lockup-linear/create-with-timestamps/createWithTimestamps.tree index 6d810042a..407705603 100644 --- a/test/integration/concrete/lockup-linear/create-with-range/createWithRange.tree +++ b/test/integration/concrete/lockup-linear/create-with-timestamps/createWithTimestamps.tree @@ -1,4 +1,4 @@ -createWithRange.t.sol +createWithTimestamps.t.sol ├── when delegate called │ └── it should revert └── when not delegate called diff --git a/test/integration/fuzz/lockup-dynamic/createWithDeltas.t.sol b/test/integration/fuzz/lockup-dynamic/createWithDurations.t.sol similarity index 83% rename from test/integration/fuzz/lockup-dynamic/createWithDeltas.t.sol rename to test/integration/fuzz/lockup-dynamic/createWithDurations.t.sol index 87a61d646..4285a8034 100644 --- a/test/integration/fuzz/lockup-dynamic/createWithDeltas.t.sol +++ b/test/integration/fuzz/lockup-dynamic/createWithDurations.t.sol @@ -3,20 +3,20 @@ pragma solidity >=0.8.22 <0.9.0; import { Lockup, LockupDynamic } from "src/types/DataTypes.sol"; -import { CreateWithDeltas_Integration_Shared_Test } from "../../shared/lockup-dynamic/createWithDeltas.t.sol"; +import { CreateWithDurations_Integration_Shared_Test } from "../../shared/lockup-dynamic/createWithDurations.t.sol"; import { LockupDynamic_Integration_Fuzz_Test } from "./LockupDynamic.t.sol"; -contract CreateWithDeltas_LockupDynamic_Integration_Fuzz_Test is +contract CreateWithDurations_LockupDynamic_Integration_Fuzz_Test is LockupDynamic_Integration_Fuzz_Test, - CreateWithDeltas_Integration_Shared_Test + CreateWithDurations_Integration_Shared_Test { function setUp() public virtual - override(LockupDynamic_Integration_Fuzz_Test, CreateWithDeltas_Integration_Shared_Test) + override(LockupDynamic_Integration_Fuzz_Test, CreateWithDurations_Integration_Shared_Test) { LockupDynamic_Integration_Fuzz_Test.setUp(); - CreateWithDeltas_Integration_Shared_Test.setUp(); + CreateWithDurations_Integration_Shared_Test.setUp(); } struct Vars { @@ -33,22 +33,22 @@ contract CreateWithDeltas_LockupDynamic_Integration_Fuzz_Test is uint128 initialProtocolRevenues; bool isCancelable; bool isSettled; - LockupDynamic.Segment[] segmentsWithMilestones; + LockupDynamic.Segment[] segmentsWithTimestamps; uint128 totalAmount; } - function testFuzz_CreateWithDeltas(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 CreateWithDeltas_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,17 +92,17 @@ contract CreateWithDeltas_LockupDynamic_Integration_Fuzz_Test is asset: dai, cancelable: true, transferable: true, - segments: vars.segmentsWithMilestones, + segments: vars.segmentsWithTimestamps, range: range, broker: users.broker }); // Create the stream. - LockupDynamic.CreateWithDeltas memory params = defaults.createWithDeltas(); + LockupDynamic.CreateWithDurations memory params = defaults.createWithDurationsLD(); params.segments = segments; params.totalAmount = vars.totalAmount; params.transferable = true; - lockupDynamic.createWithDeltas(params); + lockupDynamic.createWithDurations(params); // Check if the stream is settled. It is possible for a Lockup Dynamic stream to settle at the time of creation // because some segment amounts can be zero. @@ -118,7 +118,7 @@ contract CreateWithDeltas_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/createWithMilestones.t.sol b/test/integration/fuzz/lockup-dynamic/createWithTimestamps.t.sol similarity index 89% rename from test/integration/fuzz/lockup-dynamic/createWithMilestones.t.sol rename to test/integration/fuzz/lockup-dynamic/createWithTimestamps.t.sol index 6db69943c..16909789f 100644 --- a/test/integration/fuzz/lockup-dynamic/createWithMilestones.t.sol +++ b/test/integration/fuzz/lockup-dynamic/createWithTimestamps.t.sol @@ -7,20 +7,20 @@ import { stdError } from "forge-std/src/StdError.sol"; import { Errors } from "src/libraries/Errors.sol"; import { Broker, Lockup, LockupDynamic } from "src/types/DataTypes.sol"; -import { CreateWithMilestones_Integration_Shared_Test } from "../../shared/lockup-dynamic/createWithMilestones.t.sol"; +import { CreateWithTimestamps_Integration_Shared_Test } from "../../shared/lockup-dynamic/createWithTimestamps.t.sol"; import { LockupDynamic_Integration_Fuzz_Test } from "./LockupDynamic.t.sol"; -contract CreateWithMilestones_LockupDynamic_Integration_Fuzz_Test is +contract CreateWithTimestamps_LockupDynamic_Integration_Fuzz_Test is LockupDynamic_Integration_Fuzz_Test, - CreateWithMilestones_Integration_Shared_Test + CreateWithTimestamps_Integration_Shared_Test { function setUp() public virtual - override(LockupDynamic_Integration_Fuzz_Test, CreateWithMilestones_Integration_Shared_Test) + override(LockupDynamic_Integration_Fuzz_Test, CreateWithTimestamps_Integration_Shared_Test) { LockupDynamic_Integration_Fuzz_Test.setUp(); - CreateWithMilestones_Integration_Shared_Test.setUp(); + CreateWithTimestamps_Integration_Shared_Test.setUp(); } function testFuzz_RevertWhen_SegmentCountTooHigh(uint256 segmentCount) @@ -58,7 +58,7 @@ contract CreateWithMilestones_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 CreateWithMilestones_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 CreateWithMilestones_LockupDynamic_Integration_Fuzz_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture { depositDiff = boundUint128(depositDiff, 100, defaults.TOTAL_AMOUNT()); @@ -111,7 +111,7 @@ contract CreateWithMilestones_LockupDynamic_Integration_Fuzz_Test is uint128 depositAmount = defaultDepositAmount + depositDiff; // Prepare the params. - LockupDynamic.CreateWithMilestones memory params = defaults.createWithMilestones(); + LockupDynamic.CreateWithTimestamps memory params = defaults.createWithTimestampsLD(); params.broker = Broker({ account: address(0), fee: brokerFee }); params.totalAmount = depositAmount; @@ -125,7 +125,7 @@ contract CreateWithMilestones_LockupDynamic_Integration_Fuzz_Test is ); // Create the stream. - lockupDynamic.createWithMilestones(params); + lockupDynamic.createWithTimestamps(params); } function testFuzz_RevertWhen_ProtocolFeeTooHigh(UD60x18 protocolFee) @@ -136,8 +136,8 @@ contract CreateWithMilestones_LockupDynamic_Integration_Fuzz_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum { @@ -163,8 +163,8 @@ contract CreateWithMilestones_LockupDynamic_Integration_Fuzz_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh @@ -193,17 +193,17 @@ contract CreateWithMilestones_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_CreateWithMilestones( + function testFuzz_CreateWithTimestamps( address funder, - LockupDynamic.CreateWithMilestones memory params, + LockupDynamic.CreateWithTimestamps memory params, UD60x18 protocolFee ) external @@ -213,8 +213,8 @@ contract CreateWithMilestones_LockupDynamic_Integration_Fuzz_Test is whenSegmentCountNotZero whenSegmentCountNotTooHigh whenSegmentAmountsSumDoesNotOverflow - whenStartTimeLessThanFirstSegmentMilestone - whenSegmentMilestonesOrdered + whenStartTimeLessThanFirstSegmentTimestamp + whenSegmentTimestampsOrdered whenEndTimeInTheFuture whenDepositAmountEqualToSegmentAmountsSum givenProtocolFeeNotTooHigh @@ -229,8 +229,8 @@ contract CreateWithMilestones_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 CreateWithMilestones_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, @@ -285,8 +285,8 @@ contract CreateWithMilestones_LockupDynamic_Integration_Fuzz_Test is }); // Create the stream. - lockupDynamic.createWithMilestones( - LockupDynamic.CreateWithMilestones({ + lockupDynamic.createWithTimestamps( + LockupDynamic.CreateWithTimestamps({ sender: params.sender, recipient: params.recipient, totalAmount: vars.totalAmount, diff --git a/test/integration/fuzz/lockup-dynamic/streamedAmountOf.t.sol b/test/integration/fuzz/lockup-dynamic/streamedAmountOf.t.sol index 66f2dcca7..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. @@ -53,11 +53,11 @@ contract StreamedAmountOf_LockupDynamic_Integration_Fuzz_Test is deal({ token: address(dai), to: users.sender, give: segment.amount }); // Create the stream with the fuzzed segment. - LockupDynamic.CreateWithMilestones memory params = defaults.createWithMilestones(); + LockupDynamic.CreateWithTimestamps memory params = defaults.createWithTimestampsLD(); params.broker = Broker({ account: address(0), fee: ZERO }); params.segments = segments; params.totalAmount = segment.amount; - uint256 streamId = lockupDynamic.createWithMilestones(params); + uint256 streamId = lockupDynamic.createWithTimestamps(params); // Simulate the passage of time. uint40 currentTime = defaults.START_TIME() + timeJump; @@ -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,19 +110,19 @@ 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. deal({ token: address(dai), to: users.sender, give: totalAmount }); // Create the stream with the fuzzed segments. - LockupDynamic.CreateWithMilestones memory params = defaults.createWithMilestones(); + LockupDynamic.CreateWithTimestamps memory params = defaults.createWithTimestampsLD(); params.broker = Broker({ account: address(0), fee: ZERO }); params.segments = segments; params.totalAmount = totalAmount; - uint256 streamId = lockupDynamic.createWithMilestones(params); + uint256 streamId = lockupDynamic.createWithTimestamps(params); // Simulate the passage of time. uint40 currentTime = defaults.START_TIME() + timeJump; @@ -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); @@ -170,11 +170,11 @@ contract StreamedAmountOf_LockupDynamic_Integration_Fuzz_Test is deal({ token: address(dai), to: users.sender, give: totalAmount }); // Create the stream with the fuzzed segments. - LockupDynamic.CreateWithMilestones memory params = defaults.createWithMilestones(); + LockupDynamic.CreateWithTimestamps memory params = defaults.createWithTimestampsLD(); params.broker = Broker({ account: address(0), fee: ZERO }); params.segments = segments; params.totalAmount = totalAmount; - uint256 streamId = lockupDynamic.createWithMilestones(params); + uint256 streamId = lockupDynamic.createWithTimestamps(params); // Warp to the future for the first time. vm.warp({ timestamp: defaults.START_TIME() + timeWarp0 }); diff --git a/test/integration/fuzz/lockup-dynamic/withdraw.t.sol b/test/integration/fuzz/lockup-dynamic/withdraw.t.sol index 45fd367cc..564039809 100644 --- a/test/integration/fuzz/lockup-dynamic/withdraw.t.sol +++ b/test/integration/fuzz/lockup-dynamic/withdraw.t.sol @@ -55,14 +55,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. @@ -72,11 +72,11 @@ contract Withdraw_LockupDynamic_Integration_Fuzz_Test is changePrank({ msgSender: users.sender }); // Create the stream with the fuzzed segments. - LockupDynamic.CreateWithMilestones memory createParams = defaults.createWithMilestones(); + LockupDynamic.CreateWithTimestamps memory createParams = defaults.createWithTimestampsLD(); createParams.totalAmount = vars.totalAmount; createParams.segments = params.segments; - vars.streamId = lockupDynamic.createWithMilestones(createParams); + vars.streamId = lockupDynamic.createWithTimestamps(createParams); // Simulate the passage of time. vm.warp({ timestamp: defaults.START_TIME() + params.timeJump }); diff --git a/test/integration/fuzz/lockup-dynamic/withdrawableAmountOf.t.sol b/test/integration/fuzz/lockup-dynamic/withdrawableAmountOf.t.sol index e44e47485..e604db5df 100644 --- a/test/integration/fuzz/lockup-dynamic/withdrawableAmountOf.t.sol +++ b/test/integration/fuzz/lockup-dynamic/withdrawableAmountOf.t.sol @@ -42,10 +42,10 @@ contract WithdrawableAmountOf_LockupDynamic_Integration_Fuzz_Test is // Create the stream with a custom total amount. The broker fee is disabled so that it doesn't interfere with // the calculations. - LockupDynamic.CreateWithMilestones memory params = defaults.createWithMilestones(); + LockupDynamic.CreateWithTimestamps memory params = defaults.createWithTimestampsLD(); params.broker = Broker({ account: address(0), fee: ZERO }); params.totalAmount = defaults.DEPOSIT_AMOUNT(); - uint256 streamId = lockupDynamic.createWithMilestones(params); + uint256 streamId = lockupDynamic.createWithTimestamps(params); // Simulate the passage of time. uint40 currentTime = defaults.START_TIME() + timeJump; @@ -92,10 +92,10 @@ contract WithdrawableAmountOf_LockupDynamic_Integration_Fuzz_Test is // Create the stream with a custom total amount. The broker fee is disabled so that it doesn't interfere with // the calculations. - LockupDynamic.CreateWithMilestones memory params = defaults.createWithMilestones(); + LockupDynamic.CreateWithTimestamps memory params = defaults.createWithTimestampsLD(); params.broker = Broker({ account: address(0), fee: ZERO }); params.totalAmount = defaults.DEPOSIT_AMOUNT(); - uint256 streamId = lockupDynamic.createWithMilestones(params); + uint256 streamId = lockupDynamic.createWithTimestamps(params); // Simulate the passage of time. vm.warp({ timestamp: currentTime }); diff --git a/test/integration/fuzz/lockup-linear/createWithRange.t.sol b/test/integration/fuzz/lockup-linear/createWithTimestamps.t.sol similarity index 94% rename from test/integration/fuzz/lockup-linear/createWithRange.t.sol rename to test/integration/fuzz/lockup-linear/createWithTimestamps.t.sol index e82fb3123..1916ea86f 100644 --- a/test/integration/fuzz/lockup-linear/createWithRange.t.sol +++ b/test/integration/fuzz/lockup-linear/createWithTimestamps.t.sol @@ -6,20 +6,20 @@ import { MAX_UD60x18, UD60x18, ud } from "@prb/math/src/UD60x18.sol"; import { Errors } from "src/libraries/Errors.sol"; import { Broker, Lockup, LockupLinear } from "src/types/DataTypes.sol"; -import { CreateWithRange_Integration_Shared_Test } from "../../shared/lockup-linear/createWithRange.t.sol"; +import { CreateWithTimestamps_Integration_Shared_Test } from "../../shared/lockup-linear/createWithTimestamps.t.sol"; import { LockupLinear_Integration_Fuzz_Test } from "./LockupLinear.t.sol"; -contract CreateWithRange_LockupLinear_Integration_Fuzz_Test is +contract CreateWithTimestamps_LockupLinear_Integration_Fuzz_Test is LockupLinear_Integration_Fuzz_Test, - CreateWithRange_Integration_Shared_Test + CreateWithTimestamps_Integration_Shared_Test { function setUp() public virtual - override(LockupLinear_Integration_Fuzz_Test, CreateWithRange_Integration_Shared_Test) + override(LockupLinear_Integration_Fuzz_Test, CreateWithTimestamps_Integration_Shared_Test) { LockupLinear_Integration_Fuzz_Test.setUp(); - CreateWithRange_Integration_Shared_Test.setUp(); + CreateWithTimestamps_Integration_Shared_Test.setUp(); } function testFuzz_RevertWhen_StartTimeGreaterThanCliffTime(uint40 startTime) @@ -123,9 +123,9 @@ contract CreateWithRange_LockupLinear_Integration_Fuzz_Test is /// - Multiple values for the cliff time and the end time /// - Multiple values for the broker fee, including zero /// - Multiple values for the protocol fee, including zero - function testFuzz_CreateWithRange( + function testFuzz_CreateWithTimestamps( address funder, - LockupLinear.CreateWithRange memory params, + LockupLinear.CreateWithTimestamps memory params, UD60x18 protocolFee ) external @@ -196,8 +196,8 @@ contract CreateWithRange_LockupLinear_Integration_Fuzz_Test is }); // Create the stream. - lockupLinear.createWithRange( - LockupLinear.CreateWithRange({ + lockupLinear.createWithTimestamps( + LockupLinear.CreateWithTimestamps({ sender: params.sender, recipient: params.recipient, totalAmount: params.totalAmount, diff --git a/test/integration/fuzz/lockup-linear/streamedAmountOf.t.sol b/test/integration/fuzz/lockup-linear/streamedAmountOf.t.sol index f738bf2a4..98bbd1656 100644 --- a/test/integration/fuzz/lockup-linear/streamedAmountOf.t.sol +++ b/test/integration/fuzz/lockup-linear/streamedAmountOf.t.sol @@ -67,10 +67,10 @@ contract StreamedAmountOf_LockupLinear_Integration_Fuzz_Test is deal({ token: address(dai), to: users.sender, give: depositAmount }); // Create the stream with the fuzzed deposit amount. - LockupLinear.CreateWithRange memory params = defaults.createWithRange(); + LockupLinear.CreateWithTimestamps memory params = defaults.createWithTimestampsLL(); params.broker = Broker({ account: address(0), fee: ZERO }); params.totalAmount = depositAmount; - uint256 streamId = lockupLinear.createWithRange(params); + uint256 streamId = lockupLinear.createWithTimestamps(params); // Simulate the passage of time. uint40 currentTime = defaults.START_TIME() + timeJump; @@ -101,9 +101,9 @@ contract StreamedAmountOf_LockupLinear_Integration_Fuzz_Test is deal({ token: address(dai), to: users.sender, give: depositAmount }); // Create the stream with the fuzzed deposit amount. - LockupLinear.CreateWithRange memory params = defaults.createWithRange(); + LockupLinear.CreateWithTimestamps memory params = defaults.createWithTimestampsLL(); params.totalAmount = depositAmount; - uint256 streamId = lockupLinear.createWithRange(params); + uint256 streamId = lockupLinear.createWithTimestamps(params); // Warp to the future for the first time. vm.warp({ timestamp: defaults.START_TIME() + timeWarp0 }); diff --git a/test/integration/fuzz/lockup-linear/withdrawableAmountOf.t.sol b/test/integration/fuzz/lockup-linear/withdrawableAmountOf.t.sol index a76aa21e9..d0b93bc64 100644 --- a/test/integration/fuzz/lockup-linear/withdrawableAmountOf.t.sol +++ b/test/integration/fuzz/lockup-linear/withdrawableAmountOf.t.sol @@ -64,10 +64,10 @@ contract WithdrawableAmountOf_LockupLinear_Integration_Fuzz_Test is deal({ token: address(dai), to: users.sender, give: depositAmount }); // Create the stream. The broker fee is disabled so that it doesn't interfere with the calculations. - LockupLinear.CreateWithRange memory params = defaults.createWithRange(); + LockupLinear.CreateWithTimestamps memory params = defaults.createWithTimestampsLL(); params.broker = Broker({ account: address(0), fee: ZERO }); params.totalAmount = depositAmount; - uint256 streamId = lockupLinear.createWithRange(params); + uint256 streamId = lockupLinear.createWithTimestamps(params); // Simulate the passage of time. uint40 currentTime = defaults.START_TIME() + timeJump; @@ -119,10 +119,10 @@ contract WithdrawableAmountOf_LockupLinear_Integration_Fuzz_Test is deal({ token: address(dai), to: users.sender, give: depositAmount }); // Create the stream. The broker fee is disabled so that it doesn't interfere with the calculations. - LockupLinear.CreateWithRange memory params = defaults.createWithRange(); + LockupLinear.CreateWithTimestamps memory params = defaults.createWithTimestampsLL(); params.broker = Broker({ account: address(0), fee: ZERO }); params.totalAmount = depositAmount; - uint256 streamId = lockupLinear.createWithRange(params); + uint256 streamId = lockupLinear.createWithTimestamps(params); // Simulate the passage of time. vm.warp({ timestamp: currentTime }); diff --git a/test/integration/shared/lockup-dynamic/LockupDynamic.t.sol b/test/integration/shared/lockup-dynamic/LockupDynamic.t.sol index 5e1bd327e..b67bf3aa4 100644 --- a/test/integration/shared/lockup-dynamic/LockupDynamic.t.sol +++ b/test/integration/shared/lockup-dynamic/LockupDynamic.t.sol @@ -10,8 +10,8 @@ import { Lockup_Integration_Shared_Test } from "../lockup/Lockup.t.sol"; /// @notice Common testing logic needed across {SablierV2LockupDynamic} integration tests. abstract contract LockupDynamic_Integration_Shared_Test is Lockup_Integration_Shared_Test { struct CreateParams { - LockupDynamic.CreateWithDeltas createWithDeltas; - LockupDynamic.CreateWithMilestones createWithMilestones; + LockupDynamic.CreateWithDurations createWithDurations; + LockupDynamic.CreateWithTimestamps createWithTimestamps; } /// @dev These have to be pre-declared so that `vm.expectRevert` does not expect a revert in `defaults`. @@ -21,100 +21,100 @@ abstract contract LockupDynamic_Integration_Shared_Test is Lockup_Integration_Sh function setUp() public virtual override { Lockup_Integration_Shared_Test.setUp(); - _params.createWithDeltas.sender = users.sender; - _params.createWithDeltas.recipient = users.recipient; - _params.createWithDeltas.totalAmount = defaults.TOTAL_AMOUNT(); - _params.createWithDeltas.asset = dai; - _params.createWithDeltas.cancelable = true; - _params.createWithDeltas.transferable = true; - _params.createWithDeltas.broker = defaults.broker(); - - _params.createWithMilestones.sender = users.sender; - _params.createWithMilestones.recipient = users.recipient; - _params.createWithMilestones.totalAmount = defaults.TOTAL_AMOUNT(); - _params.createWithMilestones.asset = dai; - _params.createWithMilestones.cancelable = true; - _params.createWithMilestones.transferable = true; - _params.createWithMilestones.startTime = defaults.START_TIME(); - _params.createWithMilestones.broker = defaults.broker(); + _params.createWithDurations.sender = users.sender; + _params.createWithDurations.recipient = users.recipient; + _params.createWithDurations.totalAmount = defaults.TOTAL_AMOUNT(); + _params.createWithDurations.asset = dai; + _params.createWithDurations.cancelable = true; + _params.createWithDurations.transferable = true; + _params.createWithDurations.broker = defaults.broker(); + + _params.createWithTimestamps.sender = users.sender; + _params.createWithTimestamps.recipient = users.recipient; + _params.createWithTimestamps.totalAmount = defaults.TOTAL_AMOUNT(); + _params.createWithTimestamps.asset = dai; + _params.createWithTimestamps.cancelable = true; + _params.createWithTimestamps.transferable = true; + _params.createWithTimestamps.startTime = defaults.START_TIME(); + _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.createWithDeltas.segments.push(segmentsWithDeltas[i]); - _params.createWithMilestones.segments.push(segments[i]); + _params.createWithDurations.segments.push(segmentsWithDurations[i]); + _params.createWithTimestamps.segments.push(segments[i]); } } /// @dev Creates the default stream. function createDefaultStream() internal override returns (uint256 streamId) { - streamId = lockupDynamic.createWithMilestones(_params.createWithMilestones); + streamId = lockupDynamic.createWithTimestamps(_params.createWithTimestamps); } /// @dev Creates the default stream with the provided asset. function createDefaultStreamWithAsset(IERC20 asset) internal override returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.asset = asset; - streamId = lockupDynamic.createWithMilestones(params); + streamId = lockupDynamic.createWithTimestamps(params); } /// @dev Creates the default stream with the provided broker. function createDefaultStreamWithBroker(Broker memory broker) internal override returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.broker = broker; - streamId = lockupDynamic.createWithMilestones(params); + streamId = lockupDynamic.createWithTimestamps(params); } - /// @dev Creates the default stream with deltas. - function createDefaultStreamWithDeltas() internal returns (uint256 streamId) { - streamId = lockupDynamic.createWithDeltas(_params.createWithDeltas); + /// @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) { - LockupDynamic.CreateWithDeltas memory params = _params.createWithDeltas; + LockupDynamic.CreateWithDurations memory params = _params.createWithDurations; params.segments = segments; - streamId = lockupDynamic.createWithDeltas(params); + streamId = lockupDynamic.createWithDurations(params); } /// @dev Creates the default stream with the provided end time. function createDefaultStreamWithEndTime(uint40 endTime) internal override returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; - params.segments[1].milestone = endTime; - streamId = lockupDynamic.createWithMilestones(params); + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; + params.segments[1].timestamp = endTime; + streamId = lockupDynamic.createWithTimestamps(params); } /// @dev Creates a stream that will not be cancelable. function createDefaultStreamNotCancelable() internal override returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.cancelable = false; - streamId = lockupDynamic.createWithMilestones(params); + streamId = lockupDynamic.createWithTimestamps(params); } /// @dev Creates the default stream with the NFT transfer disabled. function createDefaultStreamNotTransferable() internal override returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.transferable = false; - streamId = lockupDynamic.createWithMilestones(params); + streamId = lockupDynamic.createWithTimestamps(params); } /// @dev Creates the default stream with the provided range. function createDefaultStreamWithRange(LockupDynamic.Range memory range) internal returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.startTime = range.start; - params.segments[1].milestone = range.end; - streamId = lockupDynamic.createWithMilestones(params); + params.segments[1].timestamp = range.end; + streamId = lockupDynamic.createWithTimestamps(params); } /// @dev Creates the default stream with the provided recipient. function createDefaultStreamWithRecipient(address recipient) internal override returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.recipient = recipient; - streamId = lockupDynamic.createWithMilestones(params); + streamId = lockupDynamic.createWithTimestamps(params); } /// @dev Creates the default stream with the provided segments. @@ -122,29 +122,29 @@ abstract contract LockupDynamic_Integration_Shared_Test is Lockup_Integration_Sh internal returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.segments = segments; - streamId = lockupDynamic.createWithMilestones(params); + streamId = lockupDynamic.createWithTimestamps(params); } /// @dev Creates the default stream with the provided sender. function createDefaultStreamWithSender(address sender) internal override returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.sender = sender; - streamId = lockupDynamic.createWithMilestones(params); + streamId = lockupDynamic.createWithTimestamps(params); } /// @dev Creates the default stream with the provided start time.. function createDefaultStreamWithStartTime(uint40 startTime) internal override returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.startTime = startTime; - streamId = lockupDynamic.createWithMilestones(params); + streamId = lockupDynamic.createWithTimestamps(params); } /// @dev Creates the default stream with the provided total amount. function createDefaultStreamWithTotalAmount(uint128 totalAmount) internal override returns (uint256 streamId) { - LockupDynamic.CreateWithMilestones memory params = _params.createWithMilestones; + LockupDynamic.CreateWithTimestamps memory params = _params.createWithTimestamps; params.totalAmount = totalAmount; - streamId = lockupDynamic.createWithMilestones(params); + streamId = lockupDynamic.createWithTimestamps(params); } } diff --git a/test/integration/shared/lockup-dynamic/createWithDeltas.t.sol b/test/integration/shared/lockup-dynamic/createWithDurations.t.sol similarity index 70% rename from test/integration/shared/lockup-dynamic/createWithDeltas.t.sol rename to test/integration/shared/lockup-dynamic/createWithDurations.t.sol index 66ae9dcd4..31460ec2b 100644 --- a/test/integration/shared/lockup-dynamic/createWithDeltas.t.sol +++ b/test/integration/shared/lockup-dynamic/createWithDurations.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.22 <0.9.0; import { LockupDynamic_Integration_Shared_Test } from "./LockupDynamic.t.sol"; -contract CreateWithDeltas_Integration_Shared_Test is LockupDynamic_Integration_Shared_Test { +contract CreateWithDurations_Integration_Shared_Test is LockupDynamic_Integration_Shared_Test { uint256 internal streamId; function setUp() public virtual override { @@ -18,11 +18,11 @@ contract CreateWithDeltas_Integration_Shared_Test is LockupDynamic_Integration_S _; } - modifier whenDeltasNotZero() { + modifier whenDurationsNotZero() { _; } - modifier whenMilestonesCalculationsDoNotOverflow() { + modifier whenTimestampsCalculationsDoNotOverflow() { _; } } diff --git a/test/integration/shared/lockup-dynamic/createWithMilestones.t.sol b/test/integration/shared/lockup-dynamic/createWithTimestamps.t.sol similarity index 86% rename from test/integration/shared/lockup-dynamic/createWithMilestones.t.sol rename to test/integration/shared/lockup-dynamic/createWithTimestamps.t.sol index 34c08fa11..574f79390 100644 --- a/test/integration/shared/lockup-dynamic/createWithMilestones.t.sol +++ b/test/integration/shared/lockup-dynamic/createWithTimestamps.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.22 <0.9.0; import { LockupDynamic_Integration_Shared_Test } from "./LockupDynamic.t.sol"; -contract CreateWithMilestones_Integration_Shared_Test is LockupDynamic_Integration_Shared_Test { +contract CreateWithTimestamps_Integration_Shared_Test is LockupDynamic_Integration_Shared_Test { uint256 internal streamId; function setUp() public virtual override { @@ -34,11 +34,11 @@ contract CreateWithMilestones_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 2d90706fd..1fe86adbf 100644 --- a/test/integration/shared/lockup-linear/LockupLinear.t.sol +++ b/test/integration/shared/lockup-linear/LockupLinear.t.sol @@ -11,7 +11,7 @@ import { Lockup_Integration_Shared_Test } from "../lockup/Lockup.t.sol"; abstract contract LockupLinear_Integration_Shared_Test is Lockup_Integration_Shared_Test { struct Params { LockupLinear.CreateWithDurations createWithDurations; - LockupLinear.CreateWithRange createWithRange; + LockupLinear.CreateWithTimestamps createWithTimestamps; } /// @dev These have to be pre-declared so that `vm.expectRevert` does not expect a revert in `defaults`. @@ -20,27 +20,27 @@ abstract contract LockupLinear_Integration_Shared_Test is Lockup_Integration_Sha function setUp() public virtual override { Lockup_Integration_Shared_Test.setUp(); - _params.createWithDurations = defaults.createWithDurations(); - _params.createWithRange = defaults.createWithRange(); + _params.createWithDurations = defaults.createWithDurationsLL(); + _params.createWithTimestamps = defaults.createWithTimestampsLL(); } /// @dev Creates the default stream. function createDefaultStream() internal override returns (uint256 streamId) { - streamId = lockupLinear.createWithRange(_params.createWithRange); + streamId = lockupLinear.createWithTimestamps(_params.createWithTimestamps); } /// @dev Creates the default stream with the provided address. function createDefaultStreamWithAsset(IERC20 asset) internal override returns (uint256 streamId) { - LockupLinear.CreateWithRange memory params = _params.createWithRange; + LockupLinear.CreateWithTimestamps memory params = _params.createWithTimestamps; params.asset = asset; - streamId = lockupLinear.createWithRange(params); + streamId = lockupLinear.createWithTimestamps(params); } /// @dev Creates the default stream with the provided broker. function createDefaultStreamWithBroker(Broker memory broker) internal override returns (uint256 streamId) { - LockupLinear.CreateWithRange memory params = _params.createWithRange; + LockupLinear.CreateWithTimestamps memory params = _params.createWithTimestamps; params.broker = broker; - streamId = lockupLinear.createWithRange(params); + streamId = lockupLinear.createWithTimestamps(params); } /// @dev Creates the default stream with durations. @@ -60,60 +60,57 @@ abstract contract LockupLinear_Integration_Shared_Test is Lockup_Integration_Sha /// @dev Creates the default stream that is not cancelable. function createDefaultStreamNotCancelable() internal override returns (uint256 streamId) { - LockupLinear.CreateWithRange memory params = _params.createWithRange; + LockupLinear.CreateWithTimestamps memory params = _params.createWithTimestamps; params.cancelable = false; - streamId = lockupLinear.createWithRange(params); + streamId = lockupLinear.createWithTimestamps(params); } /// @dev Creates the default stream with the NFT transfer disabled. function createDefaultStreamNotTransferable() internal override returns (uint256 streamId) { - LockupLinear.CreateWithRange memory params = _params.createWithRange; + LockupLinear.CreateWithTimestamps memory params = _params.createWithTimestamps; params.transferable = false; - streamId = lockupLinear.createWithRange(params); + streamId = lockupLinear.createWithTimestamps(params); } /// @dev Creates the default stream with the provided end time. function createDefaultStreamWithEndTime(uint40 endTime) internal override returns (uint256 streamId) { - LockupLinear.CreateWithRange memory params = _params.createWithRange; + LockupLinear.CreateWithTimestamps memory params = _params.createWithTimestamps; params.range.end = endTime; - streamId = lockupLinear.createWithRange(params); + streamId = lockupLinear.createWithTimestamps(params); } - /// @dev Creates the default stream with the provided createWithRange. - function createDefaultStreamWithRange(LockupLinear.Range memory createWithRange) - internal - returns (uint256 streamId) - { - LockupLinear.CreateWithRange memory params = _params.createWithRange; - params.range = createWithRange; - streamId = lockupLinear.createWithRange(params); + /// @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 = range; + streamId = lockupLinear.createWithTimestamps(params); } /// @dev Creates the default stream with the provided recipient. function createDefaultStreamWithRecipient(address recipient) internal override returns (uint256 streamId) { - LockupLinear.CreateWithRange memory params = _params.createWithRange; + LockupLinear.CreateWithTimestamps memory params = _params.createWithTimestamps; params.recipient = recipient; - streamId = lockupLinear.createWithRange(params); + streamId = lockupLinear.createWithTimestamps(params); } /// @dev Creates the default stream with the provided sender. function createDefaultStreamWithSender(address sender) internal override returns (uint256 streamId) { - LockupLinear.CreateWithRange memory params = _params.createWithRange; + LockupLinear.CreateWithTimestamps memory params = _params.createWithTimestamps; params.sender = sender; - streamId = lockupLinear.createWithRange(params); + streamId = lockupLinear.createWithTimestamps(params); } /// @dev Creates the default stream with the provided start time. function createDefaultStreamWithStartTime(uint40 startTime) internal override returns (uint256 streamId) { - LockupLinear.CreateWithRange memory params = _params.createWithRange; + LockupLinear.CreateWithTimestamps memory params = _params.createWithTimestamps; params.range.start = startTime; - streamId = lockupLinear.createWithRange(params); + streamId = lockupLinear.createWithTimestamps(params); } /// @dev Creates the default stream with the provided total amount. function createDefaultStreamWithTotalAmount(uint128 totalAmount) internal override returns (uint256 streamId) { - LockupLinear.CreateWithRange memory params = _params.createWithRange; + LockupLinear.CreateWithTimestamps memory params = _params.createWithTimestamps; params.totalAmount = totalAmount; - streamId = lockupLinear.createWithRange(params); + streamId = lockupLinear.createWithTimestamps(params); } } diff --git a/test/integration/shared/lockup-linear/createWithRange.t.sol b/test/integration/shared/lockup-linear/createWithTimestamps.t.sol similarity index 89% rename from test/integration/shared/lockup-linear/createWithRange.t.sol rename to test/integration/shared/lockup-linear/createWithTimestamps.t.sol index 2e7c59223..df2734c6d 100644 --- a/test/integration/shared/lockup-linear/createWithRange.t.sol +++ b/test/integration/shared/lockup-linear/createWithTimestamps.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.22 <0.9.0; import { LockupLinear_Integration_Shared_Test } from "./LockupLinear.t.sol"; -abstract contract CreateWithRange_Integration_Shared_Test is LockupLinear_Integration_Shared_Test { +abstract contract CreateWithTimestamps_Integration_Shared_Test is LockupLinear_Integration_Shared_Test { uint256 internal streamId; function setUp() public virtual override { 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 b101c2873..41eb5d3cf 100644 --- a/test/invariant/handlers/LockupDynamicCreateHandler.sol +++ b/test/invariant/handlers/LockupDynamicCreateHandler.sol @@ -45,12 +45,12 @@ contract LockupDynamicCreateHandler is BaseHandler { HANDLER FUNCTIONS //////////////////////////////////////////////////////////////////////////*/ - function createWithDeltas( + function createWithDurations( uint256 timeJumpSeed, - LockupDynamic.CreateWithDeltas memory params + LockupDynamic.CreateWithDurations memory params ) public - instrument("createWithDeltas") + instrument("createWithDurations") adjustTimestamp(timeJumpSeed) checkUsers(params.sender, params.recipient, params.broker.account) useNewSender(params.sender) @@ -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({ @@ -87,18 +87,18 @@ contract LockupDynamicCreateHandler is BaseHandler { // Create the stream. params.asset = asset; - uint256 streamId = lockupDynamic.createWithDeltas(params); + uint256 streamId = lockupDynamic.createWithDurations(params); // Store the stream id. lockupStore.pushStreamId(streamId, params.sender, params.recipient); } - function createWithMilestones( + function createWithTimestamps( uint256 timeJumpSeed, - LockupDynamic.CreateWithMilestones memory params + LockupDynamic.CreateWithTimestamps memory params ) public - instrument("createWithMilestones") + instrument("createWithTimestamps") adjustTimestamp(timeJumpSeed) checkUsers(params.sender, params.recipient, params.broker.account) useNewSender(params.sender) @@ -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({ @@ -135,7 +135,7 @@ contract LockupDynamicCreateHandler is BaseHandler { // Create the stream. params.asset = asset; - uint256 streamId = lockupDynamic.createWithMilestones(params); + uint256 streamId = lockupDynamic.createWithTimestamps(params); // Store the stream id. lockupStore.pushStreamId(streamId, params.sender, params.recipient); diff --git a/test/invariant/handlers/LockupLinearCreateHandler.sol b/test/invariant/handlers/LockupLinearCreateHandler.sol index af048de0a..1635c3f03 100644 --- a/test/invariant/handlers/LockupLinearCreateHandler.sol +++ b/test/invariant/handlers/LockupLinearCreateHandler.sol @@ -77,12 +77,12 @@ contract LockupLinearCreateHandler is BaseHandler { lockupStore.pushStreamId(streamId, params.sender, params.recipient); } - function createWithRange( + function createWithTimestamps( uint256 timeJumpSeed, - LockupLinear.CreateWithRange memory params + LockupLinear.CreateWithTimestamps memory params ) public - instrument("createWithRange") + instrument("createWithTimestamps") adjustTimestamp(timeJumpSeed) checkUsers(params.sender, params.recipient, params.broker.account) useNewSender(params.sender) @@ -114,7 +114,7 @@ contract LockupLinearCreateHandler is BaseHandler { // Create the stream. params.asset = asset; - uint256 streamId = lockupLinear.createWithRange(params); + uint256 streamId = lockupLinear.createWithTimestamps(params); // Store the stream id. lockupStore.pushStreamId(streamId, params.sender, params.recipient); 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 244bfbff0..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 }) ); } @@ -181,20 +185,20 @@ contract Defaults is Constants { PARAMS //////////////////////////////////////////////////////////////////////////*/ - function createWithDeltas() public view returns (LockupDynamic.CreateWithDeltas memory) { - return LockupDynamic.CreateWithDeltas({ + function createWithDurationsLD() public view returns (LockupDynamic.CreateWithDurations memory) { + return LockupDynamic.CreateWithDurations({ sender: users.sender, recipient: users.recipient, totalAmount: TOTAL_AMOUNT, asset: asset, cancelable: true, transferable: true, - segments: segmentsWithDeltas(), + segments: segmentsWithDurations(), broker: broker() }); } - function createWithDurations() public view returns (LockupLinear.CreateWithDurations memory) { + function createWithDurationsLL() public view returns (LockupLinear.CreateWithDurations memory) { return LockupLinear.CreateWithDurations({ sender: users.sender, recipient: users.recipient, @@ -207,8 +211,8 @@ contract Defaults is Constants { }); } - function createWithMilestones() public view returns (LockupDynamic.CreateWithMilestones memory) { - return LockupDynamic.CreateWithMilestones({ + function createWithTimestampsLD() public view returns (LockupDynamic.CreateWithTimestamps memory) { + return LockupDynamic.CreateWithTimestamps({ sender: users.sender, recipient: users.recipient, totalAmount: TOTAL_AMOUNT, @@ -221,8 +225,8 @@ contract Defaults is Constants { }); } - function createWithRange() public view returns (LockupLinear.CreateWithRange memory) { - return LockupLinear.CreateWithRange({ + function createWithTimestampsLL() public view returns (LockupLinear.CreateWithTimestamps memory) { + return LockupLinear.CreateWithTimestamps({ sender: users.sender, recipient: users.recipient, totalAmount: TOTAL_AMOUNT, 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 }); } }