diff --git a/hardhat.config.ts b/hardhat.config.ts index 263a02c4..8fdc1844 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -7,6 +7,7 @@ import "uniswap-v2-deploy-plugin"; import "solidity-coverage"; import "hardhat-gas-reporter"; import "./tasks/addresses"; +import "./tasks/localnet"; import "@openzeppelin/hardhat-upgrades"; import { getHardhatConfigNetworks } from "@zetachain/networks"; diff --git a/scripts/gatewayEVMdeposit.ts b/scripts/gatewayEVMdeposit.ts deleted file mode 100644 index 2c5bd66a..00000000 --- a/scripts/gatewayEVMdeposit.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { ethers } from "hardhat"; - -const hre = require("hardhat"); - -async function main() { - const gatewayEVMAddress = "0xAD523115cd35a8d4E60B3C0953E0E0ac10418309"; - const gatewayEVM = await hre.ethers.getContractAt("GatewayEVM", gatewayEVMAddress); - let [, , destination] = await ethers.getSigners(); - - const deposit = await gatewayEVM["deposit(address)"](destination.address, { value: ethers.utils.parseEther("1") }); - - console.log("deposit hash:", deposit.hash); -} - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); diff --git a/scripts/readme.md b/scripts/readme.md new file mode 100644 index 00000000..6c9254c3 --- /dev/null +++ b/scripts/readme.md @@ -0,0 +1,16 @@ +## Worker script + +To start local hardhat node execute: + +``` +yarn localnode +``` + +To start localnet using local hardhat: +``` +yarn localnet +``` +This will run worker script, which will deploy all contracts, and listen and react to events, facilitating communication between contracts. + + + diff --git a/scripts/worker.ts b/scripts/worker.ts index 9403ce88..f1ac5c64 100644 --- a/scripts/worker.ts +++ b/scripts/worker.ts @@ -117,9 +117,15 @@ export const startLocalnet = async () => { await ZRC20Contract.connect(fungibleModuleSigner).deposit(senderZEVM.address, parseEther("100")); console.log("ZEVM: Fungible module deposited 100TKN to sender:", senderZEVM.address); - gatewayEVM.on("Deposit", (...args: Array) => { - console.log("EVM: GatewayEVM Deposit event:", args); - console.log("payload: ", args[5].args["payload"]); + gatewayZEVM.on("Call", async (...args: Array) => { + console.log("Worker: Call event on GatewayZEVM."); + console.log("Worker: Calling ReceiverEVM through GatewayEVM..."); + const executeTx = await gatewayEVM.execute(receiverEVM.address, args[3].args.message, { value: 0 }); + await executeTx.wait(); + }); + + receiverEVM.on("ReceivedA", () => { + console.log("ReceiverEVM: receiveA called!"); }); process.stdin.resume(); diff --git a/tasks/localnet.ts b/tasks/localnet.ts new file mode 100644 index 00000000..aa4fa049 --- /dev/null +++ b/tasks/localnet.ts @@ -0,0 +1,26 @@ +import { task } from "hardhat/config"; + +declare const hre: any; + +// Contains tasks to make it easier to interact with prototype contracts localnet +// To make use of default contract addresses on localnet, start localnode and localnet from scratch, so contracts are deployed on same addresses +// Otherwise, provide custom addresses as parameters + +task("call-evm-receiver", "calls evm receiver from zevm account") + .addOptionalParam("gatewayZEVM", "contract address of gateway on ZEVM", "0x5133BBdfCCa3Eb4F739D599ee4eC45cBCD0E16c5") + .addOptionalParam("receiverEVM", "contract address of receiver on EVM", "0xB06c856C8eaBd1d8321b687E188204C1018BC4E5") + .setAction(async (taskArgs) => { + const gatewayZEVM = await hre.ethers.getContractAt("GatewayZEVM", taskArgs.gatewayZEVM); + const receiverEVM = await hre.ethers.getContractAt("ReceiverEVM", taskArgs.receiverEVM); + + const str = "Hello!"; + const num = 42; + const flag = true; + + // Encode the function call data and call on zevm + const message = receiverEVM.interface.encodeFunctionData("receiveA", [str, num, flag]); + const callTx = await gatewayZEVM.call(hre.ethers.utils.arrayify(receiverEVM.address), message); + + await callTx.wait(); + console.log("ReceiverEVM called from ZEVM"); + });