Skip to content

Commit

Permalink
refactor: move batch lockup contract in core
Browse files Browse the repository at this point in the history
refactor: remove deploy periphery scripts
refactor: update scripts accordingly
chore: add SALT as immutable in BaseScript
test: move batch lockup tests in core
  • Loading branch information
andreivladbrg committed Nov 14, 2024
1 parent 5d48595 commit 3813020
Show file tree
Hide file tree
Showing 44 changed files with 352 additions and 413 deletions.
57 changes: 25 additions & 32 deletions precompiles/Precompiles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
pragma solidity >=0.8.22;

import { ILockupNFTDescriptor } from "./../src/core/interfaces/ILockupNFTDescriptor.sol";
import { ISablierBatchLockup } from "./../src/core/interfaces/ISablierBatchLockup.sol";
import { ISablierLockup } from "./../src/core/interfaces/ISablierLockup.sol";
import { LockupNFTDescriptor } from "./../src/core/LockupNFTDescriptor.sol";
import { ISablierBatchLockup } from "./../src/periphery/interfaces/ISablierBatchLockup.sol";
import { ISablierMerkleFactory } from "./../src/periphery/interfaces/ISablierMerkleFactory.sol";

/// @notice This is useful for external integrations seeking to test against the exact deployed bytecode, as recompiling
Expand Down Expand Up @@ -33,6 +33,25 @@ contract Precompiles {
CORE
//////////////////////////////////////////////////////////////////////////*/

/// @notice Deploys {SablierBatchLockup} from precompiled bytecode.
function deployBatchLockup() public returns (ISablierBatchLockup batchLockup) {
bytes memory creationBytecode = BYTECODE_BATCH_LOCKUP;
assembly {
batchLockup := create(0, add(creationBytecode, 0x20), mload(creationBytecode))
}
require(address(batchLockup) != address(0), "Lockup Precompiles: deployment failed for BatchLockup contract");
}

/// @notice Deploys all Core contracts.
function deployCore(address initialAdmin)
public
returns (ILockupNFTDescriptor nftDescriptor, ISablierLockup lockup, ISablierBatchLockup batchLockup)
{
nftDescriptor = deployNFTDescriptor();
lockup = deployLockup(initialAdmin);
batchLockup = deployBatchLockup();
}

/// @notice Deploys {SablierLockup} from precompiled bytecode, passing a default value for the `maxCount` parameter.
/// @dev Notes:
/// - A default value is passed for `maxCount`.
Expand Down Expand Up @@ -87,28 +106,10 @@ contract Precompiles {
);
}

/// @notice Deploys all Core contracts.
function deployCore(address initialAdmin)
public
returns (ILockupNFTDescriptor nftDescriptor, ISablierLockup lockup)
{
nftDescriptor = deployNFTDescriptor();
lockup = deployLockup(initialAdmin);
}

/*//////////////////////////////////////////////////////////////////////////
PERIPHERY
//////////////////////////////////////////////////////////////////////////*/

/// @notice Deploys {SablierBatchLockup} from precompiled bytecode.
function deployBatchLockup() public returns (ISablierBatchLockup batchLockup) {
bytes memory creationBytecode = BYTECODE_BATCH_LOCKUP;
assembly {
batchLockup := create(0, add(creationBytecode, 0x20), mload(creationBytecode))
}
require(address(batchLockup) != address(0), "Lockup Precompiles: deployment failed for BatchLockup contract");
}

