From af257d73e77333b5271d67bae64c275a74691d53 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Thu, 28 Sep 2023 11:05:24 +0400 Subject: [PATCH] Revert to fe204438c769e8128ebc2fdd29c847256ac2a80d --- scripts/integration.sh | 4 +- templates/messaging/tasks/deploy.ts.hbs | 56 ++++++++++++------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/scripts/integration.sh b/scripts/integration.sh index d06e1b13..81fe36b9 100755 --- a/scripts/integration.sh +++ b/scripts/integration.sh @@ -71,6 +71,4 @@ git reset --hard HEAD npx hardhat messaging CrossChainMessage npx hardhat compile --force --no-typechain npx hardhat deploy --help -npx hardhat interact --help - -npx hardhat deploy --networks goerli_testnet,mumbai_testnet --json \ No newline at end of file +npx hardhat interact --help \ No newline at end of file diff --git a/templates/messaging/tasks/deploy.ts.hbs b/templates/messaging/tasks/deploy.ts.hbs index ae1d033b..283e1259 100644 --- a/templates/messaging/tasks/deploy.ts.hbs +++ b/templates/messaging/tasks/deploy.ts.hbs @@ -8,22 +8,21 @@ const contractName = "{{contractName}}"; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const networks = args.networks.split(","); + // A mapping between network names and deployed contract addresses. const contracts: { [key: string]: string } = {}; await Promise.all( networks.map(async (networkName: string) => { - contracts[networkName] = await deployContract(hre, networkName, args.json); + contracts[networkName] = await deployContract(hre, networkName); }) ); for (const source in contracts) { - await setInteractors(hre, source, contracts, args.json); - } - - if (args.json) { - console.log(JSON.stringify(contracts, null, 2)); + await setInteractors(hre, source, contracts); } }; +// Initialize a wallet using a network configuration and a private key from +// environment variables. const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { const { url } = hre.config.networks[networkName] as any; const provider = new ethers.providers.JsonRpcProvider(url); @@ -32,10 +31,12 @@ const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { return wallet; }; +// Deploy the contract on the specified network. deployContract reads the +// contract artifact, creates a contract factory, and deploys the contract using +// that factory. const deployContract = async ( hre: HardhatRuntimeEnvironment, - networkName: string, - json: boolean = false + networkName: string ) => { const wallet = initWallet(hre, networkName); @@ -59,24 +60,22 @@ const deployContract = async ( ); await contract.deployed(); - if (!json) { - console.log(` + console.log(` 🚀 Successfully deployed contract on ${networkName}. 📜 Contract address: ${contract.address}`); - } return contract.address; }; +// Set interactors for a contract. setInteractors attaches to the contract +// deployed at the specified address, and for every other network, sets the +// deployed contract's address as an interactor. const setInteractors = async ( hre: HardhatRuntimeEnvironment, source: string, - contracts: { [key: string]: string }, - json: boolean = false + contracts: { [key: string]: string } ) => { - if (!json) { - console.log(` + console.log(` 🔗 Setting interactors for a contract on ${source}`); - } const wallet = initWallet(hre, source); const { abi, bytecode } = await hre.artifacts.readArtifact(contractName); @@ -84,6 +83,9 @@ const setInteractors = async ( const contract = factory.attach(contracts[source]); for (const counterparty in contracts) { + // Skip the destination network if it's the same as the source network. + // For example, we don't need to set an interactor for a contract on + // Goerli if the destination network is also Goerli. if (counterparty === source) continue; const counterpartyContract = hre.ethers.utils.solidityPack( @@ -94,19 +96,15 @@ const setInteractors = async ( await ( await contract.setInteractorByChainId(chainId, counterpartyContract) ).wait(); - if (!json) { - console.log( - `✅ Interactor address for ${chainId} (${counterparty}) is set to ${counterpartyContract}` - ); - } + console.log( + `✅ Interactor address for ${chainId} (${counterparty}) is set to ${counterpartyContract}` + ); } }; -task("deploy", "Deploy the contract", main) - .addParam( - "networks", - `Comma separated list of networks to deploy to (e.g. ${getSupportedNetworks( - "ccm" - )})` - ) - .addFlag("json", "Output JSON"); +task("deploy", "Deploy the contract", main).addParam( + "networks", + `Comma separated list of networks to deploy to (e.g. ${getSupportedNetworks( + "ccm" + )})` +);