Skip to content

Commit

Permalink
refactor: add STREAM_ prefix
Browse files Browse the repository at this point in the history
docs: update NatSpec
refactor: import from src
  • Loading branch information
PaulRBerg committed Nov 26, 2024
1 parent 2f06f00 commit 718074c
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 103 deletions.
3 changes: 2 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
@prb/math/=node_modules/@prb/math/
@sablier/lockup/=node_modules/@sablier/lockup/src/
@sablier/lockup/=node_modules/@sablier/lockup/
@sablier/lockup-precompiles=node_modules/@sablier/lockup/precompiles/
forge-std/=node_modules/forge-std/
solady/=node_modules/solady/
3 changes: 2 additions & 1 deletion script/CreateMerkleLL.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
pragma solidity >=0.8.22 <0.9.0;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ISablierLockup } from "@sablier/lockup/interfaces/ISablierLockup.sol";
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";

import { ISablierMerkleFactory } from "../src/interfaces/ISablierMerkleFactory.sol";
import { ISablierMerkleLL } from "../src/interfaces/ISablierMerkleLL.sol";
import { MerkleBase, MerkleLL } from "../src/types/DataTypes.sol";
Expand Down
3 changes: 2 additions & 1 deletion script/CreateMerkleLT.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pragma solidity >=0.8.22 <0.9.0;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { UD2x18 } from "@prb/math/src/UD2x18.sol";
import { ISablierLockup } from "@sablier/lockup/interfaces/ISablierLockup.sol";
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";

import { ISablierMerkleFactory } from "../src/interfaces/ISablierMerkleFactory.sol";
import { ISablierMerkleLT } from "../src/interfaces/ISablierMerkleLT.sol";
import { MerkleBase, MerkleLT } from "../src/types/DataTypes.sol";
Expand Down
4 changes: 2 additions & 2 deletions src/SablierMerkleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pragma solidity >=0.8.22;

import { uUNIT } from "@prb/math/src/UD2x18.sol";

import { Adminable } from "@sablier/lockup/abstracts/Adminable.sol";
import { ISablierLockup } from "@sablier/lockup/interfaces/ISablierLockup.sol";
import { Adminable } from "@sablier/lockup/src/abstracts/Adminable.sol";
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";

import { ISablierMerkleBase } from "./interfaces/ISablierMerkleBase.sol";
import { ISablierMerkleFactory } from "./interfaces/ISablierMerkleFactory.sol";
Expand Down
47 changes: 28 additions & 19 deletions src/SablierMerkleLL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity >=0.8.22;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ZERO } from "@prb/math/src/UD60x18.sol";
import { ISablierLockup } from "@sablier/lockup/interfaces/ISablierLockup.sol";
import { Broker, Lockup, LockupLinear } from "@sablier/lockup/types/DataTypes.sol";
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";
import { Broker, Lockup, LockupLinear } from "@sablier/lockup/src/types/DataTypes.sol";

import { SablierMerkleBase } from "./abstracts/SablierMerkleBase.sol";
import { ISablierMerkleLL } from "./interfaces/ISablierMerkleLL.sol";
Expand All @@ -23,17 +23,17 @@ contract SablierMerkleLL is
STATE VARIABLES
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ISablierMerkleLL
bool public immutable override CANCELABLE;

/// @inheritdoc ISablierMerkleLL
ISablierLockup public immutable override LOCKUP;

/// @inheritdoc ISablierMerkleLL
bool public immutable override TRANSFERABLE;
bool public immutable override STREAM_CANCELABLE;

/// @inheritdoc ISablierMerkleLL
MerkleLL.Schedule public override schedule;
bool public immutable override STREAM_TRANSFERABLE;

/// @dev See the documentation in {ISablierMerkleLL.getSchedule}.
MerkleLL.Schedule internal _schedule;

/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
Expand All @@ -46,20 +46,29 @@ contract SablierMerkleLL is
ISablierLockup lockup,
bool cancelable,
bool transferable,
MerkleLL.Schedule memory schedule_,
MerkleLL.Schedule memory schedule,
uint256 fee
)
SablierMerkleBase(baseParams, fee)
{
CANCELABLE = cancelable;
LOCKUP = lockup;
TRANSFERABLE = transferable;
schedule = schedule_;
STREAM_CANCELABLE = cancelable;
STREAM_TRANSFERABLE = transferable;
_schedule = schedule;

// Max approve the Lockup contract to spend funds from the MerkleLL contract.
TOKEN.forceApprove(address(LOCKUP), type(uint256).max);
}

