Skip to content

Commit

Permalink
test: msg.value in claim function
Browse files Browse the repository at this point in the history
test: setSablierFee
  • Loading branch information
smol-ninja committed Sep 9, 2024
1 parent 945477a commit 4657ecc
Show file tree
Hide file tree
Showing 28 changed files with 353 additions and 109 deletions.
13 changes: 8 additions & 5 deletions precompiles/Precompiles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ contract Precompiles {
}

/// @notice Deploys {SablierMerkleFactory} from precompiled bytecode.
function deployMerkleFactory() public returns (ISablierMerkleFactory factory) {
bytes memory creationBytecode = BYTECODE_MERKLE_FACTORY;
function deployMerkleFactory(address initialAdmin) public returns (ISablierMerkleFactory factory) {
bytes memory creationBytecode = bytes.concat(BYTECODE_MERKLE_FACTORY, abi.encode(initialAdmin));
assembly {
factory := create(0, add(creationBytecode, 0x20), mload(creationBytecode))
}
Expand All @@ -223,9 +223,12 @@ contract Precompiles {
///
/// 1. {SablierBatchLockup}
/// 2. {SablierMerkleFactory}
function deployPeriphery() public returns (ISablierBatchLockup batchLockup, ISablierMerkleFactory merkleFactory) {
function deployPeriphery(address initialAdmin)
public
returns (ISablierBatchLockup batchLockup, ISablierMerkleFactory merkleFactory)
{
batchLockup = deployBatchLockup();
merkleFactory = deployMerkleFactory();
merkleFactory = deployMerkleFactory(initialAdmin);
}

/// @notice Deploys the entire Lockup Protocol from precompiled bytecode.
Expand All @@ -251,6 +254,6 @@ contract Precompiles {
(nftDescriptor, lockupDynamic, lockupLinear, lockupTranched) = deployCore(initialAdmin);

// Deploy Periphery.
(batchLockup, merkleFactory) = deployPeriphery();
(batchLockup, merkleFactory) = deployPeriphery(initialAdmin);
}
}
2 changes: 1 addition & 1 deletion script/DeployDeterministicProtocol.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ contract DeployDeterministicProtocol is BaseScript {

// Deploy Periphery.
batchLockup = new SablierBatchLockup{ salt: salt }();
merkleFactory = new SablierMerkleFactory{ salt: salt }();
merkleFactory = new SablierMerkleFactory{ salt: salt }(initialAdmin);
}
}
2 changes: 1 addition & 1 deletion script/DeployProtocol.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ contract DeployProtocol is BaseScript {

// Deploy Periphery.
batchLockup = new SablierBatchLockup();
merkleFactory = new SablierMerkleFactory();
merkleFactory = new SablierMerkleFactory(initialAdmin);
}
}
4 changes: 2 additions & 2 deletions script/periphery/DeployDeterministicPeriphery.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { BaseScript } from "../Base.s.sol";
/// @dev Reverts if any contract has already been deployed.
contract DeployDeterministicPeriphery is BaseScript {
/// @dev Deploy via Forge.
function run()
function run(address initialAdmin)
public
virtual
broadcast
returns (SablierBatchLockup batchLockup, SablierMerkleFactory merkleFactory)
{
bytes32 salt = constructCreate2Salt();
batchLockup = new SablierBatchLockup{ salt: salt }();
merkleFactory = new SablierMerkleFactory{ salt: salt }();
merkleFactory = new SablierMerkleFactory{ salt: salt }(initialAdmin);
}
}
4 changes: 2 additions & 2 deletions script/periphery/DeployMerkleFactory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BaseScript } from "../Base.s.sol";

