This commit is contained in:
Den Great
2024-06-11 18:45:13 +08:00
parent 2c89b2ec4c
commit 0d20d804c3
23 changed files with 68 additions and 35 deletions

1
.gitignore vendored
View File

@@ -132,3 +132,4 @@ lib
.pnp.* .pnp.*
src/artifacts/contracts/ src/artifacts/contracts/
.DS_store

14
package-lock.json generated
View File

@@ -13,7 +13,7 @@
"@babel/runtime": "^7.21.0", "@babel/runtime": "^7.21.0",
"@ethersproject/abstract-signer": "^5.7.0", "@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2", "@ethersproject/providers": "^5.7.2",
"@orionprotocol/contracts": "1.23.3", "@orionprotocol/contracts": "^1.23.9",
"@types/lodash.clonedeep": "^4.5.9", "@types/lodash.clonedeep": "^4.5.9",
"bignumber.js": "^9.1.1", "bignumber.js": "^9.1.1",
"bson-objectid": "^2.0.4", "bson-objectid": "^2.0.4",
@@ -2422,9 +2422,9 @@
} }
}, },
"node_modules/@orionprotocol/contracts": { "node_modules/@orionprotocol/contracts": {
"version": "1.23.3", "version": "1.23.9",
"resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.3.tgz", "resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.9.tgz",
"integrity": "sha512-3PBnuiUe//v7COArcm/dzFx71vxW+a9emU4PHi1zBdow+OUAa4WNb+NmNZ3AOjnx2AZKK+gWJY+zKo1zSfAOHQ==" "integrity": "sha512-tx21XokSK8kBYmuzfYrXoDattirm6yaG3dslrOKZTHgGP1wC6c6SbQF69pVCCAnPNGvQCt4lw0I/8fxm9Cx23Q=="
}, },
"node_modules/@sinclair/typebox": { "node_modules/@sinclair/typebox": {
"version": "0.27.8", "version": "0.27.8",
@@ -13489,9 +13489,9 @@
} }
}, },
"@orionprotocol/contracts": { "@orionprotocol/contracts": {
"version": "1.23.3", "version": "1.23.9",
"resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.3.tgz", "resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.9.tgz",
"integrity": "sha512-3PBnuiUe//v7COArcm/dzFx71vxW+a9emU4PHi1zBdow+OUAa4WNb+NmNZ3AOjnx2AZKK+gWJY+zKo1zSfAOHQ==" "integrity": "sha512-tx21XokSK8kBYmuzfYrXoDattirm6yaG3dslrOKZTHgGP1wC6c6SbQF69pVCCAnPNGvQCt4lw0I/8fxm9Cx23Q=="
}, },
"@sinclair/typebox": { "@sinclair/typebox": {
"version": "0.27.8", "version": "0.27.8",

View File

@@ -88,7 +88,7 @@
"@babel/runtime": "^7.21.0", "@babel/runtime": "^7.21.0",
"@ethersproject/abstract-signer": "^5.7.0", "@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2", "@ethersproject/providers": "^5.7.2",
"@orionprotocol/contracts": "1.23.3", "@orionprotocol/contracts": "^1.23.9",
"@types/lodash.clonedeep": "^4.5.9", "@types/lodash.clonedeep": "^4.5.9",
"bignumber.js": "^9.1.1", "bignumber.js": "^9.1.1",
"bson-objectid": "^2.0.4", "bson-objectid": "^2.0.4",

View File

@@ -1,7 +1,7 @@
import { BigNumber } from 'bignumber.js'; import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers'; import { ethers } from 'ethers';
import clone from 'just-clone'; 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 { APPROVE_ERC20_GAS_LIMIT, NATIVE_CURRENCY_PRECISION } from './constants/index.js';
import type { import type {
AggregatedBalanceRequirement, ApproveFix, Asset, BalanceIssue, BalanceRequirement, Source, AggregatedBalanceRequirement, ApproveFix, Asset, BalanceIssue, BalanceRequirement, Source,

View File

@@ -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<SingleSwap>,
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]
}

View File

@@ -2,7 +2,7 @@ import {
SwapExecutor__factory, SwapExecutor__factory,
CurveRegistry__factory, CurveRegistry__factory,
ERC20__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 { MaxUint256, type BigNumberish, type JsonRpcProvider } from "ethers";
import { addCallParams, pathCallWithBalance } from "./utils.js"; import { addCallParams, pathCallWithBalance } from "./utils.js";
import type { SingleSwap } from "../../../types.js"; import type { SingleSwap } from "../../../types.js";

View File

@@ -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 { BigNumberish, AddressLike } from "ethers"
import { type CallParams, addCallParams } from "./utils.js" import { type CallParams, addCallParams } from "./utils.js"

View File

@@ -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 { BigNumberish, AddressLike } from "ethers"
import { type CallParams, addCallParams } from "./utils.js" import { type CallParams, addCallParams } from "./utils.js"

View File

@@ -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 { SafeArray } from "../../../utils/safeGetters.js"
import { type BytesLike, type BigNumberish, concat, ethers, toBeHex } from "ethers" import { type BytesLike, type BigNumberish, concat, ethers, toBeHex } from "ethers"
import { addCallParams } from "./utils.js" import { addCallParams } from "./utils.js"

View File

@@ -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 { type BigNumberish , ethers, JsonRpcProvider } from "ethers"
import { SafeArray } from "../../../utils/safeGetters.js" import { SafeArray } from "../../../utils/safeGetters.js"
import { addCallParams } from "./utils.js" import { addCallParams } from "./utils.js"

View File

@@ -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 { AddressLike } from "ethers"
import { type BytesLike, ethers, type BigNumberish } from "ethers" import { type BytesLike, ethers, type BigNumberish } from "ethers"

View File

@@ -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 { BigNumberish } from "ethers"
import { type CallParams, addCallParams } from "./utils.js" import { type CallParams, addCallParams } from "./utils.js"
import type { AddressLike } from "ethers" import type { AddressLike } from "ethers"

View File

@@ -1,6 +1,6 @@
import { BigNumber } from 'bignumber.js'; import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers'; 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 getBalances from '../../utils/getBalances.js';
import BalanceGuard from '../../BalanceGuard.js'; import BalanceGuard from '../../BalanceGuard.js';
import type Unit from '../index.js'; import type Unit from '../index.js';

View File

@@ -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 { ethers, ZeroAddress } from 'ethers';
import type { AddressLike, JsonRpcProvider, BigNumberish, BytesLike } from 'ethers'; import type { AddressLike, JsonRpcProvider, BigNumberish, BytesLike } from 'ethers';
import cloneDeep from 'lodash.clonedeep'; import cloneDeep from 'lodash.clonedeep';
@@ -20,8 +20,9 @@ import { addressLikeToString } from '../../utils/addressLikeToString.js';
import { generateUnwrapAndTransferCall, generateWrapAndTransferCall } from './callGenerators/weth.js'; import { generateUnwrapAndTransferCall, generateWrapAndTransferCall } from './callGenerators/weth.js';
import { getExchangeAllowance, getTotalBalance } from '../../utils/getBalance.js'; import { getExchangeAllowance, getTotalBalance } from '../../utils/getBalance.js';
import { generateFeePaymentCall } from './callGenerators/feePayment.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 = { type BaseGenerateSwapCalldataParams = {
amount: BigNumberish amount: BigNumberish
@@ -276,6 +277,10 @@ async function processSingleFactorySwaps(
calls = await generateOrion3Calls(path, amount, swapExecutorContractAddress, provider); calls = await generateOrion3Calls(path, amount, swapExecutorContractAddress, provider);
break; break;
} }
case "Aero": {
calls = await generateAeroCalls(path, amount, swapExecutorContractAddress, provider);
break;
}
case 'Curve': { case 'Curve': {
if (path.length > 1) { if (path.length > 1) {
throw new Error('Supporting only single stable swap on curve'); throw new Error('Supporting only single stable swap on curve');

View File

@@ -1,6 +1,6 @@
import { BigNumber } from 'bignumber.js'; import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers'; 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 getBalances from '../../utils/getBalances.js';
import BalanceGuard from '../../BalanceGuard.js'; import BalanceGuard from '../../BalanceGuard.js';
import getAvailableSources from '../../utils/getAvailableFundsSources.js'; import getAvailableSources from '../../utils/getAvailableFundsSources.js';

View File

@@ -1,6 +1,6 @@
import { BigNumber } from 'bignumber.js'; import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers'; 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 getBalances from '../../utils/getBalances.js';
import BalanceGuard from '../../BalanceGuard.js'; import BalanceGuard from '../../BalanceGuard.js';
import getAvailableSources from '../../utils/getAvailableFundsSources.js'; import getAvailableSources from '../../utils/getAvailableFundsSources.js';

View File

@@ -1,6 +1,6 @@
import { BigNumber } from 'bignumber.js'; import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers'; 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 getBalances from '../../utils/getBalances.js';
import BalanceGuard from '../../BalanceGuard.js'; import BalanceGuard from '../../BalanceGuard.js';
import type Unit from '../index.js'; import type Unit from '../index.js';

View File

@@ -4,7 +4,7 @@ import {pmmOrderSchema} from "./schemas/order";
import {simpleFetch} from "simple-typed-fetch"; import {simpleFetch} from "simple-typed-fetch";
import {ethers, Wallet} from "ethers"; import {ethers, Wallet} from "ethers";
import {BigNumber} from "bignumber.js"; 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"; import {orionRFQContractABI} from "./abi/OrionRFQ";
export default class Pmm { export default class Pmm {

View File

@@ -1 +1 @@
export default ["UniswapV2", "UniswapV3", "Curve", "OrionV2", "OrionV3"] as const export default ["UniswapV2", "UniswapV3", "Curve", "OrionV2", "OrionV3", "Aero"] as const

View File

@@ -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 { ethers } from 'ethers';
import invariant from 'tiny-invariant'; import invariant from 'tiny-invariant';

View File

@@ -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 type { BigNumber } from "bignumber.js";
import { ZeroAddress, ethers } from "ethers"; import { ZeroAddress, ethers } from "ethers";
import { INTERNAL_PROTOCOL_PRECISION, NATIVE_CURRENCY_PRECISION } from "../constants/index.js"; import { INTERNAL_PROTOCOL_PRECISION, NATIVE_CURRENCY_PRECISION } from "../constants/index.js";

View File

@@ -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 { BigNumber } from 'bignumber.js';
import type { ethers } from 'ethers'; import type { ethers } from 'ethers';
import type { Aggregator } from '../services/Aggregator/index.js'; import type { Aggregator } from '../services/Aggregator/index.js';

View File

@@ -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 { ethers } from 'ethers';
import { z } from 'zod'; import { z } from 'zod';