From fa3bbd2d7d18b20c3cde8a18f9aed496f3a48212 Mon Sep 17 00:00:00 2001 From: 0xDiscotech <131301107+0xDiscotech@users.noreply.github.com> Date: Tue, 8 Oct 2024 13:23:30 -0300 Subject: [PATCH] feat: checkpoint --- .gitignore | 1 + script/DeployL1Factory.s.sol | 21 +++++++ script/DeployProtocol.s.sol | 55 +++++++++++++++++++ script/mainnet/deploy/Deploy.s.sol | 7 ++- script/mainnet/deploy/DeployBase.s.sol | 4 +- script/mainnet/deploy/DeployOptimism.s.sol | 4 +- .../deploy/L1FactoryDeployAndSetup.s.sol | 4 +- .../mainnet/migration/MigrateToNative.s.sol | 4 +- .../mainnet/migration/MigrateToNativeOp.s.sol | 2 +- script/testnet/deploy/Deploy.s.sol | 12 ++-- script/testnet/deploy/DeployBase.s.sol | 4 +- script/testnet/deploy/DeployOptimism.s.sol | 4 +- .../deploy/L1FactoryDeployAndSetup.s.sol | 6 +- 13 files changed, 103 insertions(+), 25 deletions(-) create mode 100644 script/DeployL1Factory.s.sol create mode 100644 script/DeployProtocol.s.sol diff --git a/.gitignore b/.gitignore index 40cb5861..04c6f651 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ out-via-ir # Config files .env +.env.testnet # Avoid ignoring gitkeep !/**/.gitkeep diff --git a/script/DeployL1Factory.s.sol b/script/DeployL1Factory.s.sol new file mode 100644 index 00000000..05a0aea6 --- /dev/null +++ b/script/DeployL1Factory.s.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +import {L1OpUSDCFactory} from 'contracts/L1OpUSDCFactory.sol'; +import {Script} from 'forge-std/Script.sol'; +import {console} from 'forge-std/Test.sol'; +import {IL1OpUSDCFactory} from 'interfaces/IL1OpUSDCFactory.sol'; + +contract DeployL1Factory is Script { + // address public deployer = vm.rememberKey(vm.envUint('PK')); + // address public usdc = vm.envAddress('USDC_ETHEREUM_IMPLEMENTATION'); + + function deployFactory(uint256 _deployerPk, address _usdc) public returns (address _l1Factory) { + address _deployer = vm.rememberKey(_deployerPk); + vm.startBroadcast(_deployer); + console.log('Deploying L1OpUSDCFactory ...'); + _l1Factory = address(new L1OpUSDCFactory(_usdc)); + console.log('L1OpUSDCFactory deployed at:', address(_l1Factory)); + vm.stopBroadcast(); + } +} diff --git a/script/DeployProtocol.s.sol b/script/DeployProtocol.s.sol new file mode 100644 index 00000000..447dbf18 --- /dev/null +++ b/script/DeployProtocol.s.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +import {Script} from 'forge-std/Script.sol'; +import {console} from 'forge-std/Test.sol'; +import {IL1OpUSDCFactory} from 'interfaces/IL1OpUSDCFactory.sol'; +import {IUSDC} from 'interfaces/external/IUSDC.sol'; +import {USDCInitTxs} from 'src/contracts/utils/USDCInitTxs.sol'; + +contract DeployProtocol is Script { + uint32 public constant MIN_GAS_LIMIT_DEPLOY = 9_000_000; + // IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY')); + // address public immutable BRIDGED_USDC_IMPLEMENTATION = vm.envAddress('BRIDGED_USDC_IMPLEMENTATION'); + // address public immutable L1_MESSENGER = vm.envAddress('L1_MESSENGER'); + // string public chainName = vm.envString('CHAIN_NAME'); + // address public owner = vm.rememberKey(vm.envUint('PK')); + + function deployProtocol( + uint256 _ownerPk, + address _l1Factory, + address _bridgedUsdcImplementation, + address _l1Messenger, + string memory _chainName + ) public { + address _owner = vm.rememberKey(_ownerPk); + vm.startBroadcast(_owner); + + // NOTE: We have these hardcoded to default values, if used in production you will need to change them + bytes[] memory _usdcInitTxs = new bytes[](3); + string memory _name = string.concat('Bridged USDC', ' ', '(', _chainName, ')'); + + _usdcInitTxs[0] = abi.encodeCall(IUSDC.initializeV2, (_name)); + _usdcInitTxs[1] = USDCInitTxs.INITIALIZEV2_1; + _usdcInitTxs[2] = USDCInitTxs.INITIALIZEV2_2; + + // Sanity check to ensure the caller of this script changed this value to the proper naming + assert(keccak256(_usdcInitTxs[0]) != keccak256(USDCInitTxs.INITIALIZEV2)); + + IL1OpUSDCFactory.L2Deployments memory _l2Deployments = IL1OpUSDCFactory.L2Deployments({ + l2AdapterOwner: _owner, + usdcImplAddr: _bridgedUsdcImplementation, + usdcInitTxs: _usdcInitTxs, + minGasLimitDeploy: MIN_GAS_LIMIT_DEPLOY + }); + + // Deploy the L2 contracts + (address _l1Adapter, address _l2Deploy, address _l2Adapter) = + IL1OpUSDCFactory(_l1Factory).deploy(_l1Messenger, _owner, _chainName, _l2Deployments); + vm.stopBroadcast(); + + console.log('L1 Adapter:', _l1Adapter); + console.log('L2 Adapter:', _l2Adapter); + console.log('L2 Deploy:', _l2Deploy); + } +} diff --git a/script/mainnet/deploy/Deploy.s.sol b/script/mainnet/deploy/Deploy.s.sol index 21e77290..da130938 100644 --- a/script/mainnet/deploy/Deploy.s.sol +++ b/script/mainnet/deploy/Deploy.s.sol @@ -7,13 +7,14 @@ import {IL1OpUSDCFactory} from 'interfaces/IL1OpUSDCFactory.sol'; import {IUSDC} from 'interfaces/external/IUSDC.sol'; import {USDCInitTxs} from 'src/contracts/utils/USDCInitTxs.sol'; +import {DeployProtocol} from 'script/DeployProtocol.s.sol'; + contract Deploy is Script { - uint32 public constant MIN_GAS_LIMIT_DEPLOY = 9_000_000; - IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY_MAINNET')); + IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY')); address public immutable BRIDGED_USDC_IMPLEMENTATION = vm.envAddress('BRIDGED_USDC_IMPLEMENTATION'); address public immutable L1_MESSENGER = vm.envAddress('L1_MESSENGER'); string public chainName = vm.envString('CHAIN_NAME'); - address public owner = vm.rememberKey(vm.envUint('MAINNET_PK')); + address public owner = vm.rememberKey(vm.envUint('PK')); function run() public { vm.startBroadcast(owner); diff --git a/script/mainnet/deploy/DeployBase.s.sol b/script/mainnet/deploy/DeployBase.s.sol index bfaa7857..fc8b31da 100644 --- a/script/mainnet/deploy/DeployBase.s.sol +++ b/script/mainnet/deploy/DeployBase.s.sol @@ -10,9 +10,9 @@ contract DeployBase is Script { address public constant L1_MESSENGER = 0x866E82a600A1414e583f7F13623F1aC5d58b0Afa; uint32 public constant MIN_GAS_LIMIT_DEPLOY = 9_000_000; string public constant CHAIN_NAME = 'Base'; - IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY_MAINNET')); + IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY')); address public immutable USDC_BASE_IMPLEMENTATION = vm.envAddress('USDC_BASE_IMPLEMENTATION'); - address public owner = vm.rememberKey(vm.envUint('MAINNET_PK')); + address public owner = vm.rememberKey(vm.envUint('PK')); function run() public { vm.startBroadcast(owner); diff --git a/script/mainnet/deploy/DeployOptimism.s.sol b/script/mainnet/deploy/DeployOptimism.s.sol index 72a0dc46..d483f355 100644 --- a/script/mainnet/deploy/DeployOptimism.s.sol +++ b/script/mainnet/deploy/DeployOptimism.s.sol @@ -10,9 +10,9 @@ contract DeployOptimism is Script { address public constant L1_MESSENGER = 0x25ace71c97B33Cc4729CF772ae268934F7ab5fA1; uint32 public constant MIN_GAS_LIMIT_DEPLOY = 9_000_000; string public constant CHAIN_NAME = 'Optimism'; - IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY_MAINNET')); + IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY')); address public immutable USDC_OPTIMISM_IMPLEMENTATION = vm.envAddress('USDC_OPTIMISM_IMPLEMENTATION'); - address public owner = vm.rememberKey(vm.envUint('MAINNET_PK')); + address public owner = vm.rememberKey(vm.envUint('PK')); function run() public { vm.startBroadcast(owner); diff --git a/script/mainnet/deploy/L1FactoryDeployAndSetup.s.sol b/script/mainnet/deploy/L1FactoryDeployAndSetup.s.sol index 6189d227..38c9c7d7 100644 --- a/script/mainnet/deploy/L1FactoryDeployAndSetup.s.sol +++ b/script/mainnet/deploy/L1FactoryDeployAndSetup.s.sol @@ -7,7 +7,7 @@ import {console} from 'forge-std/Test.sol'; import {IL1OpUSDCFactory} from 'interfaces/IL1OpUSDCFactory.sol'; contract L1FactoryDeployAndSetup is Script { - address public deployer = vm.rememberKey(vm.envUint('MAINNET_PK')); + address public deployer = vm.rememberKey(vm.envUint('PK')); address public usdc = vm.envAddress('USDC_ETHEREUM_IMPLEMENTATION'); function run() public { @@ -15,7 +15,7 @@ contract L1FactoryDeployAndSetup is Script { console.log('Deploying L1OpUSDCFactory ...'); IL1OpUSDCFactory _l1Factory = new L1OpUSDCFactory(usdc); console.log('L1OpUSDCFactory deployed at:', address(_l1Factory)); - /// NOTE: Hardcode the address on `L1_FACTORY_MAINNET` inside the `.env` file + /// NOTE: Hardcode the address on `L1_FACTORY` inside the `.env` file vm.stopBroadcast(); } } diff --git a/script/mainnet/migration/MigrateToNative.s.sol b/script/mainnet/migration/MigrateToNative.s.sol index bc6387e4..e6929776 100644 --- a/script/mainnet/migration/MigrateToNative.s.sol +++ b/script/mainnet/migration/MigrateToNative.s.sol @@ -9,12 +9,12 @@ contract MigrateToNative is Script { uint32 public constant MIN_GAS_LIMIT_SET_BURN_AMOUNT_L2 = 100_000; IL1OpUSDCBridgeAdapter public immutable L1_ADAPTER = IL1OpUSDCBridgeAdapter(vm.envAddress('L1_ADAPTER')); - address public owner = vm.rememberKey(vm.envUint('MAINNET_OWNER_PK')); + address public owner = vm.rememberKey(vm.envUint('OWNER_PK')); address public roleCaller = vm.envAddress('ROLE_CALLER'); address public burnCaller = vm.envAddress('BURN_CALLER'); function run() public { - vm.createSelectFork(vm.rpcUrl(vm.envString('MAINNET_RPC'))); + vm.createSelectFork(vm.rpcUrl(vm.envString('RPC'))); vm.startBroadcast(owner); L1_ADAPTER.migrateToNative(roleCaller, burnCaller, MIN_GAS_LIMIT_RECEIVE_L2, MIN_GAS_LIMIT_SET_BURN_AMOUNT_L2); vm.stopBroadcast(); diff --git a/script/mainnet/migration/MigrateToNativeOp.s.sol b/script/mainnet/migration/MigrateToNativeOp.s.sol index 67d55a65..3810dc75 100644 --- a/script/mainnet/migration/MigrateToNativeOp.s.sol +++ b/script/mainnet/migration/MigrateToNativeOp.s.sol @@ -9,7 +9,7 @@ contract MigrateToNativeOp is Script { uint32 public constant MIN_GAS_LIMIT_SET_BURN_AMOUNT_L2 = 100_000; IL1OpUSDCBridgeAdapter public immutable L1_ADAPTER = IL1OpUSDCBridgeAdapter(vm.envAddress('L1_ADAPTER_OP')); - address public owner = vm.rememberKey(vm.envUint('MAINNET_OWNER_PK')); + address public owner = vm.rememberKey(vm.envUint('OWNER_PK')); address public roleCaller = vm.envAddress('OP_ROLE_CALLER'); address public burnCaller = vm.envAddress('OP_BURN_CALLER'); diff --git a/script/testnet/deploy/Deploy.s.sol b/script/testnet/deploy/Deploy.s.sol index 963c69a6..35e50323 100644 --- a/script/testnet/deploy/Deploy.s.sol +++ b/script/testnet/deploy/Deploy.s.sol @@ -9,11 +9,11 @@ import {USDCInitTxs} from 'src/contracts/utils/USDCInitTxs.sol'; contract Deploy is Script { uint32 public constant MIN_GAS_LIMIT_DEPLOY = 9_000_000; - IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY_TESTNET')); - address public immutable BRIDGED_USDC_IMPLEMENTATION = vm.envAddress('TESTNET_BRIDGED_USDC_IMPLEMENTATION'); - address public immutable L1_MESSENGER = vm.envAddress('L1_MESSENGER_TESTNET'); - string public chainName = vm.envString('TESTNET_CHAIN_NAME'); - address public owner = vm.rememberKey(vm.envUint('TESTNET_PK')); + IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY')); + address public immutable BRIDGED_USDC_IMPLEMENTATION = vm.envAddress('BRIDGED_USDC_IMPLEMENTATION'); + address public immutable L1_MESSENGER = vm.envAddress('L1_MESSENGER'); + string public chainName = vm.envString('CHAIN_NAME'); + address public owner = vm.rememberKey(vm.envUint('PK')); function run() public { vm.startBroadcast(owner); @@ -41,7 +41,7 @@ contract Deploy is Script { L1_FACTORY.deploy(L1_MESSENGER, owner, chainName, _l2Deployments); vm.stopBroadcast(); - /// NOTE: Hardcode the `L1_ADAPTER_BASE` and `L2_ADAPTER_BASE` addresses inside the `.env` file + /// NOTE: Hardcode the `L1_ADAPTER_BASE` and `L2_ADAPTER_BASE` addresses inside the `.env.example` file console.log('L1 Adapter:', _l1Adapter); console.log('L2 Factory:', _l2Factory); console.log('L2 Adapter:', _l2Adapter); diff --git a/script/testnet/deploy/DeployBase.s.sol b/script/testnet/deploy/DeployBase.s.sol index b4a603d3..cd04850a 100644 --- a/script/testnet/deploy/DeployBase.s.sol +++ b/script/testnet/deploy/DeployBase.s.sol @@ -10,7 +10,7 @@ contract DeployBase is Script { address public constant L1_MESSENGER = 0xC34855F4De64F1840e5686e64278da901e261f20; uint32 public constant MIN_GAS_LIMIT_DEPLOY = 9_000_000; string public constant CHAIN_NAME = 'Base Sepolia'; - IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY_TESTNET')); + IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY')); address public immutable USDC_BASE_SEPOLIA_IMPLEMENTATION = vm.envAddress('USDC_BASE_SEPOLIA_IMPLEMENTATION'); address public owner = vm.rememberKey(vm.envUint('SEPOLIA_PK')); @@ -34,7 +34,7 @@ contract DeployBase is Script { L1_FACTORY.deploy(L1_MESSENGER, owner, CHAIN_NAME, _l2Deployments); vm.stopBroadcast(); - /// NOTE: Hardcode the `L1_ADAPTER_BASE_SEPOLIA` and `L2_ADAPTER_BASE_SEPOLIA` addresses inside the `.env` file + /// NOTE: Hardcode the `L1_ADAPTER_BASE_SEPOLIA` and `L2_ADAPTER_BASE_SEPOLIA` addresses inside the `.env.example` file console.log('L1 Adapter:', _l1Adapter); console.log('L2 Factory:', _l2Factory); console.log('L2 Adapter:', _l2Adapter); diff --git a/script/testnet/deploy/DeployOptimism.s.sol b/script/testnet/deploy/DeployOptimism.s.sol index ea3b4b6f..f7d239f1 100644 --- a/script/testnet/deploy/DeployOptimism.s.sol +++ b/script/testnet/deploy/DeployOptimism.s.sol @@ -10,7 +10,7 @@ contract DeployOptimism is Script { address public constant L1_MESSENGER = 0x58Cc85b8D04EA49cC6DBd3CbFFd00B4B8D6cb3ef; uint32 public constant MIN_GAS_LIMIT_DEPLOY = 9_000_000; string public constant CHAIN_NAME = 'Optimism Sepolia'; - IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY_TESTNET')); + IL1OpUSDCFactory public immutable L1_FACTORY = IL1OpUSDCFactory(vm.envAddress('L1_FACTORY')); address public immutable USDC_OPTIMISM_SEPOLIA_IMPLEMENTATION = vm.envAddress('USDC_OPTIMISM_SEPOLIA_IMPLEMENTATION'); address public owner = vm.rememberKey(vm.envUint('SEPOLIA_PK')); @@ -34,7 +34,7 @@ contract DeployOptimism is Script { L1_FACTORY.deploy(L1_MESSENGER, owner, CHAIN_NAME, _l2Deployments); vm.stopBroadcast(); - /// NOTE: Hardcode the `L1_ADAPTER_OP_SEPOLIA` and `L2_ADAPTER_OP_SEPOLIA` addresses inside the `.env` file + /// NOTE: Hardcode the `L1_ADAPTER_OP_SEPOLIA` and `L2_ADAPTER_OP_SEPOLIA` addresses inside the `.env.example` file console.log('L1 Adapter:', _l1Adapter); console.log('L2 Factory:', _l2Factory); console.log('L2 Adapter:', _l2Adapter); diff --git a/script/testnet/deploy/L1FactoryDeployAndSetup.s.sol b/script/testnet/deploy/L1FactoryDeployAndSetup.s.sol index 37b874c4..ea686753 100644 --- a/script/testnet/deploy/L1FactoryDeployAndSetup.s.sol +++ b/script/testnet/deploy/L1FactoryDeployAndSetup.s.sol @@ -7,15 +7,15 @@ import {console} from 'forge-std/Test.sol'; import {IL1OpUSDCFactory} from 'interfaces/IL1OpUSDCFactory.sol'; contract L1FactoryDeployAndSetup is Script { - address public deployer = vm.rememberKey(vm.envUint('TESTNET_PK')); - address public usdc = vm.envAddress('USDC_ETHEREUM_TESTNET_IMPLEMENTATION'); + address public deployer = vm.rememberKey(vm.envUint('PK')); + address public usdc = vm.envAddress('USDC_ETHEREUM_IMPLEMENTATION'); function run() public { vm.startBroadcast(deployer); console.log('Deploying L1OpUSDCFactory ...'); IL1OpUSDCFactory _l1Factory = new L1OpUSDCFactory(usdc); console.log('L1OpUSDCFactory deployed at:', address(_l1Factory)); - /// NOTE: Hardcode the address on `L1_FACTORY_TESTNET` inside the `.env` file + /// NOTE: Hardcode the address on `L1_FACTORY` inside the `.env.example` file vm.stopBroadcast(); } }