Skip to content

Commit

Permalink
Little refactors (#17)
Browse files Browse the repository at this point in the history
* refactor: add STREAM_ prefix

docs: update NatSpec
refactor: import from src

* chore: removes redundant remapping
perf: marks _schedule as private

* temp commit

* test: polish code

---------

Co-authored-by: smol-ninja <[email protected]>
Co-authored-by: andreivladbrg <[email protected]>
  • Loading branch information
3 people authored Nov 27, 2024
1 parent 012c8b2 commit b0f2938
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 119 deletions.
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@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/
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
59 changes: 34 additions & 25 deletions src/SablierMerkleLL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ 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";
import { MerkleBase, MerkleLL } from "./types/DataTypes.sol";

/*
/*
███████╗ █████╗ ██████╗ ██╗ ██╗███████╗██████╗
███████╗ █████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔════╝██╔══██╗██╔══██╗██║ ██║██╔════╝██╔══██╗
███████╗███████║██████╔╝██║ ██║█████╗ ██████╔╝
╚════██║██╔══██║██╔══██╗██║ ██║██╔══╝ ██╔══██╗
███████║██║ ██║██████╔╝███████╗██║███████╗██║ ██║
╚══════╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝ ╚═╝
███╗ ███╗███████╗██████╗ ██╗ ██╗██╗ ███████╗ ██╗ ██╗
████╗ ████║██╔════╝██╔══██╗██║ ██╔╝██║ ██╔════╝ ██║ ██║
██╔████╔██║█████╗ ██████╔╝█████╔╝ ██║ █████╗ ██║ ██║
██║╚██╔╝██║██╔══╝ ██╔══██╗██╔═██╗ ██║ ██╔══╝ ██║ ██║
███╗ ███╗███████╗██████╗ ██╗ ██╗██╗ ███████╗ ██╗ ██╗
████╗ ████║██╔════╝██╔══██╗██║ ██╔╝██║ ██╔════╝ ██║ ██║
██╔████╔██║█████╗ ██████╔╝█████╔╝ ██║ █████╗ ██║ ██║
██║╚██╔╝██║██╔══╝ ██╔══██╗██╔═██╗ ██║ ██╔══╝ ██║ ██║
██║ ╚═╝ ██║███████╗██║ ██║██║ ██╗███████╗███████╗ ███████╗███████╗
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚══════╝╚══════╝
Expand All @@ -41,17 +41,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 private _schedule;

/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
Expand All @@ -64,20 +64,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 @@ -86,21 +95,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 @@ -110,13 +119,13 @@ contract SablierMerkleLL is
recipient: recipient,
totalAmount: amount,
token: TOKEN,
cancelable: CANCELABLE,
transferable: TRANSFERABLE,
cancelable: STREAM_CANCELABLE,
transferable: STREAM_TRANSFERABLE,
timestamps: timestamps,
shape: shape,
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
32 changes: 16 additions & 16 deletions src/SablierMerkleLT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ 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";
import { Errors } from "./libraries/Errors.sol";
import { MerkleBase, MerkleLT } from "./types/DataTypes.sol";

/*
/*
███████╗ █████╗ ██████╗ ██╗ ██╗███████╗██████╗
███████╗ █████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔════╝██╔══██╗██╔══██╗██║ ██║██╔════╝██╔══██╗
███████╗███████║██████╔╝██║ ██║█████╗ ██████╔╝
╚════██║██╔══██║██╔══██╗██║ ██║██╔══╝ ██╔══██╗
Expand All @@ -24,10 +24,10 @@ import { MerkleBase, MerkleLT } from "./types/DataTypes.sol";
███╗ ███╗███████╗██████╗ ██╗ ██╗██╗ ███████╗ ██╗ ████████╗
████╗ ████║██╔════╝██╔══██╗██║ ██╔╝██║ ██╔════╝ ██║ ╚══██╔══╝
██╔████╔██║█████╗ ██████╔╝█████╔╝ ██║ █████╗ ██║ ██║
██║╚██╔╝██║██╔══╝ ██╔══██╗██╔═██╗ ██║ ██╔══╝ ██║ ██║
██║ ╚═╝ ██║███████╗██║ ██║██║ ██╗███████╗███████╗ ███████╗ ██║
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚══════╝ ╚═╝
██╔████╔██║█████╗ ██████╔╝█████╔╝ ██║ █████╗ ██║ ██║
██║╚██╔╝██║██╔══╝ ██╔══██╗██╔═██╗ ██║ ██╔══╝ ██║ ██║
██║ ╚═╝ ██║███████╗██║ ██║██║ ██╗███████╗███████╗ ███████╗ ██║
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚══════╝ ╚═╝
*/

Expand All @@ -44,19 +44,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 @@ -78,10 +78,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 @@ -134,8 +134,8 @@ contract SablierMerkleLT is
recipient: recipient,
totalAmount: amount,
token: TOKEN,
cancelable: CANCELABLE,
transferable: TRANSFERABLE,
cancelable: STREAM_CANCELABLE,
transferable: STREAM_TRANSFERABLE,
timestamps: Lockup.Timestamps({ start: startTime, end: endTime }),
shape: shape,
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
25 changes: 11 additions & 14 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 @@ -19,22 +19,19 @@ interface ISablierMerkleLL 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 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);
}
Loading

0 comments on commit b0f2938

Please sign in to comment.