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

refactor: constructor params #326

Merged
merged 3 commits into from
Apr 12, 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 precompiles/Precompiles.sol

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/SablierV2MerkleLockupFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ contract SablierV2MerkleLockupFactory is ISablierV2MerkleLockupFactory {
// Hash the parameters to generate a salt.
bytes32 salt = keccak256(
abi.encodePacked(
baseParams.initialAdmin,
baseParams.asset,
baseParams.cancelable,
baseParams.expiration,
baseParams.initialAdmin,
abi.encode(baseParams.ipfsCID),
bytes32(abi.encodePacked(baseParams.name)),
baseParams.merkleRoot,
baseParams.expiration,
baseParams.cancelable,
bytes32(abi.encodePacked(baseParams.name)),
baseParams.transferable,
lockupLinear,
abi.encode(streamDurations)
Expand Down Expand Up @@ -86,13 +86,13 @@ contract SablierV2MerkleLockupFactory is ISablierV2MerkleLockupFactory {
// Hash the parameters to generate a salt.
bytes32 salt = keccak256(
abi.encodePacked(
baseParams.initialAdmin,
baseParams.asset,
baseParams.cancelable,
baseParams.expiration,
baseParams.initialAdmin,
abi.encode(baseParams.ipfsCID),
bytes32(abi.encodePacked(baseParams.name)),
baseParams.merkleRoot,
baseParams.expiration,
baseParams.cancelable,
bytes32(abi.encodePacked(baseParams.name)),
baseParams.transferable,
lockupTranched,
abi.encode(tranchesWithPercentages)
Expand Down
18 changes: 9 additions & 9 deletions src/types/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ library BatchLockup {

library MerkleLockup {
/// @notice Struct encapsulating the base constructor parameters of a MerkleLockup campaign.
/// @param initialAdmin The initial admin of the MerkleLockup campaign.
/// @param asset The contract address of the ERC-20 asset to be distributed.
/// @param cancelable Indicates if the stream will be cancelable after claiming.
/// @param expiration The expiration of the campaign, as a Unix timestamp.
/// @param initialAdmin The initial admin of the MerkleLockup campaign.
/// @param ipfsCID The content identifier for indexing the contract on IPFS.
/// @param name The name of the campaign.
/// @param merkleRoot The Merkle root of the claim data.
/// @param expiration The expiration of the campaign, as a Unix timestamp.
/// @param cancelable Indicates if the stream will be cancelable after claiming.
/// @param name The name of the campaign.
/// @param transferable Indicates if the stream will be transferable after claiming.
struct ConstructorParams {
address initialAdmin;
IERC20 asset;
bool cancelable;
uint40 expiration;
address initialAdmin;
string ipfsCID;
string name;
bytes32 merkleRoot;
uint40 expiration;
bool cancelable;
string name;
bool transferable;
}
}
Expand All @@ -114,7 +114,7 @@ library MerkleLT {
/// @notice Struct encapsulating the unlock percentage and duration of a tranche.
/// @dev Since users may have different amounts allocated, this struct makes it possible to calculate the amounts
/// at claim time. An 18-decimal format is used to represent percentages: 100% = 1e18. For more information, see
/// the PRBMath documentation on {UD2x18}: https://github.com/PaulRBerg/prb-math
/// the PRBMath documentation on UD2x18: https://github.com/PaulRBerg/prb-math
/// @param unlockPercentage The percentage designated to be unlocked in this tranche.
/// @param duration The time difference in seconds between this tranche and the previous one.
struct TrancheWithPercentage {
Expand Down
20 changes: 10 additions & 10 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ abstract contract Base_Test is
{
bytes32 salt = keccak256(
abi.encodePacked(
admin,
address(asset_),
defaults.CANCELABLE(),
expiration,
admin,
abi.encode(defaults.IPFS_CID()),
defaults.NAME_BYTES32(),
merkleRoot,
expiration,
defaults.CANCELABLE(),
defaults.NAME_BYTES32(),
defaults.TRANSFERABLE(),
lockupLinear,
abi.encode(defaults.durations())
Expand Down Expand Up @@ -330,13 +330,13 @@ abstract contract Base_Test is
{
bytes32 salt = keccak256(
abi.encodePacked(
admin,
address(asset_),
defaults.CANCELABLE(),
expiration,
admin,
abi.encode(defaults.IPFS_CID()),
defaults.NAME_BYTES32(),
merkleRoot,
expiration,
defaults.CANCELABLE(),
defaults.NAME_BYTES32(),
defaults.TRANSFERABLE(),
lockupTranched,
abi.encode(defaults.tranchesWithPercentages())
Expand All @@ -361,7 +361,7 @@ abstract contract Base_Test is
returns (bytes memory)
{
bytes memory constructorArgs =
abi.encode(defaults.baseParams(admin, asset_, merkleRoot, expiration), lockupLinear, defaults.durations());
abi.encode(defaults.baseParams(admin, asset_, expiration, merkleRoot), lockupLinear, defaults.durations());
if (!isTestOptimizedProfile()) {
return bytes.concat(type(SablierV2MerkleLL).creationCode, constructorArgs);
} else {
Expand All @@ -381,7 +381,7 @@ abstract contract Base_Test is
returns (bytes memory)
{
bytes memory constructorArgs = abi.encode(
defaults.baseParams(admin, asset_, merkleRoot, expiration),
defaults.baseParams(admin, asset_, expiration, merkleRoot),
lockupTranched,
defaults.tranchesWithPercentages()
);
Expand Down
4 changes: 2 additions & 2 deletions test/fork/merkle-lockup/MerkleLT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ abstract contract MerkleLT_Fork_Test is Fork_Test {
}

struct Vars {
uint256 actualStreamId;
LockupTranched.StreamLT actualStream;
uint256 actualStreamId;
LockupTranched.Tranche[] actualTranches;
uint128[] amounts;
uint256 aggregateAmount;
uint128[] amounts;
MerkleLockup.ConstructorParams baseParams;
uint128 clawbackAmount;
address expectedLT;
Expand Down
4 changes: 2 additions & 2 deletions test/integration/merkle-lockup/MerkleLockup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ abstract contract MerkleLockup_Integration_Test is Integration_Test {

function createMerkleLL(address admin, uint40 expiration) internal returns (ISablierV2MerkleLL) {
return merkleLockupFactory.createMerkleLL({
baseParams: defaults.baseParams(admin, dai, defaults.MERKLE_ROOT(), expiration),
baseParams: defaults.baseParams(admin, dai, expiration, defaults.MERKLE_ROOT()),
lockupLinear: lockupLinear,
streamDurations: defaults.durations(),
aggregateAmount: defaults.AGGREGATE_AMOUNT(),
Expand Down Expand Up @@ -113,7 +113,7 @@ abstract contract MerkleLockup_Integration_Test is Integration_Test {

function createMerkleLT(address admin, uint40 expiration) internal returns (ISablierV2MerkleLT) {
return merkleLockupFactory.createMerkleLT({
baseParams: defaults.baseParams(admin, dai, defaults.MERKLE_ROOT(), expiration),
baseParams: defaults.baseParams(admin, dai, expiration, defaults.MERKLE_ROOT()),
lockupTranched: lockupTranched,
tranchesWithPercentages: defaults.tranchesWithPercentages(),
aggregateAmount: defaults.AGGREGATE_AMOUNT(),
Expand Down
12 changes: 6 additions & 6 deletions test/utils/BatchLockupBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ library BatchLockupBuilder {
}
}

/// @notice Turns the `params` into an array of `BatchLockup.CreateWithDurationsLD` structs.
/// @notice Turns the `params` into an array of {BatchLockup.CreateWithDurationsLD} structs.
function fillBatch(
LockupDynamic.CreateWithDurations memory params,
uint256 batchSize
Expand Down Expand Up @@ -58,7 +58,7 @@ library BatchLockupBuilder {
}
}

/// @notice Turns the `params` into an array of `BatchLockup.CreateWithDurationsLL` structs.
/// @notice Turns the `params` into an array of {BatchLockup.CreateWithDurationsLL} structs.
function fillBatch(
LockupLinear.CreateWithDurations memory params,
uint256 batchSize
Expand Down Expand Up @@ -95,7 +95,7 @@ library BatchLockupBuilder {
}
}

/// @notice Turns the `params` into an array of `BatchLockup.CreateWithDurationsLT` structs.
/// @notice Turns the `params` into an array of {BatchLockup.CreateWithDurationsLT} structs.
function fillBatch(
LockupTranched.CreateWithDurations memory params,
uint256 batchSize
Expand Down Expand Up @@ -132,7 +132,7 @@ library BatchLockupBuilder {
}
}

/// @notice Turns the `params` into an array of `BatchLockup.CreateWithTimestampsLDs` structs.
/// @notice Turns the `params` into an array of {BatchLockup.CreateWithTimestampsLDs} structs.
function fillBatch(
LockupDynamic.CreateWithTimestamps memory params,
uint256 batchSize
Expand Down Expand Up @@ -170,7 +170,7 @@ library BatchLockupBuilder {
}
}

/// @notice Turns the `params` into an array of `BatchLockup.CreateWithTimestampsLL` structs.
/// @notice Turns the `params` into an array of {BatchLockup.CreateWithTimestampsLL} structs.
function fillBatch(
LockupLinear.CreateWithTimestamps memory params,
uint256 batchSize
Expand Down Expand Up @@ -207,7 +207,7 @@ library BatchLockupBuilder {
}
}

/// @notice Turns the `params` into an array of `BatchLockup.CreateWithTimestampsLT` structs.
/// @notice Turns the `params` into an array of {BatchLockup.CreateWithTimestampsLT} structs.
function fillBatch(
LockupTranched.CreateWithTimestamps memory params,
uint256 batchSize
Expand Down
42 changes: 21 additions & 21 deletions test/utils/Defaults.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,27 @@ contract Defaults is Merkle {
}

function baseParams() public view returns (MerkleLockup.ConstructorParams memory) {
return baseParams(users.admin, asset, MERKLE_ROOT, EXPIRATION);
return baseParams(users.admin, asset, EXPIRATION, MERKLE_ROOT);
}

function baseParams(
address admin,
IERC20 asset_,
bytes32 merkleRoot,
uint40 expiration
uint40 expiration,
bytes32 merkleRoot
)
public
pure
returns (MerkleLockup.ConstructorParams memory)
{
return MerkleLockup.ConstructorParams({
initialAdmin: admin,
asset: asset_,
cancelable: CANCELABLE,
expiration: expiration,
initialAdmin: admin,
ipfsCID: IPFS_CID,
name: NAME,
merkleRoot: merkleRoot,
expiration: expiration,
cancelable: CANCELABLE,
name: NAME,
transferable: TRANSFERABLE
});
}
Expand Down Expand Up @@ -212,7 +212,7 @@ contract Defaults is Merkle {
});
}

/// @dev Returns a batch of `LockupDynamic.Segment` parameters.
/// @dev Returns a batch of {LockupDynamic.Segment} parameters.
function segments() private view returns (LockupDynamic.Segment[] memory segments_) {
segments_ = new LockupDynamic.Segment[](2);
segments_[0] = LockupDynamic.Segment({
Expand All @@ -227,12 +227,12 @@ contract Defaults is Merkle {
});
}

/// @dev Returns a batch of `LockupDynamic.SegmentWithDuration` parameters.
/// @dev Returns a batch of {LockupDynamic.SegmentWithDuration} parameters.
function segmentsWithDurations() public pure returns (LockupDynamic.SegmentWithDuration[] memory) {
return segmentsWithDurations({ amount0: 2500e18, amount1: 7500e18 });
}

/// @dev Returns a batch of `LockupDynamic.SegmentWithDuration` parameters.
/// @dev Returns a batch of {LockupDynamic.SegmentWithDuration} parameters.
function segmentsWithDurations(
uint128 amount0,
uint128 amount1
Expand Down Expand Up @@ -356,12 +356,12 @@ contract Defaults is Merkle {
}
}

/// @dev Returns a batch of `LockupTranched.TrancheWithDuration` parameters.
/// @dev Returns a batch of {LockupTranched.TrancheWithDuration} parameters.
function tranchesWithDurations() public pure returns (LockupTranched.TrancheWithDuration[] memory) {
return tranchesWithDurations({ amount0: 2500e18, amount1: 7500e18 });
}

/// @dev Returns a batch of `LockupTranched.TrancheWithDuration` parameters.
/// @dev Returns a batch of {LockupTranched.TrancheWithDuration} parameters.
function tranchesWithDurations(
uint128 amount0,
uint128 amount1
Expand All @@ -379,27 +379,27 @@ contract Defaults is Merkle {
BATCH-LOCKUP
//////////////////////////////////////////////////////////////////////////*/

/// @dev Returns a default-size batch of `BatchLockup.CreateWithDurationsLD` parameters.
/// @dev Returns a default-size batch of {BatchLockup.CreateWithDurationsLD} parameters.
function batchCreateWithDurationsLD() public view returns (BatchLockup.CreateWithDurationsLD[] memory batch) {
batch = BatchLockupBuilder.fillBatch(createWithDurationsLD(), BATCH_SIZE);
}

/// @dev Returns a default-size batch of `BatchLockup.CreateWithDurationsLL` parameters.
/// @dev Returns a default-size batch of {BatchLockup.CreateWithDurationsLL} parameters.
function batchCreateWithDurationsLL() public view returns (BatchLockup.CreateWithDurationsLL[] memory batch) {
batch = BatchLockupBuilder.fillBatch(createWithDurationsLL(), BATCH_SIZE);
}

/// @dev Returns a default-size batch of `BatchLockup.CreateWithDurationsLT` parameters.
/// @dev Returns a default-size batch of {BatchLockup.CreateWithDurationsLT} parameters.
function batchCreateWithDurationsLT() public view returns (BatchLockup.CreateWithDurationsLT[] memory batch) {
batch = BatchLockupBuilder.fillBatch(createWithDurationsLT(), BATCH_SIZE);
}

/// @dev Returns a default-size batch of `BatchLockup.CreateWithTimestampsLD` parameters.
/// @dev Returns a default-size batch of {BatchLockup.CreateWithTimestampsLD} parameters.
function batchCreateWithTimestampsLD() public view returns (BatchLockup.CreateWithTimestampsLD[] memory batch) {
batch = batchCreateWithTimestampsLD(BATCH_SIZE);
}

/// @dev Returns a batch of `BatchLockup.CreateWithTimestampsLD` parameters.
/// @dev Returns a batch of {BatchLockup.CreateWithTimestampsLD} parameters.
function batchCreateWithTimestampsLD(uint256 batchSize)
public
view
Expand All @@ -408,12 +408,12 @@ contract Defaults is Merkle {
batch = BatchLockupBuilder.fillBatch(createWithTimestampsLD(), batchSize);
}

/// @dev Returns a default-size batch of `BatchLockup.CreateWithTimestampsLL` parameters.
/// @dev Returns a default-size batch of {BatchLockup.CreateWithTimestampsLL} parameters.
function batchCreateWithTimestampsLL() public view returns (BatchLockup.CreateWithTimestampsLL[] memory batch) {
batch = batchCreateWithTimestampsLL(BATCH_SIZE);
}

/// @dev Returns a batch of `BatchLockup.CreateWithTimestampsLL` parameters.
/// @dev Returns a batch of {BatchLockup.CreateWithTimestampsLL} parameters.
function batchCreateWithTimestampsLL(uint256 batchSize)
public
view
Expand All @@ -422,12 +422,12 @@ contract Defaults is Merkle {
batch = BatchLockupBuilder.fillBatch(createWithTimestampsLL(), batchSize);
}

/// @dev Returns a default-size batch of `BatchLockup.CreateWithTimestampsLT` parameters.
/// @dev Returns a default-size batch of {BatchLockup.CreateWithTimestampsLT} parameters.
function batchCreateWithTimestampsLT() public view returns (BatchLockup.CreateWithTimestampsLT[] memory batch) {
batch = batchCreateWithTimestampsLT(BATCH_SIZE);
}

/// @dev Returns a batch of `BatchLockup.CreateWithTimestampsLL` parameters.
/// @dev Returns a batch of {BatchLockup.CreateWithTimestampsLL} parameters.
function batchCreateWithTimestampsLT(uint256 batchSize)
public
view
Expand Down