Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Sep 6, 2024
1 parent 39ea712 commit 4783164
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 42 deletions.
34 changes: 27 additions & 7 deletions contracts/SwapHelperLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -114,7 +118,6 @@ library SwapHelperLib {
address targetZRC20,
uint256 minAmountOut
) internal returns (uint256) {

address[] memory path;
path = new address[](2);
path[0] = zrc20;
Expand All @@ -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);
Expand Down Expand Up @@ -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];
}
}
2 changes: 1 addition & 1 deletion packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
getZRC20FromERC20,
getZRC20GasToken,
sendZeta,
solanaDeposit,
trackCCTX,
withdraw,
solanaDeposit,
} from ".";

export interface ZetaChainClientParamsBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
7 changes: 4 additions & 3 deletions packages/client/src/solanaDeposit.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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 (

Check warning on line 10 in packages/client/src/solanaDeposit.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using arrow functions over plain functions
this: ZetaChainClient,
args: {
amount: number;
api: string;
recipient: string;
idPath: string;
params: any[];
recipient: string;
}
) {
const keypair = await getKeypairFromFile(args.idPath);
Expand Down
10 changes: 6 additions & 4 deletions packages/tasks/src/evmCall.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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();
Expand Down
12 changes: 7 additions & 5 deletions packages/tasks/src/evmDeposit.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions packages/tasks/src/evmDepositAndCall.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions packages/tasks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
3 changes: 2 additions & 1 deletion packages/tasks/src/solanaDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions packages/tasks/src/zetachainCall.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions packages/tasks/src/zetachainWithdraw.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions packages/tasks/src/zetachainWithdrawAndCall.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
Expand Down

0 comments on commit 4783164

Please sign in to comment.