contract DeployMerkleFactory is BaseScript {
/// @dev Deploy via Forge.
function run() public virtual broadcast returns (SablierMerkleFactory merkleFactory) {
merkleFactory = new SablierMerkleFactory();
function run(address initialAdmin) public virtual broadcast returns (SablierMerkleFactory merkleFactory) {
merkleFactory = new SablierMerkleFactory(initialAdmin);
}
}
4 changes: 2 additions & 2 deletions script/periphery/DeployPeriphery.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { BaseScript } from "../Base.s.sol";
/// 2. {SablierMerkleFactory}
contract DeployPeriphery is BaseScript {
/// @dev Deploy via Forge.
function run()
function run(address initialAdmin)
public
virtual
broadcast
returns (SablierBatchLockup batchLockup, SablierMerkleFactory merkleFactory)
{
batchLockup = new SablierBatchLockup();
merkleFactory = new SablierMerkleFactory();
merkleFactory = new SablierMerkleFactory(initialAdmin);
}
}
3 changes: 3 additions & 0 deletions src/periphery/abstracts/SablierMerkleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ abstract contract SablierMerkleBase is
SABLIER_FEE = sablierFee;
}

/// @dev Implements the receive Ether function to be able to receive sablier fee during claim.
receive() external payable { }

/*//////////////////////////////////////////////////////////////////////////
USER-FACING CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
Expand Down
22 changes: 21 additions & 1 deletion test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SablierLockupLinear } from "src/core/SablierLockupLinear.sol";
import { SablierLockupTranched } from "src/core/SablierLockupTranched.sol";
import { LockupDynamic, LockupLinear, LockupTranched } from "src/core/types/DataTypes.sol";
import { ISablierBatchLockup } from "src/periphery/interfaces/ISablierBatchLockup.sol";
import { ISablierMerkleBase } from "src/periphery/interfaces/ISablierMerkleBase.sol";
import { ISablierMerkleFactory } from "src/periphery/interfaces/ISablierMerkleFactory.sol";
import { ISablierMerkleInstant } from "src/periphery/interfaces/ISablierMerkleInstant.sol";
import { ISablierMerkleLL } from "src/periphery/interfaces/ISablierMerkleLL.sol";
Expand Down Expand Up @@ -88,6 +89,9 @@ abstract contract Base_Test is Assertions, Calculations, Constants, DeployOptimi
// Deploy the protocol.
deployProtocolConditionally();

// Set the Sablier fee on the Merkle factory.
merkleFactory.setSablierFee(defaults.SABLIER_FEE());

// Create users for testing.
users.alice = createUser("Alice");
users.broker = createUser("Broker");
Expand Down Expand Up @@ -155,7 +159,7 @@ abstract contract Base_Test is Assertions, Calculations, Constants, DeployOptimi
lockupDynamic = new SablierLockupDynamic(users.admin, nftDescriptor, defaults.MAX_SEGMENT_COUNT());
lockupLinear = new SablierLockupLinear(users.admin, nftDescriptor);
lockupTranched = new SablierLockupTranched(users.admin, nftDescriptor, defaults.MAX_TRANCHE_COUNT());
merkleFactory = new SablierMerkleFactory();
merkleFactory = new SablierMerkleFactory(users.admin);
} else {
(nftDescriptor, lockupDynamic, lockupLinear, lockupTranched, batchLockup, merkleFactory) =
deployOptimizedProtocol(users.admin, defaults.MAX_SEGMENT_COUNT(), defaults.MAX_TRANCHE_COUNT());
Expand Down Expand Up @@ -220,6 +224,22 @@ abstract contract Base_Test is Assertions, Calculations, Constants, DeployOptimi
});
}

/*//////////////////////////////////////////////////////////////////////////
CALL EXPECTS - MERKLE LOCKUP
//////////////////////////////////////////////////////////////////////////*/

/// @dev Expects a call to {ISablierMerkleBase.claim} with msgValue as `msg.value`.
function expectCallToClaimWithMsgValue(address merkleLockup, uint256 msgValue) internal {
vm.expectCall(
merkleLockup,
msgValue,
abi.encodeCall(
ISablierMerkleBase.claim,
(defaults.INDEX1(), users.recipient1, defaults.CLAIM_AMOUNT(), defaults.index1Proof())
)
);
}

