Skip to content

Commit

Permalink
refactor deploy and init scripts into a single script
Browse files Browse the repository at this point in the history
this removed a few extra manual steps (env var copying and setting)
  • Loading branch information
omnifient committed Aug 14, 2023
1 parent d99a5aa commit 4326cc5
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 158 deletions.
16 changes: 5 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@
DEPLOYER_PRIVATE_KEY=0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6 # TODO: change this
# address of the account that will have admin rights over the proxies
ADDRESS_PROXY_ADMIN=0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 # TODO: change this
# address of the account that will be the owner of the contracts
ADDRESS_OWNER=0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 # TODO: change this

# bridge and token address
ADDRESS_LXLY_BRIDGE=0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe # NOTE: same address for both L1/L2 when eth/zkevm
ADDRESS_L1_USDC=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 # NOTE: Ethereum Mainnet's USDC
ADDRESS_L2_USDC=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 # TODO: set this after deploying USDC to Polygon ZKEVM
ADDRESS_L2_WUSDC=0xA8CE8aee21bC2A48a5EF670afCc9274C7bbbC035 # NOTE: Polygon ZKEVM's WrappedUSDC

# these must be set after the deployment and before the initialization
ADDRESS_L1_ESCROW_PROXY=0xeD1DB453C3156Ff3155a97AD217b3087D5Dc5f6E # TODO: change this
ADDRESS_ZK_MINTER_BURNER_PROXY=0x8ce361602B935680E8DeC218b820ff5056BeB7af # TODO: change this
ADDRESS_NATIVE_CONVERTER_PROXY=0xb19b36b1456E65E3A6D514D3F715f204BD59f431 # TODO: change this
# the nodes to run against
L1_RPC_URL=http://localhost:8001 # TODO: change this
L2_RPC_URL=http://localhost:8101 # TODO: change this

# these are internal ids, no need to change
# https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/PolygonZkEVMBridge.sol#L38-L42
L1_NETWORK_ID=0 # 0 for Ethereum mainnet
L2_NETWORK_ID=1 # 1 for Polygon ZKEVM

###############################################################################
# TEST-SPECIFIC ENV VARS
###############################################################################
# the nodes to run against
TEST_L1_RPC_URL=http://localhost:8001
TEST_L2_RPC_URL=http://localhost:8101
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ cd usdc-lxly/
ADDRESS_L2_USDC=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512

# 6. make sure L1_RPC_URL and L2_RPC_URL are pointing to the local anvil nodes
TEST_L1_RPC_URL=http://localhost:8001
TEST_L2_RPC_URL=http://localhost:8101
L1_RPC_URL=http://localhost:8001
L2_RPC_URL=http://localhost:8101

# 7. run the usdc-lxly tests
cd usdc-lxly/
Expand Down Expand Up @@ -100,19 +100,7 @@ ADDRESS_L2_USDC=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512

# 5. deploy and initialize usdc-lxly
cd usdc-lxly/

## 5.1 deployment
forge script scripts/1Deploy.s.sol:DeployL1Contracts --rpc-url http://localhost:8001 --broadcast -vvvv
forge script scripts/1Deploy.s.sol:DeployL2Contracts --rpc-url http://localhost:8101 --broadcast -vvvv --legacy

## 5.2 copy the output addresses to the .env
ADDRESS_L1_ESCROW_PROXY=0xeD1DB453C3156Ff3155a97AD217b3087D5Dc5f6E
ADDRESS_ZK_MINTER_BURNER_PROXY=0x8ce361602B935680E8DeC218b820ff5056BeB7af
ADDRESS_NATIVE_CONVERTER_PROXY=0xb19b36b1456E65E3A6D514D3F715f204BD59f431

## 5.3 initialization
forge script scripts/2Init.s.sol:InitL1Contracts --rpc-url http://localhost:8001 --broadcast -vvvv
forge script scripts/2Init.s.sol:InitL2Contracts --rpc-url http://localhost:8101 --broadcast -vvvv --legacy
forge script scripts/DeployInit.s.sol:DeployInit --broadcast -vvvv

# 6. give minter permissions
cd usdc-e/
Expand Down
67 changes: 0 additions & 67 deletions scripts/1Deploy.s.sol

