Skip to content

Commit

Permalink
add simple task to call receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Jul 2, 2024
1 parent d94d8ff commit 290a84e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
20 changes: 0 additions & 20 deletions scripts/gatewayEVMdeposit.ts

This file was deleted.

16 changes: 16 additions & 0 deletions scripts/readme.md
Original file line number Diff line number Diff line change
@@ -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.



12 changes: 9 additions & 3 deletions scripts/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>) => {
console.log("EVM: GatewayEVM Deposit event:", args);
console.log("payload: ", args[5].args["payload"]);
gatewayZEVM.on("Call", async (...args: Array<any>) => {
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();
Expand Down
26 changes: 26 additions & 0 deletions tasks/localnet.ts
Original file line number Diff line number Diff line change
@@ -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");
});

0 comments on commit 290a84e

Please sign in to comment.