/// @notice Deploys {SablierMerkleFactory} from precompiled bytecode.
function deployMerkleFactory(address initialAdmin) public returns (ISablierMerkleFactory factory) {
bytes memory creationBytecode = bytes.concat(BYTECODE_MERKLE_FACTORY, abi.encode(initialAdmin));
Expand All @@ -118,17 +119,9 @@ contract Precompiles {
require(address(factory) != address(0), "Lockup Precompiles: deployment failed for MerkleFactory contract");
}

/// @notice Deploys all Periphery contracts in the following order:
///
/// 1. {SablierBatchLockup}
/// 2. {SablierMerkleFactory}
function deployPeriphery(address initialAdmin)
public
returns (ISablierBatchLockup batchLockup, ISablierMerkleFactory merkleFactory)
{
batchLockup = deployBatchLockup();
merkleFactory = deployMerkleFactory(initialAdmin);
}
/*//////////////////////////////////////////////////////////////////////////
PROTOCOL
//////////////////////////////////////////////////////////////////////////*/

/// @notice Deploys the entire Lockup Protocol from precompiled bytecode.
///
Expand All @@ -146,9 +139,9 @@ contract Precompiles {
)
{
// Deploy Core.
(nftDescriptor, lockup) = deployCore(initialAdmin);
(nftDescriptor, lockup, batchLockup) = deployCore(initialAdmin);

// Deploy Periphery.
(batchLockup, merkleFactory) = deployPeriphery(initialAdmin);
merkleFactory = deployMerkleFactory(initialAdmin);
}
}
9 changes: 6 additions & 3 deletions script/Base.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ contract BaseScript is Script {
/// @dev The default value for `maxCountMap`.
uint256 internal constant DEFAULT_MAX_COUNT = 500;

/// @dev The salt used for deterministic deployments.
bytes32 internal immutable SALT;

/// @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";

/// @dev Needed for the deterministic deployments.
bytes32 internal constant ZERO_SALT = bytes32(0);

/// @dev The address of the transaction broadcaster.
address internal broadcaster;

Expand All @@ -46,6 +46,9 @@ contract BaseScript is Script {
(broadcaster,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 });
}

// Construct the salt for deterministic deployments.
SALT = constructCreate2Salt();

// Populate the max count map for segments and tranches.
populateMaxCountMap();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22 <0.9.0;

import { SablierBatchLockup } from "../../src/periphery/SablierBatchLockup.sol";
import { SablierBatchLockup } from "../../src/core/SablierBatchLockup.sol";

import { BaseScript } from "../Base.s.sol";

Expand Down
4 changes: 3 additions & 1 deletion script/core/DeployCore.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity >=0.8.22 <0.9.0;

import { LockupNFTDescriptor } from "../../src/core/LockupNFTDescriptor.sol";
import { SablierBatchLockup } from "./../../src/core/SablierBatchLockup.sol";
import { SablierLockup } from "../../src/core/SablierLockup.sol";

import { BaseScript } from "../Base.s.sol";
Expand All @@ -12,9 +13,10 @@ contract DeployCore is BaseScript {
public
virtual
broadcast
returns (LockupNFTDescriptor nftDescriptor, SablierLockup lockup)
returns (LockupNFTDescriptor nftDescriptor, SablierLockup lockup, SablierBatchLockup batchLockup)
{
nftDescriptor = new LockupNFTDescriptor();
lockup = new SablierLockup(initialAdmin, nftDescriptor, maxCountMap[block.chainid]);
batchLockup = new SablierBatchLockup();
}
}
13 changes: 13 additions & 0 deletions script/core/DeployDeterministicBatchLockup.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22 <0.9.0;

import { SablierBatchLockup } from "../../src/core/SablierBatchLockup.sol";

import { BaseScript } from "../Base.s.sol";

contract DeployDeterministicBatchLockup is BaseScript {
/// @dev Deploy via Forge.
function run() public virtual broadcast returns (SablierBatchLockup batchLockup) {
batchLockup = new SablierBatchLockup();
}
}
9 changes: 5 additions & 4 deletions script/core/DeployDeterministicCore.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity >=0.8.22 <0.9.0;

import { LockupNFTDescriptor } from "../../src/core/LockupNFTDescriptor.sol";
import { SablierBatchLockup } from "./../../src/core/SablierBatchLockup.sol";
import { SablierLockup } from "../../src/core/SablierLockup.sol";
import { BaseScript } from "../Base.s.sol";

