From e1d09d7b043b6ef6028cda8baa3d441e7c87a86b Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Fri, 13 Sep 2024 13:44:46 +0800 Subject: [PATCH] wip --- examples/hello/contracts/Revert.sol | 21 +++++++++++++++++++ examples/hello/tasks/deployRevert.ts | 31 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 examples/hello/contracts/Revert.sol create mode 100644 examples/hello/tasks/deployRevert.ts diff --git a/examples/hello/contracts/Revert.sol b/examples/hello/contracts/Revert.sol new file mode 100644 index 00000000..aa0b821e --- /dev/null +++ b/examples/hello/contracts/Revert.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.26; + +import {RevertContext} from "@zetachain/protocol-contracts/contracts/Revert.sol"; + +contract Revert { + event RevertEvent(string, RevertContext); + event HelloEvent(string, string); + + function hello(string memory message) external { + emit HelloEvent("Hello on EVM", message); + } + + function onRevert(RevertContext calldata revertContext) external { + emit RevertEvent("Revert on EVM", revertContext); + } + + receive() external payable {} + + fallback() external payable {} +} diff --git a/examples/hello/tasks/deployRevert.ts b/examples/hello/tasks/deployRevert.ts new file mode 100644 index 00000000..080808c7 --- /dev/null +++ b/examples/hello/tasks/deployRevert.ts @@ -0,0 +1,31 @@ +import { task, types } from "hardhat/config"; +import { HardhatRuntimeEnvironment } from "hardhat/types"; + +const main = async (args: any, hre: HardhatRuntimeEnvironment) => { + const network = hre.network.name; + + const [signer] = await hre.ethers.getSigners(); + if (signer === undefined) { + throw new Error( + `Wallet not found. Please, run "npx hardhat account --save" or set PRIVATE_KEY env variable (for example, in a .env file)` + ); + } + + const factory = await hre.ethers.getContractFactory(args.name); + const contract = await (factory as any).deploy(); + await contract.deployed(); + + if (args.json) { + console.log(JSON.stringify(contract)); + } else { + console.log(`🔑 Using account: ${signer.address} + +🚀 Successfully deployed "${args.name}" contract on ${network}. +📜 Contract address: ${contract.address} +`); + } +}; + +task("deploy-revert", "Deploy the contract", main) + .addFlag("json", "Output in JSON") + .addOptionalParam("name", "Contract to deploy", "Revert");