@sebtoday/u-exchange-sdk 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +56 -0
- package/dist/constants.d.ts +44 -0
- package/dist/entities/currency.d.ts +24 -0
- package/dist/entities/fractions/currencyAmount.d.ts +19 -0
- package/dist/entities/fractions/fraction.d.ts +19 -0
- package/dist/entities/fractions/index.d.ts +5 -0
- package/dist/entities/fractions/percent.d.ts +6 -0
- package/dist/entities/fractions/price.d.ts +19 -0
- package/dist/entities/fractions/tokenAmount.d.ts +9 -0
- package/dist/entities/index.d.ts +6 -0
- package/dist/entities/pair.d.ts +41 -0
- package/dist/entities/route.d.ts +14 -0
- package/dist/entities/token.d.ts +39 -0
- package/dist/entities/trade.d.ts +106 -0
- package/dist/errors.d.ts +16 -0
- package/dist/fetcher.d.ts +28 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/router.d.ts +63 -0
- package/dist/test/constants.test.d.ts +1 -0
- package/dist/test/data.test.d.ts +1 -0
- package/dist/test/entities.test.d.ts +1 -0
- package/dist/test/fraction.test.d.ts +1 -0
- package/dist/test/miscellaneous.test.d.ts +1 -0
- package/dist/test/pair.test.d.ts +1 -0
- package/dist/test/route.test.d.ts +1 -0
- package/dist/test/router.test.d.ts +1 -0
- package/dist/test/token.test.d.ts +1 -0
- package/dist/test/trade.test.d.ts +1 -0
- package/dist/u-exchange-sdk.cjs.development.js +1630 -0
- package/dist/u-exchange-sdk.cjs.development.js.map +1 -0
- package/dist/u-exchange-sdk.cjs.production.min.js +2 -0
- package/dist/u-exchange-sdk.cjs.production.min.js.map +1 -0
- package/dist/u-exchange-sdk.esm.js +1608 -0
- package/dist/u-exchange-sdk.esm.js.map +1 -0
- package/dist/utils.d.ts +7 -0
- package/package.json +70 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"u-exchange-sdk.esm.js","sources":["../src/constants.ts","../src/errors.ts","../src/utils.ts","../src/entities/currency.ts","../src/entities/token.ts","../src/entities/fractions/fraction.ts","../src/entities/fractions/currencyAmount.ts","../src/entities/fractions/tokenAmount.ts","../src/entities/fractions/price.ts","../src/entities/pair.ts","../src/entities/route.ts","../src/entities/fractions/percent.ts","../src/entities/trade.ts","../src/router.ts","../src/fetcher.ts"],"sourcesContent":["import JSBI from 'jsbi'\r\n\r\n// exports for external consumption\r\nexport type BigintIsh = JSBI | bigint | string\r\n\r\nexport enum ChainId {\r\n MAINNET = 1,\r\n ROPSTEN = 3,\r\n RINKEBY = 4,\r\n GÖRLI = 5,\r\n RSK = 30,\r\n RSKTEST = 31,\r\n KOVAN = 42,\r\n BINANCE = 56,\r\n BINANCETEST = 97,\r\n XDAI = 100,\r\n POLYGON = 137\r\n}\r\n\r\nexport enum TradeType {\r\n EXACT_INPUT,\r\n EXACT_OUTPUT\r\n}\r\n\r\nexport enum Rounding {\r\n ROUND_DOWN,\r\n ROUND_HALF_UP,\r\n ROUND_UP\r\n}\r\n\r\nexport const FACTORY_ADDRESS = '0x063af7b01B067eE135344FEf85d6Aecea14CFA05'\r\n\r\nexport const INIT_CODE_HASH = '0x6c0dd0b3d906c70e40fd9e96936f31ff1b70fe5784bae36fcbab40725d974a67'\r\n\r\nexport const MINIMUM_LIQUIDITY = JSBI.BigInt(1000)\r\n\r\n// exports for internal consumption\r\nexport const ZERO = JSBI.BigInt(0)\r\nexport const ONE = JSBI.BigInt(1)\r\nexport const TWO = JSBI.BigInt(2)\r\nexport const THREE = JSBI.BigInt(3)\r\nexport const FIVE = JSBI.BigInt(5)\r\nexport const TEN = JSBI.BigInt(10)\r\nexport const _100 = JSBI.BigInt(100)\r\nexport const _997 = JSBI.BigInt(997)\r\nexport const _1000 = JSBI.BigInt(1000)\r\n\r\nexport enum SolidityType {\r\n uint8 = 'uint8',\r\n uint256 = 'uint256'\r\n}\r\n\r\nexport const SOLIDITY_TYPE_MAXIMA = {\r\n [SolidityType.uint8]: JSBI.BigInt('0xff'),\r\n [SolidityType.uint256]: JSBI.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')\r\n}\r\n","// see https://stackoverflow.com/a/41102306\r\nconst CAN_SET_PROTOTYPE = 'setPrototypeOf' in Object\r\n\r\n/**\r\n * Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be\r\n * obtained by sending any amount of input.\r\n */\r\nexport class InsufficientReservesError extends Error {\r\n public readonly isInsufficientReservesError: true = true\r\n\r\n public constructor() {\r\n super()\r\n this.name = this.constructor.name\r\n if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(this, new.target.prototype)\r\n }\r\n}\r\n\r\n/**\r\n * Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less\r\n * than the price of a single unit of output after fees.\r\n */\r\nexport class InsufficientInputAmountError extends Error {\r\n public readonly isInsufficientInputAmountError: true = true\r\n\r\n public constructor() {\r\n super()\r\n this.name = this.constructor.name\r\n if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(this, new.target.prototype)\r\n }\r\n}\r\n","import invariant from 'tiny-invariant'\r\nimport warning from 'tiny-warning'\r\nimport JSBI from 'jsbi'\r\nimport { getAddress } from '@ethersproject/address'\r\n\r\nimport { BigintIsh, ZERO, ONE, TWO, THREE, SolidityType, SOLIDITY_TYPE_MAXIMA } from './constants'\r\n\r\nexport function validateSolidityTypeInstance(value: JSBI, solidityType: SolidityType): void {\r\n invariant(JSBI.greaterThanOrEqual(value, ZERO), `${value} is not a ${solidityType}.`)\r\n invariant(JSBI.lessThanOrEqual(value, SOLIDITY_TYPE_MAXIMA[solidityType]), `${value} is not a ${solidityType}.`)\r\n}\r\n\r\n// warns if addresses are not checksummed\r\nexport function validateAndParseAddress(address: string): string {\r\n try {\r\n const checksummedAddress = getAddress(address)\r\n warning(address === checksummedAddress, `${address} is not checksummed.`)\r\n return checksummedAddress\r\n } catch (error) {\r\n invariant(false, `${address} is not a valid address.`)\r\n }\r\n}\r\n\r\nexport function parseBigintIsh(bigintIsh: BigintIsh): JSBI {\r\n return bigintIsh instanceof JSBI\r\n ? bigintIsh\r\n : typeof bigintIsh === 'bigint'\r\n ? JSBI.BigInt(bigintIsh.toString())\r\n : JSBI.BigInt(bigintIsh)\r\n}\r\n\r\n// mock the on-chain sqrt function\r\nexport function sqrt(y: JSBI): JSBI {\r\n validateSolidityTypeInstance(y, SolidityType.uint256)\r\n let z: JSBI = ZERO\r\n let x: JSBI\r\n if (JSBI.greaterThan(y, THREE)) {\r\n z = y\r\n x = JSBI.add(JSBI.divide(y, TWO), ONE)\r\n while (JSBI.lessThan(x, z)) {\r\n z = x\r\n x = JSBI.divide(JSBI.add(JSBI.divide(y, x), x), TWO)\r\n }\r\n } else if (JSBI.notEqual(y, ZERO)) {\r\n z = ONE\r\n }\r\n return z\r\n}\r\n\r\n// given an array of items sorted by `comparator`, insert an item into its sort index and constrain the size to\r\n// `maxSize` by removing the last item\r\nexport function sortedInsert<T>(items: T[], add: T, maxSize: number, comparator: (a: T, b: T) => number): T | null {\r\n invariant(maxSize > 0, 'MAX_SIZE_ZERO')\r\n // this is an invariant because the interface cannot return multiple removed items if items.length exceeds maxSize\r\n invariant(items.length <= maxSize, 'ITEMS_SIZE')\r\n\r\n // short circuit first item add\r\n if (items.length === 0) {\r\n items.push(add)\r\n return null\r\n } else {\r\n const isFull = items.length === maxSize\r\n // short circuit if full and the additional item does not come before the last item\r\n if (isFull && comparator(items[items.length - 1], add) <= 0) {\r\n return add\r\n }\r\n\r\n let lo = 0,\r\n hi = items.length\r\n\r\n while (lo < hi) {\r\n const mid = (lo + hi) >>> 1\r\n if (comparator(items[mid], add) <= 0) {\r\n lo = mid + 1\r\n } else {\r\n hi = mid\r\n }\r\n }\r\n items.splice(lo, 0, add)\r\n return isFull ? items.pop()! : null\r\n }\r\n}\r\n","import JSBI from 'jsbi'\r\n\r\nimport { SolidityType } from '../constants'\r\nimport { validateSolidityTypeInstance } from '../utils'\r\n\r\n/**\r\n * A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens.\r\n *\r\n * The only instance of the base class `Currency` is Ether.\r\n */\r\nexport class Currency {\r\n public decimals: number\r\n public symbol?: string\r\n public name?: string\r\n\r\n /**\r\n * The only instance of the base class `Currency`.\r\n */\r\n public static ETHER: Currency = new Currency(18, 'BNB', 'BNB')\r\n\r\n\r\n /**\r\n * Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`.\r\n * @param decimals decimals of the currency\r\n * @param symbol symbol of the currency\r\n * @param name of the currency\r\n */\r\n protected constructor(decimals: number, symbol?: string, name?: string) {\r\n validateSolidityTypeInstance(JSBI.BigInt(decimals), SolidityType.uint8)\r\n\r\n this.decimals = decimals\r\n this.symbol = symbol\r\n this.name = name\r\n }\r\n\r\n change(cId:number){\r\n if(cId==1){\r\n ETHER.name = \"Ether\"\r\n ETHER.symbol = \"ETH\"\r\n }\r\n if(cId==56){\r\n ETHER.name = \"BNB\"\r\n ETHER.symbol = \"BNB\"\r\n }\r\n if(cId==137){\r\n ETHER.name = \"Matic\"\r\n ETHER.symbol = \"MATIC\"\r\n }\r\n if(cId==30){\r\n ETHER.name = \"Smart Bitcoin\"\r\n ETHER.symbol = \"RBTC\"\r\n }\r\n if(cId==31){\r\n ETHER.name = \"Smart Bitcoin\"\r\n ETHER.symbol = \"tRBTC\"\r\n }\r\n }\r\n}\r\n\r\nconst ETHER = Currency.ETHER\r\nexport { ETHER }\r\n","import invariant from 'tiny-invariant'\r\nimport { ChainId } from '../constants'\r\nimport { validateAndParseAddress } from '../utils'\r\nimport { Currency } from './currency'\r\n\r\n/**\r\n * Represents an ERC20 token with a unique address and some metadata.\r\n */\r\nexport class Token extends Currency {\r\n public readonly chainId: ChainId\r\n public readonly address: string\r\n\r\n public constructor(chainId: ChainId, address: string, decimals: number, symbol?: string, name?: string) {\r\n super(decimals, symbol, name)\r\n this.chainId = chainId\r\n this.address = validateAndParseAddress(address)\r\n }\r\n\r\n /**\r\n * Returns true if the two tokens are equivalent, i.e. have the same chainId and address.\r\n * @param other other token to compare\r\n */\r\n public equals(other: Token): boolean {\r\n // short circuit on reference equality\r\n if (this === other) {\r\n return true\r\n }\r\n return this.chainId === other.chainId && this.address === other.address\r\n }\r\n\r\n /**\r\n * Returns true if the address of this token sorts before the address of the other token\r\n * @param other other token to compare\r\n * @throws if the tokens have the same address\r\n * @throws if the tokens are on different chains\r\n */\r\n public sortsBefore(other: Token): boolean {\r\n invariant(this.chainId === other.chainId, 'CHAIN_IDS')\r\n invariant(this.address !== other.address, 'ADDRESSES')\r\n return this.address.toLowerCase() < other.address.toLowerCase()\r\n }\r\n}\r\n\r\n/**\r\n * Compares two currencies for equality\r\n */\r\nexport function currencyEquals(currencyA: Currency, currencyB: Currency): boolean {\r\n if (currencyA instanceof Token && currencyB instanceof Token) {\r\n return currencyA.equals(currencyB)\r\n } else if (currencyA instanceof Token) {\r\n return false\r\n } else if (currencyB instanceof Token) {\r\n return false\r\n } else {\r\n return currencyA === currencyB\r\n }\r\n}\r\n\r\nexport const WETH = {\r\n [ChainId.MAINNET]: new Token(\r\n ChainId.MAINNET,\r\n '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',\r\n 18,\r\n 'WETH',\r\n 'Wrapped Ether'\r\n ),\r\n [ChainId.ROPSTEN]: new Token(\r\n ChainId.ROPSTEN,\r\n '0xc778417E063141139Fce010982780140Aa0cD5Ab',\r\n 18,\r\n 'WETH',\r\n 'Wrapped Ether'\r\n ),\r\n [ChainId.RINKEBY]: new Token(\r\n ChainId.RINKEBY,\r\n '0xc778417E063141139Fce010982780140Aa0cD5Ab',\r\n 18,\r\n 'WETH',\r\n 'Wrapped Ether'\r\n ),\r\n [ChainId.GÖRLI]: new Token(ChainId.GÖRLI, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 18, 'WETH', 'Wrapped Ether'),\r\n [ChainId.KOVAN]: new Token(ChainId.KOVAN, '0xd0A1E359811322d97991E03f863a0C30C2cF029C', 18, 'WETH', 'Wrapped Ether'),\r\n [ChainId.BINANCE]: new Token(ChainId.BINANCE, '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', 18, 'WBNB', 'Wrapped BNB'),\r\n [ChainId.BINANCETEST]: new Token(ChainId.BINANCETEST, '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', 18, 'WBNB', 'Wrapped BNB'),\r\n [ChainId.RSK]: new Token(ChainId.RSK, '0xFa26ecdA879AC88AfD047cc6e046E85B9aFBa2CC', 18, 'WrBTC', 'Wrapped rBTC'),\r\n [ChainId.RSKTEST]: new Token(ChainId.RSKTEST, '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', 18, 'WBNB', 'Wrapped BNB'),\r\n [ChainId.XDAI]: new Token(ChainId.XDAI, '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', 18, 'WXDAI', 'Wrapped XDAI'),\r\n [ChainId.POLYGON]: new Token(ChainId.POLYGON, '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', 18, 'WMATIC', 'Wrapped Matic'),\r\n}\r\n","import invariant from 'tiny-invariant'\r\nimport JSBI from 'jsbi'\r\nimport _Decimal from 'decimal.js-light'\r\nimport _Big, { RoundingMode } from 'big.js'\r\nimport toFormat from 'toformat'\r\n\r\nimport { BigintIsh, Rounding } from '../../constants'\r\nimport { ONE } from '../../constants'\r\nimport { parseBigintIsh } from '../../utils'\r\n\r\nconst Decimal = toFormat(_Decimal)\r\nconst Big = toFormat(_Big)\r\n\r\nconst toSignificantRounding = {\r\n [Rounding.ROUND_DOWN]: Decimal.ROUND_DOWN,\r\n [Rounding.ROUND_HALF_UP]: Decimal.ROUND_HALF_UP,\r\n [Rounding.ROUND_UP]: Decimal.ROUND_UP\r\n}\r\n\r\nconst toFixedRounding = {\r\n [Rounding.ROUND_DOWN]: RoundingMode.RoundDown,\r\n [Rounding.ROUND_HALF_UP]: RoundingMode.RoundHalfUp,\r\n [Rounding.ROUND_UP]: RoundingMode.RoundUp\r\n}\r\n\r\nexport class Fraction {\r\n public readonly numerator: JSBI\r\n public readonly denominator: JSBI\r\n\r\n public constructor(numerator: BigintIsh, denominator: BigintIsh = ONE) {\r\n this.numerator = parseBigintIsh(numerator)\r\n this.denominator = parseBigintIsh(denominator)\r\n }\r\n\r\n // performs floor division\r\n public get quotient(): JSBI {\r\n return JSBI.divide(this.numerator, this.denominator)\r\n }\r\n\r\n // remainder after floor division\r\n public get remainder(): Fraction {\r\n return new Fraction(JSBI.remainder(this.numerator, this.denominator), this.denominator)\r\n }\r\n\r\n public invert(): Fraction {\r\n return new Fraction(this.denominator, this.numerator)\r\n }\r\n\r\n public add(other: Fraction | BigintIsh): Fraction {\r\n const otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other))\r\n if (JSBI.equal(this.denominator, otherParsed.denominator)) {\r\n return new Fraction(JSBI.add(this.numerator, otherParsed.numerator), this.denominator)\r\n }\r\n return new Fraction(\r\n JSBI.add(\r\n JSBI.multiply(this.numerator, otherParsed.denominator),\r\n JSBI.multiply(otherParsed.numerator, this.denominator)\r\n ),\r\n JSBI.multiply(this.denominator, otherParsed.denominator)\r\n )\r\n }\r\n\r\n public subtract(other: Fraction | BigintIsh): Fraction {\r\n const otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other))\r\n if (JSBI.equal(this.denominator, otherParsed.denominator)) {\r\n return new Fraction(JSBI.subtract(this.numerator, otherParsed.numerator), this.denominator)\r\n }\r\n return new Fraction(\r\n JSBI.subtract(\r\n JSBI.multiply(this.numerator, otherParsed.denominator),\r\n JSBI.multiply(otherParsed.numerator, this.denominator)\r\n ),\r\n JSBI.multiply(this.denominator, otherParsed.denominator)\r\n )\r\n }\r\n\r\n public lessThan(other: Fraction | BigintIsh): boolean {\r\n const otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other))\r\n return JSBI.lessThan(\r\n JSBI.multiply(this.numerator, otherParsed.denominator),\r\n JSBI.multiply(otherParsed.numerator, this.denominator)\r\n )\r\n }\r\n\r\n public equalTo(other: Fraction | BigintIsh): boolean {\r\n const otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other))\r\n return JSBI.equal(\r\n JSBI.multiply(this.numerator, otherParsed.denominator),\r\n JSBI.multiply(otherParsed.numerator, this.denominator)\r\n )\r\n }\r\n\r\n public greaterThan(other: Fraction | BigintIsh): boolean {\r\n const otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other))\r\n return JSBI.greaterThan(\r\n JSBI.multiply(this.numerator, otherParsed.denominator),\r\n JSBI.multiply(otherParsed.numerator, this.denominator)\r\n )\r\n }\r\n\r\n public multiply(other: Fraction | BigintIsh): Fraction {\r\n const otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other))\r\n return new Fraction(\r\n JSBI.multiply(this.numerator, otherParsed.numerator),\r\n JSBI.multiply(this.denominator, otherParsed.denominator)\r\n )\r\n }\r\n\r\n public divide(other: Fraction | BigintIsh): Fraction {\r\n const otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other))\r\n return new Fraction(\r\n JSBI.multiply(this.numerator, otherParsed.denominator),\r\n JSBI.multiply(this.denominator, otherParsed.numerator)\r\n )\r\n }\r\n\r\n public toSignificant(\r\n significantDigits: number,\r\n format: object = { groupSeparator: '' },\r\n rounding: Rounding = Rounding.ROUND_HALF_UP\r\n ): string {\r\n invariant(Number.isInteger(significantDigits), `${significantDigits} is not an integer.`)\r\n invariant(significantDigits > 0, `${significantDigits} is not positive.`)\r\n\r\n Decimal.set({ precision: significantDigits + 1, rounding: toSignificantRounding[rounding] })\r\n const quotient = new Decimal(this.numerator.toString())\r\n .div(this.denominator.toString())\r\n .toSignificantDigits(significantDigits)\r\n return quotient.toFormat(quotient.decimalPlaces(), format)\r\n }\r\n\r\n public toFixed(\r\n decimalPlaces: number,\r\n format: object = { groupSeparator: '' },\r\n rounding: Rounding = Rounding.ROUND_HALF_UP\r\n ): string {\r\n invariant(Number.isInteger(decimalPlaces), `${decimalPlaces} is not an integer.`)\r\n invariant(decimalPlaces >= 0, `${decimalPlaces} is negative.`)\r\n\r\n Big.DP = decimalPlaces\r\n Big.RM = toFixedRounding[rounding]\r\n return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format)\r\n }\r\n}\r\n","import { currencyEquals } from '../token'\r\nimport { Currency, ETHER } from '../currency'\r\nimport invariant from 'tiny-invariant'\r\nimport JSBI from 'jsbi'\r\nimport _Big from 'big.js'\r\nimport toFormat from 'toformat'\r\n\r\nimport { BigintIsh, Rounding, TEN, SolidityType } from '../../constants'\r\nimport { parseBigintIsh, validateSolidityTypeInstance } from '../../utils'\r\nimport { Fraction } from './fraction'\r\n\r\nconst Big = toFormat(_Big)\r\n\r\nexport class CurrencyAmount extends Fraction {\r\n public readonly currency: Currency\r\n\r\n /**\r\n * Helper that calls the constructor with the ETHER currency\r\n * @param amount ether amount in wei\r\n */\r\n public static ether(amount: BigintIsh): CurrencyAmount {\r\n return new CurrencyAmount(ETHER, amount)\r\n }\r\n\r\n // amount _must_ be raw, i.e. in the native representation\r\n protected constructor(currency: Currency, amount: BigintIsh) {\r\n const parsedAmount = parseBigintIsh(amount)\r\n validateSolidityTypeInstance(parsedAmount, SolidityType.uint256)\r\n\r\n super(parsedAmount, JSBI.exponentiate(TEN, JSBI.BigInt(currency.decimals)))\r\n this.currency = currency\r\n }\r\n\r\n public get raw(): JSBI {\r\n return this.numerator\r\n }\r\n\r\n public add(other: CurrencyAmount): CurrencyAmount {\r\n invariant(currencyEquals(this.currency, other.currency), 'TOKEN')\r\n return new CurrencyAmount(this.currency, JSBI.add(this.raw, other.raw))\r\n }\r\n\r\n public subtract(other: CurrencyAmount): CurrencyAmount {\r\n invariant(currencyEquals(this.currency, other.currency), 'TOKEN')\r\n return new CurrencyAmount(this.currency, JSBI.subtract(this.raw, other.raw))\r\n }\r\n\r\n public toSignificant(\r\n significantDigits: number = 6,\r\n format?: object,\r\n rounding: Rounding = Rounding.ROUND_DOWN\r\n ): string {\r\n return super.toSignificant(significantDigits, format, rounding)\r\n }\r\n\r\n public toFixed(\r\n decimalPlaces: number = this.currency.decimals,\r\n format?: object,\r\n rounding: Rounding = Rounding.ROUND_DOWN\r\n ): string {\r\n invariant(decimalPlaces <= this.currency.decimals, 'DECIMALS')\r\n return super.toFixed(decimalPlaces, format, rounding)\r\n }\r\n\r\n public toExact(format: object = { groupSeparator: '' }): string {\r\n Big.DP = this.currency.decimals\r\n return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(format)\r\n }\r\n}\r\n","import { CurrencyAmount } from './currencyAmount'\r\nimport { Token } from '../token'\r\nimport invariant from 'tiny-invariant'\r\nimport JSBI from 'jsbi'\r\n\r\nimport { BigintIsh } from '../../constants'\r\n\r\nexport class TokenAmount extends CurrencyAmount {\r\n public readonly token: Token\r\n\r\n // amount _must_ be raw, i.e. in the native representation\r\n public constructor(token: Token, amount: BigintIsh) {\r\n super(token, amount)\r\n this.token = token\r\n }\r\n\r\n public add(other: TokenAmount): TokenAmount {\r\n invariant(this.token.equals(other.token), 'TOKEN')\r\n return new TokenAmount(this.token, JSBI.add(this.raw, other.raw))\r\n }\r\n\r\n public subtract(other: TokenAmount): TokenAmount {\r\n invariant(this.token.equals(other.token), 'TOKEN')\r\n return new TokenAmount(this.token, JSBI.subtract(this.raw, other.raw))\r\n }\r\n}\r\n","import { Token } from '../token'\r\nimport { TokenAmount } from './tokenAmount'\r\nimport { currencyEquals } from '../token'\r\nimport invariant from 'tiny-invariant'\r\nimport JSBI from 'jsbi'\r\n\r\nimport { BigintIsh, Rounding, TEN } from '../../constants'\r\nimport { Currency } from '../currency'\r\nimport { Route } from '../route'\r\nimport { Fraction } from './fraction'\r\nimport { CurrencyAmount } from './currencyAmount'\r\n\r\nexport class Price extends Fraction {\r\n public readonly baseCurrency: Currency // input i.e. denominator\r\n public readonly quoteCurrency: Currency // output i.e. numerator\r\n public readonly scalar: Fraction // used to adjust the raw fraction w/r/t the decimals of the {base,quote}Token\r\n\r\n public static fromRoute(route: Route): Price {\r\n const prices: Price[] = []\r\n for (const [i, pair] of route.pairs.entries()) {\r\n prices.push(\r\n route.path[i].equals(pair.token0)\r\n ? new Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.raw, pair.reserve1.raw)\r\n : new Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.raw, pair.reserve0.raw)\r\n )\r\n }\r\n return prices.slice(1).reduce((accumulator, currentValue) => accumulator.multiply(currentValue), prices[0])\r\n }\r\n\r\n // denominator and numerator _must_ be raw, i.e. in the native representation\r\n public constructor(baseCurrency: Currency, quoteCurrency: Currency, denominator: BigintIsh, numerator: BigintIsh) {\r\n super(numerator, denominator)\r\n\r\n this.baseCurrency = baseCurrency\r\n this.quoteCurrency = quoteCurrency\r\n this.scalar = new Fraction(\r\n JSBI.exponentiate(TEN, JSBI.BigInt(baseCurrency.decimals)),\r\n JSBI.exponentiate(TEN, JSBI.BigInt(quoteCurrency.decimals))\r\n )\r\n }\r\n\r\n public get raw(): Fraction {\r\n return new Fraction(this.numerator, this.denominator)\r\n }\r\n\r\n public get adjusted(): Fraction {\r\n return super.multiply(this.scalar)\r\n }\r\n\r\n public invert(): Price {\r\n return new Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator)\r\n }\r\n\r\n public multiply(other: Price): Price {\r\n invariant(currencyEquals(this.quoteCurrency, other.baseCurrency), 'TOKEN')\r\n const fraction = super.multiply(other)\r\n return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator)\r\n }\r\n\r\n // performs floor division on overflow\r\n public quote(currencyAmount: CurrencyAmount): CurrencyAmount {\r\n invariant(currencyEquals(currencyAmount.currency, this.baseCurrency), 'TOKEN')\r\n if (this.quoteCurrency instanceof Token) {\r\n return new TokenAmount(this.quoteCurrency, super.multiply(currencyAmount.raw).quotient)\r\n }\r\n return CurrencyAmount.ether(super.multiply(currencyAmount.raw).quotient)\r\n }\r\n\r\n public toSignificant(significantDigits: number = 6, format?: object, rounding?: Rounding): string {\r\n return this.adjusted.toSignificant(significantDigits, format, rounding)\r\n }\r\n\r\n public toFixed(decimalPlaces: number = 4, format?: object, rounding?: Rounding): string {\r\n return this.adjusted.toFixed(decimalPlaces, format, rounding)\r\n }\r\n}\r\n","import { Price } from './fractions/price'\r\nimport { TokenAmount } from './fractions/tokenAmount'\r\nimport invariant from 'tiny-invariant'\r\nimport JSBI from 'jsbi'\r\nimport { pack, keccak256 } from '@ethersproject/solidity'\r\nimport { getCreate2Address } from '@ethersproject/address'\r\n\r\nimport {\r\n BigintIsh,\r\n FACTORY_ADDRESS,\r\n INIT_CODE_HASH,\r\n MINIMUM_LIQUIDITY,\r\n ZERO,\r\n ONE,\r\n FIVE,\r\n _997,\r\n _1000,\r\n ChainId\r\n} from '../constants'\r\nimport { sqrt, parseBigintIsh } from '../utils'\r\nimport { InsufficientReservesError, InsufficientInputAmountError } from '../errors'\r\nimport { Token } from './token'\r\n\r\nlet PAIR_ADDRESS_CACHE: { [token0Address: string]: { [token1Address: string]: string } } = {}\r\n\r\nexport class Pair {\r\n public readonly liquidityToken: Token\r\n private readonly tokenAmounts: [TokenAmount, TokenAmount]\r\n\r\n public static getAddress(tokenA: Token, tokenB: Token): string {\r\n const tokens = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks\r\n\r\n if (PAIR_ADDRESS_CACHE?.[tokens[0].address]?.[tokens[1].address] === undefined) {\r\n PAIR_ADDRESS_CACHE = {\r\n ...PAIR_ADDRESS_CACHE,\r\n [tokens[0].address]: {\r\n ...PAIR_ADDRESS_CACHE?.[tokens[0].address],\r\n [tokens[1].address]: getCreate2Address(\r\n FACTORY_ADDRESS,\r\n keccak256(['bytes'], [pack(['address', 'address'], [tokens[0].address, tokens[1].address])]),\r\n INIT_CODE_HASH\r\n )\r\n }\r\n }\r\n }\r\n\r\n return PAIR_ADDRESS_CACHE[tokens[0].address][tokens[1].address]\r\n }\r\n\r\n public constructor(tokenAmountA: TokenAmount, tokenAmountB: TokenAmount) {\r\n const tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) // does safety checks\r\n ? [tokenAmountA, tokenAmountB]\r\n : [tokenAmountB, tokenAmountA]\r\n this.liquidityToken = new Token(\r\n tokenAmounts[0].token.chainId,\r\n Pair.getAddress(tokenAmounts[0].token, tokenAmounts[1].token),\r\n 18,\r\n 'UNI-V2',\r\n 'Uniswap V2'\r\n )\r\n this.tokenAmounts = tokenAmounts as [TokenAmount, TokenAmount]\r\n }\r\n\r\n /**\r\n * Returns true if the token is either token0 or token1\r\n * @param token to check\r\n */\r\n public involvesToken(token: Token): boolean {\r\n return token.equals(this.token0) || token.equals(this.token1)\r\n }\r\n\r\n /**\r\n * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0\r\n */\r\n public get token0Price(): Price {\r\n return new Price(this.token0, this.token1, this.tokenAmounts[0].raw, this.tokenAmounts[1].raw)\r\n }\r\n\r\n /**\r\n * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1\r\n */\r\n public get token1Price(): Price {\r\n return new Price(this.token1, this.token0, this.tokenAmounts[1].raw, this.tokenAmounts[0].raw)\r\n }\r\n\r\n /**\r\n * Return the price of the given token in terms of the other token in the pair.\r\n * @param token token to return price of\r\n */\r\n public priceOf(token: Token): Price {\r\n invariant(this.involvesToken(token), 'TOKEN')\r\n return token.equals(this.token0) ? this.token0Price : this.token1Price\r\n }\r\n\r\n /**\r\n * Returns the chain ID of the tokens in the pair.\r\n */\r\n public get chainId(): ChainId {\r\n return this.token0.chainId\r\n }\r\n\r\n public get token0(): Token {\r\n return this.tokenAmounts[0].token\r\n }\r\n\r\n public get token1(): Token {\r\n return this.tokenAmounts[1].token\r\n }\r\n\r\n public get reserve0(): TokenAmount {\r\n return this.tokenAmounts[0]\r\n }\r\n\r\n public get reserve1(): TokenAmount {\r\n return this.tokenAmounts[1]\r\n }\r\n\r\n public reserveOf(token: Token): TokenAmount {\r\n invariant(this.involvesToken(token), 'TOKEN')\r\n return token.equals(this.token0) ? this.reserve0 : this.reserve1\r\n }\r\n\r\n public getOutputAmount(inputAmount: TokenAmount): [TokenAmount, Pair] {\r\n invariant(this.involvesToken(inputAmount.token), 'TOKEN')\r\n if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO)) {\r\n throw new InsufficientReservesError()\r\n }\r\n const inputReserve = this.reserveOf(inputAmount.token)\r\n const outputReserve = this.reserveOf(inputAmount.token.equals(this.token0) ? this.token1 : this.token0)\r\n const inputAmountWithFee = JSBI.multiply(inputAmount.raw, _997)\r\n const numerator = JSBI.multiply(inputAmountWithFee, outputReserve.raw)\r\n const denominator = JSBI.add(JSBI.multiply(inputReserve.raw, _1000), inputAmountWithFee)\r\n const outputAmount = new TokenAmount(\r\n inputAmount.token.equals(this.token0) ? this.token1 : this.token0,\r\n JSBI.divide(numerator, denominator)\r\n )\r\n if (JSBI.equal(outputAmount.raw, ZERO)) {\r\n throw new InsufficientInputAmountError()\r\n }\r\n return [outputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]\r\n }\r\n\r\n public getInputAmount(outputAmount: TokenAmount): [TokenAmount, Pair] {\r\n invariant(this.involvesToken(outputAmount.token), 'TOKEN')\r\n if (\r\n JSBI.equal(this.reserve0.raw, ZERO) ||\r\n JSBI.equal(this.reserve1.raw, ZERO) ||\r\n JSBI.greaterThanOrEqual(outputAmount.raw, this.reserveOf(outputAmount.token).raw)\r\n ) {\r\n throw new InsufficientReservesError()\r\n }\r\n\r\n const outputReserve = this.reserveOf(outputAmount.token)\r\n const inputReserve = this.reserveOf(outputAmount.token.equals(this.token0) ? this.token1 : this.token0)\r\n const numerator = JSBI.multiply(JSBI.multiply(inputReserve.raw, outputAmount.raw), _1000)\r\n const denominator = JSBI.multiply(JSBI.subtract(outputReserve.raw, outputAmount.raw), _997)\r\n const inputAmount = new TokenAmount(\r\n outputAmount.token.equals(this.token0) ? this.token1 : this.token0,\r\n JSBI.add(JSBI.divide(numerator, denominator), ONE)\r\n )\r\n return [inputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]\r\n }\r\n\r\n public getLiquidityMinted(\r\n totalSupply: TokenAmount,\r\n tokenAmountA: TokenAmount,\r\n tokenAmountB: TokenAmount\r\n ): TokenAmount {\r\n invariant(totalSupply.token.equals(this.liquidityToken), 'LIQUIDITY')\r\n const tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) // does safety checks\r\n ? [tokenAmountA, tokenAmountB]\r\n : [tokenAmountB, tokenAmountA]\r\n invariant(tokenAmounts[0].token.equals(this.token0) && tokenAmounts[1].token.equals(this.token1), 'TOKEN')\r\n\r\n let liquidity: JSBI\r\n if (JSBI.equal(totalSupply.raw, ZERO)) {\r\n liquidity = JSBI.subtract(sqrt(JSBI.multiply(tokenAmounts[0].raw, tokenAmounts[1].raw)), MINIMUM_LIQUIDITY)\r\n } else {\r\n const amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].raw, totalSupply.raw), this.reserve0.raw)\r\n const amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].raw, totalSupply.raw), this.reserve1.raw)\r\n liquidity = JSBI.lessThanOrEqual(amount0, amount1) ? amount0 : amount1\r\n }\r\n if (!JSBI.greaterThan(liquidity, ZERO)) {\r\n throw new InsufficientInputAmountError()\r\n }\r\n return new TokenAmount(this.liquidityToken, liquidity)\r\n }\r\n\r\n public getLiquidityValue(\r\n token: Token,\r\n totalSupply: TokenAmount,\r\n liquidity: TokenAmount,\r\n feeOn: boolean = false,\r\n kLast?: BigintIsh\r\n ): TokenAmount {\r\n invariant(this.involvesToken(token), 'TOKEN')\r\n invariant(totalSupply.token.equals(this.liquidityToken), 'TOTAL_SUPPLY')\r\n invariant(liquidity.token.equals(this.liquidityToken), 'LIQUIDITY')\r\n invariant(JSBI.lessThanOrEqual(liquidity.raw, totalSupply.raw), 'LIQUIDITY')\r\n\r\n let totalSupplyAdjusted: TokenAmount\r\n if (!feeOn) {\r\n totalSupplyAdjusted = totalSupply\r\n } else {\r\n invariant(!!kLast, 'K_LAST')\r\n const kLastParsed = parseBigintIsh(kLast)\r\n if (!JSBI.equal(kLastParsed, ZERO)) {\r\n const rootK = sqrt(JSBI.multiply(this.reserve0.raw, this.reserve1.raw))\r\n const rootKLast = sqrt(kLastParsed)\r\n if (JSBI.greaterThan(rootK, rootKLast)) {\r\n const numerator = JSBI.multiply(totalSupply.raw, JSBI.subtract(rootK, rootKLast))\r\n const denominator = JSBI.add(JSBI.multiply(rootK, FIVE), rootKLast)\r\n const feeLiquidity = JSBI.divide(numerator, denominator)\r\n totalSupplyAdjusted = totalSupply.add(new TokenAmount(this.liquidityToken, feeLiquidity))\r\n } else {\r\n totalSupplyAdjusted = totalSupply\r\n }\r\n } else {\r\n totalSupplyAdjusted = totalSupply\r\n }\r\n }\r\n\r\n return new TokenAmount(\r\n token,\r\n JSBI.divide(JSBI.multiply(liquidity.raw, this.reserveOf(token).raw), totalSupplyAdjusted.raw)\r\n )\r\n }\r\n}\r\n","import { ChainId } from '../constants'\r\nimport invariant from 'tiny-invariant'\r\n\r\nimport { Currency, ETHER } from './currency'\r\nimport { Token, WETH } from './token'\r\nimport { Pair } from './pair'\r\nimport { Price } from './fractions/price'\r\n\r\nexport class Route {\r\n public readonly pairs: Pair[]\r\n public readonly path: Token[]\r\n public readonly input: Currency\r\n public readonly output: Currency\r\n public readonly midPrice: Price\r\n\r\n public constructor(pairs: Pair[], input: Currency, output?: Currency) {\r\n invariant(pairs.length > 0, 'PAIRS')\r\n invariant(\r\n pairs.every(pair => pair.chainId === pairs[0].chainId),\r\n 'CHAIN_IDS'\r\n )\r\n invariant(\r\n (input instanceof Token && pairs[0].involvesToken(input)) ||\r\n (input === ETHER && pairs[0].involvesToken(WETH[pairs[0].chainId])),\r\n 'INPUT'\r\n )\r\n invariant(\r\n typeof output === 'undefined' ||\r\n (output instanceof Token && pairs[pairs.length - 1].involvesToken(output)) ||\r\n (output === ETHER && pairs[pairs.length - 1].involvesToken(WETH[pairs[0].chainId])),\r\n 'OUTPUT'\r\n )\r\n\r\n const path: Token[] = [input instanceof Token ? input : WETH[pairs[0].chainId]]\r\n for (const [i, pair] of pairs.entries()) {\r\n const currentInput = path[i]\r\n invariant(currentInput.equals(pair.token0) || currentInput.equals(pair.token1), 'PATH')\r\n const output = currentInput.equals(pair.token0) ? pair.token1 : pair.token0\r\n path.push(output)\r\n }\r\n\r\n this.pairs = pairs\r\n this.path = path\r\n this.midPrice = Price.fromRoute(this)\r\n this.input = input\r\n this.output = output ?? path[path.length - 1]\r\n }\r\n\r\n public get chainId(): ChainId {\r\n return this.pairs[0].chainId\r\n }\r\n}\r\n","import { Rounding, _100 } from '../../constants'\r\nimport { Fraction } from './fraction'\r\n\r\nconst _100_PERCENT = new Fraction(_100)\r\n\r\nexport class Percent extends Fraction {\r\n public toSignificant(significantDigits: number = 5, format?: object, rounding?: Rounding): string {\r\n return this.multiply(_100_PERCENT).toSignificant(significantDigits, format, rounding)\r\n }\r\n\r\n public toFixed(decimalPlaces: number = 2, format?: object, rounding?: Rounding): string {\r\n return this.multiply(_100_PERCENT).toFixed(decimalPlaces, format, rounding)\r\n }\r\n}\r\n","import invariant from 'tiny-invariant'\r\n\r\nimport { ChainId, ONE, TradeType, ZERO } from '../constants'\r\nimport { sortedInsert } from '../utils'\r\nimport { Currency, ETHER } from './currency'\r\nimport { CurrencyAmount } from './fractions/currencyAmount'\r\nimport { Fraction } from './fractions/fraction'\r\nimport { Percent } from './fractions/percent'\r\nimport { Price } from './fractions/price'\r\nimport { TokenAmount } from './fractions/tokenAmount'\r\nimport { Pair } from './pair'\r\nimport { Route } from './route'\r\nimport { currencyEquals, Token, WETH } from './token'\r\n\r\n/**\r\n * Returns the percent difference between the mid price and the execution price, i.e. price impact.\r\n * @param midPrice mid price before the trade\r\n * @param inputAmount the input amount of the trade\r\n * @param outputAmount the output amount of the trade\r\n */\r\nfunction computePriceImpact(midPrice: Price, inputAmount: CurrencyAmount, outputAmount: CurrencyAmount): Percent {\r\n const exactQuote = midPrice.raw.multiply(inputAmount.raw)\r\n // calculate slippage := (exactQuote - outputAmount) / exactQuote\r\n const slippage = exactQuote.subtract(outputAmount.raw).divide(exactQuote)\r\n return new Percent(slippage.numerator, slippage.denominator)\r\n}\r\n\r\n// minimal interface so the input output comparator may be shared across types\r\ninterface InputOutput {\r\n readonly inputAmount: CurrencyAmount\r\n readonly outputAmount: CurrencyAmount\r\n}\r\n\r\n// comparator function that allows sorting trades by their output amounts, in decreasing order, and then input amounts\r\n// in increasing order. i.e. the best trades have the most outputs for the least inputs and are sorted first\r\nexport function inputOutputComparator(a: InputOutput, b: InputOutput): number {\r\n // must have same input and output token for comparison\r\n invariant(currencyEquals(a.inputAmount.currency, b.inputAmount.currency), 'INPUT_CURRENCY')\r\n invariant(currencyEquals(a.outputAmount.currency, b.outputAmount.currency), 'OUTPUT_CURRENCY')\r\n if (a.outputAmount.equalTo(b.outputAmount)) {\r\n if (a.inputAmount.equalTo(b.inputAmount)) {\r\n return 0\r\n }\r\n // trade A requires less input than trade B, so A should come first\r\n if (a.inputAmount.lessThan(b.inputAmount)) {\r\n return -1\r\n } else {\r\n return 1\r\n }\r\n } else {\r\n // tradeA has less output than trade B, so should come second\r\n if (a.outputAmount.lessThan(b.outputAmount)) {\r\n return 1\r\n } else {\r\n return -1\r\n }\r\n }\r\n}\r\n\r\n// extension of the input output comparator that also considers other dimensions of the trade in ranking them\r\nexport function tradeComparator(a: Trade, b: Trade) {\r\n const ioComp = inputOutputComparator(a, b)\r\n if (ioComp !== 0) {\r\n return ioComp\r\n }\r\n\r\n // consider lowest slippage next, since these are less likely to fail\r\n if (a.priceImpact.lessThan(b.priceImpact)) {\r\n return -1\r\n } else if (a.priceImpact.greaterThan(b.priceImpact)) {\r\n return 1\r\n }\r\n\r\n // finally consider the number of hops since each hop costs gas\r\n return a.route.path.length - b.route.path.length\r\n}\r\n\r\nexport interface BestTradeOptions {\r\n // how many results to return\r\n maxNumResults?: number\r\n // the maximum number of hops a trade should contain\r\n maxHops?: number\r\n}\r\n\r\n/**\r\n * Given a currency amount and a chain ID, returns the equivalent representation as the token amount.\r\n * In other words, if the currency is ETHER, returns the WETH token amount for the given chain. Otherwise, returns\r\n * the input currency amount.\r\n */\r\nfunction wrappedAmount(currencyAmount: CurrencyAmount, chainId: ChainId): TokenAmount {\r\n if (currencyAmount instanceof TokenAmount) return currencyAmount\r\n if (currencyAmount.currency === ETHER) return new TokenAmount(WETH[chainId], currencyAmount.raw)\r\n invariant(false, 'CURRENCY')\r\n}\r\n\r\nfunction wrappedCurrency(currency: Currency, chainId: ChainId): Token {\r\n if (currency instanceof Token) return currency\r\n if (currency === ETHER) return WETH[chainId]\r\n invariant(false, 'CURRENCY')\r\n}\r\n\r\n/**\r\n * Represents a trade executed against a list of pairs.\r\n * Does not account for slippage, i.e. trades that front run this trade and move the price.\r\n */\r\nexport class Trade {\r\n /**\r\n * The route of the trade, i.e. which pairs the trade goes through.\r\n */\r\n public readonly route: Route\r\n /**\r\n * The type of the trade, either exact in or exact out.\r\n */\r\n public readonly tradeType: TradeType\r\n /**\r\n * The input amount for the trade assuming no slippage.\r\n */\r\n public readonly inputAmount: CurrencyAmount\r\n /**\r\n * The output amount for the trade assuming no slippage.\r\n */\r\n public readonly outputAmount: CurrencyAmount\r\n /**\r\n * The price expressed in terms of output amount/input amount.\r\n */\r\n public readonly executionPrice: Price\r\n /**\r\n * The mid price after the trade executes assuming no slippage.\r\n */\r\n public readonly nextMidPrice: Price\r\n /**\r\n * The percent difference between the mid price before the trade and the trade execution price.\r\n */\r\n public readonly priceImpact: Percent\r\n\r\n /**\r\n * Constructs an exact in trade with the given amount in and route\r\n * @param route route of the exact in trade\r\n * @param amountIn the amount being passed in\r\n */\r\n public static exactIn(route: Route, amountIn: CurrencyAmount): Trade {\r\n return new Trade(route, amountIn, TradeType.EXACT_INPUT)\r\n }\r\n\r\n /**\r\n * Constructs an exact out trade with the given amount out and route\r\n * @param route route of the exact out trade\r\n * @param amountOut the amount returned by the trade\r\n */\r\n public static exactOut(route: Route, amountOut: CurrencyAmount): Trade {\r\n return new Trade(route, amountOut, TradeType.EXACT_OUTPUT)\r\n }\r\n\r\n public constructor(route: Route, amount: CurrencyAmount, tradeType: TradeType) {\r\n const amounts: TokenAmount[] = new Array(route.path.length)\r\n const nextPairs: Pair[] = new Array(route.pairs.length)\r\n if (tradeType === TradeType.EXACT_INPUT) {\r\n invariant(currencyEquals(amount.currency, route.input), 'INPUT')\r\n amounts[0] = wrappedAmount(amount, route.chainId)\r\n for (let i = 0; i < route.path.length - 1; i++) {\r\n const pair = route.pairs[i]\r\n const [outputAmount, nextPair] = pair.getOutputAmount(amounts[i])\r\n amounts[i + 1] = outputAmount\r\n nextPairs[i] = nextPair\r\n }\r\n } else {\r\n invariant(currencyEquals(amount.currency, route.output), 'OUTPUT')\r\n amounts[amounts.length - 1] = wrappedAmount(amount, route.chainId)\r\n for (let i = route.path.length - 1; i > 0; i--) {\r\n const pair = route.pairs[i - 1]\r\n const [inputAmount, nextPair] = pair.getInputAmount(amounts[i])\r\n amounts[i - 1] = inputAmount\r\n nextPairs[i - 1] = nextPair\r\n }\r\n }\r\n\r\n this.route = route\r\n this.tradeType = tradeType\r\n this.inputAmount =\r\n tradeType === TradeType.EXACT_INPUT\r\n ? amount\r\n : route.input === ETHER\r\n ? CurrencyAmount.ether(amounts[0].raw)\r\n : amounts[0]\r\n this.outputAmount =\r\n tradeType === TradeType.EXACT_OUTPUT\r\n ? amount\r\n : route.output === ETHER\r\n ? CurrencyAmount.ether(amounts[amounts.length - 1].raw)\r\n : amounts[amounts.length - 1]\r\n this.executionPrice = new Price(\r\n this.inputAmount.currency,\r\n this.outputAmount.currency,\r\n this.inputAmount.raw,\r\n this.outputAmount.raw\r\n )\r\n this.nextMidPrice = Price.fromRoute(new Route(nextPairs, route.input))\r\n this.priceImpact = computePriceImpact(route.midPrice, this.inputAmount, this.outputAmount)\r\n }\r\n\r\n /**\r\n * Get the minimum amount that must be received from this trade for the given slippage tolerance\r\n * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade\r\n */\r\n public minimumAmountOut(slippageTolerance: Percent): CurrencyAmount {\r\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\r\n if (this.tradeType === TradeType.EXACT_OUTPUT) {\r\n return this.outputAmount\r\n } else {\r\n const slippageAdjustedAmountOut = new Fraction(ONE)\r\n .add(slippageTolerance)\r\n .invert()\r\n .multiply(this.outputAmount.raw).quotient\r\n return this.outputAmount instanceof TokenAmount\r\n ? new TokenAmount(this.outputAmount.token, slippageAdjustedAmountOut)\r\n : CurrencyAmount.ether(slippageAdjustedAmountOut)\r\n }\r\n }\r\n\r\n /**\r\n * Get the maximum amount in that can be spent via this trade for the given slippage tolerance\r\n * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade\r\n */\r\n public maximumAmountIn(slippageTolerance: Percent): CurrencyAmount {\r\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\r\n if (this.tradeType === TradeType.EXACT_INPUT) {\r\n return this.inputAmount\r\n } else {\r\n const slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.raw).quotient\r\n return this.inputAmount instanceof TokenAmount\r\n ? new TokenAmount(this.inputAmount.token, slippageAdjustedAmountIn)\r\n : CurrencyAmount.ether(slippageAdjustedAmountIn)\r\n }\r\n }\r\n\r\n /**\r\n * Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token\r\n * amount to an output token, making at most `maxHops` hops.\r\n * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting\r\n * the amount in among multiple routes.\r\n * @param pairs the pairs to consider in finding the best trade\r\n * @param currencyAmountIn exact amount of input currency to spend\r\n * @param currencyOut the desired currency out\r\n * @param maxNumResults maximum number of results to return\r\n * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair\r\n * @param currentPairs used in recursion; the current list of pairs\r\n * @param originalAmountIn used in recursion; the original value of the currencyAmountIn parameter\r\n * @param bestTrades used in recursion; the current list of best trades\r\n */\r\n public static bestTradeExactIn(\r\n pairs: Pair[],\r\n currencyAmountIn: CurrencyAmount,\r\n currencyOut: Currency,\r\n { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\r\n // used in recursion.\r\n currentPairs: Pair[] = [],\r\n originalAmountIn: CurrencyAmount = currencyAmountIn,\r\n bestTrades: Trade[] = []\r\n ): Trade[] {\r\n invariant(pairs.length > 0, 'PAIRS')\r\n invariant(maxHops > 0, 'MAX_HOPS')\r\n invariant(originalAmountIn === currencyAmountIn || currentPairs.length > 0, 'INVALID_RECURSION')\r\n const chainId: ChainId | undefined =\r\n currencyAmountIn instanceof TokenAmount\r\n ? currencyAmountIn.token.chainId\r\n : currencyOut instanceof Token\r\n ? currencyOut.chainId\r\n : undefined\r\n invariant(chainId !== undefined, 'CHAIN_ID')\r\n\r\n const amountIn = wrappedAmount(currencyAmountIn, chainId)\r\n const tokenOut = wrappedCurrency(currencyOut, chainId)\r\n for (let i = 0; i < pairs.length; i++) {\r\n const pair = pairs[i]\r\n // pair irrelevant\r\n if (!pair.token0.equals(amountIn.token) && !pair.token1.equals(amountIn.token)) continue\r\n if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue\r\n\r\n let amountOut: TokenAmount\r\n try {\r\n ;[amountOut] = pair.getOutputAmount(amountIn)\r\n } catch (error) {\r\n // input too low\r\n if (error.isInsufficientInputAmountError) {\r\n continue\r\n }\r\n throw error\r\n }\r\n // we have arrived at the output token, so this is the final trade of one of the paths\r\n if (amountOut.token.equals(tokenOut)) {\r\n sortedInsert(\r\n bestTrades,\r\n new Trade(\r\n new Route([...currentPairs, pair], originalAmountIn.currency, currencyOut),\r\n originalAmountIn,\r\n TradeType.EXACT_INPUT\r\n ),\r\n maxNumResults,\r\n tradeComparator\r\n )\r\n } else if (maxHops > 1 && pairs.length > 1) {\r\n const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length))\r\n\r\n // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops\r\n Trade.bestTradeExactIn(\r\n pairsExcludingThisPair,\r\n amountOut,\r\n currencyOut,\r\n {\r\n maxNumResults,\r\n maxHops: maxHops - 1\r\n },\r\n [...currentPairs, pair],\r\n originalAmountIn,\r\n bestTrades\r\n )\r\n }\r\n }\r\n\r\n return bestTrades\r\n }\r\n\r\n /**\r\n * similar to the above method but instead targets a fixed output amount\r\n * given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token\r\n * to an output token amount, making at most `maxHops` hops\r\n * note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting\r\n * the amount in among multiple routes.\r\n * @param pairs the pairs to consider in finding the best trade\r\n * @param currencyIn the currency to spend\r\n * @param currencyAmountOut the exact amount of currency out\r\n * @param maxNumResults maximum number of results to return\r\n * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair\r\n * @param currentPairs used in recursion; the current list of pairs\r\n * @param originalAmountOut used in recursion; the original value of the currencyAmountOut parameter\r\n * @param bestTrades used in recursion; the current list of best trades\r\n */\r\n public static bestTradeExactOut(\r\n pairs: Pair[],\r\n currencyIn: Currency,\r\n currencyAmountOut: CurrencyAmount,\r\n { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\r\n // used in recursion.\r\n currentPairs: Pair[] = [],\r\n originalAmountOut: CurrencyAmount = currencyAmountOut,\r\n bestTrades: Trade[] = []\r\n ): Trade[] {\r\n invariant(pairs.length > 0, 'PAIRS')\r\n invariant(maxHops > 0, 'MAX_HOPS')\r\n invariant(originalAmountOut === currencyAmountOut || currentPairs.length > 0, 'INVALID_RECURSION')\r\n const chainId: ChainId | undefined =\r\n currencyAmountOut instanceof TokenAmount\r\n ? currencyAmountOut.token.chainId\r\n : currencyIn instanceof Token\r\n ? currencyIn.chainId\r\n : undefined\r\n invariant(chainId !== undefined, 'CHAIN_ID')\r\n\r\n const amountOut = wrappedAmount(currencyAmountOut, chainId)\r\n const tokenIn = wrappedCurrency(currencyIn, chainId)\r\n for (let i = 0; i < pairs.length; i++) {\r\n const pair = pairs[i]\r\n // pair irrelevant\r\n if (!pair.token0.equals(amountOut.token) && !pair.token1.equals(amountOut.token)) continue\r\n if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue\r\n\r\n let amountIn: TokenAmount\r\n try {\r\n ;[amountIn] = pair.getInputAmount(amountOut)\r\n } catch (error) {\r\n // not enough liquidity in this pair\r\n if (error.isInsufficientReservesError) {\r\n continue\r\n }\r\n throw error\r\n }\r\n // we have arrived at the input token, so this is the first trade of one of the paths\r\n if (amountIn.token.equals(tokenIn)) {\r\n sortedInsert(\r\n bestTrades,\r\n new Trade(\r\n new Route([pair, ...currentPairs], currencyIn, originalAmountOut.currency),\r\n originalAmountOut,\r\n TradeType.EXACT_OUTPUT\r\n ),\r\n maxNumResults,\r\n tradeComparator\r\n )\r\n } else if (maxHops > 1 && pairs.length > 1) {\r\n const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length))\r\n\r\n // otherwise, consider all the other paths that arrive at this token as long as we have not exceeded maxHops\r\n Trade.bestTradeExactOut(\r\n pairsExcludingThisPair,\r\n currencyIn,\r\n amountIn,\r\n {\r\n maxNumResults,\r\n maxHops: maxHops - 1\r\n },\r\n [pair, ...currentPairs],\r\n originalAmountOut,\r\n bestTrades\r\n )\r\n }\r\n }\r\n\r\n return bestTrades\r\n }\r\n}\r\n","import { TradeType } from './constants'\r\nimport invariant from 'tiny-invariant'\r\nimport { validateAndParseAddress } from './utils'\r\nimport { CurrencyAmount, ETHER, Percent, Trade } from './entities'\r\n\r\n/**\r\n * Options for producing the arguments to send call to the router.\r\n */\r\nexport interface TradeOptions {\r\n /**\r\n * How much the execution price is allowed to move unfavorably from the trade execution price.\r\n */\r\n allowedSlippage: Percent\r\n /**\r\n * How long the swap is valid until it expires, in seconds.\r\n * This will be used to produce a `deadline` parameter which is computed from when the swap call parameters\r\n * are generated.\r\n */\r\n ttl: number\r\n /**\r\n * The account that should receive the output of the swap.\r\n */\r\n recipient: string\r\n\r\n /**\r\n * Whether any of the tokens in the path are fee on transfer tokens, which should be handled with special methods\r\n */\r\n feeOnTransfer?: boolean\r\n}\r\n\r\nexport interface TradeOptionsDeadline extends Omit<TradeOptions, 'ttl'> {\r\n /**\r\n * When the transaction expires.\r\n * This is an atlernate to specifying the ttl, for when you do not want to use local time.\r\n */\r\n deadline: number\r\n}\r\n\r\n/**\r\n * The parameters to use in the call to the Uniswap V2 Router to execute a trade.\r\n */\r\nexport interface SwapParameters {\r\n /**\r\n * The method to call on the Uniswap V2 Router.\r\n */\r\n methodName: string\r\n /**\r\n * The arguments to pass to the method, all hex encoded.\r\n */\r\n args: (string | string[])[]\r\n /**\r\n * The amount of wei to send in hex.\r\n */\r\n value: string\r\n}\r\n\r\nfunction toHex(currencyAmount: CurrencyAmount) {\r\n return `0x${currencyAmount.raw.toString(16)}`\r\n}\r\n\r\nconst ZERO_HEX = '0x0'\r\n\r\n/**\r\n * Represents the Uniswap V2 Router, and has static methods for helping execute trades.\r\n */\r\nexport abstract class Router {\r\n /**\r\n * Cannot be constructed.\r\n */\r\n private constructor() {}\r\n /**\r\n * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.\r\n * @param trade to produce call parameters for\r\n * @param options options for the call parameters\r\n */\r\n public static swapCallParameters(trade: Trade, options: TradeOptions | TradeOptionsDeadline): SwapParameters {\r\n const etherIn = trade.inputAmount.currency === ETHER\r\n const etherOut = trade.outputAmount.currency === ETHER\r\n // the router does not support both ether in and out\r\n invariant(!(etherIn && etherOut), 'ETHER_IN_OUT')\r\n invariant(!('ttl' in options) || options.ttl > 0, 'TTL')\r\n\r\n const to: string = validateAndParseAddress(options.recipient)\r\n const amountIn: string = toHex(trade.maximumAmountIn(options.allowedSlippage))\r\n const amountOut: string = toHex(trade.minimumAmountOut(options.allowedSlippage))\r\n const path: string[] = trade.route.path.map(token => token.address)\r\n const deadline =\r\n 'ttl' in options\r\n ? `0x${(Math.floor(new Date().getTime() / 1000) + options.ttl).toString(16)}`\r\n : `0x${options.deadline.toString(16)}`\r\n\r\n const useFeeOnTransfer = Boolean(options.feeOnTransfer)\r\n\r\n let methodName: string\r\n let args: (string | string[])[]\r\n let value: string\r\n switch (trade.tradeType) {\r\n case TradeType.EXACT_INPUT:\r\n if (etherIn) {\r\n methodName = useFeeOnTransfer ? 'swapExactETHForTokensSupportingFeeOnTransferTokens' : 'swapExactETHForTokens'\r\n // (uint amountOutMin, address[] calldata path, address to, uint deadline)\r\n args = [amountOut, path, to, deadline]\r\n value = amountIn\r\n } else if (etherOut) {\r\n methodName = useFeeOnTransfer ? 'swapExactTokensForETHSupportingFeeOnTransferTokens' : 'swapExactTokensForETH'\r\n // (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)\r\n args = [amountIn, amountOut, path, to, deadline]\r\n value = ZERO_HEX\r\n } else {\r\n methodName = useFeeOnTransfer\r\n ? 'swapExactTokensForTokensSupportingFeeOnTransferTokens'\r\n : 'swapExactTokensForTokens'\r\n // (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)\r\n args = [amountIn, amountOut, path, to, deadline]\r\n value = ZERO_HEX\r\n }\r\n break\r\n case TradeType.EXACT_OUTPUT:\r\n invariant(!useFeeOnTransfer, 'EXACT_OUT_FOT')\r\n if (etherIn) {\r\n methodName = 'swapETHForExactTokens'\r\n // (uint amountOut, address[] calldata path, address to, uint deadline)\r\n args = [amountOut, path, to, deadline]\r\n value = amountIn\r\n } else if (etherOut) {\r\n methodName = 'swapTokensForExactETH'\r\n // (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)\r\n args = [amountOut, amountIn, path, to, deadline]\r\n value = ZERO_HEX\r\n } else {\r\n methodName = 'swapTokensForExactTokens'\r\n // (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)\r\n args = [amountOut, amountIn, path, to, deadline]\r\n value = ZERO_HEX\r\n }\r\n break\r\n }\r\n return {\r\n methodName,\r\n args,\r\n value\r\n }\r\n }\r\n}\r\n","import { Contract } from '@ethersproject/contracts'\r\nimport { getNetwork } from '@ethersproject/networks'\r\nimport { getDefaultProvider } from '@ethersproject/providers'\r\nimport { TokenAmount } from './entities/fractions/tokenAmount'\r\nimport { Pair } from './entities/pair'\r\nimport IUniswapV2Pair from '@uniswap/v2-core/build/IUniswapV2Pair.json'\r\nimport invariant from 'tiny-invariant'\r\nimport ERC20 from './abis/ERC20.json'\r\nimport { ChainId } from './constants'\r\nimport { Token } from './entities/token'\r\n\r\nlet TOKEN_DECIMALS_CACHE: { [chainId: number]: { [address: string]: number } } = {\r\n [ChainId.MAINNET]: {\r\n '0xE0B7927c4aF23765Cb51314A0E0521A9645F0E2A': 9 // DGD\r\n }\r\n}\r\n\r\n/**\r\n * Contains methods for constructing instances of pairs and tokens from on-chain data.\r\n */\r\nexport abstract class Fetcher {\r\n /**\r\n * Cannot be constructed.\r\n */\r\n private constructor() {}\r\n\r\n /**\r\n * Fetch information for a given token on the given chain, using the given ethers provider.\r\n * @param chainId chain of the token\r\n * @param address address of the token on the chain\r\n * @param provider provider used to fetch the token\r\n * @param symbol optional symbol of the token\r\n * @param name optional name of the token\r\n */\r\n public static async fetchTokenData(\r\n chainId: ChainId,\r\n address: string,\r\n provider = getDefaultProvider(getNetwork(chainId)),\r\n symbol?: string,\r\n name?: string\r\n ): Promise<Token> {\r\n const parsedDecimals =\r\n typeof TOKEN_DECIMALS_CACHE?.[chainId]?.[address] === 'number'\r\n ? TOKEN_DECIMALS_CACHE[chainId][address]\r\n : await new Contract(address, ERC20, provider).decimals().then((decimals: number): number => {\r\n TOKEN_DECIMALS_CACHE = {\r\n ...TOKEN_DECIMALS_CACHE,\r\n [chainId]: {\r\n ...TOKEN_DECIMALS_CACHE?.[chainId],\r\n [address]: decimals\r\n }\r\n }\r\n return decimals\r\n })\r\n return new Token(chainId, address, parsedDecimals, symbol, name)\r\n }\r\n\r\n /**\r\n * Fetches information about a pair and constructs a pair from the given two tokens.\r\n * @param tokenA first token\r\n * @param tokenB second token\r\n * @param provider the provider to use to fetch the data\r\n */\r\n public static async fetchPairData(\r\n tokenA: Token,\r\n tokenB: Token,\r\n provider = getDefaultProvider(getNetwork(tokenA.chainId))\r\n ): Promise<Pair> {\r\n invariant(tokenA.chainId === tokenB.chainId, 'CHAIN_ID')\r\n const address = Pair.getAddress(tokenA, tokenB)\r\n const [reserves0, reserves1] = await new Contract(address, IUniswapV2Pair.abi, provider).getReserves()\r\n const balances = tokenA.sortsBefore(tokenB) ? [reserves0, reserves1] : [reserves1, reserves0]\r\n return new Pair(new TokenAmount(tokenA, balances[0]), new TokenAmount(tokenB, balances[1]))\r\n }\r\n}\r\n"],"names":["ChainId","TradeType","Rounding","FACTORY_ADDRESS","INIT_CODE_HASH","MINIMUM_LIQUIDITY","JSBI","BigInt","ZERO","ONE","TWO","THREE","FIVE","TEN","_100","_997","_1000","SolidityType","SOLIDITY_TYPE_MAXIMA","uint8","uint256","CAN_SET_PROTOTYPE","Object","InsufficientReservesError","name","constructor","setPrototypeOf","prototype","Error","InsufficientInputAmountError","validateSolidityTypeInstance","value","solidityType","greaterThanOrEqual","invariant","lessThanOrEqual","validateAndParseAddress","address","checksummedAddress","getAddress","warning","error","parseBigintIsh","bigintIsh","toString","sqrt","y","z","x","greaterThan","add","divide","lessThan","notEqual","sortedInsert","items","maxSize","comparator","length","push","isFull","lo","hi","mid","splice","pop","Currency","decimals","symbol","change","cId","ETHER","Token","chainId","equals","other","sortsBefore","toLowerCase","currencyEquals","currencyA","currencyB","WETH","MAINNET","ROPSTEN","RINKEBY","GÖRLI","KOVAN","BINANCE","BINANCETEST","RSK","RSKTEST","XDAI","POLYGON","Decimal","toFormat","_Decimal","Big","_Big","toSignificantRounding","ROUND_DOWN","ROUND_HALF_UP","ROUND_UP","toFixedRounding","Fraction","numerator","denominator","invert","otherParsed","equal","multiply","subtract","equalTo","toSignificant","significantDigits","format","rounding","groupSeparator","Number","isInteger","set","precision","quotient","div","toSignificantDigits","decimalPlaces","toFixed","DP","RM","remainder","CurrencyAmount","currency","amount","parsedAmount","exponentiate","ether","raw","toExact","TokenAmount","token","Price","baseCurrency","quoteCurrency","scalar","fromRoute","route","prices","pairs","entries","i","pair","path","token0","reserve0","reserve1","slice","reduce","accumulator","currentValue","fraction","quote","currencyAmount","adjusted","PAIR_ADDRESS_CACHE","Pair","tokenAmountA","tokenAmountB","tokenAmounts","liquidityToken","tokenA","tokenB","tokens","undefined","getCreate2Address","keccak256","pack","involvesToken","token1","priceOf","token0Price","token1Price","reserveOf","getOutputAmount","inputAmount","inputReserve","outputReserve","inputAmountWithFee","outputAmount","getInputAmount","getLiquidityMinted","totalSupply","liquidity","amount0","amount1","getLiquidityValue","feeOn","kLast","totalSupplyAdjusted","kLastParsed","rootK","rootKLast","feeLiquidity","Route","input","output","every","currentInput","midPrice","_100_PERCENT","Percent","computePriceImpact","exactQuote","slippage","inputOutputComparator","a","b","tradeComparator","ioComp","priceImpact","wrappedAmount","wrappedCurrency","Trade","tradeType","amounts","Array","nextPairs","EXACT_INPUT","nextPair","EXACT_OUTPUT","executionPrice","nextMidPrice","exactIn","amountIn","exactOut","amountOut","minimumAmountOut","slippageTolerance","slippageAdjustedAmountOut","maximumAmountIn","slippageAdjustedAmountIn","bestTradeExactIn","currencyAmountIn","currencyOut","currentPairs","originalAmountIn","bestTrades","maxNumResults","maxHops","tokenOut","isInsufficientInputAmountError","pairsExcludingThisPair","concat","bestTradeExactOut","currencyIn","currencyAmountOut","originalAmountOut","tokenIn","isInsufficientReservesError","toHex","ZERO_HEX","Router","swapCallParameters","trade","options","etherIn","etherOut","ttl","to","recipient","allowedSlippage","map","deadline","Math","floor","Date","getTime","useFeeOnTransfer","Boolean","feeOnTransfer","methodName","args","TOKEN_DECIMALS_CACHE","Fetcher","fetchTokenData","provider","parsedDecimals","getDefaultProvider","getNetwork","Contract","ERC20","then","fetchPairData","IUniswapV2Pair","abi","getReserves","reserves0","reserves1","balances"],"mappings":";;;;;;;;;;;;;;;IAKYA;;AAAZ,WAAYA;AACVA,EAAAA,+BAAA,YAAA;AACAA,EAAAA,+BAAA,YAAA;AACAA,EAAAA,+BAAA,YAAA;AACAA,EAAAA,gCAAA,aAAA;AACAA,EAAAA,4BAAA,QAAA;AACAA,EAAAA,gCAAA,YAAA;AACAA,EAAAA,8BAAA,UAAA;AACAA,EAAAA,gCAAA,YAAA;AACAA,EAAAA,oCAAA,gBAAA;AACAA,EAAAA,8BAAA,SAAA;AACAA,EAAAA,iCAAA,YAAA;AACD,CAZD,EAAYA,OAAO,KAAPA,OAAO,KAAA,CAAnB;;IAcYC;;AAAZ,WAAYA;AACVA,EAAAA,uCAAA,gBAAA;AACAA,EAAAA,wCAAA,iBAAA;AACD,CAHD,EAAYA,SAAS,KAATA,SAAS,KAAA,CAArB;;IAKYC;;AAAZ,WAAYA;AACVA,EAAAA,oCAAA,eAAA;AACAA,EAAAA,uCAAA,kBAAA;AACAA,EAAAA,kCAAA,aAAA;AACD,CAJD,EAAYA,QAAQ,KAARA,QAAQ,KAAA,CAApB;;IAMaC,eAAe,GAAG;IAElBC,cAAc,GAAG;IAEjBC,iBAAiB,gBAAGC,IAAI,CAACC,MAAL,CAAY,IAAZ;;AAG1B,IAAMC,IAAI,gBAAGF,IAAI,CAACC,MAAL,CAAY,CAAZ,CAAb;AACA,IAAME,GAAG,gBAAGH,IAAI,CAACC,MAAL,CAAY,CAAZ,CAAZ;AACA,IAAMG,GAAG,gBAAGJ,IAAI,CAACC,MAAL,CAAY,CAAZ,CAAZ;AACA,IAAMI,KAAK,gBAAGL,IAAI,CAACC,MAAL,CAAY,CAAZ,CAAd;AACA,IAAMK,IAAI,gBAAGN,IAAI,CAACC,MAAL,CAAY,CAAZ,CAAb;AACA,IAA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package/dist/utils.d.ts
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
import JSBI from 'jsbi';
|
2
|
+
import { BigintIsh, SolidityType } from './constants';
|
3
|
+
export declare function validateSolidityTypeInstance(value: JSBI, solidityType: SolidityType): void;
|
4
|
+
export declare function validateAndParseAddress(address: string): string;
|
5
|
+
export declare function parseBigintIsh(bigintIsh: BigintIsh): JSBI;
|
6
|
+
export declare function sqrt(y: JSBI): JSBI;
|
7
|
+
export declare function sortedInsert<T>(items: T[], add: T, maxSize: number, comparator: (a: T, b: T) => number): T | null;
|
package/package.json
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
{
|
2
|
+
"name": "@sebtoday/u-exchange-sdk",
|
3
|
+
"license": "MIT",
|
4
|
+
"version": "1.0.5",
|
5
|
+
"description": "🛠 An SDK for building applications on top of U.EXCHANGE.",
|
6
|
+
"main": "dist/index.js",
|
7
|
+
"typings": "dist/index.d.ts",
|
8
|
+
"files": [
|
9
|
+
"dist"
|
10
|
+
],
|
11
|
+
"repository": {
|
12
|
+
"type": "git",
|
13
|
+
"url": "git+https://github.com/antron3000/u-exchange-sdk.git"
|
14
|
+
},
|
15
|
+
"keywords": [
|
16
|
+
"u-exchange",
|
17
|
+
"ethereum"
|
18
|
+
],
|
19
|
+
"module": "dist/sdk.esm.js",
|
20
|
+
"scripts": {
|
21
|
+
"lint": "tsdx lint src test",
|
22
|
+
"build": "tsdx build",
|
23
|
+
"start": "tsdx watch",
|
24
|
+
"test": "tsdx test",
|
25
|
+
"prepublishOnly": "tsdx build"
|
26
|
+
},
|
27
|
+
"dependencies": {
|
28
|
+
"@uniswap/v2-core": "^1.0.0",
|
29
|
+
"big.js": "^5.2.2",
|
30
|
+
"decimal.js-light": "^2.5.0",
|
31
|
+
"jsbi": "^3.1.1",
|
32
|
+
"tiny-invariant": "^1.1.0",
|
33
|
+
"tiny-warning": "^1.0.3",
|
34
|
+
"toformat": "^2.0.0"
|
35
|
+
},
|
36
|
+
"peerDependencies": {
|
37
|
+
"@ethersproject/address": "^5.0.0-beta",
|
38
|
+
"@ethersproject/contracts": "^5.0.0-beta",
|
39
|
+
"@ethersproject/networks": "^5.0.0-beta",
|
40
|
+
"@ethersproject/providers": "^5.0.0-beta",
|
41
|
+
"@ethersproject/solidity": "^5.0.0-beta"
|
42
|
+
},
|
43
|
+
"devDependencies": {
|
44
|
+
"@ethersproject/address": "^5.0.2",
|
45
|
+
"@ethersproject/contracts": "^5.0.2",
|
46
|
+
"@ethersproject/networks": "^5.0.2",
|
47
|
+
"@ethersproject/providers": "^5.0.5",
|
48
|
+
"@ethersproject/solidity": "^5.0.2",
|
49
|
+
"@types/big.js": "^4.0.5",
|
50
|
+
"@types/jest": "^24.0.25",
|
51
|
+
"babel-plugin-transform-jsbi-to-bigint": "^1.3.1",
|
52
|
+
"tsdx": "^0.12.3"
|
53
|
+
},
|
54
|
+
"engines": {
|
55
|
+
"node": ">=10"
|
56
|
+
},
|
57
|
+
"prettier": {
|
58
|
+
"printWidth": 120,
|
59
|
+
"semi": false,
|
60
|
+
"singleQuote": true
|
61
|
+
},
|
62
|
+
"bugs": {
|
63
|
+
"url": "https://github.com/UdotCASH/u-exchange-sdk/issues"
|
64
|
+
},
|
65
|
+
"homepage": "https://github.com/UdotCASH/u-exchange-sdk#readme",
|
66
|
+
"directories": {
|
67
|
+
"test": "test"
|
68
|
+
},
|
69
|
+
"author": "udotcash"
|
70
|
+
}
|