From 0d20d804c3796e1b034a0fb992e4ea92650f26ca Mon Sep 17 00:00:00 2001 From: Den Great Date: Tue, 11 Jun 2024 18:45:13 +0800 Subject: [PATCH] aero --- .gitignore | 1 + package-lock.json | 14 +++++----- package.json | 2 +- src/BalanceGuard.ts | 2 +- src/Unit/Exchange/callGenerators/aero.ts | 27 +++++++++++++++++++ src/Unit/Exchange/callGenerators/curve.ts | 4 +-- src/Unit/Exchange/callGenerators/erc20.ts | 6 ++--- .../Exchange/callGenerators/feePayment.ts | 4 +-- src/Unit/Exchange/callGenerators/uniswapV2.ts | 2 +- src/Unit/Exchange/callGenerators/uniswapV3.ts | 2 +- src/Unit/Exchange/callGenerators/utils.ts | 2 +- src/Unit/Exchange/callGenerators/weth.ts | 6 ++--- src/Unit/Exchange/deposit.ts | 2 +- src/Unit/Exchange/generateSwapCalldata.ts | 9 +++++-- src/Unit/Exchange/swapLimit.ts | 2 +- src/Unit/Exchange/swapMarket.ts | 2 +- src/Unit/Exchange/withdraw.ts | 2 +- src/Unit/Pmm/index.ts | 2 +- src/constants/factories.ts | 2 +- src/utils/checkIsToken.ts | 2 +- src/utils/getBalance.ts | 4 +-- src/utils/getBalances.ts | 2 +- src/utils/parseExchangeTradeTransaction.ts | 2 +- 23 files changed, 68 insertions(+), 35 deletions(-) create mode 100644 src/Unit/Exchange/callGenerators/aero.ts diff --git a/.gitignore b/.gitignore index b095e41..60f9c3c 100644 --- a/.gitignore +++ b/.gitignore @@ -132,3 +132,4 @@ lib .pnp.* src/artifacts/contracts/ +.DS_store \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 72ed395..40ff5cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@babel/runtime": "^7.21.0", "@ethersproject/abstract-signer": "^5.7.0", "@ethersproject/providers": "^5.7.2", - "@orionprotocol/contracts": "1.23.3", + "@orionprotocol/contracts": "^1.23.9", "@types/lodash.clonedeep": "^4.5.9", "bignumber.js": "^9.1.1", "bson-objectid": "^2.0.4", @@ -2422,9 +2422,9 @@ } }, "node_modules/@orionprotocol/contracts": { - "version": "1.23.3", - "resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.3.tgz", - "integrity": "sha512-3PBnuiUe//v7COArcm/dzFx71vxW+a9emU4PHi1zBdow+OUAa4WNb+NmNZ3AOjnx2AZKK+gWJY+zKo1zSfAOHQ==" + "version": "1.23.9", + "resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.9.tgz", + "integrity": "sha512-tx21XokSK8kBYmuzfYrXoDattirm6yaG3dslrOKZTHgGP1wC6c6SbQF69pVCCAnPNGvQCt4lw0I/8fxm9Cx23Q==" }, "node_modules/@sinclair/typebox": { "version": "0.27.8", @@ -13489,9 +13489,9 @@ } }, "@orionprotocol/contracts": { - "version": "1.23.3", - "resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.3.tgz", - "integrity": "sha512-3PBnuiUe//v7COArcm/dzFx71vxW+a9emU4PHi1zBdow+OUAa4WNb+NmNZ3AOjnx2AZKK+gWJY+zKo1zSfAOHQ==" + "version": "1.23.9", + "resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.9.tgz", + "integrity": "sha512-tx21XokSK8kBYmuzfYrXoDattirm6yaG3dslrOKZTHgGP1wC6c6SbQF69pVCCAnPNGvQCt4lw0I/8fxm9Cx23Q==" }, "@sinclair/typebox": { "version": "0.27.8", diff --git a/package.json b/package.json index e4fd701..cebc429 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "@babel/runtime": "^7.21.0", "@ethersproject/abstract-signer": "^5.7.0", "@ethersproject/providers": "^5.7.2", - "@orionprotocol/contracts": "1.23.3", + "@orionprotocol/contracts": "^1.23.9", "@types/lodash.clonedeep": "^4.5.9", "bignumber.js": "^9.1.1", "bson-objectid": "^2.0.4", diff --git a/src/BalanceGuard.ts b/src/BalanceGuard.ts index 9d0b881..2308313 100644 --- a/src/BalanceGuard.ts +++ b/src/BalanceGuard.ts @@ -1,7 +1,7 @@ import { BigNumber } from 'bignumber.js'; import { ethers } from 'ethers'; import clone from 'just-clone'; -import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js'; +import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js'; import { APPROVE_ERC20_GAS_LIMIT, NATIVE_CURRENCY_PRECISION } from './constants/index.js'; import type { AggregatedBalanceRequirement, ApproveFix, Asset, BalanceIssue, BalanceRequirement, Source, diff --git a/src/Unit/Exchange/callGenerators/aero.ts b/src/Unit/Exchange/callGenerators/aero.ts new file mode 100644 index 0000000..fc235fd --- /dev/null +++ b/src/Unit/Exchange/callGenerators/aero.ts @@ -0,0 +1,27 @@ +import { SwapExecutor__factory, AeroPool__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js" +import { type BigNumberish, JsonRpcProvider } from "ethers" +import { SafeArray } from "../../../utils/safeGetters.js" +import { addCallParams } from "./utils.js" +import type { SingleSwap } from "../../../types.js" + +export async function generateAeroCalls( + path: SafeArray, + amount: BigNumberish, + recipient: string, + provider: JsonRpcProvider +) { + const pools: string[] = []; + const direct: boolean[] = []; + for (const swap of path) { + pools.push(swap.pool); + + const token0 = await AeroPool__factory.connect(swap.pool, provider).token0(); + direct.push(swap.assetIn.toLowerCase() === token0.toLowerCase()); + } + + const executorInterface = SwapExecutor__factory.createInterface() + let calldata = executorInterface.encodeFunctionData('swapAeroMulti', [pools, direct, amount, recipient]); + calldata = addCallParams(calldata) + + return [calldata] +} diff --git a/src/Unit/Exchange/callGenerators/curve.ts b/src/Unit/Exchange/callGenerators/curve.ts index 69eeb2d..596854e 100644 --- a/src/Unit/Exchange/callGenerators/curve.ts +++ b/src/Unit/Exchange/callGenerators/curve.ts @@ -2,7 +2,7 @@ import { SwapExecutor__factory, CurveRegistry__factory, ERC20__factory, -} from "@orionprotocol/contracts/lib/ethers-v6/index.js"; +} from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js"; import { MaxUint256, type BigNumberish, type JsonRpcProvider } from "ethers"; import { addCallParams, pathCallWithBalance } from "./utils.js"; import type { SingleSwap } from "../../../types.js"; @@ -45,5 +45,5 @@ export async function generateCurveStableSwapCall( } calls.push(calldata) - return calls + return calls } diff --git a/src/Unit/Exchange/callGenerators/erc20.ts b/src/Unit/Exchange/callGenerators/erc20.ts index bd54dd2..cc823d6 100644 --- a/src/Unit/Exchange/callGenerators/erc20.ts +++ b/src/Unit/Exchange/callGenerators/erc20.ts @@ -1,4 +1,4 @@ -import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js" +import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js" import type { BigNumberish, AddressLike } from "ethers" import { type CallParams, addCallParams } from "./utils.js" @@ -15,7 +15,7 @@ export function generateTransferCall( target, amount ]) - + return addCallParams(calldata, callParams) } @@ -31,6 +31,6 @@ export function generateApproveCall( target, amount ]) - + return addCallParams(calldata, callParams) } \ No newline at end of file diff --git a/src/Unit/Exchange/callGenerators/feePayment.ts b/src/Unit/Exchange/callGenerators/feePayment.ts index ee1eb29..ccff002 100644 --- a/src/Unit/Exchange/callGenerators/feePayment.ts +++ b/src/Unit/Exchange/callGenerators/feePayment.ts @@ -1,4 +1,4 @@ -import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js" +import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js" import type { BigNumberish, AddressLike } from "ethers" import { type CallParams, addCallParams } from "./utils.js" @@ -16,6 +16,6 @@ export function generateFeePaymentCall( token, amount ]) - + return addCallParams(calldata, callParams) } \ No newline at end of file diff --git a/src/Unit/Exchange/callGenerators/uniswapV2.ts b/src/Unit/Exchange/callGenerators/uniswapV2.ts index 4fa1566..53d26b5 100644 --- a/src/Unit/Exchange/callGenerators/uniswapV2.ts +++ b/src/Unit/Exchange/callGenerators/uniswapV2.ts @@ -1,4 +1,4 @@ -import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js" +import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js" import { SafeArray } from "../../../utils/safeGetters.js" import { type BytesLike, type BigNumberish, concat, ethers, toBeHex } from "ethers" import { addCallParams } from "./utils.js" diff --git a/src/Unit/Exchange/callGenerators/uniswapV3.ts b/src/Unit/Exchange/callGenerators/uniswapV3.ts index 67bfcec..2da58f1 100644 --- a/src/Unit/Exchange/callGenerators/uniswapV3.ts +++ b/src/Unit/Exchange/callGenerators/uniswapV3.ts @@ -1,4 +1,4 @@ -import { SwapExecutor__factory, UniswapV3Pool__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js" +import { SwapExecutor__factory, UniswapV3Pool__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js" import { type BigNumberish , ethers, JsonRpcProvider } from "ethers" import { SafeArray } from "../../../utils/safeGetters.js" import { addCallParams } from "./utils.js" diff --git a/src/Unit/Exchange/callGenerators/utils.ts b/src/Unit/Exchange/callGenerators/utils.ts index b61dc4b..bf0c812 100644 --- a/src/Unit/Exchange/callGenerators/utils.ts +++ b/src/Unit/Exchange/callGenerators/utils.ts @@ -1,4 +1,4 @@ -import { ERC20__factory, SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js" +import { ERC20__factory, SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js" import type { AddressLike } from "ethers" import { type BytesLike, ethers, type BigNumberish } from "ethers" diff --git a/src/Unit/Exchange/callGenerators/weth.ts b/src/Unit/Exchange/callGenerators/weth.ts index 7aaf566..1e2b7e3 100644 --- a/src/Unit/Exchange/callGenerators/weth.ts +++ b/src/Unit/Exchange/callGenerators/weth.ts @@ -1,4 +1,4 @@ -import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js" +import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js" import type { BigNumberish } from "ethers" import { type CallParams, addCallParams } from "./utils.js" import type { AddressLike } from "ethers" @@ -12,7 +12,7 @@ export function generateWrapAndTransferCall( const calldata = executorInterface.encodeFunctionData('wrapAndTransfer', [ target, ]) - + return addCallParams(calldata, callParams) } @@ -27,6 +27,6 @@ export function generateUnwrapAndTransferCall( target, amount ]) - + return addCallParams(calldata, callParams) } \ No newline at end of file diff --git a/src/Unit/Exchange/deposit.ts b/src/Unit/Exchange/deposit.ts index d257244..93f4d71 100644 --- a/src/Unit/Exchange/deposit.ts +++ b/src/Unit/Exchange/deposit.ts @@ -1,6 +1,6 @@ import { BigNumber } from 'bignumber.js'; import { ethers } from 'ethers'; -import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js'; +import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js'; import getBalances from '../../utils/getBalances.js'; import BalanceGuard from '../../BalanceGuard.js'; import type Unit from '../index.js'; diff --git a/src/Unit/Exchange/generateSwapCalldata.ts b/src/Unit/Exchange/generateSwapCalldata.ts index d58a68a..1b7b350 100644 --- a/src/Unit/Exchange/generateSwapCalldata.ts +++ b/src/Unit/Exchange/generateSwapCalldata.ts @@ -1,4 +1,4 @@ -import type { LibValidator } from '@orionprotocol/contracts/lib/ethers-v6/Exchange.js'; +import type { LibValidator } from '@orionprotocol/contracts/lib/ethers-v6-cjs/Exchange.js'; import { ethers, ZeroAddress } from 'ethers'; import type { AddressLike, JsonRpcProvider, BigNumberish, BytesLike } from 'ethers'; import cloneDeep from 'lodash.clonedeep'; @@ -20,8 +20,9 @@ import { addressLikeToString } from '../../utils/addressLikeToString.js'; import { generateUnwrapAndTransferCall, generateWrapAndTransferCall } from './callGenerators/weth.js'; import { getExchangeAllowance, getTotalBalance } from '../../utils/getBalance.js'; import { generateFeePaymentCall } from './callGenerators/feePayment.js'; +import { generateAeroCalls } from './callGenerators/aero.js'; -export type Factory = 'UniswapV2' | 'UniswapV3' | 'Curve' | 'OrionV2' | 'OrionV3'; +export type Factory = 'UniswapV2' | 'UniswapV3' | 'Curve' | 'OrionV2' | 'OrionV3' | 'Aero'; type BaseGenerateSwapCalldataParams = { amount: BigNumberish @@ -276,6 +277,10 @@ async function processSingleFactorySwaps( calls = await generateOrion3Calls(path, amount, swapExecutorContractAddress, provider); break; } + case "Aero": { + calls = await generateAeroCalls(path, amount, swapExecutorContractAddress, provider); + break; + } case 'Curve': { if (path.length > 1) { throw new Error('Supporting only single stable swap on curve'); diff --git a/src/Unit/Exchange/swapLimit.ts b/src/Unit/Exchange/swapLimit.ts index 19ae300..b2d4886 100644 --- a/src/Unit/Exchange/swapLimit.ts +++ b/src/Unit/Exchange/swapLimit.ts @@ -1,6 +1,6 @@ import { BigNumber } from 'bignumber.js'; import { ethers } from 'ethers'; -import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js'; +import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js'; import getBalances from '../../utils/getBalances.js'; import BalanceGuard from '../../BalanceGuard.js'; import getAvailableSources from '../../utils/getAvailableFundsSources.js'; diff --git a/src/Unit/Exchange/swapMarket.ts b/src/Unit/Exchange/swapMarket.ts index 934e2bb..20a0d99 100644 --- a/src/Unit/Exchange/swapMarket.ts +++ b/src/Unit/Exchange/swapMarket.ts @@ -1,6 +1,6 @@ import { BigNumber } from 'bignumber.js'; import { ethers } from 'ethers'; -import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js'; +import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js'; import getBalances from '../../utils/getBalances.js'; import BalanceGuard from '../../BalanceGuard.js'; import getAvailableSources from '../../utils/getAvailableFundsSources.js'; diff --git a/src/Unit/Exchange/withdraw.ts b/src/Unit/Exchange/withdraw.ts index 9b5d2d7..7e400d7 100644 --- a/src/Unit/Exchange/withdraw.ts +++ b/src/Unit/Exchange/withdraw.ts @@ -1,6 +1,6 @@ import { BigNumber } from 'bignumber.js'; import { ethers } from 'ethers'; -import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js'; +import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js'; import getBalances from '../../utils/getBalances.js'; import BalanceGuard from '../../BalanceGuard.js'; import type Unit from '../index.js'; diff --git a/src/Unit/Pmm/index.ts b/src/Unit/Pmm/index.ts index d4f1c57..1c8b1f5 100644 --- a/src/Unit/Pmm/index.ts +++ b/src/Unit/Pmm/index.ts @@ -4,7 +4,7 @@ import {pmmOrderSchema} from "./schemas/order"; import {simpleFetch} from "simple-typed-fetch"; import {ethers, Wallet} from "ethers"; import {BigNumber} from "bignumber.js"; -import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js'; +import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js'; import {orionRFQContractABI} from "./abi/OrionRFQ"; export default class Pmm { diff --git a/src/constants/factories.ts b/src/constants/factories.ts index 200d3e2..92bdc16 100644 --- a/src/constants/factories.ts +++ b/src/constants/factories.ts @@ -1 +1 @@ -export default ["UniswapV2", "UniswapV3", "Curve", "OrionV2", "OrionV3"] as const +export default ["UniswapV2", "UniswapV3", "Curve", "OrionV2", "OrionV3", "Aero"] as const diff --git a/src/utils/checkIsToken.ts b/src/utils/checkIsToken.ts index 5be176a..d55c45d 100644 --- a/src/utils/checkIsToken.ts +++ b/src/utils/checkIsToken.ts @@ -1,4 +1,4 @@ -import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js'; +import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js'; import { ethers } from 'ethers'; import invariant from 'tiny-invariant'; diff --git a/src/utils/getBalance.ts b/src/utils/getBalance.ts index c863f65..10b3838 100644 --- a/src/utils/getBalance.ts +++ b/src/utils/getBalance.ts @@ -1,4 +1,4 @@ -import { ERC20__factory, Exchange__factory, type Exchange } from "@orionprotocol/contracts/lib/ethers-v6/index.js"; +import { ERC20__factory, Exchange__factory, type Exchange } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js"; import type { BigNumber } from "bignumber.js"; import { ZeroAddress, ethers } from "ethers"; import { INTERNAL_PROTOCOL_PRECISION, NATIVE_CURRENCY_PRECISION } from "../constants/index.js"; @@ -195,5 +195,5 @@ export async function getTotalBalance( walletBalance, exchangeBalance, totalBalance: walletBalance + exchangeBalance - } + } } diff --git a/src/utils/getBalances.ts b/src/utils/getBalances.ts index f9e5390..02527cc 100644 --- a/src/utils/getBalances.ts +++ b/src/utils/getBalances.ts @@ -1,4 +1,4 @@ -import type { Exchange } from '@orionprotocol/contracts/lib/ethers-v6/index.js'; +import type { Exchange } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js'; import type { BigNumber } from 'bignumber.js'; import type { ethers } from 'ethers'; import type { Aggregator } from '../services/Aggregator/index.js'; diff --git a/src/utils/parseExchangeTradeTransaction.ts b/src/utils/parseExchangeTradeTransaction.ts index 9b59093..7f63a85 100644 --- a/src/utils/parseExchangeTradeTransaction.ts +++ b/src/utils/parseExchangeTradeTransaction.ts @@ -1,4 +1,4 @@ -import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js'; +import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js'; import { ethers } from 'ethers'; import { z } from 'zod';