-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fa15a8
commit f47da2a
Showing
8 changed files
with
225 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// hardhat import should be the first import in the file | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import * as hardhat from "hardhat"; | ||
import { Command } from "commander"; | ||
import { Wallet, ethers } from "ethers"; | ||
import { Deployer } from "../src.ts/deploy"; | ||
import { formatUnits, parseUnits } from "ethers/lib/utils"; | ||
import { web3Provider, GAS_MULTIPLIER, web3Url } from "./utils"; | ||
import { deployedAddressesFromEnv } from "../src.ts/deploy-utils"; | ||
import { initialBridgehubDeployment } from "../src.ts/deploy-process"; | ||
import { ethTestConfig, getAddressFromEnv, getNumberFromEnv } from "../src.ts/utils"; | ||
|
||
import { Wallet as ZkWallet, Provider as ZkProvider } from 'zksync-ethers'; | ||
|
||
const provider = web3Provider(); | ||
|
||
async function main() { | ||
const program = new Command(); | ||
|
||
program.version("0.1.0").name("deploy").description("deploy L1 contracts"); | ||
|
||
program | ||
.command('deploy-sync-layer-contracts') | ||
.option("--private-key <private-key>") | ||
.option("--chain-id <chain-id>") | ||
.option("--gas-price <gas-price>") | ||
.option("--owner-address <owner-address>") | ||
.option("--create2-salt <create2-salt>") | ||
.option("--diamond-upgrade-init <version>") | ||
.option("--only-verifier") | ||
.action(async (cmd) => { | ||
if(process.env.CONTRACTS_BASE_NETWORK_ZKSYNC !== "true") { | ||
throw new Error("This script is only for zkSync network"); | ||
} | ||
|
||
let deployWallet: ethers.Wallet | ZkWallet; | ||
|
||
// if (process.env.CONTRACTS_BASE_NETWORK_ZKSYNC === "true") { | ||
const provider = new ZkProvider(process.env.API_WEB3_JSON_RPC_HTTP_URL); | ||
deployWallet = cmd.privateKey | ||
? new ZkWallet(cmd.privateKey, provider) | ||
: ZkWallet.fromMnemonic( | ||
process.env.MNEMONIC ? process.env.MNEMONIC : ethTestConfig.mnemonic, | ||
"m/44'/60'/0'/0/1" | ||
).connect(provider); | ||
// } else { | ||
// deployWallet = cmd.privateKey | ||
// ? new Wallet(cmd.privateKey, provider) | ||
// : Wallet.fromMnemonic( | ||
// process.env.MNEMONIC ? process.env.MNEMONIC : ethTestConfig.mnemonic, | ||
// "m/44'/60'/0'/0/1" | ||
// ).connect(provider); | ||
// } | ||
|
||
console.log(`Using deployer wallet: ${deployWallet.address}`); | ||
|
||
const ownerAddress = cmd.ownerAddress ? cmd.ownerAddress : deployWallet.address; | ||
console.log(`Using owner address: ${ownerAddress}`); | ||
|
||
const gasPrice = cmd.gasPrice | ||
? parseUnits(cmd.gasPrice, "gwei") | ||
: (await provider.getGasPrice()).mul(GAS_MULTIPLIER); | ||
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`); | ||
|
||
const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount(); | ||
console.log(`Using nonce: ${nonce}`); | ||
|
||
const create2Salt = cmd.create2Salt ? cmd.create2Salt : ethers.utils.hexlify(ethers.utils.randomBytes(32)); | ||
|
||
const deployer = new Deployer({ | ||
deployWallet, | ||
addresses: deployedAddressesFromEnv(), | ||
ownerAddress, | ||
verbose: true, | ||
}); | ||
|
||
if (deployer.isZkMode()) { | ||
console.log("Deploying on a zkSync network!"); | ||
} | ||
|
||
await deployer.updateCreate2FactoryZkMode(); | ||
await deployer.updateBlobVersionedHashRetrieverZkMode(); | ||
|
||
await deployer.deployMulticall3(create2Salt, { gasPrice }); | ||
await deployer.deployDefaultUpgrade(create2Salt, { gasPrice }); | ||
await deployer.deployGenesisUpgrade(create2Salt, { gasPrice }); | ||
|
||
await deployer.deployGovernance(create2Salt, { gasPrice }); | ||
await deployer.deployVerifier(create2Salt, { gasPrice }); | ||
|
||
await deployer.deployTransparentProxyAdmin(create2Salt, { gasPrice }); | ||
|
||
// SyncLayer does not need to have all the same contracts as on L1. | ||
// We only need validator timelock as well as the STM. | ||
await deployer.deployValidatorTimelock(create2Salt, { gasPrice }); | ||
|
||
// On L2 there is no bridgebub. | ||
deployer.addresses.Bridgehub.BridgehubProxy = ethers.constants.AddressZero; | ||
|
||
await deployer.deployStateTransitionDiamondFacets(create2Salt, gasPrice); | ||
await deployer.deployStateTransitionManagerImplementation(create2Salt, { gasPrice }); | ||
await deployer.deployStateTransitionManagerProxy(create2Salt, { gasPrice }); | ||
}); | ||
|
||
program | ||
.command('register-sync-layer') | ||
.option("--private-key <private-key>") | ||
.option("--chain-id <chain-id>") | ||
.option("--gas-price <gas-price>") | ||
.option("--owner-address <owner-address>") | ||
.option("--create2-salt <create2-salt>") | ||
.option("--diamond-upgrade-init <version>") | ||
.option("--only-verifier") | ||
.action(async (cmd) => { | ||
// Now, all the operations are done on L1 | ||
const deployWallet = cmd.privateKey | ||
? new Wallet(cmd.privateKey, provider) | ||
: Wallet.fromMnemonic( | ||
process.env.MNEMONIC ? process.env.MNEMONIC : ethTestConfig.mnemonic, | ||
"m/44'/60'/0'/0/1" | ||
).connect(provider); | ||
|
||
const ownerAddress = cmd.ownerAddress ? cmd.ownerAddress : deployWallet.address; | ||
console.log(`Using owner address: ${ownerAddress}`); | ||
|
||
|
||
const stmOnSyncLayer = getAddressFromEnv('SYNC_LAYER_STATE_TRANSITION_PROXY_ADDR'); | ||
const chainId = getNumberFromEnv('CHAIN_ETH_ZKSYNC_NETWORK_ID'); | ||
|
||
console.log(`STM on SyncLayer: ${stmOnSyncLayer}`); | ||
console.log(`SyncLayer chain Id: ${chainId}`); | ||
|
||
const deployer = new Deployer({ | ||
deployWallet, | ||
addresses: deployedAddressesFromEnv(), | ||
ownerAddress, | ||
verbose: true, | ||
}); | ||
|
||
const l1STM = deployer.stateTransitionManagerContract(deployWallet); | ||
console.log(deployer.addresses.StateTransition.StateTransitionProxy); | ||
// this script only works when owner is the deployer | ||
console.log(`Registering SyncLayer chain id on the STM`); | ||
console.log(await l1STM.owner()); | ||
return; | ||
const registerChainIdTx = await l1STM.registerSyncLayer(chainId, true); | ||
console.log(`Transaction hash: ${registerChainIdTx.hash}`); | ||
await registerChainIdTx.wait(); | ||
|
||
console.log(`Registering STM counter part on the SyncLayer`); | ||
const registerCounterpartTx = await l1STM.registerCounterpart(chainId, stmOnSyncLayer); | ||
console.log(`Transaction hash: ${registerCounterpartTx.hash}`); | ||
await registerCounterpartTx.wait(); | ||
console.log(`SyncLayer registration completed`); | ||
}); | ||
|
||
await program.parseAsync(process.argv); | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((err) => { | ||
console.error("Error:", err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.