/*//////////////////////////////////////////////////////////////////////////
USER-FACING CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ISablierMerkleLL
function getSchedule() external view override returns (MerkleLL.Schedule memory) {
return _schedule;
}

/*//////////////////////////////////////////////////////////////////////////
USER-FACING NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -68,21 +77,21 @@ contract SablierMerkleLL is
function _claim(uint256 index, address recipient, uint128 amount) internal override {
// Calculate the timestamps for the stream.
Lockup.Timestamps memory timestamps;
if (schedule.startTime == 0) {
if (_schedule.startTime == 0) {
timestamps.start = uint40(block.timestamp);
} else {
timestamps.start = schedule.startTime;
timestamps.start = _schedule.startTime;
}

uint40 cliffTime;

// It is safe to use unchecked arithmetic because the `createWithTimestamps` function in the Lockup contract
// will nonetheless make the relevant checks.
unchecked {
if (schedule.cliffDuration > 0) {
cliffTime = timestamps.start + schedule.cliffDuration;
if (_schedule.cliffDuration > 0) {
cliffTime = timestamps.start + _schedule.cliffDuration;
}
timestamps.end = timestamps.start + schedule.totalDuration;
timestamps.end = timestamps.start + _schedule.totalDuration;
}

// Interaction: create the stream via {SablierLockup}.
Expand All @@ -92,12 +101,12 @@ contract SablierMerkleLL is
recipient: recipient,
totalAmount: amount,
asset: TOKEN,
cancelable: CANCELABLE,
transferable: TRANSFERABLE,
cancelable: STREAM_CANCELABLE,
transferable: STREAM_TRANSFERABLE,
timestamps: timestamps,
broker: Broker({ account: address(0), fee: ZERO })
}),
LockupLinear.UnlockAmounts({ start: schedule.startAmount, cliff: schedule.cliffAmount }),
LockupLinear.UnlockAmounts({ start: _schedule.startAmount, cliff: _schedule.cliffAmount }),
cliffTime
);

Expand Down
20 changes: 10 additions & 10 deletions src/SablierMerkleLT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { uUNIT } from "@prb/math/src/UD2x18.sol";
import { UD60x18, ud60x18, ZERO } from "@prb/math/src/UD60x18.sol";
import { ISablierLockup } from "@sablier/lockup/interfaces/ISablierLockup.sol";
import { Broker, Lockup, LockupTranched } from "@sablier/lockup/types/DataTypes.sol";
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";
import { Broker, Lockup, LockupTranched } from "@sablier/lockup/src/types/DataTypes.sol";

import { SablierMerkleBase } from "./abstracts/SablierMerkleBase.sol";
import { ISablierMerkleLT } from "./interfaces/ISablierMerkleLT.sol";
Expand All @@ -26,19 +26,19 @@ contract SablierMerkleLT is
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ISablierMerkleLT
bool public immutable override CANCELABLE;
ISablierLockup public immutable override LOCKUP;

/// @inheritdoc ISablierMerkleLT
ISablierLockup public immutable override LOCKUP;
bool public immutable override STREAM_CANCELABLE;

/// @inheritdoc ISablierMerkleLT
uint40 public immutable override STREAM_START_TIME;

/// @inheritdoc ISablierMerkleLT
uint64 public immutable override TOTAL_PERCENTAGE;
bool public immutable override STREAM_TRANSFERABLE;

/// @inheritdoc ISablierMerkleLT
bool public immutable override TRANSFERABLE;
uint64 public immutable override TOTAL_PERCENTAGE;

