-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
532 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { task, types } from "hardhat/config"; | ||
import type { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import GatewayABI from "./abi/GatewayEVM.sol/GatewayEVM.json"; | ||
|
||
export const evmCall = async (args: any, hre: HardhatRuntimeEnvironment) => { | ||
const [signer] = await hre.ethers.getSigners(); | ||
const { utils } = hre.ethers; | ||
|
||
const gateway = new hre.ethers.Contract( | ||
args.gatewayEvm, | ||
GatewayABI.abi, | ||
signer | ||
); | ||
|
||
const encodedParameters = utils.defaultAbiCoder.encode( | ||
JSON.parse(args.types), | ||
args.values | ||
); | ||
|
||
try { | ||
const tx = await gateway[ | ||
"call(address,bytes,(address,bool,address,bytes,uint256))" | ||
]( | ||
args.receiver, | ||
encodedParameters, | ||
{ | ||
revertAddress: args.revertAddress, | ||
callOnRevert: args.callOnRevert, | ||
abortAddress: "0x0000000000000000000000000000000000000000", // not used | ||
revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), | ||
onRevertGasLimit: args.onRevertGasLimit, | ||
}, | ||
{ | ||
gasPrice: args.gasPrice, | ||
gasLimit: args.gasLimit, | ||
} | ||
); | ||
const receipt = await tx.wait(); | ||
console.log("Transaction hash:", receipt.transactionHash); | ||
} catch (e) { | ||
console.error("Transaction error:", e); | ||
} | ||
}; | ||
|
||
task("evm-call", "Call a universal app", evmCall) | ||
.addParam("receiver", "Receiver address on ZetaChain") | ||
.addOptionalParam( | ||
"gatewayEvm", | ||
"contract address of gateway on EVM", | ||
"0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" | ||
) | ||
.addFlag("callOnRevert", "Whether to call on revert") | ||
.addOptionalParam( | ||
"revertAddress", | ||
"Revert address", | ||
"0x0000000000000000000000000000000000000000" | ||
) | ||
.addOptionalParam( | ||
"gasPrice", | ||
"The gas price for the transaction", | ||
10000000000, | ||
types.int | ||
) | ||
.addOptionalParam( | ||
"gasLimit", | ||
"The gas limit for the transaction", | ||
7000000, | ||
types.int | ||
) | ||
.addOptionalParam( | ||
"onRevertGasLimit", | ||
"The gas limit for the revert transaction", | ||
7000000, | ||
types.int | ||
) | ||
.addOptionalParam("revertMessage", "Revert message", "0x") | ||
.addParam("types", "The types of the parameters (example: ['string'])") | ||
.addVariadicPositionalParam("values", "The values of the parameters"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { task, types } from "hardhat/config"; | ||
import type { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import GatewayABI from "./abi/GatewayEVM.sol/GatewayEVM.json"; | ||
import ERC20_ABI from "@openzeppelin/contracts/build/contracts/ERC20.json"; | ||
|
||
export const evmDeposit = async (args: any, hre: HardhatRuntimeEnvironment) => { | ||
const [signer] = await hre.ethers.getSigners(); | ||
const { utils } = hre.ethers; | ||
|
||
const gateway = new hre.ethers.Contract( | ||
args.gatewayEvm, | ||
GatewayABI.abi, | ||
signer | ||
); | ||
|
||
const revertOptions = { | ||
revertAddress: args.revertAddress, | ||
callOnRevert: args.callOnRevert, | ||
abortAddress: "0x0000000000000000000000000000000000000000", // not used | ||
revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), | ||
onRevertGasLimit: args.onRevertGasLimit, | ||
}; | ||
|
||
const txOptions = { | ||
gasPrice: args.gasPrice, | ||
gasLimit: args.gasLimit, | ||
}; | ||
|
||
try { | ||
let tx; | ||
if (args.erc20) { | ||
const erc20Contract = new hre.ethers.Contract( | ||
args.erc20, | ||
ERC20_ABI.abi, | ||
signer | ||
); | ||
const decimals = await erc20Contract.decimals(); | ||
const value = utils.parseUnits(args.amount, decimals); | ||
await erc20Contract.connect(signer).approve(args.gatewayEvm, value); | ||
const method = | ||
"deposit(address,uint256,address,(address,bool,address,bytes,uint256))"; | ||
tx = await gateway[method]( | ||
args.receiver, | ||
value, | ||
args.erc20, | ||
revertOptions, | ||
txOptions | ||
); | ||
} else { | ||
const value = utils.parseEther(args.amount); | ||
const method = "deposit(address,(address,bool,address,bytes,uint256))"; | ||
tx = await gateway[method](args.receiver, revertOptions, { | ||
...txOptions, | ||
value, | ||
}); | ||
} | ||
if (tx) { | ||
const receipt = await tx.wait(); | ||
console.log("Transaction hash:", receipt.transactionHash); | ||
} | ||
} catch (e) { | ||
console.error("Transaction error:", e); | ||
} | ||
}; | ||
|
||
task("evm-deposit", "Deposit tokens", evmDeposit) | ||
.addParam("receiver", "Receiver address on ZetaChain") | ||
.addOptionalParam( | ||
"gatewayEvm", | ||
"contract address of gateway on EVM", | ||
"0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" | ||
) | ||
.addFlag("callOnRevert", "Whether to call on revert") | ||
.addOptionalParam( | ||
"revertAddress", | ||
"Revert address", | ||
"0x0000000000000000000000000000000000000000", | ||
types.string | ||
) | ||
.addOptionalParam( | ||
"gasPrice", | ||
"The gas price for the transaction", | ||
50000000000, | ||
types.int | ||
) | ||
.addOptionalParam( | ||
"gasLimit", | ||
"The gas limit for the transaction", | ||
7000000, | ||
types.int | ||
) | ||
.addOptionalParam( | ||
"onRevertGasLimit", | ||
"The gas limit for the revert transaction", | ||
7000000, | ||
types.int | ||
) | ||
.addOptionalParam("revertMessage", "Revert message", "0x") | ||
.addParam("amount", "amount of ETH to send with the transaction") | ||
.addOptionalParam("erc20", "ERC-20 token address"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { task, types } from "hardhat/config"; | ||
import type { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import GatewayABI from "./abi/GatewayEVM.sol/GatewayEVM.json"; | ||
import ERC20_ABI from "@openzeppelin/contracts/build/contracts/ERC20.json"; | ||
|
||
export const evmDepositAndCall = async ( | ||
args: any, | ||
hre: HardhatRuntimeEnvironment | ||
) => { | ||
const [signer] = await hre.ethers.getSigners(); | ||
const { utils } = hre.ethers; | ||
|
||
const gateway = new hre.ethers.Contract( | ||
args.gatewayEvm, | ||
GatewayABI.abi, | ||
signer | ||
); | ||
|
||
const revertOptions = { | ||
revertAddress: args.revertAddress, | ||
callOnRevert: args.callOnRevert, | ||
abortAddress: "0x0000000000000000000000000000000000000000", // not used | ||
revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), | ||
onRevertGasLimit: args.onRevertGasLimit, | ||
}; | ||
|
||
const txOptions = { | ||
gasPrice: args.gasPrice, | ||
gasLimit: args.gasLimit, | ||
}; | ||
|
||
const encodedParameters = utils.defaultAbiCoder.encode( | ||
JSON.parse(args.types), | ||
args.values | ||
); | ||
|
||
try { | ||
let tx; | ||
if (args.erc20) { | ||
const erc20Contract = new hre.ethers.Contract( | ||
args.erc20, | ||
ERC20_ABI.abi, | ||
signer | ||
); | ||
const decimals = await erc20Contract.decimals(); | ||
const value = utils.parseUnits(args.amount, decimals); | ||
await erc20Contract.connect(signer).approve(args.gatewayEvm, value); | ||
const method = | ||
"depositAndCall(address,uint256,address,bytes,(address,bool,address,bytes,uint256))"; | ||
tx = await gateway[method]( | ||
args.receiver, | ||
value, | ||
args.erc20, | ||
encodedParameters, | ||
revertOptions, | ||
txOptions | ||
); | ||
} else { | ||
const value = utils.parseEther(args.amount); | ||
const method = | ||
"depositAndCall(address,bytes,(address,bool,address,bytes,uint256))"; | ||
tx = await gateway[method]( | ||
args.receiver, | ||
encodedParameters, | ||
revertOptions, | ||
{ | ||
...txOptions, | ||
value, | ||
} | ||
); | ||
} | ||
if (tx) { | ||
const receipt = await tx.wait(); | ||
console.log("Transaction hash:", receipt.transactionHash); | ||
} | ||
} catch (e) { | ||
console.error("Transaction error:", e); | ||
} | ||
}; | ||
|
||
task("evm-deposit-and-call", "Deposit tokens", evmDepositAndCall) | ||
.addParam("receiver", "Receiver address on ZetaChain") | ||
.addOptionalParam( | ||
"gatewayEvm", | ||
"contract address of gateway on EVM", | ||
"0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" | ||
) | ||
.addFlag("callOnRevert", "Whether to call on revert") | ||
.addOptionalParam( | ||
"revertAddress", | ||
"Revert address", | ||
"0x0000000000000000000000000000000000000000", | ||
types.string | ||
) | ||
.addOptionalParam( | ||
"gasPrice", | ||
"The gas price for the transaction", | ||
50000000000, | ||
types.int | ||
) | ||
.addOptionalParam( | ||
"gasLimit", | ||
"The gas limit for the transaction", | ||
7000000, | ||
types.int | ||
) | ||
.addOptionalParam( | ||
"onRevertGasLimit", | ||
"The gas limit for the revert transaction", | ||
7000000, | ||
types.int | ||
) | ||
.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'])") | ||
.addVariadicPositionalParam("values", "The values of the parameters"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.