Skip to content

Commit

Permalink
chore: script to deploy GatewayZEVM (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito authored Oct 23, 2024
1 parent cc56841 commit abbfeea
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions v2/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ZETA_ERC20_EVM=0x42928581Ba60cD97B65D873151dc063F3D0619f8
# zevm
GATEWAY_PROXY_ZEVM=
SYSTEM_CONTRACT=
GATEWAY_ADMIN_ADDRESS_ZEVM=
WZETA=

# update for every zrc20 deployment
ZRC20_NAME=
Expand Down
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("WZETA");

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 abbfeea

Please sign in to comment.