diff --git a/package.json b/package.json index 721d7dfe9f..a77197e972 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "@polkadot/types-support": "^12.0.2", "@polkadot/util": "^12.6.2", "@polkadot/util-crypto": "^12.6.2", + "@uniswap/v3-periphery": "1.4.4", "@subwallet/chain-list": "0.2.89-beta.5", "@subwallet/keyring": "^0.1.6", "@subwallet/react-ui": "5.1.2-b79", diff --git a/packages/extension-base/src/services/swap-service/handler/uniswap-handler.ts b/packages/extension-base/src/services/swap-service/handler/uniswap-handler.ts index 76095b11f1..814c0f3613 100644 --- a/packages/extension-base/src/services/swap-service/handler/uniswap-handler.ts +++ b/packages/extension-base/src/services/swap-service/handler/uniswap-handler.ts @@ -19,7 +19,6 @@ import { calculateSwapRate, handleUniswapQuote, SWAP_QUOTE_TIMEOUT_MAP } from '@ import { BaseStepDetail, CommonOptimalPath, CommonStepFeeInfo, CommonStepType, DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/types/service-base'; import { OptimalSwapPathParams, SwapEarlyValidation, SwapFeeType, SwapProviderId, SwapQuote, SwapRequest, SwapStepType, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types/swap'; import { getEthereumSmartAccountOwner } from '@subwallet/extension-base/utils'; -import { SWAP_ROUTER_02_ADDRESSES } from '@uniswap/sdk-core'; import { batchTx, encodeApproveTx, QuoteResponse, rawTx } from 'klaster-sdk'; import { TransactionConfig } from 'web3-core'; @@ -89,7 +88,7 @@ export class UniswapHandler implements SwapBaseInterface { const toToken = this.swapBaseHandler.chainService.getAssetBySlug(to); const fromChain = this.swapBaseHandler.chainService.getChainInfoByKey(fromToken.originChain); - const [availQuote] = await handleUniswapQuote(request, this.swapBaseHandler.chainService.getEvmApi(fromChain.slug), this.swapBaseHandler.chainService); + const { quote: availQuote } = await handleUniswapQuote(request, this.swapBaseHandler.chainService.getEvmApi(fromChain.slug), this.swapBaseHandler.chainService); const result: SwapQuote = { pair: request.pair, fromAmount: request.fromAmount, @@ -146,15 +145,10 @@ export class UniswapHandler implements SwapBaseInterface { } } - const bridgeOriginToken = this.swapBaseHandler.chainService.getAssetBySlug(bridgeTokenSlug); - - const bridgeOriginChain = this.swapBaseHandler.chainService.getChainInfoByKey(bridgeOriginToken.originChain); - const bridgeDestChain = this.swapBaseHandler.chainService.getChainInfoByKey(toToken.originChain); - - const toAddress = SWAP_ROUTER_02_ADDRESSES(chainId); + // const toAddress = SWAP_ROUTER_02_ADDRESSES(chainId); const evmApi = this.swapBaseHandler.chainService.getEvmApi(fromToken.originChain); - const [, calldata] = await handleUniswapQuote(request, evmApi, this.swapBaseHandler.chainService); + const { callData, routerAddress: toAddress } = await handleUniswapQuote(request, evmApi, this.swapBaseHandler.chainService); const owner = getEthereumSmartAccountOwner(request.address); let tx: UserOpBundle | QuoteResponse; @@ -168,7 +162,7 @@ export class UniswapHandler implements SwapBaseInterface { const swapTx = rawTx({ to: toAddress as `0x${string}`, - data: calldata as `0x${string}`, + data: callData as `0x${string}`, gasLimit: BigInt(250_000) }); const txBatch = batchTx(chainId, [approveSwapTx, swapTx]); @@ -178,8 +172,12 @@ export class UniswapHandler implements SwapBaseInterface { await klasterService.init(owner?.owner as string); if (bridgeTokenSlug === '0x') { - tx = await klasterService.buildTx(bridgeOriginChain, [txBatch]); + tx = await klasterService.buildTx(fromChain, [txBatch]); } else { + const bridgeOriginToken = this.swapBaseHandler.chainService.getAssetBySlug(bridgeTokenSlug); + const bridgeOriginChain = this.swapBaseHandler.chainService.getChainInfoByKey(bridgeOriginToken.originChain); + const bridgeDestChain = this.swapBaseHandler.chainService.getChainInfoByKey(toToken.originChain); + tx = await klasterService.getBridgeTx(bridgeOriginToken, toToken, bridgeOriginChain, bridgeDestChain, params.quote.toAmount, txBatch); } } else { @@ -187,26 +185,35 @@ export class UniswapHandler implements SwapBaseInterface { const swapTxConfig: TransactionConfig = { ...swapApprovalTxConfig, - data: calldata as `0x${string}`, + gas: 250_000, + data: callData as `0x${string}`, to: toAddress as `0x${string}` }; if (bridgeTokenSlug === '0x') { - tx = await ParticleAAHandler.createUserOperation(_getEvmChainId(bridgeOriginChain) as number, owner as SmartAccountData, [swapApprovalTxConfig, swapTxConfig]); + tx = await ParticleAAHandler.createUserOperation(_getEvmChainId(fromChain) as number, owner as SmartAccountData, [swapApprovalTxConfig, swapTxConfig]); } else { + const bridgeOriginToken = this.swapBaseHandler.chainService.getAssetBySlug(bridgeTokenSlug); + const bridgeOriginChain = this.swapBaseHandler.chainService.getChainInfoByKey(bridgeOriginToken.originChain); + const bridgeDestChain = this.swapBaseHandler.chainService.getChainInfoByKey(toToken.originChain); const [feeResp, bridgeTxConfig] = await getAcrossBridgeData({ - amount: BigInt(params.quote.fromAmount), + amount: BigInt(params.quote.toAmount), + srcAccount: request.address, + sourceChainId: _getEvmChainId(bridgeOriginChain) as number, + sourceTokenContract: _getContractAddressOfToken(bridgeOriginToken), destAccount: request.address, destinationChainId: _getEvmChainId(bridgeDestChain) as number, destinationTokenContract: _getContractAddressOfToken(toToken), - sourceChainId: _getEvmChainId(bridgeOriginChain) as number, - sourceTokenContract: _getContractAddressOfToken(bridgeOriginToken), - srcAccount: owner?.owner as string, isTestnet: this.isTestnet }); const bridgeApprovalTxConfig = await getERC20SpendingApprovalTx(feeResp.spokePoolAddress, params.address, _getContractAddressOfToken(bridgeOriginToken), evmApi); - tx = await ParticleAAHandler.createUserOperation(_getEvmChainId(bridgeOriginChain) as number, owner as SmartAccountData, [swapApprovalTxConfig, swapTxConfig, bridgeApprovalTxConfig, bridgeTxConfig]); + tx = await ParticleAAHandler.createUserOperation(_getEvmChainId(fromChain) as number, owner as SmartAccountData, [ + swapApprovalTxConfig, + swapTxConfig, + bridgeApprovalTxConfig, + bridgeTxConfig + ]); } } diff --git a/packages/extension-base/src/services/swap-service/utils.ts b/packages/extension-base/src/services/swap-service/utils.ts index 96b65b8879..5236090caf 100644 --- a/packages/extension-base/src/services/swap-service/utils.ts +++ b/packages/extension-base/src/services/swap-service/utils.ts @@ -3,16 +3,16 @@ import { Asset, Assets, Chain, Chains } from '@chainflip/sdk/swap'; import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list'; -import { _ChainAsset } from '@subwallet/chain-list/types'; +import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types'; import { ChainService } from '@subwallet/extension-base/services/chain-service'; import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types'; import { _getAssetDecimals, _getAssetName, _getAssetSymbol, _getContractAddressOfToken, _getEvmChainId } from '@subwallet/extension-base/services/chain-service/utils'; import { CHAINFLIP_BROKER_API } from '@subwallet/extension-base/services/swap-service/handler/chainflip-handler'; import { SwapPair, SwapProviderId, SwapRequest } from '@subwallet/extension-base/types/swap'; -import { CurrencyAmount, Percent, QUOTER_ADDRESSES, Token, TradeType, V3_CORE_FACTORY_ADDRESSES } from '@uniswap/sdk-core'; +import { CurrencyAmount, Percent, QUOTER_ADDRESSES, SWAP_ROUTER_02_ADDRESSES, Token, TradeType, V3_CORE_FACTORY_ADDRESSES } from '@uniswap/sdk-core'; // @ts-ignore import IUniswapV3PoolABI from '@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json'; -import { computePoolAddress, FeeAmount, Pool, Route, SwapQuoter, SwapRouter, Trade } from '@uniswap/v3-sdk'; +import { computePoolAddress, FeeAmount, Pool as PoolV3, Route as RouteV3, SwapQuoter, SwapRouter as SwapRouterV3, Trade as TradeV3 } from '@uniswap/v3-sdk'; import BigN from 'bignumber.js'; import { ethers } from 'ethers'; @@ -56,7 +56,7 @@ export const _PROVIDER_TO_SUPPORTED_PAIR_MAP: Record = { [SwapProviderId.KUSAMA_ASSET_HUB]: [COMMON_CHAIN_SLUGS.KUSAMA_ASSET_HUB], [SwapProviderId.ROCOCO_ASSET_HUB]: [COMMON_CHAIN_SLUGS.ROCOCO_ASSET_HUB], [SwapProviderId.UNISWAP_SEPOLIA]: [COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA, 'base_sepolia'], - [SwapProviderId.UNISWAP_ETHEREUM]: [COMMON_CHAIN_SLUGS.ARBITRUM, 'base_mainnet'] + [SwapProviderId.UNISWAP_ETHEREUM]: [COMMON_CHAIN_SLUGS.ETHEREUM, COMMON_CHAIN_SLUGS.ARBITRUM, 'base_mainnet'] }; export function getSwapAlternativeAsset (swapPair: SwapPair): string | undefined { @@ -122,33 +122,28 @@ export interface UniSwapPoolInfo { tick: number } -export async function handleUniswapQuote (request: SwapRequest, web3Api: _EvmApi, chainService: ChainService): Promise<[string, string]> { - const { from, to: _to } = request.pair; - let to = _to; - - if (to === 'base_sepolia-ERC20-WETH-0x4200000000000000000000000000000000000006') { - to = 'sepolia_ethereum-ERC20-WETH-0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14'; - } else if (to === 'arbitrum_one-ERC20-USDC-0xaf88d065e77c8cC2239327C5EDb3A432268e5831') { - to = 'base_mainnet-ERC20-USDC-0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; - } else if (to === 'base_mainnet-ERC20-USDC-0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913') { - to = 'arbitrum_one-ERC20-USDC-0xaf88d065e77c8cC2239327C5EDb3A432268e5831'; - } else if (to === 'optimism-ERC20-DAI-0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1') { - if (from === 'base_mainnet-ERC20-USDC-0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913') { - to = 'base_mainnet-ERC20-DAI-0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb'; - } else { - to = 'arbitrum_one-ERC20-DAI-0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1'; - } - } +interface HandlerUniswapFunctionProps { + fromToken: _ChainAsset; + toToken: _ChainAsset; + fromChain: _ChainInfo; + recipient: string; + fromAmount: string; + web3Api: _EvmApi; +} - const fromToken = chainService.getAssetBySlug(from); - const toToken = chainService.getAssetBySlug(to); +interface HandlerUniswapFunctionResult { + quote: string; + callData: string; + routerAddress: string; +} - const fromChain = chainService.getChainInfoByKey(fromToken.originChain); - const chainId: number = _getEvmChainId(fromChain) || 0; - const useV2 = ['base_sepolia', 'base_mainnet', COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA].includes(fromChain.slug); +const handleUniswapV3 = async ({ fromAmount, fromChain, fromToken, recipient, toToken, web3Api }: HandlerUniswapFunctionProps): Promise => { const fromContract = _getContractAddressOfToken(fromToken); const toContract = _getContractAddressOfToken(toToken); + const chainId: number = _getEvmChainId(fromChain) || 0; + const useV2 = ['base_sepolia', 'base_mainnet', COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA].includes(fromChain.slug); + const swaptoDAI = _getAssetSymbol(toToken) === 'DAI'; const fromTokenStruct = new Token( chainId, @@ -167,7 +162,7 @@ export async function handleUniswapQuote (request: SwapRequest, web3Api: _EvmApi ); const currentPoolAddress = computePoolAddress({ - fee: to.includes('DAI') ? FeeAmount.LOW : FeeAmount.HIGH, + fee: swaptoDAI ? FeeAmount.LOW : FeeAmount.HIGH, tokenA: fromTokenStruct, tokenB: toTokenStruct, factoryAddress: V3_CORE_FACTORY_ADDRESSES[chainId] @@ -189,24 +184,6 @@ export async function handleUniswapQuote (request: SwapRequest, web3Api: _EvmApi ]); const provider = new ethers.JsonRpcProvider(web3Api.apiUrl); - // const quoterContract1 = new ethers.Contract( - // QUOTER_ADDRESSES[chainId as number], - // Quoter.abi, - // provider - // ); - // try { - // const quotedAmountOut = await quoterContract1.quoteExactInputSingle.staticCall([ - // fromContract, - // toContract, - // fee, - // request.fromAmount, - // toContract - // ]); - // - // console.log(quotedAmountOut); - // } catch (e) { - // console.log(e); - // } const poolInfo: UniSwapPoolInfo = { token0: fromContract, @@ -220,7 +197,7 @@ export async function handleUniswapQuote (request: SwapRequest, web3Api: _EvmApi tick: parseInt(slot0[1]) }; - const pool = new Pool( + const pool = new PoolV3( fromTokenStruct, toTokenStruct, poolInfo.fee, @@ -229,7 +206,7 @@ export async function handleUniswapQuote (request: SwapRequest, web3Api: _EvmApi poolInfo.tick ); - const swapRoute = new Route( + const swapRoute = new RouteV3( [pool], fromTokenStruct, toTokenStruct @@ -239,7 +216,7 @@ export async function handleUniswapQuote (request: SwapRequest, web3Api: _EvmApi swapRoute, CurrencyAmount.fromRawAmount( fromTokenStruct, - request.fromAmount + fromAmount ), TradeType.EXACT_INPUT, { @@ -254,11 +231,11 @@ export async function handleUniswapQuote (request: SwapRequest, web3Api: _EvmApi const availQuote = web3Api.api.eth.abi.decodeParameter('uint256', quoteCallReturnData); - const uncheckedTrade = Trade.createUncheckedTrade({ + const uncheckedTrade = TradeV3.createUncheckedTrade({ route: swapRoute, inputAmount: CurrencyAmount.fromRawAmount( fromTokenStruct, - request.fromAmount + fromAmount ), outputAmount: CurrencyAmount.fromRawAmount( toTokenStruct, @@ -267,14 +244,49 @@ export async function handleUniswapQuote (request: SwapRequest, web3Api: _EvmApi tradeType: TradeType.EXACT_INPUT }); - const methodParameters = SwapRouter.swapCallParameters([uncheckedTrade], { + const methodParameters = SwapRouterV3.swapCallParameters([uncheckedTrade], { slippageTolerance: new Percent(500, 10_000), deadline: Math.floor(Date.now() / 1000) + 60 * 20, - recipient: request.address + recipient }); + const routerAddress = SWAP_ROUTER_02_ADDRESSES(chainId) + + return { + quote: availQuote.toString(), + callData: methodParameters.calldata, + routerAddress + }; +}; + +export async function handleUniswapQuote (request: SwapRequest, web3Api: _EvmApi, chainService: ChainService): Promise { + const { from, to: _to } = request.pair; + let to = _to; + + if (to === 'base_sepolia-ERC20-WETH-0x4200000000000000000000000000000000000006') { + to = 'sepolia_ethereum-ERC20-WETH-0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14'; + } else if (to === 'arbitrum_one-ERC20-USDC-0xaf88d065e77c8cC2239327C5EDb3A432268e5831') { + to = 'base_mainnet-ERC20-USDC-0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; + } else if (to === 'base_mainnet-ERC20-USDC-0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913') { + to = 'arbitrum_one-ERC20-USDC-0xaf88d065e77c8cC2239327C5EDb3A432268e5831'; + } else if (to === 'optimism-ERC20-DAI-0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1') { + if (from === 'base_mainnet-ERC20-USDC-0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913') { + to = 'base_mainnet-ERC20-DAI-0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb'; + } else { + to = 'arbitrum_one-ERC20-DAI-0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1'; + } + } - return [ - availQuote.toString(), - methodParameters.calldata - ]; + const fromToken = chainService.getAssetBySlug(from); + const toToken = chainService.getAssetBySlug(to); + + const fromChain = chainService.getChainInfoByKey(fromToken.originChain); + + return await handleUniswapV3({ + fromAmount: request.fromAmount, + fromChain, + fromToken, + recipient: request.address, + toToken, + web3Api + }); } diff --git a/patches/@uniswap+v3-periphery+1.4.4.patch b/patches/@uniswap+v3-periphery+1.4.4.patch new file mode 100644 index 0000000000..98388b8148 --- /dev/null +++ b/patches/@uniswap+v3-periphery+1.4.4.patch @@ -0,0 +1,52 @@ +diff --git a/node_modules/@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json b/node_modules/@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json +index d7c2857..5a42685 100644 +--- a/node_modules/@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json ++++ b/node_modules/@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json +@@ -46,11 +46,6 @@ + "name": "recipient", + "type": "address" + }, +- { +- "internalType": "uint256", +- "name": "deadline", +- "type": "uint256" +- }, + { + "internalType": "uint256", + "name": "amountIn", +@@ -102,11 +97,6 @@ + "name": "recipient", + "type": "address" + }, +- { +- "internalType": "uint256", +- "name": "deadline", +- "type": "uint256" +- }, + { + "internalType": "uint256", + "name": "amountIn", +@@ -153,11 +143,6 @@ + "name": "recipient", + "type": "address" + }, +- { +- "internalType": "uint256", +- "name": "deadline", +- "type": "uint256" +- }, + { + "internalType": "uint256", + "name": "amountOut", +@@ -209,11 +194,6 @@ + "name": "recipient", + "type": "address" + }, +- { +- "internalType": "uint256", +- "name": "deadline", +- "type": "uint256" +- }, + { + "internalType": "uint256", + "name": "amountOut", diff --git a/patches/@uniswap+v3-sdk+3.13.1.patch b/patches/@uniswap+v3-sdk+3.13.1.patch new file mode 100644 index 0000000000..acdcc05513 --- /dev/null +++ b/patches/@uniswap+v3-sdk+3.13.1.patch @@ -0,0 +1,96 @@ +diff --git a/node_modules/@uniswap/v3-sdk/dist/v3-sdk.cjs.development.js b/node_modules/@uniswap/v3-sdk/dist/v3-sdk.cjs.development.js +index 9ee46f5..68fa5d0 100644 +--- a/node_modules/@uniswap/v3-sdk/dist/v3-sdk.cjs.development.js ++++ b/node_modules/@uniswap/v3-sdk/dist/v3-sdk.cjs.development.js +@@ -3097,7 +3097,6 @@ var SwapRouter = /*#__PURE__*/function () { + calldatas.push(SelfPermit.encodePermit(sampleTrade.inputAmount.currency, options.inputTokenPermit)); + } + var recipient = sdkCore.validateAndParseAddress(options.recipient); +- var deadline = toHex(options.deadline); + for (var _iterator = _createForOfIteratorHelperLoose(trades), _step; !(_step = _iterator()).done;) { + var trade = _step.value; + for (var _iterator2 = _createForOfIteratorHelperLoose(trade.swaps), _step2; !(_step2 = _iterator2()).done;) { +@@ -3117,7 +3116,6 @@ var SwapRouter = /*#__PURE__*/function () { + tokenOut: route.tokenPath[1].address, + fee: route.pools[0].fee, + recipient: routerMustCustody ? ADDRESS_ZERO : recipient, +- deadline: deadline, + amountIn: amountIn, + amountOutMinimum: amountOut, + sqrtPriceLimitX96: toHex((_options$sqrtPriceLim = options.sqrtPriceLimitX96) != null ? _options$sqrtPriceLim : 0) +@@ -3130,7 +3128,6 @@ var SwapRouter = /*#__PURE__*/function () { + tokenOut: route.tokenPath[1].address, + fee: route.pools[0].fee, + recipient: routerMustCustody ? ADDRESS_ZERO : recipient, +- deadline: deadline, + amountOut: amountOut, + amountInMaximum: amountIn, + sqrtPriceLimitX96: toHex((_options$sqrtPriceLim2 = options.sqrtPriceLimitX96) != null ? _options$sqrtPriceLim2 : 0) +@@ -3144,7 +3141,6 @@ var SwapRouter = /*#__PURE__*/function () { + var exactInputParams = { + path: path, + recipient: routerMustCustody ? ADDRESS_ZERO : recipient, +- deadline: deadline, + amountIn: amountIn, + amountOutMinimum: amountOut + }; +@@ -3153,7 +3149,6 @@ var SwapRouter = /*#__PURE__*/function () { + var exactOutputParams = { + path: path, + recipient: routerMustCustody ? ADDRESS_ZERO : recipient, +- deadline: deadline, + amountOut: amountOut, + amountInMaximum: amountIn + }; +diff --git a/node_modules/@uniswap/v3-sdk/dist/v3-sdk.cjs.production.min.js b/node_modules/@uniswap/v3-sdk/dist/v3-sdk.cjs.production.min.js +index 9029f1d..625ec37 100644 +--- a/node_modules/@uniswap/v3-sdk/dist/v3-sdk.cjs.production.min.js ++++ b/node_modules/@uniswap/v3-sdk/dist/v3-sdk.cjs.production.min.js +@@ -1,2 +1,2 @@ +-"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("@uniswap/sdk-core"),r=t(require("jsbi")),i=t(require("tiny-invariant")),o=require("@ethersproject/abi"),a=require("@ethersproject/address"),u=require("@ethersproject/solidity"),c=t(require("@uniswap/v3-periphery/artifacts/contracts/interfaces/IMulticall.sol/IMulticall.json")),s=t(require("@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json")),p=t(require("@uniswap/v3-periphery/artifacts/contracts/interfaces/ISelfPermit.sol/ISelfPermit.json")),l=t(require("@uniswap/v3-periphery/artifacts/contracts/interfaces/IPeripheryPaymentsWithFee.sol/IPeripheryPaymentsWithFee.json")),d=t(require("@uniswap/v3-periphery/artifacts/contracts/lens/Quoter.sol/Quoter.json")),f=t(require("@uniswap/swap-router-contracts/artifacts/contracts/lens/QuoterV2.sol/QuoterV2.json")),h=t(require("@uniswap/v3-staker/artifacts/contracts/UniswapV3Staker.sol/UniswapV3Staker.json")),m=t(require("@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json"));function v(){v=function(){return e};var t,e={},n=Object.prototype,r=n.hasOwnProperty,i=Object.defineProperty||function(t,e,n){t[e]=n.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function p(t,e,n,r){var o=Object.create((e&&e.prototype instanceof y?e:y).prototype),a=new C(r||[]);return i(o,"_invoke",{value:b(t,n,a)}),o}function l(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=p;var d="suspendedStart",f="executing",h="completed",m={};function y(){}function k(){}function g(){}var A={};s(A,a,(function(){return this}));var T=Object.getPrototypeOf,w=T&&T(T(S([])));w&&w!==n&&r.call(w,a)&&(A=w);var x=g.prototype=y.prototype=Object.create(A);function I(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function q(t,e){function n(i,o,a,u){var c=l(t[i],t,o);if("throw"!==c.type){var s=c.arg,p=s.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):e.resolve(p).then((function(t){s.value=t,a(s)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}var o;i(this,"_invoke",{value:function(t,r){function i(){return new e((function(e,i){n(t,r,e,i)}))}return o=o?o.then(i,i):i()}})}function b(e,n,r){var i=d;return function(o,a){if(i===f)throw new Error("Generator is already running");if(i===h){if("throw"===o)throw a;return{value:t,done:!0}}for(r.method=o,r.arg=a;;){var u=r.delegate;if(u){var c=R(u,r);if(c){if(c===m)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(i===d)throw i=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i=f;var s=l(e,n,r);if("normal"===s.type){if(i=r.done?h:"suspendedYield",s.arg===m)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(i=h,r.method="throw",r.arg=s.arg)}}}function R(e,n){var r=n.method,i=e.iterator[r];if(i===t)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=t,R(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),m;var o=l(i,e.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,m;var a=o.arg;return a?a.done?(n[e.resultName]=a.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,m):a:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,m)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function S(e){if(e||""===e){var n=e[a];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,o=function n(){for(;++i=0;--o){var a=this.tryEntries[o],u=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),s=r.call(a,"finallyLoc");if(c&&s){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),P(n),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;P(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:S(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),m}},e}function y(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}function k(t,e,n,r,i,o,a){try{var u=t[o](a),c=u.value}catch(t){return void n(t)}u.done?e(c):Promise.resolve(c).then(r,i)}function g(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var o=t.apply(e,n);function a(t){k(o,r,i,a,u,"next",t)}function u(t){k(o,r,i,a,u,"throw",t)}a(void 0)}))}}function A(t,e){for(var n=0;nt.length)&&(e=t.length);for(var n=0,r=new Array(e);n=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var q,b="0x0000000000000000000000000000000000000000",R="0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54";function E(t){switch(t){case n.ChainId.ZKSYNC:return"0x010013f177ea1fcbc4520f9a3ca7cd2d1d77959e05aa66484027cb38e712aeed";default:return R}}(q=exports.FeeAmount||(exports.FeeAmount={}))[q.LOWEST=100]="LOWEST",q[q.LOW=500]="LOW",q[q.MEDIUM=3e3]="MEDIUM",q[q.HIGH=1e4]="HIGH";var P=((e={})[exports.FeeAmount.LOWEST]=1,e[exports.FeeAmount.LOW]=10,e[exports.FeeAmount.MEDIUM]=60,e[exports.FeeAmount.HIGH]=200,e),C=r.BigInt(-1),S=r.BigInt(0),O=r.BigInt(1),N=r.exponentiate(r.BigInt(2),r.BigInt(96)),_=r.exponentiate(N,r.BigInt(2));function F(t){var e=t.factoryAddress,r=t.tokenA,i=t.tokenB,c=t.fee,s=t.initCodeHashManualOverride,p=t.chainId,l=r.sortsBefore(i)?[r,i]:[i,r],d=u.keccak256(["bytes"],[o.defaultAbiCoder.encode(["address","address","uint24"],[l[0].address,l[1].address,c])]),f=null!=s?s:E(p);switch(p){case n.ChainId.ZKSYNC:return n.computeZksyncCreate2Address(e,f,d);default:return a.getCreate2Address(e,d,f)}}var X=function(){function t(){}return t.mulDivRoundingUp=function(t,e,n){var i=r.multiply(t,e),o=r.divide(i,n);return r.notEqual(r.remainder(i,n),S)&&(o=r.add(o,O)),o},t}(),L=r.subtract(r.exponentiate(r.BigInt(2),r.BigInt(160)),O);function U(t,e){var i=r.multiply(t,e);return r.bitwiseAnd(i,n.MaxUint256)}var M=function(){function t(){}return t.getAmount0Delta=function(t,e,n,i){if(r.greaterThan(t,e)){var o=[e,t];t=o[0],e=o[1]}var a=r.leftShift(n,r.BigInt(96)),u=r.subtract(e,t);return i?X.mulDivRoundingUp(X.mulDivRoundingUp(a,u,e),O,t):r.divide(r.divide(r.multiply(a,u),e),t)},t.getAmount1Delta=function(t,e,n,i){if(r.greaterThan(t,e)){var o=[e,t];t=o[0],e=o[1]}return i?X.mulDivRoundingUp(n,r.subtract(e,t),N):r.divide(r.multiply(n,r.subtract(e,t)),N)},t.getNextSqrtPriceFromInput=function(t,e,n,o){return r.greaterThan(t,S)||i(!1),r.greaterThan(e,S)||i(!1),o?this.getNextSqrtPriceFromAmount0RoundingUp(t,e,n,!0):this.getNextSqrtPriceFromAmount1RoundingDown(t,e,n,!0)},t.getNextSqrtPriceFromOutput=function(t,e,n,o){return r.greaterThan(t,S)||i(!1),r.greaterThan(e,S)||i(!1),o?this.getNextSqrtPriceFromAmount1RoundingDown(t,e,n,!1):this.getNextSqrtPriceFromAmount0RoundingUp(t,e,n,!1)},t.getNextSqrtPriceFromAmount0RoundingUp=function(t,e,o,a){if(r.equal(o,S))return t;var u=r.leftShift(e,r.BigInt(96));if(a){var c=U(o,t);if(r.equal(r.divide(c,o),t)){var s=(l=r.add(u,c),r.bitwiseAnd(l,n.MaxUint256));if(r.greaterThanOrEqual(s,u))return X.mulDivRoundingUp(u,t,s)}return X.mulDivRoundingUp(u,O,r.add(r.divide(u,t),o))}var p=U(o,t);r.equal(r.divide(p,o),t)||i(!1),r.greaterThan(u,p)||i(!1);var l,d=r.subtract(u,p);return X.mulDivRoundingUp(u,t,d)},t.getNextSqrtPriceFromAmount1RoundingDown=function(t,e,n,o){if(o){var a=r.lessThanOrEqual(n,L)?r.divide(r.leftShift(n,r.BigInt(96)),e):r.divide(r.multiply(n,N),e);return r.add(t,a)}var u=X.mulDivRoundingUp(n,N,e);return r.greaterThan(t,u)||i(!1),r.subtract(t,u)},t}(),B=r.exponentiate(r.BigInt(10),r.BigInt(6)),D=function(){function t(){}return t.computeSwapStep=function(t,e,n,i,o){var a={};o=r.BigInt(o);var u=r.greaterThanOrEqual(t,e),c=r.greaterThanOrEqual(i,S);if(c){var s=r.divide(r.multiply(i,r.subtract(B,o)),B);a.amountIn=u?M.getAmount0Delta(e,t,n,!0):M.getAmount1Delta(t,e,n,!0),a.sqrtRatioNextX96=r.greaterThanOrEqual(s,a.amountIn)?e:M.getNextSqrtPriceFromInput(t,n,s,u)}else a.amountOut=u?M.getAmount1Delta(e,t,n,!1):M.getAmount0Delta(t,e,n,!1),a.sqrtRatioNextX96=r.greaterThanOrEqual(r.multiply(i,C),a.amountOut)?e:M.getNextSqrtPriceFromOutput(t,n,r.multiply(i,C),u);var p=r.equal(e,a.sqrtRatioNextX96);return u?(a.amountIn=p&&c?a.amountIn:M.getAmount0Delta(a.sqrtRatioNextX96,t,n,!0),a.amountOut=p&&!c?a.amountOut:M.getAmount1Delta(a.sqrtRatioNextX96,t,n,!1)):(a.amountIn=p&&c?a.amountIn:M.getAmount1Delta(t,a.sqrtRatioNextX96,n,!0),a.amountOut=p&&!c?a.amountOut:M.getAmount0Delta(t,a.sqrtRatioNextX96,n,!1)),!c&&r.greaterThan(a.amountOut,r.multiply(i,C))&&(a.amountOut=r.multiply(i,C)),a.feeAmount=c&&r.notEqual(a.sqrtRatioNextX96,e)?r.subtract(i,a.amountIn):X.mulDivRoundingUp(a.amountIn,o,r.subtract(B,o)),[a.sqrtRatioNextX96,a.amountIn,a.amountOut,a.feeAmount]},t}(),j=function(){function t(){}return t.addDelta=function(t,e){return r.lessThan(e,S)?r.subtract(t,r.multiply(e,C)):r.add(t,e)},t}(),W=r.BigInt(2),K=[128,64,32,16,8,4,2,1].map((function(t){return[t,r.exponentiate(W,r.BigInt(t))]}));function G(t){r.greaterThan(t,S)||i(!1),r.lessThanOrEqual(t,n.MaxUint256)||i(!1);for(var e,o=0,a=I(K);!(e=a()).done;){var u=e.value,c=u[0];r.greaterThanOrEqual(t,u[1])&&(t=r.signedRightShift(t,r.BigInt(c)),o+=c)}return o}function H(t,e){return r.signedRightShift(r.multiply(t,r.BigInt(e)),r.BigInt(128))}var Q=r.exponentiate(r.BigInt(2),r.BigInt(32)),V=function(){function t(){}return t.getSqrtRatioAtTick=function(e){e>=t.MIN_TICK&&e<=t.MAX_TICK&&Number.isInteger(e)||i(!1);var o=e<0?-1*e:e,a=r.BigInt(0!=(1&o)?"0xfffcb933bd6fad37aa2d162d1a594001":"0x100000000000000000000000000000000");return 0!=(2&o)&&(a=H(a,"0xfff97272373d413259a46990580e213a")),0!=(4&o)&&(a=H(a,"0xfff2e50f5f656932ef12357cf3c7fdcc")),0!=(8&o)&&(a=H(a,"0xffe5caca7e10e4e61c3624eaa0941cd0")),0!=(16&o)&&(a=H(a,"0xffcb9843d60f6159c9db58835c926644")),0!=(32&o)&&(a=H(a,"0xff973b41fa98c081472e6896dfb254c0")),0!=(64&o)&&(a=H(a,"0xff2ea16466c96a3843ec78b326b52861")),0!=(128&o)&&(a=H(a,"0xfe5dee046a99a2a811c461f1969c3053")),0!=(256&o)&&(a=H(a,"0xfcbe86c7900a88aedcffc83b479aa3a4")),0!=(512&o)&&(a=H(a,"0xf987a7253ac413176f2b074cf7815e54")),0!=(1024&o)&&(a=H(a,"0xf3392b0822b70005940c7a398e4b70f3")),0!=(2048&o)&&(a=H(a,"0xe7159475a2c29b7443b29c7fa6e889d9")),0!=(4096&o)&&(a=H(a,"0xd097f3bdfd2022b8845ad8f792aa5825")),0!=(8192&o)&&(a=H(a,"0xa9f746462d870fdf8a65dc1f90e061e5")),0!=(16384&o)&&(a=H(a,"0x70d869a156d2a1b890bb3df62baf32f7")),0!=(32768&o)&&(a=H(a,"0x31be135f97d08fd981231505542fcfa6")),0!=(65536&o)&&(a=H(a,"0x9aa508b5b7a84e1c677de54f3e99bc9")),0!=(131072&o)&&(a=H(a,"0x5d6af8dedb81196699c329225ee604")),0!=(262144&o)&&(a=H(a,"0x2216e584f5fa1ea926041bedfe98")),0!=(524288&o)&&(a=H(a,"0x48a170391f7dc42444e8fa2")),e>0&&(a=r.divide(n.MaxUint256,a)),r.greaterThan(r.remainder(a,Q),S)?r.add(r.divide(a,Q),O):r.divide(a,Q)},t.getTickAtSqrtRatio=function(e){r.greaterThanOrEqual(e,t.MIN_SQRT_RATIO)&&r.lessThan(e,t.MAX_SQRT_RATIO)||i(!1);var n,o=r.leftShift(e,r.BigInt(32)),a=G(o);n=r.greaterThanOrEqual(r.BigInt(a),r.BigInt(128))?r.signedRightShift(o,r.BigInt(a-127)):r.leftShift(o,r.BigInt(127-a));for(var u=r.leftShift(r.subtract(r.BigInt(a),r.BigInt(128)),r.BigInt(64)),c=0;c<14;c++){n=r.signedRightShift(r.multiply(n,n),r.BigInt(127));var s=r.signedRightShift(n,r.BigInt(128));u=r.bitwiseOr(u,r.leftShift(s,r.BigInt(63-c))),n=r.signedRightShift(n,s)}var p=r.multiply(u,r.BigInt("255738958999603826347141")),l=r.toNumber(r.signedRightShift(r.subtract(p,r.BigInt("3402992956809132418596140100660247210")),r.BigInt(128))),d=r.toNumber(r.signedRightShift(r.add(p,r.BigInt("291339464771989622907027621153398088495")),r.BigInt(128)));return l===d?l:r.lessThanOrEqual(t.getSqrtRatioAtTick(d),e)?d:l},t}();function z(t,e,n,r,i,o,a,u,c){return Y.apply(this,arguments)}function Y(){return(Y=g(v().mark((function t(e,n,o,a,u,c,s,p,l){var d,f,h,m,y,k;return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:l||(l=s?r.add(V.MIN_SQRT_RATIO,O):r.subtract(V.MAX_SQRT_RATIO,O)),s?(r.greaterThan(l,V.MIN_SQRT_RATIO)||i(!1),r.lessThan(l,n)||i(!1)):(r.lessThan(l,V.MAX_SQRT_RATIO)||i(!1),r.greaterThan(l,n)||i(!1)),d=r.greaterThanOrEqual(p,S),f={amountSpecifiedRemaining:p,amountCalculated:S,sqrtPriceX96:n,tick:o,liquidity:a};case 4:if(!r.notEqual(f.amountSpecifiedRemaining,S)||f.sqrtPriceX96===l){t.next=35;break}return(h={}).sqrtPriceStartX96=f.sqrtPriceX96,t.next=9,c.nextInitializedTickWithinOneWord(f.tick,s,u);case 9:if(h.tickNext=(m=t.sent)[0],h.initialized=m[1],h.tickNextV.MAX_TICK&&(h.tickNext=V.MAX_TICK),h.sqrtPriceNextX96=V.getSqrtRatioAtTick(h.tickNext),y=D.computeSwapStep(f.sqrtPriceX96,(s?r.lessThan(h.sqrtPriceNextX96,l):r.greaterThan(h.sqrtPriceNextX96,l))?l:h.sqrtPriceNextX96,f.liquidity,f.amountSpecifiedRemaining,e),f.sqrtPriceX96=y[0],h.amountIn=y[1],h.amountOut=y[2],h.feeAmount=y[3],d?(f.amountSpecifiedRemaining=r.subtract(f.amountSpecifiedRemaining,r.add(h.amountIn,h.feeAmount)),f.amountCalculated=r.subtract(f.amountCalculated,h.amountOut)):(f.amountSpecifiedRemaining=r.add(f.amountSpecifiedRemaining,h.amountOut),f.amountCalculated=r.add(f.amountCalculated,r.add(h.amountIn,h.feeAmount))),!r.equal(f.sqrtPriceX96,h.sqrtPriceNextX96)){t.next=32;break}if(!h.initialized){t.next=29;break}return t.t0=r,t.next=25,c.getTick(h.tickNext);case 25:t.t1=t.sent.liquidityNet,k=t.t0.BigInt.call(t.t0,t.t1),s&&(k=r.multiply(k,C)),f.liquidity=j.addDelta(f.liquidity,k);case 29:f.tick=s?h.tickNext-1:h.tickNext,t.next=33;break;case 32:r.notEqual(f.sqrtPriceX96,h.sqrtPriceStartX96)&&(f.tick=V.getTickAtSqrtRatio(f.sqrtPriceX96));case 33:t.next=4;break;case 35:return t.abrupt("return",{amountCalculated:f.amountCalculated,sqrtRatioX96:f.sqrtPriceX96,liquidity:f.liquidity,tickCurrent:f.tick});case 36:case"end":return t.stop()}}),t)})))).apply(this,arguments)}V.MIN_TICK=-887272,V.MAX_TICK=-V.MIN_TICK,V.MIN_SQRT_RATIO=r.BigInt("4295128739"),V.MAX_SQRT_RATIO=r.BigInt("1461446703485210103287273052203988822378723970342");var Z=function(){function t(){}var e=t.prototype;return e.getTick=function(){var e=g(v().mark((function e(n){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error(t.ERROR_MESSAGE);case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.nextInitializedTickWithinOneWord=function(){var e=g(v().mark((function e(n,r,i){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error(t.ERROR_MESSAGE);case 1:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t}();function $(t,e){for(var n=0;n0)return!1;return!0}function J(t,e){return t.index-e.index}Z.ERROR_MESSAGE="No tick data provider was given";var tt=function(){function t(){}return t.validateList=function(t,e){e>0||i(!1),t.every((function(t){return t.index%e==0}))||i(!1),r.equal(t.reduce((function(t,e){return r.add(t,e.liquidityNet)}),S),S)||i(!1),$(t,J)||i(!1)},t.isBelowSmallest=function(t,e){return t.length>0||i(!1),e0||i(!1),e>=t[t.length-1].index},t.getTick=function(t,e){var n=t[this.binarySearch(t,e)];return n.index!==e&&i(!1),n},t.binarySearch=function(t,e){this.isBelowSmallest(t,e)&&i(!1);for(var n,r=0,o=t.length-1;;){if(t[n=Math.floor((r+o)/2)].index<=e&&(n===t.length-1||t[n+1].index>e))return n;t[n].index>8<<8)*i;if(t.isBelowSmallest(e,n))return[a,!1];var u=t.nextInitializedTick(e,n,r).index,c=Math.max(a,u);return[c,c===u]}var s=((1+(o+1>>8)<<8)-1)*i;if(this.isAtOrAboveLargest(e,n))return[s,!1];var p=this.nextInitializedTick(e,n,r).index,l=Math.min(s,p);return[l,l===p]},t}();function et(t){var e=r.BigInt(t).toString(16);return e.length%2!=0&&(e="0"+e),"0x"+e}function nt(t,e){var n=t.pools.reduce((function(t,e,n){var r=t.inputToken,i=t.path,o=t.types,a=e.token0.equals(r)?e.token1:e.token0;return 0===n?{inputToken:a,types:["address","uint24","address"],path:[r.address,e.fee,a.address]}:{inputToken:a,types:[].concat(o,["uint24","address"]),path:[].concat(i,[e.fee,a.address])}}),{inputToken:t.input.wrapped,path:[],types:[]}),r=n.path,i=n.types;return e?u.pack(i.reverse(),r.reverse()):u.pack(i,r)}function rt(t,e){var i=r.leftShift(r.BigInt(t),r.BigInt(192)),o=r.BigInt(e),a=r.divide(i,o);return n.sqrt(a)}function it(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var o=r.divide(r.multiply(t,e),N);return r.divide(r.multiply(r.BigInt(n),o),r.subtract(e,t))}function ot(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var o=r.multiply(r.multiply(r.BigInt(n),t),e),a=r.multiply(N,r.subtract(e,t));return r.divide(o,a)}function at(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}return r.divide(r.multiply(r.BigInt(n),N),r.subtract(e,t))}function ut(t,e,n,i,o,a){if(r.greaterThan(e,n)){var u=[n,e];e=u[0],n=u[1]}var c=a?ot:it;if(r.lessThanOrEqual(t,e))return c(e,n,i);if(r.lessThan(t,n)){var s=c(t,n,i),p=at(e,t,o);return r.lessThan(s,p)?s:p}return at(e,n,o)}var ct=r.exponentiate(r.BigInt(2),r.BigInt(128)),st=function(){function t(){}return t.getTokensOwed=function(t,e,n,i,o){return[r.divide(r.multiply(dt(i,t),n),ct),r.divide(r.multiply(dt(o,e),n),ct)]},t}();function pt(t,e,i){var o=V.getSqrtRatioAtTick(i),a=r.multiply(o,o);return t.sortsBefore(e)?new n.Price(t,e,_,a):new n.Price(t,e,a,_)}var lt=r.exponentiate(r.BigInt(2),r.BigInt(256));function dt(t,e){var n=r.subtract(t,e);return r.lessThan(n,S)?r.add(lt,n):n}var ft=function(){function t(){}return t.getFeeGrowthInside=function(t,e,n,r,i,o,a){var u,c,s,p;return i>=n?(u=t.feeGrowthOutside0X128,c=t.feeGrowthOutside1X128):(u=dt(o,t.feeGrowthOutside0X128),c=dt(a,t.feeGrowthOutside1X128)),i=V.MIN_TICK&&e<=V.MAX_TICK||i(!1),this.index=e,this.liquidityGross=r.BigInt(n),this.liquidityNet=r.BigInt(o)},mt=function(){function t(t,e){var n=t.map((function(t){return t instanceof ht?t:new ht(t)}));tt.validateList(n,e),this.ticks=n}var e=t.prototype;return e.getTick=function(){var t=g(v().mark((function t(e){return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",tt.getTick(this.ticks,e));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.nextInitializedTickWithinOneWord=function(){var t=g(v().mark((function t(e,n,r){return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",tt.nextInitializedTickWithinOneWord(this.ticks,e,n,r));case 1:case"end":return t.stop()}}),t,this)})));return function(e,n,r){return t.apply(this,arguments)}}(),t}(),vt=new Z,yt=function(){function t(t,e,n,o,a,u,c){void 0===c&&(c=vt),Number.isInteger(n)&&n<1e6||i(!1);var s=V.getSqrtRatioAtTick(u),p=V.getSqrtRatioAtTick(u+1);r.greaterThanOrEqual(r.BigInt(o),s)&&r.lessThanOrEqual(r.BigInt(o),p)||i(!1);var l=t.sortsBefore(e)?[t,e]:[e,t];this.token0=l[0],this.token1=l[1],this.fee=n,this.sqrtRatioX96=r.BigInt(o),this.liquidity=r.BigInt(a),this.tickCurrent=u,this.tickDataProvider=Array.isArray(c)?new mt(c,P[n]):c}t.getAddress=function(t,e,n,r,i){return F({factoryAddress:null!=i?i:"0x1F98431c8aD98523631AE4a59f267346ea31F984",fee:n,tokenA:t,tokenB:e,initCodeHashManualOverride:r})};var e=t.prototype;return e.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},e.priceOf=function(t){return this.involvesToken(t)||i(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.getOutputAmount=function(){var e=g(v().mark((function e(o,a){var u,c,s,p,l;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.involvesToken(o.currency)||i(!1),u=o.currency.equals(this.token0),e.next=4,this.swap(u,o.quotient,a);case 4:return s=(c=e.sent).sqrtRatioX96,p=c.liquidity,l=c.tickCurrent,e.abrupt("return",[n.CurrencyAmount.fromRawAmount(u?this.token1:this.token0,r.multiply(c.amountCalculated,C)),new t(this.token0,this.token1,this.fee,s,p,l,this.tickDataProvider)]);case 11:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),e.getInputAmount=function(){var e=g(v().mark((function e(o,a){var u,c,s,p,l;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o.currency.isToken&&this.involvesToken(o.currency)||i(!1),u=o.currency.equals(this.token1),e.next=4,this.swap(u,r.multiply(o.quotient,C),a);case 4:return s=(c=e.sent).sqrtRatioX96,p=c.liquidity,l=c.tickCurrent,e.abrupt("return",[n.CurrencyAmount.fromRawAmount(u?this.token0:this.token1,c.amountCalculated),new t(this.token0,this.token1,this.fee,s,p,l,this.tickDataProvider)]);case 11:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),e.swap=function(){var t=g(v().mark((function t(e,n,i){return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",z(r.BigInt(this.fee),this.sqrtRatioX96,this.tickCurrent,this.liquidity,this.tickSpacing,this.tickDataProvider,e,n,i));case 1:case"end":return t.stop()}}),t,this)})));return function(e,n,r){return t.apply(this,arguments)}}(),T(t,[{key:"token0Price",get:function(){var t;return null!=(t=this._token0Price)?t:this._token0Price=new n.Price(this.token0,this.token1,_,r.multiply(this.sqrtRatioX96,this.sqrtRatioX96))}},{key:"token1Price",get:function(){var t;return null!=(t=this._token1Price)?t:this._token1Price=new n.Price(this.token1,this.token0,r.multiply(this.sqrtRatioX96,this.sqrtRatioX96),_)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"tickSpacing",get:function(){return P[this.fee]}}]),t}(),kt=function(){function t(t){var e=t.pool,n=t.liquidity,o=t.tickLower,a=t.tickUpper;this._token0Amount=null,this._token1Amount=null,this._mintAmounts=null,o=V.MIN_TICK&&o%e.tickSpacing==0||i(!1),a<=V.MAX_TICK&&a%e.tickSpacing==0||i(!1),this.pool=e,this.tickLower=o,this.tickUpper=a,this.liquidity=r.BigInt(n)}var e=t.prototype;return e.ratiosAfterSlippage=function(t){var e=this.pool.token0Price.asFraction.multiply(new n.Percent(1).subtract(t)),i=this.pool.token0Price.asFraction.multiply(t.add(1)),o=rt(e.numerator,e.denominator);r.lessThanOrEqual(o,V.MIN_SQRT_RATIO)&&(o=r.add(V.MIN_SQRT_RATIO,r.BigInt(1)));var a=rt(i.numerator,i.denominator);return r.greaterThanOrEqual(a,V.MAX_SQRT_RATIO)&&(a=r.subtract(V.MAX_SQRT_RATIO,r.BigInt(1))),{sqrtRatioX96Lower:o,sqrtRatioX96Upper:a}},e.mintAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,o=new yt(this.pool.token0,this.pool.token1,this.pool.fee,i,0,V.getTickAtSqrtRatio(i)),a=new yt(this.pool.token0,this.pool.token1,this.pool.fee,r,0,V.getTickAtSqrtRatio(r)),u=t.fromAmounts(w({pool:this.pool,tickLower:this.tickLower,tickUpper:this.tickUpper},this.mintAmounts,{useFullPrecision:!1}));return{amount0:new t({pool:a,liquidity:u.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount0,amount1:new t({pool:o,liquidity:u.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount1}},e.burnAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,o=new yt(this.pool.token0,this.pool.token1,this.pool.fee,i,0,V.getTickAtSqrtRatio(i)),a=new t({pool:new yt(this.pool.token0,this.pool.token1,this.pool.fee,r,0,V.getTickAtSqrtRatio(r)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount0,u=new t({pool:o,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount1;return{amount0:a.quotient,amount1:u.quotient}},t.fromAmounts=function(e){var n=e.pool,r=e.tickLower,i=e.tickUpper,o=e.amount0,a=e.amount1,u=e.useFullPrecision,c=V.getSqrtRatioAtTick(r),s=V.getSqrtRatioAtTick(i);return new t({pool:n,tickLower:r,tickUpper:i,liquidity:ut(n.sqrtRatioX96,c,s,o,a,u)})},t.fromAmount0=function(e){return t.fromAmounts({pool:e.pool,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0:e.amount0,amount1:n.MaxUint256,useFullPrecision:e.useFullPrecision})},t.fromAmount1=function(e){return t.fromAmounts({pool:e.pool,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0:n.MaxUint256,amount1:e.amount1,useFullPrecision:!0})},T(t,[{key:"token0PriceLower",get:function(){return pt(this.pool.token0,this.pool.token1,this.tickLower)}},{key:"token0PriceUpper",get:function(){return pt(this.pool.token0,this.pool.token1,this.tickUpper)}},{key:"amount0",get:function(){return null===this._token0Amount&&(this._token0Amount=n.CurrencyAmount.fromRawAmount(this.pool.token0,this.pool.tickCurrent0||i(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||i(!1);var o=e.wrapped;t[0].involvesToken(o)||i(!1),t[t.length-1].involvesToken(n.wrapped)||i(!1);for(var a,u=[o],c=I(t.entries());!(a=c()).done;){var s=a.value,p=s[1],l=u[s[0]];l.equals(p.token0)||l.equals(p.token1)||i(!1);var d=l.equals(p.token0)?p.token1:p.token0;u.push(d)}this.pools=t,this.tokenPath=u,this.input=e,this.output=null!=n?n:u[u.length-1]}return T(t,[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;var t=this.pools.slice(1).reduce((function(t,e){var n=t.price;return t.nextInput.equals(e.token0)?{nextInput:e.token1,price:n.multiply(e.token0Price)}:{nextInput:e.token0,price:n.multiply(e.token1Price)}}),this.pools[0].token0.equals(this.input.wrapped)?{nextInput:this.pools[0].token1,price:this.pools[0].token0Price}:{nextInput:this.pools[0].token0,price:this.pools[0].token1Price}).price;return this._midPrice=new n.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function At(t,e){return t.inputAmount.currency.equals(e.inputAmount.currency)||i(!1),t.outputAmount.currency.equals(e.outputAmount.currency)||i(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?t.swaps.reduce((function(t,e){return t+e.route.tokenPath.length}),0)-e.swaps.reduce((function(t,e){return t+e.route.tokenPath.length}),0):t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}var Tt=function(){function t(t){var e=t.routes,n=t.tradeType,r=e[0].inputAmount.currency,o=e[0].outputAmount.currency;e.every((function(t){return r.wrapped.equals(t.route.input.wrapped)}))||i(!1),e.every((function(t){return o.wrapped.equals(t.route.output.wrapped)}))||i(!1);for(var a,u=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),c=new Set,s=I(e);!(a=s()).done;)for(var p,l=I(a.value.route.pools);!(p=l()).done;){var d=p.value;c.add(yt.getAddress(d.token0,d.token1,d.fee))}u!==c.size&&i(!1),this.swaps=e,this.tradeType=n}t.exactIn=function(){var e=g(v().mark((function e(r,i){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.fromRoute(r,i,n.TradeType.EXACT_INPUT));case 1:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.exactOut=function(){var e=g(v().mark((function e(r,i){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.fromRoute(r,i,n.TradeType.EXACT_OUTPUT));case 1:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=g(v().mark((function e(r,o,a){var u,c,s,p,l,d,f;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u=new Array(r.tokenPath.length),a!==n.TradeType.EXACT_INPUT){e.next=19;break}o.currency.equals(r.input)||i(!1),u[0]=o.wrapped,p=0;case 5:if(!(p0)){e.next=32;break}return f=r.pools[d-1],e.next=26,f.getInputAmount(u[d]);case 26:u[d-1]=e.sent[0];case 29:d--,e.next=22;break;case 32:c=n.CurrencyAmount.fromFractionalAmount(r.input,u[0].numerator,u[0].denominator),s=n.CurrencyAmount.fromFractionalAmount(r.output,o.numerator,o.denominator);case 34:return e.abrupt("return",new t({routes:[{inputAmount:c,outputAmount:s,route:r}],tradeType:a}));case 35:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.fromRoutes=function(){var e=g(v().mark((function e(r,o){var a,u,c,s,p,l,d,f,h,m,y,k,g;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=[],u=I(r);case 2:if((c=u()).done){e.next=43;break}if(p=(s=c.value).route,l=s.amount,d=new Array(p.tokenPath.length),f=void 0,h=void 0,o!==n.TradeType.EXACT_INPUT){e.next=25;break}l.currency.equals(p.input)||i(!1),f=n.CurrencyAmount.fromFractionalAmount(p.input,l.numerator,l.denominator),d[0]=n.CurrencyAmount.fromFractionalAmount(p.input.wrapped,l.numerator,l.denominator),m=0;case 12:if(!(m0)){e.next=39;break}return g=p.pools[k-1],e.next=33,g.getInputAmount(d[k]);case 33:d[k-1]=e.sent[0];case 36:k--,e.next=29;break;case 39:f=n.CurrencyAmount.fromFractionalAmount(p.input,d[0].numerator,d[0].denominator);case 40:a.push({route:p,inputAmount:f,outputAmount:h});case 41:e.next=2;break;case 43:return e.abrupt("return",new t({routes:a,tradeType:o}));case 44:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(w({},e,{routes:[{inputAmount:e.inputAmount,outputAmount:e.outputAmount,route:e.route}]}))},t.createUncheckedTradeWithMultipleRoutes=function(e){return new t(e)};var e=t.prototype;return e.minimumAmountOut=function(t,e){if(void 0===e&&(e=this.outputAmount),t.lessThan(S)&&i(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return e;var r=new n.Fraction(O).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(S)&&i(!1),this.tradeType===n.TradeType.EXACT_INPUT)return e;var r=new n.Fraction(O).add(t).multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var e=g(v().mark((function e(r,o,a,u,c,s,p){var l,d,f,h,m,y,k,g,A,T,w;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:f=void 0===(d=(l=void 0===u?{}:u).maxNumResults)?3:d,m=void 0===(h=l.maxHops)?3:h,void 0===c&&(c=[]),void 0===s&&(s=o),void 0===p&&(p=[]),r.length>0||i(!1),m>0||i(!1),o===s||c.length>0||i(!1),y=s.wrapped,k=a.wrapped,g=0;case 10:if(!(g1&&r.length>1)){e.next=43;break}return w=r.slice(0,g).concat(r.slice(g+1,r.length)),e.next=43,t.bestTradeExactIn(w,o,a,{maxNumResults:f,maxHops:m-1},[].concat(c,[A]),T,p);case 43:g++,e.next=10;break;case 46:return e.abrupt("return",p);case 47:case"end":return e.stop()}}),e,null,[[15,23]])})));return function(t,n,r,i,o,a,u){return e.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var e=g(v().mark((function e(r,o,a,u,c,s,p){var l,d,f,h,m,y,k,g,A,T,w;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:f=void 0===(d=(l=void 0===u?{}:u).maxNumResults)?3:d,m=void 0===(h=l.maxHops)?3:h,void 0===c&&(c=[]),void 0===s&&(s=a),void 0===p&&(p=[]),r.length>0||i(!1),m>0||i(!1),a===s||c.length>0||i(!1),y=s.wrapped,k=o.wrapped,g=0;case 10:if(!(g1&&r.length>1)){e.next=43;break}return w=r.slice(0,g).concat(r.slice(g+1,r.length)),e.next=43,t.bestTradeExactOut(w,o,a,{maxNumResults:f,maxHops:m-1},[A].concat(c),T,p);case 43:g++,e.next=10;break;case 46:return e.abrupt("return",p);case 47:case"end":return e.stop()}}),e,null,[[15,23]])})));return function(t,n,r,i,o,a,u){return e.apply(this,arguments)}}(),T(t,[{key:"route",get:function(){return 1!==this.swaps.length&&i(!1),this.swaps[0].route}},{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),r=I(this.swaps);!(t=r()).done;){var i=t.value;e=e.add(i.route.midPrice.quote(i.inputAmount))}var o=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new n.Percent(o.numerator,o.denominator),this._priceImpact}}]),t}(),wt=function(){function t(){}return t.encodeMulticall=function(e){return Array.isArray(e)||(e=[e]),1===e.length?e[0]:t.INTERFACE.encodeFunctionData("multicall",[e])},t}();wt.INTERFACE=new o.Interface(c.abi);var xt=function(){function t(){}return t.encodePermit=function(e,n){return"nonce"in n?t.INTERFACE.encodeFunctionData("selfPermitAllowed",[e.address,et(n.nonce),et(n.expiry),n.v,n.r,n.s]):t.INTERFACE.encodeFunctionData("selfPermit",[e.address,et(n.amount),et(n.deadline),n.v,n.r,n.s])},t}();xt.INTERFACE=new o.Interface(p.abi);var It=function(){function t(){}return t.encodeFeeBips=function(t){return et(t.multiply(1e4).quotient)},t.encodeUnwrapWETH9=function(e,r,i){if(r=n.validateAndParseAddress(r),i){var o=this.encodeFeeBips(i.fee),a=n.validateAndParseAddress(i.recipient);return t.INTERFACE.encodeFunctionData("unwrapWETH9WithFee",[et(e),r,o,a])}return t.INTERFACE.encodeFunctionData("unwrapWETH9",[et(e),r])},t.encodeSweepToken=function(e,r,i,o){if(i=n.validateAndParseAddress(i),o){var a=this.encodeFeeBips(o.fee),u=n.validateAndParseAddress(o.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee",[e.address,et(r),i,a,u])}return t.INTERFACE.encodeFunctionData("sweepToken",[e.address,et(r),i])},t.encodeRefundETH=function(){return t.INTERFACE.encodeFunctionData("refundETH")},t}();It.INTERFACE=new o.Interface(l.abi);var qt=["expectedCurrencyOwed0","expectedCurrencyOwed1"],bt=et(r.subtract(r.exponentiate(r.BigInt(2),r.BigInt(128)),r.BigInt(1)));function Rt(t){return Object.keys(t).some((function(t){return"recipient"===t}))}var Et=function(){function t(){}return t.encodeCreate=function(e){return t.INTERFACE.encodeFunctionData("createAndInitializePoolIfNecessary",[e.token0.address,e.token1.address,e.fee,et(e.sqrtRatioX96)])},t.createCallParameters=function(t){return{calldata:this.encodeCreate(t),value:et(0)}},t.addCallParameters=function(e,o){r.greaterThan(e.liquidity,S)||i(!1);var a=[],u=e.mintAmounts,c=u.amount0,s=u.amount1,p=e.mintAmountsWithSlippage(o.slippageTolerance),l=et(p.amount0),d=et(p.amount1),f=et(o.deadline);if(Rt(o)&&o.createPool&&a.push(this.encodeCreate(e.pool)),o.token0Permit&&a.push(xt.encodePermit(e.pool.token0,o.token0Permit)),o.token1Permit&&a.push(xt.encodePermit(e.pool.token1,o.token1Permit)),Rt(o)){var h=n.validateAndParseAddress(o.recipient);a.push(t.INTERFACE.encodeFunctionData("mint",[{token0:e.pool.token0.address,token1:e.pool.token1.address,fee:e.pool.fee,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0Desired:et(c),amount1Desired:et(s),amount0Min:l,amount1Min:d,recipient:h,deadline:f}]))}else a.push(t.INTERFACE.encodeFunctionData("increaseLiquidity",[{tokenId:et(o.tokenId),amount0Desired:et(c),amount1Desired:et(s),amount0Min:l,amount1Min:d,deadline:f}]));var m=et(0);if(o.useNative){var v=o.useNative.wrapped;e.pool.token0.equals(v)||e.pool.token1.equals(v)||i(!1);var y=e.pool.token0.equals(v)?c:s;r.greaterThan(y,S)&&a.push(It.encodeRefundETH()),m=et(y)}return{calldata:wt.encodeMulticall(a),value:m}},t.encodeCollect=function(e){var r=[],i=et(e.tokenId),o=e.expectedCurrencyOwed0.currency.isNative||e.expectedCurrencyOwed1.currency.isNative,a=n.validateAndParseAddress(e.recipient);if(r.push(t.INTERFACE.encodeFunctionData("collect",[{tokenId:i,recipient:o?b:a,amount0Max:bt,amount1Max:bt}])),o){var u=e.expectedCurrencyOwed0.currency.isNative?e.expectedCurrencyOwed1.currency:e.expectedCurrencyOwed0.currency,c=e.expectedCurrencyOwed0.currency.isNative?e.expectedCurrencyOwed1.quotient:e.expectedCurrencyOwed0.quotient;r.push(It.encodeUnwrapWETH9(e.expectedCurrencyOwed0.currency.isNative?e.expectedCurrencyOwed0.quotient:e.expectedCurrencyOwed1.quotient,a)),r.push(It.encodeSweepToken(u,c,a))}return r},t.collectCallParameters=function(e){var n=t.encodeCollect(e);return{calldata:wt.encodeMulticall(n),value:et(0)}},t.removeCallParameters=function(e,o){var a=[],u=et(o.deadline),c=et(o.tokenId),s=new kt({pool:e.pool,liquidity:o.liquidityPercentage.multiply(e.liquidity).quotient,tickLower:e.tickLower,tickUpper:e.tickUpper});r.greaterThan(s.liquidity,S)||i(!1);var p=s.burnAmountsWithSlippage(o.slippageTolerance),l=p.amount0,d=p.amount1;o.permit&&a.push(t.INTERFACE.encodeFunctionData("permit",[n.validateAndParseAddress(o.permit.spender),c,et(o.permit.deadline),o.permit.v,o.permit.r,o.permit.s])),a.push(t.INTERFACE.encodeFunctionData("decreaseLiquidity",[{tokenId:c,liquidity:et(s.liquidity),amount0Min:et(l),amount1Min:et(d),deadline:u}]));var f=o.collectOptions,h=f.expectedCurrencyOwed0,m=f.expectedCurrencyOwed1,v=function(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r=0||(i[n]=t[n]);return i}(f,qt);return a.push.apply(a,t.encodeCollect(w({tokenId:et(o.tokenId),expectedCurrencyOwed0:h.add(n.CurrencyAmount.fromRawAmount(h.currency,l)),expectedCurrencyOwed1:m.add(n.CurrencyAmount.fromRawAmount(m.currency,d))},v))),o.liquidityPercentage.equalTo(O)?o.burnToken&&a.push(t.INTERFACE.encodeFunctionData("burn",[c])):!0===o.burnToken&&i(!1),{calldata:wt.encodeMulticall(a),value:et(0)}},t.safeTransferFromParameters=function(e){var r=n.validateAndParseAddress(e.recipient),i=n.validateAndParseAddress(e.sender);return{calldata:e.data?t.INTERFACE.encodeFunctionData("safeTransferFrom(address,address,uint256,bytes)",[i,r,et(e.tokenId),e.data]):t.INTERFACE.encodeFunctionData("safeTransferFrom(address,address,uint256)",[i,r,et(e.tokenId)]),value:et(0)}},t}();Et.INTERFACE=new o.Interface(s.abi);var Pt=function(){function t(){}return t.quoteCallParameters=function(t,e,r,o){void 0===o&&(o={});var a,u=1===t.pools.length,c=et(e.quotient),s=o.useQuoterV2?this.V2INTERFACE:this.V1INTERFACE;if(u){var p,l,d={tokenIn:t.tokenPath[0].address,tokenOut:t.tokenPath[1].address,fee:t.pools[0].fee,sqrtPriceLimitX96:et(null!=(p=null==(l=o)?void 0:l.sqrtPriceLimitX96)?p:0)},f=w({},d,r===n.TradeType.EXACT_INPUT?{amountIn:c}:{amount:c});a=s.encodeFunctionData(r===n.TradeType.EXACT_INPUT?"quoteExactInputSingle":"quoteExactOutputSingle",o.useQuoterV2?[f]:[d.tokenIn,d.tokenOut,d.fee,c,d.sqrtPriceLimitX96])}else{var h;void 0!==(null==(h=o)?void 0:h.sqrtPriceLimitX96)&&i(!1);var m=nt(t,r===n.TradeType.EXACT_OUTPUT);a=s.encodeFunctionData(r===n.TradeType.EXACT_INPUT?"quoteExactInput":"quoteExactOutput",[m,c])}return{calldata:a,value:et(0)}},t}();Pt.V1INTERFACE=new o.Interface(d.abi),Pt.V2INTERFACE=new o.Interface(f.abi);var Ct=function(){function t(){}return t.encodeClaim=function(e,r){var i,o=[];o.push(t.INTERFACE.encodeFunctionData("unstakeToken",[this._encodeIncentiveKey(e),et(r.tokenId)]));var a=n.validateAndParseAddress(r.recipient),u=null!=(i=r.amount)?i:0;return o.push(t.INTERFACE.encodeFunctionData("claimReward",[e.rewardToken.address,a,et(u)])),o},t.collectRewards=function(e,n){e=Array.isArray(e)?e:[e];for(var r=[],i=0;i1){for(var r=[],i=0;i0||i(!1),t>=V.MIN_TICK&&t<=V.MAX_TICK||i(!1);var n=Math.round(t/e)*e;return nV.MAX_TICK?n-e:n},exports.poolInitCodeHash=E,exports.priceToClosestTick=function(t){var e=t.baseCurrency.sortsBefore(t.quoteCurrency),n=e?rt(t.numerator,t.denominator):rt(t.denominator,t.numerator),r=V.getTickAtSqrtRatio(n),i=pt(t.baseCurrency,t.quoteCurrency,r+1);return e?t.lessThan(i)||r++:t.greaterThan(i)||r++,r},exports.subIn256=dt,exports.tickToPrice=pt,exports.toHex=et,exports.tradeComparator=At,exports.v3Swap=z; ++"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("@uniswap/sdk-core"),r=t(require("jsbi")),i=t(require("tiny-invariant")),o=require("@ethersproject/abi"),u=require("@ethersproject/address"),a=require("@ethersproject/solidity"),c=t(require("@uniswap/v3-periphery/artifacts/contracts/interfaces/IMulticall.sol/IMulticall.json")),s=t(require("@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json")),p=t(require("@uniswap/v3-periphery/artifacts/contracts/interfaces/ISelfPermit.sol/ISelfPermit.json")),l=t(require("@uniswap/v3-periphery/artifacts/contracts/interfaces/IPeripheryPaymentsWithFee.sol/IPeripheryPaymentsWithFee.json")),d=t(require("@uniswap/v3-periphery/artifacts/contracts/lens/Quoter.sol/Quoter.json")),f=t(require("@uniswap/swap-router-contracts/artifacts/contracts/lens/QuoterV2.sol/QuoterV2.json")),h=t(require("@uniswap/v3-staker/artifacts/contracts/UniswapV3Staker.sol/UniswapV3Staker.json")),m=t(require("@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json"));function v(){v=function(){return e};var t,e={},n=Object.prototype,r=n.hasOwnProperty,i=Object.defineProperty||function(t,e,n){t[e]=n.value},o="function"==typeof Symbol?Symbol:{},u=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function p(t,e,n,r){var o=Object.create((e&&e.prototype instanceof y?e:y).prototype),u=new C(r||[]);return i(o,"_invoke",{value:b(t,n,u)}),o}function l(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=p;var d="suspendedStart",f="executing",h="completed",m={};function y(){}function k(){}function g(){}var A={};s(A,u,(function(){return this}));var T=Object.getPrototypeOf,w=T&&T(T(S([])));w&&w!==n&&r.call(w,u)&&(A=w);var x=g.prototype=y.prototype=Object.create(A);function I(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function q(t,e){function n(i,o,u,a){var c=l(t[i],t,o);if("throw"!==c.type){var s=c.arg,p=s.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,u,a)}),(function(t){n("throw",t,u,a)})):e.resolve(p).then((function(t){s.value=t,u(s)}),(function(t){return n("throw",t,u,a)}))}a(c.arg)}var o;i(this,"_invoke",{value:function(t,r){function i(){return new e((function(e,i){n(t,r,e,i)}))}return o=o?o.then(i,i):i()}})}function b(e,n,r){var i=d;return function(o,u){if(i===f)throw new Error("Generator is already running");if(i===h){if("throw"===o)throw u;return{value:t,done:!0}}for(r.method=o,r.arg=u;;){var a=r.delegate;if(a){var c=R(a,r);if(c){if(c===m)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(i===d)throw i=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i=f;var s=l(e,n,r);if("normal"===s.type){if(i=r.done?h:"suspendedYield",s.arg===m)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(i=h,r.method="throw",r.arg=s.arg)}}}function R(e,n){var r=n.method,i=e.iterator[r];if(i===t)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=t,R(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),m;var o=l(i,e.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,m;var u=o.arg;return u?u.done?(n[e.resultName]=u.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,m):u:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,m)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function S(e){if(e||""===e){var n=e[u];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,o=function n(){for(;++i=0;--o){var u=this.tryEntries[o],a=u.completion;if("root"===u.tryLoc)return i("end");if(u.tryLoc<=this.prev){var c=r.call(u,"catchLoc"),s=r.call(u,"finallyLoc");if(c&&s){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),P(n),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;P(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:S(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),m}},e}function y(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}function k(t,e,n,r,i,o,u){try{var a=t[o](u),c=a.value}catch(t){return void n(t)}a.done?e(c):Promise.resolve(c).then(r,i)}function g(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var o=t.apply(e,n);function u(t){k(o,r,i,u,a,"next",t)}function a(t){k(o,r,i,u,a,"throw",t)}u(void 0)}))}}function A(t,e){for(var n=0;nt.length)&&(e=t.length);for(var n=0,r=new Array(e);n=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var q,b="0x0000000000000000000000000000000000000000",R="0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54";function E(t){switch(t){case n.ChainId.ZKSYNC:return"0x010013f177ea1fcbc4520f9a3ca7cd2d1d77959e05aa66484027cb38e712aeed";default:return R}}(q=exports.FeeAmount||(exports.FeeAmount={}))[q.LOWEST=100]="LOWEST",q[q.LOW=500]="LOW",q[q.MEDIUM=3e3]="MEDIUM",q[q.HIGH=1e4]="HIGH";var P=((e={})[exports.FeeAmount.LOWEST]=1,e[exports.FeeAmount.LOW]=10,e[exports.FeeAmount.MEDIUM]=60,e[exports.FeeAmount.HIGH]=200,e),C=r.BigInt(-1),S=r.BigInt(0),O=r.BigInt(1),N=r.exponentiate(r.BigInt(2),r.BigInt(96)),_=r.exponentiate(N,r.BigInt(2));function F(t){var e=t.factoryAddress,r=t.tokenA,i=t.tokenB,c=t.fee,s=t.initCodeHashManualOverride,p=t.chainId,l=r.sortsBefore(i)?[r,i]:[i,r],d=a.keccak256(["bytes"],[o.defaultAbiCoder.encode(["address","address","uint24"],[l[0].address,l[1].address,c])]),f=null!=s?s:E(p);switch(p){case n.ChainId.ZKSYNC:return n.computeZksyncCreate2Address(e,f,d);default:return u.getCreate2Address(e,d,f)}}var X=function(){function t(){}return t.mulDivRoundingUp=function(t,e,n){var i=r.multiply(t,e),o=r.divide(i,n);return r.notEqual(r.remainder(i,n),S)&&(o=r.add(o,O)),o},t}(),L=r.subtract(r.exponentiate(r.BigInt(2),r.BigInt(160)),O);function U(t,e){var i=r.multiply(t,e);return r.bitwiseAnd(i,n.MaxUint256)}var M=function(){function t(){}return t.getAmount0Delta=function(t,e,n,i){if(r.greaterThan(t,e)){var o=[e,t];t=o[0],e=o[1]}var u=r.leftShift(n,r.BigInt(96)),a=r.subtract(e,t);return i?X.mulDivRoundingUp(X.mulDivRoundingUp(u,a,e),O,t):r.divide(r.divide(r.multiply(u,a),e),t)},t.getAmount1Delta=function(t,e,n,i){if(r.greaterThan(t,e)){var o=[e,t];t=o[0],e=o[1]}return i?X.mulDivRoundingUp(n,r.subtract(e,t),N):r.divide(r.multiply(n,r.subtract(e,t)),N)},t.getNextSqrtPriceFromInput=function(t,e,n,o){return r.greaterThan(t,S)||i(!1),r.greaterThan(e,S)||i(!1),o?this.getNextSqrtPriceFromAmount0RoundingUp(t,e,n,!0):this.getNextSqrtPriceFromAmount1RoundingDown(t,e,n,!0)},t.getNextSqrtPriceFromOutput=function(t,e,n,o){return r.greaterThan(t,S)||i(!1),r.greaterThan(e,S)||i(!1),o?this.getNextSqrtPriceFromAmount1RoundingDown(t,e,n,!1):this.getNextSqrtPriceFromAmount0RoundingUp(t,e,n,!1)},t.getNextSqrtPriceFromAmount0RoundingUp=function(t,e,o,u){if(r.equal(o,S))return t;var a=r.leftShift(e,r.BigInt(96));if(u){var c=U(o,t);if(r.equal(r.divide(c,o),t)){var s=(l=r.add(a,c),r.bitwiseAnd(l,n.MaxUint256));if(r.greaterThanOrEqual(s,a))return X.mulDivRoundingUp(a,t,s)}return X.mulDivRoundingUp(a,O,r.add(r.divide(a,t),o))}var p=U(o,t);r.equal(r.divide(p,o),t)||i(!1),r.greaterThan(a,p)||i(!1);var l,d=r.subtract(a,p);return X.mulDivRoundingUp(a,t,d)},t.getNextSqrtPriceFromAmount1RoundingDown=function(t,e,n,o){if(o){var u=r.lessThanOrEqual(n,L)?r.divide(r.leftShift(n,r.BigInt(96)),e):r.divide(r.multiply(n,N),e);return r.add(t,u)}var a=X.mulDivRoundingUp(n,N,e);return r.greaterThan(t,a)||i(!1),r.subtract(t,a)},t}(),B=r.exponentiate(r.BigInt(10),r.BigInt(6)),D=function(){function t(){}return t.computeSwapStep=function(t,e,n,i,o){var u={};o=r.BigInt(o);var a=r.greaterThanOrEqual(t,e),c=r.greaterThanOrEqual(i,S);if(c){var s=r.divide(r.multiply(i,r.subtract(B,o)),B);u.amountIn=a?M.getAmount0Delta(e,t,n,!0):M.getAmount1Delta(t,e,n,!0),u.sqrtRatioNextX96=r.greaterThanOrEqual(s,u.amountIn)?e:M.getNextSqrtPriceFromInput(t,n,s,a)}else u.amountOut=a?M.getAmount1Delta(e,t,n,!1):M.getAmount0Delta(t,e,n,!1),u.sqrtRatioNextX96=r.greaterThanOrEqual(r.multiply(i,C),u.amountOut)?e:M.getNextSqrtPriceFromOutput(t,n,r.multiply(i,C),a);var p=r.equal(e,u.sqrtRatioNextX96);return a?(u.amountIn=p&&c?u.amountIn:M.getAmount0Delta(u.sqrtRatioNextX96,t,n,!0),u.amountOut=p&&!c?u.amountOut:M.getAmount1Delta(u.sqrtRatioNextX96,t,n,!1)):(u.amountIn=p&&c?u.amountIn:M.getAmount1Delta(t,u.sqrtRatioNextX96,n,!0),u.amountOut=p&&!c?u.amountOut:M.getAmount0Delta(t,u.sqrtRatioNextX96,n,!1)),!c&&r.greaterThan(u.amountOut,r.multiply(i,C))&&(u.amountOut=r.multiply(i,C)),u.feeAmount=c&&r.notEqual(u.sqrtRatioNextX96,e)?r.subtract(i,u.amountIn):X.mulDivRoundingUp(u.amountIn,o,r.subtract(B,o)),[u.sqrtRatioNextX96,u.amountIn,u.amountOut,u.feeAmount]},t}(),j=function(){function t(){}return t.addDelta=function(t,e){return r.lessThan(e,S)?r.subtract(t,r.multiply(e,C)):r.add(t,e)},t}(),W=r.BigInt(2),K=[128,64,32,16,8,4,2,1].map((function(t){return[t,r.exponentiate(W,r.BigInt(t))]}));function G(t){r.greaterThan(t,S)||i(!1),r.lessThanOrEqual(t,n.MaxUint256)||i(!1);for(var e,o=0,u=I(K);!(e=u()).done;){var a=e.value,c=a[0];r.greaterThanOrEqual(t,a[1])&&(t=r.signedRightShift(t,r.BigInt(c)),o+=c)}return o}function H(t,e){return r.signedRightShift(r.multiply(t,r.BigInt(e)),r.BigInt(128))}var Q=r.exponentiate(r.BigInt(2),r.BigInt(32)),V=function(){function t(){}return t.getSqrtRatioAtTick=function(e){e>=t.MIN_TICK&&e<=t.MAX_TICK&&Number.isInteger(e)||i(!1);var o=e<0?-1*e:e,u=r.BigInt(0!=(1&o)?"0xfffcb933bd6fad37aa2d162d1a594001":"0x100000000000000000000000000000000");return 0!=(2&o)&&(u=H(u,"0xfff97272373d413259a46990580e213a")),0!=(4&o)&&(u=H(u,"0xfff2e50f5f656932ef12357cf3c7fdcc")),0!=(8&o)&&(u=H(u,"0xffe5caca7e10e4e61c3624eaa0941cd0")),0!=(16&o)&&(u=H(u,"0xffcb9843d60f6159c9db58835c926644")),0!=(32&o)&&(u=H(u,"0xff973b41fa98c081472e6896dfb254c0")),0!=(64&o)&&(u=H(u,"0xff2ea16466c96a3843ec78b326b52861")),0!=(128&o)&&(u=H(u,"0xfe5dee046a99a2a811c461f1969c3053")),0!=(256&o)&&(u=H(u,"0xfcbe86c7900a88aedcffc83b479aa3a4")),0!=(512&o)&&(u=H(u,"0xf987a7253ac413176f2b074cf7815e54")),0!=(1024&o)&&(u=H(u,"0xf3392b0822b70005940c7a398e4b70f3")),0!=(2048&o)&&(u=H(u,"0xe7159475a2c29b7443b29c7fa6e889d9")),0!=(4096&o)&&(u=H(u,"0xd097f3bdfd2022b8845ad8f792aa5825")),0!=(8192&o)&&(u=H(u,"0xa9f746462d870fdf8a65dc1f90e061e5")),0!=(16384&o)&&(u=H(u,"0x70d869a156d2a1b890bb3df62baf32f7")),0!=(32768&o)&&(u=H(u,"0x31be135f97d08fd981231505542fcfa6")),0!=(65536&o)&&(u=H(u,"0x9aa508b5b7a84e1c677de54f3e99bc9")),0!=(131072&o)&&(u=H(u,"0x5d6af8dedb81196699c329225ee604")),0!=(262144&o)&&(u=H(u,"0x2216e584f5fa1ea926041bedfe98")),0!=(524288&o)&&(u=H(u,"0x48a170391f7dc42444e8fa2")),e>0&&(u=r.divide(n.MaxUint256,u)),r.greaterThan(r.remainder(u,Q),S)?r.add(r.divide(u,Q),O):r.divide(u,Q)},t.getTickAtSqrtRatio=function(e){r.greaterThanOrEqual(e,t.MIN_SQRT_RATIO)&&r.lessThan(e,t.MAX_SQRT_RATIO)||i(!1);var n,o=r.leftShift(e,r.BigInt(32)),u=G(o);n=r.greaterThanOrEqual(r.BigInt(u),r.BigInt(128))?r.signedRightShift(o,r.BigInt(u-127)):r.leftShift(o,r.BigInt(127-u));for(var a=r.leftShift(r.subtract(r.BigInt(u),r.BigInt(128)),r.BigInt(64)),c=0;c<14;c++){n=r.signedRightShift(r.multiply(n,n),r.BigInt(127));var s=r.signedRightShift(n,r.BigInt(128));a=r.bitwiseOr(a,r.leftShift(s,r.BigInt(63-c))),n=r.signedRightShift(n,s)}var p=r.multiply(a,r.BigInt("255738958999603826347141")),l=r.toNumber(r.signedRightShift(r.subtract(p,r.BigInt("3402992956809132418596140100660247210")),r.BigInt(128))),d=r.toNumber(r.signedRightShift(r.add(p,r.BigInt("291339464771989622907027621153398088495")),r.BigInt(128)));return l===d?l:r.lessThanOrEqual(t.getSqrtRatioAtTick(d),e)?d:l},t}();function z(t,e,n,r,i,o,u,a,c){return Y.apply(this,arguments)}function Y(){return(Y=g(v().mark((function t(e,n,o,u,a,c,s,p,l){var d,f,h,m,y,k;return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:l||(l=s?r.add(V.MIN_SQRT_RATIO,O):r.subtract(V.MAX_SQRT_RATIO,O)),s?(r.greaterThan(l,V.MIN_SQRT_RATIO)||i(!1),r.lessThan(l,n)||i(!1)):(r.lessThan(l,V.MAX_SQRT_RATIO)||i(!1),r.greaterThan(l,n)||i(!1)),d=r.greaterThanOrEqual(p,S),f={amountSpecifiedRemaining:p,amountCalculated:S,sqrtPriceX96:n,tick:o,liquidity:u};case 4:if(!r.notEqual(f.amountSpecifiedRemaining,S)||f.sqrtPriceX96===l){t.next=35;break}return(h={}).sqrtPriceStartX96=f.sqrtPriceX96,t.next=9,c.nextInitializedTickWithinOneWord(f.tick,s,a);case 9:if(h.tickNext=(m=t.sent)[0],h.initialized=m[1],h.tickNextV.MAX_TICK&&(h.tickNext=V.MAX_TICK),h.sqrtPriceNextX96=V.getSqrtRatioAtTick(h.tickNext),y=D.computeSwapStep(f.sqrtPriceX96,(s?r.lessThan(h.sqrtPriceNextX96,l):r.greaterThan(h.sqrtPriceNextX96,l))?l:h.sqrtPriceNextX96,f.liquidity,f.amountSpecifiedRemaining,e),f.sqrtPriceX96=y[0],h.amountIn=y[1],h.amountOut=y[2],h.feeAmount=y[3],d?(f.amountSpecifiedRemaining=r.subtract(f.amountSpecifiedRemaining,r.add(h.amountIn,h.feeAmount)),f.amountCalculated=r.subtract(f.amountCalculated,h.amountOut)):(f.amountSpecifiedRemaining=r.add(f.amountSpecifiedRemaining,h.amountOut),f.amountCalculated=r.add(f.amountCalculated,r.add(h.amountIn,h.feeAmount))),!r.equal(f.sqrtPriceX96,h.sqrtPriceNextX96)){t.next=32;break}if(!h.initialized){t.next=29;break}return t.t0=r,t.next=25,c.getTick(h.tickNext);case 25:t.t1=t.sent.liquidityNet,k=t.t0.BigInt.call(t.t0,t.t1),s&&(k=r.multiply(k,C)),f.liquidity=j.addDelta(f.liquidity,k);case 29:f.tick=s?h.tickNext-1:h.tickNext,t.next=33;break;case 32:r.notEqual(f.sqrtPriceX96,h.sqrtPriceStartX96)&&(f.tick=V.getTickAtSqrtRatio(f.sqrtPriceX96));case 33:t.next=4;break;case 35:return t.abrupt("return",{amountCalculated:f.amountCalculated,sqrtRatioX96:f.sqrtPriceX96,liquidity:f.liquidity,tickCurrent:f.tick});case 36:case"end":return t.stop()}}),t)})))).apply(this,arguments)}V.MIN_TICK=-887272,V.MAX_TICK=-V.MIN_TICK,V.MIN_SQRT_RATIO=r.BigInt("4295128739"),V.MAX_SQRT_RATIO=r.BigInt("1461446703485210103287273052203988822378723970342");var Z=function(){function t(){}var e=t.prototype;return e.getTick=function(){var e=g(v().mark((function e(n){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error(t.ERROR_MESSAGE);case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.nextInitializedTickWithinOneWord=function(){var e=g(v().mark((function e(n,r,i){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error(t.ERROR_MESSAGE);case 1:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t}();function $(t,e){for(var n=0;n0)return!1;return!0}function J(t,e){return t.index-e.index}Z.ERROR_MESSAGE="No tick data provider was given";var tt=function(){function t(){}return t.validateList=function(t,e){e>0||i(!1),t.every((function(t){return t.index%e==0}))||i(!1),r.equal(t.reduce((function(t,e){return r.add(t,e.liquidityNet)}),S),S)||i(!1),$(t,J)||i(!1)},t.isBelowSmallest=function(t,e){return t.length>0||i(!1),e0||i(!1),e>=t[t.length-1].index},t.getTick=function(t,e){var n=t[this.binarySearch(t,e)];return n.index!==e&&i(!1),n},t.binarySearch=function(t,e){this.isBelowSmallest(t,e)&&i(!1);for(var n,r=0,o=t.length-1;;){if(t[n=Math.floor((r+o)/2)].index<=e&&(n===t.length-1||t[n+1].index>e))return n;t[n].index>8<<8)*i;if(t.isBelowSmallest(e,n))return[u,!1];var a=t.nextInitializedTick(e,n,r).index,c=Math.max(u,a);return[c,c===a]}var s=((1+(o+1>>8)<<8)-1)*i;if(this.isAtOrAboveLargest(e,n))return[s,!1];var p=this.nextInitializedTick(e,n,r).index,l=Math.min(s,p);return[l,l===p]},t}();function et(t){var e=r.BigInt(t).toString(16);return e.length%2!=0&&(e="0"+e),"0x"+e}function nt(t,e){var n=t.pools.reduce((function(t,e,n){var r=t.inputToken,i=t.path,o=t.types,u=e.token0.equals(r)?e.token1:e.token0;return 0===n?{inputToken:u,types:["address","uint24","address"],path:[r.address,e.fee,u.address]}:{inputToken:u,types:[].concat(o,["uint24","address"]),path:[].concat(i,[e.fee,u.address])}}),{inputToken:t.input.wrapped,path:[],types:[]}),r=n.path,i=n.types;return e?a.pack(i.reverse(),r.reverse()):a.pack(i,r)}function rt(t,e){var i=r.leftShift(r.BigInt(t),r.BigInt(192)),o=r.BigInt(e),u=r.divide(i,o);return n.sqrt(u)}function it(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var o=r.divide(r.multiply(t,e),N);return r.divide(r.multiply(r.BigInt(n),o),r.subtract(e,t))}function ot(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var o=r.multiply(r.multiply(r.BigInt(n),t),e),u=r.multiply(N,r.subtract(e,t));return r.divide(o,u)}function ut(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}return r.divide(r.multiply(r.BigInt(n),N),r.subtract(e,t))}function at(t,e,n,i,o,u){if(r.greaterThan(e,n)){var a=[n,e];e=a[0],n=a[1]}var c=u?ot:it;if(r.lessThanOrEqual(t,e))return c(e,n,i);if(r.lessThan(t,n)){var s=c(t,n,i),p=ut(e,t,o);return r.lessThan(s,p)?s:p}return ut(e,n,o)}var ct=r.exponentiate(r.BigInt(2),r.BigInt(128)),st=function(){function t(){}return t.getTokensOwed=function(t,e,n,i,o){return[r.divide(r.multiply(dt(i,t),n),ct),r.divide(r.multiply(dt(o,e),n),ct)]},t}();function pt(t,e,i){var o=V.getSqrtRatioAtTick(i),u=r.multiply(o,o);return t.sortsBefore(e)?new n.Price(t,e,_,u):new n.Price(t,e,u,_)}var lt=r.exponentiate(r.BigInt(2),r.BigInt(256));function dt(t,e){var n=r.subtract(t,e);return r.lessThan(n,S)?r.add(lt,n):n}var ft=function(){function t(){}return t.getFeeGrowthInside=function(t,e,n,r,i,o,u){var a,c,s,p;return i>=n?(a=t.feeGrowthOutside0X128,c=t.feeGrowthOutside1X128):(a=dt(o,t.feeGrowthOutside0X128),c=dt(u,t.feeGrowthOutside1X128)),i=V.MIN_TICK&&e<=V.MAX_TICK||i(!1),this.index=e,this.liquidityGross=r.BigInt(n),this.liquidityNet=r.BigInt(o)},mt=function(){function t(t,e){var n=t.map((function(t){return t instanceof ht?t:new ht(t)}));tt.validateList(n,e),this.ticks=n}var e=t.prototype;return e.getTick=function(){var t=g(v().mark((function t(e){return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",tt.getTick(this.ticks,e));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.nextInitializedTickWithinOneWord=function(){var t=g(v().mark((function t(e,n,r){return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",tt.nextInitializedTickWithinOneWord(this.ticks,e,n,r));case 1:case"end":return t.stop()}}),t,this)})));return function(e,n,r){return t.apply(this,arguments)}}(),t}(),vt=new Z,yt=function(){function t(t,e,n,o,u,a,c){void 0===c&&(c=vt),Number.isInteger(n)&&n<1e6||i(!1);var s=V.getSqrtRatioAtTick(a),p=V.getSqrtRatioAtTick(a+1);r.greaterThanOrEqual(r.BigInt(o),s)&&r.lessThanOrEqual(r.BigInt(o),p)||i(!1);var l=t.sortsBefore(e)?[t,e]:[e,t];this.token0=l[0],this.token1=l[1],this.fee=n,this.sqrtRatioX96=r.BigInt(o),this.liquidity=r.BigInt(u),this.tickCurrent=a,this.tickDataProvider=Array.isArray(c)?new mt(c,P[n]):c}t.getAddress=function(t,e,n,r,i){return F({factoryAddress:null!=i?i:"0x1F98431c8aD98523631AE4a59f267346ea31F984",fee:n,tokenA:t,tokenB:e,initCodeHashManualOverride:r})};var e=t.prototype;return e.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},e.priceOf=function(t){return this.involvesToken(t)||i(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.getOutputAmount=function(){var e=g(v().mark((function e(o,u){var a,c,s,p,l;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.involvesToken(o.currency)||i(!1),a=o.currency.equals(this.token0),e.next=4,this.swap(a,o.quotient,u);case 4:return s=(c=e.sent).sqrtRatioX96,p=c.liquidity,l=c.tickCurrent,e.abrupt("return",[n.CurrencyAmount.fromRawAmount(a?this.token1:this.token0,r.multiply(c.amountCalculated,C)),new t(this.token0,this.token1,this.fee,s,p,l,this.tickDataProvider)]);case 11:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),e.getInputAmount=function(){var e=g(v().mark((function e(o,u){var a,c,s,p,l;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o.currency.isToken&&this.involvesToken(o.currency)||i(!1),a=o.currency.equals(this.token1),e.next=4,this.swap(a,r.multiply(o.quotient,C),u);case 4:return s=(c=e.sent).sqrtRatioX96,p=c.liquidity,l=c.tickCurrent,e.abrupt("return",[n.CurrencyAmount.fromRawAmount(a?this.token0:this.token1,c.amountCalculated),new t(this.token0,this.token1,this.fee,s,p,l,this.tickDataProvider)]);case 11:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),e.swap=function(){var t=g(v().mark((function t(e,n,i){return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",z(r.BigInt(this.fee),this.sqrtRatioX96,this.tickCurrent,this.liquidity,this.tickSpacing,this.tickDataProvider,e,n,i));case 1:case"end":return t.stop()}}),t,this)})));return function(e,n,r){return t.apply(this,arguments)}}(),T(t,[{key:"token0Price",get:function(){var t;return null!=(t=this._token0Price)?t:this._token0Price=new n.Price(this.token0,this.token1,_,r.multiply(this.sqrtRatioX96,this.sqrtRatioX96))}},{key:"token1Price",get:function(){var t;return null!=(t=this._token1Price)?t:this._token1Price=new n.Price(this.token1,this.token0,r.multiply(this.sqrtRatioX96,this.sqrtRatioX96),_)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"tickSpacing",get:function(){return P[this.fee]}}]),t}(),kt=function(){function t(t){var e=t.pool,n=t.liquidity,o=t.tickLower,u=t.tickUpper;this._token0Amount=null,this._token1Amount=null,this._mintAmounts=null,o=V.MIN_TICK&&o%e.tickSpacing==0||i(!1),u<=V.MAX_TICK&&u%e.tickSpacing==0||i(!1),this.pool=e,this.tickLower=o,this.tickUpper=u,this.liquidity=r.BigInt(n)}var e=t.prototype;return e.ratiosAfterSlippage=function(t){var e=this.pool.token0Price.asFraction.multiply(new n.Percent(1).subtract(t)),i=this.pool.token0Price.asFraction.multiply(t.add(1)),o=rt(e.numerator,e.denominator);r.lessThanOrEqual(o,V.MIN_SQRT_RATIO)&&(o=r.add(V.MIN_SQRT_RATIO,r.BigInt(1)));var u=rt(i.numerator,i.denominator);return r.greaterThanOrEqual(u,V.MAX_SQRT_RATIO)&&(u=r.subtract(V.MAX_SQRT_RATIO,r.BigInt(1))),{sqrtRatioX96Lower:o,sqrtRatioX96Upper:u}},e.mintAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,o=new yt(this.pool.token0,this.pool.token1,this.pool.fee,i,0,V.getTickAtSqrtRatio(i)),u=new yt(this.pool.token0,this.pool.token1,this.pool.fee,r,0,V.getTickAtSqrtRatio(r)),a=t.fromAmounts(w({pool:this.pool,tickLower:this.tickLower,tickUpper:this.tickUpper},this.mintAmounts,{useFullPrecision:!1}));return{amount0:new t({pool:u,liquidity:a.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount0,amount1:new t({pool:o,liquidity:a.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount1}},e.burnAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,o=new yt(this.pool.token0,this.pool.token1,this.pool.fee,i,0,V.getTickAtSqrtRatio(i)),u=new t({pool:new yt(this.pool.token0,this.pool.token1,this.pool.fee,r,0,V.getTickAtSqrtRatio(r)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount0,a=new t({pool:o,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount1;return{amount0:u.quotient,amount1:a.quotient}},t.fromAmounts=function(e){var n=e.pool,r=e.tickLower,i=e.tickUpper,o=e.amount0,u=e.amount1,a=e.useFullPrecision,c=V.getSqrtRatioAtTick(r),s=V.getSqrtRatioAtTick(i);return new t({pool:n,tickLower:r,tickUpper:i,liquidity:at(n.sqrtRatioX96,c,s,o,u,a)})},t.fromAmount0=function(e){return t.fromAmounts({pool:e.pool,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0:e.amount0,amount1:n.MaxUint256,useFullPrecision:e.useFullPrecision})},t.fromAmount1=function(e){return t.fromAmounts({pool:e.pool,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0:n.MaxUint256,amount1:e.amount1,useFullPrecision:!0})},T(t,[{key:"token0PriceLower",get:function(){return pt(this.pool.token0,this.pool.token1,this.tickLower)}},{key:"token0PriceUpper",get:function(){return pt(this.pool.token0,this.pool.token1,this.tickUpper)}},{key:"amount0",get:function(){return null===this._token0Amount&&(this._token0Amount=n.CurrencyAmount.fromRawAmount(this.pool.token0,this.pool.tickCurrent0||i(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||i(!1);var o=e.wrapped;t[0].involvesToken(o)||i(!1),t[t.length-1].involvesToken(n.wrapped)||i(!1);for(var u,a=[o],c=I(t.entries());!(u=c()).done;){var s=u.value,p=s[1],l=a[s[0]];l.equals(p.token0)||l.equals(p.token1)||i(!1);var d=l.equals(p.token0)?p.token1:p.token0;a.push(d)}this.pools=t,this.tokenPath=a,this.input=e,this.output=null!=n?n:a[a.length-1]}return T(t,[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;var t=this.pools.slice(1).reduce((function(t,e){var n=t.price;return t.nextInput.equals(e.token0)?{nextInput:e.token1,price:n.multiply(e.token0Price)}:{nextInput:e.token0,price:n.multiply(e.token1Price)}}),this.pools[0].token0.equals(this.input.wrapped)?{nextInput:this.pools[0].token1,price:this.pools[0].token0Price}:{nextInput:this.pools[0].token0,price:this.pools[0].token1Price}).price;return this._midPrice=new n.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function At(t,e){return t.inputAmount.currency.equals(e.inputAmount.currency)||i(!1),t.outputAmount.currency.equals(e.outputAmount.currency)||i(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?t.swaps.reduce((function(t,e){return t+e.route.tokenPath.length}),0)-e.swaps.reduce((function(t,e){return t+e.route.tokenPath.length}),0):t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}var Tt=function(){function t(t){var e=t.routes,n=t.tradeType,r=e[0].inputAmount.currency,o=e[0].outputAmount.currency;e.every((function(t){return r.wrapped.equals(t.route.input.wrapped)}))||i(!1),e.every((function(t){return o.wrapped.equals(t.route.output.wrapped)}))||i(!1);for(var u,a=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),c=new Set,s=I(e);!(u=s()).done;)for(var p,l=I(u.value.route.pools);!(p=l()).done;){var d=p.value;c.add(yt.getAddress(d.token0,d.token1,d.fee))}a!==c.size&&i(!1),this.swaps=e,this.tradeType=n}t.exactIn=function(){var e=g(v().mark((function e(r,i){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.fromRoute(r,i,n.TradeType.EXACT_INPUT));case 1:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.exactOut=function(){var e=g(v().mark((function e(r,i){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.fromRoute(r,i,n.TradeType.EXACT_OUTPUT));case 1:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=g(v().mark((function e(r,o,u){var a,c,s,p,l,d,f;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=new Array(r.tokenPath.length),u!==n.TradeType.EXACT_INPUT){e.next=19;break}o.currency.equals(r.input)||i(!1),a[0]=o.wrapped,p=0;case 5:if(!(p0)){e.next=32;break}return f=r.pools[d-1],e.next=26,f.getInputAmount(a[d]);case 26:a[d-1]=e.sent[0];case 29:d--,e.next=22;break;case 32:c=n.CurrencyAmount.fromFractionalAmount(r.input,a[0].numerator,a[0].denominator),s=n.CurrencyAmount.fromFractionalAmount(r.output,o.numerator,o.denominator);case 34:return e.abrupt("return",new t({routes:[{inputAmount:c,outputAmount:s,route:r}],tradeType:u}));case 35:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.fromRoutes=function(){var e=g(v().mark((function e(r,o){var u,a,c,s,p,l,d,f,h,m,y,k,g;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:u=[],a=I(r);case 2:if((c=a()).done){e.next=43;break}if(p=(s=c.value).route,l=s.amount,d=new Array(p.tokenPath.length),f=void 0,h=void 0,o!==n.TradeType.EXACT_INPUT){e.next=25;break}l.currency.equals(p.input)||i(!1),f=n.CurrencyAmount.fromFractionalAmount(p.input,l.numerator,l.denominator),d[0]=n.CurrencyAmount.fromFractionalAmount(p.input.wrapped,l.numerator,l.denominator),m=0;case 12:if(!(m0)){e.next=39;break}return g=p.pools[k-1],e.next=33,g.getInputAmount(d[k]);case 33:d[k-1]=e.sent[0];case 36:k--,e.next=29;break;case 39:f=n.CurrencyAmount.fromFractionalAmount(p.input,d[0].numerator,d[0].denominator);case 40:u.push({route:p,inputAmount:f,outputAmount:h});case 41:e.next=2;break;case 43:return e.abrupt("return",new t({routes:u,tradeType:o}));case 44:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(w({},e,{routes:[{inputAmount:e.inputAmount,outputAmount:e.outputAmount,route:e.route}]}))},t.createUncheckedTradeWithMultipleRoutes=function(e){return new t(e)};var e=t.prototype;return e.minimumAmountOut=function(t,e){if(void 0===e&&(e=this.outputAmount),t.lessThan(S)&&i(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return e;var r=new n.Fraction(O).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(S)&&i(!1),this.tradeType===n.TradeType.EXACT_INPUT)return e;var r=new n.Fraction(O).add(t).multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var e=g(v().mark((function e(r,o,u,a,c,s,p){var l,d,f,h,m,y,k,g,A,T,w;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:f=void 0===(d=(l=void 0===a?{}:a).maxNumResults)?3:d,m=void 0===(h=l.maxHops)?3:h,void 0===c&&(c=[]),void 0===s&&(s=o),void 0===p&&(p=[]),r.length>0||i(!1),m>0||i(!1),o===s||c.length>0||i(!1),y=s.wrapped,k=u.wrapped,g=0;case 10:if(!(g1&&r.length>1)){e.next=43;break}return w=r.slice(0,g).concat(r.slice(g+1,r.length)),e.next=43,t.bestTradeExactIn(w,o,u,{maxNumResults:f,maxHops:m-1},[].concat(c,[A]),T,p);case 43:g++,e.next=10;break;case 46:return e.abrupt("return",p);case 47:case"end":return e.stop()}}),e,null,[[15,23]])})));return function(t,n,r,i,o,u,a){return e.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var e=g(v().mark((function e(r,o,u,a,c,s,p){var l,d,f,h,m,y,k,g,A,T,w;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:f=void 0===(d=(l=void 0===a?{}:a).maxNumResults)?3:d,m=void 0===(h=l.maxHops)?3:h,void 0===c&&(c=[]),void 0===s&&(s=u),void 0===p&&(p=[]),r.length>0||i(!1),m>0||i(!1),u===s||c.length>0||i(!1),y=s.wrapped,k=o.wrapped,g=0;case 10:if(!(g1&&r.length>1)){e.next=43;break}return w=r.slice(0,g).concat(r.slice(g+1,r.length)),e.next=43,t.bestTradeExactOut(w,o,u,{maxNumResults:f,maxHops:m-1},[A].concat(c),T,p);case 43:g++,e.next=10;break;case 46:return e.abrupt("return",p);case 47:case"end":return e.stop()}}),e,null,[[15,23]])})));return function(t,n,r,i,o,u,a){return e.apply(this,arguments)}}(),T(t,[{key:"route",get:function(){return 1!==this.swaps.length&&i(!1),this.swaps[0].route}},{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),r=I(this.swaps);!(t=r()).done;){var i=t.value;e=e.add(i.route.midPrice.quote(i.inputAmount))}var o=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new n.Percent(o.numerator,o.denominator),this._priceImpact}}]),t}(),wt=function(){function t(){}return t.encodeMulticall=function(e){return Array.isArray(e)||(e=[e]),1===e.length?e[0]:t.INTERFACE.encodeFunctionData("multicall",[e])},t}();wt.INTERFACE=new o.Interface(c.abi);var xt=function(){function t(){}return t.encodePermit=function(e,n){return"nonce"in n?t.INTERFACE.encodeFunctionData("selfPermitAllowed",[e.address,et(n.nonce),et(n.expiry),n.v,n.r,n.s]):t.INTERFACE.encodeFunctionData("selfPermit",[e.address,et(n.amount),et(n.deadline),n.v,n.r,n.s])},t}();xt.INTERFACE=new o.Interface(p.abi);var It=function(){function t(){}return t.encodeFeeBips=function(t){return et(t.multiply(1e4).quotient)},t.encodeUnwrapWETH9=function(e,r,i){if(r=n.validateAndParseAddress(r),i){var o=this.encodeFeeBips(i.fee),u=n.validateAndParseAddress(i.recipient);return t.INTERFACE.encodeFunctionData("unwrapWETH9WithFee",[et(e),r,o,u])}return t.INTERFACE.encodeFunctionData("unwrapWETH9",[et(e),r])},t.encodeSweepToken=function(e,r,i,o){if(i=n.validateAndParseAddress(i),o){var u=this.encodeFeeBips(o.fee),a=n.validateAndParseAddress(o.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee",[e.address,et(r),i,u,a])}return t.INTERFACE.encodeFunctionData("sweepToken",[e.address,et(r),i])},t.encodeRefundETH=function(){return t.INTERFACE.encodeFunctionData("refundETH")},t}();It.INTERFACE=new o.Interface(l.abi);var qt=["expectedCurrencyOwed0","expectedCurrencyOwed1"],bt=et(r.subtract(r.exponentiate(r.BigInt(2),r.BigInt(128)),r.BigInt(1)));function Rt(t){return Object.keys(t).some((function(t){return"recipient"===t}))}var Et=function(){function t(){}return t.encodeCreate=function(e){return t.INTERFACE.encodeFunctionData("createAndInitializePoolIfNecessary",[e.token0.address,e.token1.address,e.fee,et(e.sqrtRatioX96)])},t.createCallParameters=function(t){return{calldata:this.encodeCreate(t),value:et(0)}},t.addCallParameters=function(e,o){r.greaterThan(e.liquidity,S)||i(!1);var u=[],a=e.mintAmounts,c=a.amount0,s=a.amount1,p=e.mintAmountsWithSlippage(o.slippageTolerance),l=et(p.amount0),d=et(p.amount1),f=et(o.deadline);if(Rt(o)&&o.createPool&&u.push(this.encodeCreate(e.pool)),o.token0Permit&&u.push(xt.encodePermit(e.pool.token0,o.token0Permit)),o.token1Permit&&u.push(xt.encodePermit(e.pool.token1,o.token1Permit)),Rt(o)){var h=n.validateAndParseAddress(o.recipient);u.push(t.INTERFACE.encodeFunctionData("mint",[{token0:e.pool.token0.address,token1:e.pool.token1.address,fee:e.pool.fee,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0Desired:et(c),amount1Desired:et(s),amount0Min:l,amount1Min:d,recipient:h,deadline:f}]))}else u.push(t.INTERFACE.encodeFunctionData("increaseLiquidity",[{tokenId:et(o.tokenId),amount0Desired:et(c),amount1Desired:et(s),amount0Min:l,amount1Min:d,deadline:f}]));var m=et(0);if(o.useNative){var v=o.useNative.wrapped;e.pool.token0.equals(v)||e.pool.token1.equals(v)||i(!1);var y=e.pool.token0.equals(v)?c:s;r.greaterThan(y,S)&&u.push(It.encodeRefundETH()),m=et(y)}return{calldata:wt.encodeMulticall(u),value:m}},t.encodeCollect=function(e){var r=[],i=et(e.tokenId),o=e.expectedCurrencyOwed0.currency.isNative||e.expectedCurrencyOwed1.currency.isNative,u=n.validateAndParseAddress(e.recipient);if(r.push(t.INTERFACE.encodeFunctionData("collect",[{tokenId:i,recipient:o?b:u,amount0Max:bt,amount1Max:bt}])),o){var a=e.expectedCurrencyOwed0.currency.isNative?e.expectedCurrencyOwed1.currency:e.expectedCurrencyOwed0.currency,c=e.expectedCurrencyOwed0.currency.isNative?e.expectedCurrencyOwed1.quotient:e.expectedCurrencyOwed0.quotient;r.push(It.encodeUnwrapWETH9(e.expectedCurrencyOwed0.currency.isNative?e.expectedCurrencyOwed0.quotient:e.expectedCurrencyOwed1.quotient,u)),r.push(It.encodeSweepToken(a,c,u))}return r},t.collectCallParameters=function(e){var n=t.encodeCollect(e);return{calldata:wt.encodeMulticall(n),value:et(0)}},t.removeCallParameters=function(e,o){var u=[],a=et(o.deadline),c=et(o.tokenId),s=new kt({pool:e.pool,liquidity:o.liquidityPercentage.multiply(e.liquidity).quotient,tickLower:e.tickLower,tickUpper:e.tickUpper});r.greaterThan(s.liquidity,S)||i(!1);var p=s.burnAmountsWithSlippage(o.slippageTolerance),l=p.amount0,d=p.amount1;o.permit&&u.push(t.INTERFACE.encodeFunctionData("permit",[n.validateAndParseAddress(o.permit.spender),c,et(o.permit.deadline),o.permit.v,o.permit.r,o.permit.s])),u.push(t.INTERFACE.encodeFunctionData("decreaseLiquidity",[{tokenId:c,liquidity:et(s.liquidity),amount0Min:et(l),amount1Min:et(d),deadline:a}]));var f=o.collectOptions,h=f.expectedCurrencyOwed0,m=f.expectedCurrencyOwed1,v=function(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r=0||(i[n]=t[n]);return i}(f,qt);return u.push.apply(u,t.encodeCollect(w({tokenId:et(o.tokenId),expectedCurrencyOwed0:h.add(n.CurrencyAmount.fromRawAmount(h.currency,l)),expectedCurrencyOwed1:m.add(n.CurrencyAmount.fromRawAmount(m.currency,d))},v))),o.liquidityPercentage.equalTo(O)?o.burnToken&&u.push(t.INTERFACE.encodeFunctionData("burn",[c])):!0===o.burnToken&&i(!1),{calldata:wt.encodeMulticall(u),value:et(0)}},t.safeTransferFromParameters=function(e){var r=n.validateAndParseAddress(e.recipient),i=n.validateAndParseAddress(e.sender);return{calldata:e.data?t.INTERFACE.encodeFunctionData("safeTransferFrom(address,address,uint256,bytes)",[i,r,et(e.tokenId),e.data]):t.INTERFACE.encodeFunctionData("safeTransferFrom(address,address,uint256)",[i,r,et(e.tokenId)]),value:et(0)}},t}();Et.INTERFACE=new o.Interface(s.abi);var Pt=function(){function t(){}return t.quoteCallParameters=function(t,e,r,o){void 0===o&&(o={});var u,a=1===t.pools.length,c=et(e.quotient),s=o.useQuoterV2?this.V2INTERFACE:this.V1INTERFACE;if(a){var p,l,d={tokenIn:t.tokenPath[0].address,tokenOut:t.tokenPath[1].address,fee:t.pools[0].fee,sqrtPriceLimitX96:et(null!=(p=null==(l=o)?void 0:l.sqrtPriceLimitX96)?p:0)},f=w({},d,r===n.TradeType.EXACT_INPUT?{amountIn:c}:{amount:c});u=s.encodeFunctionData(r===n.TradeType.EXACT_INPUT?"quoteExactInputSingle":"quoteExactOutputSingle",o.useQuoterV2?[f]:[d.tokenIn,d.tokenOut,d.fee,c,d.sqrtPriceLimitX96])}else{var h;void 0!==(null==(h=o)?void 0:h.sqrtPriceLimitX96)&&i(!1);var m=nt(t,r===n.TradeType.EXACT_OUTPUT);u=s.encodeFunctionData(r===n.TradeType.EXACT_INPUT?"quoteExactInput":"quoteExactOutput",[m,c])}return{calldata:u,value:et(0)}},t}();Pt.V1INTERFACE=new o.Interface(d.abi),Pt.V2INTERFACE=new o.Interface(f.abi);var Ct=function(){function t(){}return t.encodeClaim=function(e,r){var i,o=[];o.push(t.INTERFACE.encodeFunctionData("unstakeToken",[this._encodeIncentiveKey(e),et(r.tokenId)]));var u=n.validateAndParseAddress(r.recipient),a=null!=(i=r.amount)?i:0;return o.push(t.INTERFACE.encodeFunctionData("claimReward",[e.rewardToken.address,u,et(a)])),o},t.collectRewards=function(e,n){e=Array.isArray(e)?e:[e];for(var r=[],i=0;i1){for(var r=[],i=0;i0||i(!1),t>=V.MIN_TICK&&t<=V.MAX_TICK||i(!1);var n=Math.round(t/e)*e;return nV.MAX_TICK?n-e:n},exports.poolInitCodeHash=E,exports.priceToClosestTick=function(t){var e=t.baseCurrency.sortsBefore(t.quoteCurrency),n=e?rt(t.numerator,t.denominator):rt(t.denominator,t.numerator),r=V.getTickAtSqrtRatio(n),i=pt(t.baseCurrency,t.quoteCurrency,r+1);return e?t.lessThan(i)||r++:t.greaterThan(i)||r++,r},exports.subIn256=dt,exports.tickToPrice=pt,exports.toHex=et,exports.tradeComparator=At,exports.v3Swap=z; + //# sourceMappingURL=v3-sdk.cjs.production.min.js.map +diff --git a/node_modules/@uniswap/v3-sdk/dist/v3-sdk.esm.js b/node_modules/@uniswap/v3-sdk/dist/v3-sdk.esm.js +index f1c2a42..9475d20 100644 +--- a/node_modules/@uniswap/v3-sdk/dist/v3-sdk.esm.js ++++ b/node_modules/@uniswap/v3-sdk/dist/v3-sdk.esm.js +@@ -3095,7 +3095,6 @@ var SwapRouter = /*#__PURE__*/function () { + calldatas.push(SelfPermit.encodePermit(sampleTrade.inputAmount.currency, options.inputTokenPermit)); + } + var recipient = validateAndParseAddress(options.recipient); +- var deadline = toHex(options.deadline); + for (var _iterator = _createForOfIteratorHelperLoose(trades), _step; !(_step = _iterator()).done;) { + var trade = _step.value; + for (var _iterator2 = _createForOfIteratorHelperLoose(trade.swaps), _step2; !(_step2 = _iterator2()).done;) { +@@ -3115,7 +3114,6 @@ var SwapRouter = /*#__PURE__*/function () { + tokenOut: route.tokenPath[1].address, + fee: route.pools[0].fee, + recipient: routerMustCustody ? ADDRESS_ZERO : recipient, +- deadline: deadline, + amountIn: amountIn, + amountOutMinimum: amountOut, + sqrtPriceLimitX96: toHex((_options$sqrtPriceLim = options.sqrtPriceLimitX96) != null ? _options$sqrtPriceLim : 0) +@@ -3128,7 +3126,6 @@ var SwapRouter = /*#__PURE__*/function () { + tokenOut: route.tokenPath[1].address, + fee: route.pools[0].fee, + recipient: routerMustCustody ? ADDRESS_ZERO : recipient, +- deadline: deadline, + amountOut: amountOut, + amountInMaximum: amountIn, + sqrtPriceLimitX96: toHex((_options$sqrtPriceLim2 = options.sqrtPriceLimitX96) != null ? _options$sqrtPriceLim2 : 0) +@@ -3142,7 +3139,6 @@ var SwapRouter = /*#__PURE__*/function () { + var exactInputParams = { + path: path, + recipient: routerMustCustody ? ADDRESS_ZERO : recipient, +- deadline: deadline, + amountIn: amountIn, + amountOutMinimum: amountOut + }; +@@ -3151,7 +3147,6 @@ var SwapRouter = /*#__PURE__*/function () { + var exactOutputParams = { + path: path, + recipient: routerMustCustody ? ADDRESS_ZERO : recipient, +- deadline: deadline, + amountOut: amountOut, + amountInMaximum: amountIn + }; diff --git a/yarn.lock b/yarn.lock index 3bb16c023e..99d42130f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8429,7 +8429,7 @@ __metadata: languageName: node linkType: hard -"@uniswap/v3-periphery@npm:^1.0.1, @uniswap/v3-periphery@npm:^1.1.1, @uniswap/v3-periphery@npm:^1.4.4": +"@uniswap/v3-periphery@npm:1.4.4": version: 1.4.4 resolution: "@uniswap/v3-periphery@npm:1.4.4" dependencies: