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

feat: emit BatchMetadataUpdate in setProtocolFee #306

Merged
merged 2 commits into from
Oct 15, 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
2 changes: 1 addition & 1 deletion src/SablierFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract SablierFlow is
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/

/// @dev Emits a {TransferAdmin} event.
/// @dev Emits {TransferAdmin} event.
/// @param initialAdmin The address of the initial contract admin.
/// @param initialNFTDescriptor The address of the initial NFT descriptor.
constructor(
Expand Down
5 changes: 4 additions & 1 deletion src/abstracts/SablierFlowBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract contract SablierFlowBase is
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/

/// @dev Emits a {TransferAdmin} event.
/// @dev Emits {TransferAdmin} event.
/// @param initialAdmin The address of the initial contract admin.
/// @param initialNFTDescriptor The address of the initial NFT descriptor.
constructor(address initialAdmin, IFlowNFTDescriptor initialNFTDescriptor) {
Expand Down Expand Up @@ -277,6 +277,9 @@ abstract contract SablierFlowBase is
oldProtocolFee: oldProtocolFee,
newProtocolFee: newProtocolFee
});

// Refresh the NFT metadata for all streams.
emit BatchMetadataUpdate({ _fromTokenId: 1, _toTokenId: nextStreamId - 1 });
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down
28 changes: 14 additions & 14 deletions src/interfaces/ISablierFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ interface ISablierFlow is

/// @notice Changes the stream's rate per second.
///
/// @dev Emits an {AdjustFlowStream} and {MetadataUpdate} event.
/// @dev Emits {AdjustFlowStream} and {MetadataUpdate} events.
///
/// Notes:
/// - Performs a debt snapshot.
Expand All @@ -178,7 +178,7 @@ interface ISablierFlow is
/// @notice Creates a new Flow stream by setting the snapshot time to `block.timestamp` and leaving the balance to
/// zero. The stream is wrapped in an ERC-721 NFT.
///
/// @dev Emits a {CreateFlowStream} event.
/// @dev Emits {CreateFlowStream} event.
///
/// Requirements:
/// - Must not be delegate called.
Expand Down Expand Up @@ -208,7 +208,7 @@ interface ISablierFlow is
/// @notice Creates a new Flow stream by setting the snapshot time to `block.timestamp` and the balance to `amount`.
/// The stream is wrapped in an ERC-721 NFT.
///
/// @dev Emits a {Transfer}, {CreateFlowStream}, and {DepositFlowStream} event.
/// @dev Emits {Transfer}, {CreateFlowStream}, and {DepositFlowStream} events.
///
/// Notes:
/// - Refer to the notes in {deposit}.
Expand Down Expand Up @@ -238,7 +238,7 @@ interface ISablierFlow is

/// @notice Makes a deposit in a stream.
///
/// @dev Emits a {Transfer} and {DepositFlowStream} event.
/// @dev Emits {Transfer} and {DepositFlowStream} events.
///
/// Requirements:
/// - Must not be delegate called.
Expand All @@ -251,7 +251,7 @@ interface ISablierFlow is

/// @notice Deposits tokens in a stream and pauses it.
///
/// @dev Emits a {Transfer}, {DepositFlowStream} and {PauseFlowStream} event.
/// @dev Emits {Transfer}, {DepositFlowStream} and {PauseFlowStream} events.
///
/// Notes:
/// - Refer to the notes in {deposit} and {pause}.
Expand All @@ -265,7 +265,7 @@ interface ISablierFlow is

/// @notice Deposits tokens in a stream.
///
/// @dev Emits a {Transfer} and {DepositFlowStream} event.
/// @dev Emits {Transfer} and {DepositFlowStream} events.
///
/// Notes:
/// - Refer to the notes in {deposit}.
Expand All @@ -285,7 +285,7 @@ interface ISablierFlow is

/// @notice Pauses the stream.
///
/// @dev Emits a {PauseFlowStream} event.
/// @dev Emits {PauseFlowStream} event.
///
/// Notes:
/// - It does not set the snapshot time to the current block timestamp.
Expand All @@ -302,7 +302,7 @@ interface ISablierFlow is

/// @notice Refunds the provided amount of tokens from the stream to the sender's address.
///
/// @dev Emits a {Transfer} and {RefundFromFlowStream} event.
/// @dev Emits {Transfer} and {RefundFromFlowStream} events.
///
/// Requirements:
/// - Must not be delegate called.
Expand All @@ -316,7 +316,7 @@ interface ISablierFlow is

/// @notice Refunds the provided amount of tokens from the stream to the sender's address.
///
/// @dev Emits a {Transfer}, {RefundFromFlowStream} and {PauseFlowStream} event.
/// @dev Emits {Transfer}, {RefundFromFlowStream} and {PauseFlowStream} events.
///
/// Notes:
/// - Refer to the notes in {pause}.
Expand All @@ -330,7 +330,7 @@ interface ISablierFlow is

/// @notice Restarts the stream with the provided rate per second.
///
/// @dev Emits a {RestartFlowStream} event.
/// @dev Emits {RestartFlowStream} event.
/// - This function updates stream's `snapshotTime` to the current block timestamp.
///
/// Notes:
Expand All @@ -349,7 +349,7 @@ interface ISablierFlow is

/// @notice Restarts the stream with the provided rate per second, and makes a deposit.
///
/// @dev Emits a {RestartFlowStream}, {Transfer}, and {DepositFlowStream} event.
/// @dev Emits {RestartFlowStream}, {Transfer}, and {DepositFlowStream} events.
///
/// Notes:
/// - Refer to the notes in {restart} and {deposit}.
Expand All @@ -366,7 +366,7 @@ interface ISablierFlow is

/// @notice Voids a stream.
///
/// @dev Emits a {VoidFlowStream} event.
/// @dev Emits {VoidFlowStream} event.
///
/// Notes:
/// - It sets snapshot time to the `block.timestamp`
Expand All @@ -386,7 +386,7 @@ interface ISablierFlow is

/// @notice Withdraws the provided amount of tokens from the stream to the `to` address.
///
/// @dev Emits a {Transfer} and {WithdrawFromFlowStream} event.
/// @dev Emits {Transfer} and {WithdrawFromFlowStream} events.
///
/// Notes:
/// - It sets the snapshot time to the `block.timestamp` if `amount` is greater than snapshot debt.
Expand All @@ -406,7 +406,7 @@ interface ISablierFlow is

/// @notice Withdraws the entire withdrawable amount from the stream to the provided address `to`.
///
/// @dev Emits a {Transfer} and {WithdrawFromFlowStream} event.
/// @dev Emits {Transfer} and {WithdrawFromFlowStream} events.
///
/// Notes:
/// - Refer to the notes in {withdraw}.
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/ISablierFlowBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ interface ISablierFlowBase is

/// @notice Collect the protocol revenue accrued for the provided ERC-20 token.
///
/// @dev Emits a {CollectProtocolRevenue} event.
/// @dev Emits {CollectProtocolRevenue} event.
///
/// Requirements:
/// - `msg.sender` must be the contract admin.
Expand All @@ -160,7 +160,7 @@ interface ISablierFlowBase is

/// @notice Recover the surplus amount of tokens.
///
/// @dev Emits a {Recover} event.
/// @dev Emits {Recover} event.
///
/// Notes:
/// - The surplus amount is defined as the difference between the total balance of the contract for the provided
Expand All @@ -176,7 +176,7 @@ interface ISablierFlowBase is

/// @notice Sets a new NFT descriptor contract, which produces the URI describing the Sablier stream NFTs.
///
/// @dev Emits a {SetNFTDescriptor} and {BatchMetadataUpdate} event.
/// @dev Emits {SetNFTDescriptor} and {BatchMetadataUpdate} events.
///
/// Notes:
/// - Does not revert if the NFT descriptor is the same.
Expand All @@ -190,7 +190,7 @@ interface ISablierFlowBase is
/// @notice Sets a new protocol fee that will be charged on all the withdrawals from streams created with the
/// provided ERC-20 token.
///
/// @dev Emits a {SetProtocolFee} event.
/// @dev Emits {SetProtocolFee} and {BatchMetadataUpdate} events.
///
/// Notes:
/// - Does not revert if the fee is the same.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22;

import { IERC4906 } from "@openzeppelin/contracts/interfaces/IERC4906.sol";
import { UD60x18, UNIT } from "@prb/math/src/UD60x18.sol";

import { ISablierFlowBase } from "src/interfaces/ISablierFlowBase.sol";
Expand Down Expand Up @@ -28,9 +29,11 @@ contract SetProtocolFee_Integration_Concrete_Test is Integration_Test {
}

function test_WhenNewAndOldProtocolFeeAreSame() external whenCallerAdmin whenNewProtocolFeeNotExceedMaxFee {
// It should emit {SetProtocolFee} event.
// It should emit {SetProtocolFee} and {BatchMetadataUpdate} events.
vm.expectEmit({ emitter: address(flow) });
emit ISablierFlowBase.SetProtocolFee(users.admin, tokenWithProtocolFee, PROTOCOL_FEE, PROTOCOL_FEE);
vm.expectEmit({ emitter: address(flow) });
emit IERC4906.BatchMetadataUpdate({ _fromTokenId: 1, _toTokenId: flow.nextStreamId() - 1 });

flow.setProtocolFee(tokenWithProtocolFee, PROTOCOL_FEE);

Expand All @@ -41,9 +44,11 @@ contract SetProtocolFee_Integration_Concrete_Test is Integration_Test {
function test_WhenNewAndOldProtocolFeeAreNotSame() external whenCallerAdmin whenNewProtocolFeeNotExceedMaxFee {
UD60x18 newProtocolFee = PROTOCOL_FEE + UD60x18.wrap(0.01e18);

// It should emit {SetProtocolFee} event.
// It should emit {SetProtocolFee} and {BatchMetadataUpdate} events.
vm.expectEmit({ emitter: address(flow) });
emit ISablierFlowBase.SetProtocolFee(users.admin, tokenWithProtocolFee, PROTOCOL_FEE, newProtocolFee);
vm.expectEmit({ emitter: address(flow) });
emit IERC4906.BatchMetadataUpdate({ _fromTokenId: 1, _toTokenId: flow.nextStreamId() - 1 });

flow.setProtocolFee(tokenWithProtocolFee, newProtocolFee);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SetProtocolFee_Integration_Concrete_Test
└── when new protocol fee not exceed max fee
├── when new and old protocol fee are same
│ ├── it should re-set the protocol fee
│ └── it should emit {SetProtocolFee} event
│ └── it should emit {SetProtocolFee} and {BatchMetadataUpdate} events
└── when new and old protocol fee are not same
├── it should set the new protocol fee
└── it should emit {SetProtocolFee} event
└── it should emit {SetProtocolFee} and {BatchMetadataUpdate} events
Loading