From 653e5ec1cf28e57f0305c67b7dfa1cba8e36042e Mon Sep 17 00:00:00 2001 From: xBalbinus Date: Mon, 13 May 2024 11:15:18 -0400 Subject: [PATCH] CallBreaker deployment --- script/BaseDeployer.s.sol | 11 +++--- script/CallBreaker.s.sol | 73 +++++++++++---------------------------- 2 files changed, 26 insertions(+), 58 deletions(-) diff --git a/script/BaseDeployer.s.sol b/script/BaseDeployer.s.sol index b8c7468..d72e190 100644 --- a/script/BaseDeployer.s.sol +++ b/script/BaseDeployer.s.sol @@ -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, @@ -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"; diff --git a/script/CallBreaker.s.sol b/script/CallBreaker.s.sol index 933422f..6adddfb 100644 --- a/script/CallBreaker.s.sol +++ b/script/CallBreaker.s.sol @@ -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) ); _; @@ -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; @@ -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; @@ -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; @@ -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"); @@ -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"); } -} \ No newline at end of file +}