UNPKG

@photonswap/sdk

Version:

🛠 An example SDK for building applications on top of Photonswap.

1,175 lines (946 loc) • 70.1 kB
import JSBI from 'jsbi'; export { default as JSBI } from 'jsbi'; import invariant from 'tiny-invariant'; import warning from 'tiny-warning'; import { getAddress, getCreate2Address } from '@ethersproject/address'; import _Big from 'big.js'; import toFormat from 'toformat'; import _Decimal from 'decimal.js-light'; import { keccak256, pack } from '@ethersproject/solidity'; import { Contract } from '@ethersproject/contracts'; import { getNetwork } from '@ethersproject/networks'; import { getDefaultProvider } from '@ethersproject/providers'; import IUniswapV2Pair from '@uniswap/v2-core/build/IUniswapV2Pair.json'; var _FACTORY_ADDRESSES, _INIT_CODE_HASH, _SOLIDITY_TYPE_MAXIMA; var ChainId; (function (ChainId) { ChainId[ChainId["CRONOSMAINNET"] = 25] = "CRONOSMAINNET"; ChainId[ChainId["CRONOSTEST"] = 338] = "CRONOSTEST"; ChainId[ChainId["BSC_TEST_NET"] = 97] = "BSC_TEST_NET"; ChainId[ChainId["CASSINI"] = 339] = "CASSINI"; ChainId[ChainId["MUMBAI_TESTNET"] = 80001] = "MUMBAI_TESTNET"; ChainId[ChainId["EVMOS_TESTNET"] = 9000] = "EVMOS_TESTNET"; ChainId[ChainId["EVMOS_MAINNET"] = 9001] = "EVMOS_MAINNET"; ChainId[ChainId["KAVA_TESTNET"] = 2221] = "KAVA_TESTNET"; ChainId[ChainId["KAVA_MAINNET"] = 2222] = "KAVA_MAINNET"; ChainId[ChainId["SHARDEUM_LIBERTY_TESTNET"] = 8080] = "SHARDEUM_LIBERTY_TESTNET"; ChainId[ChainId["HAQQ_TESTNET"] = 53211] = "HAQQ_TESTNET"; ChainId[ChainId["REBUS_TESTNET"] = 3333] = "REBUS_TESTNET"; ChainId[ChainId["MINTME_MAINNET"] = 24734] = "MINTME_MAINNET"; ChainId[ChainId["POLYGON_ZK_TESTNET"] = 1402] = "POLYGON_ZK_TESTNET"; ChainId[ChainId["MANTLE_TESTNET"] = 5001] = "MANTLE_TESTNET"; ChainId[ChainId["PEPE_CHAIN"] = 906090] = "PEPE_CHAIN"; ChainId[ChainId["SEPOLIA"] = 11155111] = "SEPOLIA"; })(ChainId || (ChainId = {})); var TradeType; (function (TradeType) { TradeType[TradeType["EXACT_INPUT"] = 0] = "EXACT_INPUT"; TradeType[TradeType["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT"; })(TradeType || (TradeType = {})); var Rounding; (function (Rounding) { Rounding[Rounding["ROUND_DOWN"] = 0] = "ROUND_DOWN"; Rounding[Rounding["ROUND_HALF_UP"] = 1] = "ROUND_HALF_UP"; Rounding[Rounding["ROUND_UP"] = 2] = "ROUND_UP"; })(Rounding || (Rounding = {})); var FACTORY_ADDRESSES = (_FACTORY_ADDRESSES = {}, _FACTORY_ADDRESSES[ChainId.CRONOSMAINNET] = '0x462C98Cae5AffEED576c98A55dAA922604e2D875', _FACTORY_ADDRESSES[ChainId.CRONOSTEST] = '0xF9db97007782ae35051a97790766531684C4943c', _FACTORY_ADDRESSES[ChainId.BSC_TEST_NET] = '0x4117FfdD251fD54fe0dfa3Ff89b9f3a2a3d370a1', _FACTORY_ADDRESSES[ChainId.CASSINI] = '0xD4bbbA8812263f82f97866d1fe7961eB02D695c3', _FACTORY_ADDRESSES[ChainId.MUMBAI_TESTNET] = '0xD4bbbA8812263f82f97866d1fe7961eB02D695c3', _FACTORY_ADDRESSES[ChainId.EVMOS_TESTNET] = '0xa95D850cad9f5c9c43f63755c3F8f5f0a7913a1f', _FACTORY_ADDRESSES[ChainId.EVMOS_MAINNET] = '0x1c671d6fEC45Ec0de88C82e6D8536bFe33F00c8a', _FACTORY_ADDRESSES[ChainId.KAVA_TESTNET] = '0x1c671d6fEC45Ec0de88C82e6D8536bFe33F00c8a', _FACTORY_ADDRESSES[ChainId.KAVA_MAINNET] = '0x4FD2c40c25Dd40e9Bf0CE8479bA384178b8671b5', _FACTORY_ADDRESSES[ChainId.SHARDEUM_LIBERTY_TESTNET] = '0x4FD2c40c25Dd40e9Bf0CE8479bA384178b8671b5', _FACTORY_ADDRESSES[ChainId.HAQQ_TESTNET] = '0x1c671d6fEC45Ec0de88C82e6D8536bFe33F00c8a', _FACTORY_ADDRESSES[ChainId.REBUS_TESTNET] = '0x361Fcc661938cD5a99C4AdacE77f2Bf0a5fe1314', _FACTORY_ADDRESSES[ChainId.MINTME_MAINNET] = '0x9E91c2bff4a5504898a33186c19901d786B394cD', _FACTORY_ADDRESSES[ChainId.POLYGON_ZK_TESTNET] = '0x6c6A6F2a8113f11d3F5C860ac5fD80a7398e8d2e', _FACTORY_ADDRESSES[ChainId.MANTLE_TESTNET] = '0x1c671d6fEC45Ec0de88C82e6D8536bFe33F00c8a', _FACTORY_ADDRESSES[ChainId.PEPE_CHAIN] = '0x1c671d6fEC45Ec0de88C82e6D8536bFe33F00c8a', _FACTORY_ADDRESSES[ChainId.SEPOLIA] = '0x1c671d6fEC45Ec0de88C82e6D8536bFe33F00c8a', _FACTORY_ADDRESSES); var INIT_CODE_HASH = (_INIT_CODE_HASH = {}, _INIT_CODE_HASH[ChainId.CRONOSTEST] = '0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c', _INIT_CODE_HASH[ChainId.CRONOSMAINNET] = '0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c', _INIT_CODE_HASH[ChainId.BSC_TEST_NET] = '0xcbd5bfb195b0b40a24ed317b4dda6b82614ee29ab16622fe28aa0d62c15da783', _INIT_CODE_HASH[ChainId.CASSINI] = '0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c', _INIT_CODE_HASH[ChainId.MUMBAI_TESTNET] = '0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c', _INIT_CODE_HASH[ChainId.EVMOS_TESTNET] = '0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c', _INIT_CODE_HASH[ChainId.EVMOS_MAINNET] = '0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c', _INIT_CODE_HASH[ChainId.KAVA_TESTNET] = '0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c', _INIT_CODE_HASH[ChainId.KAVA_MAINNET] = '0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c', _INIT_CODE_HASH[ChainId.SHARDEUM_LIBERTY_TESTNET] = '0xcbd5bfb195b0b40a24ed317b4dda6b82614ee29ab16622fe28aa0d62c15da783', _INIT_CODE_HASH[ChainId.HAQQ_TESTNET] = '0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c', _INIT_CODE_HASH[ChainId.REBUS_TESTNET] = '0x1cd980072399273f55deb8c618cb6873f43e3fe305ee432ee3b9b5ff9116555d', _INIT_CODE_HASH[ChainId.MINTME_MAINNET] = '0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c', _INIT_CODE_HASH[ChainId.POLYGON_ZK_TESTNET] = '0xcbd5bfb195b0b40a24ed317b4dda6b82614ee29ab16622fe28aa0d62c15da783', _INIT_CODE_HASH[ChainId.MANTLE_TESTNET] = '0xcbd5bfb195b0b40a24ed317b4dda6b82614ee29ab16622fe28aa0d62c15da783', _INIT_CODE_HASH[ChainId.PEPE_CHAIN] = '0xcbd5bfb195b0b40a24ed317b4dda6b82614ee29ab16622fe28aa0d62c15da783', _INIT_CODE_HASH[ChainId.SEPOLIA] = '0xcbd5bfb195b0b40a24ed317b4dda6b82614ee29ab16622fe28aa0d62c15da783', _INIT_CODE_HASH); var MINIMUM_LIQUIDITY = /*#__PURE__*/JSBI.BigInt(100); // exports for internal consumption var ZERO = /*#__PURE__*/JSBI.BigInt(0); var ONE = /*#__PURE__*/JSBI.BigInt(1); var TWO = /*#__PURE__*/JSBI.BigInt(2); var THREE = /*#__PURE__*/JSBI.BigInt(3); var FIVE = /*#__PURE__*/JSBI.BigInt(5); var TEN = /*#__PURE__*/JSBI.BigInt(10); var _100 = /*#__PURE__*/JSBI.BigInt(100); var _997 = /*#__PURE__*/JSBI.BigInt(997); var _1000 = /*#__PURE__*/JSBI.BigInt(1000); var SolidityType; (function (SolidityType) { SolidityType["uint8"] = "uint8"; SolidityType["uint256"] = "uint256"; })(SolidityType || (SolidityType = {})); var SOLIDITY_TYPE_MAXIMA = (_SOLIDITY_TYPE_MAXIMA = {}, _SOLIDITY_TYPE_MAXIMA[SolidityType.uint8] = /*#__PURE__*/JSBI.BigInt('0xff'), _SOLIDITY_TYPE_MAXIMA[SolidityType.uint256] = /*#__PURE__*/JSBI.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), _SOLIDITY_TYPE_MAXIMA); function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } // see https://stackoverflow.com/a/41102306 var CAN_SET_PROTOTYPE = ('setPrototypeOf' in Object); /** * Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be * obtained by sending any amount of input. */ var InsufficientReservesError = /*#__PURE__*/function (_Error) { _inheritsLoose(InsufficientReservesError, _Error); function InsufficientReservesError() { var _this; _this = _Error.call(this) || this; _this.isInsufficientReservesError = true; _this.name = _this.constructor.name; if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(_assertThisInitialized(_this), (this instanceof InsufficientReservesError ? this.constructor : void 0).prototype); return _this; } return InsufficientReservesError; }( /*#__PURE__*/_wrapNativeSuper(Error)); /** * Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less * than the price of a single unit of output after fees. */ var InsufficientInputAmountError = /*#__PURE__*/function (_Error2) { _inheritsLoose(InsufficientInputAmountError, _Error2); function InsufficientInputAmountError() { var _this2; _this2 = _Error2.call(this) || this; _this2.isInsufficientInputAmountError = true; _this2.name = _this2.constructor.name; if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(_assertThisInitialized(_this2), (this instanceof InsufficientInputAmountError ? this.constructor : void 0).prototype); return _this2; } return InsufficientInputAmountError; }( /*#__PURE__*/_wrapNativeSuper(Error)); function validateSolidityTypeInstance(value, solidityType) { !JSBI.greaterThanOrEqual(value, ZERO) ? process.env.NODE_ENV !== "production" ? invariant(false, value + " is not a " + solidityType + ".") : invariant(false) : void 0; !JSBI.lessThanOrEqual(value, SOLIDITY_TYPE_MAXIMA[solidityType]) ? process.env.NODE_ENV !== "production" ? invariant(false, value + " is not a " + solidityType + ".") : invariant(false) : void 0; } // warns if addresses are not checksummed function validateAndParseAddress(address) { try { var checksummedAddress = getAddress(address); process.env.NODE_ENV !== "production" ? warning(address === checksummedAddress, address + " is not checksummed.") : void 0; return checksummedAddress; } catch (error) { process.env.NODE_ENV !== "production" ? invariant(false, address + " is not a valid address.") : invariant(false) ; } } function parseBigintIsh(bigintIsh) { return bigintIsh instanceof JSBI ? bigintIsh : typeof bigintIsh === 'bigint' ? JSBI.BigInt(bigintIsh.toString()) : JSBI.BigInt(bigintIsh); } // mock the on-chain sqrt function function sqrt(y) { validateSolidityTypeInstance(y, SolidityType.uint256); var z = ZERO; var x; if (JSBI.greaterThan(y, THREE)) { z = y; x = JSBI.add(JSBI.divide(y, TWO), ONE); while (JSBI.lessThan(x, z)) { z = x; x = JSBI.divide(JSBI.add(JSBI.divide(y, x), x), TWO); } } else if (JSBI.notEqual(y, ZERO)) { z = ONE; } return z; } // given an array of items sorted by `comparator`, insert an item into its sort index and constrain the size to // `maxSize` by removing the last item function sortedInsert(items, add, maxSize, comparator) { !(maxSize > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MAX_SIZE_ZERO') : invariant(false) : void 0; // this is an invariant because the interface cannot return multiple removed items if items.length exceeds maxSize !(items.length <= maxSize) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ITEMS_SIZE') : invariant(false) : void 0; // short circuit first item add if (items.length === 0) { items.push(add); return null; } else { var isFull = items.length === maxSize; // short circuit if full and the additional item does not come before the last item if (isFull && comparator(items[items.length - 1], add) <= 0) { return add; } var lo = 0, hi = items.length; while (lo < hi) { var mid = lo + hi >>> 1; if (comparator(items[mid], add) <= 0) { lo = mid + 1; } else { hi = mid; } } items.splice(lo, 0, add); return isFull ? items.pop() : null; } } /** * A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens. * * The only instance of the base class `Currency` is Ether. */ var Currency = /*#__PURE__*/function () { /** * Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`. * @param decimals decimals of the currency * @param symbol symbol of the currency * @param name of the currency */ function Currency(decimals, symbol, name) { validateSolidityTypeInstance(JSBI.BigInt(decimals), SolidityType.uint8); this.decimals = decimals; this.symbol = symbol; this.name = name; } var _proto = Currency.prototype; _proto.getDisplaySymbol = function getDisplaySymbol(chainId) { if (this.symbol == 'ETHER') { switch (chainId) { case ChainId.BSC_TEST_NET: return "BNB"; case ChainId.CRONOSTEST: case ChainId.CRONOSMAINNET: case ChainId.CASSINI: return "CRO"; case ChainId.MUMBAI_TESTNET: return "MATIC"; case ChainId.EVMOS_TESTNET: case ChainId.EVMOS_MAINNET: return "EVMOS"; case ChainId.KAVA_TESTNET: case ChainId.KAVA_MAINNET: return "KAVA"; case ChainId.SHARDEUM_LIBERTY_TESTNET: return "SHM"; case ChainId.HAQQ_TESTNET: return "ISLM"; case ChainId.REBUS_TESTNET: return "REBUS"; case ChainId.MINTME_MAINNET: return "MINTME"; case ChainId.POLYGON_ZK_TESTNET: return "ETHER"; case ChainId.MANTLE_TESTNET: return "BIT"; case ChainId.PEPE_CHAIN: return "ETH"; case ChainId.SEPOLIA: return "ETH"; } } return this.symbol; }; return Currency; }(); /** * The only instance of the base class `Currency`. */ Currency.ETHER = /*#__PURE__*/new Currency(18, 'ETHER', 'Eth'); Currency.BNB = /*#__PURE__*/new Currency(18, 'BNB', 'BNB'); Currency.CRO = /*#__PURE__*/new Currency(18, 'CRO', 'CRO'); Currency.MATIC = /*#__PURE__*/new Currency(18, 'MATIC', 'Matic'); Currency.EVMOS = /*#__PURE__*/new Currency(18, 'EVMOS', 'EVMOS'); Currency.KAVA = /*#__PURE__*/new Currency(18, 'KAVA', 'KAVA'); Currency.SHARDEUM = /*#__PURE__*/new Currency(18, 'SHM', 'SHARDEUM'); Currency.ISLM = /*#__PURE__*/new Currency(18, 'ISLM', 'ISLAMCOIN'); Currency.REBUS = /*#__PURE__*/new Currency(18, 'REBUS', 'REBUS'); Currency.MINTME = /*#__PURE__*/new Currency(18, 'MINTME', 'MINTME'); var ETHER = Currency.ETHER; var _WETH; /** * Represents an ERC20 token with a unique address and some metadata. */ var Token = /*#__PURE__*/function (_Currency) { _inheritsLoose(Token, _Currency); function Token(chainId, address, decimals, symbol, name) { var _this; _this = _Currency.call(this, decimals, symbol, name) || this; _this.chainId = chainId; _this.address = validateAndParseAddress(address); return _this; } /** * Returns true if the two tokens are equivalent, i.e. have the same chainId and address. * @param other other token to compare */ var _proto = Token.prototype; _proto.equals = function equals(other) { // short circuit on reference equality if (this === other) { return true; } return this.chainId === other.chainId && this.address === other.address; } /** * Returns true if the address of this token sorts before the address of the other token * @param other other token to compare * @throws if the tokens have the same address * @throws if the tokens are on different chains */ ; _proto.sortsBefore = function sortsBefore(other) { !(this.chainId === other.chainId) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_IDS') : invariant(false) : void 0; !(this.address !== other.address) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ADDRESSES') : invariant(false) : void 0; return this.address.toLowerCase() < other.address.toLowerCase(); }; return Token; }(Currency); /** * Compares two currencies for equality */ function currencyEquals(currencyA, currencyB) { if (currencyA instanceof Token && currencyB instanceof Token) { return currencyA.equals(currencyB); } else if (currencyA instanceof Token) { return false; } else if (currencyB instanceof Token) { return false; } else { return currencyA === currencyB; } } var WETH = (_WETH = {}, _WETH[ChainId.CRONOSMAINNET] = /*#__PURE__*/new Token(ChainId.CRONOSMAINNET, '0x5c7f8a570d578ed84e63fdfa7b1ee72deae1ae23', 18, 'WCRO', 'Wrapped Cronos'), _WETH[ChainId.CRONOSTEST] = /*#__PURE__*/new Token(ChainId.CRONOSTEST, '0xa85d35eb8E439078a1810Ec3738997E61d157f0d', 18, 'WCRO', 'Wrapped Cronos'), _WETH[ChainId.BSC_TEST_NET] = /*#__PURE__*/new Token(ChainId.BSC_TEST_NET, '0x6820305F97141dAe62bBacf73a3b09a01edfCBD9', 18, 'WBNB', 'Wrapped BNB'), _WETH[ChainId.CASSINI] = /*#__PURE__*/new Token(ChainId.CASSINI, '0x77e66C840e7198C95500f7f547543E1466C5CB2c', 18, 'WCRO', 'Wrapped Cronos'), _WETH[ChainId.MUMBAI_TESTNET] = /*#__PURE__*/new Token(ChainId.MUMBAI_TESTNET, '0x77e66C840e7198C95500f7f547543E1466C5CB2c', 18, 'WMATIC', 'Wrapped Matic'), _WETH[ChainId.EVMOS_TESTNET] = /*#__PURE__*/new Token(ChainId.EVMOS_TESTNET, '0xc8A2413D8ac65eC936F7350d6FF62ec603004565', 18, 'WEVMOS', 'Wrapped EVMOS'), _WETH[ChainId.KAVA_TESTNET] = /*#__PURE__*/new Token(ChainId.KAVA_TESTNET, '0xbAAFeC4B6eF4F5E0bAFA850CBC48364B953EFCf9', 18, 'WKAVA', 'Wrapped KAVA'), _WETH[ChainId.KAVA_MAINNET] = /*#__PURE__*/new Token(ChainId.KAVA_MAINNET, '0xc86c7C0eFbd6A49B35E8714C5f59D99De09A225b', 18, 'WKAVA', 'Wrapped KAVA'), _WETH[ChainId.MANTLE_TESTNET] = /*#__PURE__*/new Token(ChainId.MANTLE_TESTNET, '0xbAAFeC4B6eF4F5E0bAFA850CBC48364B953EFCf9', 18, 'WBIT', 'Wrapped BIT'), _WETH[ChainId.SHARDEUM_LIBERTY_TESTNET] = /*#__PURE__*/new Token(ChainId.SHARDEUM_LIBERTY_TESTNET, '0x1c671d6fEC45Ec0de88C82e6D8536bFe33F00c8a', 18, 'WSHM', 'Wrapped SHM'), _WETH[ChainId.EVMOS_MAINNET] = /*#__PURE__*/new Token(ChainId.EVMOS_MAINNET, '0xD4949664cD82660AaE99bEdc034a0deA8A0bd517', 18, 'WEVMOS', 'Wrapped EVMOS'), _WETH[ChainId.HAQQ_TESTNET] = /*#__PURE__*/new Token(ChainId.HAQQ_TESTNET, '0xbAAFeC4B6eF4F5E0bAFA850CBC48364B953EFCf9', 18, 'WISLM', 'Wrapped ISLM'), _WETH[ChainId.REBUS_TESTNET] = /*#__PURE__*/new Token(ChainId.REBUS_TESTNET, '0x1A3d70c6Ba491680393F6a05140B09358A78CFd2', 18, 'WREBUS', 'Wrapped Rebus'), _WETH[ChainId.MINTME_MAINNET] = /*#__PURE__*/new Token(ChainId.MINTME_MAINNET, '0xa297432E5c707435cd2249f78978206626dcA17C', 18, 'WMINTME', 'Wrapped MINTME'), _WETH[ChainId.POLYGON_ZK_TESTNET] = /*#__PURE__*/new Token(ChainId.POLYGON_ZK_TESTNET, '0x65A0fC432f88aF171656E707709863E82F3e0775', 18, 'WETH', 'Wrapped Ether'), _WETH[ChainId.PEPE_CHAIN] = /*#__PURE__*/new Token(ChainId.PEPE_CHAIN, '0xbAAFeC4B6eF4F5E0bAFA850CBC48364B953EFCf9', 18, 'WETH', 'Wrapped Ether'), _WETH[ChainId.SEPOLIA] = /*#__PURE__*/new Token(ChainId.SEPOLIA, '0xbAAFeC4B6eF4F5E0bAFA850CBC48364B953EFCf9', 18, 'WETH', 'Wrapped Ether'), _WETH); var _toSignificantRoundin, _toFixedRounding; var Decimal = /*#__PURE__*/toFormat(_Decimal); var Big = /*#__PURE__*/toFormat(_Big); var toSignificantRounding = (_toSignificantRoundin = {}, _toSignificantRoundin[Rounding.ROUND_DOWN] = Decimal.ROUND_DOWN, _toSignificantRoundin[Rounding.ROUND_HALF_UP] = Decimal.ROUND_HALF_UP, _toSignificantRoundin[Rounding.ROUND_UP] = Decimal.ROUND_UP, _toSignificantRoundin); var toFixedRounding = (_toFixedRounding = {}, _toFixedRounding[Rounding.ROUND_DOWN] = 0, _toFixedRounding[Rounding.ROUND_HALF_UP] = 1, _toFixedRounding[Rounding.ROUND_UP] = 3, _toFixedRounding); var Fraction = /*#__PURE__*/function () { function Fraction(numerator, denominator) { if (denominator === void 0) { denominator = ONE; } this.numerator = parseBigintIsh(numerator); this.denominator = parseBigintIsh(denominator); } // performs floor division var _proto = Fraction.prototype; _proto.invert = function invert() { return new Fraction(this.denominator, this.numerator); }; _proto.add = function add(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); if (JSBI.equal(this.denominator, otherParsed.denominator)) { return new Fraction(JSBI.add(this.numerator, otherParsed.numerator), this.denominator); } return new Fraction(JSBI.add(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator)); }; _proto.subtract = function subtract(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); if (JSBI.equal(this.denominator, otherParsed.denominator)) { return new Fraction(JSBI.subtract(this.numerator, otherParsed.numerator), this.denominator); } return new Fraction(JSBI.subtract(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator)); }; _proto.lessThan = function lessThan(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); return JSBI.lessThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); }; _proto.equalTo = function equalTo(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); return JSBI.equal(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); }; _proto.greaterThan = function greaterThan(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); return JSBI.greaterThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); }; _proto.multiply = function multiply(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); return new Fraction(JSBI.multiply(this.numerator, otherParsed.numerator), JSBI.multiply(this.denominator, otherParsed.denominator)); }; _proto.divide = function divide(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); return new Fraction(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(this.denominator, otherParsed.numerator)); }; _proto.toSignificant = function toSignificant(significantDigits, format, rounding) { if (format === void 0) { format = { groupSeparator: '' }; } if (rounding === void 0) { rounding = Rounding.ROUND_HALF_UP; } !Number.isInteger(significantDigits) ? process.env.NODE_ENV !== "production" ? invariant(false, significantDigits + " is not an integer.") : invariant(false) : void 0; !(significantDigits > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, significantDigits + " is not positive.") : invariant(false) : void 0; Decimal.set({ precision: significantDigits + 1, rounding: toSignificantRounding[rounding] }); var quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits); return quotient.toFormat(quotient.decimalPlaces(), format); }; _proto.toFixed = function toFixed(decimalPlaces, format, rounding) { if (format === void 0) { format = { groupSeparator: '' }; } if (rounding === void 0) { rounding = Rounding.ROUND_HALF_UP; } !Number.isInteger(decimalPlaces) ? process.env.NODE_ENV !== "production" ? invariant(false, decimalPlaces + " is not an integer.") : invariant(false) : void 0; !(decimalPlaces >= 0) ? process.env.NODE_ENV !== "production" ? invariant(false, decimalPlaces + " is negative.") : invariant(false) : void 0; Big.DP = decimalPlaces; Big.RM = toFixedRounding[rounding]; return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format); }; _createClass(Fraction, [{ key: "quotient", get: function get() { return JSBI.divide(this.numerator, this.denominator); } // remainder after floor division }, { key: "remainder", get: function get() { return new Fraction(JSBI.remainder(this.numerator, this.denominator), this.denominator); } }]); return Fraction; }(); var Big$1 = /*#__PURE__*/toFormat(_Big); var CurrencyAmount = /*#__PURE__*/function (_Fraction) { _inheritsLoose(CurrencyAmount, _Fraction); // amount _must_ be raw, i.e. in the native representation function CurrencyAmount(currency, amount) { var _this; var parsedAmount = parseBigintIsh(amount); validateSolidityTypeInstance(parsedAmount, SolidityType.uint256); _this = _Fraction.call(this, parsedAmount, JSBI.exponentiate(TEN, JSBI.BigInt(currency.decimals))) || this; _this.currency = currency; return _this; } /** * Helper that calls the constructor with the ETHER currency * @param amount ether amount in wei */ CurrencyAmount.ether = function ether(amount) { return new CurrencyAmount(ETHER, amount); }; var _proto = CurrencyAmount.prototype; _proto.add = function add(other) { !currencyEquals(this.currency, other.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; return new CurrencyAmount(this.currency, JSBI.add(this.raw, other.raw)); }; _proto.subtract = function subtract(other) { !currencyEquals(this.currency, other.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; return new CurrencyAmount(this.currency, JSBI.subtract(this.raw, other.raw)); }; _proto.toSignificant = function toSignificant(significantDigits, format, rounding) { if (significantDigits === void 0) { significantDigits = 6; } if (rounding === void 0) { rounding = Rounding.ROUND_DOWN; } return _Fraction.prototype.toSignificant.call(this, significantDigits, format, rounding); }; _proto.toFixed = function toFixed(decimalPlaces, format, rounding) { if (decimalPlaces === void 0) { decimalPlaces = this.currency.decimals; } if (rounding === void 0) { rounding = Rounding.ROUND_DOWN; } !(decimalPlaces <= this.currency.decimals) ? process.env.NODE_ENV !== "production" ? invariant(false, 'DECIMALS') : invariant(false) : void 0; return _Fraction.prototype.toFixed.call(this, decimalPlaces, format, rounding); }; _proto.toExact = function toExact(format) { if (format === void 0) { format = { groupSeparator: '' }; } Big$1.DP = this.currency.decimals; return new Big$1(this.numerator.toString()).div(this.denominator.toString()).toFormat(format); }; _createClass(CurrencyAmount, [{ key: "raw", get: function get() { return this.numerator; } }]); return CurrencyAmount; }(Fraction); var TokenAmount = /*#__PURE__*/function (_CurrencyAmount) { _inheritsLoose(TokenAmount, _CurrencyAmount); // amount _must_ be raw, i.e. in the native representation function TokenAmount(token, amount) { var _this; _this = _CurrencyAmount.call(this, token, amount) || this; _this.token = token; return _this; } var _proto = TokenAmount.prototype; _proto.add = function add(other) { !this.token.equals(other.token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; return new TokenAmount(this.token, JSBI.add(this.raw, other.raw)); }; _proto.subtract = function subtract(other) { !this.token.equals(other.token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; return new TokenAmount(this.token, JSBI.subtract(this.raw, other.raw)); }; return TokenAmount; }(CurrencyAmount); var Price = /*#__PURE__*/function (_Fraction) { _inheritsLoose(Price, _Fraction); // denominator and numerator _must_ be raw, i.e. in the native representation function Price(baseCurrency, quoteCurrency, denominator, numerator) { var _this; _this = _Fraction.call(this, numerator, denominator) || this; _this.baseCurrency = baseCurrency; _this.quoteCurrency = quoteCurrency; _this.scalar = new Fraction(JSBI.exponentiate(TEN, JSBI.BigInt(baseCurrency.decimals)), JSBI.exponentiate(TEN, JSBI.BigInt(quoteCurrency.decimals))); return _this; } Price.fromRoute = function fromRoute(route) { var prices = []; for (var _iterator = _createForOfIteratorHelperLoose(route.pairs.entries()), _step; !(_step = _iterator()).done;) { var _step$value = _step.value, i = _step$value[0], pair = _step$value[1]; prices.push(route.path[i].equals(pair.token0) ? new Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.raw, pair.reserve1.raw) : new Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.raw, pair.reserve0.raw)); } return prices.slice(1).reduce(function (accumulator, currentValue) { return accumulator.multiply(currentValue); }, prices[0]); }; var _proto = Price.prototype; _proto.invert = function invert() { return new Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator); }; _proto.multiply = function multiply(other) { !currencyEquals(this.quoteCurrency, other.baseCurrency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; var fraction = _Fraction.prototype.multiply.call(this, other); return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator); } // performs floor division on overflow ; _proto.quote = function quote(currencyAmount) { !currencyEquals(currencyAmount.currency, this.baseCurrency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; if (this.quoteCurrency instanceof Token) { return new TokenAmount(this.quoteCurrency, _Fraction.prototype.multiply.call(this, currencyAmount.raw).quotient); } return CurrencyAmount.ether(_Fraction.prototype.multiply.call(this, currencyAmount.raw).quotient); }; _proto.toSignificant = function toSignificant(significantDigits, format, rounding) { if (significantDigits === void 0) { significantDigits = 6; } return this.adjusted.toSignificant(significantDigits, format, rounding); }; _proto.toFixed = function toFixed(decimalPlaces, format, rounding) { if (decimalPlaces === void 0) { decimalPlaces = 4; } return this.adjusted.toFixed(decimalPlaces, format, rounding); }; _createClass(Price, [{ key: "raw", get: function get() { return new Fraction(this.numerator, this.denominator); } }, { key: "adjusted", get: function get() { return _Fraction.prototype.multiply.call(this, this.scalar); } }]); return Price; }(Fraction); var PAIR_ADDRESS_CACHE = {}; var Pair = /*#__PURE__*/function () { function Pair(tokenAmountA, tokenAmountB) { var tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) // does safety checks ? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA]; this.liquidityToken = new Token(tokenAmounts[0].token.chainId, Pair.getAddress(tokenAmounts[0].token, tokenAmounts[1].token), 18, 'UNI-V2', 'Uniswap V2'); this.tokenAmounts = tokenAmounts; } Pair.getAddress = function getAddress(tokenA, tokenB) { var _PAIR_ADDRESS_CACHE, _PAIR_ADDRESS_CACHE$t; var tokens = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA]; // does safety checks if (((_PAIR_ADDRESS_CACHE = PAIR_ADDRESS_CACHE) === null || _PAIR_ADDRESS_CACHE === void 0 ? void 0 : (_PAIR_ADDRESS_CACHE$t = _PAIR_ADDRESS_CACHE[tokens[0].address]) === null || _PAIR_ADDRESS_CACHE$t === void 0 ? void 0 : _PAIR_ADDRESS_CACHE$t[tokens[1].address]) === undefined) { var _PAIR_ADDRESS_CACHE2, _extends2, _extends3; PAIR_ADDRESS_CACHE = _extends({}, PAIR_ADDRESS_CACHE, (_extends3 = {}, _extends3[tokens[0].address] = _extends({}, (_PAIR_ADDRESS_CACHE2 = PAIR_ADDRESS_CACHE) === null || _PAIR_ADDRESS_CACHE2 === void 0 ? void 0 : _PAIR_ADDRESS_CACHE2[tokens[0].address], (_extends2 = {}, _extends2[tokens[1].address] = getCreate2Address(FACTORY_ADDRESSES[tokens[0].chainId], keccak256(['bytes'], [pack(['address', 'address'], [tokens[0].address, tokens[1].address])]), INIT_CODE_HASH[tokens[0].chainId]), _extends2)), _extends3)); } return PAIR_ADDRESS_CACHE[tokens[0].address][tokens[1].address]; } /** * Returns true if the token is either token0 or token1 * @param token to check */ ; var _proto = Pair.prototype; _proto.involvesToken = function involvesToken(token) { return token.equals(this.token0) || token.equals(this.token1); } /** * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0 */ ; /** * Return the price of the given token in terms of the other token in the pair. * @param token token to return price of */ _proto.priceOf = function priceOf(token) { !this.involvesToken(token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; return token.equals(this.token0) ? this.token0Price : this.token1Price; } /** * Returns the chain ID of the tokens in the pair. */ ; _proto.reserveOf = function reserveOf(token) { !this.involvesToken(token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; return token.equals(this.token0) ? this.reserve0 : this.reserve1; }; _proto.getOutputAmount = function getOutputAmount(inputAmount) { !this.involvesToken(inputAmount.token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO)) { throw new InsufficientReservesError(); } var inputReserve = this.reserveOf(inputAmount.token); var outputReserve = this.reserveOf(inputAmount.token.equals(this.token0) ? this.token1 : this.token0); var inputAmountWithFee = JSBI.multiply(inputAmount.raw, _997); var numerator = JSBI.multiply(inputAmountWithFee, outputReserve.raw); var denominator = JSBI.add(JSBI.multiply(inputReserve.raw, _1000), inputAmountWithFee); var outputAmount = new TokenAmount(inputAmount.token.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator)); if (JSBI.equal(outputAmount.raw, ZERO)) { throw new InsufficientInputAmountError(); } return [outputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]; }; _proto.getInputAmount = function getInputAmount(outputAmount) { !this.involvesToken(outputAmount.token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO) || JSBI.greaterThanOrEqual(outputAmount.raw, this.reserveOf(outputAmount.token).raw)) { throw new InsufficientReservesError(); } var outputReserve = this.reserveOf(outputAmount.token); var inputReserve = this.reserveOf(outputAmount.token.equals(this.token0) ? this.token1 : this.token0); var numerator = JSBI.multiply(JSBI.multiply(inputReserve.raw, outputAmount.raw), _1000); var denominator = JSBI.multiply(JSBI.subtract(outputReserve.raw, outputAmount.raw), _997); var inputAmount = new TokenAmount(outputAmount.token.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE)); return [inputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]; }; _proto.getLiquidityMinted = function getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) { !totalSupply.token.equals(this.liquidityToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0; var tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) // does safety checks ? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA]; !(tokenAmounts[0].token.equals(this.token0) && tokenAmounts[1].token.equals(this.token1)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; var liquidity; if (JSBI.equal(totalSupply.raw, ZERO)) { liquidity = JSBI.subtract(sqrt(JSBI.multiply(tokenAmounts[0].raw, tokenAmounts[1].raw)), MINIMUM_LIQUIDITY); } else { var amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].raw, totalSupply.raw), this.reserve0.raw); var amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].raw, totalSupply.raw), this.reserve1.raw); liquidity = JSBI.lessThanOrEqual(amount0, amount1) ? amount0 : amount1; } if (!JSBI.greaterThan(liquidity, ZERO)) { throw new InsufficientInputAmountError(); } return new TokenAmount(this.liquidityToken, liquidity); }; _proto.getLiquidityValue = function getLiquidityValue(token, totalSupply, liquidity, feeOn, kLast) { if (feeOn === void 0) { feeOn = false; } !this.involvesToken(token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; !totalSupply.token.equals(this.liquidityToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOTAL_SUPPLY') : invariant(false) : void 0; !liquidity.token.equals(this.liquidityToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0; !JSBI.lessThanOrEqual(liquidity.raw, totalSupply.raw) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0; var totalSupplyAdjusted; if (!feeOn) { totalSupplyAdjusted = totalSupply; } else { !!!kLast ? process.env.NODE_ENV !== "production" ? invariant(false, 'K_LAST') : invariant(false) : void 0; var kLastParsed = parseBigintIsh(kLast); if (!JSBI.equal(kLastParsed, ZERO)) { var rootK = sqrt(JSBI.multiply(this.reserve0.raw, this.reserve1.raw)); var rootKLast = sqrt(kLastParsed); if (JSBI.greaterThan(rootK, rootKLast)) { var numerator = JSBI.multiply(totalSupply.raw, JSBI.subtract(rootK, rootKLast)); var denominator = JSBI.add(JSBI.multiply(rootK, FIVE), rootKLast); var feeLiquidity = JSBI.divide(numerator, denominator); totalSupplyAdjusted = totalSupply.add(new TokenAmount(this.liquidityToken, feeLiquidity)); } else { totalSupplyAdjusted = totalSupply; } } else { totalSupplyAdjusted = totalSupply; } } return new TokenAmount(token, JSBI.divide(JSBI.multiply(liquidity.raw, this.reserveOf(token).raw), totalSupplyAdjusted.raw)); }; _createClass(Pair, [{ key: "token0Price", get: function get() { return new Price(this.token0, this.token1, this.tokenAmounts[0].raw, this.tokenAmounts[1].raw); } /** * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1 */ }, { key: "token1Price", get: function get() { return new Price(this.token1, this.token0, this.tokenAmounts[1].raw, this.tokenAmounts[0].raw); } }, { key: "chainId", get: function get() { return this.token0.chainId; } }, { key: "token0", get: function get() { return this.tokenAmounts[0].token; } }, { key: "token1", get: function get() { return this.tokenAmounts[1].token; } }, { key: "reserve0", get: function get() { return this.tokenAmounts[0]; } }, { key: "reserve1", get: function get() { return this.tokenAmounts[1]; } }]); return Pair; }(); var Route = /*#__PURE__*/function () { function Route(pairs, input, output) { !(pairs.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'PAIRS') : invariant(false) : void 0; !pairs.every(function (pair) { return pair.chainId === pairs[0].chainId; }) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_IDS') : invariant(false) : void 0; !(input instanceof Token && pairs[0].involvesToken(input) || input === ETHER && pairs[0].involvesToken(WETH[pairs[0].chainId])) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0; !(typeof output === 'undefined' || output instanceof Token && pairs[pairs.length - 1].involvesToken(output) || output === ETHER && pairs[pairs.length - 1].involvesToken(WETH[pairs[0].chainId])) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0; var path = [input instanceof Token ? input : WETH[pairs[0].chainId]]; for (var _iterator = _createForOfIteratorHelperLoose(pairs.entries()), _step; !(_step = _iterator()).done;) { var _step$value = _step.value, i = _step$value[0], pair = _step$value[1]; var currentInput = path[i]; !(currentInput.equals(pair.token0) || currentInput.equals(pair.token1)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'PATH') : invariant(false) : void 0; var _output = currentInput.equals(pair.token0) ? pair.token1 : pair.token0; path.push(_output); } this.pairs = pairs; this.path = path; this.midPrice = Price.fromRoute(this); this.input = input; this.output = output !== null && output !== void 0 ? output : path[path.length - 1]; } _createClass(Route, [{ key: "chainId", get: function get() { return this.pairs[0].chainId; } }]); return Route; }(); var _100_PERCENT = /*#__PURE__*/new Fraction(_100); var Percent = /*#__PURE__*/function (_Fraction) { _inheritsLoose(Percent, _Fraction); function Percent() { return _Fraction.apply(this, arguments) || this; } var _proto = Percent.prototype; _proto.toSignificant = function toSignificant(significantDigits, format, rounding) { if (significantDigits === void 0) { significantDigits = 5; } return this.multiply(_100_PERCENT).toSignificant(significantDigits, format, rounding); }; _proto.toFixed = function toFixed(decimalPlaces, format, rounding) { if (decimalPlaces === void 0) { decimalPlaces = 2; } return this.multiply(_100_PERCENT).toFixed(decimalPlaces, format, rounding); }; return Percent; }(Fraction); /** * Returns the percent difference between the mid price and the execution price, i.e. price impact. * @param midPrice mid price before the trade * @param inputAmount the input amount of the trade * @param outputAmount the output amount of the trade */ function computePriceImpact(midPrice, inputAmount, outputAmount) { var exactQuote = midPrice.raw.multiply(inputAmount.raw); // calculate slippage := (exactQuote - outputAmount) / exactQuote var slippage = exactQuote.subtract(outputAmount.raw).divide(exactQuote); return new Percent(slippage.numerator, slippage.denominator); } // comparator function that allows sorting trades by their output amounts, in decreasing order, and then input amounts // in increasing order. i.e. the best trades have the most outputs for the least inputs and are sorted first function inputOutputComparator(a, b) { // must have same input and output token for comparison !currencyEquals(a.inputAmount.currency, b.inputAmount.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT_CURRENCY') : invariant(false) : void 0; !currencyEquals(a.outputAmount.currency, b.outputAmount.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT_CURRENCY') : invariant(false) : void 0; if (a.outputAmount.equalTo(b.outputAmount)) { if (a.inputAmount.equalTo(b.inputAmount)) { return 0; } // trade A requires less input than trade B, so A should come first if (a.inputAmount.lessThan(b.inputAmount)) { return -1; } else { return 1; } } else { // tradeA has less output than trade B, so should come second if (a.outputAmount.lessThan(b.outputAmount)) { return 1; } else { return -1; } } } // extension of the input output comparator that also considers other dimensions of the trade in ranking them function tradeComparator(a, b) { var ioComp = inputOutputComparator(a, b); if (ioComp !== 0) { return ioComp; } // consider lowest slippage next, since these are less likely to fail if (a.priceImpact.lessThan(b.priceImpact)) { return -1; } else if (a.priceImpact.greaterThan(b.priceImpact)) { return 1; } // finally consider the number of hops since each hop costs gas return a.route.path.length - b.route.path.length; } /** * Given a currency amount and a chain ID, returns the equivalent representation as the token amount. * In other words, if the currency is ETHER, returns the WETH token amount for the given chain. Otherwise, returns * the input currency amount. */ function wrappedAmount(currencyAmount, chainId) { if (currencyAmount instanceof TokenAmount) return currencyAmount; if (currencyAmount.currency === ETHER) return new TokenAmount(WETH[chainId], currencyAmount.raw); process.env.NODE_ENV !== "production" ? invariant(false, 'CURRENCY') : invariant(false) ; } function wrappedCurrency(currency, chainId) { if (currency instanceof Token) return currency; if (currency === ETHER) return WETH[chainId]; process.env.NODE_ENV !== "production" ? invariant(false, 'CURRENCY') : invariant(false) ; } /** * Represents a trade executed against a list of pairs. * Does