Skip to content

Commit

Permalink
feat(dock-registry): add deterministic deployment and Makefile shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielstoica committed Aug 5, 2024
1 parent b3cd6bd commit 24dbde2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ deploy-deterministic-module-keeper:
$(CREATE2SALT) {INITIAL_OWNER} \
--sig "run(string,address)" --rpc-url {RPC_URL} \
--private-key $(PRIVATE_KEY) --etherscan-api-key $(ETHERSCAN_API_KEY) \
--broadcast --verify

# Deploy the {DockRegistry} contract deterministically
# Update the following configs before running the script:
# - {INITIAL_OWNER} with the address of the initial owner
# - {MODULE_KEEPER} with the address of the {ModuleKeeper} deployment
# - {RPC_URL} with the network RPC used for deployment
deploy-deterministic-dock-registry:
forge script script/DeployDeterministicDockRegistry.s.sol:DeployDeterministicDockRegistry \
$(CREATE2SALT) {INITIAL_OWNER} {MODULE_KEEPER} \
--sig "run(string,address,address)" --rpc-url {RPC_URL} \
--private-key $(PRIVATE_KEY) --etherscan-api-key $(ETHERSCAN_API_KEY) \
--broadcast --verify
23 changes: 23 additions & 0 deletions script/DeployDeterministicDockRegistry.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.26;

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

/// @notice Deploys at deterministic addresses across chains an instance of {DockRegistry}
/// @dev Reverts if any contract has already been deployed
contract DeployDeterministicDockRegistry is BaseScript {
/// @dev By using a salt, Forge will deploy the contract via a deterministic CREATE2 factory
/// https://book.getfoundry.sh/tutorials/create2-tutorial?highlight=deter#deterministic-deployment-using-create2
function run(
string memory create2Salt,
address initialOwner,
ModuleKeeper moduleKeeper
) public virtual broadcast returns (DockRegistry dockRegistry) {
bytes32 salt = bytes32(abi.encodePacked(create2Salt));

// Deterministically deploy a {DockRegistry} contract
dockRegistry = new DockRegistry{ salt: salt }(initialOwner, moduleKeeper);
}
}

0 comments on commit 24dbde2

Please sign in to comment.