Skip to content

Commit

Permalink
fix: messaging deploy task
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Jul 18, 2023
1 parent 14b077c commit 55fac46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
52 changes: 22 additions & 30 deletions templates/messaging/tasks/deploy.ts.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getAddress, getChainId } from "@zetachain/addresses";
import { getAddress } from "@zetachain/protocol-contracts";
import { ethers } from "ethers";
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { getSupportedNetworks } from "@zetachain/networks";

const contractName = "{{contractName}}";

Expand All @@ -23,7 +24,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
// 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];
const { url } = hre.config.networks[networkName] as any;
const provider = new ethers.providers.JsonRpcProvider(url);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider);

Expand All @@ -38,41 +39,30 @@ const deployContract = async (
networkName: string
) => {
const wallet = initWallet(hre, networkName);
const zetaNetwork = "athens";
const connectorAddress = getAddress({
address: "connector",
networkName,
zetaNetwork,
});
const zetaTokenAddress = getAddress({
address: "zetaToken",
networkName,
zetaNetwork,
});
const zetaTokenConsumerV2 = getAddress({
address: "zetaTokenConsumerUniV2",
networkName,
zetaNetwork,
});
const zetaTokenConsumerV3 = getAddress({
address: "zetaTokenConsumerUniV3",
networkName,
zetaNetwork,
});

const connector = getAddress("connector", networkName as any);
const zetaToken = getAddress("zetaToken", networkName as any);
const zetaTokenConsumerUniV2 = getAddress(
"zetaTokenConsumerUniV2",
networkName as any
);
const zetaTokenConsumerUniV3 = getAddress(
"zetaTokenConsumerUniV3",
networkName as any
);

const { abi, bytecode } = await hre.artifacts.readArtifact(contractName);
const factory = new ethers.ContractFactory(abi, bytecode, wallet);
const contract = await factory.deploy(
connectorAddress,
zetaTokenAddress,
zetaTokenConsumerV2 || zetaTokenConsumerV3
connector,
zetaToken,
zetaTokenConsumerUniV2 || zetaTokenConsumerUniV3
);

await contract.deployed();
console.log(`
🚀 Successfully deployed contract on ${networkName}.
📜 Contract address: ${contract.address}
`);
📜 Contract address: ${contract.address}`);
return contract.address;
};

Expand Down Expand Up @@ -102,7 +92,7 @@ const setInteractors = async (
["address"],
[contracts[counterparty]]
);
const chainId = getChainId(counterparty as any);
const chainId = hre.config.networks[counterparty].chainId;
await (
await contract.setInteractorByChainId(chainId, counterpartyContract)
).wait();
Expand All @@ -114,5 +104,7 @@ const setInteractors = async (

task("deploy", "Deploy the contract", main).addParam(
"networks",
"Comma separated list of networks to deploy to"
`Comma separated list of networks to deploy to (e.g. ${getSupportedNetworks(
"ccm"
)})`
);
4 changes: 2 additions & 2 deletions templates/messaging/tasks/interact.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {

const tx = await contract
.connect(signer)
.sendHelloWorld(args.destination, { value: parseEther(args.amount) });
.sendMessage(args.destination, { value: parseEther(args.amount) });

const receipt = await tx.wait();
console.log(`✅ "sendHelloWorld" transaction has been broadcasted to ${hre.network.name}
console.log(`✅ The transaction has been broadcasted to ${hre.network.name}
📝 Transaction hash: ${receipt.transactionHash}

Please, refer to ZetaChain's explorer for updates on the progress of the cross-chain transaction.
Expand Down

0 comments on commit 55fac46

Please sign in to comment.