/// @dev The tranches with their respective unlock percentages and durations.
MerkleLT.TrancheWithPercentage[] internal _tranchesWithPercentages;
Expand All @@ -60,10 +60,10 @@ contract SablierMerkleLT is
)
SablierMerkleBase(baseParams, fee)
{
CANCELABLE = cancelable;
STREAM_CANCELABLE = cancelable;
LOCKUP = lockup;
STREAM_START_TIME = streamStartTime;
TRANSFERABLE = transferable;
STREAM_TRANSFERABLE = transferable;

uint256 count = tranchesWithPercentages.length;

Expand Down Expand Up @@ -116,8 +116,8 @@ contract SablierMerkleLT is
recipient: recipient,
totalAmount: amount,
asset: TOKEN,
cancelable: CANCELABLE,
transferable: TRANSFERABLE,
cancelable: STREAM_CANCELABLE,
transferable: STREAM_TRANSFERABLE,
timestamps: Lockup.Timestamps({ start: startTime, end: endTime }),
broker: Broker({ account: address(0), fee: ZERO })
}),
Expand Down
2 changes: 1 addition & 1 deletion src/abstracts/SablierMerkleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { MerkleProof } from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import { BitMaps } from "@openzeppelin/contracts/utils/structs/BitMaps.sol";
import { Adminable } from "@sablier/lockup/abstracts/Adminable.sol";
import { Adminable } from "@sablier/lockup/src/abstracts/Adminable.sol";

import { ISablierMerkleBase } from "./../interfaces/ISablierMerkleBase.sol";
import { Errors } from "./../libraries/Errors.sol";
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/ISablierMerkleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity >=0.8.22;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IAdminable } from "@sablier/lockup/interfaces/IAdminable.sol";
import { IAdminable } from "@sablier/lockup/src/interfaces/IAdminable.sol";

