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

Revert "Implement cancelInvoice integration tests" #8

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/modules/invoice-module/InvoiceModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,33 +213,27 @@ contract InvoiceModule is IInvoiceModule, StreamManager {
if (invoice.status == Types.Status.Paid) {
revert Errors.CannotCancelPaidInvoice();
} else if (invoice.status == Types.Status.Canceled) {
revert Errors.InvoiceAlreadyCanceled();
revert Errors.CannotCancelCanceledInvoice();
}

// Checks: the `msg.sender` is the creator if dealing with a transfer-based invoice
// or a linear/tranched stream-based invoice which was not paid yet (not streaming)
//
// Notes:
// - Once a linear or tranched stream is created, the `msg.sender` is checked in the
// - for a linear or tranched stream-based invoice, the `msg.sender` is checked in the
// {SablierV2Lockup} `cancel` method
if (invoice.payment.method == Types.Method.Transfer || invoice.status == Types.Status.Pending) {
if (invoice.payment.method == Types.Method.Transfer) {
if (invoice.recipient != msg.sender) {
revert Errors.InvoiceOwnerUnauthorized();
}
}

// Effects: cancel the stream accordingly depending on its type
//
// Notes:
// - A transfer-based invoice can be canceled directly
// - A linear or tranched stream MUST be canceled by calling the `cancel` method on the according
// {ISablierV2Lockup} contract
else if (invoice.status == Types.Status.Ongoing) {
if (invoice.payment.method == Types.Method.LinearStream) {
cancelLinearStream({ streamId: invoice.payment.streamId });
} else if (invoice.payment.method == Types.Method.TranchedStream) {
cancelTranchedStream({ streamId: invoice.payment.streamId });
}
if (invoice.payment.method == Types.Method.LinearStream) {
cancelLinearStream({ streamId: invoice.payment.streamId });
} else if (invoice.payment.method == Types.Method.TranchedStream) {
cancelTranchedStream({ streamId: invoice.payment.streamId });
}

// Effects: mark the invoice as canceled
_invoices[id].status = Types.Status.Canceled;

Expand Down
3 changes: 0 additions & 3 deletions src/modules/invoice-module/interfaces/IInvoiceModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ interface IInvoiceModule {
/// @notice Cancels the `id` invoice
///
/// Notes:
/// - A transfer-based invoice can be canceled only by its creator (recipient)
/// - A linear/tranched stream-based invoice can be canceled by its creator only if its
/// status is `Pending`; otherwise only the stream sender can cancel it
/// - if the invoice has a linear or tranched stream payment method, the streaming flow will be
/// stopped and the remaining funds will be refunded to the stream payer
///
Expand Down
5 changes: 1 addition & 4 deletions src/modules/invoice-module/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ library Errors {
error CannotCancelPaidInvoice();

/// @notice Thrown when an attempt is made to cancel an already canceled invoice
error InvoiceAlreadyCanceled();

/// @notice Thrown when the caller is not the initial stream sender
error OnlyInitialStreamSender(address initialSender);
error CannotCancelCanceledInvoice();

/*//////////////////////////////////////////////////////////////////////////
STREAM-MANAGER
Expand Down
33 changes: 4 additions & 29 deletions src/modules/invoice-module/sablier-v2/StreamManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ contract StreamManager is IStreamManager {
/// @inheritdoc IStreamManager
UD60x18 public override brokerFee;

/*//////////////////////////////////////////////////////////////////////////
PRIVATE STORAGE
//////////////////////////////////////////////////////////////////////////*/

/// @dev Stores the initial address of the account that started the stream
mapping(uint256 streamId => address initialSender) private _initialStreamSender;

/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -68,13 +61,6 @@ contract StreamManager is IStreamManager {
_;
}

/// @notice Reverts if the `msg.sender` is not the initial stream sender (creator of the stream)
modifier onlyInitialStreamSender(uint256 streamId) {
address initialSender = _initialStreamSender[streamId];
if (msg.sender != initialSender) revert Errors.OnlyInitialStreamSender(initialSender);
_;
}

/*//////////////////////////////////////////////////////////////////////////
NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -92,9 +78,6 @@ 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
_initialStreamSender[streamId] = msg.sender;
}

/// @inheritdoc IStreamManager
Expand All @@ -111,9 +94,6 @@ 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
_initialStreamSender[streamId] = msg.sender;
}

/// @inheritdoc IStreamManager
Expand Down Expand Up @@ -185,7 +165,7 @@ contract StreamManager is IStreamManager {
LockupLinear.CreateWithTimestamps memory params;

// Declare the function parameters
params.sender = address(this); // The sender will be able to cancel the stream
params.sender = msg.sender; // The sender will be able to cancel the stream
params.recipient = recipient; // The recipient of the streamed assets
params.totalAmount = totalAmount; // Total amount is the amount inclusive of all fees
params.asset = asset; // The streaming asset
Expand Down Expand Up @@ -213,7 +193,7 @@ contract StreamManager is IStreamManager {
LockupTranched.CreateWithTimestamps memory params;

// Declare the function parameters
params.sender = address(this); // The sender will be able to cancel the stream
params.sender = msg.sender; // The sender will be able to cancel the stream
params.recipient = recipient; // The recipient of the streamed assets
params.totalAmount = totalAmount; // Total amount is the amount inclusive of all fees
params.asset = asset; // The streaming asset
Expand Down Expand Up @@ -247,17 +227,12 @@ contract StreamManager is IStreamManager {
}

/// @dev Withdraws from either a linear or tranched stream
function _withdrawStream(
ISablierV2Lockup sablier,
uint256 streamId,
address to,
uint128 amount
) internal onlyInitialStreamSender(streamId) {
function _withdrawStream(ISablierV2Lockup sablier, uint256 streamId, address to, uint128 amount) internal {
sablier.withdraw(streamId, to, amount);
}

/// @dev Cancels the `streamId` stream
function _cancelStream(ISablierV2Lockup sablier, uint256 streamId) internal onlyInitialStreamSender(streamId) {
function _cancelStream(ISablierV2Lockup sablier, uint256 streamId) internal {
sablier.cancel(streamId);
}

Expand Down
Loading