Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement cancelInvoice integration tests [extended] #9

Merged
merged 7 commits into from
Jul 22, 2024
17 changes: 13 additions & 4 deletions src/modules/invoice-module/sablier-v2/StreamManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Types } from "./../libraries/Types.sol";

/// @title StreamManager
/// @dev See the documentation in {IStreamManager}
contract StreamManager is IStreamManager {
abstract contract StreamManager is IStreamManager {
using SafeERC20 for IERC20;

/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -40,6 +40,8 @@ contract StreamManager is IStreamManager {
//////////////////////////////////////////////////////////////////////////*/

/// @dev Stores the initial address of the account that started the stream
/// By default, each stream will be created by this contract (the sender address of each stream will be address(this))
/// therefore this mapping is used to allow only authorized senders to execute management-related actions i.e. cancellations
mapping(uint256 streamId => address initialSender) private _initialStreamSender;

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -93,7 +95,7 @@ contract StreamManager is IStreamManager {
// Create the Lockup Linear stream
streamId = _createLinearStream(asset, totalAmount, startTime, endTime, recipient);

// Set `msg.sender` as the initial stream sender to allow secure stream management
// Set `msg.sender` as the initial stream sender to allow authenticated stream management
_initialStreamSender[streamId] = msg.sender;
}

Expand All @@ -112,7 +114,7 @@ contract StreamManager is IStreamManager {
// Create the Lockup Linear stream
streamId = _createTranchedStream(asset, totalAmount, startTime, recipient, numberOfTranches, recurrence);

// Set `msg.sender` as the initial stream sender to allow secure stream management
// Set `msg.sender` as the initial stream sender to allow authenticated stream management
_initialStreamSender[streamId] = msg.sender;
}

Expand Down Expand Up @@ -145,11 +147,13 @@ contract StreamManager is IStreamManager {

/// @inheritdoc IStreamManager
function cancelLinearStream(uint256 streamId) public {
// Checks, Effect, Interactions
_cancelStream({ sablier: LOCKUP_LINEAR, streamId: streamId });
}

/// @inheritdoc IStreamManager
function cancelTranchedStream(uint256 streamId) public {
// Checks, Effect, Interactions
_cancelStream({ sablier: LOCKUP_TRANCHED, streamId: streamId });
}

Expand Down Expand Up @@ -257,7 +261,12 @@ contract StreamManager is IStreamManager {
}

/// @dev Cancels the `streamId` stream
function _cancelStream(ISablierV2Lockup sablier, uint256 streamId) internal onlyInitialStreamSender(streamId) {
function _cancelStream(ISablierV2Lockup sablier, uint256 streamId) internal {
// Checks: the `msg.sender` is the initial stream creator
address initialSender = _initialStreamSender[streamId];
if (msg.sender != initialSender) revert Errors.OnlyInitialStreamSender(initialSender);

// Cancel the stream
sablier.cancel(streamId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ interface IStreamManager {
function withdrawTranchedStream(uint256 streamId, address to, uint128 amount) external;

/// @notice See the documentation in {ISablierV2Lockup-cancel}
///
/// Notes:
/// - Reverts with {OnlyInitialStreamSender} if `msg.sender` is not the initial stream creator
function cancelLinearStream(uint256 streamId) external;

/// @notice See the documentation in {ISablierV2Lockup-cancel}
///
/// Notes:
/// - Reverts with {OnlyInitialStreamSender} if `msg.sender` is not the initial stream creator
function cancelTranchedStream(uint256 streamId) external;
}