Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Jan 14, 2025
1 parent c0a77f4 commit 63b4a4b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 127 deletions.
10 changes: 5 additions & 5 deletions examples/call/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import "./tasks/universalWithdrawAndCall";
import "@zetachain/localnet/tasks";
import "@nomicfoundation/hardhat-toolbox";
import "@zetachain/toolkit/tasks";
import * as dotenv from "dotenv";

import { getHardhatConfigNetworks } from "@zetachain/networks";
import { getHardhatConfig } from "@zetachain/toolkit/client";
import { HardhatUserConfig } from "hardhat/config";

dotenv.config();

const config: HardhatUserConfig = {
networks: {
...getHardhatConfigNetworks(),
},
solidity: "0.8.26",
...getHardhatConfig({ accounts: [process.env.PRIVATE_KEY] }),
};

export default config;
2 changes: 2 additions & 0 deletions examples/call/scripts/localnet.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

set -e
set -x
set -o pipefail

if [ "$1" = "start" ]; then npx hardhat localnet --exit-on-error & sleep 10; fi

Expand Down
20 changes: 1 addition & 19 deletions examples/call/tasks/connectedCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { ethers } = hre;
const [signer] = await ethers.getSigners();

const txOptions = {
gasPrice: args.txOptionsGasPrice,
gasLimit: args.txOptionsGasLimit,
};

