Skip to content

Commit

Permalink
refactor: delete "funder" argument
Browse files Browse the repository at this point in the history
test: rename "streamIdEve" to "eveStreamId"
test: rewrite tests to account for the removal of the "funder" argument
  • Loading branch information
PaulRBerg committed Jun 21, 2022
1 parent 332af1d commit 9e4a546
Show file tree
Hide file tree
Showing 25 changed files with 51 additions and 220 deletions.
6 changes: 0 additions & 6 deletions src/SablierV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,12 @@ abstract contract SablierV2 is ISablierV2 {

/// @dev Checks the basic requiremenets for the `create` function.
function checkCreateArguments(
address funder,
address sender,
address recipient,
uint256 depositAmount,
uint256 startTime,
uint256 stopTime
) internal pure {
// Checks: the funder is not the zero address.
if (funder == address(0)) {
revert SablierV2__FunderZeroAddress();
}

// Checks: the sender is not the zero address.
if (sender == address(0)) {
revert SablierV2__SenderZeroAddress();
Expand Down
43 changes: 5 additions & 38 deletions src/SablierV2Cliff.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ contract SablierV2Cliff is

/// @inheritdoc ISablierV2Cliff
function create(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand All @@ -155,28 +154,12 @@ contract SablierV2Cliff is
uint256 stopTime,
bool cancelable
) external returns (uint256 streamId) {
// Checks: the funder is not the zero address.
if (funder == address(0)) {
revert SablierV2__FunderZeroAddress();
}

// Checks, Effects and Interactions: create the stream.
streamId = createInternal(
funder,
sender,
recipient,
depositAmount,
token,
startTime,
cliffTime,
stopTime,
cancelable
);
streamId = createInternal(sender, recipient, depositAmount, token, startTime, cliffTime, stopTime, cancelable);
}

/// @inheritdoc ISablierV2Cliff
function createWithDuration(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand All @@ -185,11 +168,6 @@ contract SablierV2Cliff is
uint256 totalDuration,
bool cancelable
) external returns (uint256 streamId) {
// Checks: the funder is not the zero address.
if (funder == address(0)) {
revert SablierV2__FunderZeroAddress();
}

// Calculate the cliff time and the stop time. It is fine to use unchecked arithmetic because the
// `createInternal` function will nonetheless check that the stop time is greater than or equal to the
// cliff time, and that the cliff time is greater than or equal to the start time.
Expand All @@ -202,17 +180,7 @@ contract SablierV2Cliff is
}

// Checks, Effects and Interactions: create the stream.
streamId = createInternal(
funder,
sender,
recipient,
depositAmount,
token,
startTime,
cliffTime,
stopTime,
cancelable
);
streamId = createInternal(sender, recipient, depositAmount, token, startTime, cliffTime, stopTime, cancelable);
}

/// @inheritdoc ISablierV2
Expand Down Expand Up @@ -368,7 +336,6 @@ contract SablierV2Cliff is

/// @dev See the documentation for the public functions that call this internal function.
function createInternal(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand All @@ -379,7 +346,7 @@ contract SablierV2Cliff is
bool cancelable
) internal returns (uint256 streamId) {
// Checks: the common requirements for the `create` function arguments.
checkCreateArguments(funder, sender, recipient, depositAmount, startTime, stopTime);
checkCreateArguments(sender, recipient, depositAmount, startTime, stopTime);

// Checks: the cliff time is greater than or equal to the start time.
if (startTime > cliffTime) {
Expand Down Expand Up @@ -412,12 +379,12 @@ contract SablierV2Cliff is
}

// Interactions: perform the ERC-20 transfer.
token.safeTransferFrom(funder, address(this), depositAmount);
token.safeTransferFrom(msg.sender, address(this), depositAmount);

// Emit an event.
emit CreateStream(
streamId,
funder,
msg.sender,
sender,
recipient,
depositAmount,
Expand Down
23 changes: 15 additions & 8 deletions src/SablierV2Linear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ contract SablierV2Linear is

/// @inheritdoc ISablierV2Linear
function create(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand All @@ -150,12 +149,11 @@ contract SablierV2Linear is
bool cancelable
) external returns (uint256 streamId) {
// Checks, Effects and Interactions: create the stream.
streamId = createInternal(funder, sender, recipient, depositAmount, token, startTime, stopTime, cancelable);
streamId = createInternal(sender, recipient, depositAmount, token, startTime, stopTime, cancelable);
}

/// @inheritdoc ISablierV2Linear
function createWithDuration(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand All @@ -172,7 +170,7 @@ contract SablierV2Linear is
}

// Checks, Effects and Interactions: create the stream.
streamId = createInternal(funder, sender, recipient, depositAmount, token, startTime, stopTime, cancelable);
streamId = createInternal(sender, recipient, depositAmount, token, startTime, stopTime, cancelable);
}

/// @inheritdoc ISablierV2
Expand Down Expand Up @@ -328,7 +326,6 @@ contract SablierV2Linear is

/// @dev See the documentation for the public functions that call this internal function.
function createInternal(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand All @@ -338,7 +335,7 @@ contract SablierV2Linear is
bool cancelable
) internal returns (uint256 streamId) {
// Checks: the common requirements for the `create` function arguments.
checkCreateArguments(funder, sender, recipient, depositAmount, startTime, stopTime);
checkCreateArguments(sender, recipient, depositAmount, startTime, stopTime);

// Effects: create and store the stream.
streamId = nextStreamId;
Expand All @@ -360,10 +357,20 @@ contract SablierV2Linear is
}

// Interactions: perform the ERC-20 transfer.
token.safeTransferFrom(funder, address(this), depositAmount);
token.safeTransferFrom(msg.sender, address(this), depositAmount);

// Emit an event.
emit CreateStream(streamId, funder, sender, recipient, depositAmount, token, startTime, stopTime, cancelable);
emit CreateStream(
streamId,
msg.sender,
sender,
recipient,
depositAmount,
token,
startTime,
stopTime,
cancelable
);
}

/// @dev See the documentation for the public functions that call this internal function.
Expand Down
16 changes: 3 additions & 13 deletions src/SablierV2Pro.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ contract SablierV2Pro is

/// @inheritdoc ISablierV2Pro
function create(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand All @@ -214,14 +213,8 @@ contract SablierV2Pro is
uint256[] memory segmentMilestones,
bool cancelable
) external returns (uint256 streamId) {
// Checks: the funder is not the zero address.
if (funder == address(0)) {
revert SablierV2__FunderZeroAddress();
}

// Checks, Effects and Interactions: create the stream.
streamId = createInternal(
funder,
sender,
recipient,
depositAmount,
Expand All @@ -236,7 +229,6 @@ contract SablierV2Pro is

/// @inheritdoc ISablierV2Pro
function createWithDuration(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand Down Expand Up @@ -267,7 +259,6 @@ contract SablierV2Pro is

// Checks, Effects and Interactions: create the stream.
streamId = createInternal(
funder,
sender,
recipient,
depositAmount,
Expand Down Expand Up @@ -528,7 +519,6 @@ contract SablierV2Pro is

/// @dev See the documentation for the public functions that call this internal function.
function createInternal(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand All @@ -546,7 +536,7 @@ contract SablierV2Pro is
uint256 stopTime = segmentMilestones[segmentCount - 1];

// Checks: the common requirements for the `create` function arguments.
checkCreateArguments(funder, sender, recipient, depositAmount, startTime, stopTime);
checkCreateArguments(sender, recipient, depositAmount, startTime, stopTime);

// Checks: requirements of segments variables.
checkSegments(depositAmount, startTime, segmentAmounts, segmentExponents, segmentMilestones, segmentCount);
Expand All @@ -573,12 +563,12 @@ contract SablierV2Pro is
}

// Interactions: perform the ERC-20 transfer.
token.safeTransferFrom(funder, address(this), depositAmount);
token.safeTransferFrom(msg.sender, address(this), depositAmount);

// Emit an event.
emit CreateStream(
streamId,
funder,
msg.sender,
sender,
recipient,
depositAmount,
Expand Down
19 changes: 6 additions & 13 deletions src/interfaces/ISablierV2Cliff.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ interface ISablierV2Cliff is ISablierV2 {

/// NON-CONSTANT FUNCTIONS ///

/// @notice Creates a new stream funded by `funder`.
/// @notice Creates a new stream funded by `msg.sender`.
///
/// @dev Emits a {CreateStream} event. If `funder` is not the same as `msg.sender`, it also emits an
/// {Authorize} event.
/// @dev Emits a {CreateStream} event.
///
/// Requirements:
/// - `sender` must not be the zero address.
Expand All @@ -88,13 +87,10 @@ interface ISablierV2Cliff is ISablierV2 {
/// - `startTime` must not be greater than `stopTime`.
/// - `startTime` must not be greater than cliffTime`.
/// - `cliffTime` must not be greater than `stopTime`.
/// - `funder` must have allowed this contract to spend `depositAmount` tokens.
/// - If `funder` is not the same as `msg.sender`, `funder` must have allowed `msg.sender` to create a
/// stream worth `depositAmount` tokens.
/// - `msg.sender` must have allowed this contract to spend `depositAmount` tokens.
///
/// @param funder The address which funds the stream.
/// @param sender The address from which to stream the tokens with a cliff period, which will have the ability to
/// cancel the stream. It doesn't have to be the same as `funder`.
/// cancel the stream. It doesn't have to be the same as `msg.sender`.
/// @param recipient The address toward which to stream the tokens.
/// @param depositAmount The amount of tokens to be streamed.
/// @param token The address of the ERC-20 token to use for streaming.
Expand All @@ -104,7 +100,6 @@ interface ISablierV2Cliff is ISablierV2 {
/// @param cancelable Whether the stream will be cancelable or not.
/// @return streamId The id of the newly created stream.
function create(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand All @@ -115,17 +110,16 @@ interface ISablierV2Cliff is ISablierV2 {
bool cancelable
) external returns (uint256 streamId);

/// @notice Creates a stream funded by `funder` and sets the start time to `block.timestamp` and the stop
/// @notice Creates a stream funded by `msg.sender` and sets the start time to `block.timestamp` and the stop
/// time to `block.timestamp + duration`.
///
/// @dev Emits a {CreateStream} event and an {Authorize} event.
///
/// Requirements:
/// - All from `create`.
///
/// @param funder The address which funds the stream.
/// @param sender The address from which to stream the tokens with a cliff period, which will have the ability to
/// cancel the stream. It doesn't have to be the same as `funder`.
/// cancel the stream. It doesn't have to be the same as `msg.sender`.
/// @param recipient The address toward which to stream the tokens.
/// @param depositAmount The amount of tokens to be streamed.
/// @param token The address of the ERC-20 token to use for streaming.
Expand All @@ -134,7 +128,6 @@ interface ISablierV2Cliff is ISablierV2 {
/// @param cancelable Whether the stream will be cancelable or not.
/// @return streamId The id of the newly created stream.
function createWithDuration(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand Down
22 changes: 7 additions & 15 deletions src/interfaces/ISablierV2Linear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,19 @@ interface ISablierV2Linear is ISablierV2 {

/// NON-CONSTANT FUNCTIONS ///

/// @notice Creates a new stream funded by `funder`.
/// @notice Creates a new stream funded by `msg.sender`.
///
/// @dev Emits a {CreateStream} event. If `funder` is not the same as `msg.sender`, it also emits an
/// {Authorize} event.
/// @dev Emits a {CreateStream} event.
///
/// Requirements:
/// - `sender` must not be the zero address.
/// - `recipient` must not be the zero address.
/// - `depositAmount` must not be zero.
/// - `startTime` must not be greater than `stopTime`.
/// - `funder` must have allowed this contract to spend `depositAmount` tokens.
/// - If `funder` is not the same as `msg.sender`, `funder` must have allowed `msg.sender` to create a
/// stream worth `depositAmount` tokens.
/// - `msg.sender` must have allowed this contract to spend `depositAmount` tokens.
///
/// @param funder The address which funds the stream.
/// @param sender The address from which to stream the tokens, which will have the ability to cancel the stream.
/// It doesn't have to be the same as `funder`.
/// It doesn't have to be the same as `msg.sender`.
/// @param recipient The address toward which to stream the tokens.
/// @param depositAmount The amount of tokens to be streamed.
/// @param token The address of the ERC-20 token to use for streaming.
Expand All @@ -81,7 +77,6 @@ interface ISablierV2Linear is ISablierV2 {
/// @param cancelable Whether the stream is cancelable or not.
/// @return streamId The id of the newly created stream.
function create(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand All @@ -91,26 +86,23 @@ interface ISablierV2Linear is ISablierV2 {
bool cancelable
) external returns (uint256 streamId);

/// @notice Creates a stream funded by `funder` and sets the start time to `block.timestamp` and the stop
/// @notice Creates a stream funded by `msg.sender` and sets the start time to `block.timestamp` and the stop
/// time to `block.timestamp + duration`.
///
/// @dev Emits a {CreateStream} event. If `funder` is not the same as `msg.sender`, it also emits an
/// {Authorize} event.
/// @dev Emits a {CreateStream} event.
///
/// Requirements:
/// - All from `create`.
///
/// @param funder The address which funds the stream.
/// @param sender The address from which to stream the tokens, which will have the ability to cancel the stream.
/// It doesn't have to be the same as `funder`.
/// It doesn't have to be the same as `msg.sender`.
/// @param recipient The address toward which to stream the tokens.
/// @param depositAmount The amount of tokens to be streamed.
/// @param token The address of the ERC-20 token to use for streaming.
/// @param duration The number of seconds for how long the stream will last.
/// @param cancelable Whether the stream is cancelable or not.
/// @return streamId The id of the newly created stream.
function createWithDuration(
address funder,
address sender,
address recipient,
uint256 depositAmount,
Expand Down
Loading

0 comments on commit 9e4a546

Please sign in to comment.