diff --git a/contracts/SwapHelperLib.sol b/contracts/SwapHelperLib.sol index 7c5d2b2e..a1eadd74 100644 --- a/contracts/SwapHelperLib.sol +++ b/contracts/SwapHelperLib.sol @@ -103,7 +103,11 @@ library SwapHelperLib { if (!existsPairPool) { return false; } - uint256[] memory amounts = UniswapV2Library.getAmountsOut(uniswapV2Factory, amountIn, path); + uint256[] memory amounts = UniswapV2Library.getAmountsOut( + uniswapV2Factory, + amountIn, + path + ); return amounts[amounts.length - 1] >= minAmountOut; } @@ -114,7 +118,6 @@ library SwapHelperLib { address targetZRC20, uint256 minAmountOut ) internal returns (uint256) { - address[] memory path; path = new address[](2); path[0] = zrc20; @@ -127,7 +130,8 @@ library SwapHelperLib { path ); - bool isZETA = targetZRC20 == systemContract.wZetaContractAddress() || zrc20 == systemContract.wZetaContractAddress(); + bool isZETA = targetZRC20 == systemContract.wZetaContractAddress() || + zrc20 == systemContract.wZetaContractAddress(); if (!isSufficientLiquidity && !isZETA) { path = new address[](3); @@ -234,20 +238,36 @@ library SwapHelperLib { return amounts[0]; } - function getMinOutAmount(SystemContract systemContract, address zrc20, address target, uint256 amountIn) public view returns (uint256 minOutAmount) { + function getMinOutAmount( + SystemContract systemContract, + address zrc20, + address target, + uint256 amountIn + ) public view returns (uint256 minOutAmount) { address[] memory path; path = new address[](2); path[0] = zrc20; path[1] = target; - uint[] memory amounts1 = UniswapV2Library.getAmountsOut(systemContract.uniswapv2FactoryAddress(), amountIn, path); + uint[] memory amounts1 = UniswapV2Library.getAmountsOut( + systemContract.uniswapv2FactoryAddress(), + amountIn, + path + ); path = new address[](3); path[0] = zrc20; path[1] = systemContract.wZetaContractAddress(); path[2] = target; - uint[] memory amounts2 = UniswapV2Library.getAmountsOut(systemContract.uniswapv2FactoryAddress(), amountIn, path); + uint[] memory amounts2 = UniswapV2Library.getAmountsOut( + systemContract.uniswapv2FactoryAddress(), + amountIn, + path + ); - minOutAmount = amounts1[amounts1.length - 1] > amounts2[amounts2.length - 1] ? amounts1[amounts1.length - 1] : amounts2[amounts2.length - 1]; + minOutAmount = amounts1[amounts1.length - 1] > + amounts2[amounts2.length - 1] + ? amounts1[amounts1.length - 1] + : amounts2[amounts2.length - 1]; } } diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index f9e7bb61..f5765fd9 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -17,9 +17,9 @@ import { getZRC20FromERC20, getZRC20GasToken, sendZeta, + solanaDeposit, trackCCTX, withdraw, - solanaDeposit, } from "."; export interface ZetaChainClientParamsBase { diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 3f510f06..accb0f2b 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -11,6 +11,6 @@ export * from "./getQuote"; export * from "./getSupportedChains"; export * from "./prepareData"; export * from "./sendZeta"; +export * from "./solanaDeposit"; export * from "./trackCCTX"; export * from "./withdraw"; -export * from "./solanaDeposit"; diff --git a/packages/client/src/solanaDeposit.ts b/packages/client/src/solanaDeposit.ts index 2bab252f..c2df7d4e 100644 --- a/packages/client/src/solanaDeposit.ts +++ b/packages/client/src/solanaDeposit.ts @@ -1,9 +1,10 @@ import * as anchor from "@coral-xyz/anchor"; -import Gateway_IDL from "./idl/gateway.json"; -import { ZetaChainClient } from "./client"; import { Keypair } from "@solana/web3.js"; import { ethers } from "ethers"; +import { ZetaChainClient } from "./client"; +import Gateway_IDL from "./idl/gateway.json"; + const SEED = "meta"; export const solanaDeposit = async function ( @@ -11,9 +12,9 @@ export const solanaDeposit = async function ( args: { amount: number; api: string; - recipient: string; idPath: string; params: any[]; + recipient: string; } ) { const keypair = await getKeypairFromFile(args.idPath); diff --git a/packages/tasks/src/evmCall.ts b/packages/tasks/src/evmCall.ts index 25c23cfa..01ee363d 100644 --- a/packages/tasks/src/evmCall.ts +++ b/packages/tasks/src/evmCall.ts @@ -1,5 +1,6 @@ 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) => { @@ -24,15 +25,16 @@ export const evmCall = async (args: any, hre: HardhatRuntimeEnvironment) => { args.receiver, encodedParameters, { - revertAddress: args.revertAddress, + abortAddress: "0x0000000000000000000000000000000000000000", callOnRevert: args.callOnRevert, - abortAddress: "0x0000000000000000000000000000000000000000", // not used - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + // not used + revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), }, { - gasPrice: args.gasPrice, gasLimit: args.gasLimit, + gasPrice: args.gasPrice, } ); const receipt = await tx.wait(); diff --git a/packages/tasks/src/evmDeposit.ts b/packages/tasks/src/evmDeposit.ts index 4e092535..b5668f56 100644 --- a/packages/tasks/src/evmDeposit.ts +++ b/packages/tasks/src/evmDeposit.ts @@ -1,7 +1,8 @@ +import ERC20_ABI from "@openzeppelin/contracts/build/contracts/ERC20.json"; 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(); @@ -14,16 +15,17 @@ export const evmDeposit = async (args: any, hre: HardhatRuntimeEnvironment) => { ); const revertOptions = { - revertAddress: args.revertAddress, + abortAddress: "0x0000000000000000000000000000000000000000", callOnRevert: args.callOnRevert, - abortAddress: "0x0000000000000000000000000000000000000000", // not used - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + // not used + revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), }; const txOptions = { - gasPrice: args.gasPrice, gasLimit: args.gasLimit, + gasPrice: args.gasPrice, }; try { diff --git a/packages/tasks/src/evmDepositAndCall.ts b/packages/tasks/src/evmDepositAndCall.ts index 7e0ee502..e6df98b3 100644 --- a/packages/tasks/src/evmDepositAndCall.ts +++ b/packages/tasks/src/evmDepositAndCall.ts @@ -1,7 +1,8 @@ +import ERC20_ABI from "@openzeppelin/contracts/build/contracts/ERC20.json"; 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, @@ -17,16 +18,17 @@ export const evmDepositAndCall = async ( ); const revertOptions = { - revertAddress: args.revertAddress, + abortAddress: "0x0000000000000000000000000000000000000000", callOnRevert: args.callOnRevert, - abortAddress: "0x0000000000000000000000000000000000000000", // not used - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + // not used + revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), }; const txOptions = { - gasPrice: args.gasPrice, gasLimit: args.gasLimit, + gasPrice: args.gasPrice, }; const encodedParameters = utils.defaultAbiCoder.encode( diff --git a/packages/tasks/src/index.ts b/packages/tasks/src/index.ts index b3c05928..bb01e1fc 100644 --- a/packages/tasks/src/index.ts +++ b/packages/tasks/src/index.ts @@ -10,12 +10,12 @@ export { poolsTask } from "./pools"; export { sendBTCTask } from "./sendBTC"; export { sendZETATask } from "./sendZETA"; // export { verifyTask } from "./verify"; -export { tokensTask } from "./tokens"; -export { withdrawTask } from "./withdraw"; export { evmCall } from "./evmCall"; export { evmDeposit } from "./evmDeposit"; export { evmDepositAndCall } from "./evmDepositAndCall"; +export { solanaDeposit } from "./solanaDeposit"; +export { tokensTask } from "./tokens"; +export { withdrawTask } from "./withdraw"; export { zetachainCall } from "./zetachainCall"; export { zetachainWithdraw } from "./zetachainWithdraw"; export { zetachainWithdrawAndCall } from "./zetachainWithdrawAndCall"; -export { solanaDeposit } from "./solanaDeposit"; diff --git a/packages/tasks/src/solanaDeposit.ts b/packages/tasks/src/solanaDeposit.ts index f9d2f759..8c99b529 100644 --- a/packages/tasks/src/solanaDeposit.ts +++ b/packages/tasks/src/solanaDeposit.ts @@ -2,6 +2,7 @@ import bech32 from "bech32"; import { utils } from "ethers"; import { task } from "hardhat/config"; import type { HardhatRuntimeEnvironment } from "hardhat/types"; + import { ZetaChainClient } from "../../client/src"; export const solanaDeposit = async ( @@ -22,7 +23,7 @@ export const solanaDeposit = async ( } const { amount, api, idPath } = args; const params = [JSON.parse(args.types), args.values]; - await client.solanaDeposit({ amount, api, recipient, idPath, params }); + await client.solanaDeposit({ amount, api, idPath, params, recipient }); }; task("solana-deposit", "Solana deposit", solanaDeposit) diff --git a/packages/tasks/src/zetachainCall.ts b/packages/tasks/src/zetachainCall.ts index 414dd01d..76c5d451 100644 --- a/packages/tasks/src/zetachainCall.ts +++ b/packages/tasks/src/zetachainCall.ts @@ -1,5 +1,6 @@ import { task, types } from "hardhat/config"; import type { HardhatRuntimeEnvironment } from "hardhat/types"; + import GatewayABI from "./abi/GatewayZEVM.sol/GatewayZEVM.json"; import ZRC20ABI from "./abi/ZRC20.sol/ZRC20.json"; @@ -18,16 +19,17 @@ export const zetachainCall = async ( ); const revertOptions = { - revertAddress: args.revertAddress, + abortAddress: "0x0000000000000000000000000000000000000000", callOnRevert: args.callOnRevert, - abortAddress: "0x0000000000000000000000000000000000000000", // not used - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + // not used + revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), }; const txOptions = { - gasPrice: args.gasPrice, gasLimit: args.gasLimit, + gasPrice: args.gasPrice, }; const functionSignature = utils.id(args.function).slice(0, 10); diff --git a/packages/tasks/src/zetachainWithdraw.ts b/packages/tasks/src/zetachainWithdraw.ts index ca248d00..4996b88c 100644 --- a/packages/tasks/src/zetachainWithdraw.ts +++ b/packages/tasks/src/zetachainWithdraw.ts @@ -1,5 +1,6 @@ import { task, types } from "hardhat/config"; import type { HardhatRuntimeEnvironment } from "hardhat/types"; + import GatewayABI from "./abi/GatewayZEVM.sol/GatewayZEVM.json"; import ZRC20ABI from "./abi/ZRC20.sol/ZRC20.json"; @@ -17,16 +18,17 @@ export const zetachainWithdraw = async ( ); const revertOptions = { - revertAddress: args.revertAddress, + abortAddress: "0x0000000000000000000000000000000000000000", callOnRevert: args.callOnRevert, - abortAddress: "0x0000000000000000000000000000000000000000", // not used - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + // not used + revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), }; const txOptions = { - gasPrice: args.gasPrice, gasLimit: args.gasLimit, + gasPrice: args.gasPrice, }; try { diff --git a/packages/tasks/src/zetachainWithdrawAndCall.ts b/packages/tasks/src/zetachainWithdrawAndCall.ts index 6985e463..81a19d80 100644 --- a/packages/tasks/src/zetachainWithdrawAndCall.ts +++ b/packages/tasks/src/zetachainWithdrawAndCall.ts @@ -1,5 +1,6 @@ import { task, types } from "hardhat/config"; import type { HardhatRuntimeEnvironment } from "hardhat/types"; + import GatewayABI from "./abi/GatewayZEVM.sol/GatewayZEVM.json"; import ZRC20ABI from "./abi/ZRC20.sol/ZRC20.json"; @@ -17,16 +18,17 @@ export const zetachainWithdrawAndCall = async ( ); const revertOptions = { - revertAddress: args.revertAddress, + abortAddress: "0x0000000000000000000000000000000000000000", callOnRevert: args.callOnRevert, - abortAddress: "0x0000000000000000000000000000000000000000", // not used - revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), onRevertGasLimit: args.onRevertGasLimit, + revertAddress: args.revertAddress, + // not used + revertMessage: utils.hexlify(utils.toUtf8Bytes(args.revertMessage)), }; const txOptions = { - gasPrice: args.gasPrice, gasLimit: args.gasLimit, + gasPrice: args.gasPrice, }; const functionSignature = utils.id(args.function).slice(0, 10);