Skip to content

Commit

Permalink
script to deploy GatewayZEVM
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Oct 21, 2024
1 parent d40d2e2 commit f5a7285
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions v2/scripts/deploy/deterministic/DeployGatewayZEVM.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit f5a7285

Please sign in to comment.