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

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,
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
}

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 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)
}

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 CallParams, addCallParams } from "./utils.js"
@@ -16,6 +16,6 @@ export function generateFeePaymentCall(
token,
amount
])
return addCallParams(calldata, callParams)
}

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

View File

@@ -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';

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 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');

View File

@@ -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';

View File

@@ -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';

View File

@@ -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';

View File

@@ -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 {