const revertOptions = {
abortAddress: "0x0000000000000000000000000000000000000000", // not used
callOnRevert: args.callOnRevert,
Expand Down Expand Up @@ -54,8 +49,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const tx = await contract.call(
args.receiver,
encodedParameters,
revertOptions,
txOptions
revertOptions
);

await tx.wait();
Expand All @@ -68,18 +62,6 @@ task(
main
)
.addParam("contract", "The address of the deployed contract")
.addOptionalParam(
"txOptionsGasPrice",
"The gas price for the transaction",
20000000000,
types.int
)
.addOptionalParam(
"txOptionsGasLimit",
"The gas limit for the transaction",
500000,
types.int
)
.addFlag("callOnRevert", "Whether to call on revert")
.addOptionalParam(
"revertAddress",
Expand Down
25 changes: 2 additions & 23 deletions examples/call/tasks/connectedDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { ethers } = hre;
const [signer] = await ethers.getSigners();

const txOptions = {
gasPrice: args.txOptionsGasPrice,
gasLimit: args.txOptionsGasLimit,
};

const revertOptions = {
abortAddress: "0x0000000000000000000000000000000000000000", // not used
callOnRevert: args.callOnRevert,
Expand Down Expand Up @@ -43,16 +38,12 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
args.receiver,
value,
args.erc20,
revertOptions,
txOptions
revertOptions
);
} else {
const value = hre.ethers.utils.parseEther(args.amount);
const method = "deposit(address,(address,bool,address,bytes,uint256))";
tx = await contract[method](args.receiver, revertOptions, {
...txOptions,
value,
});
tx = await contract[method](args.receiver, revertOptions, { value });
}

await tx.wait();
Expand All @@ -61,18 +52,6 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {

task("connected-deposit", "Deposit tokens to ZetaChain", main)
.addParam("contract", "The address of the deployed contract")
.addOptionalParam(
"txOptionsGasPrice",
"The gas price for the transaction",
20000000000,
types.int
)
.addOptionalParam(
"txOptionsGasLimit",
"The gas limit for the transaction",
500000,
types.int
)
.addFlag("callOnRevert", "Whether to call on revert")
.addOptionalParam(
"revertAddress",
Expand Down
25 changes: 2 additions & 23 deletions examples/call/tasks/connectedDepositAndCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { ethers } = hre;
const [signer] = await ethers.getSigners();

const txOptions = {
gasPrice: args.txOptionsGasPrice,
gasLimit: args.txOptionsGasLimit,
};

const revertOptions = {
abortAddress: "0x0000000000000000000000000000000000000000", // not used
callOnRevert: args.callOnRevert,
Expand Down Expand Up @@ -72,8 +67,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
value,
args.erc20,
encodedParameters,
revertOptions,
txOptions
revertOptions
);
} else {
const value = hre.ethers.utils.parseEther(args.amount);
Expand All @@ -83,10 +77,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
args.receiver,
encodedParameters,
revertOptions,
{
...txOptions,
value,
}
{ value }
);
}

Expand All @@ -100,18 +91,6 @@ task(
main
)
.addParam("contract", "The address of the deployed contract")
.addOptionalParam(
"txOptionsGasPrice",
"The gas price for the transaction",
20000000000,
types.int
)
.addOptionalParam(
"txOptionsGasLimit",
"The gas limit for the transaction",
500000,
types.int
)
.addFlag("callOnRevert", "Whether to call on revert")
.addOptionalParam(
"revertAddress",
Expand Down
26 changes: 4 additions & 22 deletions examples/call/tasks/universalCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { ethers } = hre;
const [signer] = await ethers.getSigners();

const txOptions = {
gasPrice: args.txOptionsGasPrice,
gasLimit: args.txOptionsGasLimit,
};

const callOptions = {
isArbitraryCall: args.callOptionsIsArbitraryCall,
gasLimit: args.callOptionsGasLimit,
Expand Down Expand Up @@ -60,10 +55,10 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
ethers.utils.concat([functionSignature, encodedParameters])
);

const gasLimit = hre.ethers.BigNumber.from(args.txOptionsGasLimit);
const gasLimit = hre.ethers.BigNumber.from(callOptions.gasLimit);
const zrc20 = new ethers.Contract(args.zrc20, ZRC20ABI.abi, signer);
const [, gasFee] = await zrc20.withdrawGasFeeWithGasLimit(gasLimit);
const zrc20TransferTx = await zrc20.approve(args.contract, gasFee, txOptions);
const zrc20TransferTx = await zrc20.approve(args.contract, gasFee);

await zrc20TransferTx.wait();

Expand All @@ -75,8 +70,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
args.zrc20,
message,
callOptions,
revertOptions,
txOptions
revertOptions
);

await tx.wait();
Expand All @@ -90,18 +84,6 @@ task(
)
.addParam("contract", "The address of the deployed universal contract")
.addParam("zrc20", "The address of ZRC-20 to pay fees")
.addOptionalParam(
"txOptionsGasPrice",
"The gas price for the transaction",
20000000000,
types.int
)
.addOptionalParam(
"txOptionsGasLimit",
"The gas limit for the transaction",
500000,
types.int
)
.addFlag("callOnRevert", "Whether to call on revert")
.addOptionalParam(
"revertAddress",
Expand All @@ -116,7 +98,7 @@ task(
.addOptionalParam(
"onRevertGasLimit",
"The gas limit for the revert transaction",
50000,
500000,
types.int
)
.addFlag("callOptionsIsArbitraryCall", "Call any function")
Expand Down
14 changes: 3 additions & 11 deletions examples/call/tasks/universalWithdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { ethers } = hre;
const [signer] = await ethers.getSigners();

const txOptions = {
gasPrice: args.txOptionsGasPrice,
gasLimit: args.txOptionsGasLimit,
};

const revertOptions = {
abortAddress: "0x0000000000000000000000000000000000000000", // not used
callOnRevert: args.callOnRevert,
Expand All @@ -28,16 +23,14 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const gasZRC20Contract = new ethers.Contract(gasZRC20, ZRC20ABI.abi, signer);
const gasFeeApprove = await gasZRC20Contract.approve(
args.contract,
gasZRC20 == args.zrc20 ? gasFee.add(amount) : gasFee,
txOptions
gasZRC20 == args.zrc20 ? gasFee.add(amount) : gasFee
);
await gasFeeApprove.wait();

if (gasZRC20 !== args.zrc20) {
const targetTokenApprove = await zrc20.approve(
args.contract,
gasFee.add(amount),
txOptions
gasFee.add(amount)
);
await targetTokenApprove.wait();
}
Expand All @@ -49,8 +42,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
ethers.utils.hexlify(args.receiver),
amount,
args.zrc20,
revertOptions,
txOptions
revertOptions
);

await tx.wait();
Expand Down
28 changes: 4 additions & 24 deletions examples/call/tasks/universalWithdrawAndCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
throw new Error("Function is not allowed for non-arbitrary calls");
}

const txOptions = {
gasPrice: args.txOptionsGasPrice,
gasLimit: args.txOptionsGasLimit,
};

const callOptions = {
isArbitraryCall: args.callOptionsIsArbitraryCall,
gasLimit: args.callOptionsGasLimit,
Expand Down Expand Up @@ -73,7 +68,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
message = encodedParameters;
}

const gasLimit = hre.ethers.BigNumber.from(args.txOptionsGasLimit);
const gasLimit = hre.ethers.BigNumber.from(callOptions.gasLimit);

const amount = hre.ethers.utils.parseUnits(args.amount, 18);

Expand All @@ -82,16 +77,14 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const gasZRC20Contract = new ethers.Contract(gasZRC20, ZRC20ABI.abi, signer);
const gasFeeApprove = await gasZRC20Contract.approve(
args.contract,
gasZRC20 == args.zrc20 ? gasFee.add(amount) : gasFee,
txOptions
gasZRC20 == args.zrc20 ? gasFee.add(amount) : gasFee
);
await gasFeeApprove.wait();

if (gasZRC20 !== args.zrc20) {
const targetTokenApprove = await zrc20.approve(
args.contract,
gasFee.add(amount),
txOptions
gasFee.add(amount)
);
await targetTokenApprove.wait();
}
Expand All @@ -105,8 +98,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
args.zrc20,
message,
callOptions,
revertOptions,
txOptions
revertOptions
);

await tx.wait();
Expand All @@ -120,18 +112,6 @@ task(
)
.addParam("contract", "The address of the deployed Hello contract")
.addParam("zrc20", "The address of ZRC-20 to pay fees")
.addOptionalParam(
"txOptionsGasPrice",
"The gas price for the transaction",
20000000000,
types.int
)
.addOptionalParam(
"txOptionsGasLimit",
"The gas limit for the transaction",
500000,
types.int
)
.addFlag("callOnRevert", "Whether to call on revert")
.addOptionalParam(
"revertAddress",
Expand Down

0 comments on commit 63b4a4b

Please sign in to comment.