From f5a72851320def6fd6ecfdfb43f4f996b098bd15 Mon Sep 17 00:00:00 2001 From: skosito Date: Mon, 21 Oct 2024 17:08:45 +0200 Subject: [PATCH] script to deploy GatewayZEVM --- .../deterministic/DeployGatewayZEVM.s.sol | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 v2/scripts/deploy/deterministic/DeployGatewayZEVM.s.sol diff --git a/v2/scripts/deploy/deterministic/DeployGatewayZEVM.s.sol b/v2/scripts/deploy/deterministic/DeployGatewayZEVM.s.sol new file mode 100644 index 00000000..5b329a49 --- /dev/null +++ b/v2/scripts/deploy/deterministic/DeployGatewayZEVM.s.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.26; + +import "forge-std/Script.sol"; +import "contracts/zevm/GatewayZEVM.sol"; +import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; + +contract DeployGatewayZEVM is Script { + function run() external { + address admin = vm.envAddress("GATEWAY_ADMIN_ADDRESS_ZEVM"); + address zeta = vm.envAddress("ZETA_TOKEN"); + + address expectedImplAddress; + address expectedProxyAddress; + + bytes32 implSalt = keccak256("GatewayZEVM"); + bytes32 proxySalt = keccak256("GatewayZEVMProxy"); + + vm.startBroadcast(); + + expectedImplAddress = vm.computeCreate2Address( + implSalt, + hashInitCode(type(GatewayZEVM).creationCode) + ); + + GatewayZEVM gatewayImpl = new GatewayZEVM{salt: implSalt}(); + require(address(gatewayImpl) != address(0), "gatewayImpl deployment failed"); + + require(expectedImplAddress == address(gatewayImpl), "impl address doesn't match expected address"); + + expectedProxyAddress = vm.computeCreate2Address( + proxySalt, + hashInitCode( + type(ERC1967Proxy).creationCode, + abi.encode( + address(gatewayImpl), + abi.encodeWithSelector(GatewayZEVM.initialize.selector, zeta, admin) + ) + ) + ); + + ERC1967Proxy gatewayProxy = new ERC1967Proxy{salt: proxySalt}( + address(gatewayImpl), + abi.encodeWithSelector(GatewayZEVM.initialize.selector, zeta, admin) + ); + require(address(gatewayProxy) != address(0), "gatewayProxy deployment failed"); + + require(expectedProxyAddress == address(gatewayProxy), "proxy address doesn't match expected address"); + + GatewayZEVM gateway = GatewayZEVM(payable(address(gatewayProxy))); + require(gateway.zetaToken() == zeta, "zeta token not set"); + + vm.stopBroadcast(); + } +} \ No newline at end of file