Expand All @@ -12,10 +13,10 @@ contract DeployDeterministicCore is BaseScript {
public
virtual
broadcast
returns (LockupNFTDescriptor nftDescriptor, SablierLockup lockup)
returns (LockupNFTDescriptor nftDescriptor, SablierLockup lockup, SablierBatchLockup batchLockup)
{
bytes32 salt = constructCreate2Salt();
nftDescriptor = new LockupNFTDescriptor{ salt: salt }();
lockup = new SablierLockup{ salt: salt }(initialAdmin, nftDescriptor, maxCountMap[block.chainid]);
nftDescriptor = new LockupNFTDescriptor{ salt: SALT }();
lockup = new SablierLockup{ salt: SALT }(initialAdmin, nftDescriptor, maxCountMap[block.chainid]);
batchLockup = new SablierBatchLockup{ salt: SALT }();
}
}
3 changes: 1 addition & 2 deletions script/core/DeployDeterministicLockup.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ contract DeployDeterministicLockup is BaseScript {
broadcast
returns (SablierLockup lockup)
{
bytes32 salt = constructCreate2Salt();
lockup = new SablierLockup{ salt: salt }(initialAdmin, nftDescriptor, maxCountMap[block.chainid]);
lockup = new SablierLockup{ salt: SALT }(initialAdmin, nftDescriptor, maxCountMap[block.chainid]);
}
}
3 changes: 1 addition & 2 deletions script/core/DeployDeterministicNFTDescriptor.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { BaseScript } from "../Base.s.sol";
/// @dev Reverts if the contract has already been deployed.
contract DeployDeterministicNFTDescriptor is BaseScript {
function run() public virtual broadcast returns (LockupNFTDescriptor nftDescriptor) {
bytes32 salt = constructCreate2Salt();
nftDescriptor = new LockupNFTDescriptor{ salt: salt }();
nftDescriptor = new LockupNFTDescriptor{ salt: SALT }();
}
}
16 changes: 0 additions & 16 deletions script/periphery/DeployDeterministicBatchLockup.s.sol

This file was deleted.

15 changes: 15 additions & 0 deletions script/periphery/DeployDeterministicMerkleFactory.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22 <0.9.0;

import { SablierMerkleFactory } from "../../src/periphery/SablierMerkleFactory.sol";

import { BaseScript } from "../Base.s.sol";

/// @dev Deploys {SablierMerkleFactory} at a deterministic address across chains.
/// @dev Reverts if the contract has already been deployed.
contract DeployDeterministicMerkleFactory is BaseScript {
/// @dev Deploy via Forge.
function run(address initialAdmin) public virtual broadcast returns (SablierMerkleFactory merkleFactory) {
merkleFactory = new SablierMerkleFactory{ salt: SALT }(initialAdmin);
}
}
27 changes: 0 additions & 27 deletions script/periphery/DeployDeterministicPeriphery.s.sol

This file was deleted.

23 changes: 0 additions & 23 deletions script/periphery/DeployPeriphery.s.sol

This file was deleted.

19 changes: 8 additions & 11 deletions script/protocol/DeployDeterministicProtocol.s.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22 <0.9.0;

import { LockupNFTDescriptor } from "../../src/core/LockupNFTDescriptor.sol";
import { SablierLockup } from "../../src/core/SablierLockup.sol";
import { SablierBatchLockup } from "../../src/periphery/SablierBatchLockup.sol";
import { SablierMerkleFactory } from "../../src/periphery/SablierMerkleFactory.sol";

import { LockupNFTDescriptor } from "./../../src/core/LockupNFTDescriptor.sol";
import { SablierBatchLockup } from "./../../src/core/SablierBatchLockup.sol";
import { SablierLockup } from "./../../src/core/SablierLockup.sol";
import { SablierMerkleFactory } from "./../../src/periphery/SablierMerkleFactory.sol";
import { DeploymentLogger } from "./DeploymentLogger.s.sol";

