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

Inherit SablierV2Blast in Batch and Factory #341

Merged
merged 5 commits into from
May 4, 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
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": "5.0.2",
"@prb/math": "github:PaulRBerg/prb-math#16419e5686504e15f973ebe73c3a75bd618d6ca4",
"@sablier/v2-core": "github:sablier-labs/v2-core#c3ac0afe12fd3218c14f277a15ae4d8fd17e751d"
"@sablier/v2-core": "github:sablier-labs/v2-core#58fe2b247c202985b6f996a4eb9ca4c22a9d8f19"
},
"devDependencies": {
"@sphinx-labs/plugins": "^0.31.9",
Expand Down
20 changes: 10 additions & 10 deletions precompiles/Precompiles.sol

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions script/Base.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity >=0.8.22 <0.9.0;

import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { Sphinx } from "@sphinx-labs/contracts/SphinxPlugin.sol";
import { IBlast, YieldMode, GasMode } from "@sablier/v2-core/src/interfaces/blast/IBlast.sol";
import { IERC20Rebasing } from "@sablier/v2-core/src/interfaces/blast/IERC20Rebasing.sol";

import { console2 } from "forge-std/src/console2.sol";
import { Script } from "forge-std/src/Script.sol";
Expand All @@ -13,6 +15,13 @@ contract BaseScript is Script, Sphinx {
using Strings for uint256;
using stdJson for string;

/// @dev Blast mainnet configuration variables.
IBlast public constant BLAST = IBlast(0x4300000000000000000000000000000000000002);
GasMode public constant GAS_MODE = GasMode.CLAIMABLE;
YieldMode public constant YIELD_MODE = YieldMode.CLAIMABLE;
IERC20Rebasing public constant WETH = IERC20Rebasing(0x4300000000000000000000000000000000000004);
IERC20Rebasing public constant USDB = IERC20Rebasing(0x4300000000000000000000000000000000000003);

/// @dev Included to enable compilation of the script without a $MNEMONIC environment variable.
string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk";

Expand Down
18 changes: 12 additions & 6 deletions script/DeployBatchLockup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ import { SablierV2BatchLockup } from "../src/SablierV2BatchLockup.sol";

contract DeployBatchLockup is BaseScript {
/// @dev Deploy via Forge.
function runBroadcast() public virtual broadcast returns (SablierV2BatchLockup batchLockup) {
batchLockup = _run();
function runBroadcast(address admin) public virtual broadcast returns (SablierV2BatchLockup batchLockup) {
batchLockup = _run(admin);
}

/// @dev Deploy via Sphinx.
function runSphinx() public virtual sphinx returns (SablierV2BatchLockup batchLockup) {
batchLockup = _run();
function runSphinx(address admin) public virtual sphinx returns (SablierV2BatchLockup batchLockup) {
batchLockup = _run(admin);
}

function _run() internal returns (SablierV2BatchLockup batchLockup) {
batchLockup = new SablierV2BatchLockup();
function _run(address admin) internal returns (SablierV2BatchLockup batchLockup) {
batchLockup = new SablierV2BatchLockup(msg.sender);

// Configure Blast mainnet yield and gas modes.
batchLockup.configureRebasingAsset({ asset: USDB, yieldMode: YIELD_MODE });
batchLockup.configureRebasingAsset({ asset: WETH, yieldMode: YIELD_MODE });
batchLockup.configureYieldAndGas({ blast: BLAST, yieldMode: YIELD_MODE, gasMode: GAS_MODE, governor: admin });
batchLockup.transferAdmin(admin);
}
}
18 changes: 12 additions & 6 deletions script/DeployDeterministicBatchLockup.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ import { SablierV2BatchLockup } from "../src/SablierV2BatchLockup.sol";
/// @dev Reverts if the contract has already been deployed.
contract DeployDeterministicBatchLockup is BaseScript {
/// @dev Deploy via Forge.
function runBroadcast() public virtual broadcast returns (SablierV2BatchLockup batchLockup) {
batchLockup = _run();
function runBroadcast(address admin) public virtual broadcast returns (SablierV2BatchLockup batchLockup) {
batchLockup = _run(admin);
}

/// @dev Deploy via Sphinx.
function runSphinx() public virtual sphinx returns (SablierV2BatchLockup batchLockup) {
batchLockup = _run();
function runSphinx(address admin) public virtual sphinx returns (SablierV2BatchLockup batchLockup) {
batchLockup = _run(admin);
}

function _run() internal returns (SablierV2BatchLockup batchLockup) {
function _run(address admin) internal returns (SablierV2BatchLockup batchLockup) {
bytes32 salt = constructCreate2Salt();
batchLockup = new SablierV2BatchLockup{ salt: salt }();

// Configure Blast mainnet yield and gas modes.
batchLockup = new SablierV2BatchLockup{ salt: salt }(msg.sender);
batchLockup.configureRebasingAsset({ asset: USDB, yieldMode: YIELD_MODE });
batchLockup.configureRebasingAsset({ asset: WETH, yieldMode: YIELD_MODE });
batchLockup.configureYieldAndGas({ blast: BLAST, yieldMode: YIELD_MODE, gasMode: GAS_MODE, governor: admin });
batchLockup.transferAdmin(admin);
}
}
33 changes: 26 additions & 7 deletions script/DeployDeterministicPeriphery.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,50 @@ import { SablierV2MerkleLockupFactory } from "../src/SablierV2MerkleLockupFactor
/// @dev Reverts if any contract has already been deployed.
contract DeployDeterministicPeriphery is BaseScript {
/// @dev Deploy via Forge.
function runBroadcast()
function runBroadcast(address admin)
public
virtual
broadcast
returns (SablierV2BatchLockup batchLockup, SablierV2MerkleLockupFactory merkleLockupFactory)
{
(batchLockup, merkleLockupFactory) = _run();
(batchLockup, merkleLockupFactory) = _run(admin);
}

/// @dev Deploy via Sphinx.
function runSphinx()
function runSphinx(address admin)
public
virtual
sphinx
returns (SablierV2BatchLockup batchLockup, SablierV2MerkleLockupFactory merkleLockupFactory)
{
(batchLockup, merkleLockupFactory) = _run();
(batchLockup, merkleLockupFactory) = _run(admin);
}

function _run()
function _run(address admin)
internal
returns (SablierV2BatchLockup batchLockup, SablierV2MerkleLockupFactory merkleLockupFactory)
{
bytes32 salt = constructCreate2Salt();
batchLockup = new SablierV2BatchLockup{ salt: salt }();
merkleLockupFactory = new SablierV2MerkleLockupFactory{ salt: salt }();

batchLockup = new SablierV2BatchLockup{ salt: salt }(msg.sender);

// Configure Blast mainnet yield and gas modes.
batchLockup.configureRebasingAsset({ asset: USDB, yieldMode: YIELD_MODE });
batchLockup.configureRebasingAsset({ asset: WETH, yieldMode: YIELD_MODE });
batchLockup.configureYieldAndGas({ blast: BLAST, yieldMode: YIELD_MODE, gasMode: GAS_MODE, governor: admin });
batchLockup.transferAdmin(admin);

merkleLockupFactory = new SablierV2MerkleLockupFactory{ salt: salt }(msg.sender);

// Configure Blast mainnet yield and gas modes.
merkleLockupFactory.configureRebasingAsset({ asset: USDB, yieldMode: YIELD_MODE });
merkleLockupFactory.configureRebasingAsset({ asset: WETH, yieldMode: YIELD_MODE });
merkleLockupFactory.configureYieldAndGas({
blast: BLAST,
yieldMode: YIELD_MODE,
gasMode: GAS_MODE,
governor: admin
});
merkleLockupFactory.transferAdmin(admin);
}
}
33 changes: 27 additions & 6 deletions script/DeployMerkleLockupFactory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,37 @@ import { SablierV2MerkleLockupFactory } from "../src/SablierV2MerkleLockupFactor

contract DeployMerkleLockupFactory is BaseScript {
/// @dev Deploy via Forge.
function runBroadcast() public virtual broadcast returns (SablierV2MerkleLockupFactory merkleLockupFactory) {
merkleLockupFactory = _run();
function runBroadcast(address admin)
public
virtual
broadcast
returns (SablierV2MerkleLockupFactory merkleLockupFactory)
{
merkleLockupFactory = _run(admin);
}

/// @dev Deploy via Sphinx.
function runSphinx() public virtual sphinx returns (SablierV2MerkleLockupFactory merkleLockupFactory) {
merkleLockupFactory = _run();
function runSphinx(address admin)
public
virtual
sphinx
returns (SablierV2MerkleLockupFactory merkleLockupFactory)
{
merkleLockupFactory = _run(admin);
}

function _run() internal returns (SablierV2MerkleLockupFactory merkleLockupFactory) {
merkleLockupFactory = new SablierV2MerkleLockupFactory();
function _run(address admin) internal returns (SablierV2MerkleLockupFactory merkleLockupFactory) {
merkleLockupFactory = new SablierV2MerkleLockupFactory(msg.sender);

// Configure Blast mainnet yield and gas modes.
merkleLockupFactory.configureRebasingAsset({ asset: USDB, yieldMode: YIELD_MODE });
merkleLockupFactory.configureRebasingAsset({ asset: WETH, yieldMode: YIELD_MODE });
merkleLockupFactory.configureYieldAndGas({
blast: BLAST,
yieldMode: YIELD_MODE,
gasMode: GAS_MODE,
governor: admin
});
merkleLockupFactory.transferAdmin(admin);
}
}
32 changes: 25 additions & 7 deletions script/DeployPeriphery.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,48 @@ import { SablierV2BatchLockup } from "../src/SablierV2BatchLockup.sol";
/// 2. {SablierV2MerkleLockupFactory}
contract DeployPeriphery is BaseScript {
/// @dev Deploy via Forge.
function runBroadcast()
function runBroadcast(address admin)
public
virtual
broadcast
returns (SablierV2BatchLockup batchLockup, SablierV2MerkleLockupFactory merkleLockupFactory)
{
(batchLockup, merkleLockupFactory) = _run();
(batchLockup, merkleLockupFactory) = _run(admin);
}

/// @dev Deploy via Sphinx.
function runSphinx()
function runSphinx(address admin)
public
virtual
sphinx
returns (SablierV2BatchLockup batchLockup, SablierV2MerkleLockupFactory merkleLockupFactory)
{
(batchLockup, merkleLockupFactory) = _run();
(batchLockup, merkleLockupFactory) = _run(admin);
}

function _run()
function _run(address admin)
internal
returns (SablierV2BatchLockup batchLockup, SablierV2MerkleLockupFactory merkleLockupFactory)
{
batchLockup = new SablierV2BatchLockup();
merkleLockupFactory = new SablierV2MerkleLockupFactory();
batchLockup = new SablierV2BatchLockup(msg.sender);

// Configure Blast mainnet yield and gas modes.
batchLockup.configureRebasingAsset({ asset: USDB, yieldMode: YIELD_MODE });
batchLockup.configureRebasingAsset({ asset: WETH, yieldMode: YIELD_MODE });
batchLockup.configureYieldAndGas({ blast: BLAST, yieldMode: YIELD_MODE, gasMode: GAS_MODE, governor: admin });
batchLockup.transferAdmin(admin);

merkleLockupFactory = new SablierV2MerkleLockupFactory(msg.sender);

// Configure Blast mainnet yield and gas modes.
merkleLockupFactory.configureRebasingAsset({ asset: USDB, yieldMode: YIELD_MODE });
merkleLockupFactory.configureRebasingAsset({ asset: WETH, yieldMode: YIELD_MODE });
merkleLockupFactory.configureYieldAndGas({
blast: BLAST,
yieldMode: YIELD_MODE,
gasMode: GAS_MODE,
governor: admin
});
merkleLockupFactory.transferAdmin(admin);
}
}
4 changes: 2 additions & 2 deletions script/DeployProtocol.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract DeployProtocol is BaseScript {
lockupTranched = new SablierV2LockupTranched(initialAdmin, nftDescriptor, maxTrancheCount);

// Deploy V2 Periphery.
batchLockup = new SablierV2BatchLockup();
merkleLockupFactory = new SablierV2MerkleLockupFactory();
batchLockup = new SablierV2BatchLockup(initialAdmin);
merkleLockupFactory = new SablierV2MerkleLockupFactory(initialAdmin);
}
}
14 changes: 13 additions & 1 deletion src/SablierV2BatchLockup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 { SablierV2Blast } from "@sablier/v2-core/src/abstracts/SablierV2Blast.sol";
import { ISablierV2LockupDynamic } from "@sablier/v2-core/src/interfaces/ISablierV2LockupDynamic.sol";
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
import { ISablierV2LockupTranched } from "@sablier/v2-core/src/interfaces/ISablierV2LockupTranched.sol";
Expand All @@ -14,9 +15,20 @@ import { BatchLockup } from "./types/DataTypes.sol";

/// @title SablierV2BatchLockup
/// @notice See the documentation in {ISablierV2BatchLockup}.
contract SablierV2BatchLockup is ISablierV2BatchLockup {
contract SablierV2BatchLockup is ISablierV2BatchLockup, SablierV2Blast {
using SafeERC20 for IERC20;

/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/

/// @dev Emits a {TransferAdmin} event.
/// @param initialAdmin The address of the initial contract admin.
constructor(address initialAdmin) {
admin = initialAdmin;
emit TransferAdmin({ oldAdmin: address(0), newAdmin: initialAdmin });
}

/*//////////////////////////////////////////////////////////////////////////
SABLIER-V2-LOCKUP-DYNAMIC
//////////////////////////////////////////////////////////////////////////*/
Expand Down
14 changes: 13 additions & 1 deletion src/SablierV2MerkleLockupFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity >=0.8.22;

import { uUNIT } from "@prb/math/src/UD2x18.sol";
import { SablierV2Blast } from "@sablier/v2-core/src/abstracts/SablierV2Blast.sol";
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
import { ISablierV2LockupTranched } from "@sablier/v2-core/src/interfaces/ISablierV2LockupTranched.sol";
import { LockupLinear } from "@sablier/v2-core/src/types/DataTypes.sol";
Expand All @@ -16,7 +17,18 @@ import { MerkleLockup, MerkleLT } from "./types/DataTypes.sol";

/// @title SablierV2MerkleLockupFactory
/// @notice See the documentation in {ISablierV2MerkleLockupFactory}.
contract SablierV2MerkleLockupFactory is ISablierV2MerkleLockupFactory {
contract SablierV2MerkleLockupFactory is ISablierV2MerkleLockupFactory, SablierV2Blast {
/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/

/// @dev Emits a {TransferAdmin} event.
/// @param initialAdmin The address of the initial contract admin.
constructor(address initialAdmin) {
admin = initialAdmin;
emit TransferAdmin({ oldAdmin: address(0), newAdmin: initialAdmin });
}

/*//////////////////////////////////////////////////////////////////////////
USER-FACING NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/ISablierV2BatchLockup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity >=0.8.22;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ISablierV2Blast } from "@sablier/v2-core/src/interfaces/blast/ISablierV2Blast.sol";
import { ISablierV2LockupDynamic } from "@sablier/v2-core/src/interfaces/ISablierV2LockupDynamic.sol";
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
import { ISablierV2LockupTranched } from "@sablier/v2-core/src/interfaces/ISablierV2LockupTranched.sol";
Expand All @@ -10,7 +11,7 @@ import { BatchLockup } from "../types/DataTypes.sol";

/// @title ISablierV2BatchLockup
/// @notice Helper to batch create Sablier V2 Lockup streams.
interface ISablierV2BatchLockup {
interface ISablierV2BatchLockup is ISablierV2Blast {
/*//////////////////////////////////////////////////////////////////////////
SABLIER-V2-LOCKUP-LINEAR
//////////////////////////////////////////////////////////////////////////*/
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/ISablierV2MerkleLockupFactory.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22;

import { ISablierV2Blast } from "@sablier/v2-core/src/interfaces/blast/ISablierV2Blast.sol";
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
import { ISablierV2LockupTranched } from "@sablier/v2-core/src/interfaces/ISablierV2LockupTranched.sol";
import { LockupLinear } from "@sablier/v2-core/src/types/DataTypes.sol";
Expand All @@ -11,7 +12,7 @@ import { MerkleLockup, MerkleLT } from "../types/DataTypes.sol";

/// @title ISablierV2MerkleLockupFactory
/// @notice Deploys MerkleLockup campaigns with CREATE.
interface ISablierV2MerkleLockupFactory {
interface ISablierV2MerkleLockupFactory is ISablierV2Blast {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////////////////*/
Expand Down
6 changes: 3 additions & 3 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ abstract contract Base_Test is
/// @dev Conditionally deploy V2 Periphery normally or from an optimized source compiled with `--via-ir`.
function deployPeripheryConditionally() internal {
if (!isTestOptimizedProfile()) {
batchLockup = new SablierV2BatchLockup();
merkleLockupFactory = new SablierV2MerkleLockupFactory();
batchLockup = new SablierV2BatchLockup(users.admin);
merkleLockupFactory = new SablierV2MerkleLockupFactory(users.admin);
} else {
(batchLockup, merkleLockupFactory) = deployOptimizedPeriphery();
(batchLockup, merkleLockupFactory) = deployOptimizedPeriphery(users.admin);
}
}

Expand Down
22 changes: 22 additions & 0 deletions test/integration/batch-lockup/constructor/constructor.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22 <0.9.0;

import { SablierV2BatchLockup } from "src/SablierV2BatchLockup.sol";

import { Integration_Test } from "../../Integration.t.sol";

contract Constructor_BatchLockup_Integration_Test is Integration_Test {
function setUp() public virtual override {
Integration_Test.setUp();
}

function test_Constructor() external {
vm.expectEmit();
emit TransferAdmin({ oldAdmin: address(0), newAdmin: users.admin });
SablierV2BatchLockup batchLockup = new SablierV2BatchLockup(users.admin);

address actualAdmin = batchLockup.admin();
address expectedAdmin = users.admin;
assertEq(actualAdmin, expectedAdmin, "admin mismatch");
}
}
Loading
Loading