-
Notifications
You must be signed in to change notification settings - Fork 302
Chore(entropy) deploy on abstract #2056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
168 changes: 168 additions & 0 deletions
168
target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts
This file contains hidden or 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,168 @@ | ||
| require("dotenv").config({ path: ".env" }); | ||
| import { utils, Wallet } from "zksync-web3"; | ||
| import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
| import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; | ||
| import { CHAINS } from "@pythnetwork/xc-admin-common"; | ||
| import { assert } from "chai"; | ||
| import { | ||
| DefaultStore, | ||
| EvmChain, | ||
| EvmWormholeContract, | ||
| } from "@pythnetwork/contract-manager"; | ||
| import { | ||
| findWormholeContract, | ||
| deployWormholeContract, | ||
| } from "./zkSyncDeployWormhole"; | ||
|
|
||
| // import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work | ||
| // import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync"; | ||
|
|
||
| const { getDefaultConfig } = require("../scripts/contractManagerConfig"); | ||
|
|
||
| function envOrErr(name: string): string { | ||
| const res = process.env[name]; | ||
| if (res === undefined) { | ||
| throw new Error(`${name} environment variable is not set.`); | ||
| } | ||
| return res; | ||
| } | ||
| export const ENTROPY_DEFAULT_PROVIDER = { | ||
| mainnet: "0x52DeaA1c84233F7bb8C8A45baeDE41091c616506", | ||
| testnet: "0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344", | ||
| }; | ||
| export const ENTROPY_DEFAULT_KEEPER = { | ||
| mainnet: "0xbcab779fca45290288c35f5e231c37f9fa87b130", | ||
| testnet: "0xa5A68ed167431Afe739846A22597786ba2da85df", | ||
| }; | ||
|
|
||
| export default async function (hre: HardhatRuntimeEnvironment) { | ||
| // Initialize the wallet. | ||
| const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC")); | ||
| const isMainnet = envOrErr("MAINNET") === "true"; | ||
|
|
||
| // Create deployer object and load the artifact of the contract we want to deploy. | ||
| const deployer = new Deployer(hre, wallet); | ||
|
|
||
| const { | ||
| wormholeGovernanceChainId, | ||
| wormholeGovernanceContract, | ||
| wormholeInitialSigners, | ||
| governanceEmitter, | ||
| governanceChainId, | ||
| } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); | ||
|
|
||
| const chainName = envOrErr("MIGRATIONS_NETWORK"); | ||
aditya520 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const wormholeReceiverChainId = CHAINS[chainName]; | ||
| assert(wormholeReceiverChainId !== undefined); | ||
|
|
||
| let wormholeReceiverContractAddress = await findWormholeContract(chainName); | ||
| if (!wormholeReceiverContractAddress) { | ||
| console.log(`Wormhole contract not found for chain ${chainName}`); | ||
| console.log("Deploying Wormhole contract..."); | ||
| wormholeReceiverContractAddress = await deployWormholeContract( | ||
| deployer, | ||
| chainName, | ||
| wormholeGovernanceChainId, | ||
| wormholeGovernanceContract, | ||
| wormholeInitialSigners, | ||
| wormholeReceiverChainId | ||
| ); | ||
| } | ||
|
|
||
| console.log( | ||
| "WormholeReceiver contract address:", | ||
| wormholeReceiverContractAddress | ||
| ); | ||
|
|
||
| // // TODO: Top up accounts if necessary | ||
|
|
||
| const executorContractAddress = await deployExecutorContract( | ||
| deployer, | ||
| wormholeReceiverContractAddress, | ||
| wormholeReceiverChainId, | ||
| governanceChainId, | ||
| governanceEmitter | ||
| ); | ||
|
|
||
| console.log("Executor contract address:", executorContractAddress); | ||
|
|
||
| const entropyContractAddress = await deployEntropyContract( | ||
| deployer, | ||
| executorContractAddress, | ||
| wormholeReceiverChainId, | ||
| isMainnet | ||
| ); | ||
|
|
||
| console.log("Entropy contract address:", entropyContractAddress); | ||
| } | ||
|
|
||
| async function deployExecutorContract( | ||
| deployer: Deployer, | ||
| wormholeReceiverContractAddress: string, | ||
| wormholeReceiverChainId: number, | ||
| governanceChainId: string, | ||
| governanceEmitter: string | ||
| ) { | ||
| const executorImplArtifact = await deployer.loadArtifact( | ||
| "ExecutorUpgradable" | ||
| ); | ||
| const executorImplContract = await deployer.deploy(executorImplArtifact); | ||
| console.log( | ||
| "Deployed ExecutorImpl contract on", | ||
| executorImplContract.address | ||
| ); | ||
|
|
||
| const executorInitData = executorImplContract.interface.encodeFunctionData( | ||
| "initialize", | ||
| [ | ||
| wormholeReceiverContractAddress, | ||
| 0, // lastExecutedSequence, | ||
| wormholeReceiverChainId, | ||
| governanceChainId, | ||
| governanceEmitter, | ||
| ] | ||
| ); | ||
|
|
||
| const executorProxyArtifact = await deployer.loadArtifact("ERC1967Proxy"); | ||
|
|
||
| const executorProxyContract = await deployer.deploy(executorProxyArtifact, [ | ||
| executorImplContract.address, | ||
| executorInitData, | ||
| ]); | ||
|
|
||
| console.log(`Deployed Executor contract on ${executorProxyContract.address}`); | ||
|
|
||
| return executorProxyContract.address; | ||
| } | ||
|
|
||
| async function deployEntropyContract( | ||
| deployer: Deployer, | ||
| executorContractAddress: string, | ||
| chainId: number, | ||
| isMainnet: boolean | ||
| ) { | ||
| const entropyImplArtifact = await deployer.loadArtifact("EntropyUpgradable"); | ||
| const entropyImplContract = await deployer.deploy(entropyImplArtifact); | ||
|
|
||
| const entropyInitData = entropyImplContract.interface.encodeFunctionData( | ||
| "initialize", | ||
| [ | ||
| executorContractAddress, | ||
| executorContractAddress, | ||
| 1, | ||
aditya520 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| isMainnet | ||
| ? ENTROPY_DEFAULT_PROVIDER.mainnet | ||
| : ENTROPY_DEFAULT_PROVIDER.testnet, | ||
| true, | ||
| ] | ||
| ); | ||
|
|
||
| const entropyProxyArtifact = await deployer.loadArtifact("ERC1967Proxy"); | ||
| const entropyProxyContract = await deployer.deploy(entropyProxyArtifact, [ | ||
| entropyImplContract.address, | ||
| entropyInitData, | ||
| ]); | ||
|
|
||
| return entropyProxyContract.address; | ||
| } | ||
This file contains hidden or 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
72 changes: 72 additions & 0 deletions
72
target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts
This file contains hidden or 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,72 @@ | ||
| import { | ||
| DefaultStore, | ||
| EvmChain, | ||
| EvmWormholeContract, | ||
| } from "@pythnetwork/contract-manager"; | ||
| import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; | ||
| import { CHAINS } from "@pythnetwork/xc-admin-common"; | ||
| import { assert } from "chai"; | ||
|
|
||
| export function findWormholeContract(chainId: string): string | undefined { | ||
| for (const contract of Object.values(DefaultStore.wormhole_contracts)) { | ||
| if ( | ||
| contract instanceof EvmWormholeContract && | ||
| contract.getChain().getId() === chainId | ||
| ) { | ||
| return contract.address; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export async function deployWormholeContract( | ||
| deployer: Deployer, | ||
| chainName: string, | ||
| wormholeGovernanceChainId: string, | ||
| wormholeGovernanceContract: string, | ||
| wormholeInitialSigners: string[], | ||
| wormholeReceiverChainId: number | ||
| ): Promise<string> { | ||
| const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup"); | ||
| const receiverImplArtifact = await deployer.loadArtifact( | ||
| "ReceiverImplementation" | ||
| ); | ||
| const wormholeReceiverArtifact = await deployer.loadArtifact( | ||
| "WormholeReceiver" | ||
| ); | ||
| console.log("Deploying WormholeReceiver contract..."); | ||
|
|
||
| const receiverSetupContract = await deployer.deploy(receiverSetupArtifact); | ||
| console.log("Deployed ReceiverSetup on", receiverSetupContract.address); | ||
| console.log("Deploying ReceiverImplementation contract..."); | ||
|
|
||
| // deploy implementation | ||
| const receiverImplContract = await deployer.deploy(receiverImplArtifact); | ||
| console.log( | ||
| "Deployed ReceiverImplementation on", | ||
| receiverImplContract.address | ||
| ); | ||
|
|
||
| // encode initialisation data | ||
| const whInitData = receiverSetupContract.interface.encodeFunctionData( | ||
| "setup", | ||
| [ | ||
| receiverImplContract.address, | ||
| wormholeInitialSigners, | ||
| wormholeReceiverChainId, | ||
| wormholeGovernanceChainId, | ||
| wormholeGovernanceContract, | ||
| ] | ||
| ); | ||
|
|
||
| // deploy proxy | ||
| const wormholeReceiverContract = await deployer.deploy( | ||
| wormholeReceiverArtifact, | ||
| [receiverSetupContract.address, whInitData] | ||
| ); | ||
|
|
||
| console.log( | ||
| `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` | ||
| ); | ||
|
|
||
| return wormholeReceiverContract.address; | ||
| } |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.