/*//////////////////////////////////////////////////////////////////////////
CALL EXPECTS - LOCKUP
//////////////////////////////////////////////////////////////////////////*/
Expand Down
34 changes: 22 additions & 12 deletions test/periphery/Periphery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ contract Periphery_Test is Base_Test {
address admin,
IERC20 asset_,
bytes32 merkleRoot,
uint40 expiration
uint40 expiration,
uint256 sablierFee
)
internal
view
Expand All @@ -40,7 +41,8 @@ contract Periphery_Test is Base_Test {
defaults.NAME_BYTES32()
)
);
bytes32 creationBytecodeHash = keccak256(getMerkleInstantBytecode(admin, asset_, merkleRoot, expiration));
bytes32 creationBytecodeHash =
keccak256(getMerkleInstantBytecode(admin, asset_, merkleRoot, expiration, sablierFee));
return vm.computeCreate2Address({
salt: salt,
initCodeHash: creationBytecodeHash,
Expand All @@ -53,7 +55,8 @@ contract Periphery_Test is Base_Test {
address admin,
IERC20 asset_,
bytes32 merkleRoot,
uint40 expiration
uint40 expiration,
uint256 sablierFee
)
internal
view
Expand All @@ -74,7 +77,7 @@ contract Periphery_Test is Base_Test {
abi.encode(defaults.schedule())
)
);
bytes32 creationBytecodeHash = keccak256(getMerkleLLBytecode(admin, asset_, merkleRoot, expiration));
bytes32 creationBytecodeHash = keccak256(getMerkleLLBytecode(admin, asset_, merkleRoot, expiration, sablierFee));
return vm.computeCreate2Address({
salt: salt,
initCodeHash: creationBytecodeHash,
Expand All @@ -87,7 +90,8 @@ contract Periphery_Test is Base_Test {
address admin,
IERC20 asset_,
bytes32 merkleRoot,
uint40 expiration
uint40 expiration,
uint256 sablierFee
)
internal
view
Expand All @@ -109,7 +113,7 @@ contract Periphery_Test is Base_Test {
abi.encode(defaults.tranchesWithPercentages())
)
);
bytes32 creationBytecodeHash = keccak256(getMerkleLTBytecode(admin, asset_, merkleRoot, expiration));
bytes32 creationBytecodeHash = keccak256(getMerkleLTBytecode(admin, asset_, merkleRoot, expiration, sablierFee));
return vm.computeCreate2Address({
salt: salt,
initCodeHash: creationBytecodeHash,
Expand All @@ -121,13 +125,15 @@ contract Periphery_Test is Base_Test {
address admin,
IERC20 asset_,
bytes32 merkleRoot,
uint40 expiration
uint40 expiration,
uint256 sablierFee
)
internal
view
returns (bytes memory)
{
bytes memory constructorArgs = abi.encode(defaults.baseParams(admin, asset_, expiration, merkleRoot));
bytes memory constructorArgs =
abi.encode(defaults.baseParams(admin, asset_, expiration, merkleRoot), sablierFee);
if (!isTestOptimizedProfile()) {
return bytes.concat(type(SablierMerkleInstant).creationCode, constructorArgs);
} else {
Expand All @@ -141,7 +147,8 @@ contract Periphery_Test is Base_Test {
address admin,
IERC20 asset_,
bytes32 merkleRoot,
uint40 expiration
uint40 expiration,
uint256 sablierFee
)
internal
view
Expand All @@ -152,7 +159,8 @@ contract Periphery_Test is Base_Test {
lockupLinear,
defaults.CANCELABLE(),
defaults.TRANSFERABLE(),
defaults.schedule()
defaults.schedule(),
sablierFee
);
if (!isTestOptimizedProfile()) {
return bytes.concat(type(SablierMerkleLL).creationCode, constructorArgs);
Expand All @@ -165,7 +173,8 @@ contract Periphery_Test is Base_Test {
address admin,
IERC20 asset_,
bytes32 merkleRoot,
uint40 expiration
uint40 expiration,
uint256 sablierFee
)
internal
view
Expand All @@ -177,7 +186,8 @@ contract Periphery_Test is Base_Test {
defaults.CANCELABLE(),
defaults.TRANSFERABLE(),
defaults.STREAM_START_TIME_ZERO(),
defaults.tranchesWithPercentages()
defaults.tranchesWithPercentages(),
sablierFee
);
if (!isTestOptimizedProfile()) {
return bytes.concat(type(SablierMerkleLT).creationCode, constructorArgs);
Expand Down
9 changes: 6 additions & 3 deletions test/periphery/fork/merkle-campaign/MerkleInstant.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ abstract contract MerkleInstant_Fork_Test is Fork_Test {
// Make the caller the admin.
resetPrank({ msgSender: params.admin });

vars.expectedMerkleInstant =
computeMerkleInstantAddress(params.admin, params.admin, FORK_ASSET, vars.merkleRoot, params.expiration);
uint256 sablierFee = defaults.SABLIER_FEE();

vars.expectedMerkleInstant = computeMerkleInstantAddress(
params.admin, params.admin, FORK_ASSET, vars.merkleRoot, params.expiration, sablierFee
);

vars.baseParams = defaults.baseParams({
admin: params.admin,
Expand Down Expand Up @@ -165,7 +168,7 @@ abstract contract MerkleInstant_Fork_Test is Fork_Test {
value: vars.amounts[params.posBeforeSort]
});

vars.merkleInstant.claim({
vars.merkleInstant.claim{ value: sablierFee }({
index: vars.indexes[params.posBeforeSort],
recipient: vars.recipients[params.posBeforeSort],
amount: vars.amounts[params.posBeforeSort],
Expand Down
9 changes: 6 additions & 3 deletions test/periphery/fork/merkle-campaign/MerkleLL.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ abstract contract MerkleLL_Fork_Test is Fork_Test {
// Make the caller the admin.
resetPrank({ msgSender: params.admin });

vars.expectedLL =
computeMerkleLLAddress(params.admin, params.admin, FORK_ASSET, vars.merkleRoot, params.expiration);
uint256 sablierFee = defaults.SABLIER_FEE();

vars.expectedLL = computeMerkleLLAddress(
params.admin, params.admin, FORK_ASSET, vars.merkleRoot, params.expiration, sablierFee
);

vars.baseParams = defaults.baseParams({
admin: params.admin,
Expand Down Expand Up @@ -170,7 +173,7 @@ abstract contract MerkleLL_Fork_Test is Fork_Test {
vars.merkleProof = getProof(leaves.toBytes32(), vars.leafPos);
}

vars.merkleLL.claim({
vars.merkleLL.claim{ value: sablierFee }({
index: vars.indexes[params.posBeforeSort],
recipient: vars.recipients[params.posBeforeSort],
amount: vars.amounts[params.posBeforeSort],
Expand Down
9 changes: 6 additions & 3 deletions test/periphery/fork/merkle-campaign/MerkleLT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ abstract contract MerkleLT_Fork_Test is Fork_Test {
// Make the caller the admin.
resetPrank({ msgSender: params.admin });

vars.expectedLT =
computeMerkleLTAddress(params.admin, params.admin, FORK_ASSET, vars.merkleRoot, params.expiration);
uint256 sablierFee = defaults.SABLIER_FEE();

vars.expectedLT = computeMerkleLTAddress(
params.admin, params.admin, FORK_ASSET, vars.merkleRoot, params.expiration, sablierFee
);

vars.baseParams = defaults.baseParams({
admin: params.admin,
Expand Down Expand Up @@ -173,7 +176,7 @@ abstract contract MerkleLT_Fork_Test is Fork_Test {
vars.merkleProof = getProof(leaves.toBytes32(), vars.leafPos);
}

vars.merkleLT.claim({
vars.merkleLT.claim{value; sablierFee}({
index: vars.indexes[params.posBeforeSort],
recipient: vars.recipients[params.posBeforeSort],
amount: vars.amounts[params.posBeforeSort],
Expand Down
Loading

0 comments on commit 4657ecc

Please sign in to comment.