Skip to content

Commit

Permalink
feat: add protocol scripts (#1049)
Browse files Browse the repository at this point in the history
feat: create a markdown deployment file with docs structure
build: remove problematic etherscan fields
  • Loading branch information
andreivladbrg authored Oct 11, 2024
1 parent da4c076 commit a322ba6
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 89 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ out-svg
lcov.info
package-lock.json
pnpm-lock.yaml
script/protocol/*.md
yarn.lock
7 changes: 1 addition & 6 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{ access = "read", path = "./out-optimized" },
{ access = "read", path = "package.json" },
{ access = "read-write", path = "./benchmark/results" },
{ access = "read-write", path = "./script/protocol"}
]
gas_limit = 9223372036854775807
optimizer = true
Expand Down Expand Up @@ -88,22 +89,16 @@
avalanche = { key = "${SNOWTRACE_API_KEY}" }
base = { key = "${BASESCAN_API_KEY}" }
base_sepolia = { key = "${BASESCAN_API_KEY}" }
berachain_artio = { key = "verifyContract", url = "https://api.routescan.io/v2/network/testnet/evm/80085/etherscan" }
bnb = { key = "${BSCSCAN_API_KEY}" }
gnosis = { key = "${GNOSISSCAN_API_KEY}" }
linea = { key = "${LINEASCAN_API_KEY}" }
linea_sepolia = { key = "${LINEASCAN_API_KEY}" }
mainnet = { key = "${ETHERSCAN_API_KEY}" }
mode = { key = "verifyContract", url = "https://explorer.mode.network/api?" }
mode_sepolia = { key = "verifyContract", url = "https://sepolia.explorer.mode.network/api?" }
optimism = { key = "${OPTIMISTIC_API_KEY}" }
optimism_sepolia = { key = "${OPTIMISTIC_API_KEY}" }
polygon = { key = "${POLYGONSCAN_API_KEY}" }
scroll = { key = "${SCROLLSCAN_API_KEY}" }
sei = { key = "verifyContract", url = "https://seitrace/pacific-1/api?" }
sei_testnet = { key = "verifyContract", url = "https://blockscout.com/poa/core/api?" }
sepolia = { key = "${SEPOLIASCAN_KEY}" }
taiko_hekla = { key = "verifyContract", url = "https://blockscoutapi.hekla.taiko.xyz/api?" }
taiko_mainnet = { key = "${TAIKO_MAINNET_API_KEY}" }

[fmt]
Expand Down
10 changes: 7 additions & 3 deletions script/Base.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,20 @@ contract BaseScript is Script {
///
/// Notes:
/// - The salt format is "ChainID <chainid>, Version <version>".
/// - The version is obtained from `package.json`.
function constructCreate2Salt() public view returns (bytes32) {
string memory chainId = block.chainid.toString();
string memory json = vm.readFile("package.json");
string memory version = json.readString(".version");
string memory version = getVersion();
string memory create2Salt = string.concat("ChainID ", chainId, ", Version ", version);
console2.log("The CREATE2 salt is \"%s\"", create2Salt);
return bytes32(abi.encodePacked(create2Salt));
}

/// @dev The version is obtained from `package.json`.
function getVersion() internal view returns (string memory) {
string memory json = vm.readFile("package.json");
return json.readString(".version");
}

/// @dev Populates the segment & tranche count map. Values can be updated using the `update-counts.sh` script.
function populateSegmentAndTrancheCountMap() internal {
// forgefmt: disable-start
Expand Down
42 changes: 0 additions & 42 deletions script/DeployDeterministicProtocol.s.sol

This file was deleted.

38 changes: 0 additions & 38 deletions script/DeployProtocol.s.sol

This file was deleted.

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

import { LockupNFTDescriptor } from "../../src/core/LockupNFTDescriptor.sol";
import { SablierLockupDynamic } from "../../src/core/SablierLockupDynamic.sol";
import { SablierLockupLinear } from "../../src/core/SablierLockupLinear.sol";
import { SablierLockupTranched } from "../../src/core/SablierLockupTranched.sol";
import { SablierMerkleFactory } from "../../src/periphery/SablierMerkleFactory.sol";
import { SablierBatchLockup } from "../../src/periphery/SablierBatchLockup.sol";

import { DeploymentLogger } from "./DeploymentLogger.s.sol";

/// @notice Deploys the Lockup Protocol at deterministic addresses across chains.
contract DeployDeterministicProtocol is DeploymentLogger("deterministic") {
/// @dev Deploys the protocol with the admin set in `adminMap`.
function run()
public
virtual
broadcast
returns (
LockupNFTDescriptor nftDescriptor,
SablierLockupDynamic lockupDynamic,
SablierLockupLinear lockupLinear,
SablierLockupTranched lockupTranched,
SablierBatchLockup batchLockup,
SablierMerkleFactory merkleLockupFactory
)
{
address initialAdmin = adminMap[block.chainid];

(nftDescriptor, lockupDynamic, lockupLinear, lockupTranched, batchLockup, merkleLockupFactory) =
_run(initialAdmin);
}

/// @dev Deploys the protocol with the given `initialAdmin`.
function run(address initialAdmin)
internal
returns (
LockupNFTDescriptor nftDescriptor,
SablierLockupDynamic lockupDynamic,
SablierLockupLinear lockupLinear,
SablierLockupTranched lockupTranched,
SablierBatchLockup batchLockup,
SablierMerkleFactory merkleLockupFactory
)
{
(nftDescriptor, lockupDynamic, lockupLinear, lockupTranched, batchLockup, merkleLockupFactory) =
_run(initialAdmin);
}

/// @dev Common logic for the run functions.
function _run(address initialAdmin)
internal
returns (
LockupNFTDescriptor nftDescriptor,
SablierLockupDynamic lockupDynamic,
SablierLockupLinear lockupLinear,
SablierLockupTranched lockupTranched,
SablierBatchLockup batchLockup,
SablierMerkleFactory merkleLockupFactory
)
{
bytes32 salt = constructCreate2Salt();

// Deploy Core.
nftDescriptor = new LockupNFTDescriptor{ salt: salt }();
lockupDynamic =
new SablierLockupDynamic{ salt: salt }(initialAdmin, nftDescriptor, segmentCountMap[block.chainid]);
lockupLinear = new SablierLockupLinear{ salt: salt }(initialAdmin, nftDescriptor);
lockupTranched =
new SablierLockupTranched{ salt: salt }(initialAdmin, nftDescriptor, trancheCountMap[block.chainid]);

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

appendToFileDeployedAddresses(
address(lockupDynamic),
address(lockupLinear),
address(lockupTranched),
address(nftDescriptor),
address(batchLockup),
address(merkleLockupFactory)
);
}
}
79 changes: 79 additions & 0 deletions script/protocol/DeployProtocol.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22 <0.9.0;

import { LockupNFTDescriptor } from "../../src/core/LockupNFTDescriptor.sol";
import { SablierLockupDynamic } from "../../src/core/SablierLockupDynamic.sol";
import { SablierLockupLinear } from "../../src/core/SablierLockupLinear.sol";
import { SablierLockupTranched } from "../../src/core/SablierLockupTranched.sol";
import { SablierMerkleFactory } from "../../src/periphery/SablierMerkleFactory.sol";
import { SablierBatchLockup } from "../../src/periphery/SablierBatchLockup.sol";

import { DeploymentLogger } from "./DeploymentLogger.s.sol";

/// @notice Deploys the Lockup Protocol.
contract DeployProtocol is DeploymentLogger("non_deterministic") {
/// @dev Deploys the protocol with the admin set in `adminMap`.
function run()
public
virtual
broadcast
returns (
LockupNFTDescriptor nftDescriptor,
SablierLockupDynamic lockupDynamic,
SablierLockupLinear lockupLinear,
SablierLockupTranched lockupTranched,
SablierBatchLockup batchLockup,
SablierMerkleFactory merkleLockupFactory
)
{
address initialAdmin = adminMap[block.chainid];

(nftDescriptor, lockupDynamic, lockupLinear, lockupTranched, batchLockup, merkleLockupFactory) =
_run(initialAdmin);
}

/// @dev Deploys the protocol with the given `initialAdmin`.
function run(address initialAdmin)
internal
returns (
LockupNFTDescriptor nftDescriptor,
SablierLockupDynamic lockupDynamic,
SablierLockupLinear lockupLinear,
SablierLockupTranched lockupTranched,
SablierBatchLockup batchLockup,
SablierMerkleFactory merkleLockupFactory
)
{
(nftDescriptor, lockupDynamic, lockupLinear, lockupTranched, batchLockup, merkleLockupFactory) =
_run(initialAdmin);
}

/// @dev Common logic for the run functions.
function _run(address initialAdmin)
internal
returns (
LockupNFTDescriptor nftDescriptor,
SablierLockupDynamic lockupDynamic,
SablierLockupLinear lockupLinear,
SablierLockupTranched lockupTranched,
SablierBatchLockup batchLockup,
SablierMerkleFactory merkleLockupFactory
)
{
nftDescriptor = new LockupNFTDescriptor();
lockupDynamic = new SablierLockupDynamic(initialAdmin, nftDescriptor, segmentCountMap[block.chainid]);
lockupLinear = new SablierLockupLinear(initialAdmin, nftDescriptor);
lockupTranched = new SablierLockupTranched(initialAdmin, nftDescriptor, trancheCountMap[block.chainid]);
batchLockup = new SablierBatchLockup();
merkleLockupFactory = new SablierMerkleFactory();

appendToFileDeployedAddresses(
address(lockupDynamic),
address(lockupLinear),
address(lockupTranched),
address(nftDescriptor),
address(batchLockup),
address(merkleLockupFactory)
);
}
}
Loading

0 comments on commit a322ba6

Please sign in to comment.