zeta-chain / localnet

ZetaChain's local dev environment with connected EVM chains.
https://www.zetachain.com/docs/developers/tutorials/localnet/
MIT License
6 stars 2 forks source link

`gatewayZEVM.call` does emit a `Called` event #17

Closed fadeev closed 2 months ago

fadeev commented 2 months ago

Using branch from this PR https://github.com/zeta-chain/localnet/pull/16

Example is universal/hello from https://github.com/zeta-chain/example-contracts/pull/189

    function callFromZetaChain(
        bytes memory receiver,
        address zrc20,
        bytes calldata message,
        uint256 gasLimit,
        RevertOptions memory revertOptions
    ) external {
        IGatewayZEVM(gateway).call(
            receiver,
            zrc20,
            message,
            gasLimit,
            revertOptions
        );
    }
import { task, types } from "hardhat/config";
import type { HardhatRuntimeEnvironment } from "hardhat/types";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
  const [signer] = await hre.ethers.getSigners();

  const contractArtifact = await hre.artifacts.readArtifact("Hello");
  const contract = new hre.ethers.Contract(
    args.contract,
    contractArtifact.abi,
    signer
  );

  const message = hre.ethers.utils.defaultAbiCoder.encode(
    ["string"],
    [args.message]
  );

  const revertMessageBytes = hre.ethers.utils.toUtf8Bytes(args.revertMessage);

  try {
    const tx = await contract.callFromZetaChain(
      hre.ethers.utils.hexlify(args.receiver),
      args.zrc20,
      message,
      args.gasLimit,
      {
        revertAddress: args.revertAddress,
        callOnRevert: args.callOnRevert,
        abortAddress: "0x0000000000000000000000000000000000000000", // not used
        revertMessage: hre.ethers.utils.hexlify(revertMessageBytes),
      },
      {
        gasPrice: 10000000000,
        gasLimit: 7000000,
      }
    );

    await tx.wait();
    console.log("Successfully called the contract on ZetaChain!");
  } catch (e) {
    console.error("Error calling contract:", e);
  }
};

task(
  "call-from-zetachain",
  "Calls the callFromZetaChain function on a universal app",
  main
)
  .addParam("message", "A message")
  .addParam("contract", "The address of the universal app on ZetaChain")
  .addOptionalParam(
    "zrc20",
    "The address of the ZRC20 token",
    "0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c"
  )
  .addParam("gasLimit", "The gas limit for the transaction", 7000000, types.int)
  .addFlag("callOnRevert", "Whether to call on revert")
  .addParam("revertAddress")
  .addParam("revertMessage")
  .addParam("receiver", "The address of the receiver contract on EVM");
npx hardhat call-from-zetachain --message alice  --network localhost --revert-address 0x9A676e781A523b5d0C0e43731313A708CB607508 --revert-message "my revert message" --call-on-revert --contract 0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82 --receiver 0x9A676e781A523b5d0C0e43731313A708CB607508

Ts is processed fine in localnet:

eth_chainId
eth_sendTransaction

    Transaction: 0xe12d713fae1ef9566bb7bfa0c78b6fe7a57b13fdb0521cf795090c45acd5f904
    Gas used: 24392

    Block Number: 20
    Block Hash: 0x20273a00c78b1651e4a2ef5dbc2b159160a3556804f9bb46f43ec1597057e09f
    Block Time: "Tue, 20 Aug 2024 13:25:34 +0000"

eth_chainId
eth_getTransactionByHash
eth_chainId

But I'm not seeing the event:

cast logs --address 0x610178dA211FEF7D417bC0e6FeD39F05609AD788
- address: 0x610178dA211FEF7D417bC0e6FeD39F05609AD788
  blockHash: 0x7e5289544ce6fa98404fb6dedd3bf1fb1b3b27bc7cd2ed4304f39debd291a202
  blockNumber: 11
  data: 0x
  logIndex: 0
  removed: false
  topics: [
        0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b
        0x0000000000000000000000008a791620dd6260079bf849dc5567adc3f2fdc318
  ]
  transactionHash: 0x536906ac4a3c58770cce1518ac44cd0f7d60c92138d03b3ddd6f86dbd3b61fa5
  transactionIndex: 0
- address: 0x610178dA211FEF7D417bC0e6FeD39F05609AD788
  blockHash: 0x7e5289544ce6fa98404fb6dedd3bf1fb1b3b27bc7cd2ed4304f39debd291a202
  blockNumber: 11
  data: 0x
  logIndex: 1
  removed: false
  topics: [
        0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d
        0x0000000000000000000000000000000000000000000000000000000000000000
        0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266
        0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266
  ]
  transactionHash: 0x536906ac4a3c58770cce1518ac44cd0f7d60c92138d03b3ddd6f86dbd3b61fa5
  transactionIndex: 0
- address: 0x610178dA211FEF7D417bC0e6FeD39F05609AD788
  blockHash: 0x7e5289544ce6fa98404fb6dedd3bf1fb1b3b27bc7cd2ed4304f39debd291a202
  blockNumber: 11
  data: 0x
  logIndex: 2
  removed: false
  topics: [
        0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d
        0x65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a
        0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266
        0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266
  ]
  transactionHash: 0x536906ac4a3c58770cce1518ac44cd0f7d60c92138d03b3ddd6f86dbd3b61fa5
  transactionIndex: 0
- address: 0x610178dA211FEF7D417bC0e6FeD39F05609AD788
  blockHash: 0x7e5289544ce6fa98404fb6dedd3bf1fb1b3b27bc7cd2ed4304f39debd291a202
  blockNumber: 11
  data: 0x0000000000000000000000000000000000000000000000000000000000000001
  logIndex: 3
  removed: false
  topics: [
        0xc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2
  ]
  transactionHash: 0x536906ac4a3c58770cce1518ac44cd0f7d60c92138d03b3ddd6f86dbd3b61fa5
  transactionIndex: 0

And localnet does not console.log anything.

fadeev commented 2 months ago

@skosito