@array.inc/sdk
Version:
đź› An SDK for building applications on top of Array.
1,338 lines (1,051 loc) • 205 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var JSBI = _interopDefault(require('jsbi'));
var bignumber = require('@ethersproject/bignumber');
var invariant = _interopDefault(require('tiny-invariant'));
var address = require('@ethersproject/address');
var warning = _interopDefault(require('tiny-warning'));
var _Big = _interopDefault(require('big.js'));
var _Decimal = _interopDefault(require('decimal.js-light'));
var toFormat = _interopDefault(require('toformat'));
var solidity = require('@ethersproject/solidity');
var abi$1 = require('@ethersproject/abi');
var signingKey = require('@ethersproject/signing-key');
var eip712 = require('eip-712');
var bytes = require('@ethersproject/bytes');
var contracts = require('@ethersproject/contracts');
var fetch = _interopDefault(require('isomorphic-unfetch'));
(function (ChainId) {
ChainId[ChainId["MAINNET"] = 1] = "MAINNET";
ChainId[ChainId["ROPSTEN"] = 3] = "ROPSTEN";
ChainId[ChainId["RINKEBY"] = 4] = "RINKEBY";
ChainId[ChainId["G\xD6RLI"] = 5] = "G\xD6RLI";
ChainId[ChainId["KOVAN"] = 42] = "KOVAN";
ChainId[ChainId["MATIC"] = 137] = "MATIC";
ChainId[ChainId["MATIC_TESTNET"] = 80001] = "MATIC_TESTNET";
ChainId[ChainId["FANTOM"] = 250] = "FANTOM";
ChainId[ChainId["FANTOM_TESTNET"] = 4002] = "FANTOM_TESTNET";
ChainId[ChainId["XDAI"] = 100] = "XDAI";
ChainId[ChainId["BSC"] = 56] = "BSC";
ChainId[ChainId["BSC_TESTNET"] = 97] = "BSC_TESTNET";
ChainId[ChainId["ARBITRUM"] = 42161] = "ARBITRUM";
ChainId[ChainId["ARBITRUM_TESTNET"] = 79377087078960] = "ARBITRUM_TESTNET";
ChainId[ChainId["MOONBEAM_TESTNET"] = 1287] = "MOONBEAM_TESTNET";
ChainId[ChainId["MOONBEAM"] = 1284] = "MOONBEAM";
ChainId[ChainId["AVALANCHE"] = 43114] = "AVALANCHE";
ChainId[ChainId["AVALANCHE_TESTNET"] = 43113] = "AVALANCHE_TESTNET";
ChainId[ChainId["HECO"] = 128] = "HECO";
ChainId[ChainId["HECO_TESTNET"] = 256] = "HECO_TESTNET";
ChainId[ChainId["HARMONY"] = 1666600000] = "HARMONY";
ChainId[ChainId["HARMONY_TESTNET"] = 1666700000] = "HARMONY_TESTNET";
ChainId[ChainId["OKEX"] = 66] = "OKEX";
ChainId[ChainId["OKEX_TESTNET"] = 65] = "OKEX_TESTNET";
ChainId[ChainId["CELO"] = 42220] = "CELO";
ChainId[ChainId["PALM"] = 11297108109] = "PALM";
ChainId[ChainId["PALM_TESTNET"] = 11297108099] = "PALM_TESTNET";
ChainId[ChainId["MOONRIVER"] = 1285] = "MOONRIVER";
ChainId[ChainId["FUSE"] = 122] = "FUSE";
ChainId[ChainId["SHIDEN"] = 336] = "SHIDEN";
ChainId[ChainId["PLASM_TESTNET"] = 80] = "PLASM_TESTNET";
})(exports.ChainId || (exports.ChainId = {}));
(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";
})(exports.Rounding || (exports.Rounding = {}));
(function (TradeType) {
TradeType[TradeType["EXACT_INPUT"] = 0] = "EXACT_INPUT";
TradeType[TradeType["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT";
})(exports.TradeType || (exports.TradeType = {}));
(function (KashiAction) {
KashiAction[KashiAction["ADD_ASSET"] = 1] = "ADD_ASSET";
KashiAction[KashiAction["REPAY"] = 2] = "REPAY";
KashiAction[KashiAction["REMOVE_ASSET"] = 3] = "REMOVE_ASSET";
KashiAction[KashiAction["REMOVE_COLLATERAL"] = 4] = "REMOVE_COLLATERAL";
KashiAction[KashiAction["BORROW"] = 5] = "BORROW";
KashiAction[KashiAction["GET_REPAY_SHARE"] = 6] = "GET_REPAY_SHARE";
KashiAction[KashiAction["GET_REPAY_PART"] = 7] = "GET_REPAY_PART";
KashiAction[KashiAction["ACCRUE"] = 8] = "ACCRUE"; // Functions that don't need accrue to be called
KashiAction[KashiAction["ADD_COLLATERAL"] = 10] = "ADD_COLLATERAL";
KashiAction[KashiAction["UPDATE_EXCHANGE_RATE"] = 11] = "UPDATE_EXCHANGE_RATE"; // Function on BentoBox
KashiAction[KashiAction["BENTO_DEPOSIT"] = 20] = "BENTO_DEPOSIT";
KashiAction[KashiAction["BENTO_WITHDRAW"] = 21] = "BENTO_WITHDRAW";
KashiAction[KashiAction["BENTO_TRANSFER"] = 22] = "BENTO_TRANSFER";
KashiAction[KashiAction["BENTO_TRANSFER_MULTIPLE"] = 23] = "BENTO_TRANSFER_MULTIPLE";
KashiAction[KashiAction["BENTO_SETAPPROVAL"] = 24] = "BENTO_SETAPPROVAL"; // Any external call (except to BentoBox)
KashiAction[KashiAction["CALL"] = 30] = "CALL";
})(exports.KashiAction || (exports.KashiAction = {}));
// Fee - Tiers TBD
(function (Fee) {
Fee[Fee["DEFAULT"] = 30] = "DEFAULT";
})(exports.Fee || (exports.Fee = {}));
(function (OrderStatus) {
OrderStatus["FILLED"] = "FILLED";
OrderStatus["CANCELLED"] = "CANCELLED";
OrderStatus["EXPIRED"] = "EXPIRED";
OrderStatus["PENDING"] = "PENDING";
})(exports.OrderStatus || (exports.OrderStatus = {}));
var _USDC_ADDRESS, _FACTORY_ADDRESS, _ROUTER_ADDRESS, _ARRAY_ADDRESS, _WETH9_ADDRESS, _WNATIVE_ADDRESS, _MASTERCHEF_ADDRESS, _ENS_REGISTRAR_ADDRES, _MULTICALL2_ADDRESS, _STOP_LIMIT_ORDER_ADD, _BENTOBOX_ADDRESS;
var USDC_ADDRESS = (_USDC_ADDRESS = {}, _USDC_ADDRESS[exports.ChainId.AVALANCHE] = '0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664', _USDC_ADDRESS[exports.ChainId.AVALANCHE_TESTNET] = '0x5425890298aed601595a70AB815c96711a31Bc65', _USDC_ADDRESS);
var FACTORY_ADDRESS = (_FACTORY_ADDRESS = {}, _FACTORY_ADDRESS[exports.ChainId.AVALANCHE_TESTNET] = '0x6f6C1C188631D1951DcE7A9B83c65747244bF43A', _FACTORY_ADDRESS[exports.ChainId.AVALANCHE] = '0x32B304298d5fA82407AA552b864e9a62e3D19528', _FACTORY_ADDRESS);
var ROUTER_ADDRESS = (_ROUTER_ADDRESS = {}, _ROUTER_ADDRESS[exports.ChainId.AVALANCHE_TESTNET] = '0xEdB76bF8bdBd864ff31c66803712286dc3f0b4F7', _ROUTER_ADDRESS[exports.ChainId.AVALANCHE] = '0x7ddf3eCcd19f3a6A1F4e8634BfE0a32978CF038A', _ROUTER_ADDRESS);
var ARRAY_ADDRESS = (_ARRAY_ADDRESS = {}, _ARRAY_ADDRESS[exports.ChainId.AVALANCHE] = '0xEAf1A8F1BB3929a6f7365E5c38418b9032d7b2B1', _ARRAY_ADDRESS);
var WETH9_ADDRESS = (_WETH9_ADDRESS = {}, _WETH9_ADDRESS[exports.ChainId.AVALANCHE] = '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7', _WETH9_ADDRESS[exports.ChainId.AVALANCHE_TESTNET] = '0xd00ae08403B9bbb9124bB305C09058E32C39A48c', _WETH9_ADDRESS);
var WNATIVE_ADDRESS = (_WNATIVE_ADDRESS = {}, _WNATIVE_ADDRESS[exports.ChainId.AVALANCHE] = WETH9_ADDRESS[exports.ChainId.AVALANCHE], _WNATIVE_ADDRESS[exports.ChainId.AVALANCHE_TESTNET] = WETH9_ADDRESS[exports.ChainId.AVALANCHE_TESTNET], _WNATIVE_ADDRESS);
var MASTERCHEF_ADDRESS = (_MASTERCHEF_ADDRESS = {}, _MASTERCHEF_ADDRESS[exports.ChainId.AVALANCHE_TESTNET] = '0xd11e75079Ef9AE80D4C18739cF7070ED9678507d', _MASTERCHEF_ADDRESS[exports.ChainId.AVALANCHE] = '0xEC8413897e056a7ee79Ab5bDacc116c27b8fF4ec', _MASTERCHEF_ADDRESS);
var MASTERCHEF_V2_ADDRESS = {};
var STATIC_FARM_ADDRESS = {};
var ENS_REGISTRAR_ADDRESS = (_ENS_REGISTRAR_ADDRES = {}, _ENS_REGISTRAR_ADDRES[exports.ChainId.ROPSTEN] = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', _ENS_REGISTRAR_ADDRES);
var MULTICALL2_ADDRESS = (_MULTICALL2_ADDRESS = {}, _MULTICALL2_ADDRESS[exports.ChainId.AVALANCHE] = '0xdDCbf776dF3dE60163066A5ddDF2277cB445E0F3', _MULTICALL2_ADDRESS[exports.ChainId.AVALANCHE_TESTNET] = '0xA6577666FE76BA7561d2B5edd72152125d8C2891', _MULTICALL2_ADDRESS); // not being used in Array
var STOP_LIMIT_ORDER_ADDRESS = (_STOP_LIMIT_ORDER_ADD = {}, _STOP_LIMIT_ORDER_ADD[exports.ChainId.KOVAN] = '0xce9365dB1C99897f04B3923C03ba9a5f80E8DB87', _STOP_LIMIT_ORDER_ADD[exports.ChainId.MATIC] = '0x1aDb3Bd86bb01797667eC382a0BC6A9854b4005f', _STOP_LIMIT_ORDER_ADD);
var BENTOBOX_ADDRESS = (_BENTOBOX_ADDRESS = {}, _BENTOBOX_ADDRESS[exports.ChainId.MAINNET] = '0xF5BCE5077908a1b7370B9ae04AdC565EBd643966', _BENTOBOX_ADDRESS[exports.ChainId.ROPSTEN] = '0x6BdD85290001C8Aef74f35A7606065FA15aD5ACF', _BENTOBOX_ADDRESS[exports.ChainId.RINKEBY] = '0xF5BCE5077908a1b7370B9ae04AdC565EBd643966', _BENTOBOX_ADDRESS[exports.ChainId.GĂ–RLI] = '0xF5BCE5077908a1b7370B9ae04AdC565EBd643966', _BENTOBOX_ADDRESS[exports.ChainId.KOVAN] = '0x9A0D9920D92c178a58D99B455898Df2df22A2eE4', _BENTOBOX_ADDRESS[exports.ChainId.FANTOM] = '0xF5BCE5077908a1b7370B9ae04AdC565EBd643966', _BENTOBOX_ADDRESS[exports.ChainId.MATIC] = '0x0319000133d3AdA02600f0875d2cf03D442C3367', _BENTOBOX_ADDRESS[exports.ChainId.MATIC_TESTNET] = '0xF5BCE5077908a1b7370B9ae04AdC565EBd643966', _BENTOBOX_ADDRESS[exports.ChainId.XDAI] = '0xE2d7F5dd869Fc7c126D21b13a9080e75a4bDb324', _BENTOBOX_ADDRESS[exports.ChainId.BSC] = '0xF5BCE5077908a1b7370B9ae04AdC565EBd643966', _BENTOBOX_ADDRESS[exports.ChainId.BSC_TESTNET] = '0xF5BCE5077908a1b7370B9ae04AdC565EBd643966', _BENTOBOX_ADDRESS[exports.ChainId.ARBITRUM] = '0x74c764D41B77DBbb4fe771daB1939B00b146894A', _BENTOBOX_ADDRESS[exports.ChainId.AVALANCHE] = '0x0711B6026068f736bae6B213031fCE978D48E026', _BENTOBOX_ADDRESS[exports.ChainId.HECO] = '0xF5BCE5077908a1b7370B9ae04AdC565EBd643966', _BENTOBOX_ADDRESS);
var ACTION_ADD_ASSET = 1;
var ACTION_REPAY = 2;
var ACTION_REMOVE_ASSET = 3;
var ACTION_REMOVE_COLLATERAL = 4;
var ACTION_BORROW = 5;
var ACTION_GET_REPAY_SHARE = 6;
var ACTION_GET_REPAY_PART = 7;
var ACTION_ACCRUE = 8; // Functions that don't need accrue to be called
var ACTION_ADD_COLLATERAL = 10;
var ACTION_UPDATE_EXCHANGE_RATE = 11; // Function on BentoBox
var ACTION_BENTO_DEPOSIT = 20;
var ACTION_BENTO_WITHDRAW = 21;
var ACTION_BENTO_TRANSFER = 22;
var ACTION_BENTO_TRANSFER_MULTIPLE = 23;
var ACTION_BENTO_SETAPPROVAL = 24; // Any external call (except to BentoBox)
var ACTION_CALL = 30;
var MINIMUM_TARGET_UTILIZATION = /*#__PURE__*/bignumber.BigNumber.from('700000000000000000'); // 70%
var MAXIMUM_TARGET_UTILIZATION = /*#__PURE__*/bignumber.BigNumber.from('800000000000000000'); // 80%
var UTILIZATION_PRECISION = /*#__PURE__*/bignumber.BigNumber.from('1000000000000000000');
var FULL_UTILIZATION = /*#__PURE__*/bignumber.BigNumber.from('1000000000000000000');
var FULL_UTILIZATION_MINUS_MAX = /*#__PURE__*/FULL_UTILIZATION.sub(MAXIMUM_TARGET_UTILIZATION);
var STARTING_INTEREST_PER_YEAR = /*#__PURE__*/bignumber.BigNumber.from(317097920).mul(bignumber.BigNumber.from(60)).mul(bignumber.BigNumber.from(60)).mul(bignumber.BigNumber.from(24)).mul( /*#__PURE__*/bignumber.BigNumber.from(365)); // approx 1% APR
var MINIMUM_INTEREST_PER_YEAR = /*#__PURE__*/bignumber.BigNumber.from(79274480).mul(bignumber.BigNumber.from(60)).mul(bignumber.BigNumber.from(60)).mul(bignumber.BigNumber.from(24)).mul( /*#__PURE__*/bignumber.BigNumber.from(365)); // approx 0.25% APR
var MAXIMUM_INTEREST_PER_YEAR = /*#__PURE__*/bignumber.BigNumber.from(317097920000).mul(bignumber.BigNumber.from(60)).mul(bignumber.BigNumber.from(60)).mul(bignumber.BigNumber.from(24)).mul( /*#__PURE__*/bignumber.BigNumber.from(365)); // approx 1000% APR
var INTEREST_ELASTICITY = /*#__PURE__*/bignumber.BigNumber.from('28800000000000000000000000000000000000000'); // Half or double in 28800 seconds (8 hours) if linear
var FACTOR_PRECISION = /*#__PURE__*/bignumber.BigNumber.from('1000000000000000000');
var PROTOCOL_FEE = /*#__PURE__*/bignumber.BigNumber.from('10000'); // 10%
var PROTOCOL_FEE_DIVISOR = /*#__PURE__*/bignumber.BigNumber.from('100000');
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
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.");
}
/**
* A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
*/
var AbstractCurrency = /*#__PURE__*/function () {
/**
* Constructs an instance of the base class `BaseCurrency`.
* @param chainId the chain ID on which this currency resides
* @param decimals decimals of the currency
* @param symbol symbol of the currency
* @param name of the currency
*/
function AbstractCurrency(chainId, decimals, symbol, name) {
!Number.isSafeInteger(chainId) ? invariant(false, 'CHAIN_ID') : void 0;
!(decimals >= 0 && decimals < 255 && Number.isInteger(decimals)) ? invariant(false, 'DECIMALS') : void 0;
this.chainId = chainId;
this.decimals = decimals;
this.symbol = symbol;
this.name = name;
}
/**
* Returns token address. Useful in cases where a dependency is needed to detect changes (e.g. useEffect).
*/
var _proto = AbstractCurrency.prototype;
_proto.serialize = function serialize() {
return this.wrapped.address;
};
return AbstractCurrency;
}();
/**
* Represents the native currency of the chain on which it resides, e.g.
*/
var NativeCurrency = /*#__PURE__*/function (_AbstractCurrency) {
_inheritsLoose(NativeCurrency, _AbstractCurrency);
function NativeCurrency() {
var _this;
_this = _AbstractCurrency.apply(this, arguments) || this;
_this.isNative = true;
_this.isToken = false;
return _this;
}
return NativeCurrency;
}(AbstractCurrency);
function validateAndParseAddress(address$1) {
try {
var checksummedAddress = address.getAddress(address$1);
"development" !== "production" ? warning(address$1 === checksummedAddress, address$1 + " is not checksummed.") : void 0;
return checksummedAddress;
} catch (error) {
invariant(false, address$1 + " is not a valid address.") ;
}
}
/**
* Represents an ERC20 token with a unique address and some metadata.
*/
var Token = /*#__PURE__*/function (_AbstractCurrency) {
_inheritsLoose(Token, _AbstractCurrency);
function Token(chainId, address, decimals, symbol, name) {
var _this;
_this = _AbstractCurrency.call(this, chainId, decimals, symbol, name) || this;
_this.isNative = false;
_this.isToken = true;
_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) {
return other.isToken && 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) ? invariant(false, 'CHAIN_IDS') : void 0;
!(this.address !== other.address) ? invariant(false, 'ADDRESSES') : void 0;
return this.address.toLowerCase() < other.address.toLowerCase();
}
/**
* Return this token, which does not need to be wrapped
*/
;
_createClass(Token, [{
key: "wrapped",
get: function get() {
return this;
}
}]);
return Token;
}(AbstractCurrency);
/**
* 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 _USDC, _WETH, _WNATIVE;
var USDC = (_USDC = {}, _USDC[exports.ChainId.AVALANCHE] = /*#__PURE__*/new Token(exports.ChainId.AVALANCHE, USDC_ADDRESS[exports.ChainId.AVALANCHE], 6, 'USDC', 'USD Coin'), _USDC[exports.ChainId.AVALANCHE_TESTNET] = /*#__PURE__*/new Token(exports.ChainId.AVALANCHE_TESTNET, USDC_ADDRESS[exports.ChainId.AVALANCHE_TESTNET], 6, 'USDC', 'USD Coin'), _USDC);
var WETH9 = (_WETH = {}, _WETH[exports.ChainId.AVALANCHE] = /*#__PURE__*/new Token(exports.ChainId.AVALANCHE, WNATIVE_ADDRESS[exports.ChainId.AVALANCHE], 18, 'WAVAX', 'Wrapped AVAX'), _WETH[exports.ChainId.AVALANCHE_TESTNET] = /*#__PURE__*/new Token(exports.ChainId.AVALANCHE_TESTNET, WNATIVE_ADDRESS[exports.ChainId.AVALANCHE_TESTNET], 18, 'WAVAX', 'Wrapped AVAX'), _WETH);
var WNATIVE = (_WNATIVE = {}, _WNATIVE[exports.ChainId.AVALANCHE] = WETH9[exports.ChainId.AVALANCHE], _WNATIVE[exports.ChainId.AVALANCHE_TESTNET] = WETH9[exports.ChainId.AVALANCHE_TESTNET], _WNATIVE);
var Avalanche = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Avalanche, _NativeCurrency);
function Avalanche(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'AVAX', 'Avalanche') || this;
}
Avalanche.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Avalanche(chainId);
};
var _proto = Avalanche.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Avalanche, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Avalanche;
}(NativeCurrency);
Avalanche._cache = {};
var Binance = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Binance, _NativeCurrency);
function Binance(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'BNB', 'Binance Coin') || this;
}
Binance.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Binance(chainId);
};
var _proto = Binance.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Binance, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Binance;
}(NativeCurrency);
Binance._cache = {};
var Celo = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Celo, _NativeCurrency);
function Celo(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'CELO', 'Celo') || this;
}
Celo.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Celo(chainId);
};
var _proto = Celo.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Celo, [{
key: "wrapped",
get: function get() {
var wcelo = WNATIVE[this.chainId];
!!!wcelo ? invariant(false, 'WRAPPED') : void 0;
return wcelo;
}
}]);
return Celo;
}(NativeCurrency);
Celo._cache = {};
/**
* Ether is the main usage of a 'native' currency, i.e. for Ethereum mainnet and all testnets
*/
var Ether = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Ether, _NativeCurrency);
function Ether(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'ETH', 'Ether') || this;
}
Ether.onChain = function onChain(chainId) {
var _this$_etherCache$cha;
return (_this$_etherCache$cha = this._etherCache[chainId]) != null ? _this$_etherCache$cha : this._etherCache[chainId] = new Ether(chainId);
};
var _proto = Ether.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Ether, [{
key: "wrapped",
get: function get() {
var weth9 = WETH9[this.chainId];
!!!weth9 ? invariant(false, 'WRAPPED') : void 0;
return weth9;
}
}]);
return Ether;
}(NativeCurrency);
Ether._etherCache = {};
var Fantom = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Fantom, _NativeCurrency);
function Fantom(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'FTM', 'Fantom') || this;
}
Fantom.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Fantom(chainId);
};
var _proto = Fantom.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Fantom, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Fantom;
}(NativeCurrency);
Fantom._cache = {};
var Harmony = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Harmony, _NativeCurrency);
function Harmony(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'ONE', 'Harmony') || this;
}
Harmony.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Harmony(chainId);
};
var _proto = Harmony.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Harmony, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Harmony;
}(NativeCurrency);
Harmony._cache = {};
var Heco = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Heco, _NativeCurrency);
function Heco(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'HT', 'Huobi Token') || this;
}
Heco.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Heco(chainId);
};
var _proto = Heco.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Heco, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Heco;
}(NativeCurrency);
Heco._cache = {};
var Matic = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Matic, _NativeCurrency);
function Matic(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'MATIC', 'Matic') || this;
}
Matic.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Matic(chainId);
};
var _proto = Matic.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Matic, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Matic;
}(NativeCurrency);
Matic._cache = {};
var Movr = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Movr, _NativeCurrency);
function Movr(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'MOVR', 'Moonriver') || this;
}
Movr.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Movr(chainId);
};
var _proto = Movr.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Movr, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Movr;
}(NativeCurrency);
Movr._cache = {};
var Mba = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Mba, _NativeCurrency);
function Mba(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'DEV', 'Moonbeam') || this;
}
Mba.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Mba(chainId);
};
var _proto = Mba.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Mba, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Mba;
}(NativeCurrency);
Mba._cache = {};
var GLMR = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(GLMR, _NativeCurrency);
function GLMR(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'GLMR', 'GLMR') || this;
}
GLMR.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new GLMR(chainId);
};
var _proto = GLMR.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(GLMR, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return GLMR;
}(NativeCurrency);
GLMR._cache = {};
var Okex = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Okex, _NativeCurrency);
function Okex(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'OKT', 'OKExChain') || this;
}
Okex.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Okex(chainId);
};
var _proto = Okex.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Okex, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Okex;
}(NativeCurrency);
Okex._cache = {};
var xDai = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(xDai, _NativeCurrency);
function xDai(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'XDAI', 'xDai') || this;
}
xDai.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new xDai(chainId);
};
var _proto = xDai.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(xDai, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return xDai;
}(NativeCurrency);
xDai._cache = {};
var Palm = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Palm, _NativeCurrency);
function Palm(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'PALM', 'Palm') || this;
}
Palm.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Palm(chainId);
};
var _proto = Palm.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Palm, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Palm;
}(NativeCurrency);
Palm._cache = {};
var Fuse = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Fuse, _NativeCurrency);
function Fuse(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'FUSE', 'Fuse') || this;
}
Fuse.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Fuse(chainId);
};
var _proto = Fuse.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Fuse, [{
key: "wrapped",
get: function get() {
var wnative = WNATIVE[this.chainId];
!!!wnative ? invariant(false, 'WRAPPED') : void 0;
return wnative;
}
}]);
return Fuse;
}(NativeCurrency);
Fuse._cache = {};
/**
* Shiden is the main usage of a 'native' currency, i.e. for Shiden mainnet and all testnets
*/
var Shiden = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Shiden, _NativeCurrency);
function Shiden(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'SDN', 'Shiden') || this;
}
Shiden.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Shiden(chainId);
};
var _proto = Shiden.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Shiden, [{
key: "wrapped",
get: function get() {
var weth9 = WETH9[this.chainId];
!!!weth9 ? invariant(false, 'WRAPPED') : void 0;
return weth9;
}
}]);
return Shiden;
}(NativeCurrency);
Shiden._cache = {};
/**
* Plasm is the main usage of a 'native' currency, i.e. for Plasm mainnet and all testnets
*/
var Plasm = /*#__PURE__*/function (_NativeCurrency) {
_inheritsLoose(Plasm, _NativeCurrency);
function Plasm(chainId) {
return _NativeCurrency.call(this, chainId, 18, 'PLD', 'Plasm') || this;
}
Plasm.onChain = function onChain(chainId) {
var _this$_cache$chainId;
return (_this$_cache$chainId = this._cache[chainId]) != null ? _this$_cache$chainId : this._cache[chainId] = new Plasm(chainId);
};
var _proto = Plasm.prototype;
_proto.equals = function equals(other) {
return other.isNative && other.chainId === this.chainId;
};
_createClass(Plasm, [{
key: "wrapped",
get: function get() {
var weth9 = WETH9[this.chainId];
!!!weth9 ? invariant(false, 'WRAPPED') : void 0;
return weth9;
}
}]);
return Plasm;
}(NativeCurrency);
Plasm._cache = {};
var _NATIVE;
var NATIVE = (_NATIVE = {}, _NATIVE[exports.ChainId.MAINNET] = /*#__PURE__*/Ether.onChain(exports.ChainId.MAINNET), _NATIVE[exports.ChainId.ROPSTEN] = /*#__PURE__*/Ether.onChain(exports.ChainId.ROPSTEN), _NATIVE[exports.ChainId.RINKEBY] = /*#__PURE__*/Ether.onChain(exports.ChainId.RINKEBY), _NATIVE[exports.ChainId.GĂ–RLI] = /*#__PURE__*/Ether.onChain(exports.ChainId.GĂ–RLI), _NATIVE[exports.ChainId.KOVAN] = /*#__PURE__*/Ether.onChain(exports.ChainId.KOVAN), _NATIVE[exports.ChainId.FANTOM] = /*#__PURE__*/Fantom.onChain(exports.ChainId.FANTOM), _NATIVE[exports.ChainId.FANTOM_TESTNET] = /*#__PURE__*/Fantom.onChain(exports.ChainId.FANTOM_TESTNET), _NATIVE[exports.ChainId.MATIC] = /*#__PURE__*/Matic.onChain(exports.ChainId.MATIC), _NATIVE[exports.ChainId.MATIC_TESTNET] = /*#__PURE__*/Matic.onChain(exports.ChainId.MATIC_TESTNET), _NATIVE[exports.ChainId.XDAI] = /*#__PURE__*/xDai.onChain(exports.ChainId.XDAI), _NATIVE[exports.ChainId.BSC] = /*#__PURE__*/Binance.onChain(exports.ChainId.BSC), _NATIVE[exports.ChainId.BSC_TESTNET] = /*#__PURE__*/Binance.onChain(exports.ChainId.BSC_TESTNET), _NATIVE[exports.ChainId.MOONBEAM_TESTNET] = /*#__PURE__*/Mba.onChain(exports.ChainId.MOONBEAM_TESTNET), _NATIVE[exports.ChainId.MOONBEAM] = /*#__PURE__*/GLMR.onChain(exports.ChainId.MOONBEAM), _NATIVE[exports.ChainId.ARBITRUM] = /*#__PURE__*/Ether.onChain(exports.ChainId.ARBITRUM), _NATIVE[exports.ChainId.AVALANCHE] = /*#__PURE__*/Avalanche.onChain(exports.ChainId.AVALANCHE), _NATIVE[exports.ChainId.AVALANCHE_TESTNET] = /*#__PURE__*/Avalanche.onChain(exports.ChainId.AVALANCHE_TESTNET), _NATIVE[exports.ChainId.HECO] = /*#__PURE__*/Heco.onChain(exports.ChainId.HECO), _NATIVE[exports.ChainId.HECO_TESTNET] = /*#__PURE__*/Heco.onChain(exports.ChainId.HECO_TESTNET), _NATIVE[exports.ChainId.HARMONY] = /*#__PURE__*/Harmony.onChain(exports.ChainId.HARMONY), _NATIVE[exports.ChainId.HARMONY_TESTNET] = /*#__PURE__*/Harmony.onChain(exports.ChainId.HARMONY_TESTNET), _NATIVE[exports.ChainId.OKEX] = /*#__PURE__*/Okex.onChain(exports.ChainId.OKEX), _NATIVE[exports.ChainId.OKEX_TESTNET] = /*#__PURE__*/Okex.onChain(exports.ChainId.OKEX_TESTNET), _NATIVE[exports.ChainId.CELO] = /*#__PURE__*/Celo.onChain(exports.ChainId.CELO), _NATIVE[exports.ChainId.PALM] = /*#__PURE__*/Palm.onChain(exports.ChainId.PALM), _NATIVE[exports.ChainId.MOONRIVER] = /*#__PURE__*/Movr.onChain(exports.ChainId.MOONRIVER), _NATIVE[exports.ChainId.FUSE] = /*#__PURE__*/Fuse.onChain(exports.ChainId.FUSE), _NATIVE[exports.ChainId.SHIDEN] = /*#__PURE__*/Shiden.onChain(exports.ChainId.SHIDEN), _NATIVE[exports.ChainId.PLASM_TESTNET] = /*#__PURE__*/Plasm.onChain(exports.ChainId.PLASM_TESTNET), _NATIVE);
var MaxUint256 = /*#__PURE__*/JSBI.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); // 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 _INIT_CODE_HASH, _SOLIDITY_TYPE_MAXIMA;
var INIT_CODE_HASH = (_INIT_CODE_HASH = {}, _INIT_CODE_HASH[exports.ChainId.AVALANCHE_TESTNET] = '0xa8661c96efb76d829721e6476502121629dc935e644b75e8e011cf077ac1f3c5', _INIT_CODE_HASH[exports.ChainId.AVALANCHE] = '0x6c945f0d3cca1b6eb1c2a50f18c53a069882569cf19adb5dc04596c050ffdda3', _INIT_CODE_HASH);
var MINIMUM_LIQUIDITY = /*#__PURE__*/JSBI.BigInt(1000);
(function (SolidityType) {
SolidityType["uint8"] = "uint8";
SolidityType["uint256"] = "uint256";
})(exports.SolidityType || (exports.SolidityType = {}));
var SOLIDITY_TYPE_MAXIMA = (_SOLIDITY_TYPE_MAXIMA = {}, _SOLIDITY_TYPE_MAXIMA[exports.SolidityType.uint8] = /*#__PURE__*/JSBI.BigInt('0xff'), _SOLIDITY_TYPE_MAXIMA[exports.SolidityType.uint256] = /*#__PURE__*/JSBI.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), _SOLIDITY_TYPE_MAXIMA);
var LAMBDA_URL = 'https://9epjsvomc4.execute-api.us-east-1.amazonaws.com/dev';
var SOCKET_URL = 'wss://hfimt374ge.execute-api.us-east-1.amazonaws.com/dev';
// 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));
var _toSignificantRoundin, _toFixedRounding;
var Decimal = /*#__PURE__*/toFormat(_Decimal);
var Big = /*#__PURE__*/toFormat(_Big);
Big.strict = true;
var toSignificantRounding = (_toSignificantRoundin = {}, _toSignificantRoundin[exports.Rounding.ROUND_DOWN] = Decimal.ROUND_DOWN, _toSignificantRoundin[exports.Rounding.ROUND_HALF_UP] = Decimal.ROUND_HALF_UP, _toSignificantRoundin[exports.Rounding.ROUND_UP] = Decimal.ROUND_UP, _toSignificantRoundin);
var toFixedRounding = (_toFixedRounding = {}, _toFixedRounding[exports.Rounding.ROUND_DOWN] = 0, _toFixedRounding[exports.Rounding.ROUND_HALF_UP] = 1, _toFixedRounding[exports.Rounding.ROUND_UP] = 3, _toFixedRounding);
var Fraction = /*#__PURE__*/function () {
function Fraction(numerator, denominator) {
if (denominator === void 0) {
denominator = JSBI.BigInt(1);
}
this.numerator = JSBI.BigInt(numerator);
this.denominator = JSBI.BigInt(denominator);
}
Fraction.tryParseFraction = function tryParseFraction(fractionish) {
if (fractionish instanceof JSBI || typeof fractionish === 'number' || typeof fractionish === 'string') return new Fraction(fractionish);
if ('numerator' in fractionish && 'denominator' in fractionish) return fractionish;
throw new Error('Could not parse fraction');
} // 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 = Fraction.tryParseFraction(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 = Fraction.tryParseFraction(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 = Fraction.tryParseFraction(other);
return JSBI.lessThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
};
_proto.equalTo = function equalTo(other) {
var otherParsed = Fraction.tryParseFraction(other);
return JSBI.equal(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
};
_proto.greaterThan = function greaterThan(other) {
var otherParsed = Fraction.tryParseFraction(other);
return JSBI.greaterThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
};
_proto.multiply = function multiply(other) {
var otherParsed = Fraction.tryParseFraction(other);
return new Fraction(JSBI.multiply(this.numerator, otherParsed.numerator), JSBI.multiply(this.denominator, otherParsed.denominator));
};
_proto.divide = function divide(other) {
var otherParsed = Fraction.tryParseFraction(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 = exports.Rounding.ROUND_HALF_UP;
}
!Number.isInteger(significantDigits) ? invariant(false, significantDigits + " is not an integer.") : void 0;
!(significantDigits > 0) ? invariant(false, significantDigits + " is not positive.") : 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 = exports.Rounding.ROUND_HALF_UP;
}
!Number.isInteger(decimalPlaces) ? invariant(false, decimalPlaces + " is not an integer.") : void 0;
!(decimalPlaces >= 0) ? invariant(false, decimalPlaces + " is negative.") : void 0;
Big.DP = decimalPlaces;
Big.RM = toFixedRounding[rounding];
return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format);
}
/**
* Helper method for converting any super class back to a fraction
*/
;
_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);
}
}, {
key: "asFraction",
get: function get() {
return new Fraction(this.numerator, this.denominator);
}
}]);
return Fraction;
}();
var Big$1 = /*#__PURE__*/toFormat(_Big);
Big$1.strict = true;
var CurrencyAmount = /*#__PURE__*/function (_Fraction) {
_inheritsLoose(CurrencyAmount, _Fraction);
function CurrencyAmount(currency, numerator, denominator) {
var _this;
_this = _Fraction.call(this, numerator, denominator) || this;
!JSBI.lessThanOrEqual(_this.quotient, MaxUint256) ? invariant(false, 'AMOUNT') : void 0;
_this.currency = currency;
_this.decimalScale = JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(currency.decimals));
return _this;
}
/**
* Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
* @param currency the currency in the amount
* @param rawAmount the raw token or ether amount
*/
CurrencyAmount.fromRawAmount = function fromRawAmount(currency, rawAmount) {
return new CurrencyAmount(currency, rawAmount);
}
/**
* Construct a currency amount with a denominator that is not equal to 1
* @param currency the currency
* @param numerator the numerator of the fractional token amount
* @param denominator the denominator of the fractional token amount
*/
;
CurrencyAmount.fromFractionalAmount = function fromFractionalAmount(currency, numerator, denominator) {
return new CurrencyAmount(currency, numerator, denominator);
};
var _proto = CurrencyAmount.prototype;
_proto.add = function add(other) {
!this.currency.equals(other.currency) ? invariant(false, 'CURRENCY') : void 0;
var added = _Fraction.prototype.add.call(this, other);
return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
};
_proto.subtract = function subtract(other) {
!this.currency.equals(other.currency) ? invariant(false, 'CURRENCY') : void 0;
var subtracted = _Fraction.prototype.subtract.call(this, other);
return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
};
_proto.multiply = function multiply(other) {
var multiplied = _Fraction.prototype.multiply.call(this, other);
return CurrencyAmount.fromFractionalAmount(this.currency, multiplied.numerator, multiplied.denominator);
};
_proto.divide = function divide(other) {
var divided = _Fraction.prototype.divide.call(this, other);
return CurrencyAmount.fromFractionalAmount(this.currency, divided.numerator, divided.denominator);
};
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
if (significantDigits === void 0) {
sig