Skip to content

Commit

Permalink
refactor: rename create functions
Browse files Browse the repository at this point in the history
  • Loading branch information
andreivladbrg committed Jan 21, 2024
1 parent ca8bfdb commit 720cc45
Show file tree
Hide file tree
Showing 32 changed files with 227 additions and 218 deletions.
4 changes: 2 additions & 2 deletions script/Init.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ contract Init is BaseScript {
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.createWithDurations(
LockupDynamic.CreateWithDurations({
sender: sender,
recipient: recipient,
totalAmount: 10_000e18,
Expand Down
14 changes: 7 additions & 7 deletions src/SablierV2LockupDynamic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ contract SablierV2LockupDynamic is
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ISablierV2LockupDynamic
function createWithDeltas(LockupDynamic.CreateWithDeltas calldata params)
function createWithDurations(LockupDynamic.CreateWithDurations calldata params)
external
override
noDelegateCall
Expand All @@ -277,8 +277,8 @@ contract SablierV2LockupDynamic is
LockupDynamic.Segment[] memory segments = Helpers.checkDeltasAndCalculateMilestones(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,
Expand All @@ -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);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions src/SablierV2LockupLinear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/interfaces/ISablierV2LockupDynamic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ interface ISablierV2LockupDynamic is ISablierV2Lockup {
/// @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.
/// The stream is funded by `msg.sender` and is wrapped in an ERC-721 NFT.
Expand All @@ -127,7 +129,7 @@ interface ISablierV2LockupDynamic is ISablierV2Lockup {
///
/// @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);
}
6 changes: 4 additions & 2 deletions src/interfaces/ISablierV2LockupLinear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
8 changes: 4 additions & 4 deletions src/libraries/Helpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions src/types/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -83,7 +83,7 @@ library LockupDynamic {
/// starting from `block.timestamp` and adding each delta to the previous milestone.
/// @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;
Expand All @@ -94,7 +94,7 @@ library LockupDynamic {
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`.
Expand All @@ -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;
Expand Down Expand Up @@ -139,7 +139,7 @@ library LockupDynamic {
uint40 milestone;
}

/// @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.
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/fork/LockupDynamic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/fork/LockupLinear.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ 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);
}
Expand All @@ -44,7 +45,7 @@ contract CreateWithDeltas_LockupDynamic_Integration_Concrete_Test is
whenLoopCalculationsDoNotOverflowBlockGasLimit
{
uint40 startTime = getBlockTimestamp();
LockupDynamic.SegmentWithDelta[] memory segments = defaults.createWithDeltas().segments;
LockupDynamic.SegmentWithDelta[] memory segments = defaults.createWithDurationsLD().segments;
segments[1].delta = 0;
uint256 index = 1;
vm.expectRevert(
Expand All @@ -66,7 +67,7 @@ contract CreateWithDeltas_LockupDynamic_Integration_Concrete_Test is
{
unchecked {
uint40 startTime = getBlockTimestamp();
LockupDynamic.SegmentWithDelta[] memory segments = defaults.createWithDeltas().segments;
LockupDynamic.SegmentWithDelta[] memory segments = defaults.createWithDurationsLD().segments;
segments[0].delta = MAX_UINT40;
vm.expectRevert(
abi.encodeWithSelector(
Expand Down Expand Up @@ -111,7 +112,7 @@ contract CreateWithDeltas_LockupDynamic_Integration_Concrete_Test is
}
}

function test_CreateWithDeltas()
function test_CreateWithDurations()
external
whenNotDelegateCalled
whenLoopCalculationsDoNotOverflowBlockGasLimit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
createWithDeltas.t.sol
createWithDurations.t.sol
├── when delegate called
│ └── it should revert
└── when not delegate called
Expand Down
Loading

0 comments on commit 720cc45

Please sign in to comment.