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 7506fcf
Show file tree
Hide file tree
Showing 44 changed files with 304 additions and 343 deletions.
2 changes: 1 addition & 1 deletion 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ 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 { ISablierLockup } from "../core/interfaces/ISablierLockup.sol";
import { Lockup } from "../core/types/DataTypes.sol";

import { ISablierBatchLockup } from "./interfaces/ISablierBatchLockup.sol";
import { ISablierLockup } from "./interfaces/ISablierLockup.sol";
import { Errors } from "./libraries/Errors.sol";
import { BatchLockup } from "./types/DataTypes.sol";
import { BatchLockup, Lockup } from "./types/DataTypes.sol";

/// @title SablierBatchLockup
/// @notice See the documentation in {ISablierBatchLockup}.
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions src/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ library Errors {
/// @notice Thrown when trying to delegate call to a function that disallows delegate calls.
error DelegateCall();

/*//////////////////////////////////////////////////////////////////////////
SABLIER-BATCH-LOCKUP
//////////////////////////////////////////////////////////////////////////*/

error SablierBatchLockup_BatchSizeZero();

/*//////////////////////////////////////////////////////////////////////////
LOCKUP-NFT-DESCRIPTOR
//////////////////////////////////////////////////////////////////////////*/
Expand Down
Loading

0 comments on commit 7506fcf

Please sign in to comment.