/// @title ISablierMerkleBase
/// @dev This is the base interface for Merkle Lockups and Merkle Instant.
/// @dev Common interface between Merkle Lockups and Merkle Instant.
interface ISablierMerkleBase is IAdminable {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/ISablierMerkleFactory.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22;

import { IAdminable } from "@sablier/lockup/interfaces/IAdminable.sol";
import { ISablierLockup } from "@sablier/lockup/interfaces/ISablierLockup.sol";
import { IAdminable } from "@sablier/lockup/src/interfaces/IAdminable.sol";
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";

import { ISablierMerkleBase } from "../interfaces/ISablierMerkleBase.sol";
import { MerkleBase, MerkleFactory, MerkleLL, MerkleLT } from "../types/DataTypes.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ISablierMerkleInstant.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity >=0.8.22;
import { ISablierMerkleBase } from "./ISablierMerkleBase.sol";

/// @title ISablierMerkleInstant
/// @notice MerkleInstant enables instant airdrop campaigns.
/// @notice MerkleInstant enables airdrop distributions where the tokens are claimed directly to the users' wallets.
interface ISablierMerkleInstant is ISablierMerkleBase {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
Expand Down
19 changes: 8 additions & 11 deletions src/interfaces/ISablierMerkleLL.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22;

import { ISablierLockup } from "@sablier/lockup/interfaces/ISablierLockup.sol";

import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";
import { MerkleLL } from "./../types/DataTypes.sol";
import { ISablierMerkleBase } from "./ISablierMerkleBase.sol";

/// @title ISablierMerkleLL
/// @notice Merkle Lockup campaign that creates Lockup Linear streams.
/// @notice Merkle Lockup enables airdrops with a vesting period powered by the Lockup Linear distribution model.
interface ISablierMerkleLL is ISablierMerkleBase {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
Expand All @@ -21,20 +21,17 @@ interface ISablierMerkleLL is ISablierMerkleBase {

/// @notice A flag indicating whether the streams can be canceled.
/// @dev This is an immutable state variable.
function CANCELABLE() external returns (bool);
function STREAM_CANCELABLE() external returns (bool);

/// @notice The address of the {SablierLockup} contract.
function LOCKUP() external view returns (ISablierLockup);

/// @notice A flag indicating whether the stream NFTs are transferable.
/// @dev This is an immutable state variable.
function TRANSFERABLE() external returns (bool);
function STREAM_TRANSFERABLE() external returns (bool);

/// @notice The start time, start unlock amount, cliff duration, cliff unlock amount and the end duration used to
/// calculate the vesting schedule in `Lockup.CreateWithTimestampsLL`.
/// @notice A tuple containing the start time, start unlock amount, cliff duration, cliff unlock amount, and end
/// duration. These values are used to calculate the vesting schedule in `Lockup.CreateWithTimestampsLL`.
/// @dev A start time value of zero will be considered as `block.timestamp`.
function schedule()
external
view
returns (uint40 startTime, uint128 startAmount, uint40 cliffDuration, uint128 cliffAmount, uint40 endDuration);
function getSchedule() external view returns (MerkleLL.Schedule memory);
}
22 changes: 11 additions & 11 deletions src/interfaces/ISablierMerkleLT.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22;

import { ISablierLockup } from "@sablier/lockup/interfaces/ISablierLockup.sol";
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";

import { MerkleLT } from "./../types/DataTypes.sol";
import { ISablierMerkleBase } from "./ISablierMerkleBase.sol";

/// @title ISablierMerkleLT
/// @notice Merkle Lockup campaign that creates Lockup Tranched streams.
/// @notice Merkle Lockup enables airdrops with a vesting period powered by the Lockup Tranched distribution model.
interface ISablierMerkleLT is ISablierMerkleBase {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
Expand All @@ -20,23 +20,23 @@ interface ISablierMerkleLT is ISablierMerkleBase {
CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/

/// @notice A flag indicating whether the streams can be canceled.
/// @dev This is an immutable state variable.
function CANCELABLE() external returns (bool);

/// @notice The address of the {SablierLockup} contract.
function LOCKUP() external view returns (ISablierLockup);

/// @notice A flag indicating whether the streams can be canceled.
/// @dev This is an immutable state variable.
function STREAM_CANCELABLE() external returns (bool);

/// @notice The start time of the streams created through {SablierMerkleBase.claim} function.
/// @dev A start time value of zero will be considered as `block.timestamp`.
/// @dev A start time value of zero will be treated as `block.timestamp`.
function STREAM_START_TIME() external returns (uint40);

/// @notice The total percentage of the tranches.
function TOTAL_PERCENTAGE() external view returns (uint64);

/// @notice A flag indicating whether the stream NFTs are transferable.
/// @dev This is an immutable state variable.
function TRANSFERABLE() external returns (bool);
function STREAM_TRANSFERABLE() external returns (bool);

/// @notice The total percentage of the tranches.
function TOTAL_PERCENTAGE() external view returns (uint64);

/// @notice Retrieves the tranches with their respective unlock percentages and durations.
function getTranchesWithPercentages() external view returns (MerkleLT.TrancheWithPercentage[] memory);
Expand Down
6 changes: 3 additions & 3 deletions tests/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity >=0.8.22 <0.9.0;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ISablierLockup } from "@sablier/lockup/interfaces/ISablierLockup.sol";
import { LockupNFTDescriptor } from "@sablier/lockup/LockupNFTDescriptor.sol";
import { SablierLockup } from "@sablier/lockup/SablierLockup.sol";
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";
import { LockupNFTDescriptor } from "@sablier/lockup/src/LockupNFTDescriptor.sol";
import { SablierLockup } from "@sablier/lockup/src/SablierLockup.sol";
import { ISablierMerkleBase } from "src/interfaces/ISablierMerkleBase.sol";
import { ISablierMerkleFactory } from "src/interfaces/ISablierMerkleFactory.sol";
import { ISablierMerkleInstant } from "src/interfaces/ISablierMerkleInstant.sol";
Expand Down
2 changes: 1 addition & 1 deletion tests/fork/merkle-campaign/MerkleLL.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.22 <0.9.0;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Arrays } from "@openzeppelin/contracts/utils/Arrays.sol";
import { Lockup } from "@sablier/lockup/types/DataTypes.sol";
import { Lockup } from "@sablier/lockup/src/types/DataTypes.sol";

import { ISablierMerkleFactory } from "src/interfaces/ISablierMerkleFactory.sol";
import { ISablierMerkleBase, ISablierMerkleLL } from "src/interfaces/ISablierMerkleLL.sol";
Expand Down
4 changes: 2 additions & 2 deletions tests/fork/merkle-campaign/MerkleLT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pragma solidity >=0.8.22 <0.9.0;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Arrays } from "@openzeppelin/contracts/utils/Arrays.sol";
import { LockupTranched } from "@sablier/lockup//types/DataTypes.sol";
import { Lockup } from "@sablier/lockup/types/DataTypes.sol";
import { LockupTranched } from "@sablier/lockup/src/types/DataTypes.sol";
import { Lockup } from "@sablier/lockup/src/types/DataTypes.sol";
import { ISablierMerkleFactory } from "src/interfaces/ISablierMerkleFactory.sol";
import { ISablierMerkleBase, ISablierMerkleLT } from "src/interfaces/ISablierMerkleLT.sol";
import { MerkleBase } from "src/types/DataTypes.sol";
Expand Down
Loading

0 comments on commit 718074c

Please sign in to comment.