diff --git a/packages/client/src/evmCall.ts b/packages/client/src/evmCall.ts index 8cd9bc06..d05ee5fa 100644 --- a/packages/client/src/evmCall.ts +++ b/packages/client/src/evmCall.ts @@ -2,19 +2,33 @@ import { ethers } from "ethers"; import GatewayABI from "./abi/GatewayEVM.sol/GatewayEVM.json"; import { ZetaChainClient } from "./client"; +import type { revertOptions, txOptions } from "./types"; + +/** + * @function evmCall + * @description Calls a universal app contract on ZetaChain. + * + * @param {ZetaChainClient} this - The instance of the ZetaChain client that contains the signer information. + * @param {object} args - The function arguments. + * @param {string} args.gatewayEvm - The address of the EVM gateway contract. + * @param {string} args.receiver - The address of the target contract or account to call on the EVM chain. + * @param {string} args.types - JSON string representing the types of the function parameters (e.g., ["uint256", "address"]). + * @param {Array} args.values - The values to be passed to the function (should match the types). + * @param {txOptions} args.txOptions - Transaction options such as gasLimit, gasPrice, etc. + * @param {revertOptions} args.revertOptions - Options to handle call reversion, including revert address, message, and gas limit for the revert scenario. + * + * @returns {object} - Returns the transaction object. + * @property {object} tx - The transaction object that represents the function call. + */ export const evmCall = async function ( this: ZetaChainClient, args: { - callOnRevert: boolean; - gasLimit: number; - gasPrice: ethers.BigNumber; gatewayEvm: string; - onRevertGasLimit: number; receiver: string; - revertAddress: string; - revertMessage: string; - types: string; + revertOptions: revertOptions; + txOptions: txOptions; + types: string[]; values: any[]; } ) { @@ -22,9 +36,8 @@ export const evmCall = async function ( const { utils } = ethers; const gateway = new ethers.Contract(args.gatewayEvm, GatewayABI.abi, signer); - const typesArray = JSON.parse(args.types); const valuesArray = args.values.map((value, index) => { - const type = typesArray[index]; + const type = args.types[index]; if (type === "bool") { try { @@ -40,7 +53,7 @@ export const evmCall = async function ( }); const encodedParameters = utils.defaultAbiCoder.encode( - typesArray, + args.types, valuesArray ); @@ -50,15 +63,17 @@ export const evmCall = async function ( args.receiver, encodedParameters, { - abortAddress: "0x0000000000000000000000000000000000000000", - callOnRevert: args.callOnRevert, - onRevertGasLimit: args.onRevertGasLimit, - revertAddress: args.revertAddress, - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), + abortAddress: "0x0000000000000000000000000000000000000000", // not used + callOnRevert: args.revertOptions.callOnRevert, + onRevertGasLimit: args.revertOptions.onRevertGasLimit, + revertAddress: args.revertOptions.revertAddress, + revertMessage: utils.hexlify( + utils.toUtf8Bytes(args.revertOptions.revertMessage) + ), }, { - gasLimit: args.gasLimit, - gasPrice: args.gasPrice, + gasLimit: args.txOptions.gasLimit, + gasPrice: args.txOptions.gasPrice, } ); diff --git a/packages/client/src/evmDeposit.ts b/packages/client/src/evmDeposit.ts index ba2fc963..de556728 100644 --- a/packages/client/src/evmDeposit.ts +++ b/packages/client/src/evmDeposit.ts @@ -3,20 +3,34 @@ import { ethers } from "ethers"; import GatewayABI from "./abi/GatewayEVM.sol/GatewayEVM.json"; import { ZetaChainClient } from "./client"; +import type { revertOptions, txOptions } from "./types"; + +/** + * @function evmDeposit + * @description Deposits a specified amount of ERC-20 or native gas tokens to a receiver on ZetaChain. + * + * @param {ZetaChainClient} this - The instance of the ZetaChain client that contains the signer information. + * @param {object} args - The function arguments. + * @param {string} args.amount - The amount of ERC20 tokens or native currency to deposit. + * @param {string} args.erc20 - The address of the ERC20 token contract. If depositing native currency (e.g., ETH), this can be left empty or undefined. + * @param {string} args.gatewayEvm - The address of the ZetaChain gateway contract on the EVM-compatible blockchain. + * @param {string} args.receiver - The address of the receiver or target contract for the deposit. + * @param {txOptions} args.txOptions - Transaction options, including gasLimit, gasPrice, etc. + * @param {revertOptions} args.revertOptions - Options to handle call reversion, including revert address, message, and gas limit for the revert scenario. + * + * @returns {object} - Returns the transaction object. + * @property {object} tx - The transaction object representing the deposit transaction. + */ export const evmDeposit = async function ( this: ZetaChainClient, args: { amount: string; - callOnRevert: boolean; erc20: string; - gasLimit: number; - gasPrice: ethers.BigNumber; gatewayEvm: string; - onRevertGasLimit: number; receiver: string; - revertAddress: string; - revertMessage: string; + revertOptions: revertOptions; + txOptions: txOptions; } ) { const signer = this.signer; @@ -24,17 +38,19 @@ export const evmDeposit = async function ( const gateway = new ethers.Contract(args.gatewayEvm, GatewayABI.abi, signer); const revertOptions = { - abortAddress: "0x0000000000000000000000000000000000000000", - callOnRevert: args.callOnRevert, - onRevertGasLimit: args.onRevertGasLimit, - revertAddress: args.revertAddress, + abortAddress: "0x0000000000000000000000000000000000000000", // not used + callOnRevert: args.revertOptions.callOnRevert, + onRevertGasLimit: args.revertOptions.onRevertGasLimit, + revertAddress: args.revertOptions.revertAddress, // not used - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), + revertMessage: utils.hexlify( + utils.toUtf8Bytes(args.revertOptions.revertMessage) + ), }; const txOptions = { - gasLimit: args.gasLimit, - gasPrice: args.gasPrice, + gasLimit: args.txOptions.gasLimit, + gasPrice: args.txOptions.gasPrice, }; let tx; if (args.erc20) { diff --git a/packages/client/src/evmDepositAndCall.ts b/packages/client/src/evmDepositAndCall.ts index 0b36e386..c5a1833d 100644 --- a/packages/client/src/evmDepositAndCall.ts +++ b/packages/client/src/evmDepositAndCall.ts @@ -3,21 +3,37 @@ import { ethers } from "ethers"; import GatewayABI from "./abi/GatewayEVM.sol/GatewayEVM.json"; import { ZetaChainClient } from "./client"; +import type { revertOptions, txOptions } from "./types"; + +/** + * @function evmDepositAndCall + * @description Deposits a specified amount of ERC-20 or native gas tokens and calls a universal app contract on ZetaChain. + * + * @param {ZetaChainClient} this - The instance of the ZetaChain client that contains the signer information. + * @param {object} args - The function arguments. + * @param {string} args.amount - The amount of ERC20 tokens or native currency to deposit. + * @param {string} args.erc20 - The address of the ERC20 token contract. If depositing native currency (e.g., ETH), this can be left empty or undefined. + * @param {string} args.gatewayEvm - The address of the ZetaChain gateway contract on the EVM-compatible blockchain. + * @param {string} args.receiver - The address of the receiver contract or account where the function call will be executed. + * @param {string} args.types - JSON string representing the types of the function parameters (e.g., ["uint256", "address"]). + * @param {Array} args.values - The values to be passed to the function (should match the types). + * @param {txOptions} args.txOptions - Transaction options, including gasLimit, gasPrice, etc. + * @param {revertOptions} args.revertOptions - Options to handle call reversion, including revert address, message, and gas limit for the revert scenario. + * + * @returns {object} - Returns the transaction object. + * @property {object} tx - The transaction object representing the deposit and function call. + */ export const evmDepositAndCall = async function ( this: ZetaChainClient, args: { amount: string; - callOnRevert: boolean; erc20: string; - gasLimit: number; - gasPrice: ethers.BigNumber; gatewayEvm: string; - onRevertGasLimit: number; receiver: string; - revertAddress: string; - revertMessage: string; - types: string; + revertOptions: revertOptions; + txOptions: txOptions; + types: string[]; values: any[]; } ) { @@ -26,22 +42,23 @@ export const evmDepositAndCall = async function ( const gateway = new ethers.Contract(args.gatewayEvm, GatewayABI.abi, signer); const revertOptions = { - abortAddress: "0x0000000000000000000000000000000000000000", - callOnRevert: args.callOnRevert, - onRevertGasLimit: args.onRevertGasLimit, - revertAddress: args.revertAddress, + abortAddress: "0x0000000000000000000000000000000000000000", // not used + callOnRevert: args.revertOptions.callOnRevert, + onRevertGasLimit: args.revertOptions.onRevertGasLimit, + revertAddress: args.revertOptions.revertAddress, // not used - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), + revertMessage: utils.hexlify( + utils.toUtf8Bytes(args.revertOptions.revertMessage) + ), }; const txOptions = { - gasLimit: args.gasLimit, - gasPrice: args.gasPrice, + gasLimit: args.txOptions.gasLimit, + gasPrice: args.txOptions.gasPrice, }; - const typesArray = JSON.parse(args.types); const valuesArray = args.values.map((value, index) => { - const type = typesArray[index]; + const type = args.types[index]; if (type === "bool") { try { @@ -57,7 +74,7 @@ export const evmDepositAndCall = async function ( }); const encodedParameters = utils.defaultAbiCoder.encode( - typesArray, + args.types, valuesArray ); diff --git a/packages/client/src/types.ts b/packages/client/src/types.ts new file mode 100644 index 00000000..92b666e8 --- /dev/null +++ b/packages/client/src/types.ts @@ -0,0 +1,13 @@ +import { ethers } from "ethers"; + +export type revertOptions = { + callOnRevert: boolean; + onRevertGasLimit: number; + revertAddress: string; + revertMessage: string; +}; + +export type txOptions = { + gasLimit: number; + gasPrice: ethers.BigNumber; +}; diff --git a/packages/client/src/zetachainCall.ts b/packages/client/src/zetachainCall.ts index 4772b0d5..8355723e 100644 --- a/packages/client/src/zetachainCall.ts +++ b/packages/client/src/zetachainCall.ts @@ -3,21 +3,40 @@ import { ethers } from "ethers"; import GatewayABI from "./abi/GatewayZEVM.sol/GatewayZEVM.json"; import ZRC20ABI from "./abi/ZRC20.sol/ZRC20.json"; import { ZetaChainClient } from "./client"; +import type { revertOptions, txOptions } from "./types"; + +/** + * @function zetachainCall + * @description Calls a contract on a connected chain. + * + * @param {ZetaChainClient} this - The instance of the ZetaChain client that contains the signer information. + * @param {object} args - The function arguments. + * @param {string} args.function - The name of the function to be executed on the target contract. + * @param {string} args.gatewayZetaChain - The address of the ZetaChain gateway contract. + * @param {string} args.receiver - The address of the contract or account that will receive the call. + * @param {string} args.types - JSON string representing the types of the function parameters (e.g., ["uint256", "address"]). + * @param {Array} args.values - The values to be passed to the function (should match the types). + * @param {string} args.zrc20 - The address of the ZRC20 token contract used for paying gas fees. + * @param {number} args.gasLimit - The amount of gas to be used for the call. + * @param {txOptions} args.txOptions - Transaction options such as gasPrice, nonce, etc. + * @param {revertOptions} args.revertOptions - Options to handle call reversion, including revert address and message. + * + * @returns {object} - Returns an object containing the transaction, gas token, and gas fee. + * @property {object} tx - The transaction object for the cross-chain call. + * @property {string} gasZRC20 - The address of the ZRC20 gas token. + * @property {ethers.BigNumber} gasFee - The amount of gas fee paid for the transaction. + */ export const zetachainCall = async function ( this: ZetaChainClient, args: { - amount: string; - callOnRevert: boolean; function: string; gasLimit: number; - gasPrice: ethers.BigNumber; gatewayZetaChain: string; - onRevertGasLimit: number; receiver: string; - revertAddress: string; - revertMessage: string; - types: string; + revertOptions: revertOptions; + txOptions: txOptions; + types: string[]; values: any[]; zrc20: string; } @@ -32,24 +51,19 @@ export const zetachainCall = async function ( ); const revertOptions = { - abortAddress: "0x0000000000000000000000000000000000000000", - callOnRevert: args.callOnRevert, - onRevertGasLimit: args.onRevertGasLimit, - revertAddress: args.revertAddress, - // not used - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), - }; - - const txOptions = { - gasLimit: args.gasLimit, - gasPrice: args.gasPrice, + abortAddress: "0x0000000000000000000000000000000000000000", // not used + callOnRevert: args.revertOptions.callOnRevert, + onRevertGasLimit: args.revertOptions.onRevertGasLimit, + revertAddress: args.revertOptions.revertAddress, + revertMessage: utils.hexlify( + utils.toUtf8Bytes(args.revertOptions.revertMessage) + ), }; const functionSignature = utils.id(args.function).slice(0, 10); - const typesArray = JSON.parse(args.types); const valuesArray = args.values.map((value, index) => { - const type = typesArray[index]; + const type = args.types[index]; if (type === "bool") { try { @@ -65,7 +79,7 @@ export const zetachainCall = async function ( }); const encodedParameters = utils.defaultAbiCoder.encode( - typesArray, + args.types, valuesArray ); @@ -80,7 +94,7 @@ export const zetachainCall = async function ( const approve = await gasZRC20Contract.approve( args.gatewayZetaChain, gasFee, - txOptions + args.txOptions ); await approve.wait(); const tx = await gateway[ @@ -91,7 +105,7 @@ export const zetachainCall = async function ( message, args.gasLimit, revertOptions, - txOptions + args.txOptions ); - return tx; + return { gasFee, gasZRC20, tx }; }; diff --git a/packages/client/src/zetachainWithdraw.ts b/packages/client/src/zetachainWithdraw.ts index 027249f0..daf6bbfb 100644 --- a/packages/client/src/zetachainWithdraw.ts +++ b/packages/client/src/zetachainWithdraw.ts @@ -3,19 +3,35 @@ import { ethers } from "ethers"; import GatewayABI from "./abi/GatewayZEVM.sol/GatewayZEVM.json"; import ZRC20ABI from "./abi/ZRC20.sol/ZRC20.json"; import { ZetaChainClient } from "./client"; +import type { revertOptions, txOptions } from "./types"; + +/** + * @function zetachainWithdraw + * @description Withdraws a specified amount of ZRC20 tokens from ZetaChain to a connected chain. + * + * @param {ZetaChainClient} this - The instance of the ZetaChain client that contains the signer information. + * @param {object} args - The function arguments. + * @param {string} args.amount - The amount of ZRC20 tokens to withdraw. + * @param {string} args.gatewayZetaChain - The address of the ZetaChain gateway contract. + * @param {string} args.receiver - The address that will receive the withdrawn ZRC20 tokens. + * @param {string} args.zrc20 - The address of the ZRC20 token contract from which the withdrawal will be made. + * @param {txOptions} args.txOptions - Transaction options such as gasPrice, nonce, etc. + * @param {revertOptions} args.revertOptions - Options to handle call reversion, including revert address and message. + * + * @returns {object} - Returns an object containing the transaction, gas token, and gas fee. + * @property {object} tx - The transaction object for the withdrawal. + * @property {string} gasZRC20 - The address of the ZRC20 gas token. + * @property {ethers.BigNumber} gasFee - The amount of gas fee paid for the transaction. + */ export const zetachainWithdraw = async function ( this: ZetaChainClient, args: { amount: string; - callOnRevert: boolean; - gasLimit: number; - gasPrice: ethers.BigNumber; gatewayZetaChain: string; - onRevertGasLimit: number; receiver: string; - revertAddress: string; - revertMessage: string; + revertOptions: revertOptions; + txOptions: txOptions; zrc20: string; } ) { @@ -30,28 +46,23 @@ export const zetachainWithdraw = async function ( const revertOptions = { abortAddress: "0x0000000000000000000000000000000000000000", - callOnRevert: args.callOnRevert, - onRevertGasLimit: args.onRevertGasLimit, - revertAddress: args.revertAddress, - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), - }; - - const txOptions = { - gasLimit: args.gasLimit, - gasPrice: args.gasPrice, + callOnRevert: args.revertOptions.callOnRevert, + onRevertGasLimit: args.revertOptions.onRevertGasLimit, + revertAddress: args.revertOptions.revertAddress, + revertMessage: utils.hexlify( + utils.toUtf8Bytes(args.revertOptions.revertMessage) + ), }; const zrc20 = new ethers.Contract(args.zrc20, ZRC20ABI.abi, signer); const decimals = await zrc20.decimals(); const value = utils.parseUnits(args.amount, decimals); - const [gasZRC20, gasFee] = await zrc20.withdrawGasFeeWithGasLimit( - args.gasLimit - ); + const [gasZRC20, gasFee] = await zrc20.withdrawGasFee(); if (args.zrc20 === gasZRC20) { const approveGasAndWithdraw = await zrc20.approve( args.gatewayZetaChain, value.add(gasFee), - txOptions + args.txOptions ); await approveGasAndWithdraw.wait(); } else { @@ -63,13 +74,13 @@ export const zetachainWithdraw = async function ( const approveGas = await gasZRC20Contract.approve( args.gatewayZetaChain, gasFee, - txOptions + args.txOptions ); await approveGas.wait(); const approveWithdraw = await zrc20.approve( args.gatewayZetaChain, value, - txOptions + args.txOptions ); await approveWithdraw.wait(); } @@ -80,7 +91,7 @@ export const zetachainWithdraw = async function ( value, args.zrc20, revertOptions, - txOptions + args.txOptions ); - return tx; + return { gasFee, gasZRC20, tx }; }; diff --git a/packages/client/src/zetachainWithdrawAndCall.ts b/packages/client/src/zetachainWithdrawAndCall.ts index b8547fee..91d8521a 100644 --- a/packages/client/src/zetachainWithdrawAndCall.ts +++ b/packages/client/src/zetachainWithdrawAndCall.ts @@ -3,21 +3,42 @@ import { ethers } from "ethers"; import GatewayABI from "./abi/GatewayZEVM.sol/GatewayZEVM.json"; import ZRC20ABI from "./abi/ZRC20.sol/ZRC20.json"; import { ZetaChainClient } from "./client"; +import type { revertOptions, txOptions } from "./types"; + +/** + * @function zetachainWithdrawAndCall + * @description Withdraws a specified amount of ZRC20 tokens and makes a function call on the target contract on a connected chain. + * + * @param {ZetaChainClient} this - The instance of the ZetaChain client that contains the signer information. + * @param {object} args - The function arguments. + * @param {string} args.amount - The amount of ZRC20 tokens to withdraw. + * @param {string} args.function - The name of the function to be called on the target contract. + * @param {string} args.gatewayZetaChain - The address of the ZetaChain gateway contract. + * @param {string} args.receiver - The address that will receive the withdrawn ZRC20 tokens or the contract to interact with. + * @param {string} args.types - JSON string representing the types of the function parameters (e.g., ["uint256", "address"]). + * @param {Array} args.values - The values to be passed to the function (should match the types). + * @param {string} args.zrc20 - The address of the ZRC20 token contract used for the withdrawal and fee payment. + * @param {number} args.gasLimit - The gas limit for the transaction. + * @param {txOptions} args.txOptions - Transaction options such as gasPrice, nonce, etc. + * @param {revertOptions} args.revertOptions - Options to handle call reversion, including revert address and message. + * + * @returns {object} - Returns an object containing the transaction, gas token, and gas fee. + * @property {object} tx - The transaction object for the withdrawal and contract call. + * @property {string} gasZRC20 - The address of the ZRC20 gas token. + * @property {ethers.BigNumber} gasFee - The amount of gas fee paid for the transaction. + */ export const zetachainWithdrawAndCall = async function ( this: ZetaChainClient, args: { amount: string; - callOnRevert: boolean; function: string; gasLimit: number; - gasPrice: ethers.BigNumber; gatewayZetaChain: string; - onRevertGasLimit: number; receiver: string; - revertAddress: string; - revertMessage: string; - types: string; + revertOptions: revertOptions; + txOptions: txOptions; + types: string[]; values: any[]; zrc20: string; } @@ -33,22 +54,18 @@ export const zetachainWithdrawAndCall = async function ( const revertOptions = { abortAddress: "0x0000000000000000000000000000000000000000", - callOnRevert: args.callOnRevert, - onRevertGasLimit: args.onRevertGasLimit, - revertAddress: args.revertAddress, - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), - }; - - const txOptions = { - gasLimit: args.gasLimit, - gasPrice: args.gasPrice, + callOnRevert: args.revertOptions.callOnRevert, + onRevertGasLimit: args.revertOptions.onRevertGasLimit, + revertAddress: args.revertOptions.revertAddress, + revertMessage: utils.hexlify( + utils.toUtf8Bytes(args.revertOptions.revertMessage) + ), }; const functionSignature = utils.id(args.function).slice(0, 10); - const typesArray = JSON.parse(args.types); const valuesArray = args.values.map((value, index) => { - const type = typesArray[index]; + const type = args.types[index]; if (type === "bool") { try { @@ -64,7 +81,7 @@ export const zetachainWithdrawAndCall = async function ( }); const encodedParameters = utils.defaultAbiCoder.encode( - typesArray, + args.types, valuesArray ); @@ -81,7 +98,7 @@ export const zetachainWithdrawAndCall = async function ( const approveGasAndWithdraw = await zrc20.approve( args.gatewayZetaChain, value.add(gasFee), - txOptions + args.txOptions ); await approveGasAndWithdraw.wait(); } else { @@ -93,13 +110,13 @@ export const zetachainWithdrawAndCall = async function ( const approveGas = await gasZRC20Contract.approve( args.gatewayZetaChain, gasFee, - txOptions + args.txOptions ); await approveGas.wait(); const approveWithdraw = await zrc20.approve( args.gatewayZetaChain, value, - txOptions + args.txOptions ); await approveWithdraw.wait(); } @@ -112,7 +129,7 @@ export const zetachainWithdrawAndCall = async function ( message, args.gasLimit, revertOptions, - txOptions + args.txOptions ); - return tx; + return { gasFee, gasZRC20, tx }; }; diff --git a/packages/tasks/src/evmCall.ts b/packages/tasks/src/evmCall.ts index c170bd2b..6258c936 100644 --- a/packages/tasks/src/evmCall.ts +++ b/packages/tasks/src/evmCall.ts @@ -8,15 +8,19 @@ export const evmCall = async (args: any, hre: HardhatRuntimeEnvironment) => { const [signer] = await hre.ethers.getSigners(); const client = new ZetaChainClient({ network: "testnet", signer }); const tx = await client.evmCall({ - callOnRevert: args.callOnRevert, - gasLimit: args.gasLimit, - gasPrice: args.gasPrice, gatewayEvm: args.gatewayEvm, - onRevertGasLimit: args.onRevertGasLimit, receiver: args.receiver, - revertAddress: args.revertAddress, - revertMessage: args.revertMessage, - types: args.types, + revertOptions: { + callOnRevert: args.callOnRevert, + onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + revertMessage: args.revertMessage, + }, + txOptions: { + gasLimit: args.gasLimit, + gasPrice: args.gasPrice, + }, + types: JSON.parse(args.types), values: args.values, }); const receipt = await tx.wait(); @@ -58,5 +62,5 @@ task("evm-call", "Call a universal app", evmCall) types.int ) .addOptionalParam("revertMessage", "Revert message", "0x") - .addParam("types", "The types of the parameters (example: ['string'])") + .addParam("types", `The types of the parameters (example: '["string"]')`) .addVariadicPositionalParam("values", "The values of the parameters"); diff --git a/packages/tasks/src/evmDeposit.ts b/packages/tasks/src/evmDeposit.ts index 31b4815b..f2568af2 100644 --- a/packages/tasks/src/evmDeposit.ts +++ b/packages/tasks/src/evmDeposit.ts @@ -9,15 +9,19 @@ export const evmDeposit = async (args: any, hre: HardhatRuntimeEnvironment) => { const client = new ZetaChainClient({ network: "testnet", signer }); const tx = await client.evmDeposit({ amount: args.amount, - callOnRevert: args.callOnRevert, erc20: args.erc20, - gasLimit: args.gasLimit, - gasPrice: args.gasPrice, gatewayEvm: args.gatewayEvm, - onRevertGasLimit: args.onRevertGasLimit, receiver: args.receiver, - revertAddress: args.revertAddress, - revertMessage: args.revertMessage, + revertOptions: { + callOnRevert: args.callOnRevert, + onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + revertMessage: args.revertMessage, + }, + txOptions: { + gasLimit: args.gasLimit, + gasPrice: args.gasPrice, + }, }); if (tx) { const receipt = await tx.wait(); diff --git a/packages/tasks/src/evmDepositAndCall.ts b/packages/tasks/src/evmDepositAndCall.ts index 7b1231f8..5045bdce 100644 --- a/packages/tasks/src/evmDepositAndCall.ts +++ b/packages/tasks/src/evmDepositAndCall.ts @@ -12,16 +12,20 @@ export const evmDepositAndCall = async ( const client = new ZetaChainClient({ network: "testnet", signer }); const tx = await client.evmDepositAndCall({ amount: args.amount, - callOnRevert: args.callOnRevert, erc20: args.erc20, - gasLimit: args.gasLimit, - gasPrice: args.gasPrice, gatewayEvm: args.gatewayEvm, - onRevertGasLimit: args.onRevertGasLimit, receiver: args.receiver, - revertAddress: args.revertAddress, - revertMessage: args.revertMessage, - types: args.types, + revertOptions: { + callOnRevert: args.callOnRevert, + onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + revertMessage: args.revertMessage, + }, + txOptions: { + gasLimit: args.gasLimit, + gasPrice: args.gasPrice, + }, + types: JSON.parse(args.types), values: args.values, }); if (tx) { @@ -68,5 +72,5 @@ task("evm-deposit-and-call", "Deposit tokens", evmDepositAndCall) .addOptionalParam("revertMessage", "Revert message", "0x") .addParam("amount", "amount of ETH to send with the transaction") .addOptionalParam("erc20", "ERC-20 token address") - .addParam("types", "The types of the parameters (example: ['string'])") + .addParam("types", `The types of the parameters (example: '["string"]')`) .addVariadicPositionalParam("values", "The values of the parameters"); diff --git a/packages/tasks/src/zetachainCall.ts b/packages/tasks/src/zetachainCall.ts index e2a22d0c..1def729c 100644 --- a/packages/tasks/src/zetachainCall.ts +++ b/packages/tasks/src/zetachainCall.ts @@ -10,22 +10,26 @@ export const zetachainCall = async ( try { const [signer] = await hre.ethers.getSigners(); const client = new ZetaChainClient({ network: "testnet", signer }); - const tx = await client.zetachainCall({ - amount: args.amount, - callOnRevert: args.callOnRevert, + const response = await client.zetachainCall({ function: args.function, gasLimit: args.gasLimit, - gasPrice: args.gasPrice, gatewayZetaChain: args.gatewayZetaChain, - onRevertGasLimit: args.onRevertGasLimit, receiver: args.receiver, - revertAddress: args.revertAddress, - revertMessage: args.revertMessage, - types: args.types, + revertOptions: { + callOnRevert: args.callOnRevert, + onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + revertMessage: args.revertMessage, + }, + txOptions: { + gasLimit: args.txOptionsGasLimit, + gasPrice: args.txOptionsGasPrice, + }, + types: JSON.parse(args.types), values: args.values, zrc20: args.zrc20, }); - const receipt = await tx.wait(); + const receipt = await response.tx.wait(); console.log("Transaction hash:", receipt.transactionHash); } catch (e) { console.error("Transaction error:", e); @@ -46,19 +50,19 @@ task("zetachain-call", "Call a contract on a connected chain", zetachainCall) "0x0000000000000000000000000000000000000000" ) .addOptionalParam( - "callGasLimit", + "gasLimit", "The gas limit for the transaction", 7000000, types.int ) .addOptionalParam( - "gasPrice", + "txOptionsGasPrice", "The gas price for the transaction", 10000000000, types.int ) .addOptionalParam( - "gasLimit", + "txOptionsGasLimit", "The gas limit for the transaction", 7000000, types.int @@ -74,6 +78,6 @@ task("zetachain-call", "Call a contract on a connected chain", zetachainCall) 7000000, types.int ) - .addParam("function", "Function to call (example: 'hello(string)')") - .addParam("types", "The types of the parameters (example: ['string'])") + .addParam("function", `Function to call (example: "hello(string)")`) + .addParam("types", `The types of the parameters (example: '["string"]')`) .addVariadicPositionalParam("values", "The values of the parameters"); diff --git a/packages/tasks/src/zetachainWithdraw.ts b/packages/tasks/src/zetachainWithdraw.ts index 6ed57051..da26a60e 100644 --- a/packages/tasks/src/zetachainWithdraw.ts +++ b/packages/tasks/src/zetachainWithdraw.ts @@ -10,20 +10,24 @@ export const zetachainWithdraw = async ( try { const [signer] = await hre.ethers.getSigners(); const client = new ZetaChainClient({ network: "testnet", signer }); - const tx = await client.zetachainWithdraw({ + const response = await client.zetachainWithdraw({ amount: args.amount, - callOnRevert: args.callOnRevert, - gasLimit: args.gasLimit, - gasPrice: args.gasPrice, gatewayZetaChain: args.gatewayZetaChain, - onRevertGasLimit: args.onRevertGasLimit, receiver: args.receiver, - revertAddress: args.revertAddress, - revertMessage: args.revertMessage, + revertOptions: { + callOnRevert: args.callOnRevert, + onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + revertMessage: args.revertMessage, + }, + txOptions: { + gasLimit: args.txOptionsGasLimit, + gasPrice: args.txOptionsGasPrice, + }, zrc20: args.zrc20, }); - const receipt = await tx.wait(); + const receipt = await response.tx.wait(); console.log("Transaction hash:", receipt.transactionHash); } catch (e) { console.error("Transaction error:", e); @@ -44,13 +48,13 @@ task("zetachain-withdraw", "Withdraw tokens from ZetaChain", zetachainWithdraw) "0x0000000000000000000000000000000000000000" ) .addOptionalParam( - "gasPrice", + "txOptionsGasPrice", "The gas price for the transaction", 10000000000, types.int ) .addOptionalParam( - "gasLimit", + "txOptionsGasLimit", "The gas limit for the transaction", 7000000, types.int diff --git a/packages/tasks/src/zetachainWithdrawAndCall.ts b/packages/tasks/src/zetachainWithdrawAndCall.ts index e686accc..24506818 100644 --- a/packages/tasks/src/zetachainWithdrawAndCall.ts +++ b/packages/tasks/src/zetachainWithdrawAndCall.ts @@ -10,23 +10,28 @@ export const zetachainWithdrawAndCall = async ( try { const [signer] = await hre.ethers.getSigners(); const client = new ZetaChainClient({ network: "testnet", signer }); - const tx = await client.zetachainWithdrawAndCall({ + const response = await client.zetachainWithdrawAndCall({ amount: args.amount, - callOnRevert: args.callOnRevert, function: args.function, gasLimit: args.gasLimit, - gasPrice: args.gasPrice, gatewayZetaChain: args.gatewayZetaChain, - onRevertGasLimit: args.onRevertGasLimit, receiver: args.receiver, - revertAddress: args.revertAddress, - revertMessage: args.revertMessage, - types: args.types, + revertOptions: { + callOnRevert: args.callOnRevert, + onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + revertMessage: args.revertMessage, + }, + txOptions: { + gasLimit: args.txOptionsGasLimit, + gasPrice: args.txOptionsGasPrice, + }, + types: JSON.parse(args.types), values: args.values, zrc20: args.zrc20, }); - const receipt = await tx.wait(); + const receipt = await response.tx.wait(); console.log("Transaction hash:", receipt.transactionHash); } catch (e) { console.error("Transaction error:", e); @@ -51,13 +56,13 @@ task( "0x0000000000000000000000000000000000000000" ) .addOptionalParam( - "gasPrice", + "txOptionsGasPrice", "The gas price for the transaction", 10000000000, types.int ) .addOptionalParam( - "gasLimit", + "txOptionsGasLimit", "The gas limit for the transaction", 7000000, types.int @@ -74,6 +79,6 @@ task( types.int ) .addParam("amount", "The amount of tokens to send") - .addParam("function", "Function to call (example: 'hello(string)')") - .addParam("types", "The types of the parameters (example: ['string'])") + .addParam("function", `Function to call (example: "hello(string)")`) + .addParam("types", `The types of the parameters (example: '["string"]')`) .addVariadicPositionalParam("values", "The values of the parameters");