@juiceswapxyz/router-sdk 0.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/approveAndCall.d.ts +33 -0
- package/dist/constants.d.ts +13 -0
- package/dist/entities/mixedRoute/route.d.ts +29 -0
- package/dist/entities/mixedRoute/trade.d.ts +183 -0
- package/dist/entities/protocol.d.ts +6 -0
- package/dist/entities/route.d.ts +40 -0
- package/dist/entities/trade.d.ts +127 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +8 -0
- package/dist/multicallExtended.d.ts +11 -0
- package/dist/paymentsExtended.d.ts +15 -0
- package/dist/router-sdk.cjs.development.js +2250 -0
- package/dist/router-sdk.cjs.development.js.map +1 -0
- package/dist/router-sdk.cjs.production.min.js +2 -0
- package/dist/router-sdk.cjs.production.min.js.map +1 -0
- package/dist/router-sdk.esm.js +2217 -0
- package/dist/router-sdk.esm.js.map +1 -0
- package/dist/swapRouter.d.ts +95 -0
- package/dist/utils/TPool.d.ts +4 -0
- package/dist/utils/encodeMixedRouteToPath.d.ts +10 -0
- package/dist/utils/index.d.ts +16 -0
- package/dist/utils/pathCurrency.d.ts +4 -0
- package/package.json +73 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-sdk.cjs.production.min.js","sources":["../src/approveAndCall.ts","../src/constants.ts","../src/multicallExtended.ts","../src/paymentsExtended.ts","../src/utils/pathCurrency.ts","../src/entities/mixedRoute/route.ts","../src/entities/mixedRoute/trade.ts","../src/entities/protocol.ts","../src/entities/route.ts","../src/entities/trade.ts","../src/utils/encodeMixedRouteToPath.ts","../src/utils/index.ts","../src/swapRouter.ts"],"sourcesContent":["import { Interface } from '@ethersproject/abi'\nimport invariant from 'tiny-invariant'\nimport IApproveAndCall from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json'\nimport { Currency, Percent, Token } from '@juiceswapxyz/sdk-core'\nimport {\n MintSpecificOptions,\n IncreaseSpecificOptions,\n NonfungiblePositionManager,\n Position,\n toHex,\n} from '@juiceswapxyz/v3-sdk'\nimport JSBI from 'jsbi'\n\n// condensed version of v3-sdk AddLiquidityOptions containing only necessary swap + add attributes\nexport type CondensedAddLiquidityOptions = Omit<MintSpecificOptions, 'createPool'> | IncreaseSpecificOptions\n\nexport enum ApprovalTypes {\n NOT_REQUIRED = 0,\n MAX = 1,\n MAX_MINUS_ONE = 2,\n ZERO_THEN_MAX = 3,\n ZERO_THEN_MAX_MINUS_ONE = 4,\n}\n\n// type guard\nexport function isMint(options: CondensedAddLiquidityOptions): options is Omit<MintSpecificOptions, 'createPool'> {\n return Object.keys(options).some((k) => k === 'recipient')\n}\n\nexport abstract class ApproveAndCall {\n public static INTERFACE: Interface = new Interface(IApproveAndCall.abi)\n\n /**\n * Cannot be constructed.\n */\n private constructor() {}\n\n public static encodeApproveMax(token: Token): string {\n return ApproveAndCall.INTERFACE.encodeFunctionData('approveMax', [token.address])\n }\n\n public static encodeApproveMaxMinusOne(token: Token): string {\n return ApproveAndCall.INTERFACE.encodeFunctionData('approveMaxMinusOne', [token.address])\n }\n\n public static encodeApproveZeroThenMax(token: Token): string {\n return ApproveAndCall.INTERFACE.encodeFunctionData('approveZeroThenMax', [token.address])\n }\n\n public static encodeApproveZeroThenMaxMinusOne(token: Token): string {\n return ApproveAndCall.INTERFACE.encodeFunctionData('approveZeroThenMaxMinusOne', [token.address])\n }\n\n public static encodeCallPositionManager(calldatas: string[]): string {\n invariant(calldatas.length > 0, 'NULL_CALLDATA')\n\n if (calldatas.length === 1) {\n return ApproveAndCall.INTERFACE.encodeFunctionData('callPositionManager', calldatas)\n } else {\n const encodedMulticall = NonfungiblePositionManager.INTERFACE.encodeFunctionData('multicall', [calldatas])\n return ApproveAndCall.INTERFACE.encodeFunctionData('callPositionManager', [encodedMulticall])\n }\n }\n /**\n * Encode adding liquidity to a position in the nft manager contract\n * @param position Forcasted position with expected amount out from swap\n * @param minimalPosition Forcasted position with custom minimal token amounts\n * @param addLiquidityOptions Options for adding liquidity\n * @param slippageTolerance Defines maximum slippage\n */\n public static encodeAddLiquidity(\n position: Position,\n minimalPosition: Position,\n addLiquidityOptions: CondensedAddLiquidityOptions,\n slippageTolerance: Percent\n ): string {\n let { amount0: amount0Min, amount1: amount1Min } = position.mintAmountsWithSlippage(slippageTolerance)\n\n // position.mintAmountsWithSlippage() can create amounts not dependenable in scenarios\n // such as range orders. Allow the option to provide a position with custom minimum amounts\n // for these scenarios\n if (JSBI.lessThan(minimalPosition.amount0.quotient, amount0Min)) {\n amount0Min = minimalPosition.amount0.quotient\n }\n if (JSBI.lessThan(minimalPosition.amount1.quotient, amount1Min)) {\n amount1Min = minimalPosition.amount1.quotient\n }\n\n if (isMint(addLiquidityOptions)) {\n return ApproveAndCall.INTERFACE.encodeFunctionData('mint', [\n {\n token0: position.pool.token0.address,\n token1: position.pool.token1.address,\n fee: position.pool.fee,\n tickLower: position.tickLower,\n tickUpper: position.tickUpper,\n amount0Min: toHex(amount0Min),\n amount1Min: toHex(amount1Min),\n recipient: addLiquidityOptions.recipient,\n },\n ])\n } else {\n return ApproveAndCall.INTERFACE.encodeFunctionData('increaseLiquidity', [\n {\n token0: position.pool.token0.address,\n token1: position.pool.token1.address,\n amount0Min: toHex(amount0Min),\n amount1Min: toHex(amount1Min),\n tokenId: toHex(addLiquidityOptions.tokenId),\n },\n ])\n }\n }\n\n public static encodeApprove(token: Currency, approvalType: ApprovalTypes): string {\n switch (approvalType) {\n case ApprovalTypes.MAX:\n return ApproveAndCall.encodeApproveMax(token.wrapped)\n case ApprovalTypes.MAX_MINUS_ONE:\n return ApproveAndCall.encodeApproveMaxMinusOne(token.wrapped)\n case ApprovalTypes.ZERO_THEN_MAX:\n return ApproveAndCall.encodeApproveZeroThenMax(token.wrapped)\n case ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE:\n return ApproveAndCall.encodeApproveZeroThenMaxMinusOne(token.wrapped)\n default:\n throw new Error('Error: invalid ApprovalType')\n }\n }\n}\n","import { Percent } from '@juiceswapxyz/sdk-core'\nimport JSBI from 'jsbi'\n\nexport const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'\nexport const MSG_SENDER = '0x0000000000000000000000000000000000000001'\nexport const ADDRESS_THIS = '0x0000000000000000000000000000000000000002'\n\nexport const ZERO = JSBI.BigInt(0)\nexport const ONE = JSBI.BigInt(1)\n\n// = 1 << 23 or 0b0100000000000000000000000\nexport const MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER = 1 << 23\n\n// = 10 << 4 or 0b00100000\nexport const MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER = 2 << 4\n\n// = 11 << 20 or 0b001100000000000000000000\nexport const MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER = 3 << 20\n\n// = 100 << 20 or 0b010000000000000000000000\nexport const MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER = 4 << 20\n\nexport const ZERO_PERCENT = new Percent(ZERO)\nexport const ONE_HUNDRED_PERCENT = new Percent(100, 100)\n","import { Interface } from '@ethersproject/abi'\nimport { BigintIsh } from '@juiceswapxyz/sdk-core'\nimport IMulticallExtended from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json'\nimport { Multicall, toHex } from '@juiceswapxyz/v3-sdk'\n\n// deadline or previousBlockhash\nexport type Validation = BigintIsh | string\n\nfunction validateAndParseBytes32(bytes32: string): string {\n if (!bytes32.match(/^0x[0-9a-fA-F]{64}$/)) {\n throw new Error(`${bytes32} is not valid bytes32.`)\n }\n\n return bytes32.toLowerCase()\n}\n\nexport abstract class MulticallExtended {\n public static INTERFACE: Interface = new Interface(IMulticallExtended.abi)\n\n /**\n * Cannot be constructed.\n */\n private constructor() {}\n\n public static encodeMulticall(calldatas: string | string[], validation?: Validation): string {\n // if there's no validation, we can just fall back to regular multicall\n if (typeof validation === 'undefined') {\n return Multicall.encodeMulticall(calldatas)\n }\n\n // if there is validation, we have to normalize calldatas\n if (!Array.isArray(calldatas)) {\n calldatas = [calldatas]\n }\n\n // this means the validation value should be a previousBlockhash\n if (typeof validation === 'string' && validation.startsWith('0x')) {\n const previousBlockhash = validateAndParseBytes32(validation)\n return MulticallExtended.INTERFACE.encodeFunctionData('multicall(bytes32,bytes[])', [\n previousBlockhash,\n calldatas,\n ])\n } else {\n const deadline = toHex(validation)\n return MulticallExtended.INTERFACE.encodeFunctionData('multicall(uint256,bytes[])', [deadline, calldatas])\n }\n }\n}\n","import { Interface } from '@ethersproject/abi'\nimport { Percent, Token, validateAndParseAddress } from '@juiceswapxyz/sdk-core'\nimport IPeripheryPaymentsWithFeeExtended from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json'\nimport { FeeOptions, Payments, toHex } from '@juiceswapxyz/v3-sdk'\nimport JSBI from 'jsbi'\n\nfunction encodeFeeBips(fee: Percent): string {\n return toHex(fee.multiply(10_000).quotient)\n}\n\nexport abstract class PaymentsExtended {\n public static INTERFACE: Interface = new Interface(IPeripheryPaymentsWithFeeExtended.abi)\n\n /**\n * Cannot be constructed.\n */\n private constructor() {}\n\n public static encodeUnwrapWETH9(amountMinimum: JSBI, recipient?: string, feeOptions?: FeeOptions): string {\n // if there's a recipient, just pass it along\n if (typeof recipient === 'string') {\n return Payments.encodeUnwrapWETH9(amountMinimum, recipient, feeOptions)\n }\n\n if (!!feeOptions) {\n const feeBips = encodeFeeBips(feeOptions.fee)\n const feeRecipient = validateAndParseAddress(feeOptions.recipient)\n\n return PaymentsExtended.INTERFACE.encodeFunctionData('unwrapWETH9WithFee(uint256,uint256,address)', [\n toHex(amountMinimum),\n feeBips,\n feeRecipient,\n ])\n } else {\n return PaymentsExtended.INTERFACE.encodeFunctionData('unwrapWETH9(uint256)', [toHex(amountMinimum)])\n }\n }\n\n public static encodeSweepToken(\n token: Token,\n amountMinimum: JSBI,\n recipient?: string,\n feeOptions?: FeeOptions\n ): string {\n // if there's a recipient, just pass it along\n if (typeof recipient === 'string') {\n return Payments.encodeSweepToken(token, amountMinimum, recipient, feeOptions)\n }\n\n if (!!feeOptions) {\n const feeBips = encodeFeeBips(feeOptions.fee)\n const feeRecipient = validateAndParseAddress(feeOptions.recipient)\n\n return PaymentsExtended.INTERFACE.encodeFunctionData('sweepTokenWithFee(address,uint256,uint256,address)', [\n token.address,\n toHex(amountMinimum),\n feeBips,\n feeRecipient,\n ])\n } else {\n return PaymentsExtended.INTERFACE.encodeFunctionData('sweepToken(address,uint256)', [\n token.address,\n toHex(amountMinimum),\n ])\n }\n }\n\n public static encodePull(token: Token, amount: JSBI): string {\n return PaymentsExtended.INTERFACE.encodeFunctionData('pull', [token.address, toHex(amount)])\n }\n\n public static encodeWrapETH(amount: JSBI): string {\n return PaymentsExtended.INTERFACE.encodeFunctionData('wrapETH', [toHex(amount)])\n }\n}\n","import { Currency, CurrencyAmount, Token } from '@juiceswapxyz/sdk-core'\nimport { Pool as V4Pool } from '@juiceswapxyz/v4-sdk'\nimport { TPool } from './TPool'\n\nexport function amountWithPathCurrency(amount: CurrencyAmount<Currency>, pool: TPool): CurrencyAmount<Currency> {\n return CurrencyAmount.fromFractionalAmount(\n getPathCurrency(amount.currency, pool),\n amount.numerator,\n amount.denominator\n )\n}\n\nexport function getPathCurrency(currency: Currency, pool: TPool): Currency {\n // return currency if the currency matches a currency of the pool\n if (pool.involvesToken(currency as Token)) {\n return currency\n\n // return if currency.wrapped if pool involves wrapped currency\n } else if (pool.involvesToken(currency.wrapped as Token)) {\n return currency.wrapped\n\n // return native currency if pool involves native version of wrapped currency (only applies to V4)\n } else if (pool instanceof V4Pool) {\n if (pool.token0.wrapped.equals(currency)) {\n return pool.token0\n } else if (pool.token1.wrapped.equals(currency)) {\n return pool.token1\n }\n\n // otherwise the token is invalid\n } else {\n throw new Error(`Expected currency ${currency.symbol} to be either ${pool.token0.symbol} or ${pool.token1.symbol}`)\n }\n\n return currency // this line needed for typescript to compile\n}\n","import invariant from 'tiny-invariant'\nimport { Currency, Price, Token } from '@juiceswapxyz/sdk-core'\nimport { Pool as V4Pool } from '@juiceswapxyz/v4-sdk'\nimport { getPathCurrency } from '../../utils/pathCurrency'\nimport { TPool } from '../../utils/TPool'\n\n/**\n * Represents a list of pools or pairs through which a swap can occur\n * @template TInput The input token\n * @template TOutput The output token\n */\nexport class MixedRouteSDK<TInput extends Currency, TOutput extends Currency> {\n public readonly pools: TPool[]\n public readonly path: Currency[]\n public readonly input: TInput\n public readonly output: TOutput\n public readonly pathInput: Currency // routes may need to wrap/unwrap a currency to begin trading path\n public readonly pathOutput: Currency // routes may need to wrap/unwrap a currency at the end of trading path\n\n private _midPrice: Price<TInput, TOutput> | null = null\n\n /**\n * Creates an instance of route.\n * @param pools An array of `TPool` objects (pools or pairs), ordered by the route the swap will take\n * @param input The input token\n * @param output The output token\n * @param retainsFakePool Set to true to filter out a pool that has a fake eth-weth pool\n */\n public constructor(pools: TPool[], input: TInput, output: TOutput, retainFakePools = false) {\n pools = retainFakePools ? pools : pools.filter((pool) => !(pool instanceof V4Pool && pool.tickSpacing === 0))\n invariant(pools.length > 0, 'POOLS')\n // there is a pool mismatched to the path if we do not retain the fake eth-weth pools\n\n const chainId = pools[0].chainId\n const allOnSameChain = pools.every((pool) => pool.chainId === chainId)\n invariant(allOnSameChain, 'CHAIN_IDS')\n\n this.pathInput = getPathCurrency(input, pools[0])\n this.pathOutput = getPathCurrency(output, pools[pools.length - 1])\n\n if (!(pools[0] instanceof V4Pool)) {\n invariant(pools[0].involvesToken(this.pathInput as Token), 'INPUT')\n } else {\n invariant((pools[0] as V4Pool).v4InvolvesToken(this.pathInput), 'INPUT')\n }\n const lastPool = pools[pools.length - 1]\n if (lastPool instanceof V4Pool) {\n invariant(lastPool.v4InvolvesToken(output) || lastPool.v4InvolvesToken(output.wrapped), 'OUTPUT')\n } else {\n invariant(lastPool.involvesToken(output.wrapped as Token), 'OUTPUT')\n }\n\n /**\n * Normalizes token0-token1 order and selects the next token/fee step to add to the path\n * */\n const tokenPath: Currency[] = [this.pathInput]\n pools[0].token0.equals(this.pathInput) ? tokenPath.push(pools[0].token1) : tokenPath.push(pools[0].token0)\n\n for (let i = 1; i < pools.length; i++) {\n const pool = pools[i]\n const inputToken = tokenPath[i]\n\n let outputToken\n if (\n // we hit an edge case if it's a v4 pool and neither of the tokens are in the pool OR it is not a v4 pool but the input currency is eth\n (pool instanceof V4Pool && !pool.involvesToken(inputToken)) ||\n (!(pool instanceof V4Pool) && inputToken.isNative)\n ) {\n // We handle the case where the inputToken =/= pool.token0 or pool.token1. There are 2 specific cases.\n if (inputToken.equals(pool.token0.wrapped)) {\n // 1) the inputToken is WETH and the current pool has ETH\n // for example, pools: USDC-WETH, ETH-PEPE, path: USDC, WETH, PEPE\n // second pool is a v4 pool, the first could be any version\n outputToken = pool.token1\n } else if (inputToken.wrapped.equals(pool.token0) || inputToken.wrapped.equals(pool.token1)) {\n // 2) the inputToken is ETH and the current pool has WETH\n // for example, pools: USDC-ETH, WETH-PEPE, path: USDC, ETH, PEPE\n // first pool is a v4 pool, the second could be any version\n outputToken = inputToken.wrapped.equals(pool.token0) ? pool.token1 : pool.token0\n } else {\n throw new Error(`POOL_MISMATCH pool: ${JSON.stringify(pool)} inputToken: ${JSON.stringify(inputToken)}`)\n }\n } else {\n // then the input token must equal either token0 or token1\n invariant(\n inputToken.equals(pool.token0) || inputToken.equals(pool.token1),\n `PATH pool ${JSON.stringify(pool)} inputToken ${JSON.stringify(inputToken)}`\n )\n outputToken = inputToken.equals(pool.token0) ? pool.token1 : pool.token0\n }\n tokenPath.push(outputToken)\n }\n\n this.pools = pools\n this.path = tokenPath\n this.input = input\n this.output = output ?? tokenPath[tokenPath.length - 1]\n }\n\n public get chainId(): number {\n return this.pools[0].chainId\n }\n\n /**\n * Returns the mid price of the route\n */\n public get midPrice(): Price<TInput, TOutput> {\n if (this._midPrice !== null) return this._midPrice\n\n const price = this.pools.slice(1).reduce(\n ({ nextInput, price }, pool) => {\n return nextInput.equals(pool.token0)\n ? {\n nextInput: pool.token1,\n price: price.multiply(pool.token0Price.asFraction),\n }\n : {\n nextInput: pool.token0,\n price: price.multiply(pool.token1Price.asFraction),\n }\n },\n\n this.pools[0].token0.equals(this.pathInput)\n ? {\n nextInput: this.pools[0].token1,\n price: this.pools[0].token0Price.asFraction,\n }\n : {\n nextInput: this.pools[0].token0,\n price: this.pools[0].token1Price.asFraction,\n }\n ).price\n\n return (this._midPrice = new Price(this.input, this.output, price.denominator, price.numerator))\n }\n}\n","import { Currency, Fraction, Percent, Price, sortedInsert, CurrencyAmount, TradeType, Token } from '@juiceswapxyz/sdk-core'\nimport { Pair } from '@juiceswapxyz/v2-sdk'\nimport { BestTradeOptions, Pool as V3Pool } from '@juiceswapxyz/v3-sdk'\nimport { Pool as V4Pool } from '@juiceswapxyz/v4-sdk'\nimport invariant from 'tiny-invariant'\nimport { ONE, ZERO } from '../../constants'\nimport { MixedRouteSDK } from './route'\nimport { amountWithPathCurrency } from '../../utils/pathCurrency'\nimport { TPool } from '../../utils/TPool'\n\n/**\n * Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them\n * @template TInput The input token, either Ether or an ERC-20\n * @template TOutput The output token, either Ether or an ERC-20\n * @template TTradeType The trade type, either exact input or exact output\n * @param a The first trade to compare\n * @param b The second trade to compare\n * @returns A sorted ordering for two neighboring elements in a trade array\n */\nexport function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(\n a: MixedRouteTrade<TInput, TOutput, TTradeType>,\n b: MixedRouteTrade<TInput, TOutput, TTradeType>\n) {\n // must have same input and output token for comparison\n invariant(a.inputAmount.currency.equals(b.inputAmount.currency), 'INPUT_CURRENCY')\n invariant(a.outputAmount.currency.equals(b.outputAmount.currency), 'OUTPUT_CURRENCY')\n if (a.outputAmount.equalTo(b.outputAmount)) {\n if (a.inputAmount.equalTo(b.inputAmount)) {\n // consider the number of hops since each hop costs gas\n const aHops = a.swaps.reduce((total, cur) => total + cur.route.path.length, 0)\n const bHops = b.swaps.reduce((total, cur) => total + cur.route.path.length, 0)\n return aHops - bHops\n }\n // trade A requires less input than trade B, so A should come first\n if (a.inputAmount.lessThan(b.inputAmount)) {\n return -1\n } else {\n return 1\n }\n } else {\n // tradeA has less output than trade B, so should come second\n if (a.outputAmount.lessThan(b.outputAmount)) {\n return 1\n } else {\n return -1\n }\n }\n}\n\n/**\n * Represents a trade executed against a set of routes where some percentage of the input is\n * split across each route.\n *\n * Each route has its own set of pools. Pools can not be re-used across routes.\n *\n * Does not account for slippage, i.e., changes in price environment that can occur between\n * the time the trade is submitted and when it is executed.\n * @notice This class is functionally the same as the `Trade` class in the `@juiceswapxyz/v3-sdk` package, aside from typing and some input validation.\n * @template TInput The input token, either Ether or an ERC-20\n * @template TOutput The output token, either Ether or an ERC-20\n * @template TTradeType The trade type, either exact input or exact output\n */\nexport class MixedRouteTrade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {\n /**\n * @deprecated Deprecated in favor of 'swaps' property. If the trade consists of multiple routes\n * this will return an error.\n *\n * When the trade consists of just a single route, this returns the route of the trade,\n * i.e. which pools the trade goes through.\n */\n public get route(): MixedRouteSDK<TInput, TOutput> {\n invariant(this.swaps.length === 1, 'MULTIPLE_ROUTES')\n return this.swaps[0].route\n }\n\n /**\n * The swaps of the trade, i.e. which routes and how much is swapped in each that\n * make up the trade.\n */\n public readonly swaps: {\n route: MixedRouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[]\n\n /**\n * The type of the trade, either exact in or exact out.\n */\n public readonly tradeType: TTradeType\n\n /**\n * The cached result of the input amount computation\n * @private\n */\n private _inputAmount: CurrencyAmount<TInput> | undefined\n\n /**\n * The input amount for the trade assuming no slippage.\n */\n public get inputAmount(): CurrencyAmount<TInput> {\n if (this._inputAmount) {\n return this._inputAmount\n }\n\n const inputCurrency = this.swaps[0].inputAmount.currency\n const totalInputFromRoutes = this.swaps\n .map(({ inputAmount }) => inputAmount)\n .reduce((total, cur) => total.add(cur), CurrencyAmount.fromRawAmount(inputCurrency, 0))\n\n this._inputAmount = totalInputFromRoutes\n return this._inputAmount\n }\n\n /**\n * The cached result of the output amount computation\n * @private\n */\n private _outputAmount: CurrencyAmount<TOutput> | undefined\n\n /**\n * The output amount for the trade assuming no slippage.\n */\n public get outputAmount(): CurrencyAmount<TOutput> {\n if (this._outputAmount) {\n return this._outputAmount\n }\n\n const outputCurrency = this.swaps[0].outputAmount.currency\n const totalOutputFromRoutes = this.swaps\n .map(({ outputAmount }) => outputAmount)\n .reduce((total, cur) => total.add(cur), CurrencyAmount.fromRawAmount(outputCurrency, 0))\n\n this._outputAmount = totalOutputFromRoutes\n return this._outputAmount\n }\n\n /**\n * The cached result of the computed execution price\n * @private\n */\n private _executionPrice: Price<TInput, TOutput> | undefined\n\n /**\n * The price expressed in terms of output amount/input amount.\n */\n public get executionPrice(): Price<TInput, TOutput> {\n return (\n this._executionPrice ??\n (this._executionPrice = new Price(\n this.inputAmount.currency,\n this.outputAmount.currency,\n this.inputAmount.quotient,\n this.outputAmount.quotient\n ))\n )\n }\n\n /**\n * The cached result of the price impact computation\n * @private\n */\n private _priceImpact: Percent | undefined\n\n /**\n * Returns the percent difference between the route's mid price and the price impact\n */\n public get priceImpact(): Percent {\n if (this._priceImpact) {\n return this._priceImpact\n }\n\n let spotOutputAmount = CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0)\n for (const { route, inputAmount } of this.swaps) {\n const midPrice = route.midPrice\n spotOutputAmount = spotOutputAmount.add(midPrice.quote(inputAmount))\n }\n\n const priceImpact = spotOutputAmount.subtract(this.outputAmount).divide(spotOutputAmount)\n this._priceImpact = new Percent(priceImpact.numerator, priceImpact.denominator)\n\n return this._priceImpact\n }\n\n /**\n * Constructs a trade by simulating swaps through the given route\n * @template TInput The input token, either Ether or an ERC-20.\n * @template TOutput The output token, either Ether or an ERC-20.\n * @template TTradeType The type of the trade, either exact in or exact out.\n * @param route route to swap through\n * @param amount the amount specified, either input or output, depending on tradeType\n * @param tradeType whether the trade is an exact input or exact output swap\n * @returns The route\n */\n public static async fromRoute<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(\n route: MixedRouteSDK<TInput, TOutput>,\n amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>,\n tradeType: TTradeType\n ): Promise<MixedRouteTrade<TInput, TOutput, TTradeType>> {\n const amounts: CurrencyAmount<Currency>[] = new Array(route.path.length)\n let inputAmount: CurrencyAmount<TInput>\n let outputAmount: CurrencyAmount<TOutput>\n\n invariant(tradeType === TradeType.EXACT_INPUT, 'TRADE_TYPE')\n invariant(amount.currency.equals(route.input), 'INPUT')\n\n amounts[0] = amountWithPathCurrency(amount, route.pools[0])\n for (let i = 0; i < route.path.length - 1; i++) {\n const pool = route.pools[i]\n const [outputAmount] = await pool.getOutputAmount(\n amountWithPathCurrency(amounts[i], pool) as CurrencyAmount<Token>\n )\n amounts[i + 1] = outputAmount\n }\n\n inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator)\n outputAmount = CurrencyAmount.fromFractionalAmount(\n route.output,\n amounts[amounts.length - 1].numerator,\n amounts[amounts.length - 1].denominator\n )\n\n return new MixedRouteTrade({\n routes: [{ inputAmount, outputAmount, route }],\n tradeType,\n })\n }\n\n /**\n * Constructs a trade from routes by simulating swaps\n *\n * @template TInput The input token, either Ether or an ERC-20.\n * @template TOutput The output token, either Ether or an ERC-20.\n * @template TTradeType The type of the trade, either exact in or exact out.\n * @param routes the routes to swap through and how much of the amount should be routed through each\n * @param tradeType whether the trade is an exact input or exact output swap\n * @returns The trade\n */\n public static async fromRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(\n routes: {\n amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>\n route: MixedRouteSDK<TInput, TOutput>\n }[],\n tradeType: TTradeType\n ): Promise<MixedRouteTrade<TInput, TOutput, TTradeType>> {\n const populatedRoutes: {\n route: MixedRouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[] = []\n\n invariant(tradeType === TradeType.EXACT_INPUT, 'TRADE_TYPE')\n\n for (const { route, amount } of routes) {\n const amounts: CurrencyAmount<Currency>[] = new Array(route.path.length)\n let inputAmount: CurrencyAmount<TInput>\n let outputAmount: CurrencyAmount<TOutput>\n\n invariant(amount.currency.equals(route.input), 'INPUT')\n inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator)\n amounts[0] = CurrencyAmount.fromFractionalAmount(route.pathInput, amount.numerator, amount.denominator)\n\n for (let i = 0; i < route.path.length - 1; i++) {\n const pool = route.pools[i]\n const [outputAmount] = await pool.getOutputAmount(\n amountWithPathCurrency(amounts[i], pool) as CurrencyAmount<Token>\n )\n amounts[i + 1] = outputAmount\n }\n\n outputAmount = CurrencyAmount.fromFractionalAmount(\n route.output,\n amounts[amounts.length - 1].numerator,\n amounts[amounts.length - 1].denominator\n )\n\n populatedRoutes.push({ route, inputAmount, outputAmount })\n }\n\n return new MixedRouteTrade({\n routes: populatedRoutes,\n tradeType,\n })\n }\n\n /**\n * Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade\n * elsewhere and do not have any tick data\n * @template TInput The input token, either Ether or an ERC-20\n * @template TOutput The output token, either Ether or an ERC-20\n * @template TTradeType The type of the trade, either exact in or exact out\n * @param constructorArguments The arguments passed to the trade constructor\n * @returns The unchecked trade\n */\n public static createUncheckedTrade<\n TInput extends Currency,\n TOutput extends Currency,\n TTradeType extends TradeType\n >(constructorArguments: {\n route: MixedRouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n tradeType: TTradeType\n }): MixedRouteTrade<TInput, TOutput, TTradeType> {\n return new MixedRouteTrade({\n ...constructorArguments,\n routes: [\n {\n inputAmount: constructorArguments.inputAmount,\n outputAmount: constructorArguments.outputAmount,\n route: constructorArguments.route,\n },\n ],\n })\n }\n\n /**\n * Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade\n * elsewhere and do not have any tick data\n * @template TInput The input token, either Ether or an ERC-20\n * @template TOutput The output token, either Ether or an ERC-20\n * @template TTradeType The type of the trade, either exact in or exact out\n * @param constructorArguments The arguments passed to the trade constructor\n * @returns The unchecked trade\n */\n public static createUncheckedTradeWithMultipleRoutes<\n TInput extends Currency,\n TOutput extends Currency,\n TTradeType extends TradeType\n >(constructorArguments: {\n routes: {\n route: MixedRouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[]\n tradeType: TTradeType\n }): MixedRouteTrade<TInput, TOutput, TTradeType> {\n return new MixedRouteTrade(constructorArguments)\n }\n\n /**\n * Construct a trade by passing in the pre-computed property values\n * @param routes The routes through which the trade occurs\n * @param tradeType The type of trade, exact input or exact output\n */\n private constructor({\n routes,\n tradeType,\n }: {\n routes: {\n route: MixedRouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[]\n tradeType: TTradeType\n }) {\n const inputCurrency = routes[0].inputAmount.currency\n const outputCurrency = routes[0].outputAmount.currency\n invariant(\n routes.every(({ route }) => inputCurrency.wrapped.equals(route.input.wrapped)),\n 'INPUT_CURRENCY_MATCH'\n )\n invariant(\n routes.every(({ route }) => outputCurrency.wrapped.equals(route.output.wrapped)),\n 'OUTPUT_CURRENCY_MATCH'\n )\n\n const numPools = routes.map(({ route }) => route.pools.length).reduce((total, cur) => total + cur, 0)\n const poolIdentifierSet = new Set<string>()\n for (const { route } of routes) {\n for (const pool of route.pools) {\n if (pool instanceof V4Pool) {\n poolIdentifierSet.add(pool.poolId)\n } else if (pool instanceof V3Pool) {\n poolIdentifierSet.add(V3Pool.getAddress(pool.token0, pool.token1, pool.fee))\n } else if (pool instanceof Pair) {\n const pair = pool\n poolIdentifierSet.add(Pair.getAddress(pair.token0, pair.token1))\n } else {\n throw new Error('Unexpected pool type in route when constructing trade object')\n }\n }\n }\n\n invariant(numPools === poolIdentifierSet.size, 'POOLS_DUPLICATED')\n\n invariant(tradeType === TradeType.EXACT_INPUT, 'TRADE_TYPE')\n\n this.swaps = routes\n this.tradeType = tradeType\n }\n\n /**\n * Get the minimum amount that must be received from this trade for the given slippage tolerance\n * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade\n * @returns The amount out\n */\n public minimumAmountOut(slippageTolerance: Percent, amountOut = this.outputAmount): CurrencyAmount<TOutput> {\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n /// does not support exactOutput, as enforced in the constructor\n const slippageAdjustedAmountOut = new Fraction(ONE)\n .add(slippageTolerance)\n .invert()\n .multiply(amountOut.quotient).quotient\n return CurrencyAmount.fromRawAmount(amountOut.currency, slippageAdjustedAmountOut)\n }\n\n /**\n * Get the maximum amount in that can be spent via this trade for the given slippage tolerance\n * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade\n * @returns The amount in\n */\n public maximumAmountIn(slippageTolerance: Percent, amountIn = this.inputAmount): CurrencyAmount<TInput> {\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n return amountIn\n /// does not support exactOutput\n }\n\n /**\n * Return the execution price after accounting for slippage tolerance\n * @param slippageTolerance the allowed tolerated slippage\n * @returns The execution price\n */\n public worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput> {\n return new Price(\n this.inputAmount.currency,\n this.outputAmount.currency,\n this.maximumAmountIn(slippageTolerance).quotient,\n this.minimumAmountOut(slippageTolerance).quotient\n )\n }\n\n /**\n * Given a list of pools, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token\n * amount to an output token, making at most `maxHops` hops.\n * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting\n * the amount in among multiple routes.\n * @param pools the pools to consider in finding the best trade\n * @param nextAmountIn exact amount of input currency to spend\n * @param currencyOut the desired currency out\n * @param maxNumResults maximum number of results to return\n * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool\n * @param currentPools used in recursion; the current list of pools\n * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter\n * @param bestTrades used in recursion; the current list of best trades\n * @returns The exact in trade\n */\n public static async bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(\n pools: TPool[],\n currencyAmountIn: CurrencyAmount<TInput>,\n currencyOut: TOutput,\n { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\n // used in recursion.\n currentPools: TPool[] = [],\n nextAmountIn: CurrencyAmount<Currency> = currencyAmountIn,\n bestTrades: MixedRouteTrade<TInput, TOutput, TradeType.EXACT_INPUT>[] = []\n ): Promise<MixedRouteTrade<TInput, TOutput, TradeType.EXACT_INPUT>[]> {\n invariant(pools.length > 0, 'POOLS')\n invariant(maxHops > 0, 'MAX_HOPS')\n invariant(currencyAmountIn === nextAmountIn || currentPools.length > 0, 'INVALID_RECURSION')\n\n const amountIn = nextAmountIn\n for (let i = 0; i < pools.length; i++) {\n const pool = pools[i]\n const amountInAdjusted = pool instanceof V4Pool ? amountIn : amountIn.wrapped\n // pool irrelevant\n if (!pool.token0.equals(amountInAdjusted.currency) && !pool.token1.equals(amountInAdjusted.currency)) continue\n if (pool instanceof Pair) {\n if ((pool as Pair).reserve0.equalTo(ZERO) || (pool as Pair).reserve1.equalTo(ZERO)) continue\n }\n\n let amountOut: CurrencyAmount<Currency>\n try {\n ;[amountOut] =\n pool instanceof V4Pool\n ? await pool.getOutputAmount(amountInAdjusted)\n : await pool.getOutputAmount(amountInAdjusted.wrapped)\n } catch (error) {\n // input too low\n // @ts-ignore[2571] error is unknown\n if (error.isInsufficientInputAmountError) {\n continue\n }\n throw error\n }\n // we have arrived at the output token, so this is the final trade of one of the paths\n if (amountOut.currency.wrapped.equals(currencyOut.wrapped)) {\n sortedInsert(\n bestTrades,\n await MixedRouteTrade.fromRoute(\n new MixedRouteSDK([...currentPools, pool], currencyAmountIn.currency, currencyOut),\n currencyAmountIn,\n TradeType.EXACT_INPUT\n ),\n maxNumResults,\n tradeComparator\n )\n } else if (maxHops > 1 && pools.length > 1) {\n const poolsExcludingThisPool = pools.slice(0, i).concat(pools.slice(i + 1, pools.length))\n\n // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops\n await MixedRouteTrade.bestTradeExactIn(\n poolsExcludingThisPool,\n currencyAmountIn,\n currencyOut,\n {\n maxNumResults,\n maxHops: maxHops - 1,\n },\n [...currentPools, pool],\n amountOut,\n bestTrades\n )\n }\n }\n\n return bestTrades\n }\n}\n","export enum Protocol {\n V2 = 'V2',\n V3 = 'V3',\n V4 = 'V4',\n MIXED = 'MIXED',\n}\n","// entities/route.ts\n\nimport { Route as V2RouteSDK, Pair } from '@juiceswapxyz/v2-sdk'\nimport { Route as V3RouteSDK, Pool as V3Pool } from '@juiceswapxyz/v3-sdk'\nimport { Route as V4RouteSDK, Pool as V4Pool } from '@juiceswapxyz/v4-sdk'\nimport { Protocol } from './protocol'\nimport { Currency, Price, Token } from '@juiceswapxyz/sdk-core'\nimport { MixedRouteSDK } from './mixedRoute/route'\n\n// Helper function to get the pathInput and pathOutput for a V2 / V3 route\n// currency could be native so we check against the wrapped version as they don't support native ETH in path\nexport function getPathToken(currency: Currency, pool: Pair | V3Pool): Token {\n if (pool.token0.wrapped.equals(currency.wrapped)) {\n return pool.token0\n } else if (pool.token1.wrapped.equals(currency.wrapped)) {\n return pool.token1\n } else {\n throw new Error(`Expected token ${currency.symbol} to be either ${pool.token0.symbol} or ${pool.token1.symbol}`)\n }\n}\n\nexport interface IRoute<TInput extends Currency, TOutput extends Currency, TPool extends Pair | V3Pool | V4Pool> {\n protocol: Protocol\n // array of pools if v3 or pairs if v2\n pools: TPool[]\n path: Currency[]\n midPrice: Price<TInput, TOutput>\n input: TInput\n output: TOutput\n pathInput: Currency\n pathOutput: Currency\n}\n\n// V2 route wrapper\nexport class RouteV2<TInput extends Currency, TOutput extends Currency>\n extends V2RouteSDK<TInput, TOutput>\n implements IRoute<TInput, TOutput, Pair>\n{\n public readonly protocol: Protocol = Protocol.V2\n public readonly pools: Pair[]\n public pathInput: Currency\n public pathOutput: Currency\n\n constructor(v2Route: V2RouteSDK<TInput, TOutput>) {\n super(v2Route.pairs, v2Route.input, v2Route.output)\n this.pools = this.pairs\n this.pathInput = getPathToken(v2Route.input, this.pairs[0])\n this.pathOutput = getPathToken(v2Route.output, this.pairs[this.pairs.length - 1])\n }\n}\n\n// V3 route wrapper\nexport class RouteV3<TInput extends Currency, TOutput extends Currency>\n extends V3RouteSDK<TInput, TOutput>\n implements IRoute<TInput, TOutput, V3Pool>\n{\n public readonly protocol: Protocol = Protocol.V3\n public readonly path: Token[]\n public pathInput: Currency\n public pathOutput: Currency\n\n constructor(v3Route: V3RouteSDK<TInput, TOutput>) {\n super(v3Route.pools, v3Route.input, v3Route.output)\n this.path = v3Route.tokenPath\n this.pathInput = getPathToken(v3Route.input, this.pools[0])\n this.pathOutput = getPathToken(v3Route.output, this.pools[this.pools.length - 1])\n }\n}\n\n// V4 route wrapper\nexport class RouteV4<TInput extends Currency, TOutput extends Currency>\n extends V4RouteSDK<TInput, TOutput>\n implements IRoute<TInput, TOutput, V4Pool>\n{\n public readonly protocol: Protocol = Protocol.V4\n public readonly path: Currency[]\n\n constructor(v4Route: V4RouteSDK<TInput, TOutput>) {\n super(v4Route.pools, v4Route.input, v4Route.output)\n this.path = v4Route.currencyPath\n }\n}\n\n// Mixed route wrapper\nexport class MixedRoute<TInput extends Currency, TOutput extends Currency>\n extends MixedRouteSDK<TInput, TOutput>\n implements IRoute<TInput, TOutput, Pair | V3Pool | V4Pool>\n{\n public readonly protocol: Protocol = Protocol.MIXED\n\n constructor(mixedRoute: MixedRouteSDK<TInput, TOutput>) {\n super(mixedRoute.pools, mixedRoute.input, mixedRoute.output)\n }\n}\n","import { Currency, CurrencyAmount, Fraction, Percent, Price, TradeType, Ether } from '@juiceswapxyz/sdk-core'\nimport { Pair, Route as V2RouteSDK, Trade as V2TradeSDK } from '@juiceswapxyz/v2-sdk'\nimport { Pool as V3Pool, Route as V3RouteSDK, Trade as V3TradeSDK } from '@juiceswapxyz/v3-sdk'\nimport { Pool as V4Pool, Route as V4RouteSDK, Trade as V4TradeSDK } from '@juiceswapxyz/v4-sdk'\nimport invariant from 'tiny-invariant'\nimport { ONE, ONE_HUNDRED_PERCENT, ZERO, ZERO_PERCENT } from '../constants'\nimport { MixedRouteSDK } from './mixedRoute/route'\nimport { MixedRouteTrade as MixedRouteTradeSDK } from './mixedRoute/trade'\nimport { IRoute, MixedRoute, RouteV2, RouteV3, RouteV4 } from './route'\n\nexport class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {\n public readonly routes: IRoute<TInput, TOutput, Pair | V3Pool | V4Pool>[]\n public readonly tradeType: TTradeType\n private _outputAmount: CurrencyAmount<TOutput> | undefined\n private _inputAmount: CurrencyAmount<TInput> | undefined\n private _nativeInputRoutes: IRoute<TInput, TOutput, Pair | V3Pool | V4Pool>[] | undefined\n private _wethInputRoutes: IRoute<TInput, TOutput, Pair | V3Pool | V4Pool>[] | undefined\n\n /**\n * The swaps of the trade, i.e. which routes and how much is swapped in each that\n * make up the trade. May consist of swaps in v2 or v3.\n */\n public readonly swaps: {\n route: IRoute<TInput, TOutput, Pair | V3Pool | V4Pool>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[]\n\n // construct a trade across v2 and v3 routes from pre-computed amounts\n public constructor({\n v2Routes = [],\n v3Routes = [],\n v4Routes = [],\n mixedRoutes = [],\n tradeType,\n }: {\n v2Routes?: {\n routev2: V2RouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[]\n v3Routes?: {\n routev3: V3RouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[]\n v4Routes?: {\n routev4: V4RouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[]\n mixedRoutes?: {\n mixedRoute: MixedRouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[]\n tradeType: TTradeType\n }) {\n this.swaps = []\n this.routes = []\n // wrap v2 routes\n for (const { routev2, inputAmount, outputAmount } of v2Routes) {\n const route = new RouteV2(routev2)\n this.routes.push(route)\n this.swaps.push({\n route,\n inputAmount,\n outputAmount,\n })\n }\n // wrap v3 routes\n for (const { routev3, inputAmount, outputAmount } of v3Routes) {\n const route = new RouteV3(routev3)\n this.routes.push(route)\n this.swaps.push({\n route,\n inputAmount,\n outputAmount,\n })\n }\n // wrap v4 routes\n for (const { routev4, inputAmount, outputAmount } of v4Routes) {\n const route = new RouteV4(routev4)\n this.routes.push(route)\n this.swaps.push({\n route,\n inputAmount,\n outputAmount,\n })\n }\n for (const { mixedRoute, inputAmount, outputAmount } of mixedRoutes) {\n const route = new MixedRoute(mixedRoute)\n this.routes.push(route)\n this.swaps.push({\n route,\n inputAmount,\n outputAmount,\n })\n }\n\n if (this.swaps.length === 0) {\n throw new Error('No routes provided when calling Trade constructor')\n }\n\n this.tradeType = tradeType\n\n // each route must have the same input and output currency\n const inputCurrency = this.swaps[0].inputAmount.currency\n const outputCurrency = this.swaps[0].outputAmount.currency\n invariant(\n this.swaps.every(({ route }) => inputCurrency.wrapped.equals(route.input.wrapped)),\n 'INPUT_CURRENCY_MATCH'\n )\n invariant(\n this.swaps.every(({ route }) => outputCurrency.wrapped.equals(route.output.wrapped)),\n 'OUTPUT_CURRENCY_MATCH'\n )\n\n // pools must be unique inter protocols\n const numPools = this.swaps.map(({ route }) => route.pools.length).reduce((total, cur) => total + cur, 0)\n const poolIdentifierSet = new Set<string>()\n for (const { route } of this.swaps) {\n for (const pool of route.pools) {\n if (pool instanceof V4Pool) {\n poolIdentifierSet.add(pool.poolId)\n } else if (pool instanceof V3Pool) {\n poolIdentifierSet.add(V3Pool.getAddress(pool.token0, pool.token1, pool.fee))\n } else if (pool instanceof Pair) {\n const pair = pool\n poolIdentifierSet.add(Pair.getAddress(pair.token0, pair.token1))\n } else {\n throw new Error('Unexpected pool type in route when constructing trade object')\n }\n }\n }\n invariant(numPools === poolIdentifierSet.size, 'POOLS_DUPLICATED')\n }\n\n public get inputAmount(): CurrencyAmount<TInput> {\n if (this._inputAmount) {\n return this._inputAmount\n }\n\n const inputAmountCurrency = this.swaps[0].inputAmount.currency\n const totalInputFromRoutes = this.swaps\n .map(({ inputAmount: routeInputAmount }) => routeInputAmount)\n .reduce((total, cur) => total.add(cur), CurrencyAmount.fromRawAmount(inputAmountCurrency, 0))\n\n this._inputAmount = totalInputFromRoutes\n return this._inputAmount\n }\n\n public get outputAmount(): CurrencyAmount<TOutput> {\n if (this._outputAmount) {\n return this._outputAmount\n }\n\n const outputCurrency = this.swaps[0].outputAmount.currency\n const totalOutputFromRoutes = this.swaps\n .map(({ outputAmount: routeOutputAmount }) => routeOutputAmount)\n .reduce((total, cur) => total.add(cur), CurrencyAmount.fromRawAmount(outputCurrency, 0))\n\n this._outputAmount = totalOutputFromRoutes\n return this._outputAmount\n }\n\n /**\n * Returns the sum of all swaps within the trade\n * @returns\n * inputAmount: total input amount\n * inputAmountNative: total amount of native currency required for ETH input paths\n * - 0 if inputAmount is native but no native input paths\n * - undefined if inputAmount is not native\n * outputAmount: total output amount\n * outputAmountNative: total amount of native currency returned from ETH output paths\n * - 0 if outputAmount is native but no native output paths\n * - undefined if outputAmount is not native\n */\n public get amounts(): {\n inputAmount: CurrencyAmount<TInput>\n inputAmountNative: CurrencyAmount<TInput> | undefined\n outputAmount: CurrencyAmount<TOutput>\n outputAmountNative: CurrencyAmount<TOutput> | undefined\n } {\n // Find native currencies for reduce below\n const inputNativeCurrency = this.swaps.find(({ inputAmount }) => inputAmount.currency.isNative)?.inputAmount\n .currency\n const outputNativeCurrency = this.swaps.find(({ outputAmount }) => outputAmount.currency.isNative)?.outputAmount\n .currency\n\n return {\n inputAmount: this.inputAmount,\n inputAmountNative: inputNativeCurrency\n ? this.swaps.reduce((total, swap) => {\n return swap.route.pathInput.isNative ? total.add(swap.inputAmount) : total\n }, CurrencyAmount.fromRawAmount(inputNativeCurrency, 0))\n : undefined,\n outputAmount: this.outputAmount,\n outputAmountNative: outputNativeCurrency\n ? this.swaps.reduce((total, swap) => {\n return swap.route.pathOutput.isNative ? total.add(swap.outputAmount) : total\n }, CurrencyAmount.fromRawAmount(outputNativeCurrency, 0))\n : undefined,\n }\n }\n\n public get numberOfInputWraps(): number {\n // if the trade's input is eth it may require a wrap\n if (this.inputAmount.currency.isNative) {\n return this.wethInputRoutes.length\n } else return 0\n }\n\n public get numberOfInputUnwraps(): number {\n // if the trade's input is weth, it may require an unwrap\n if (this.isWrappedNative(this.inputAmount.currency)) {\n return this.nativeInputRoutes.length\n } else return 0\n }\n\n public get nativeInputRoutes(): IRoute<TInput, TOutput, Pair | V3Pool | V4Pool>[] {\n if (this._nativeInputRoutes) {\n return this._nativeInputRoutes\n }\n\n this._nativeInputRoutes = this.routes.filter((route) => route.pathInput.isNative)\n return this._nativeInputRoutes\n }\n\n public get wethInputRoutes(): IRoute<TInput, TOutput, Pair | V3Pool | V4Pool>[] {\n if (this._wethInputRoutes) {\n return this._wethInputRoutes\n }\n\n this._wethInputRoutes = this.routes.filter((route) => this.isWrappedNative(route.pathInput))\n return this._wethInputRoutes\n }\n\n private _executionPrice: Price<TInput, TOutput> | undefined\n\n /**\n * The price expressed in terms of output amount/input amount.\n */\n public get executionPrice(): Price<TInput, TOutput> {\n return (\n this._executionPrice ??\n (this._executionPrice = new Price(\n this.inputAmount.currency,\n this.outputAmount.currency,\n this.inputAmount.quotient,\n this.outputAmount.quotient\n ))\n )\n }\n\n /**\n * Returns the sell tax of the input token\n */\n public get inputTax(): Percent {\n const inputCurrency = this.inputAmount.currency\n if (inputCurrency.isNative || !inputCurrency.wrapped.sellFeeBps) return ZERO_PERCENT\n\n return new Percent(inputCurrency.wrapped.sellFeeBps.toNumber(), 10000)\n }\n\n /**\n * Returns the buy tax of the output token\n */\n public get outputTax(): Percent {\n const outputCurrency = this.outputAmount.currency\n if (outputCurrency.isNative || !outputCurrency.wrapped.buyFeeBps) return ZERO_PERCENT\n\n return new Percent(outputCurrency.wrapped.buyFeeBps.toNumber(), 10000)\n }\n\n private isWrappedNative(currency: Currency): boolean {\n const chainId = currency.chainId\n return currency.equals(Ether.onChain(chainId).wrapped)\n }\n\n /**\n * The cached result of the price impact computation\n * @private\n */\n private _priceImpact: Percent | undefined\n /**\n * Returns the percent difference between the route's mid price and the expected execution price\n * In order to exclude token taxes from the price impact calculation, the spot price is calculated\n * using a ratio of values that go into the pools, which are the post-tax input amount and pre-tax output amount.\n */\n public get priceImpact(): Percent {\n if (this._priceImpact) {\n return this._priceImpact\n }\n\n // returns 0% price impact even though this may be inaccurate as a swap may have occured.\n // because we're unable to derive the pre-buy-tax amount, use 0% as a placeholder.\n if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) return ZERO_PERCENT\n\n let spotOutputAmount = CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0)\n for (const { route, inputAmount } of this.swaps) {\n const midPrice = route.midPrice\n const postTaxInputAmount = inputAmount.multiply(new Fraction(ONE).subtract(this.inputTax))\n spotOutputAmount = spotOutputAmount.add(midPrice.quote(postTaxInputAmount))\n }\n\n // if the total output of this trade is 0, then most likely the post-tax input was also 0, and therefore this swap\n // does not move the pools' market price\n if (spotOutputAmount.equalTo(ZERO)) return ZERO_PERCENT\n\n const preTaxOutputAmount = this.outputAmount.divide(new Fraction(ONE).subtract(this.outputTax))\n const priceImpact = spotOutputAmount.subtract(preTaxOutputAmount).divide(spotOutputAmount)\n this._priceImpact = new Percent(priceImpact.numerator, priceImpact.denominator)\n\n return this._priceImpact\n }\n\n /**\n * Get the minimum amount that must be received from this trade for the given slippage tolerance\n * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade\n * @returns The amount out\n */\n public minimumAmountOut(slippageTolerance: Percent, amountOut = this.outputAmount): CurrencyAmount<TOutput> {\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n if (this.tradeType === TradeType.EXACT_OUTPUT) {\n return amountOut\n } else {\n const slippageAdjustedAmountOut = new Fraction(ONE)\n .add(slippageTolerance)\n .invert()\n .multiply(amountOut.quotient).quotient\n return CurrencyAmount.fromRawAmount(amountOut.currency, slippageAdjustedAmountOut)\n }\n }\n\n /**\n * Get the maximum amount in that can be spent via this trade for the given slippage tolerance\n * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade\n * @returns The amount in\n */\n public maximumAmountIn(slippageTolerance: Percent, amountIn = this.inputAmount): CurrencyAmount<TInput> {\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n if (this.tradeType === TradeType.EXACT_INPUT) {\n return amountIn\n } else {\n const slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(amountIn.quotient).quotient\n return CurrencyAmount.fromRawAmount(amountIn.currency, slippageAdjustedAmountIn)\n }\n }\n\n /**\n * Return the execution price after accounting for slippage tolerance\n * @param slippageTolerance the allowed tolerated slippage\n * @returns The execution price\n */\n public worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput> {\n return new Price(\n this.inputAmount.currency,\n this.outputAmount.currency,\n this.maximumAmountIn(slippageTolerance).quotient,\n this.minimumAmountOut(slippageTolerance).quotient\n )\n }\n\n public static async fromRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(\n v2Routes: {\n routev2: V2RouteSDK<TInput, TOutput>\n amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>\n }[],\n v3Routes: {\n routev3: V3RouteSDK<TInput, TOutput>\n amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>\n }[],\n tradeType: TTradeType,\n mixedRoutes?: {\n mixedRoute: MixedRouteSDK<TInput, TOutput>\n amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>\n }[],\n v4Routes?: {\n routev4: V4RouteSDK<TInput, TOutput>\n amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>\n }[]\n ): Promise<Trade<TInput, TOutput, TTradeType>> {\n const populatedV2Routes: {\n routev2: V2RouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[] = []\n\n const populatedV3Routes: {\n routev3: V3RouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[] = []\n\n const populatedV4Routes: {\n routev4: V4RouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[] = []\n\n const populatedMixedRoutes: {\n mixedRoute: MixedRouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[] = []\n\n for (const { routev2, amount } of v2Routes) {\n const v2Trade = new V2TradeSDK(routev2, amount, tradeType)\n const { inputAmount, outputAmount } = v2Trade\n\n populatedV2Routes.push({\n routev2,\n inputAmount,\n outputAmount,\n })\n }\n\n for (const { routev3, amount } of v3Routes) {\n const v3Trade = await V3TradeSDK.fromRoute(routev3, amount, tradeType)\n const { inputAmount, outputAmount } = v3Trade\n\n populatedV3Routes.push({\n routev3,\n inputAmount,\n outputAmount,\n })\n }\n\n if (v4Routes) {\n for (const { routev4, amount } of v4Routes) {\n const v4Trade = await V4TradeSDK.fromRoute(routev4, amount, tradeType)\n const { inputAmount, outputAmount } = v4Trade\n\n populatedV4Routes.push({\n routev4,\n inputAmount,\n outputAmount,\n })\n }\n }\n\n if (mixedRoutes) {\n for (const { mixedRoute, amount } of mixedRoutes) {\n const mixedRouteTrade = await MixedRouteTradeSDK.fromRoute(mixedRoute, amount, tradeType)\n const { inputAmount, outputAmount } = mixedRouteTrade\n\n populatedMixedRoutes.push({\n mixedRoute,\n inputAmount,\n outputAmount,\n })\n }\n }\n\n return new Trade({\n v2Routes: populatedV2Routes,\n v3Routes: populatedV3Routes,\n v4Routes: populatedV4Routes,\n mixedRoutes: populatedMixedRoutes,\n tradeType,\n })\n }\n\n public static async fromRoute<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(\n route:\n | V2RouteSDK<TInput, TOutput>\n | V3RouteSDK<TInput, TOutput>\n | V4RouteSDK<TInput, TOutput>\n | MixedRouteSDK<TInput, TOutput>,\n amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>,\n tradeType: TTradeType\n ): Promise<Trade<TInput, TOutput, TTradeType>> {\n let v2Routes: {\n routev2: V2RouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[] = []\n\n let v3Routes: {\n routev3: V3RouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[] = []\n\n let v4Routes: {\n routev4: V4RouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[] = []\n\n let mixedRoutes: {\n mixedRoute: MixedRouteSDK<TInput, TOutput>\n inputAmount: CurrencyAmount<TInput>\n outputAmount: CurrencyAmount<TOutput>\n }[] = []\n\n if (route instanceof V2RouteSDK) {\n const v2Trade = new V2TradeSDK(route, amount, tradeType)\n const { inputAmount, outputAmount } = v2Trade\n v2Routes = [{ routev2: route, inputAmount, outputAmount }]\n } else if (route instanceof V3RouteSDK) {\n const v3Trade = await V3TradeSDK.fromRoute(route, amount, tradeType)\n const { inputAmount, outputAmount } = v3Trade\n v3Routes = [{ routev3: route, inputAmount, outputAmount }]\n } else if (route instanceof V4RouteSDK) {\n const v4Trade = await V4TradeSDK.fromRoute(route, amount, tradeType)\n const { inputAmount, outputAmount } = v4Trade\n v4Routes = [{ routev4: route, inputAmount, outputAmount }]\n } else if (route instanceof MixedRouteSDK) {\n const mixedRouteTrade = await MixedRouteTradeSDK.fromRoute(route, amount, tradeType)\n const { inputAmount, outputAmount } = mixedRouteTrade\n mixedRoutes = [{ mixedRoute: route, inputAmount, outputAmount }]\n } else {\n throw new Error('Invalid route type')\n }\n\n return new Trade({\n v2Routes,\n v3Routes,\n v4Routes,\n mixedRoutes,\n tradeType,\n })\n }\n}\n","import { pack } from '@ethersproject/solidity'\nimport { Currency } from '@juiceswapxyz/sdk-core'\nimport { Pair } from '@juiceswapxyz/v2-sdk'\nimport { Pool as V3Pool } from '@juiceswapxyz/v3-sdk'\nimport { Pool as V4Pool } from '@juiceswapxyz/v4-sdk'\nimport {\n ADDRESS_ZERO,\n MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER,\n MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER,\n MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER,\n MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER,\n} from '../constants'\nimport { MixedRouteSDK } from '../entities/mixedRoute/route'\nimport { TPool } from './TPool'\n\n/**\n * Converts a route to a hex encoded path\n * @notice only supports exactIn route encodings\n * @param route the mixed path to convert to an encoded path\n * @param useMixedRouterQuoteV2 if true, uses the Mixed Quoter V2 encoding for v4 pools. By default, we do not set it. This is only used in SOR for explicit setting during onchain quoting.\n * @returns the exactIn encoded path\n */\nexport function encodeMixedRouteToPath(\n route: MixedRouteSDK<Currency, Currency>,\n useMixedRouterQuoteV2?: boolean\n): string {\n const containsV4Pool = useMixedRouterQuoteV2 ?? route.pools.some((pool) => pool instanceof V4Pool)\n\n let path: (string | number)[]\n let types: string[]\n\n if (containsV4Pool) {\n path = [route.pathInput.isNative ? ADDRESS_ZERO : route.pathInput.address]\n types = ['address']\n let currencyIn = route.pathInput\n\n for (const pool of route.pools) {\n const currencyOut = currencyIn.equals(pool.token0) ? pool.token1 : pool.token0\n\n if (pool instanceof V4Pool) {\n // a tickSpacing of 0 indicates a \"fake\" v4 pool where the quote actually requires a wrap or unwrap\n // the fake v4 pool will always have native as token0 and wrapped native as token1\n if (pool.tickSpacing === 0) {\n const wrapOrUnwrapEncoding = 0\n path.push(wrapOrUnwrapEncoding, currencyOut.isNative ? ADDRESS_ZERO : currencyOut.wrapped.address)\n types.push('uint8', 'address')\n } else {\n const v4Fee = pool.fee + MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER\n path.push(\n v4Fee,\n pool.tickSpacing,\n pool.hooks,\n currencyOut.isNative ? ADDRESS_ZERO : currencyOut.wrapped.address\n )\n types.push('uint24', 'uint24', 'address', 'address')\n }\n } else if (pool instanceof V3Pool) {\n const v3Fee = pool.fee + MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER\n path.push(v3Fee, currencyOut.wrapped.address)\n types.push('uint24', 'address')\n } else if (pool instanceof Pair) {\n const v2Fee = MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER\n path.push(v2Fee, currencyOut.wrapped.address)\n types.push('uint8', 'address')\n } else {\n throw new Error(`Unsupported pool type ${JSON.stringify(pool)}`)\n }\n\n currencyIn = currencyOut\n }\n } else {\n // TODO: ROUTE-276 - delete this else block\n // We introduced this else block as a safety measure to prevent non-v4 mixed routes from potentially regressing\n // We'd like to gain more confidence in the new implementation before removing this block\n const result = route.pools.reduce(\n (\n { inputToken, path, types }: { inputToken: Currency; path: (string | number)[]; types: string[] },\n pool: TPool,\n index\n ): { inputToken: Currency; path: (string | number)[]; types: string[] } => {\n const outputToken: Currency = pool.token0.equals(inputToken) ? pool.token1 : pool.token0\n if (index === 0) {\n return {\n inputToken: outputToken,\n types: ['address', 'uint24', 'address'],\n path: [\n inputToken.wrapped.address,\n pool instanceof V3Pool ? pool.fee : MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER,\n outputToken.wrapped.address,\n ],\n }\n } else {\n return {\n inputToken: outputToken,\n types: [...types, 'uint24', 'address'],\n path: [\n ...path,\n pool instanceof V3Pool ? pool.fee : MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER,\n outputToken.wrapped.address,\n ],\n }\n }\n },\n { inputToken: route.input, path: [], types: [] }\n )\n\n path = result.path\n types = result.types\n }\n\n return pack(types, path)\n}\n","import { Currency, Token } from '@juiceswapxyz/sdk-core'\nimport { Pair } from '@juiceswapxyz/v2-sdk'\nimport { Pool as V3Pool } from '@juiceswapxyz/v3-sdk'\nimport { Pool as V4Pool } from '@juiceswapxyz/v4-sdk'\nimport { MixedRouteSDK } from '../entities/mixedRoute/route'\nimport { TPool } from './TPool'\n\n/**\n * Utility function to return each consecutive section of Pools or Pairs in a MixedRoute\n * @param route\n * @returns a nested array of Pools or Pairs in the order of the route\n */\nexport const partitionMixedRouteByProtocol = (route: MixedRouteSDK<Currency, Currency>): TPool[][] => {\n let acc = []\n\n let left = 0\n let right = 0\n while (right < route.pools.length) {\n if (\n (route.pools[left] instanceof V4Pool && !(route.pools[right] instanceof V4Pool)) ||\n (route.pools[left] instanceof V3Pool && !(route.pools[right] instanceof V3Pool)) ||\n (route.pools[left] instanceof Pair && !(route.pools[right] instanceof Pair))\n ) {\n acc.push(route.pools.slice(left, right))\n left = right\n }\n // seek forward with right pointer\n right++\n if (right === route.pools.length) {\n /// we reached the end, take the rest\n acc.push(route.pools.slice(left, right))\n }\n }\n return acc\n}\n\n/**\n * Simple utility function to get the output of an array of Pools or Pairs\n * @param pools\n * @param firstInputToken\n * @returns the output token of the last pool in the array\n */\nexport const getOutputOfPools = (pools: TPool[], firstInputToken: Currency): Currency => {\n const { inputToken: outputToken } = pools.reduce(\n ({ inputToken }, pool: TPool): { inputToken: Currency } => {\n if (!pool.involvesToken(inputToken as Token)) throw new Error('PATH')\n const outputToken: Currency = pool.token0.equals(inputToken) ? pool.token1 : pool.token0\n return {\n inputToken: outputToken,\n }\n },\n { inputToken: firstInputToken }\n )\n return outputToken\n}\n","import { Interface } from '@ethersproject/abi'\nimport { Currency, CurrencyAmount, Percent, TradeType, validateAndParseAddress, WETH9 } from '@juiceswapxyz/sdk-core'\nimport ISwapRouter02 from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json'\nimport { Trade as V2Trade } from '@juiceswapxyz/v2-sdk'\nimport {\n encodeRouteToPath,\n FeeOptions,\n MethodParameters,\n Payments,\n PermitOptions,\n Pool as V3Pool,\n Position,\n SelfPermit,\n toHex,\n Trade as V3Trade,\n} from '@juiceswapxyz/v3-sdk'\nimport { Pool as V4Pool } from '@juiceswapxyz/v4-sdk'\nimport invariant from 'tiny-invariant'\nimport JSBI from 'jsbi'\nimport { ADDRESS_THIS, MSG_SENDER } from './constants'\nimport { ApproveAndCall, ApprovalTypes, CondensedAddLiquidityOptions } from './approveAndCall'\nimport { Trade } from './entities/trade'\nimport { Protocol } from './entities/protocol'\nimport { MixedRoute, RouteV2, RouteV3 } from './entities/route'\nimport { MulticallExtended, Validation } from './multicallExtended'\nimport { PaymentsExtended } from './paymentsExtended'\nimport { MixedRouteTrade } from './entities/mixedRoute/trade'\nimport { encodeMixedRouteToPath } from './utils/encodeMixedRouteToPath'\nimport { MixedRouteSDK } from './entities/mixedRoute/route'\nimport { partitionMixedRouteByProtocol, getOutputOfPools } from './utils'\n\nconst ZERO = JSBI.BigInt(0)\nconst REFUND_ETH_PRICE_IMPACT_THRESHOLD = new Percent(JSBI.BigInt(50), JSBI.BigInt(100))\n\n/**\n * Options for producing the arguments to send calls to the router.\n */\nexport interface SwapOptions {\n /**\n * How much the execution price is allowed to move unfavorably from the trade execution price.\n */\n slippageTolerance: Percent\n\n /**\n * The account that should receive the output. If omitted, output is sent to msg.sender.\n */\n recipient?: string\n\n /**\n * Either deadline (when the transaction expires, in epoch seconds), or previousBlockhash.\n */\n deadlineOrPreviousBlockhash?: Validation\n\n /**\n * The optional permit parameters for spending the input.\n */\n inputTokenPermit?: PermitOptions\n\n /**\n * Optional information for taking a fee on output.\n */\n fee?: FeeOptions\n}\n\nexport interface SwapAndAddOptions extends SwapOptions {\n /**\n * The optional permit parameters for pulling in remaining output token.\n */\n outputTokenPermit?: PermitOptions\n}\n\ntype AnyTradeType =\n | Trade<Currency, Currency, TradeType>\n | V2Trade<Currency, Currency, TradeType>\n | V3Trade<Currency, Currency, TradeType>\n | MixedRouteTrade<Currency, Currency, TradeType>\n | (\n | V2Trade<Currency, Currency, TradeType>\n | V3Trade<Currency, Currency, TradeType>\n | MixedRouteTrade<Currency, Currency, TradeType>\n )[]\n\n/**\n * Represents the Uniswap V2 + V3 SwapRouter02, and has static methods for helping execute trades.\n */\nexport abstract class SwapRouter {\n public static INTERFACE: Interface = new Interface(ISwapRouter02.abi)\n\n /**\n * Cannot be constructed.\n */\n private constructor() {}\n\n /**\n * @notice Generates the calldata for a Swap with a V2 Route.\n * @param trade The V2Trade to encode.\n * @param options SwapOptions to use for the trade.\n * @param routerMustCustody Flag for whether funds should be sent to the router\n * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check\n * @returns A string array of calldatas for the trade.\n */\n private static encodeV2Swap(\n trade: V2Trade<Currency, Currency, TradeType>,\n options: SwapOptions,\n routerMustCustody: boolean,\n performAggregatedSlippageCheck: boolean\n ): string {\n const amountIn: string = toHex(trade.maximumAmountIn(options.slippageTolerance).quotient)\n const amountOut: string = toHex(trade.minimumAmountOut(options.slippageTolerance).quotient)\n\n const path = trade.route.path.map((token) => token.address)\n const recipient = routerMustCustody\n ? ADDRESS_THIS\n : typeof options.recipient === 'undefined'\n ? MSG_SENDER\n : validateAndParseAddress(options.recipient)\n\n if (trade.tradeType === TradeType.EXACT_INPUT) {\n const exactInputParams = [amountIn, performAggregatedSlippageCheck ? 0 : amountOut, path, recipient]\n\n return SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams)\n } else {\n const exactOutputParams = [amountOut, amountIn, path, recipient]\n\n return SwapRouter.INTERFACE.encodeFunctionData('swapTokensForExactTokens', exactOutputParams)\n }\n }\n\n /**\n * @notice Generates the calldata for a Swap with a V3 Route.\n * @param trade The V3Trade to encode.\n * @param options SwapOptions to use for the trade.\n * @param routerMustCustody Flag for whether funds should be sent to the router\n * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check\n * @returns A string array of calldatas for the trade.\n */\n private static encodeV3Swap(\n trade: V3Trade<Currency, Currency, TradeType>,\n options: SwapOptions,\n routerMustCustody: boolean,\n performAggregatedSlippageCheck: boolean\n ): string[] {\n const calldatas: string[] = []\n\n for (const { route, inputAmount, outputAmount } of trade.swaps) {\n const amountIn: string = toHex(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient)\n const amountOut: string = toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient)\n\n // flag for whether the trade is single hop or not\n const singleHop = route.pools.length === 1\n\n const recipient = routerMustCustody\n ? ADDRESS_THIS\n : typeof options.recipient === 'undefined'\n ? MSG_SENDER\n : validateAndParseAddress(options.recipient)\n\n if (singleHop) {\n if (trade.tradeType === TradeType.EXACT_INPUT) {\n const exactInputSingleParams = {\n tokenIn: route.tokenPath[0].address,\n tokenOut: route.tokenPath[1].address,\n fee: route.pools[0].fee,\n recipient,\n amountIn,\n amountOutMinimum: performAggregatedSlippageCheck ? 0 : amountOut,\n sqrtPriceLimitX96: 0,\n }\n\n calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInputSingle', [exactInputSingleParams]))\n } else {\n const exactOutputSingleParams = {\n tokenIn: route.tokenPath[0].address,\n tokenOut: route.tokenPath[1].address,\n fee: route.pools[0].fee,\n recipient,\n amountOut,\n amountInMaximum: amountIn,\n sqrtPriceLimitX96: 0,\n }\n\n calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactOutputSingle', [exactOutputSingleParams]))\n }\n } else {\n const path: string = encodeRouteToPath(route, trade.tradeType === TradeType.EXACT_OUTPUT)\n\n if (trade.tradeType === TradeType.EXACT_INPUT) {\n const exactInputParams = {\n path,\n recipient,\n amountIn,\n amountOutMinimum: performAggregatedSlippageCheck ? 0 : amountOut,\n }\n\n calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [exactInputParams]))\n } else {\n const exactOutputParams = {\n path,\n recipient,\n amountOut,\n amountInMaximum: amountIn,\n }\n\n calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactOutput', [exactOutputParams]))\n }\n }\n }\n\n return calldatas\n }\n\n /**\n * @notice Generates the calldata for a MixedRouteSwap. Since single hop routes are not MixedRoutes, we will instead generate\n * them via the existing encodeV3Swap and encodeV2Swap methods.\n * @param trade The MixedRouteTrade to encode.\n * @param options SwapOptions to use for the trade.\n * @param routerMustCustody Flag for whether funds should be sent to the router\n * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check\n * @returns A string array of calldatas for the trade.\n */\n private static encodeMixedRouteSwap(\n trade: MixedRouteTrade<Currency, Currency, TradeType>,\n options: SwapOptions,\n routerMustCustody: boolean,\n performAggregatedSlippageCheck: boolean\n ): string[] {\n const calldatas: string[] = []\n\n invariant(trade.tradeType === TradeType.EXACT_INPUT, 'TRADE_TYPE')\n\n for (const { route, inputAmount, outputAmount } of trade.swaps) {\n if (route.pools.some((pool) => pool instanceof V4Pool))\n throw new Error('Encoding mixed routes with V4 not supported')\n const amountIn: string = toHex(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient)\n const amountOut: string = toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient)\n\n // flag for whether the trade is single hop or not\n const singleHop = route.pools.length === 1\n\n const recipient = routerMustCustody\n ? ADDRESS_THIS\n : typeof options.recipient === 'undefined'\n ? MSG_SENDER\n : validateAndParseAddress(options.recipient)\n\n const mixedRouteIsAllV3 = (route: MixedRouteSDK<Currency, Currency>) => {\n return route.pools.every((pool) => pool instanceof V3Pool)\n }\n\n if (singleHop) {\n /// For single hop, since it isn't really a mixedRoute, we'll just mimic behavior of V3 or V2\n /// We don't use encodeV3Swap() or encodeV2Swap() because casting the trade to a V3Trade or V2Trade is overcomplex\n if (mixedRouteIsAllV3(route)) {\n const exactInputSingleParams = {\n tokenIn: route.path[0].wrapped.address,\n tokenOut: route.path[1].wrapped.address,\n fee: (route.pools as V3Pool[])[0].fee,\n recipient,\n amountIn,\n amountOutMinimum: performAggregatedSlippageCheck ? 0 : amountOut,\n sqrtPriceLimitX96: 0,\n }\n\n calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInputSingle', [exactInputSingleParams]))\n } else {\n const path = route.path.map((token) => token.wrapped.address)\n\n const exactInputParams = [amountIn, performAggregatedSlippageCheck ? 0 : amountOut, path, recipient]\n\n calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams))\n }\n } else {\n const sections = partitionMixedRouteByProtocol(route)\n\n const isLastSectionInRoute = (i: number) => {\n return i === sections.length - 1\n }\n\n let outputToken\n let inputToken = route.input.wrapped\n\n for (let i = 0; i < sections.length; i++) {\n const section = sections[i]\n /// Now, we get output of this section\n outputToken = getOutputOfPools(section, inputToken)\n\n const newRouteOriginal = new MixedRouteSDK(\n [...section],\n section[0].token0.equals(inputToken) ? section[0].token0 : section[0].token1,\n outputToken\n )\n const newRoute = new MixedRoute(newRouteOriginal)\n\n /// Previous output is now input\n inputToken = outputToken.wrapped\n\n if (mixedRouteIsAllV3(newRoute)) {\n const path: string = encodeMixedRouteToPath(newRoute)\n const exactInputParams = {\n path,\n // By default router holds funds until the last swap, then it is sent to the recipient\n // special case exists where we are unwrapping WETH output, in which case `routerMustCustody` is set to true\n // and router still holds the funds. That logic bundled into how the value of `recipient` is calculated\n recipient: isLastSectionInRoute(i) ? recipient : ADDRESS_THIS,\n amountIn: i === 0 ? amountIn : 0,\n amountOutMinimum: !isLastSectionInRoute(i) ? 0 : amountOut,\n }\n\n calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [exactInputParams]))\n } else {\n const exactInputParams = [\n i === 0 ? amountIn : 0, // amountIn\n !isLastSectionInRoute(i) ? 0 : amountOut, // amountOutMin\n newRoute.path.map((token) => token.wrapped.address),\n isLastSectionInRoute(i) ? recipient : ADDRESS_THIS, // to\n ]\n\n calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams))\n }\n }\n }\n }\n\n return calldatas\n }\n\n private static encodeSwaps(\n trades: AnyTradeType,\n options: SwapOptions,\n isSwapAndAdd?: boolean\n ): {\n calldatas: string[]\n sampleTrade:\n | V2Trade<Currency, Currency, TradeType>\n | V3Trade<Currency, Currency, TradeType>\n | MixedRouteTrade<Currency, Currency, TradeType>\n routerMustCustody: boolean\n inputIsNative: boolean\n outputIsNative: boolean\n totalAmountIn: CurrencyAmount<Currency>\n minimumAmountOut: CurrencyAmount<Currency>\n quoteAmountOut: CurrencyAmount<Currency>\n } {\n // If dealing with an instance of the aggregated Trade object, unbundle it to individual trade objects.\n if (trades instanceof Trade) {\n invariant(\n trades.swaps.every(\n (swap) =>\n swap.route.protocol === Protocol.V3 ||\n swap.route.protocol === Protocol.V2 ||\n swap.route.protocol === Protocol.MIXED\n ),\n 'UNSUPPORTED_PROTOCOL (encoding routes with v4 not supported)'\n )\n\n let individualTrades: (\n | V2Trade<Currency, Currency, TradeType>\n | V3Trade<Currency, Currency, TradeType>\n | MixedRouteTrade<Currency, Currency, TradeType>\n )[] = []\n\n for (const { route, inputAmount, outputAmount } of trades.swaps) {\n if (route.protocol === Protocol.V2) {\n individualTrades.push(\n new V2Trade(\n route as RouteV2<Currency, Currency>,\n trades.tradeType === TradeType.EXACT_INPUT ? inputAmount : outputAmount,\n trades.tradeType\n )\n )\n } else if (route.protocol === Protocol.V3) {\n individualTrades.push(\n V3Trade.createUncheckedTrade({\n route: route as RouteV3<Currency, Currency>,\n inputAmount,\n outputAmount,\n tradeType: trades.tradeType,\n })\n )\n } else if (route.protocol === Protocol.MIXED) {\n individualTrades.push(\n /// we can change the naming of this function on MixedRouteTrade if needed\n MixedRouteTrade.createUncheckedTrade({\n route: route as MixedRoute<Currency, Currency>,\n inputAmount,\n outputAmount,\n tradeType: trades.tradeType,\n })\n )\n } else {\n throw new Error('UNSUPPORTED_TRADE_PROTOCOL')\n }\n }\n trades = individualTrades\n }\n\n if (!Array.isArray(trades)) {\n trades = [trades]\n }\n\n const numberOfTrades = trades.reduce(\n (numberOfTrades, trade) =>\n numberOfTrades + (trade instanceof V3Trade || trade instanceof MixedRouteTrade ? trade.swaps.length : 1),\n 0\n )\n\n const sampleTrade = trades[0]\n\n // All trades should have the same starting/ending currency and trade type\n invariant(\n trades.every((trade) => trade.inputAmount.currency.equals(sampleTrade.inputAmount.currency)),\n 'TOKEN_IN_DIFF'\n )\n invariant(\n trades.every((trade) => trade.outputAmount.currency.equals(sampleTrade.outputAmount.currency)),\n 'TOKEN_OUT_DIFF'\n )\n invariant(\n trades.every((trade) => trade.tradeType === sampleTrade.tradeType),\n 'TRADE_TYPE_DIFF'\n )\n\n const calldatas: string[] = []\n\n const inputIsNative = sampleTrade.inputAmount.currency.isNative\n const outputIsNative = sampleTrade.outputAmount.currency.isNative\n\n // flag for whether we want to perform an aggregated slippage check\n // 1. when there are >2 exact input trades. this is only a heuristic,\n // as it's still more gas-expensive even in this case, but has benefits\n // in that the reversion probability is lower\n const performAggregatedSlippageCheck = sampleTrade.tradeType === TradeType.EXACT_INPUT && numberOfTrades > 2\n // flag for whether funds should be send first to the router\n // 1. when receiving ETH (which much be unwrapped from WETH)\n // 2. when a fee on the output is being taken\n // 3. when performing swap and add\n // 4. when performing an aggregated slippage check\n const routerMustCustody = outputIsNative || !!options.fee || !!isSwapAndAdd || performAggregatedSlippageCheck\n\n // encode permit if necessary\n if (options.inputTokenPermit) {\n invariant(sampleTrade.inputAmount.currency.isToken, 'NON_TOKEN_PERMIT')\n calldatas.push(SelfPermit.encodePermit(sampleTrade.inputAmount.currency, options.inputTokenPermit))\n }\n\n for (const trade of trades) {\n if (trade instanceof V2Trade) {\n calldatas.push(SwapRouter.encodeV2Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck))\n } else if (trade instanceof V3Trade) {\n for (const calldata of SwapRouter.encodeV3Swap(\n trade,\n options,\n routerMustCustody,\n performAggregatedSlippageCheck\n )) {\n calldatas.push(calldata)\n }\n } else if (trade instanceof MixedRouteTrade) {\n for (const calldata of SwapRouter.encodeMixedRouteSwap(\n trade,\n options,\n routerMustCustody,\n performAggregatedSlippageCheck\n )) {\n calldatas.push(calldata)\n }\n } else {\n throw new Error('Unsupported trade object')\n }\n }\n\n const ZERO_IN: CurrencyAmount<Currency> = CurrencyAmount.fromRawAmount(sampleTrade.inputAmount.currency, 0)\n const ZERO_OUT: CurrencyAmount<Currency> = CurrencyAmount.fromRawAmount(sampleTrade.outputAmount.currency, 0)\n\n const minimumAmountOut: CurrencyAmount<Currency> = trades.reduce(\n (sum, trade) => sum.add(trade.minimumAmountOut(options.slippageTolerance)),\n ZERO_OUT\n )\n\n const quoteAmountOut: CurrencyAmount<Currency> = trades.reduce(\n (sum, trade) => sum.add(trade.outputAmount),\n ZERO_OUT\n )\n\n const totalAmountIn: CurrencyAmount<Currency> = trades.reduce(\n (sum, trade) => sum.add(trade.maximumAmountIn(options.slippageTolerance)),\n ZERO_IN\n )\n\n return {\n calldatas,\n sampleTrade,\n routerMustCustody,\n inputIsNative,\n outputIsNative,\n totalAmountIn,\n minimumAmountOut,\n quoteAmountOut,\n }\n }\n\n /**\n * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.\n * @param trades to produce call parameters for\n * @param options options for the call parameters\n */\n public static swapCallParameters(\n trades:\n | Trade<Currency, Currency, TradeType>\n | V2Trade<Currency, Currency, TradeType>\n | V3Trade<Currency, Currency, TradeType>\n | MixedRouteTrade<Currency, Currency, TradeType>\n | (\n | V2Trade<Currency, Currency, TradeType>\n | V3Trade<Currency, Currency, TradeType>\n | MixedRouteTrade<Currency, Currency, TradeType>\n )[],\n options: SwapOptions\n ): MethodParameters {\n const {\n calldatas,\n sampleTrade,\n routerMustCustody,\n inputIsNative,\n outputIsNative,\n totalAmountIn,\n minimumAmountOut,\n } = SwapRouter.encodeSwaps(trades, options)\n\n // unwrap or sweep\n if (routerMustCustody) {\n if (outputIsNative) {\n calldatas.push(PaymentsExtended.encodeUnwrapWETH9(minimumAmountOut.quotient, options.recipient, options.fee))\n } else {\n calldatas.push(\n PaymentsExtended.encodeSweepToken(\n sampleTrade.outputAmount.currency.wrapped,\n minimumAmountOut.quotient,\n options.recipient,\n options.fee\n )\n )\n }\n }\n\n // must refund when paying in ETH: either with an uncertain input amount OR if there's a chance of a partial fill.\n // unlike ERC20's, the full ETH value must be sent in the transaction, so the rest must be refunded.\n if (inputIsNative && (sampleTrade.tradeType === TradeType.EXACT_OUTPUT || SwapRouter.riskOfPartialFill(trades))) {\n calldatas.push(Payments.encodeRefundETH())\n }\n\n return {\n calldata: MulticallExtended.encodeMulticall(calldatas, options.deadlineOrPreviousBlockhash),\n value: toHex(inputIsNative ? totalAmountIn.quotient : ZERO),\n }\n }\n\n /**\n * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.\n * @param trades to produce call parameters for\n * @param options options for the call parameters\n */\n public static swapAndAddCallParameters(\n trades: AnyTradeType,\n options: SwapAndAddOptions,\n position: Position,\n addLiquidityOptions: CondensedAddLiquidityOptions,\n tokenInApprovalType: ApprovalTypes,\n tokenOutApprovalType: ApprovalTypes\n ): MethodParameters {\n const {\n calldatas,\n inputIsNative,\n outputIsNative,\n sampleTrade,\n totalAmountIn: totalAmountSwapped,\n quoteAmountOut,\n minimumAmountOut,\n } = SwapRouter.encodeSwaps(trades, options, true)\n\n // encode output token permit if necessary\n if (options.outputTokenPermit) {\n invariant(quoteAmountOut.currency.isToken, 'NON_TOKEN_PERMIT_OUTPUT')\n calldatas.push(SelfPermit.encodePermit(quoteAmountOut.currency, options.outputTokenPermit))\n }\n\n const chainId = sampleTrade.route.chainId\n const zeroForOne = position.pool.token0.wrapped.address === totalAmountSwapped.currency.wrapped.address\n const { positionAmountIn, positionAmountOut } = SwapRouter.getPositionAmounts(position, zeroForOne)\n\n // if tokens are native they will be converted to WETH9\n const tokenIn = inputIsNative ? WETH9[chainId] : positionAmountIn.currency.wrapped\n const tokenOut = outputIsNative ? WETH9[chainId] : positionAmountOut.currency.wrapped\n\n // if swap output does not make up whole outputTokenBalanceDesired, pull in remaining tokens for adding liquidity\n const amountOutRemaining = positionAmountOut.subtract(quoteAmountOut.wrapped)\n if (amountOutRemaining.greaterThan(CurrencyAmount.fromRawAmount(positionAmountOut.currency, 0))) {\n // if output is native, this means the remaining portion is included as native value in the transaction\n // and must be wrapped. Otherwise, pull in remaining ERC20 token.\n outputIsNative\n ? calldatas.push(PaymentsExtended.encodeWrapETH(amountOutRemaining.quotient))\n : calldatas.push(PaymentsExtended.encodePull(tokenOut, amountOutRemaining.quotient))\n }\n\n // if input is native, convert to WETH9, else pull ERC20 token\n inputIsNative\n ? calldatas.push(PaymentsExtended.encodeWrapETH(positionAmountIn.quotient))\n : calldatas.push(PaymentsExtended.encodePull(tokenIn, positionAmountIn.quotient))\n\n // approve token balances to NFTManager\n if (tokenInApprovalType !== ApprovalTypes.NOT_REQUIRED)\n calldatas.push(ApproveAndCall.encodeApprove(tokenIn, tokenInApprovalType))\n if (tokenOutApprovalType !== ApprovalTypes.NOT_REQUIRED)\n calldatas.push(ApproveAndCall.encodeApprove(tokenOut, tokenOutApprovalType))\n\n // represents a position with token amounts resulting from a swap with maximum slippage\n // hence the minimal amount out possible.\n const minimalPosition = Position.fromAmounts({\n pool: position.pool,\n tickLower: position.tickLower,\n tickUpper: position.tickUpper,\n amount0: zeroForOne ? position.amount0.quotient.toString() : minimumAmountOut.quotient.toString(),\n amount1: zeroForOne ? minimumAmountOut.quotient.toString() : position.amount1.quotient.toString(),\n useFullPrecision: false,\n })\n\n // encode NFTManager add liquidity\n calldatas.push(\n ApproveAndCall.encodeAddLiquidity(position, minimalPosition, addLiquidityOptions, options.slippageTolerance)\n )\n\n // sweep remaining tokens\n inputIsNative\n ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO))\n : calldatas.push(PaymentsExtended.encodeSweepToken(tokenIn, ZERO))\n outputIsNative\n ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO))\n : calldatas.push(PaymentsExtended.encodeSweepToken(tokenOut, ZERO))\n\n let value: JSBI\n if (inputIsNative) {\n value = totalAmountSwapped.wrapped.add(positionAmountIn.wrapped).quotient\n } else if (outputIsNative) {\n value = amountOutRemaining.quotient\n } else {\n value = ZERO\n }\n\n return {\n calldata: MulticallExtended.encodeMulticall(calldatas, options.deadlineOrPreviousBlockhash),\n value: value.toString(),\n }\n }\n\n // if price impact is very high, there's a chance of hitting max/min prices resulting in a partial fill of the swap\n private static riskOfPartialFill(trades: AnyTradeType): boolean {\n if (Array.isArray(trades)) {\n return trades.some((trade) => {\n return SwapRouter.v3TradeWithHighPriceImpact(trade)\n })\n } else {\n return SwapRouter.v3TradeWithHighPriceImpact(trades)\n }\n }\n\n private static v3TradeWithHighPriceImpact(\n trade:\n | Trade<Currency, Currency, TradeType>\n | V2Trade<Currency, Currency, TradeType>\n | V3Trade<Currency, Currency, TradeType>\n | MixedRouteTrade<Currency, Currency, TradeType>\n ): boolean {\n return !(trade instanceof V2Trade) && trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD)\n }\n\n private static getPositionAmounts(\n position: Position,\n zeroForOne: boolean\n ): {\n positionAmountIn: CurrencyAmount<Currency>\n positionAmountOut: CurrencyAmount<Currency>\n } {\n const { amount0, amount1 } = position.mintAmounts\n const currencyAmount0 = CurrencyAmount.fromRawAmount(position.pool.token0, amount0)\n const currencyAmount1 = CurrencyAmount.fromRawAmount(position.pool.token1, amount1)\n\n const [positionAmountIn, positionAmountOut] = zeroForOne\n ? [currencyAmount0, currencyAmount1]\n : [currencyAmount1, currencyAmount0]\n return { positionAmountIn, positionAmountOut }\n }\n}\n"],"names":["ApprovalTypes","ADDRESS_ZERO","MSG_SENDER","ADDRESS_THIS","ZERO","JSBI","BigInt","ONE","ZERO_PERCENT","Percent","ONE_HUNDRED_PERCENT","isMint","options","Object","keys","some","k","ApproveAndCall","encodeApproveMax","token","INTERFACE","encodeFunctionData","address","encodeApproveMaxMinusOne","encodeApproveZeroThenMax","encodeApproveZeroThenMaxMinusOne","encodeCallPositionManager","calldatas","length","invariant","encodedMulticall","NonfungiblePositionManager","encodeAddLiquidity","position","minimalPosition","addLiquidityOptions","slippageTolerance","_position$mintAmounts","mintAmountsWithSlippage","amount0Min","amount0","amount1Min","amount1","lessThan","quotient","token0","pool","token1","fee","tickLower","tickUpper","toHex","recipient","tokenId","encodeApprove","approvalType","MAX","wrapped","MAX_MINUS_ONE","ZERO_THEN_MAX","ZERO_THEN_MAX_MINUS_ONE","Error","Interface","IApproveAndCall","abi","MulticallExtended","encodeMulticall","validation","Multicall","Array","isArray","startsWith","previousBlockhash","bytes32","match","toLowerCase","validateAndParseBytes32","deadline","encodeFeeBips","multiply","IMulticallExtended","PaymentsExtended","encodeUnwrapWETH9","amountMinimum","feeOptions","Payments","feeBips","feeRecipient","validateAndParseAddress","encodeSweepToken","encodePull","amount","encodeWrapETH","amountWithPathCurrency","CurrencyAmount","fromFractionalAmount","getPathCurrency","currency","numerator","denominator","involvesToken","V4Pool","symbol","equals","IPeripheryPaymentsWithFeeExtended","MixedRouteSDK","_createClass","pools","input","output","retainFakePools","this","filter","tickSpacing","chainId","every","pathInput","pathOutput","v4InvolvesToken","lastPool","tokenPath","push","i","inputToken","outputToken","isNative","JSON","stringify","path","key","get","_midPrice","price","slice","reduce","_ref","nextInput","token0Price","asFraction","token1Price","Price","tradeComparator","a","b","inputAmount","outputAmount","equalTo","swaps","total","cur","route","Protocol","MixedRouteTrade","routes","tradeType","inputCurrency","outputCurrency","_ref2","_ref3","_step","numPools","map","_ref4","poolIdentifierSet","Set","_iterator","_createForOfIteratorHelperLoose","done","_step2","_iterator2","value","add","poolId","V3Pool","getAddress","Pair","size","TradeType","EXACT_INPUT","fromRoute","_fromRoute","_asyncToGenerator","_regenerator","m","_callee","amounts","w","_context","n","getOutputAmount","v","_x","_x2","_x3","apply","arguments","fromRoutes","_fromRoutes","_callee2","populatedRoutes","_iterator3","_step3","_step3$value","_context2","_x4","_x5","createUncheckedTrade","constructorArguments","_extends","createUncheckedTradeWithMultipleRoutes","_proto","prototype","minimumAmountOut","amountOut","slippageAdjustedAmountOut","Fraction","invert","fromRawAmount","maximumAmountIn","amountIn","worstExecutionPrice","bestTradeExactIn","_bestTradeExactIn","_callee3","currencyAmountIn","currencyOut","_temp","currentPools","nextAmountIn","bestTrades","maxNumResults","_ref5$maxNumResults","maxHops","_ref5$maxHops","_ref5","_context3","amountInAdjusted","reserve0","reserve1","p","_t","_t2","isInsufficientInputAmountError","_t3","sortedInsert","_t4","concat","poolsExcludingThisPool","_x6","_x7","_x8","_x9","_x0","_x1","_x10","_inputAmount","totalInputFromRoutes","_ref7","_outputAmount","totalOutputFromRoutes","_ref8","_this$_executionPrice","_executionPrice","_priceImpact","_step4","spotOutputAmount","_iterator4","_step4$value","midPrice","quote","priceImpact","subtract","divide","getPathToken","RouteV2","_V2RouteSDK","v2Route","_this","call","pairs","V2","_inheritsLoose","V2RouteSDK","RouteV3","_V3RouteSDK","v3Route","_this2","V3","V3RouteSDK","RouteV4","_V4RouteSDK","v4Route","_this3","V4","currencyPath","V4RouteSDK","MixedRoute","_MixedRouteSDK","mixedRoute","_this4","MIXED","Trade","v2Routes","_ref$v2Routes","_ref$v3Routes","v3Routes","_ref$v4Routes","v4Routes","_ref$mixedRoutes","mixedRoutes","_step$value","routev2","_step2$value","routev3","routev4","_step5","_iterator5","_step6","_iterator6","isWrappedNative","Ether","onChain","EXACT_OUTPUT","slippageAdjustedAmountIn","populatedV2Routes","populatedV3Routes","populatedV4Routes","populatedMixedRoutes","_iterator7","_step7","_step7$value","v2Trade","_iterator8","_step8","_step8$value","_amount3","v3Trade","_iterator9","_step9","_step9$value","v4Trade","_iterator0","_step0","_step0$value","_amount","mixedRouteTrade","V2TradeSDK","V3TradeSDK","V4TradeSDK","MixedRouteTradeSDK","inputAmountCurrency","_ref6","inputNativeCurrency","_this$swaps$find","find","outputNativeCurrency","_this$swaps$find2","inputAmountNative","swap","undefined","outputAmountNative","wethInputRoutes","nativeInputRoutes","_nativeInputRoutes","_wethInputRoutes","sellFeeBps","toNumber","buyFeeBps","outputTax","_step1","_iterator1","_step1$value","postTaxInputAmount","inputTax","preTaxOutputAmount","encodeMixedRouteToPath","useMixedRouterQuoteV2","types","currencyIn","hooks","result","index","pack","partitionMixedRouteByProtocol","acc","left","right","getOutputOfPools","firstInputToken","REFUND_ETH_PRICE_IMPACT_THRESHOLD","SwapRouter","encodeV2Swap","trade","routerMustCustody","performAggregatedSlippageCheck","encodeV3Swap","singleHop","tokenIn","tokenOut","amountOutMinimum","sqrtPriceLimitX96","amountInMaximum","encodeRouteToPath","encodeMixedRouteSwap","_loop","mixedRouteIsAllV3","sections","isLastSectionInRoute","section","newRouteOriginal","newRoute","exactInputParams","encodeSwaps","trades","isSwapAndAdd","protocol","individualTrades","V2Trade","V3Trade","numberOfTrades","sampleTrade","inputIsNative","outputIsNative","inputTokenPermit","isToken","SelfPermit","encodePermit","ZERO_IN","ZERO_OUT","sum","quoteAmountOut","totalAmountIn","swapCallParameters","_SwapRouter$encodeSwa","riskOfPartialFill","encodeRefundETH","calldata","deadlineOrPreviousBlockhash","swapAndAddCallParameters","tokenInApprovalType","tokenOutApprovalType","_SwapRouter$encodeSwa2","totalAmountSwapped","outputTokenPermit","zeroForOne","_SwapRouter$getPositi","getPositionAmounts","positionAmountIn","positionAmountOut","WETH9","amountOutRemaining","greaterThan","NOT_REQUIRED","Position","fromAmounts","toString","useFullPrecision","v3TradeWithHighPriceImpact","mintAmounts","currencyAmount0","currencyAmount1","ISwapRouter02"],"mappings":"8IAgBYA,uwBCbCC,EAAe,6CACfC,EAAa,6CACbC,EAAe,6CAEfC,EAAOC,EAAKC,OAAO,GACnBC,EAAMF,EAAKC,OAAO,GAclBE,EAAe,IAAIC,UAAQL,GAC3BM,EAAsB,IAAID,UAAQ,IAAK,cDEpCE,EAAOC,GACrB,OAAOC,OAAOC,KAAKF,GAASG,MAAK,SAACC,GAAC,MAAW,cAANA,MAV9BhB,EAAAA,wBAAAA,4DAEVA,iBACAA,qCACAA,qCACAA,yDAQF,IAAsBiB,aAMpB,SAAAA,KA4FC,OA5FuBA,EAEVC,iBAAP,SAAwBC,GAC7B,OAAOF,EAAeG,UAAUC,mBAAmB,aAAc,CAACF,EAAMG,WACzEL,EAEaM,yBAAP,SAAgCJ,GACrC,OAAOF,EAAeG,UAAUC,mBAAmB,qBAAsB,CAACF,EAAMG,WACjFL,EAEaO,yBAAP,SAAgCL,GACrC,OAAOF,EAAeG,UAAUC,mBAAmB,qBAAsB,CAACF,EAAMG,WACjFL,EAEaQ,iCAAP,SAAwCN,GAC7C,OAAOF,EAAeG,UAAUC,mBAAmB,6BAA8B,CAACF,EAAMG,WACzFL,EAEaS,0BAAP,SAAiCC,GAGtC,GAFUA,EAAUC,OAAS,GAA7BC,MAEyB,IAArBF,EAAUC,OACZ,OAAOX,EAAeG,UAAUC,mBAAmB,sBAAuBM,GAE1E,IAAMG,EAAmBC,6BAA2BX,UAAUC,mBAAmB,YAAa,CAACM,IAC/F,OAAOV,EAAeG,UAAUC,mBAAmB,sBAAuB,CAACS,KAG/Eb,EAOce,mBAAP,SACLC,EACAC,EACAC,EACAC,GAEA,IAAAC,EAAmDJ,EAASK,wBAAwBF,GAArEG,EAAUF,EAAnBG,QAA8BC,EAAUJ,EAAnBK,QAY3B,OAPIrC,EAAKsC,SAAST,EAAgBM,QAAQI,SAAUL,K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