Skip to content

Commit

Permalink
refactor: prefix errors name used in Helpers with SablierHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
smol-ninja committed Nov 10, 2024
1 parent b4d9ea6 commit 151dbdd
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 81 deletions.
128 changes: 66 additions & 62 deletions src/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,72 @@ library Errors {
/// @notice Thrown when trying to generate the token URI for an unknown ERC-721 NFT contract.
error LockupNFTDescriptor_UnknownNFT(IERC721Metadata nft, string symbol);

/*//////////////////////////////////////////////////////////////////////////
HELPERS
//////////////////////////////////////////////////////////////////////////*/

/// @notice Thrown when the broker fee exceeds the maximum allowed fee.
error SablierHelpers_BrokerFeeTooHigh(UD60x18 brokerFee, UD60x18 maxBrokerFee);

/// @notice Thrown when trying to create a linear stream with a cliff time not strictly less than the end time.
error SablierHelpers_CliffTimeNotLessThanEndTime(uint40 cliffTime, uint40 endTime);

/// @notice Thrown when trying to create a dynamic stream with a deposit amount not equal to the sum of the segment
/// amounts.
error SablierHelpers_DepositAmountNotEqualToSegmentAmountsSum(uint128 depositAmount, uint128 segmentAmountsSum);

/// @notice Thrown when trying to create a tranched stream with a deposit amount not equal to the sum of the tranche
/// amounts.
error SablierHelpers_DepositAmountNotEqualToTrancheAmountsSum(uint128 depositAmount, uint128 trancheAmountsSum);

/// @notice Thrown when trying to create a stream with a zero deposit amount.
error SablierHelpers_DepositAmountZero();

/// @notice Thrown when trying to create a dynamic stream with end time not equal to the last segment's timestamp.
error SablierHelpers_EndTimeNotEqualToLastSegmentTimestamp(uint40 endTime, uint40 lastSegmentTimestamp);

/// @notice Thrown when trying to create a tranched stream with end time not equal to the last tranche's timestamp.
error SablierHelpers_EndTimeNotEqualToLastTrancheTimestamp(uint40 endTime, uint40 lastTrancheTimestamp);

/// @notice Thrown when trying to create a dynamic stream with more segments than the maximum allowed.
error SablierHelpers_SegmentCountTooHigh(uint256 count);

/// @notice Thrown when trying to create a dynamic stream with no segments.
error SablierHelpers_SegmentCountZero();

/// @notice Thrown when trying to create a dynamic stream with unordered segment timestamps.
error SablierHelpers_SegmentTimestampsNotOrdered(uint256 index, uint40 previousTimestamp, uint40 currentTimestamp);

/// @notice Thrown when trying to create a stream with the sender as the zero address.
error SablierHelpers_SenderZeroAddress();

/// @notice Thrown when trying to create a linear stream with a start time not strictly less than the cliff time,
/// when the cliff time does not have a zero value.
error SablierHelpers_StartTimeNotLessThanCliffTime(uint40 startTime, uint40 cliffTime);

/// @notice Thrown when trying to create a linear stream with a start time not strictly less than the end time.
error SablierHelpers_StartTimeNotLessThanEndTime(uint40 startTime, uint40 endTime);

/// @notice Thrown when trying to create a dynamic stream with a start time not strictly less than the first
/// segment timestamp.
error SablierHelpers_StartTimeNotLessThanFirstSegmentTimestamp(uint40 startTime, uint40 firstSegmentTimestamp);

/// @notice Thrown when trying to create a tranched stream with a start time not strictly less than the first
/// tranche timestamp.
error SablierHelpers_StartTimeNotLessThanFirstTrancheTimestamp(uint40 startTime, uint40 firstTrancheTimestamp);

/// @notice Thrown when trying to create a stream with a zero start time.
error SablierHelpers_StartTimeZero();

/// @notice Thrown when trying to create a tranched stream with more tranches than the maximum allowed.
error SablierHelpers_TrancheCountTooHigh(uint256 count);

/// @notice Thrown when trying to create a tranched stream with no tranches.
error SablierHelpers_TrancheCountZero();

/// @notice Thrown when trying to create a tranched stream with unordered tranche timestamps.
error SablierHelpers_TrancheTimestampsNotOrdered(uint256 index, uint40 previousTimestamp, uint40 currentTimestamp);

/*//////////////////////////////////////////////////////////////////////////
SABLIER-LOCKUP-BASE
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -86,68 +152,6 @@ library Errors {
SABLIER-LOCKUP
//////////////////////////////////////////////////////////////////////////*/

/// @notice Thrown when the broker fee exceeds the maximum allowed fee.
error SablierLockup_BrokerFeeTooHigh(UD60x18 brokerFee, UD60x18 maxBrokerFee);

/// @notice Thrown when trying to create a linear stream with a cliff time not strictly less than the end time.
error SablierLockup_CliffTimeNotLessThanEndTime(uint40 cliffTime, uint40 endTime);

/// @notice Thrown when trying to create a dynamic stream with a deposit amount not equal to the sum of the segment
/// amounts.
error SablierLockup_DepositAmountNotEqualToSegmentAmountsSum(uint128 depositAmount, uint128 segmentAmountsSum);

/// @notice Thrown when trying to create a tranched stream with a deposit amount not equal to the sum of the tranche
/// amounts.
error SablierLockup_DepositAmountNotEqualToTrancheAmountsSum(uint128 depositAmount, uint128 trancheAmountsSum);

/// @notice Thrown when trying to create a stream with a zero deposit amount.
error SablierLockup_DepositAmountZero();

/// @notice Thrown when trying to create a dynamic stream with end time not equal to the last segment's timestamp.
error SablierLockup_EndTimeNotEqualToLastSegmentTimestamp(uint40 endTime, uint40 lastSegmentTimestamp);

/// @notice Thrown when trying to create a tranched stream with end time not equal to the last tranche's timestamp.
error SablierLockup_EndTimeNotEqualToLastTrancheTimestamp(uint40 endTime, uint40 lastTrancheTimestamp);

/// @notice Thrown when a function is called on a stream that does not use the expected Lockup model.
error SablierLockup_NotExpectedModel(Lockup.Model actualLockupModel, Lockup.Model expectedLockupModel);

/// @notice Thrown when trying to create a dynamic stream with more segments than the maximum allowed.
error SablierLockup_SegmentCountTooHigh(uint256 count);

/// @notice Thrown when trying to create a dynamic stream with no segments.
error SablierLockup_SegmentCountZero();

/// @notice Thrown when trying to create a dynamic stream with unordered segment timestamps.
error SablierLockup_SegmentTimestampsNotOrdered(uint256 index, uint40 previousTimestamp, uint40 currentTimestamp);

/// @notice Thrown when trying to create a stream with the sender as the zero address.
error SablierLockup_SenderZeroAddress();

/// @notice Thrown when trying to create a linear stream with a start time not strictly less than the cliff time,
/// when the cliff time does not have a zero value.
error SablierLockup_StartTimeNotLessThanCliffTime(uint40 startTime, uint40 cliffTime);

/// @notice Thrown when trying to create a linear stream with a start time not strictly less than the end time.
error SablierLockup_StartTimeNotLessThanEndTime(uint40 startTime, uint40 endTime);

/// @notice Thrown when trying to create a dynamic stream with a start time not strictly less than the first
/// segment timestamp.
error SablierLockup_StartTimeNotLessThanFirstSegmentTimestamp(uint40 startTime, uint40 firstSegmentTimestamp);

/// @notice Thrown when trying to create a tranched stream with a start time not strictly less than the first
/// tranche timestamp.
error SablierLockup_StartTimeNotLessThanFirstTrancheTimestamp(uint40 startTime, uint40 firstTrancheTimestamp);

/// @notice Thrown when trying to create a stream with a zero start time.
error SablierLockup_StartTimeZero();

/// @notice Thrown when trying to create a tranched stream with more tranches than the maximum allowed.
error SablierLockup_TrancheCountTooHigh(uint256 count);

/// @notice Thrown when trying to create a tranched stream with no tranches.
error SablierLockup_TrancheCountZero();

/// @notice Thrown when trying to create a tranched stream with unordered tranche timestamps.
error SablierLockup_TrancheTimestampsNotOrdered(uint256 index, uint40 previousTimestamp, uint40 currentTimestamp);
}
38 changes: 19 additions & 19 deletions src/core/libraries/Helpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ library Helpers {

// Check: the broker fee is not greater than `maxBrokerFee`.
if (brokerFee.gt(maxBrokerFee)) {
revert Errors.SablierLockup_BrokerFeeTooHigh(brokerFee, maxBrokerFee);
revert Errors.SablierHelpers_BrokerFeeTooHigh(brokerFee, maxBrokerFee);
}

// Calculate the broker fee amount.
Expand All @@ -193,36 +193,36 @@ library Helpers {
if (cliffTime > 0) {
// Check: the start time is strictly less than the cliff time.
if (timestamps.start >= cliffTime) {
revert Errors.SablierLockup_StartTimeNotLessThanCliffTime(timestamps.start, cliffTime);
revert Errors.SablierHelpers_StartTimeNotLessThanCliffTime(timestamps.start, cliffTime);
}

// Check: the cliff time is strictly less than the end time.
if (cliffTime >= timestamps.end) {
revert Errors.SablierLockup_CliffTimeNotLessThanEndTime(cliffTime, timestamps.end);
revert Errors.SablierHelpers_CliffTimeNotLessThanEndTime(cliffTime, timestamps.end);
}
}

// Check: the start time is strictly less than the end time.
if (timestamps.start >= timestamps.end) {
revert Errors.SablierLockup_StartTimeNotLessThanEndTime(timestamps.start, timestamps.end);
revert Errors.SablierHelpers_StartTimeNotLessThanEndTime(timestamps.start, timestamps.end);
}
}

/// @dev Checks the user-provided common parameters across lockup streams.
function _checkCreateStream(address sender, uint128 depositAmount, uint40 startTime) private pure {
// Check: the sender is not the zero address.
if (sender == address(0)) {
revert Errors.SablierLockup_SenderZeroAddress();
revert Errors.SablierHelpers_SenderZeroAddress();
}

// Check: the deposit amount is not zero.
if (depositAmount == 0) {
revert Errors.SablierLockup_DepositAmountZero();
revert Errors.SablierHelpers_DepositAmountZero();
}

// Check: the start time is not zero.
if (startTime == 0) {
revert Errors.SablierLockup_StartTimeZero();
revert Errors.SablierHelpers_StartTimeZero();
}
}

Expand All @@ -245,24 +245,24 @@ library Helpers {
// Check: the segment count is not zero.
uint256 segmentCount = segments.length;
if (segmentCount == 0) {
revert Errors.SablierLockup_SegmentCountZero();
revert Errors.SablierHelpers_SegmentCountZero();
}

// Check: the segment count is not greater than the maximum allowed.
if (segmentCount > maxSegmentCount) {
revert Errors.SablierLockup_SegmentCountTooHigh(segmentCount);
revert Errors.SablierHelpers_SegmentCountTooHigh(segmentCount);
}

// Check: the start time is strictly less than the first segment timestamp.
if (timestamps.start >= segments[0].timestamp) {
revert Errors.SablierLockup_StartTimeNotLessThanFirstSegmentTimestamp(
revert Errors.SablierHelpers_StartTimeNotLessThanFirstSegmentTimestamp(
timestamps.start, segments[0].timestamp
);
}

// Check: the end time equals the last segment's timestamp.
if (timestamps.end != segments[segmentCount - 1].timestamp) {
revert Errors.SablierLockup_EndTimeNotEqualToLastSegmentTimestamp(
revert Errors.SablierHelpers_EndTimeNotEqualToLastSegmentTimestamp(
timestamps.end, segments[segmentCount - 1].timestamp
);
}
Expand All @@ -283,7 +283,7 @@ library Helpers {
// Check: the current timestamp is strictly greater than the previous timestamp.
currentSegmentTimestamp = segments[index].timestamp;
if (currentSegmentTimestamp <= previousSegmentTimestamp) {
revert Errors.SablierLockup_SegmentTimestampsNotOrdered(
revert Errors.SablierHelpers_SegmentTimestampsNotOrdered(
index, previousSegmentTimestamp, currentSegmentTimestamp
);
}
Expand All @@ -294,7 +294,7 @@ library Helpers {

// Check: the deposit amount is equal to the segment amounts sum.
if (depositAmount != segmentAmountsSum) {
revert Errors.SablierLockup_DepositAmountNotEqualToSegmentAmountsSum(depositAmount, segmentAmountsSum);
revert Errors.SablierHelpers_DepositAmountNotEqualToSegmentAmountsSum(depositAmount, segmentAmountsSum);
}
}

Expand All @@ -317,24 +317,24 @@ library Helpers {
// Check: the tranche count is not zero.
uint256 trancheCount = tranches.length;
if (trancheCount == 0) {
revert Errors.SablierLockup_TrancheCountZero();
revert Errors.SablierHelpers_TrancheCountZero();
}

// Check: the tranche count is not greater than the maximum allowed.
if (trancheCount > maxTrancheCount) {
revert Errors.SablierLockup_TrancheCountTooHigh(trancheCount);
revert Errors.SablierHelpers_TrancheCountTooHigh(trancheCount);
}

// Check: the start time is strictly less than the first tranche timestamp.
if (timestamps.start >= tranches[0].timestamp) {
revert Errors.SablierLockup_StartTimeNotLessThanFirstTrancheTimestamp(
revert Errors.SablierHelpers_StartTimeNotLessThanFirstTrancheTimestamp(
timestamps.start, tranches[0].timestamp
);
}

// Check: the end time equals the tranche's timestamp.
if (timestamps.end != tranches[trancheCount - 1].timestamp) {
revert Errors.SablierLockup_EndTimeNotEqualToLastTrancheTimestamp(
revert Errors.SablierHelpers_EndTimeNotEqualToLastTrancheTimestamp(
timestamps.end, tranches[trancheCount - 1].timestamp
);
}
Expand All @@ -355,7 +355,7 @@ library Helpers {
// Check: the current timestamp is strictly greater than the previous timestamp.
currentTrancheTimestamp = tranches[index].timestamp;
if (currentTrancheTimestamp <= previousTrancheTimestamp) {
revert Errors.SablierLockup_TrancheTimestampsNotOrdered(
revert Errors.SablierHelpers_TrancheTimestampsNotOrdered(
index, previousTrancheTimestamp, currentTrancheTimestamp
);
}
Expand All @@ -366,7 +366,7 @@ library Helpers {

// Check: the deposit amount is equal to the tranche amounts sum.
if (depositAmount != trancheAmountsSum) {
revert Errors.SablierLockup_DepositAmountNotEqualToTrancheAmountsSum(depositAmount, trancheAmountsSum);
revert Errors.SablierHelpers_DepositAmountNotEqualToTrancheAmountsSum(depositAmount, trancheAmountsSum);
}
}
}

0 comments on commit 151dbdd

Please sign in to comment.