{"version":3,"sources":["../src/constants.ts","../src/entities/pair.ts","../src/entities/route.ts","../src/entities/trade.ts","../src/abis/IPancakePair.ts","../src/router.ts","../src/fetcher.ts","../src/trade.ts"],"names":["ChainId","invariant","Price","output","ONE","ZERO","CurrencyAmount","TradeType","Token"],"mappings":";AAAA,SAAS,eAAe;AAGjB,IAAM,kBAAkB;AAE/B,IAAM,sBAAsB;AAErB,IAAM,sBAAsB;AAAA,EACjC,CAAC,QAAQ,QAAQ,GAAG;AAAA,EACpB,CAAC,QAAQ,MAAM,GAAG;AAAA,EAClB,CAAC,QAAQ,GAAG,GAAG;AAAA,EACf,CAAC,QAAQ,WAAW,GAAG;AAAA,EACvB,CAAC,QAAQ,YAAY,GAAG;AAAA,EACxB,CAAC,QAAQ,eAAe,GAAG;AAAA,EAC3B,CAAC,QAAQ,MAAM,GAAG;AAAA,EAClB,CAAC,QAAQ,cAAc,GAAG;AAAA,EAC1B,CAAC,QAAQ,KAAK,GAAG;AAAA,EACjB,CAAC,QAAQ,aAAa,GAAG;AAAA,EACzB,CAAC,QAAQ,KAAK,GAAG;AAAA,EACjB,CAAC,QAAQ,aAAa,GAAG;AAAA,EACzB,CAAC,QAAQ,IAAI,GAAG;AAAA,EAChB,CAAC,QAAQ,YAAY,GAAG;AAAA,EACxB,CAAC,QAAQ,cAAc,GAAG;AAAA,EAC1B,CAAC,QAAQ,OAAO,GAAG;AAAA,EACnB,CAAC,QAAQ,gBAAgB,GAAG;AAAA,EAC5B,CAAC,QAAQ,YAAY,GAAG;AAAA,EACxB,CAAC,QAAQ,aAAa,GAAG;AAAA,EACzB,CAAC,QAAQ,aAAa,GAAG;AAC3B;AAEO,IAAM,iBAAiB;AAE9B,IAAM,qBAAqB;AACpB,IAAM,qBAAqB;AAAA,EAChC,CAAC,QAAQ,QAAQ,GAAG;AAAA,EACpB,CAAC,QAAQ,MAAM,GAAG;AAAA,EAClB,CAAC,QAAQ,GAAG,GAAG;AAAA,EACf,CAAC,QAAQ,WAAW,GA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AK3C,SAAS,cACd,QACA,QACA,eAAwB,cACH;AACrB,MAAI,UAAU,CAAC;AAAQ,WAAO;AAC9B,MAAI,UAAU,CAAC;AAAQ,WAAO;AAC9B,MAAI,CAAC,UAAU,CAAC;AAAQ,WAAO;AAE/B,MACE,OAAO,cAAc,OAAO,aAC5B,CAAC,OAAO,YAAY,SAAS,OAAO,OAAO,YAAY,QAAQ,KAC/D,CAAC,OAAO,aAAa,SAAS,OAAO,OAAO,aAAa,QAAQ,GACjE;AACA,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AAEA,MAAI,aAAa,QAAQ,YAAY,GAAG;AACtC,WAAO,OAAO,eAAe,SAAS,OAAO,cAAc;AAAA,EAC7D;AACA,SAAO,OAAO,eAAe,WAC1B,SAAS,aAAa,IAAI,mBAAmB,CAAC,EAC9C,SAAS,OAAO,cAAc;AACnC","sourcesContent":["import { ChainId } from '@pancakeswap/chains'\nimport type { Address, Hash } from 'viem'\n\nexport const FACTORY_ADDRESS = '0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73'\n\nconst FACTORY_ADDRESS_ETH = '0x1097053Fd2ea711dad45caCcc45EfF7548fCB362'\n\nexport const FACTORY_ADDRESS_MAP = {\n  [ChainId.ETHEREUM]: FACTORY_ADDRESS_ETH,\n  [ChainId.GOERLI]: FACTORY_ADDRESS_ETH,\n  [ChainId.BSC]: FACTORY_ADDRESS,\n  [ChainId.BSC_TESTNET]: '0x6725F303b657a9451d8BA641348b6761A6CC7a17',\n  [ChainId.ARBITRUM_ONE]: '0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E',\n  [ChainId.ARBITRUM_GOERLI]: '0x333EAE459075b1d7dE8eb57997b5d4eee5F1070a',\n  [ChainId.ZKSYNC]: '0xd03D8D566183F0086d8D09A84E1e30b58Dd5619d',\n  [ChainId.ZKSYNC_TESTNET]: '0x48a33610Cd0E130af2024D55F67aE72a8C51aC27',\n  [ChainId.LINEA]: '0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E',\n  [ChainId.LINEA_TESTNET]: '0xB6FAfd4ADbCd21cF665909767e0eD0D05709abfB',\n  [ChainId.OPBNB]: '0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E',\n  [ChainId.OPBNB_TESTNET]: '0x776e4bD2f72de2176A59465e316335aaf8ed4E8F',\n  [ChainId.BASE]: '0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E',\n  [ChainId.BASE_TESTNET]: '0x715303D2eF7dA7FFAbF637651D71FD11d41fAf7F',\n  [ChainId.SCROLL_SEPOLIA]: '0x2B3C5df29F73dbF028BA82C33e0A5A6e5800F75e',\n  [ChainId.SEPOLIA]: '0x1bdc540dEB9Ed1fA29964DeEcCc524A8f5e2198e',\n  [ChainId.ARBITRUM_SEPOLIA]: '0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E',\n  [ChainId.BASE_SEPOLIA]: '0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E',\n  [ChainId.MONAD_MAINNET]: '0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E',\n  [ChainId.MONAD_TESTNET]: '0x82438CE666d9403e488bA720c7424434e8Aa47CD',\n} as const satisfies Record<ChainId, Address>\n\nexport const INIT_CODE_HASH = '0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5'\n\nconst INIT_CODE_HASH_ETH = '0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d'\nexport const INIT_CODE_HASH_MAP = {\n  [ChainId.ETHEREUM]: INIT_CODE_HASH_ETH,\n  [ChainId.GOERLI]: INIT_CODE_HASH_ETH,\n  [ChainId.BSC]: INIT_CODE_HASH,\n  [ChainId.BSC_TESTNET]: '0xd0d4c4cd0848c93cb4fd1f498d7013ee6bfb25783ea21593d5834f5d250ece66',\n  [ChainId.ARBITRUM_ONE]: INIT_CODE_HASH_ETH,\n  [ChainId.ARBITRUM_GOERLI]: INIT_CODE_HASH_ETH,\n  [ChainId.ZKSYNC]: '0x0100045707a42494392b3558029b9869f865ff9df8f375dc1bf20b0555093f43',\n  [ChainId.ZKSYNC_TESTNET]: '0x0100045707a42494392b3558029b9869f865ff9df8f375dc1bf20b0555093f43',\n  [ChainId.LINEA]: INIT_CODE_HASH_ETH,\n  [ChainId.LINEA_TESTNET]: INIT_CODE_HASH_ETH,\n  [ChainId.OPBNB]: INIT_CODE_HASH_ETH,\n  [ChainId.OPBNB_TESTNET]: INIT_CODE_HASH_ETH,\n  [ChainId.BASE]: INIT_CODE_HASH_ETH,\n  [ChainId.BASE_TESTNET]: '0xa5934690703a592a07e841ca29d5e5c79b5e22ed4749057bb216dc31100be1c0',\n  [ChainId.SCROLL_SEPOLIA]: INIT_CODE_HASH_ETH,\n  [ChainId.SEPOLIA]: INIT_CODE_HASH_ETH,\n  [ChainId.ARBITRUM_SEPOLIA]: INIT_CODE_HASH_ETH,\n  [ChainId.BASE_SEPOLIA]: INIT_CODE_HASH_ETH,\n  [ChainId.MONAD_MAINNET]: INIT_CODE_HASH_ETH,\n  [ChainId.MONAD_TESTNET]: '0xa5934690703a592a07e841ca29d5e5c79b5e22ed4749057bb216dc31100be1c0',\n} as const satisfies Record<ChainId, Hash>\n","import { ChainId } from '@pancakeswap/chains'\nimport {\n  _10000,\n  _9975,\n  BigintIsh,\n  CurrencyAmount,\n  FIVE,\n  InsufficientInputAmountError,\n  InsufficientReservesError,\n  MINIMUM_LIQUIDITY,\n  ONE,\n  Price,\n  sqrt,\n  ZERO,\n} from '@pancakeswap/swap-sdk-core'\nimport { ERC20Token } from '@pancakeswap/swap-sdk-evm'\nimport invariant from 'tiny-invariant'\nimport {\n  Address,\n  ByteArray,\n  concat,\n  encodePacked,\n  getAddress,\n  GetCreate2AddressOptions,\n  Hex,\n  isBytes,\n  keccak256,\n  pad,\n  slice,\n  toBytes,\n} from 'viem'\n\nimport { FACTORY_ADDRESS_MAP, INIT_CODE_HASH_MAP } from '../constants'\n\nlet PAIR_ADDRESS_CACHE: { [key: string]: Address } = {}\n\nconst composeKey = (token0: ERC20Token, token1: ERC20Token) => `${token0.chainId}-${token0.address}-${token1.address}`\n\nfunction getCreate2Address(\n  from_: GetCreate2AddressOptions['from'],\n  salt_: GetCreate2AddressOptions['salt'],\n  initCodeHash: Hex,\n) {\n  const from = toBytes(getAddress(from_))\n  const salt = pad(isBytes(salt_) ? salt_ : toBytes(salt_ as Hex), {\n    size: 32,\n  }) as ByteArray\n\n  return getAddress(slice(keccak256(concat([toBytes('0xff'), from, salt, toBytes(initCodeHash)])), 12))\n}\n\nconst EMPTY_INPU_HASH = '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'\nconst ZKSYNC_PREFIX = '0x2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494' // keccak256('zksyncCreate2')\n\nfunction getCreate2AddressZkSync(from: Address, salt: `0x${string}`, initCodeHash: `0x${string}`): `0x${string}` {\n  return getAddress(\n    `0x${keccak256(concat([ZKSYNC_PREFIX, pad(from, { size: 32 }), salt, initCodeHash, EMPTY_INPU_HASH])).slice(26)}`,\n  )\n}\n\nexport const computePairAddress = ({\n  factoryAddress,\n  tokenA,\n  tokenB,\n}: {\n  factoryAddress: Address\n  tokenA: ERC20Token\n  tokenB: ERC20Token\n}): Address => {\n  const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks\n  const key = composeKey(token0, token1)\n\n  if (PAIR_ADDRESS_CACHE?.[key] === undefined) {\n    const getCreate2Address_ =\n      token0.chainId === ChainId.ZKSYNC_TESTNET || token1.chainId === ChainId.ZKSYNC\n        ? getCreate2AddressZkSync\n        : getCreate2Address\n    PAIR_ADDRESS_CACHE = {\n      ...PAIR_ADDRESS_CACHE,\n      [key]: getCreate2Address_(\n        factoryAddress,\n        keccak256(encodePacked(['address', 'address'], [token0.address, token1.address])),\n        INIT_CODE_HASH_MAP[token0.chainId as keyof typeof INIT_CODE_HASH_MAP],\n      ),\n    }\n  }\n\n  return PAIR_ADDRESS_CACHE[key]\n}\n\nexport class Pair {\n  public readonly liquidityToken: ERC20Token\n\n  private readonly tokenAmounts: [CurrencyAmount<ERC20Token>, CurrencyAmount<ERC20Token>]\n\n  public static getAddress(tokenA: ERC20Token, tokenB: ERC20Token): Address {\n    return computePairAddress({\n      factoryAddress: FACTORY_ADDRESS_MAP[tokenA.chainId as keyof typeof FACTORY_ADDRESS_MAP],\n      tokenA,\n      tokenB,\n    })\n  }\n\n  public constructor(currencyAmountA: CurrencyAmount<ERC20Token>, tokenAmountB: CurrencyAmount<ERC20Token>) {\n    const tokenAmounts = currencyAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks\n      ? [currencyAmountA, tokenAmountB]\n      : [tokenAmountB, currencyAmountA]\n    this.liquidityToken = new ERC20Token(\n      tokenAmounts[0].currency.chainId,\n      Pair.getAddress(tokenAmounts[0].currency, tokenAmounts[1].currency),\n      18,\n      'Cake-LP',\n      'Pancake LPs',\n    )\n    this.tokenAmounts = tokenAmounts as [CurrencyAmount<ERC20Token>, CurrencyAmount<ERC20Token>]\n  }\n\n  /**\n   * Returns true if the token is either token0 or token1\n   * @param token to check\n   */\n  public involvesToken(token: ERC20Token): boolean {\n    return token.equals(this.token0) || token.equals(this.token1)\n  }\n\n  /**\n   * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0\n   */\n  public get token0Price(): Price<ERC20Token, ERC20Token> {\n    const result = this.tokenAmounts[1].divide(this.tokenAmounts[0])\n    return new Price(this.token0, this.token1, result.denominator, result.numerator)\n  }\n\n  /**\n   * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1\n   */\n  public get token1Price(): Price<ERC20Token, ERC20Token> {\n    const result = this.tokenAmounts[0].divide(this.tokenAmounts[1])\n    return new Price(this.token1, this.token0, result.denominator, result.numerator)\n  }\n\n  /**\n   * Return the price of the given token in terms of the other token in the pair.\n   * @param token token to return price of\n   */\n  public priceOf(token: ERC20Token): Price<ERC20Token, ERC20Token> {\n    invariant(this.involvesToken(token), 'TOKEN')\n    return token.equals(this.token0) ? this.token0Price : this.token1Price\n  }\n\n  /**\n   * Returns the chain ID of the tokens in the pair.\n   */\n  public get chainId(): number {\n    return this.token0.chainId\n  }\n\n  public get token0(): ERC20Token {\n    return this.tokenAmounts[0].currency\n  }\n\n  public get token1(): ERC20Token {\n    return this.tokenAmounts[1].currency\n  }\n\n  public get reserve0(): CurrencyAmount<ERC20Token> {\n    return this.tokenAmounts[0]\n  }\n\n  public get reserve1(): CurrencyAmount<ERC20Token> {\n    return this.tokenAmounts[1]\n  }\n\n  public reserveOf(token: ERC20Token): CurrencyAmount<ERC20Token> {\n    invariant(this.involvesToken(token), 'TOKEN')\n    return token.equals(this.token0) ? this.reserve0 : this.reserve1\n  }\n\n  public getOutputAmount(inputAmount: CurrencyAmount<ERC20Token>): [CurrencyAmount<ERC20Token>, Pair] {\n    invariant(this.involvesToken(inputAmount.currency), 'TOKEN')\n    if (this.reserve0.quotient === ZERO || this.reserve1.quotient === ZERO) {\n      throw new InsufficientReservesError()\n    }\n    const inputReserve = this.reserveOf(inputAmount.currency)\n    const outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0)\n    const inputAmountWithFee = inputAmount.quotient * _9975\n    const numerator = inputAmountWithFee * outputReserve.quotient\n    const denominator = inputReserve.quotient * _10000 + inputAmountWithFee\n    const outputAmount = CurrencyAmount.fromRawAmount(\n      inputAmount.currency.equals(this.token0) ? this.token1 : this.token0,\n      numerator / denominator,\n    )\n    if (outputAmount.quotient === ZERO) {\n      throw new InsufficientInputAmountError()\n    }\n    return [outputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]\n  }\n\n  public getInputAmount(outputAmount: CurrencyAmount<ERC20Token>): [CurrencyAmount<ERC20Token>, Pair] {\n    invariant(this.involvesToken(outputAmount.currency), 'TOKEN')\n    if (\n      this.reserve0.quotient === ZERO ||\n      this.reserve1.quotient === ZERO ||\n      outputAmount.quotient >= this.reserveOf(outputAmount.currency).quotient\n    ) {\n      throw new InsufficientReservesError()\n    }\n\n    const outputReserve = this.reserveOf(outputAmount.currency)\n    const inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0)\n    const numerator = inputReserve.quotient * outputAmount.quotient * _10000\n    const denominator = (outputReserve.quotient - outputAmount.quotient) * _9975\n    const inputAmount = CurrencyAmount.fromRawAmount(\n      outputAmount.currency.equals(this.token0) ? this.token1 : this.token0,\n      numerator / denominator + ONE,\n    )\n    return [inputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]\n  }\n\n  public getLiquidityMinted(\n    totalSupply: CurrencyAmount<ERC20Token>,\n    tokenAmountA: CurrencyAmount<ERC20Token>,\n    tokenAmountB: CurrencyAmount<ERC20Token>,\n  ): CurrencyAmount<ERC20Token> {\n    invariant(totalSupply.currency.equals(this.liquidityToken), 'LIQUIDITY')\n    const tokenAmounts = tokenAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks\n      ? [tokenAmountA, tokenAmountB]\n      : [tokenAmountB, tokenAmountA]\n    invariant(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1), 'TOKEN')\n\n    let liquidity: bigint\n    if (totalSupply.quotient === ZERO) {\n      liquidity = sqrt(tokenAmounts[0].quotient * tokenAmounts[1].quotient) - MINIMUM_LIQUIDITY\n    } else {\n      const amount0 = (tokenAmounts[0].quotient * totalSupply.quotient) / this.reserve0.quotient\n      const amount1 = (tokenAmounts[1].quotient * totalSupply.quotient) / this.reserve1.quotient\n      liquidity = amount0 <= amount1 ? amount0 : amount1\n    }\n    if (!(liquidity > ZERO)) {\n      throw new InsufficientInputAmountError()\n    }\n    return CurrencyAmount.fromRawAmount(this.liquidityToken, liquidity)\n  }\n\n  public getLiquidityValue(\n    token: ERC20Token,\n    totalSupply: CurrencyAmount<ERC20Token>,\n    liquidity: CurrencyAmount<ERC20Token>,\n    feeOn = false,\n    kLast?: BigintIsh,\n  ): CurrencyAmount<ERC20Token> {\n    invariant(this.involvesToken(token), 'TOKEN')\n    invariant(totalSupply.currency.equals(this.liquidityToken), 'TOTAL_SUPPLY')\n    invariant(liquidity.currency.equals(this.liquidityToken), 'LIQUIDITY')\n    invariant(liquidity.quotient <= totalSupply.quotient, 'LIQUIDITY')\n\n    let totalSupplyAdjusted: CurrencyAmount<ERC20Token>\n    if (!feeOn) {\n      totalSupplyAdjusted = totalSupply\n    } else {\n      invariant(!!kLast, 'K_LAST')\n      const kLastParsed = BigInt(kLast)\n      if (!(kLastParsed === ZERO)) {\n        const rootK = sqrt(this.reserve0.quotient * this.reserve1.quotient)\n        const rootKLast = sqrt(kLastParsed)\n        if (rootK > rootKLast) {\n          const numerator = totalSupply.quotient * (rootK - rootKLast)\n          const denominator = rootK * FIVE + rootKLast\n          const feeLiquidity = numerator / denominator\n          totalSupplyAdjusted = totalSupply.add(CurrencyAmount.fromRawAmount(this.liquidityToken, feeLiquidity))\n        } else {\n          totalSupplyAdjusted = totalSupply\n        }\n      } else {\n        totalSupplyAdjusted = totalSupply\n      }\n    }\n\n    if (totalSupply.equalTo(0)) {\n      return CurrencyAmount.fromRawAmount(token, 0)\n    }\n\n    return CurrencyAmount.fromRawAmount(\n      token,\n      (liquidity.quotient * this.reserveOf(token).quotient) / totalSupplyAdjusted.quotient,\n    )\n  }\n}\n","import invariant from 'tiny-invariant'\nimport { Token, Currency, Price } from '@pancakeswap/swap-sdk-core'\n\nimport { Pair } from './pair'\n\nexport class Route<TInput extends Currency, TOutput extends Currency> {\n  public readonly pairs: Pair[]\n\n  public readonly path: Token[]\n\n  public readonly input: TInput\n\n  public readonly output: TOutput\n\n  public constructor(pairs: Pair[], input: TInput, output: TOutput) {\n    invariant(pairs.length > 0, 'PAIRS')\n    const { chainId } = pairs[0]\n    invariant(\n      pairs.every((pair) => pair.chainId === chainId),\n      'CHAIN_IDS',\n    )\n\n    const wrappedInput = input.wrapped\n    invariant(pairs[0].involvesToken(wrappedInput), 'INPUT')\n    invariant(typeof output === 'undefined' || pairs[pairs.length - 1].involvesToken(output.wrapped), 'OUTPUT')\n\n    const path: Token[] = [wrappedInput]\n    for (const [i, pair] of pairs.entries()) {\n      const currentInput = path[i]\n      invariant(currentInput.equals(pair.token0) || currentInput.equals(pair.token1), 'PATH')\n      // eslint-disable-next-line @typescript-eslint/no-shadow\n      const output = currentInput.equals(pair.token0) ? pair.token1 : pair.token0\n      path.push(output)\n    }\n\n    this.pairs = pairs\n    this.path = path\n    this.input = input\n    this.output = output\n  }\n\n  private _midPrice: Price<TInput, TOutput> | null = null\n\n  public get midPrice(): Price<TInput, TOutput> {\n    if (this._midPrice !== null) return this._midPrice\n    const prices: Price<Currency, Currency>[] = []\n    for (const [i, pair] of this.pairs.entries()) {\n      prices.push(\n        this.path[i].equals(pair.token0)\n          ? new Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.quotient, pair.reserve1.quotient)\n          : new Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.quotient, pair.reserve0.quotient),\n      )\n    }\n    const reduced = prices.slice(1).reduce((accumulator, currentValue) => accumulator.multiply(currentValue), prices[0])\n    // eslint-disable-next-line no-return-assign\n    return (this._midPrice = new Price(this.input, this.output, reduced.denominator, reduced.numerator))\n  }\n\n  public get chainId(): number {\n    return this.pairs[0].chainId\n  }\n}\n","import invariant from 'tiny-invariant'\nimport {\n  InsufficientInputAmountError,\n  InsufficientReservesError,\n  ONE,\n  TradeType,\n  ZERO,\n  CurrencyAmount,\n  Currency,\n  Fraction,\n  Percent,\n  Price,\n  Token,\n  sortedInsert,\n  computePriceImpact,\n} from '@pancakeswap/swap-sdk-core'\n\nimport { Pair } from './pair'\nimport { Route } from './route'\n\n// minimal interface so the input output comparator may be shared across types\ninterface InputOutput<TInput extends Currency, TOutput extends Currency> {\n  readonly inputAmount: CurrencyAmount<TInput>\n  readonly outputAmount: CurrencyAmount<TOutput>\n}\n\n// comparator function that allows sorting trades by their output amounts, in decreasing order, and then input amounts\n// in increasing order. i.e. the best trades have the most outputs for the least inputs and are sorted first\nexport function inputOutputComparator<TInput extends Currency, TOutput extends Currency>(\n  a: InputOutput<TInput, TOutput>,\n  b: InputOutput<TInput, TOutput>,\n): number {\n  // must have same input and output token for comparison\n  invariant(a.inputAmount.currency.equals(b.inputAmount.currency), 'INPUT_CURRENCY')\n  invariant(a.outputAmount.currency.equals(b.outputAmount.currency), 'OUTPUT_CURRENCY')\n  if (a.outputAmount.equalTo(b.outputAmount)) {\n    if (a.inputAmount.equalTo(b.inputAmount)) {\n      return 0\n    }\n    // trade A requires less input than trade B, so A should come first\n    if (a.inputAmount.lessThan(b.inputAmount)) {\n      return -1\n    }\n    return 1\n  }\n  // tradeA has less output than trade B, so should come second\n  if (a.outputAmount.lessThan(b.outputAmount)) {\n    return 1\n  }\n  return -1\n}\n\n// extension of the input output comparator that also considers other dimensions of the trade in ranking them\nexport function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(\n  a: Trade<TInput, TOutput, TTradeType>,\n  b: Trade<TInput, TOutput, TTradeType>,\n) {\n  const ioComp = inputOutputComparator(a, b)\n  if (ioComp !== 0) {\n    return ioComp\n  }\n\n  // consider lowest slippage next, since these are less likely to fail\n  if (a.priceImpact.lessThan(b.priceImpact)) {\n    return -1\n  }\n  if (a.priceImpact.greaterThan(b.priceImpact)) {\n    return 1\n  }\n\n  // finally consider the number of hops since each hop costs gas\n  return a.route.path.length - b.route.path.length\n}\n\nexport interface BestTradeOptions {\n  // how many results to return\n  maxNumResults?: number\n  // the maximum number of hops a trade should contain\n  maxHops?: number\n}\n\n/**\n * Represents a trade executed against a list of pairs.\n * Does not account for slippage, i.e. trades that front run this trade and move the price.\n */\nexport class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {\n  /**\n   * The route of the trade, i.e. which pairs the trade goes through and the input/output currencies.\n   */\n  public readonly route: Route<TInput, TOutput>\n\n  /**\n   * The type of the trade, either exact in or exact out.\n   */\n  public readonly tradeType: TTradeType\n\n  /**\n   * The input amount for the trade assuming no slippage.\n   */\n  public readonly inputAmount: CurrencyAmount<TInput>\n\n  /**\n   * The output amount for the trade assuming no slippage.\n   */\n  public readonly outputAmount: CurrencyAmount<TOutput>\n\n  /**\n   * The price expressed in terms of output amount/input amount.\n   */\n  public readonly executionPrice: Price<TInput, TOutput>\n\n  /**\n   * The percent difference between the mid price before the trade and the trade execution price.\n   */\n  public readonly priceImpact: Percent\n\n  /**\n   * Constructs an exact in trade with the given amount in and route\n   * @param route route of the exact in trade\n   * @param amountIn the amount being passed in\n   */\n  public static exactIn<TInput extends Currency, TOutput extends Currency>(\n    route: Route<TInput, TOutput>,\n    amountIn: CurrencyAmount<TInput>,\n  ): Trade<TInput, TOutput, TradeType.EXACT_INPUT> {\n    return new Trade(route, amountIn, TradeType.EXACT_INPUT)\n  }\n\n  /**\n   * Constructs an exact out trade with the given amount out and route\n   * @param route route of the exact out trade\n   * @param amountOut the amount returned by the trade\n   */\n  public static exactOut<TInput extends Currency, TOutput extends Currency>(\n    route: Route<TInput, TOutput>,\n    amountOut: CurrencyAmount<TOutput>,\n  ): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT> {\n    return new Trade(route, amountOut, TradeType.EXACT_OUTPUT)\n  }\n\n  public constructor(\n    route: Route<TInput, TOutput>,\n    amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>,\n    tradeType: TTradeType,\n  ) {\n    this.route = route\n    this.tradeType = tradeType\n\n    const tokenAmounts: CurrencyAmount<Token>[] = new Array(route.path.length)\n    if (tradeType === TradeType.EXACT_INPUT) {\n      invariant(amount.currency.equals(route.input), 'INPUT')\n      tokenAmounts[0] = amount.wrapped\n      for (let i = 0; i < route.path.length - 1; i++) {\n        const pair = route.pairs[i]\n        const [outputAmount] = pair.getOutputAmount(tokenAmounts[i])\n        tokenAmounts[i + 1] = outputAmount\n      }\n      this.inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator)\n      this.outputAmount = CurrencyAmount.fromFractionalAmount(\n        route.output,\n        tokenAmounts[tokenAmounts.length - 1].numerator,\n        tokenAmounts[tokenAmounts.length - 1].denominator,\n      )\n    } else {\n      invariant(amount.currency.equals(route.output), 'OUTPUT')\n      tokenAmounts[tokenAmounts.length - 1] = amount.wrapped\n      for (let i = route.path.length - 1; i > 0; i--) {\n        const pair = route.pairs[i - 1]\n        const [inputAmount] = pair.getInputAmount(tokenAmounts[i])\n        tokenAmounts[i - 1] = inputAmount\n      }\n      this.inputAmount = CurrencyAmount.fromFractionalAmount(\n        route.input,\n        tokenAmounts[0].numerator,\n        tokenAmounts[0].denominator,\n      )\n      this.outputAmount = CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator)\n    }\n    this.executionPrice = new Price(\n      this.inputAmount.currency,\n      this.outputAmount.currency,\n      this.inputAmount.quotient,\n      this.outputAmount.quotient,\n    )\n    this.priceImpact = computePriceImpact(route.midPrice, this.inputAmount, this.outputAmount)\n  }\n\n  /**\n   * Get the minimum amount that must be received from this trade for the given slippage tolerance\n   * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade\n   */\n  public minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput> {\n    invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n    if (this.tradeType === TradeType.EXACT_OUTPUT) {\n      return this.outputAmount\n    }\n    const slippageAdjustedAmountOut = new Fraction(ONE)\n      .add(slippageTolerance)\n      .invert()\n      .multiply(this.outputAmount.quotient).quotient\n    return CurrencyAmount.fromRawAmount(this.outputAmount.currency, slippageAdjustedAmountOut)\n  }\n\n  /**\n   * Get the maximum amount in that can be spent via this trade for the given slippage tolerance\n   * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade\n   */\n  public maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput> {\n    invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n    if (this.tradeType === TradeType.EXACT_INPUT) {\n      return this.inputAmount\n    }\n    const slippageAdjustedAmountIn = new Fraction(ONE)\n      .add(slippageTolerance)\n      .multiply(this.inputAmount.quotient).quotient\n    return CurrencyAmount.fromRawAmount(this.inputAmount.currency, slippageAdjustedAmountIn)\n  }\n\n  /**\n   * Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token\n   * amount to an output token, making at most `maxHops` hops.\n   * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting\n   * the amount in among multiple routes.\n   * @param pairs the pairs to consider in finding the best trade\n   * @param nextAmountIn exact amount of input currency to spend\n   * @param currencyOut the desired currency out\n   * @param maxNumResults maximum number of results to return\n   * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair\n   * @param currentPairs used in recursion; the current list of pairs\n   * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter\n   * @param bestTrades used in recursion; the current list of best trades\n   */\n  public static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(\n    pairs: Pair[],\n    currencyAmountIn: CurrencyAmount<TInput>,\n    currencyOut: TOutput,\n    { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\n    // used in recursion.\n    currentPairs: Pair[] = [],\n    nextAmountIn: CurrencyAmount<Currency> = currencyAmountIn,\n    bestTrades: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[] = [],\n  ): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[] {\n    invariant(pairs.length > 0, 'PAIRS')\n    invariant(maxHops > 0, 'MAX_HOPS')\n    invariant(currencyAmountIn === nextAmountIn || currentPairs.length > 0, 'INVALID_RECURSION')\n\n    const amountIn = nextAmountIn.wrapped\n    const tokenOut = currencyOut.wrapped\n    for (let i = 0; i < pairs.length; i++) {\n      const pair = pairs[i]\n      // pair irrelevant\n      // eslint-disable-next-line no-continue\n      if (!pair.token0.equals(amountIn.currency) && !pair.token1.equals(amountIn.currency)) continue\n      // eslint-disable-next-line no-continue\n      if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue\n\n      let amountOut: CurrencyAmount<Token>\n      try {\n        // eslint-disable-next-line @typescript-eslint/no-extra-semi\n        ;[amountOut] = pair.getOutputAmount(amountIn)\n      } catch (error) {\n        // input too low\n        if ((error as InsufficientInputAmountError).isInsufficientInputAmountError) {\n          // eslint-disable-next-line no-continue\n          continue\n        }\n        throw error\n      }\n      // we have arrived at the output token, so this is the final trade of one of the paths\n      if (amountOut.currency.equals(tokenOut)) {\n        sortedInsert(\n          bestTrades,\n          new Trade(\n            new Route([...currentPairs, pair], currencyAmountIn.currency, currencyOut),\n            currencyAmountIn,\n            TradeType.EXACT_INPUT,\n          ),\n          maxNumResults,\n          tradeComparator,\n        )\n      } else if (maxHops > 1 && pairs.length > 1) {\n        const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length))\n\n        // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops\n        Trade.bestTradeExactIn(\n          pairsExcludingThisPair,\n          currencyAmountIn,\n          currencyOut,\n          {\n            maxNumResults,\n            maxHops: maxHops - 1,\n          },\n          [...currentPairs, pair],\n          amountOut,\n          bestTrades,\n        )\n      }\n    }\n\n    return bestTrades\n  }\n\n  /**\n   * Return the execution price after accounting for slippage tolerance\n   * @param slippageTolerance the allowed tolerated slippage\n   */\n  public worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput> {\n    return new Price(\n      this.inputAmount.currency,\n      this.outputAmount.currency,\n      this.maximumAmountIn(slippageTolerance).quotient,\n      this.minimumAmountOut(slippageTolerance).quotient,\n    )\n  }\n\n  /**\n   * similar to the above method but instead targets a fixed output amount\n   * given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token\n   * to an output token amount, making at most `maxHops` hops\n   * note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting\n   * the amount in among multiple routes.\n   * @param pairs the pairs to consider in finding the best trade\n   * @param currencyIn the currency to spend\n   * @param nextAmountOut the exact amount of currency out\n   * @param maxNumResults maximum number of results to return\n   * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair\n   * @param currentPairs used in recursion; the current list of pairs\n   * @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter\n   * @param bestTrades used in recursion; the current list of best trades\n   */\n  public static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(\n    pairs: Pair[],\n    currencyIn: TInput,\n    currencyAmountOut: CurrencyAmount<TOutput>,\n    { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\n    // used in recursion.\n    currentPairs: Pair[] = [],\n    nextAmountOut: CurrencyAmount<Currency> = currencyAmountOut,\n    bestTrades: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[] = [],\n  ): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[] {\n    invariant(pairs.length > 0, 'PAIRS')\n    invariant(maxHops > 0, 'MAX_HOPS')\n    invariant(currencyAmountOut === nextAmountOut || currentPairs.length > 0, 'INVALID_RECURSION')\n\n    const amountOut = nextAmountOut.wrapped\n    const tokenIn = currencyIn.wrapped\n    for (let i = 0; i < pairs.length; i++) {\n      const pair = pairs[i]\n      // pair irrelevant\n      // eslint-disable-next-line no-continue\n      if (!pair.token0.equals(amountOut.currency) && !pair.token1.equals(amountOut.currency)) continue\n      // eslint-disable-next-line no-continue\n      if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue\n\n      let amountIn: CurrencyAmount<Token>\n      try {\n        // eslint-disable-next-line @typescript-eslint/no-extra-semi\n        ;[amountIn] = pair.getInputAmount(amountOut)\n      } catch (error) {\n        // not enough liquidity in this pair\n        if ((error as InsufficientReservesError).isInsufficientReservesError) {\n          // eslint-disable-next-line no-continue\n          continue\n        }\n        throw error\n      }\n      // we have arrived at the input token, so this is the first trade of one of the paths\n      if (amountIn.currency.equals(tokenIn)) {\n        sortedInsert(\n          bestTrades,\n          new Trade(\n            new Route([pair, ...currentPairs], currencyIn, currencyAmountOut.currency),\n            currencyAmountOut,\n            TradeType.EXACT_OUTPUT,\n          ),\n          maxNumResults,\n          tradeComparator,\n        )\n      } else if (maxHops > 1 && pairs.length > 1) {\n        const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length))\n\n        // otherwise, consider all the other paths that arrive at this token as long as we have not exceeded maxHops\n        Trade.bestTradeExactOut(\n          pairsExcludingThisPair,\n          currencyIn,\n          currencyAmountOut,\n          {\n            maxNumResults,\n            maxHops: maxHops - 1,\n          },\n          [pair, ...currentPairs],\n          amountIn,\n          bestTrades,\n        )\n      }\n    }\n\n    return bestTrades\n  }\n}\n","export const pancakePairV2ABI = [\n  {\n    anonymous: false,\n    inputs: [\n      {\n        indexed: true,\n        internalType: 'address',\n        name: 'owner',\n        type: 'address',\n      },\n      {\n        indexed: true,\n        internalType: 'address',\n        name: 'spender',\n        type: 'address',\n      },\n      {\n        indexed: false,\n        internalType: 'uint256',\n        name: 'value',\n        type: 'uint256',\n      },\n    ],\n    name: 'Approval',\n    type: 'event',\n  },\n  {\n    anonymous: false,\n    inputs: [\n      {\n        indexed: true,\n        internalType: 'address',\n        name: 'sender',\n        type: 'address',\n      },\n      {\n        indexed: false,\n        internalType: 'uint256',\n        name: 'amount0',\n        type: 'uint256',\n      },\n      {\n        indexed: false,\n        internalType: 'uint256',\n        name: 'amount1',\n        type: 'uint256',\n      },\n      {\n        indexed: true,\n        internalType: 'address',\n        name: 'to',\n        type: 'address',\n      },\n    ],\n    name: 'Burn',\n    type: 'event',\n  },\n  {\n    anonymous: false,\n    inputs: [\n      {\n        indexed: true,\n        internalType: 'address',\n        name: 'sender',\n        type: 'address',\n      },\n      {\n        indexed: false,\n        internalType: 'uint256',\n        name: 'amount0',\n        type: 'uint256',\n      },\n      {\n        indexed: false,\n        internalType: 'uint256',\n        name: 'amount1',\n        type: 'uint256',\n      },\n    ],\n    name: 'Mint',\n    type: 'event',\n  },\n  {\n    anonymous: false,\n    inputs: [\n      {\n        indexed: true,\n        internalType: 'address',\n        name: 'sender',\n        type: 'address',\n      },\n      {\n        indexed: false,\n        internalType: 'uint256',\n        name: 'amount0In',\n        type: 'uint256',\n      },\n      {\n        indexed: false,\n        internalType: 'uint256',\n        name: 'amount1In',\n        type: 'uint256',\n      },\n      {\n        indexed: false,\n        internalType: 'uint256',\n        name: 'amount0Out',\n        type: 'uint256',\n      },\n      {\n        indexed: false,\n        internalType: 'uint256',\n        name: 'amount1Out',\n        type: 'uint256',\n      },\n      {\n        indexed: true,\n        internalType: 'address',\n        name: 'to',\n        type: 'address',\n      },\n    ],\n    name: 'Swap',\n    type: 'event',\n  },\n  {\n    anonymous: false,\n    inputs: [\n      {\n        indexed: false,\n        internalType: 'uint112',\n        name: 'reserve0',\n        type: 'uint112',\n      },\n      {\n        indexed: false,\n        internalType: 'uint112',\n        name: 'reserve1',\n        type: 'uint112',\n      },\n    ],\n    name: 'Sync',\n    type: 'event',\n  },\n  {\n    anonymous: false,\n    inputs: [\n      {\n        indexed: true,\n        internalType: 'address',\n        name: 'from',\n        type: 'address',\n      },\n      {\n        indexed: true,\n        internalType: 'address',\n        name: 'to',\n        type: 'address',\n      },\n      {\n        indexed: false,\n        internalType: 'uint256',\n        name: 'value',\n        type: 'uint256',\n      },\n    ],\n    name: 'Transfer',\n    type: 'event',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'DOMAIN_SEPARATOR',\n    outputs: [\n      {\n        internalType: 'bytes32',\n        name: '',\n        type: 'bytes32',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'MINIMUM_LIQUIDITY',\n    outputs: [\n      {\n        internalType: 'uint256',\n        name: '',\n        type: 'uint256',\n      },\n    ],\n    payable: false,\n    stateMutability: 'pure',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'PERMIT_TYPEHASH',\n    outputs: [\n      {\n        internalType: 'bytes32',\n        name: '',\n        type: 'bytes32',\n      },\n    ],\n    payable: false,\n    stateMutability: 'pure',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [\n      {\n        internalType: 'address',\n        name: 'owner',\n        type: 'address',\n      },\n      {\n        internalType: 'address',\n        name: 'spender',\n        type: 'address',\n      },\n    ],\n    name: 'allowance',\n    outputs: [\n      {\n        internalType: 'uint256',\n        name: '',\n        type: 'uint256',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: false,\n    inputs: [\n      {\n        internalType: 'address',\n        name: 'spender',\n        type: 'address',\n      },\n      {\n        internalType: 'uint256',\n        name: 'value',\n        type: 'uint256',\n      },\n    ],\n    name: 'approve',\n    outputs: [\n      {\n        internalType: 'bool',\n        name: '',\n        type: 'bool',\n      },\n    ],\n    payable: false,\n    stateMutability: 'nonpayable',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [\n      {\n        internalType: 'address',\n        name: 'owner',\n        type: 'address',\n      },\n    ],\n    name: 'balanceOf',\n    outputs: [\n      {\n        internalType: 'uint256',\n        name: '',\n        type: 'uint256',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: false,\n    inputs: [\n      {\n        internalType: 'address',\n        name: 'to',\n        type: 'address',\n      },\n    ],\n    name: 'burn',\n    outputs: [\n      {\n        internalType: 'uint256',\n        name: 'amount0',\n        type: 'uint256',\n      },\n      {\n        internalType: 'uint256',\n        name: 'amount1',\n        type: 'uint256',\n      },\n    ],\n    payable: false,\n    stateMutability: 'nonpayable',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'decimals',\n    outputs: [\n      {\n        internalType: 'uint8',\n        name: '',\n        type: 'uint8',\n      },\n    ],\n    payable: false,\n    stateMutability: 'pure',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'factory',\n    outputs: [\n      {\n        internalType: 'address',\n        name: '',\n        type: 'address',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'getReserves',\n    outputs: [\n      {\n        internalType: 'uint112',\n        name: 'reserve0',\n        type: 'uint112',\n      },\n      {\n        internalType: 'uint112',\n        name: 'reserve1',\n        type: 'uint112',\n      },\n      {\n        internalType: 'uint32',\n        name: 'blockTimestampLast',\n        type: 'uint32',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: false,\n    inputs: [\n      {\n        internalType: 'address',\n        name: '',\n        type: 'address',\n      },\n      {\n        internalType: 'address',\n        name: '',\n        type: 'address',\n      },\n    ],\n    name: 'initialize',\n    outputs: [],\n    payable: false,\n    stateMutability: 'nonpayable',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'kLast',\n    outputs: [\n      {\n        internalType: 'uint256',\n        name: '',\n        type: 'uint256',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: false,\n    inputs: [\n      {\n        internalType: 'address',\n        name: 'to',\n        type: 'address',\n      },\n    ],\n    name: 'mint',\n    outputs: [\n      {\n        internalType: 'uint256',\n        name: 'liquidity',\n        type: 'uint256',\n      },\n    ],\n    payable: false,\n    stateMutability: 'nonpayable',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'name',\n    outputs: [\n      {\n        internalType: 'string',\n        name: '',\n        type: 'string',\n      },\n    ],\n    payable: false,\n    stateMutability: 'pure',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [\n      {\n        internalType: 'address',\n        name: 'owner',\n        type: 'address',\n      },\n    ],\n    name: 'nonces',\n    outputs: [\n      {\n        internalType: 'uint256',\n        name: '',\n        type: 'uint256',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: false,\n    inputs: [\n      {\n        internalType: 'address',\n        name: 'owner',\n        type: 'address',\n      },\n      {\n        internalType: 'address',\n        name: 'spender',\n        type: 'address',\n      },\n      {\n        internalType: 'uint256',\n        name: 'value',\n        type: 'uint256',\n      },\n      {\n        internalType: 'uint256',\n        name: 'deadline',\n        type: 'uint256',\n      },\n      {\n        internalType: 'uint8',\n        name: 'v',\n        type: 'uint8',\n      },\n      {\n        internalType: 'bytes32',\n        name: 'r',\n        type: 'bytes32',\n      },\n      {\n        internalType: 'bytes32',\n        name: 's',\n        type: 'bytes32',\n      },\n    ],\n    name: 'permit',\n    outputs: [],\n    payable: false,\n    stateMutability: 'nonpayable',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'price0CumulativeLast',\n    outputs: [\n      {\n        internalType: 'uint256',\n        name: '',\n        type: 'uint256',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'price1CumulativeLast',\n    outputs: [\n      {\n        internalType: 'uint256',\n        name: '',\n        type: 'uint256',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: false,\n    inputs: [\n      {\n        internalType: 'address',\n        name: 'to',\n        type: 'address',\n      },\n    ],\n    name: 'skim',\n    outputs: [],\n    payable: false,\n    stateMutability: 'nonpayable',\n    type: 'function',\n  },\n  {\n    constant: false,\n    inputs: [\n      {\n        internalType: 'uint256',\n        name: 'amount0Out',\n        type: 'uint256',\n      },\n      {\n        internalType: 'uint256',\n        name: 'amount1Out',\n        type: 'uint256',\n      },\n      {\n        internalType: 'address',\n        name: 'to',\n        type: 'address',\n      },\n      {\n        internalType: 'bytes',\n        name: 'data',\n        type: 'bytes',\n      },\n    ],\n    name: 'swap',\n    outputs: [],\n    payable: false,\n    stateMutability: 'nonpayable',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'symbol',\n    outputs: [\n      {\n        internalType: 'string',\n        name: '',\n        type: 'string',\n      },\n    ],\n    payable: false,\n    stateMutability: 'pure',\n    type: 'function',\n  },\n  {\n    constant: false,\n    inputs: [],\n    name: 'sync',\n    outputs: [],\n    payable: false,\n    stateMutability: 'nonpayable',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'token0',\n    outputs: [\n      {\n        internalType: 'address',\n        name: '',\n        type: 'address',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'token1',\n    outputs: [\n      {\n        internalType: 'address',\n        name: '',\n        type: 'address',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: true,\n    inputs: [],\n    name: 'totalSupply',\n    outputs: [\n      {\n        internalType: 'uint256',\n        name: '',\n        type: 'uint256',\n      },\n    ],\n    payable: false,\n    stateMutability: 'view',\n    type: 'function',\n  },\n  {\n    constant: false,\n    inputs: [\n      {\n        internalType: 'address',\n        name: 'to',\n        type: 'address',\n      },\n      {\n        internalType: 'uint256',\n        name: 'value',\n        type: 'uint256',\n      },\n    ],\n    name: 'transfer',\n    outputs: [\n      {\n        internalType: 'bool',\n        name: '',\n        type: 'bool',\n      },\n    ],\n    payable: false,\n    stateMutability: 'nonpayable',\n    type: 'function',\n  },\n  {\n    constant: false,\n    inputs: [\n      {\n        internalType: 'address',\n        name: 'from',\n        type: 'address',\n      },\n      {\n        internalType: 'address',\n        name: 'to',\n        type: 'address',\n      },\n      {\n        internalType: 'uint256',\n        name: 'value',\n        type: 'uint256',\n      },\n    ],\n    name: 'transferFrom',\n    outputs: [\n      {\n        internalType: 'bool',\n        name: '',\n        type: 'bool',\n      },\n    ],\n    payable: false,\n    stateMutability: 'nonpayable',\n    type: 'function',\n  },\n] as const\n","import { Currency, CurrencyAmount, Percent, Token, TradeType } from '@pancakeswap/swap-sdk-core'\nimport { validateAndParseAddress } from '@pancakeswap/swap-sdk-evm'\nimport invariant from 'tiny-invariant'\nimport { Address, Hex } from 'viem'\n\nimport { Trade } from './entities'\n\n/**\n * Options for producing the arguments to send call to the router.\n */\nexport interface TradeOptions {\n  /**\n   * How much the execution price is allowed to move unfavorably from the trade execution price.\n   */\n  allowedSlippage: Percent\n  /**\n   * How long the swap is valid until it expires, in seconds.\n   * This will be used to produce a `deadline` parameter which is computed from when the swap call parameters\n   * are generated.\n   */\n  ttl: number\n  /**\n   * The account that should receive the output of the swap.\n   */\n  recipient: string\n\n  /**\n   * Whether any of the tokens in the path are fee on transfer tokens, which should be handled with special methods\n   */\n  feeOnTransfer?: boolean\n}\n\nexport interface TradeOptionsDeadline extends Omit<TradeOptions, 'ttl'> {\n  /**\n   * When the transaction expires.\n   * This is an atlernate to specifying the ttl, for when you do not want to use local time.\n   */\n  deadline: number\n}\n\n/**\n * The parameters to use in the call to the Pancake Router to execute a trade.\n */\nexport interface SwapParameters {\n  /**\n   * The method to call on the Pancake Router.\n   */\n  methodName: string\n  /**\n   * The arguments to pass to the method, all hex encoded.\n   */\n  args: Array<Hex | Hex[] | unknown>\n  /**\n   * The amount of wei to send in hex.\n   */\n  value: Hex\n}\n\nfunction toHex(currencyAmount: CurrencyAmount<Currency>): Hex {\n  return `0x${currencyAmount.quotient.toString(16)}`\n}\n\nconst ZERO_HEX = '0x0'\n\n/**\n * Represents the Pancake Router, and has static methods for helping execute trades.\n */\nexport abstract class Router {\n  /**\n   * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.\n   * @param trade to produce call parameters for\n   * @param options options for the call parameters\n   */\n  public static swapCallParameters(\n    trade: Trade<Currency, Currency, TradeType>,\n    options: TradeOptions | TradeOptionsDeadline,\n  ): SwapParameters {\n    const etherIn = trade.inputAmount.currency.isNative\n    const etherOut = trade.outputAmount.currency.isNative\n    // the router does not support both ether in and out\n    invariant(!(etherIn && etherOut), 'ETHER_IN_OUT')\n    invariant(!('ttl' in options) || options.ttl > 0, 'TTL')\n\n    const to = validateAndParseAddress(options.recipient)\n    const amountIn = toHex(trade.maximumAmountIn(options.allowedSlippage))\n    const amountOut = toHex(trade.minimumAmountOut(options.allowedSlippage))\n    const path: Address[] = trade.route.path.map((token: Token) => token.address)\n    const deadline: Hex =\n      'ttl' in options\n        ? `0x${(Math.floor(new Date().getTime() / 1000) + options.ttl).toString(16)}`\n        : `0x${options.deadline.toString(16)}`\n\n    const useFeeOnTransfer = Boolean(options.feeOnTransfer)\n\n    let methodName: string\n    let args: (Hex | Hex[])[]\n    let value: Hex\n\n    // eslint-disable-next-line default-case\n    switch (trade.tradeType) {\n      case TradeType.EXACT_INPUT:\n        if (etherIn) {\n          methodName = useFeeOnTransfer ? 'swapExactETHForTokensSupportingFeeOnTransferTokens' : 'swapExactETHForTokens'\n          // (uint amountOutMin, address[] calldata path, address to, uint deadline)\n          args = [amountOut, path, to, deadline]\n          value = amountIn\n        } else if (etherOut) {\n          methodName = useFeeOnTransfer ? 'swapExactTokensForETHSupportingFeeOnTransferTokens' : 'swapExactTokensForETH'\n          // (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)\n          args = [amountIn, amountOut, path, to, deadline]\n          value = ZERO_HEX\n        } else {\n          methodName = useFeeOnTransfer\n            ? 'swapExactTokensForTokensSupportingFeeOnTransferTokens'\n            : 'swapExactTokensForTokens'\n          // (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)\n          args = [amountIn, amountOut, path, to, deadline]\n          value = ZERO_HEX\n        }\n        break\n      case TradeType.EXACT_OUTPUT:\n        invariant(!useFeeOnTransfer, 'EXACT_OUT_FOT')\n        if (etherIn) {\n          methodName = 'swapETHForExactTokens'\n          // (uint amountOut, address[] calldata path, address to, uint deadline)\n          args = [amountOut, path, to, deadline]\n          value = amountIn\n        } else if (etherOut) {\n          methodName = 'swapTokensForExactETH'\n          // (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)\n          args = [amountOut, amountIn, path, to, deadline]\n          value = ZERO_HEX\n        } else {\n          methodName = 'swapTokensForExactTokens'\n          // (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)\n          args = [amountOut, amountIn, path, to, deadline]\n          value = ZERO_HEX\n        }\n        break\n    }\n\n    return {\n      methodName,\n      args,\n      value,\n    }\n  }\n}\n","import { ChainId } from '@pancakeswap/chains'\nimport { CurrencyAmount, Token } from '@pancakeswap/swap-sdk-core'\nimport { erc20Abi } from '@pancakeswap/swap-sdk-evm'\nimport invariant from 'tiny-invariant'\nimport { Address, PublicClient, createPublicClient, getContract, http } from 'viem'\nimport { bsc, bscTestnet, goerli, mainnet } from 'viem/chains'\n\nimport { pancakePairV2ABI } from './abis/IPancakePair'\nimport { Pair } from './entities/pair'\n\nlet TOKEN_DECIMALS_CACHE: { [chainId: number]: { [address: string]: number } } = {\n  [ChainId.BSC]: {},\n}\n\nconst ethClient = createPublicClient({ chain: mainnet, transport: http() })\nconst bscClient = createPublicClient({ chain: bsc, transport: http() })\nconst bscTestnetClient = createPublicClient({ chain: bscTestnet, transport: http() })\nconst goerliClient = createPublicClient({ chain: goerli, transport: http() })\n\nconst getDefaultClient = (chainId: ChainId): PublicClient => {\n  switch (chainId) {\n    case ChainId.ETHEREUM:\n      return ethClient\n    case ChainId.BSC:\n      return bscClient\n    case ChainId.BSC_TESTNET:\n      return bscTestnetClient\n    case ChainId.GOERLI:\n      return goerliClient\n    default:\n      return bscClient\n  }\n}\n\n/**\n * Contains methods for constructing instances of pairs and tokens from on-chain data.\n */\nexport abstract class Fetcher {\n  /**\n   * Cannot be constructed.\n   */\n  // eslint-disable-next-line no-useless-constructor,@typescript-eslint/no-empty-function\n  private constructor() {}\n\n  /**\n   * Fetch information for a given token on the given chain, using the given viem provider.\n   * @param chainId chain of the token\n   * @param address address of the token on the chain\n   * @param provider provider used to fetch the token\n   * @param symbol symbol of the token\n   * @param name optional name of the token\n   */\n  public static async fetchTokenData(\n    chainId: ChainId,\n    address: Address,\n    publicClient: any = getDefaultClient(chainId),\n    symbol: string,\n    name?: string,\n  ): Promise<Token> {\n    const erc20 = getContract({\n      abi: erc20Abi,\n      address,\n      client: publicClient as PublicClient,\n    })\n    const parsedDecimals =\n      typeof TOKEN_DECIMALS_CACHE?.[chainId]?.[address] === 'number'\n        ? TOKEN_DECIMALS_CACHE[chainId][address]\n        : await erc20.read.decimals().then((decimals): number => {\n            TOKEN_DECIMALS_CACHE = {\n              ...TOKEN_DECIMALS_CACHE,\n              [chainId]: {\n                ...TOKEN_DECIMALS_CACHE?.[chainId],\n                [address]: decimals,\n              },\n            }\n            return decimals\n          })\n    return new Token(chainId, address, parsedDecimals, symbol, name)\n  }\n\n  /**\n   * Fetches information about a pair and constructs a pair from the given two tokens.\n   * @param tokenA first token\n   * @param tokenB second token\n   * @param provider the provider to use to fetch the data\n   */\n  public static async fetchPairData(\n    tokenA: Token,\n    tokenB: Token,\n    publicClient: any = getDefaultClient(tokenA.chainId),\n  ): Promise<Pair> {\n    invariant(tokenA.chainId === tokenB.chainId, 'CHAIN_ID')\n    const address = Pair.getAddress(tokenA, tokenB)\n    const pairContract: any = getContract({\n      abi: pancakePairV2ABI,\n      address,\n      client: publicClient,\n    })\n    const [reserves0, reserves1] = await pairContract.read.getReserves()\n    const balances = tokenA.sortsBefore(tokenB) ? [reserves0, reserves1] : [reserves1, reserves0]\n    return new Pair(\n      CurrencyAmount.fromRawAmount(tokenA, balances[0]),\n      CurrencyAmount.fromRawAmount(tokenB, balances[1]),\n    )\n  }\n}\n","import { Currency, Percent, TradeType } from '@pancakeswap/swap-sdk-core'\nimport { ONE_HUNDRED_PERCENT, ZERO_PERCENT } from '@pancakeswap/swap-sdk-evm'\n\nimport { Trade } from './entities'\n\n// returns whether tradeB is better than tradeA by at least a threshold percentage amount\nexport function isTradeBetter(\n  tradeA: Trade<Currency, Currency, TradeType> | undefined | null,\n  tradeB: Trade<Currency, Currency, TradeType> | undefined | null,\n  minimumDelta: Percent = ZERO_PERCENT,\n): boolean | undefined {\n  if (tradeA && !tradeB) return false\n  if (tradeB && !tradeA) return true\n  if (!tradeA || !tradeB) return undefined\n\n  if (\n    tradeA.tradeType !== tradeB.tradeType ||\n    !tradeA.inputAmount.currency.equals(tradeB.inputAmount.currency) ||\n    !tradeA.outputAmount.currency.equals(tradeB.outputAmount.currency)\n  ) {\n    throw new Error('Trades are not comparable')\n  }\n\n  if (minimumDelta.equalTo(ZERO_PERCENT)) {\n    return tradeA.executionPrice.lessThan(tradeB.executionPrice)\n  }\n  return tradeA.executionPrice.asFraction\n    .multiply(minimumDelta.add(ONE_HUNDRED_PERCENT))\n    .lessThan(tradeB.executionPrice)\n}\n\nexport default isTradeBetter\n"]}