Skip to content

Commit

Permalink
Rename create functions to match V2 core (#264)
Browse files Browse the repository at this point in the history
* refactor: rename create functions to match v2-core

* build: install v2 core from staging branch

* test: deploy v2-core dependencies for fork testing

* test: update function name

---------

Co-authored-by: andreivladbrg <andreivladbrg@gmail.com>
  • Loading branch information
smol-ninja and andreivladbrg authored Jan 26, 2024
1 parent d355029 commit 0d99298
Show file tree
Hide file tree
Showing 21 changed files with 239 additions and 200 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@openzeppelin/contracts": "4.9.2",
"@prb/math": "4.0.2",
"@sablier/v2-core": "1.1.2"
"@sablier/v2-core": "github:sablier-labs/v2-core#staging"
},
"devDependencies": {
"@prb/test": "0.6.4",
Expand Down
28 changes: 14 additions & 14 deletions src/SablierV2Batch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ contract SablierV2Batch is ISablierV2Batch {
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ISablierV2Batch
function createWithDurations(
function createWithDurationsLL(
ISablierV2LockupLinear lockupLinear,
IERC20 asset,
Batch.CreateWithDurations[] calldata batch
Batch.CreateWithDurationsLL[] calldata batch
)
external
override
Expand Down Expand Up @@ -69,10 +69,10 @@ contract SablierV2Batch is ISablierV2Batch {
}

/// @inheritdoc ISablierV2Batch
function createWithRange(
function createWithTimestampsLL(
ISablierV2LockupLinear lockupLinear,
IERC20 asset,
Batch.CreateWithRange[] calldata batch
Batch.CreateWithTimestampsLL[] calldata batch
)
external
override
Expand Down Expand Up @@ -101,8 +101,8 @@ contract SablierV2Batch is ISablierV2Batch {
streamIds = new uint256[](batchSize);
for (i = 0; i < batchSize; ++i) {
// Create the stream.
streamIds[i] = lockupLinear.createWithRange(
LockupLinear.CreateWithRange({
streamIds[i] = lockupLinear.createWithTimestamps(
LockupLinear.CreateWithTimestamps({
sender: batch[i].sender,
recipient: batch[i].recipient,
totalAmount: batch[i].totalAmount,
Expand All @@ -121,10 +121,10 @@ contract SablierV2Batch is ISablierV2Batch {
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ISablierV2Batch
function createWithDeltas(
function createWithDurationsLD(
ISablierV2LockupDynamic lockupDynamic,
IERC20 asset,
Batch.CreateWithDeltas[] calldata batch
Batch.CreateWithDurationsLD[] calldata batch
)
external
override
Expand Down Expand Up @@ -153,8 +153,8 @@ contract SablierV2Batch is ISablierV2Batch {
streamIds = new uint256[](batchSize);
for (i = 0; i < batchSize; ++i) {
// Create the stream.
streamIds[i] = lockupDynamic.createWithDeltas(
LockupDynamic.CreateWithDeltas({
streamIds[i] = lockupDynamic.createWithDurations(
LockupDynamic.CreateWithDurations({
sender: batch[i].sender,
recipient: batch[i].recipient,
totalAmount: batch[i].totalAmount,
Expand All @@ -169,10 +169,10 @@ contract SablierV2Batch is ISablierV2Batch {
}

/// @inheritdoc ISablierV2Batch
function createWithMilestones(
function createWithTimestampsLD(
ISablierV2LockupDynamic lockupDynamic,
IERC20 asset,
Batch.CreateWithMilestones[] calldata batch
Batch.CreateWithTimestampsLD[] calldata batch
)
external
override
Expand Down Expand Up @@ -201,8 +201,8 @@ contract SablierV2Batch is ISablierV2Batch {
streamIds = new uint256[](batchSize);
for (i = 0; i < batchSize; ++i) {
// Create the stream.
streamIds[i] = lockupDynamic.createWithMilestones(
LockupDynamic.CreateWithMilestones({
streamIds[i] = lockupDynamic.createWithTimestamps(
LockupDynamic.CreateWithTimestamps({
sender: batch[i].sender,
recipient: batch[i].recipient,
totalAmount: batch[i].totalAmount,
Expand Down
34 changes: 17 additions & 17 deletions src/interfaces/ISablierV2Batch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@ interface ISablierV2Batch {
/// @param batch An array of structs, each encapsulating a subset of the parameters of
/// {SablierV2LockupLinear.createWithDurations}.
/// @return streamIds The ids of the newly created streams.
function createWithDurations(
function createWithDurationsLL(
ISablierV2LockupLinear lockupLinear,
IERC20 asset,
Batch.CreateWithDurations[] calldata batch
Batch.CreateWithDurationsLL[] calldata batch
)
external
returns (uint256[] memory streamIds);

/// @notice Creates a batch of Lockup Linear streams using `createWithRange`.
/// @notice Creates a batch of Lockup Linear streams using `createWithTimestamps`.
///
/// @dev Requirements:
/// - There must be at least one element in `batch`.
/// - All requirements from {ISablierV2LockupLinear.createWithRange} must be met for each stream.
/// - All requirements from {ISablierV2LockupLinear.createWithTimestamps} must be met for each stream.
///
/// @param lockupLinear The address of the {SablierV2LockupLinear} contract.
/// @param asset The contract address of the ERC-20 asset used for streaming.
/// @param batch An array of structs, each encapsulating a subset of the parameters of
/// {SablierV2LockupLinear.createWithRange}.
/// {SablierV2LockupLinear.createWithTimestamps}.
/// @return streamIds The ids of the newly created streams.
function createWithRange(
function createWithTimestampsLL(
ISablierV2LockupLinear lockupLinear,
IERC20 asset,
Batch.CreateWithRange[] calldata batch
Batch.CreateWithTimestampsLL[] calldata batch
)
external
returns (uint256[] memory streamIds);
Expand All @@ -56,40 +56,40 @@ interface ISablierV2Batch {
SABLIER-V2-LOCKUP-DYNAMIC
//////////////////////////////////////////////////////////////////////////*/

/// @notice Creates a batch of Lockup Dynamic streams using `createWithDeltas`.
/// @notice Creates a batch of Lockup Dynamic streams using `createWithDurations`.
///
/// @dev Requirements:
/// - There must be at least one element in `batch`.
/// - All requirements from {ISablierV2LockupDynamic.createWithDeltas} must be met for each stream.
/// - All requirements from {ISablierV2LockupDynamic.createWithDurations} must be met for each stream.
///
/// @param lockupDynamic The address of the {SablierV2LockupDynamic} contract.
/// @param asset The contract address of the ERC-20 asset used for streaming.
/// @param batch An array of structs, each encapsulating a subset of the parameters of
/// {SablierV2LockupDynamic.createWithDeltas}.
/// {SablierV2LockupDynamic.createWithDurations}.
/// @return streamIds The ids of the newly created streams.
function createWithDeltas(
function createWithDurationsLD(
ISablierV2LockupDynamic lockupDynamic,
IERC20 asset,
Batch.CreateWithDeltas[] calldata batch
Batch.CreateWithDurationsLD[] calldata batch
)
external
returns (uint256[] memory streamIds);

/// @notice Creates a batch of Lockup Dynamic streams using `createWithMilestones`.
/// @notice Creates a batch of Lockup Dynamic streams using `createWithTimestamps`.
///
/// @dev Requirements:
/// - There must be at least one element in `batch`.
/// - All requirements from {ISablierV2LockupDynamic.createWithMilestones} must be met for each stream.
/// - All requirements from {ISablierV2LockupDynamic.createWithTimestamps} must be met for each stream.
///
/// @param lockupDynamic The address of the {SablierV2LockupDynamic} contract.
/// @param asset The contract address of the ERC-20 asset used for streaming.
/// @param batch An array of structs, each encapsulating a subset of the parameters of
/// {SablierV2LockupDynamic.createWithMilestones}.
/// {SablierV2LockupDynamic.createWithTimestamps}.
/// @return streamIds The ids of the newly created streams.
function createWithMilestones(
function createWithTimestampsLD(
ISablierV2LockupDynamic lockupDynamic,
IERC20 asset,
Batch.CreateWithMilestones[] calldata batch
Batch.CreateWithTimestampsLD[] calldata batch
)
external
returns (uint256[] memory streamIds);
Expand Down
18 changes: 10 additions & 8 deletions src/types/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ library Batch {
uint256[] streamIds;
}

/// @notice A struct encapsulating all parameters of {SablierV2LockupDynamic.createWithDelta} except for the asset.
struct CreateWithDeltas {
/// @notice A struct encapsulating all parameters of {SablierV2LockupDynamic.createWithDurations} except for the
/// asset.
struct CreateWithDurationsLD {
address sender;
address recipient;
uint128 totalAmount;
bool cancelable;
bool transferable;
LockupDynamic.SegmentWithDelta[] segments;
LockupDynamic.SegmentWithDuration[] segments;
Broker broker;
}

/// @notice A struct encapsulating all parameters of {SablierV2LockupLinear.createWithDurations} except for the
/// asset.
struct CreateWithDurations {
struct CreateWithDurationsLL {
address sender;
address recipient;
uint128 totalAmount;
Expand All @@ -34,9 +35,9 @@ library Batch {
Broker broker;
}

/// @notice A struct encapsulating all parameters of {SablierV2LockupDynamic.createWithMilestones} except for the
/// @notice A struct encapsulating all parameters of {SablierV2LockupDynamic.createWithTimestamps} except for the
/// asset.
struct CreateWithMilestones {
struct CreateWithTimestampsLD {
address sender;
address recipient;
uint128 totalAmount;
Expand All @@ -47,8 +48,9 @@ library Batch {
Broker broker;
}

/// @notice A struct encapsulating all parameters of {SablierV2LockupLinear.createWithRange} except for the asset.
struct CreateWithRange {
/// @notice A struct encapsulating all parameters of {SablierV2LockupLinear.createWithTimestamps} except for the
/// asset.
struct CreateWithTimestampsLL {
address sender;
address recipient;
uint128 totalAmount;
Expand Down
51 changes: 28 additions & 23 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,35 @@ abstract contract Base_Test is DeployOptimized, Events, Merkle, V2CoreAssertions
CALL EXPECTS
//////////////////////////////////////////////////////////////////////////*/

/// @dev Expects a call to {ISablierV2LockupDynamic.createWithDeltas}.
function expectCallToCreateWithDeltas(LockupDynamic.CreateWithDeltas memory params) internal {
/// @dev Expects a call to {ISablierV2LockupDynamic.createWithDurations}.
function expectCallToCreateWithDurationsLD(LockupDynamic.CreateWithDurations memory params) internal {
vm.expectCall({
callee: address(lockupDynamic),
data: abi.encodeCall(ISablierV2LockupDynamic.createWithDeltas, (params))
data: abi.encodeCall(ISablierV2LockupDynamic.createWithDurations, (params))
});
}

/// @dev Expects a call to {ISablierV2LockupLinear.createWithDurations}.
function expectCallToCreateWithDurations(LockupLinear.CreateWithDurations memory params) internal {
function expectCallToCreateWithDurationsLL(LockupLinear.CreateWithDurations memory params) internal {
vm.expectCall({
callee: address(lockupLinear),
data: abi.encodeCall(ISablierV2LockupLinear.createWithDurations, (params))
});
}

/// @dev Expects a call to {ISablierV2LockupDynamic.createWithMilestones}.
function expectCallToCreateWithMilestones(LockupDynamic.CreateWithMilestones memory params) internal {
/// @dev Expects a call to {ISablierV2LockupDynamic.createWithTimestamps}.
function expectCallToCreateWithTimestampsLD(LockupDynamic.CreateWithTimestamps memory params) internal {
vm.expectCall({
callee: address(lockupDynamic),
data: abi.encodeCall(ISablierV2LockupDynamic.createWithMilestones, (params))
data: abi.encodeCall(ISablierV2LockupDynamic.createWithTimestamps, (params))
});
}

/// @dev Expects a call to {ISablierV2LockupLinear.createWithRange}.
function expectCallToCreateWithRange(LockupLinear.CreateWithRange memory params) internal {
/// @dev Expects a call to {ISablierV2LockupLinear.createWithTimestamps}.
function expectCallToCreateWithTimestampsLL(LockupLinear.CreateWithTimestamps memory params) internal {
vm.expectCall({
callee: address(lockupLinear),
data: abi.encodeCall(ISablierV2LockupLinear.createWithRange, (params))
data: abi.encodeCall(ISablierV2LockupLinear.createWithTimestamps, (params))
});
}

Expand All @@ -163,24 +163,24 @@ abstract contract Base_Test is DeployOptimized, Events, Merkle, V2CoreAssertions
vm.expectCall({ callee: asset_, data: abi.encodeCall(IERC20.transferFrom, (from, to, amount)) });
}

/// @dev Expects multiple calls to {ISablierV2LockupDynamic.createWithDeltas}, each with the specified
/// @dev Expects multiple calls to {ISablierV2LockupDynamic.createWithDurations}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithDeltas(
function expectMultipleCallsToCreateWithDurationsLD(
uint64 count,
LockupDynamic.CreateWithDeltas memory params
LockupDynamic.CreateWithDurations memory params
)
internal
{
vm.expectCall({
callee: address(lockupDynamic),
count: count,
data: abi.encodeCall(ISablierV2LockupDynamic.createWithDeltas, (params))
data: abi.encodeCall(ISablierV2LockupDynamic.createWithDurations, (params))
});
}

/// @dev Expects multiple calls to {ISablierV2LockupDynamic.createWithDurations}, each with the specified
/// @dev Expects multiple calls to {ISablierV2LockupLinear.createWithDurations}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithDurations(
function expectMultipleCallsToCreateWithDurationsLL(
uint64 count,
LockupLinear.CreateWithDurations memory params
)
Expand All @@ -193,28 +193,33 @@ abstract contract Base_Test is DeployOptimized, Events, Merkle, V2CoreAssertions
});
}

/// @dev Expects multiple calls to {ISablierV2LockupDynamic.createWithMilestones}, each with the specified
/// @dev Expects multiple calls to {ISablierV2LockupDynamic.createWithTimestamps}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithMilestones(
function expectMultipleCallsToCreateWithTimestampsLD(
uint64 count,
LockupDynamic.CreateWithMilestones memory params
LockupDynamic.CreateWithTimestamps memory params
)
internal
{
vm.expectCall({
callee: address(lockupDynamic),
count: count,
data: abi.encodeCall(ISablierV2LockupDynamic.createWithMilestones, (params))
data: abi.encodeCall(ISablierV2LockupDynamic.createWithTimestamps, (params))
});
}

/// @dev Expects multiple calls to {ISablierV2LockupDynamic.createWithRange}, each with the specified
/// @dev Expects multiple calls to {ISablierV2LockupLinear.createWithTimestamps}, each with the specified
/// `params`.
function expectMultipleCallsToCreateWithRange(uint64 count, LockupLinear.CreateWithRange memory params) internal {
function expectMultipleCallsToCreateWithTimestampsLL(
uint64 count,
LockupLinear.CreateWithTimestamps memory params
)
internal
{
vm.expectCall({
callee: address(lockupLinear),
count: count,
data: abi.encodeCall(ISablierV2LockupLinear.createWithRange, (params))
data: abi.encodeCall(ISablierV2LockupLinear.createWithTimestamps, (params))
});
}

Expand Down
11 changes: 10 additions & 1 deletion test/fork/Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity >=0.8.22 <0.9.0;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ISablierV2LockupDynamic } from "@sablier/v2-core/src/interfaces/ISablierV2LockupDynamic.sol";
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
import { Precompiles as V2CorePrecompiles } from "@sablier/v2-core/test/utils/Precompiles.sol";

import { Fuzzers as V2CoreFuzzers } from "@sablier/v2-core/test/utils/Fuzzers.sol";

Expand Down Expand Up @@ -32,7 +33,9 @@ abstract contract Fork_Test is Base_Test, V2CoreFuzzers {
Base_Test.setUp();

// Load the external dependencies.
loadDependencies();
// loadDependencies();
// TODO: Remove this line once the v2 core contracts are deployed on Mainnet.
deployDependencies();

// Deploy the defaults contract and allow it to access cheatcodes.
defaults = new Defaults(users, asset);
Expand Down Expand Up @@ -72,4 +75,10 @@ abstract contract Fork_Test is Base_Test, V2CoreFuzzers {
lockupDynamic = ISablierV2LockupDynamic(0x7CC7e125d83A581ff438608490Cc0f7bDff79127);
lockupLinear = ISablierV2LockupLinear(0xAFb979d9afAd1aD27C5eFf4E27226E3AB9e5dCC9);
}

/// @dev Deploys the v2 core dependencies.
// TODO: Remove this function once the v2 core contracts are deployed on Mainnet.
function deployDependencies() private {
(, lockupDynamic, lockupLinear,) = new V2CorePrecompiles().deployCore(users.admin);
}
}
Loading

0 comments on commit 0d99298

Please sign in to comment.