Skip to content

Commit

Permalink
CallBreaker deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
xBalbinus committed May 13, 2024
1 parent 78b5bee commit 653e5ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 58 deletions.
11 changes: 6 additions & 5 deletions script/BaseDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {Script} from "forge-std/Script.sol";

/* solhint-disable max-states-count */
contract BaseDeployer is Script {
bytes32 internal counterProxySalt;
bytes32 internal counterSalt;
bytes32 internal _counterProxySalt;
bytes32 internal _counterSalt;

uint256 internal deployerPrivateKey;
uint256 internal _deployerPrivateKey;

address internal ownerAddress;
address internal proxyCounterAddress;
address internal _ownerAddress;
address internal _proxyCounterAddress;

enum Chains {
LocalGoerli,
Expand Down Expand Up @@ -103,6 +103,7 @@ contract BaseDeployer is Script {
forks[Chains.OptimismGoerli] = "optimismgoerli";
forks[Chains.Moonriver] = "moonriver";
forks[Chains.Shiden] = "shiden";
// @TODO Add Base

// Mainnet
forks[Chains.Etherum] = "etherum";
Expand Down
73 changes: 20 additions & 53 deletions script/CallBreaker.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,23 @@
pragma solidity ^0.8.19;

import {Script} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
import {CallBreaker} from "../src/timetravel/CallBreaker.sol";

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

/* solhint-disable no-console*/
import {console2} from "forge-std/console2.sol";

contract DeployCounter is Script, BaseDeployer {
address private create2addrCounter;
address private create2addrProxy;
contract DeployCallBreaker is Script, BaseDeployer {
address private _create2addrCallBreaker;
CallBreaker private _callBreaker;

Counter private wrappedProxy;

/// @dev Compute the CREATE2 addresses for contracts (proxy, counter).
/// @param saltCounter The salt for the counter contract.
/// @param saltProxy The salt for the proxy contract.
modifier computeCreate2(bytes32 saltCounter, bytes32 saltProxy) {
create2addrCounter = computeCreate2Address(
saltCounter,
hashInitCode(type(Counter).creationCode)
);

create2addrProxy = computeCreate2Address(
saltProxy,
hashInitCode(
type(UUPSProxy).creationCode,
abi.encode(
create2addrCounter,
abi.encodeWithSelector(Counter.initialize.selector, ownerAddress)
)
)
/// @dev Compute the CREATE2 address for CallBreaker contract.
/// @param salt The salt for the CallBreaker contract.
modifier computeCreate2(bytes32 salt) {
_create2addrCallBreaker = computeCreate2Address(
salt,
hashInitCode(type(CallBreaker).creationCode)
);

_;
Expand All @@ -44,7 +30,6 @@ contract DeployCounter is Script, BaseDeployer {
Chains[] memory deployForks = new Chains[](8);

counterSalt = bytes32(uint256(10));
counterProxySalt = bytes32(uint256(11));

deployForks[0] = Chains.Etherum;
deployForks[1] = Chains.Polygon;
Expand All @@ -60,13 +45,11 @@ contract DeployCounter is Script, BaseDeployer {

/// @dev Deploy contracts to testnet.
function deployCounterTestnet(
uint256 _counterSalt,
uint256 _counterProxySalt
uint256 _counterSalt
) public setEnvDeploy(Cycle.Test) {
Chains[] memory deployForks = new Chains[](8);

counterSalt = bytes32(_counterSalt);
counterProxySalt = bytes32(_counterProxySalt);

deployForks[0] = Chains.Goerli;
deployForks[1] = Chains.Mumbai;
Expand All @@ -84,7 +67,6 @@ contract DeployCounter is Script, BaseDeployer {
function deployCounterLocal() external setEnvDeploy(Cycle.Dev) {
Chains[] memory deployForks = new Chains[](3);
counterSalt = bytes32(uint256(1));
counterProxySalt = bytes32(uint256(2));

deployForks[0] = Chains.LocalGoerli;
deployForks[1] = Chains.LocalFuji;
Expand All @@ -95,28 +77,24 @@ contract DeployCounter is Script, BaseDeployer {

/// @dev Deploy contracts to selected chains.
/// @param _counterSalt The salt for the counter contract.
/// @param _counterProxySalt The salt for the proxy contract.
/// @param deployForks The chains to deploy to.
/// @param cycle The development cycle to set env variables (dev, test, prod).
function deployCounterSelectedChains(
uint256 _counterSalt,
uint256 _counterProxySalt,
Chains[] calldata deployForks,
Cycle cycle
) external setEnvDeploy(cycle) {
counterSalt = bytes32(_counterSalt);
counterProxySalt = bytes32(_counterProxySalt);

createDeployMultichain(deployForks);
}

/// @dev Helper to iterate over chains and select fork.
/// @param deployForks The chains to deploy to.
function createDeployMultichain(
function _createDeployMultichain(
Chains[] memory deployForks
) private computeCreate2(counterSalt, counterProxySalt) {
) private computeCreate2(counterSalt) {
console2.log("Counter create2 address:", create2addrCounter, "\n");
console2.log("Counter proxy create2 address:", create2addrProxy, "\n");

for (uint256 i; i < deployForks.length; ) {
console2.log("Deploying Counter to chain: ", uint(deployForks[i]), "\n");
Expand All @@ -132,26 +110,15 @@ contract DeployCounter is Script, BaseDeployer {
}

/// @dev Function to perform actual deployment.
function chainDeployCounter() private broadcast(deployerPrivateKey) {
Counter counter = new Counter{salt: counterSalt}();

require(create2addrCounter == address(counter), "Address mismatch Counter");

console2.log("Counter address:", address(counter), "\n");

proxyCounter = new UUPSProxy{salt: counterProxySalt}(
address(counter),
abi.encodeWithSelector(Counter.initialize.selector, ownerAddress)
);

proxyCounterAddress = address(proxyCounter);
function _chainDeployCallBreaker() private broadcast(deployerPrivateKey) {
CallBreaker callBreaker = new CallBreaker{salt: counterSalt}();

require(create2addrProxy == proxyCounterAddress, "Address mismatch ProxyCounter");
require(create2addrCallBreaker == address(callBreaker), "Address mismatch CallBreaker");

wrappedProxy = Counter(proxyCounterAddress);
console2.log("Computed CallBreaker address:", address(callBreaker), "\n");

require(wrappedProxy.owner() == ownerAddress, "Owner role mismatch");
_callBreaker = CallBreaker(callBreaker);

console2.log("Counter Proxy address:", address(proxyCounter), "\n");
console2.log("CallBreaker deployed at address:", address(_callBreaker), "\n");
}
}
}

0 comments on commit 653e5ec

Please sign in to comment.