Skip to content

Commit

Permalink
Revert to fe20443
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Sep 28, 2023
1 parent 64648fe commit af257d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
4 changes: 1 addition & 3 deletions scripts/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
npx hardhat interact --help
56 changes: 27 additions & 29 deletions templates/messaging/tasks/deploy.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -59,31 +60,32 @@ 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);
const factory = new ethers.ContractFactory(abi, bytecode, wallet);
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(
Expand All @@ -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"
)})`
);

0 comments on commit af257d7

Please sign in to comment.