/// @notice Deploys the Lockup Protocol at deterministic addresses across chains.
Expand Down Expand Up @@ -50,15 +49,13 @@ contract DeployDeterministicProtocol is DeploymentLogger("deterministic") {
SablierMerkleFactory merkleLockupFactory
)
{
bytes32 salt = constructCreate2Salt();

// Deploy Core.
nftDescriptor = new LockupNFTDescriptor{ salt: salt }();
lockup = new SablierLockup{ salt: salt }(initialAdmin, nftDescriptor, maxCountMap[block.chainid]);
nftDescriptor = new LockupNFTDescriptor{ salt: SALT }();
lockup = new SablierLockup{ salt: SALT }(initialAdmin, nftDescriptor, maxCountMap[block.chainid]);
batchLockup = new SablierBatchLockup{ salt: SALT }();

// Deploy Periphery.
batchLockup = new SablierBatchLockup{ salt: salt }();
merkleLockupFactory = new SablierMerkleFactory{ salt: salt }(initialAdmin);
merkleLockupFactory = new SablierMerkleFactory{ salt: SALT }(initialAdmin);

appendToFileDeployedAddresses(
address(lockup), address(nftDescriptor), address(batchLockup), address(merkleLockupFactory)
Expand Down
12 changes: 7 additions & 5 deletions script/protocol/DeployProtocol.s.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22 <0.9.0;

import { LockupNFTDescriptor } from "../../src/core/LockupNFTDescriptor.sol";
import { SablierLockup } from "../../src/core/SablierLockup.sol";
import { SablierBatchLockup } from "../../src/periphery/SablierBatchLockup.sol";
import { SablierMerkleFactory } from "../../src/periphery/SablierMerkleFactory.sol";

import { LockupNFTDescriptor } from "./../../src/core/LockupNFTDescriptor.sol";
import { SablierBatchLockup } from "./../../src/core/SablierBatchLockup.sol";
import { SablierLockup } from "./../../src/core/SablierLockup.sol";
import { SablierMerkleFactory } from "./../../src/periphery/SablierMerkleFactory.sol";
import { DeploymentLogger } from "./DeploymentLogger.s.sol";

/// @notice Deploys the Lockup Protocol.
Expand Down Expand Up @@ -50,9 +49,12 @@ contract DeployProtocol is DeploymentLogger("non_deterministic") {
SablierMerkleFactory merkleLockupFactory
)
{
// Deploy Core.
nftDescriptor = new LockupNFTDescriptor();
lockup = new SablierLockup(initialAdmin, nftDescriptor, maxCountMap[block.chainid]);
batchLockup = new SablierBatchLockup();

// Deploy Periphery.
merkleLockupFactory = new SablierMerkleFactory(initialAdmin);

appendToFileDeployedAddresses(
Expand Down
14 changes: 7 additions & 7 deletions script/protocol/DeploymentLogger.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ abstract contract DeploymentLogger is BaseScript {
string memory firstTwoLines = "| Contract | Address | Deployment |\n | :------- | :------ | :----------|";
_appendToFile(firstTwoLines);

string memory batchLockupLine = _getContractLine({
contractName: "SablierBatchLockup",
contractAddress: batchLockup.toHexString(),
coreOrPeriphery: "core"
});
_appendToFile(batchLockupLine);

string memory lockupLine = _getContractLine({
contractName: "SablierLockup",
contractAddress: lockup.toHexString(),
Expand All @@ -92,13 +99,6 @@ abstract contract DeploymentLogger is BaseScript {
_appendToFile(peripheryTitle);
_appendToFile(firstTwoLines);

string memory batchLockupLine = _getContractLine({
contractName: "SablierBatchLockup",
contractAddress: batchLockup.toHexString(),
coreOrPeriphery: "periphery"
});
_appendToFile(batchLockupLine);

string memory merkleFactoryLine = _getContractLine({
contractName: "MerkleFactory",
contractAddress: merkleFactory.toHexString(),
Expand Down
Loading

0 comments on commit 3813020

Please sign in to comment.