Skip to content

Commit

Permalink
feat(evm): implement deploy scripts for core contracts
Browse files Browse the repository at this point in the history
The boost core and registry modules can now be deployed with a single
command. A local npm script is included for local testing
  • Loading branch information
topocount committed Sep 10, 2024
1 parent 87f0cf2 commit 92579c3
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ docs
cache
docs
.boost

# don't commit local testnet deploys
packages/evm/deploys/31337.json
2 changes: 2 additions & 0 deletions packages/evm/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
TEST_SIGNER_PRIVATE_KEY=
BOOST_FEE_RECIPIENT=
BOOST_DEPLOYMENT_SALT=
Empty file added packages/evm/deploys/.gitkeep
Empty file.
3 changes: 2 additions & 1 deletion packages/evm/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ optimizer_runs = 10_000
out = 'out'
src = 'contracts'
test = 'test'
script = 'script/solidity'
cache_path = 'cache_forge'
libs = ['node_modules', 'lib']
solc_version = '0.8.26'
evm_version = 'cancun'

fs_permissions = [{access = "write", path = "./deploys"}]
remappings=[
'@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/',
'@openzeppelin-upgrades/contracts/=lib/openzeppelin-contracts-upgradeable/contracts/',
Expand Down
4 changes: 3 additions & 1 deletion packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"clean": "forge clean && hardhat clean && rm -rf cache",
"test": "forge test -vvv && hardhat test",
"test:ci": "forge test --summary --detailed -vvv && hardhat test",
"coverage": "forge coverage --report lcov --report-file coverage/lcov.info"
"coverage": "forge coverage --report lcov --report-file coverage/lcov.info",
"deploy:local": "forge script script/solidity/Deploy.s.sol:Deployer -f http://127.0.0.1:8545 --broadcast --mnemonics \"test test test test test test test test test test test junk\"",
"anvil": "anvil"
},
"keywords": [],
"license": "GPL-3.0-or-later",
Expand Down
79 changes: 79 additions & 0 deletions packages/evm/script/solidity/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.24;

import "forge-std/Script.sol";

import {BoostCore} from "contracts/BoostCore.sol";
import {BoostRegistry} from "contracts/BoostRegistry.sol";

contract Deployer is Script {

address BOOST_FEE_RECIPIENT;

function setUp() external {
BOOST_FEE_RECIPIENT = vm.envAddress("BOOST_FEE_RECIPIENT");
}

function run() public {
// 1. Deploy Boost registry
address registry = _deployRegistry();
address core = _deployCore(registry);
_saveDeployments(registry, core);
}

function _deployRegistry() internal returns (address registry) {
bytes memory initCode = type(BoostRegistry).creationCode;
registry = _getCreate2Address(initCode, "");
console.log("BoostRegistry: ", registry);
_deploy2(initCode, "");
}

function _deployCore(address registry) internal returns (address core) {
bytes memory initCode = type(BoostCore).creationCode;
bytes memory constructorArgs = abi.encode(registry, BOOST_FEE_RECIPIENT);
core = _getCreate2Address(initCode, constructorArgs);
console.log("BoostCore: ", core);
_deploy2(initCode, constructorArgs);
}

function _getCreate2Address(
bytes memory creationCode,
bytes memory args
) internal view returns (address) {
bytes32 salt = keccak256(bytes(vm.envString("BOOST_DEPLOYMENT_SALT")));
bytes32 codeHash = hashInitCode(creationCode, args);
return vm.computeCreate2Address(salt, codeHash);
}

function _deploy2(
bytes memory deployCode,
bytes memory args
) internal {
bytes32 salt = keccak256(bytes(vm.envString("BOOST_DEPLOYMENT_SALT")));
bytes memory payload = abi.encodePacked(salt, deployCode, args);
// deploy using address configured at the CLI level
vm.broadcast();
(bool success, ) = CREATE2_FACTORY.call(payload);
if (!success) revert("create2 failed");
}

function _saveDeployments(address registry, address core) internal {
string memory deployKey = "deployments";

vm.serializeAddress(deployKey, "BoostRegistry", registry);
string memory finalJson = vm.serializeAddress(deployKey, "BoostCore", core);
vm.writeJson(
finalJson,
string(
abi.encodePacked(
vm.projectRoot(),
"/deploys/",
vm.toString(block.chainid),
".json"
)
)
);
}

}

0 comments on commit 92579c3

Please sign in to comment.