|
| 1 | +import path from "path"; |
| 2 | +import fs from "fs"; |
| 3 | +import { ethers } from "ethers"; |
| 4 | +import { Command } from "commander"; |
| 5 | + |
| 6 | +export const getAbi = (name: string) => { |
| 7 | + const abiPath = path.resolve( |
| 8 | + __dirname, |
| 9 | + path.join("..", "artifacts", "contracts", `${name}.sol`, `${name}.json`) |
| 10 | + ); |
| 11 | + return JSON.parse(fs.readFileSync(abiPath, "utf8")); |
| 12 | +}; |
| 13 | + |
| 14 | +export const createRevertOptions = (options: { |
| 15 | + abortAddress: string; |
| 16 | + callOnRevert: boolean; |
| 17 | + onRevertGasLimit: string; |
| 18 | + revertAddress: string; |
| 19 | + revertMessage: string; |
| 20 | +}) => { |
| 21 | + return { |
| 22 | + abortAddress: options.abortAddress, |
| 23 | + callOnRevert: options.callOnRevert, |
| 24 | + onRevertGasLimit: BigInt(options.onRevertGasLimit), |
| 25 | + revertAddress: options.revertAddress, |
| 26 | + revertMessage: ethers.hexlify(ethers.toUtf8Bytes(options.revertMessage)), |
| 27 | + }; |
| 28 | +}; |
| 29 | + |
| 30 | +export const createCommand = (name: string) => { |
| 31 | + return new Command(name) |
| 32 | + .requiredOption( |
| 33 | + "-c, --contract <address>", |
| 34 | + "The address of the deployed contract" |
| 35 | + ) |
| 36 | + .requiredOption( |
| 37 | + "-r, --receiver <address>", |
| 38 | + "The address of the receiver contract" |
| 39 | + ) |
| 40 | + .option("--call-on-revert", "Whether to call on revert", false) |
| 41 | + .option( |
| 42 | + "--revert-address <address>", |
| 43 | + "Revert address", |
| 44 | + "0x0000000000000000000000000000000000000000" |
| 45 | + ) |
| 46 | + .option( |
| 47 | + "--abort-address <address>", |
| 48 | + "Abort address", |
| 49 | + "0x0000000000000000000000000000000000000000" |
| 50 | + ) |
| 51 | + .option("--revert-message <string>", "Revert message", "0x") |
| 52 | + .option( |
| 53 | + "--on-revert-gas-limit <number>", |
| 54 | + "Gas limit for revert tx", |
| 55 | + "500000" |
| 56 | + ) |
| 57 | + .option("-n, --name <contract>", "Contract name", "Connected") |
| 58 | + .option( |
| 59 | + "--rpc <url>", |
| 60 | + "RPC endpoint", |
| 61 | + "https://zetachain-athens-evm.blockpi.network/v1/rpc/public" |
| 62 | + ) |
| 63 | + .option("--private-key <key>", "Private key to sign the transaction"); |
| 64 | +}; |
0 commit comments