This file was deleted.

63 changes: 0 additions & 63 deletions scripts/2Init.s.sol

This file was deleted.

80 changes: 80 additions & 0 deletions scripts/DeployInit.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;

import "lib/forge-std/src/console.sol";
import "lib/forge-std/src/Script.sol";

import {LibDeployInit} from "./DeployInitHelpers.sol";

import "../src/L1EscrowProxy.sol";
import "../src/L1EscrowImpl.sol";
import "../src/NativeConverterProxy.sol";
import "../src/NativeConverterImpl.sol";
import "../src/ZkMinterBurnerProxy.sol";
import "../src/ZkMinterBurnerImpl.sol";

contract DeployInit is Script {
uint256 l1ForkId = vm.createFork(vm.envString("L1_RPC_URL"));
uint256 l2ForkId = vm.createFork(vm.envString("L2_RPC_URL"));

address bridge = vm.envAddress("ADDRESS_LXLY_BRIDGE");
uint32 l1NetworkId = uint32(vm.envUint("L1_NETWORK_ID"));
uint32 l2NetworkId = uint32(vm.envUint("L2_NETWORK_ID"));

address l1Usdc = vm.envAddress("ADDRESS_L1_USDC");
address l2Usdc = vm.envAddress("ADDRESS_L2_USDC"); // ATTN: needs to be deployed beforehand zkUsdc
address l2WrappedUsdc = vm.envAddress("ADDRESS_L2_WUSDC");

address admin = vm.envAddress("ADDRESS_PROXY_ADMIN");
address owner = vm.envAddress("ADDRESS_OWNER");

function run() external {
// deploy L1 contract
vm.selectFork(l1ForkId);
vm.startBroadcast(vm.envUint("DEPLOYER_PRIVATE_KEY"));
address l1EscrowProxy = LibDeployInit.deployL1Contracts(admin);
vm.stopBroadcast();

// deploy L2 contracts
vm.selectFork(l2ForkId);
vm.startBroadcast(vm.envUint("DEPLOYER_PRIVATE_KEY"));
(
address minterBurnerProxy,
address nativeConverterProxy
) = LibDeployInit.deployL2Contracts(admin);
vm.stopBroadcast();

// init L1 contract
vm.selectFork(l1ForkId);
vm.startBroadcast(vm.envUint("DEPLOYER_PRIVATE_KEY"));
L1EscrowImpl l1Escrow = LibDeployInit.initL1Contracts(
l2NetworkId,
bridge,
l1EscrowProxy,
minterBurnerProxy,
l1Usdc
);
vm.stopBroadcast();

// init L2 contracts
vm.selectFork(l2ForkId);
vm.startBroadcast(vm.envUint("DEPLOYER_PRIVATE_KEY"));
(
ZkMinterBurnerImpl minterBurner,
NativeConverterImpl nativeConverter
) = LibDeployInit.initL2Contracts(
l1NetworkId,
bridge,
l1EscrowProxy,
minterBurnerProxy,
nativeConverterProxy,
l2Usdc,
l2WrappedUsdc
);
vm.stopBroadcast();

console.log("L1_ESCROW_PROXY=%s", address(l1Escrow));
console.log("ZK_MINTER_BURNER_PROXY=%s", address(minterBurner));
console.log("NATIVE_CONVERTER_PROXY=%s", address(nativeConverter));
}
}
4 changes: 2 additions & 2 deletions test/Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ contract Base is Test {
/* ================= SETUP ================= */
function setUp() public virtual {
// create the forks
_l1Fork = vm.createFork(vm.envString("TEST_L1_RPC_URL"));
_l2Fork = vm.createFork(vm.envString("TEST_L2_RPC_URL"));
_l1Fork = vm.createFork(vm.envString("L1_RPC_URL"));
_l2Fork = vm.createFork(vm.envString("L2_RPC_URL"));
_l1NetworkId = uint32(vm.envUint("L1_NETWORK_ID"));
_l2NetworkId = uint32(vm.envUint("L2_NETWORK_ID"));

Expand Down

0 comments on commit 4326cc5

Please sign in to comment.