@sebtoday/u-exchange-sdk 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +56 -0
- package/dist/constants.d.ts +44 -0
- package/dist/entities/currency.d.ts +24 -0
- package/dist/entities/fractions/currencyAmount.d.ts +19 -0
- package/dist/entities/fractions/fraction.d.ts +19 -0
- package/dist/entities/fractions/index.d.ts +5 -0
- package/dist/entities/fractions/percent.d.ts +6 -0
- package/dist/entities/fractions/price.d.ts +19 -0
- package/dist/entities/fractions/tokenAmount.d.ts +9 -0
- package/dist/entities/index.d.ts +6 -0
- package/dist/entities/pair.d.ts +41 -0
- package/dist/entities/route.d.ts +14 -0
- package/dist/entities/token.d.ts +39 -0
- package/dist/entities/trade.d.ts +106 -0
- package/dist/errors.d.ts +16 -0
- package/dist/fetcher.d.ts +28 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/router.d.ts +63 -0
- package/dist/test/constants.test.d.ts +1 -0
- package/dist/test/data.test.d.ts +1 -0
- package/dist/test/entities.test.d.ts +1 -0
- package/dist/test/fraction.test.d.ts +1 -0
- package/dist/test/miscellaneous.test.d.ts +1 -0
- package/dist/test/pair.test.d.ts +1 -0
- package/dist/test/route.test.d.ts +1 -0
- package/dist/test/router.test.d.ts +1 -0
- package/dist/test/token.test.d.ts +1 -0
- package/dist/test/trade.test.d.ts +1 -0
- package/dist/u-exchange-sdk.cjs.development.js +1630 -0
- package/dist/u-exchange-sdk.cjs.development.js.map +1 -0
- package/dist/u-exchange-sdk.cjs.production.min.js +2 -0
- package/dist/u-exchange-sdk.cjs.production.min.js.map +1 -0
- package/dist/u-exchange-sdk.esm.js +1608 -0
- package/dist/u-exchange-sdk.esm.js.map +1 -0
- package/dist/utils.d.ts +7 -0
- package/package.json +70 -0
@@ -0,0 +1,1630 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6
|
+
|
7
|
+
var JSBI = _interopDefault(require('jsbi'));
|
8
|
+
var invariant = _interopDefault(require('tiny-invariant'));
|
9
|
+
var warning = _interopDefault(require('tiny-warning'));
|
10
|
+
var address = require('@ethersproject/address');
|
11
|
+
var _Big = _interopDefault(require('big.js'));
|
12
|
+
var toFormat = _interopDefault(require('toformat'));
|
13
|
+
var _Decimal = _interopDefault(require('decimal.js-light'));
|
14
|
+
var solidity = require('@ethersproject/solidity');
|
15
|
+
var contracts = require('@ethersproject/contracts');
|
16
|
+
var networks = require('@ethersproject/networks');
|
17
|
+
var providers = require('@ethersproject/providers');
|
18
|
+
var IUniswapV2Pair = _interopDefault(require('@uniswap/v2-core/build/IUniswapV2Pair.json'));
|
19
|
+
|
20
|
+
var _SOLIDITY_TYPE_MAXIMA;
|
21
|
+
|
22
|
+
(function (ChainId) {
|
23
|
+
ChainId[ChainId["MAINNET"] = 1] = "MAINNET";
|
24
|
+
ChainId[ChainId["ROPSTEN"] = 3] = "ROPSTEN";
|
25
|
+
ChainId[ChainId["RINKEBY"] = 4] = "RINKEBY";
|
26
|
+
ChainId[ChainId["G\xD6RLI"] = 5] = "G\xD6RLI";
|
27
|
+
ChainId[ChainId["RSK"] = 30] = "RSK";
|
28
|
+
ChainId[ChainId["RSKTEST"] = 31] = "RSKTEST";
|
29
|
+
ChainId[ChainId["KOVAN"] = 42] = "KOVAN";
|
30
|
+
ChainId[ChainId["BINANCE"] = 56] = "BINANCE";
|
31
|
+
ChainId[ChainId["BINANCETEST"] = 97] = "BINANCETEST";
|
32
|
+
ChainId[ChainId["XDAI"] = 100] = "XDAI";
|
33
|
+
ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
|
34
|
+
})(exports.ChainId || (exports.ChainId = {}));
|
35
|
+
|
36
|
+
(function (TradeType) {
|
37
|
+
TradeType[TradeType["EXACT_INPUT"] = 0] = "EXACT_INPUT";
|
38
|
+
TradeType[TradeType["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT";
|
39
|
+
})(exports.TradeType || (exports.TradeType = {}));
|
40
|
+
|
41
|
+
(function (Rounding) {
|
42
|
+
Rounding[Rounding["ROUND_DOWN"] = 0] = "ROUND_DOWN";
|
43
|
+
Rounding[Rounding["ROUND_HALF_UP"] = 1] = "ROUND_HALF_UP";
|
44
|
+
Rounding[Rounding["ROUND_UP"] = 2] = "ROUND_UP";
|
45
|
+
})(exports.Rounding || (exports.Rounding = {}));
|
46
|
+
|
47
|
+
var FACTORY_ADDRESS = '0x063af7b01B067eE135344FEf85d6Aecea14CFA05';
|
48
|
+
var INIT_CODE_HASH = '0x6c0dd0b3d906c70e40fd9e96936f31ff1b70fe5784bae36fcbab40725d974a67';
|
49
|
+
var MINIMUM_LIQUIDITY = /*#__PURE__*/JSBI.BigInt(1000); // exports for internal consumption
|
50
|
+
|
51
|
+
var ZERO = /*#__PURE__*/JSBI.BigInt(0);
|
52
|
+
var ONE = /*#__PURE__*/JSBI.BigInt(1);
|
53
|
+
var TWO = /*#__PURE__*/JSBI.BigInt(2);
|
54
|
+
var THREE = /*#__PURE__*/JSBI.BigInt(3);
|
55
|
+
var FIVE = /*#__PURE__*/JSBI.BigInt(5);
|
56
|
+
var TEN = /*#__PURE__*/JSBI.BigInt(10);
|
57
|
+
var _100 = /*#__PURE__*/JSBI.BigInt(100);
|
58
|
+
var _997 = /*#__PURE__*/JSBI.BigInt(997);
|
59
|
+
var _1000 = /*#__PURE__*/JSBI.BigInt(1000);
|
60
|
+
var SolidityType;
|
61
|
+
|
62
|
+
(function (SolidityType) {
|
63
|
+
SolidityType["uint8"] = "uint8";
|
64
|
+
SolidityType["uint256"] = "uint256";
|
65
|
+
})(SolidityType || (SolidityType = {}));
|
66
|
+
|
67
|
+
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);
|
68
|
+
|
69
|
+
function _defineProperties(target, props) {
|
70
|
+
for (var i = 0; i < props.length; i++) {
|
71
|
+
var descriptor = props[i];
|
72
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
73
|
+
descriptor.configurable = true;
|
74
|
+
if ("value" in descriptor) descriptor.writable = true;
|
75
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
80
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
81
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
82
|
+
return Constructor;
|
83
|
+
}
|
84
|
+
|
85
|
+
function _extends() {
|
86
|
+
_extends = Object.assign || function (target) {
|
87
|
+
for (var i = 1; i < arguments.length; i++) {
|
88
|
+
var source = arguments[i];
|
89
|
+
|
90
|
+
for (var key in source) {
|
91
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
92
|
+
target[key] = source[key];
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
return target;
|
98
|
+
};
|
99
|
+
|
100
|
+
return _extends.apply(this, arguments);
|
101
|
+
}
|
102
|
+
|
103
|
+
function _inheritsLoose(subClass, superClass) {
|
104
|
+
subClass.prototype = Object.create(superClass.prototype);
|
105
|
+
subClass.prototype.constructor = subClass;
|
106
|
+
|
107
|
+
_setPrototypeOf(subClass, superClass);
|
108
|
+
}
|
109
|
+
|
110
|
+
function _getPrototypeOf(o) {
|
111
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
112
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
113
|
+
};
|
114
|
+
return _getPrototypeOf(o);
|
115
|
+
}
|
116
|
+
|
117
|
+
function _setPrototypeOf(o, p) {
|
118
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
119
|
+
o.__proto__ = p;
|
120
|
+
return o;
|
121
|
+
};
|
122
|
+
|
123
|
+
return _setPrototypeOf(o, p);
|
124
|
+
}
|
125
|
+
|
126
|
+
function _isNativeReflectConstruct() {
|
127
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
128
|
+
if (Reflect.construct.sham) return false;
|
129
|
+
if (typeof Proxy === "function") return true;
|
130
|
+
|
131
|
+
try {
|
132
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
133
|
+
return true;
|
134
|
+
} catch (e) {
|
135
|
+
return false;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
function _construct(Parent, args, Class) {
|
140
|
+
if (_isNativeReflectConstruct()) {
|
141
|
+
_construct = Reflect.construct;
|
142
|
+
} else {
|
143
|
+
_construct = function _construct(Parent, args, Class) {
|
144
|
+
var a = [null];
|
145
|
+
a.push.apply(a, args);
|
146
|
+
var Constructor = Function.bind.apply(Parent, a);
|
147
|
+
var instance = new Constructor();
|
148
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
149
|
+
return instance;
|
150
|
+
};
|
151
|
+
}
|
152
|
+
|
153
|
+
return _construct.apply(null, arguments);
|
154
|
+
}
|
155
|
+
|
156
|
+
function _isNativeFunction(fn) {
|
157
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
158
|
+
}
|
159
|
+
|
160
|
+
function _wrapNativeSuper(Class) {
|
161
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
162
|
+
|
163
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
164
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
165
|
+
|
166
|
+
if (typeof Class !== "function") {
|
167
|
+
throw new TypeError("Super expression must either be null or a function");
|
168
|
+
}
|
169
|
+
|
170
|
+
if (typeof _cache !== "undefined") {
|
171
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
172
|
+
|
173
|
+
_cache.set(Class, Wrapper);
|
174
|
+
}
|
175
|
+
|
176
|
+
function Wrapper() {
|
177
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
178
|
+
}
|
179
|
+
|
180
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
181
|
+
constructor: {
|
182
|
+
value: Wrapper,
|
183
|
+
enumerable: false,
|
184
|
+
writable: true,
|
185
|
+
configurable: true
|
186
|
+
}
|
187
|
+
});
|
188
|
+
return _setPrototypeOf(Wrapper, Class);
|
189
|
+
};
|
190
|
+
|
191
|
+
return _wrapNativeSuper(Class);
|
192
|
+
}
|
193
|
+
|
194
|
+
function _assertThisInitialized(self) {
|
195
|
+
if (self === void 0) {
|
196
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
197
|
+
}
|
198
|
+
|
199
|
+
return self;
|
200
|
+
}
|
201
|
+
|
202
|
+
function _unsupportedIterableToArray(o, minLen) {
|
203
|
+
if (!o) return;
|
204
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
205
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
206
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
207
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
208
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
209
|
+
}
|
210
|
+
|
211
|
+
function _arrayLikeToArray(arr, len) {
|
212
|
+
if (len == null || len > arr.length) len = arr.length;
|
213
|
+
|
214
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
215
|
+
|
216
|
+
return arr2;
|
217
|
+
}
|
218
|
+
|
219
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
220
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
221
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
222
|
+
|
223
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
224
|
+
if (it) o = it;
|
225
|
+
var i = 0;
|
226
|
+
return function () {
|
227
|
+
if (i >= o.length) return {
|
228
|
+
done: true
|
229
|
+
};
|
230
|
+
return {
|
231
|
+
done: false,
|
232
|
+
value: o[i++]
|
233
|
+
};
|
234
|
+
};
|
235
|
+
}
|
236
|
+
|
237
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
238
|
+
}
|
239
|
+
|
240
|
+
// see https://stackoverflow.com/a/41102306
|
241
|
+
var CAN_SET_PROTOTYPE = ('setPrototypeOf' in Object);
|
242
|
+
/**
|
243
|
+
* Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be
|
244
|
+
* obtained by sending any amount of input.
|
245
|
+
*/
|
246
|
+
|
247
|
+
var InsufficientReservesError = /*#__PURE__*/function (_Error) {
|
248
|
+
_inheritsLoose(InsufficientReservesError, _Error);
|
249
|
+
|
250
|
+
function InsufficientReservesError() {
|
251
|
+
var _this;
|
252
|
+
|
253
|
+
_this = _Error.call(this) || this;
|
254
|
+
_this.isInsufficientReservesError = true;
|
255
|
+
_this.name = _this.constructor.name;
|
256
|
+
if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(_assertThisInitialized(_this), (this instanceof InsufficientReservesError ? this.constructor : void 0).prototype);
|
257
|
+
return _this;
|
258
|
+
}
|
259
|
+
|
260
|
+
return InsufficientReservesError;
|
261
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
262
|
+
/**
|
263
|
+
* Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less
|
264
|
+
* than the price of a single unit of output after fees.
|
265
|
+
*/
|
266
|
+
|
267
|
+
var InsufficientInputAmountError = /*#__PURE__*/function (_Error2) {
|
268
|
+
_inheritsLoose(InsufficientInputAmountError, _Error2);
|
269
|
+
|
270
|
+
function InsufficientInputAmountError() {
|
271
|
+
var _this2;
|
272
|
+
|
273
|
+
_this2 = _Error2.call(this) || this;
|
274
|
+
_this2.isInsufficientInputAmountError = true;
|
275
|
+
_this2.name = _this2.constructor.name;
|
276
|
+
if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(_assertThisInitialized(_this2), (this instanceof InsufficientInputAmountError ? this.constructor : void 0).prototype);
|
277
|
+
return _this2;
|
278
|
+
}
|
279
|
+
|
280
|
+
return InsufficientInputAmountError;
|
281
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
282
|
+
|
283
|
+
function validateSolidityTypeInstance(value, solidityType) {
|
284
|
+
!JSBI.greaterThanOrEqual(value, ZERO) ? invariant(false, value + " is not a " + solidityType + ".") : void 0;
|
285
|
+
!JSBI.lessThanOrEqual(value, SOLIDITY_TYPE_MAXIMA[solidityType]) ? invariant(false, value + " is not a " + solidityType + ".") : void 0;
|
286
|
+
} // warns if addresses are not checksummed
|
287
|
+
|
288
|
+
function validateAndParseAddress(address$1) {
|
289
|
+
try {
|
290
|
+
var checksummedAddress = address.getAddress(address$1);
|
291
|
+
"development" !== "production" ? warning(address$1 === checksummedAddress, address$1 + " is not checksummed.") : void 0;
|
292
|
+
return checksummedAddress;
|
293
|
+
} catch (error) {
|
294
|
+
invariant(false, address$1 + " is not a valid address.") ;
|
295
|
+
}
|
296
|
+
}
|
297
|
+
function parseBigintIsh(bigintIsh) {
|
298
|
+
return bigintIsh instanceof JSBI ? bigintIsh : typeof bigintIsh === 'bigint' ? JSBI.BigInt(bigintIsh.toString()) : JSBI.BigInt(bigintIsh);
|
299
|
+
} // mock the on-chain sqrt function
|
300
|
+
|
301
|
+
function sqrt(y) {
|
302
|
+
validateSolidityTypeInstance(y, SolidityType.uint256);
|
303
|
+
var z = ZERO;
|
304
|
+
var x;
|
305
|
+
|
306
|
+
if (JSBI.greaterThan(y, THREE)) {
|
307
|
+
z = y;
|
308
|
+
x = JSBI.add(JSBI.divide(y, TWO), ONE);
|
309
|
+
|
310
|
+
while (JSBI.lessThan(x, z)) {
|
311
|
+
z = x;
|
312
|
+
x = JSBI.divide(JSBI.add(JSBI.divide(y, x), x), TWO);
|
313
|
+
}
|
314
|
+
} else if (JSBI.notEqual(y, ZERO)) {
|
315
|
+
z = ONE;
|
316
|
+
}
|
317
|
+
|
318
|
+
return z;
|
319
|
+
} // given an array of items sorted by `comparator`, insert an item into its sort index and constrain the size to
|
320
|
+
// `maxSize` by removing the last item
|
321
|
+
|
322
|
+
function sortedInsert(items, add, maxSize, comparator) {
|
323
|
+
!(maxSize > 0) ? invariant(false, 'MAX_SIZE_ZERO') : void 0; // this is an invariant because the interface cannot return multiple removed items if items.length exceeds maxSize
|
324
|
+
|
325
|
+
!(items.length <= maxSize) ? invariant(false, 'ITEMS_SIZE') : void 0; // short circuit first item add
|
326
|
+
|
327
|
+
if (items.length === 0) {
|
328
|
+
items.push(add);
|
329
|
+
return null;
|
330
|
+
} else {
|
331
|
+
var isFull = items.length === maxSize; // short circuit if full and the additional item does not come before the last item
|
332
|
+
|
333
|
+
if (isFull && comparator(items[items.length - 1], add) <= 0) {
|
334
|
+
return add;
|
335
|
+
}
|
336
|
+
|
337
|
+
var lo = 0,
|
338
|
+
hi = items.length;
|
339
|
+
|
340
|
+
while (lo < hi) {
|
341
|
+
var mid = lo + hi >>> 1;
|
342
|
+
|
343
|
+
if (comparator(items[mid], add) <= 0) {
|
344
|
+
lo = mid + 1;
|
345
|
+
} else {
|
346
|
+
hi = mid;
|
347
|
+
}
|
348
|
+
}
|
349
|
+
|
350
|
+
items.splice(lo, 0, add);
|
351
|
+
return isFull ? items.pop() : null;
|
352
|
+
}
|
353
|
+
}
|
354
|
+
|
355
|
+
/**
|
356
|
+
* A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens.
|
357
|
+
*
|
358
|
+
* The only instance of the base class `Currency` is Ether.
|
359
|
+
*/
|
360
|
+
|
361
|
+
var Currency = /*#__PURE__*/function () {
|
362
|
+
/**
|
363
|
+
* Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`.
|
364
|
+
* @param decimals decimals of the currency
|
365
|
+
* @param symbol symbol of the currency
|
366
|
+
* @param name of the currency
|
367
|
+
*/
|
368
|
+
function Currency(decimals, symbol, name) {
|
369
|
+
validateSolidityTypeInstance(JSBI.BigInt(decimals), SolidityType.uint8);
|
370
|
+
this.decimals = decimals;
|
371
|
+
this.symbol = symbol;
|
372
|
+
this.name = name;
|
373
|
+
}
|
374
|
+
|
375
|
+
var _proto = Currency.prototype;
|
376
|
+
|
377
|
+
_proto.change = function change(cId) {
|
378
|
+
if (cId == 1) {
|
379
|
+
ETHER.name = "Ether";
|
380
|
+
ETHER.symbol = "ETH";
|
381
|
+
}
|
382
|
+
|
383
|
+
if (cId == 56) {
|
384
|
+
ETHER.name = "BNB";
|
385
|
+
ETHER.symbol = "BNB";
|
386
|
+
}
|
387
|
+
|
388
|
+
if (cId == 137) {
|
389
|
+
ETHER.name = "Matic";
|
390
|
+
ETHER.symbol = "MATIC";
|
391
|
+
}
|
392
|
+
|
393
|
+
if (cId == 30) {
|
394
|
+
ETHER.name = "Smart Bitcoin";
|
395
|
+
ETHER.symbol = "RBTC";
|
396
|
+
}
|
397
|
+
|
398
|
+
if (cId == 31) {
|
399
|
+
ETHER.name = "Smart Bitcoin";
|
400
|
+
ETHER.symbol = "tRBTC";
|
401
|
+
}
|
402
|
+
};
|
403
|
+
|
404
|
+
return Currency;
|
405
|
+
}();
|
406
|
+
/**
|
407
|
+
* The only instance of the base class `Currency`.
|
408
|
+
*/
|
409
|
+
|
410
|
+
Currency.ETHER = /*#__PURE__*/new Currency(18, 'BNB', 'BNB');
|
411
|
+
var ETHER = Currency.ETHER;
|
412
|
+
|
413
|
+
var _WETH;
|
414
|
+
/**
|
415
|
+
* Represents an ERC20 token with a unique address and some metadata.
|
416
|
+
*/
|
417
|
+
|
418
|
+
var Token = /*#__PURE__*/function (_Currency) {
|
419
|
+
_inheritsLoose(Token, _Currency);
|
420
|
+
|
421
|
+
function Token(chainId, address, decimals, symbol, name) {
|
422
|
+
var _this;
|
423
|
+
|
424
|
+
_this = _Currency.call(this, decimals, symbol, name) || this;
|
425
|
+
_this.chainId = chainId;
|
426
|
+
_this.address = validateAndParseAddress(address);
|
427
|
+
return _this;
|
428
|
+
}
|
429
|
+
/**
|
430
|
+
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
|
431
|
+
* @param other other token to compare
|
432
|
+
*/
|
433
|
+
|
434
|
+
|
435
|
+
var _proto = Token.prototype;
|
436
|
+
|
437
|
+
_proto.equals = function equals(other) {
|
438
|
+
// short circuit on reference equality
|
439
|
+
if (this === other) {
|
440
|
+
return true;
|
441
|
+
}
|
442
|
+
|
443
|
+
return this.chainId === other.chainId && this.address === other.address;
|
444
|
+
}
|
445
|
+
/**
|
446
|
+
* Returns true if the address of this token sorts before the address of the other token
|
447
|
+
* @param other other token to compare
|
448
|
+
* @throws if the tokens have the same address
|
449
|
+
* @throws if the tokens are on different chains
|
450
|
+
*/
|
451
|
+
;
|
452
|
+
|
453
|
+
_proto.sortsBefore = function sortsBefore(other) {
|
454
|
+
!(this.chainId === other.chainId) ? invariant(false, 'CHAIN_IDS') : void 0;
|
455
|
+
!(this.address !== other.address) ? invariant(false, 'ADDRESSES') : void 0;
|
456
|
+
return this.address.toLowerCase() < other.address.toLowerCase();
|
457
|
+
};
|
458
|
+
|
459
|
+
return Token;
|
460
|
+
}(Currency);
|
461
|
+
/**
|
462
|
+
* Compares two currencies for equality
|
463
|
+
*/
|
464
|
+
|
465
|
+
function currencyEquals(currencyA, currencyB) {
|
466
|
+
if (currencyA instanceof Token && currencyB instanceof Token) {
|
467
|
+
return currencyA.equals(currencyB);
|
468
|
+
} else if (currencyA instanceof Token) {
|
469
|
+
return false;
|
470
|
+
} else if (currencyB instanceof Token) {
|
471
|
+
return false;
|
472
|
+
} else {
|
473
|
+
return currencyA === currencyB;
|
474
|
+
}
|
475
|
+
}
|
476
|
+
var WETH = (_WETH = {}, _WETH[exports.ChainId.MAINNET] = /*#__PURE__*/new Token(exports.ChainId.MAINNET, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH', 'Wrapped Ether'), _WETH[exports.ChainId.ROPSTEN] = /*#__PURE__*/new Token(exports.ChainId.ROPSTEN, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH', 'Wrapped Ether'), _WETH[exports.ChainId.RINKEBY] = /*#__PURE__*/new Token(exports.ChainId.RINKEBY, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH', 'Wrapped Ether'), _WETH[exports.ChainId.GÖRLI] = /*#__PURE__*/new Token(exports.ChainId.GÖRLI, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 18, 'WETH', 'Wrapped Ether'), _WETH[exports.ChainId.KOVAN] = /*#__PURE__*/new Token(exports.ChainId.KOVAN, '0xd0A1E359811322d97991E03f863a0C30C2cF029C', 18, 'WETH', 'Wrapped Ether'), _WETH[exports.ChainId.BINANCE] = /*#__PURE__*/new Token(exports.ChainId.BINANCE, '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', 18, 'WBNB', 'Wrapped BNB'), _WETH[exports.ChainId.BINANCETEST] = /*#__PURE__*/new Token(exports.ChainId.BINANCETEST, '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', 18, 'WBNB', 'Wrapped BNB'), _WETH[exports.ChainId.RSK] = /*#__PURE__*/new Token(exports.ChainId.RSK, '0xFa26ecdA879AC88AfD047cc6e046E85B9aFBa2CC', 18, 'WrBTC', 'Wrapped rBTC'), _WETH[exports.ChainId.RSKTEST] = /*#__PURE__*/new Token(exports.ChainId.RSKTEST, '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', 18, 'WBNB', 'Wrapped BNB'), _WETH[exports.ChainId.XDAI] = /*#__PURE__*/new Token(exports.ChainId.XDAI, '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', 18, 'WXDAI', 'Wrapped XDAI'), _WETH[exports.ChainId.POLYGON] = /*#__PURE__*/new Token(exports.ChainId.POLYGON, '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', 18, 'WMATIC', 'Wrapped Matic'), _WETH);
|
477
|
+
|
478
|
+
var _toSignificantRoundin, _toFixedRounding;
|
479
|
+
var Decimal = /*#__PURE__*/toFormat(_Decimal);
|
480
|
+
var Big = /*#__PURE__*/toFormat(_Big);
|
481
|
+
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);
|
482
|
+
var toFixedRounding = (_toFixedRounding = {}, _toFixedRounding[exports.Rounding.ROUND_DOWN] = 0, _toFixedRounding[exports.Rounding.ROUND_HALF_UP] = 1, _toFixedRounding[exports.Rounding.ROUND_UP] = 3, _toFixedRounding);
|
483
|
+
var Fraction = /*#__PURE__*/function () {
|
484
|
+
function Fraction(numerator, denominator) {
|
485
|
+
if (denominator === void 0) {
|
486
|
+
denominator = ONE;
|
487
|
+
}
|
488
|
+
|
489
|
+
this.numerator = parseBigintIsh(numerator);
|
490
|
+
this.denominator = parseBigintIsh(denominator);
|
491
|
+
} // performs floor division
|
492
|
+
|
493
|
+
|
494
|
+
var _proto = Fraction.prototype;
|
495
|
+
|
496
|
+
_proto.invert = function invert() {
|
497
|
+
return new Fraction(this.denominator, this.numerator);
|
498
|
+
};
|
499
|
+
|
500
|
+
_proto.add = function add(other) {
|
501
|
+
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
|
502
|
+
|
503
|
+
if (JSBI.equal(this.denominator, otherParsed.denominator)) {
|
504
|
+
return new Fraction(JSBI.add(this.numerator, otherParsed.numerator), this.denominator);
|
505
|
+
}
|
506
|
+
|
507
|
+
return new Fraction(JSBI.add(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator));
|
508
|
+
};
|
509
|
+
|
510
|
+
_proto.subtract = function subtract(other) {
|
511
|
+
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
|
512
|
+
|
513
|
+
if (JSBI.equal(this.denominator, otherParsed.denominator)) {
|
514
|
+
return new Fraction(JSBI.subtract(this.numerator, otherParsed.numerator), this.denominator);
|
515
|
+
}
|
516
|
+
|
517
|
+
return new Fraction(JSBI.subtract(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator));
|
518
|
+
};
|
519
|
+
|
520
|
+
_proto.lessThan = function lessThan(other) {
|
521
|
+
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
|
522
|
+
return JSBI.lessThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
|
523
|
+
};
|
524
|
+
|
525
|
+
_proto.equalTo = function equalTo(other) {
|
526
|
+
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
|
527
|
+
return JSBI.equal(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
|
528
|
+
};
|
529
|
+
|
530
|
+
_proto.greaterThan = function greaterThan(other) {
|
531
|
+
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
|
532
|
+
return JSBI.greaterThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
|
533
|
+
};
|
534
|
+
|
535
|
+
_proto.multiply = function multiply(other) {
|
536
|
+
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
|
537
|
+
return new Fraction(JSBI.multiply(this.numerator, otherParsed.numerator), JSBI.multiply(this.denominator, otherParsed.denominator));
|
538
|
+
};
|
539
|
+
|
540
|
+
_proto.divide = function divide(other) {
|
541
|
+
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
|
542
|
+
return new Fraction(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(this.denominator, otherParsed.numerator));
|
543
|
+
};
|
544
|
+
|
545
|
+
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
|
546
|
+
if (format === void 0) {
|
547
|
+
format = {
|
548
|
+
groupSeparator: ''
|
549
|
+
};
|
550
|
+
}
|
551
|
+
|
552
|
+
if (rounding === void 0) {
|
553
|
+
rounding = exports.Rounding.ROUND_HALF_UP;
|
554
|
+
}
|
555
|
+
|
556
|
+
!Number.isInteger(significantDigits) ? invariant(false, significantDigits + " is not an integer.") : void 0;
|
557
|
+
!(significantDigits > 0) ? invariant(false, significantDigits + " is not positive.") : void 0;
|
558
|
+
Decimal.set({
|
559
|
+
precision: significantDigits + 1,
|
560
|
+
rounding: toSignificantRounding[rounding]
|
561
|
+
});
|
562
|
+
var quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits);
|
563
|
+
return quotient.toFormat(quotient.decimalPlaces(), format);
|
564
|
+
};
|
565
|
+
|
566
|
+
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) {
|
567
|
+
if (format === void 0) {
|
568
|
+
format = {
|
569
|
+
groupSeparator: ''
|
570
|
+
};
|
571
|
+
}
|
572
|
+
|
573
|
+
if (rounding === void 0) {
|
574
|
+
rounding = exports.Rounding.ROUND_HALF_UP;
|
575
|
+
}
|
576
|
+
|
577
|
+
!Number.isInteger(decimalPlaces) ? invariant(false, decimalPlaces + " is not an integer.") : void 0;
|
578
|
+
!(decimalPlaces >= 0) ? invariant(false, decimalPlaces + " is negative.") : void 0;
|
579
|
+
Big.DP = decimalPlaces;
|
580
|
+
Big.RM = toFixedRounding[rounding];
|
581
|
+
return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format);
|
582
|
+
};
|
583
|
+
|
584
|
+
_createClass(Fraction, [{
|
585
|
+
key: "quotient",
|
586
|
+
get: function get() {
|
587
|
+
return JSBI.divide(this.numerator, this.denominator);
|
588
|
+
} // remainder after floor division
|
589
|
+
|
590
|
+
}, {
|
591
|
+
key: "remainder",
|
592
|
+
get: function get() {
|
593
|
+
return new Fraction(JSBI.remainder(this.numerator, this.denominator), this.denominator);
|
594
|
+
}
|
595
|
+
}]);
|
596
|
+
|
597
|
+
return Fraction;
|
598
|
+
}();
|
599
|
+
|
600
|
+
var Big$1 = /*#__PURE__*/toFormat(_Big);
|
601
|
+
var CurrencyAmount = /*#__PURE__*/function (_Fraction) {
|
602
|
+
_inheritsLoose(CurrencyAmount, _Fraction);
|
603
|
+
|
604
|
+
// amount _must_ be raw, i.e. in the native representation
|
605
|
+
function CurrencyAmount(currency, amount) {
|
606
|
+
var _this;
|
607
|
+
|
608
|
+
var parsedAmount = parseBigintIsh(amount);
|
609
|
+
validateSolidityTypeInstance(parsedAmount, SolidityType.uint256);
|
610
|
+
_this = _Fraction.call(this, parsedAmount, JSBI.exponentiate(TEN, JSBI.BigInt(currency.decimals))) || this;
|
611
|
+
_this.currency = currency;
|
612
|
+
return _this;
|
613
|
+
}
|
614
|
+
/**
|
615
|
+
* Helper that calls the constructor with the ETHER currency
|
616
|
+
* @param amount ether amount in wei
|
617
|
+
*/
|
618
|
+
|
619
|
+
|
620
|
+
CurrencyAmount.ether = function ether(amount) {
|
621
|
+
return new CurrencyAmount(ETHER, amount);
|
622
|
+
};
|
623
|
+
|
624
|
+
var _proto = CurrencyAmount.prototype;
|
625
|
+
|
626
|
+
_proto.add = function add(other) {
|
627
|
+
!currencyEquals(this.currency, other.currency) ? invariant(false, 'TOKEN') : void 0;
|
628
|
+
return new CurrencyAmount(this.currency, JSBI.add(this.raw, other.raw));
|
629
|
+
};
|
630
|
+
|
631
|
+
_proto.subtract = function subtract(other) {
|
632
|
+
!currencyEquals(this.currency, other.currency) ? invariant(false, 'TOKEN') : void 0;
|
633
|
+
return new CurrencyAmount(this.currency, JSBI.subtract(this.raw, other.raw));
|
634
|
+
};
|
635
|
+
|
636
|
+
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
|
637
|
+
if (significantDigits === void 0) {
|
638
|
+
significantDigits = 6;
|
639
|
+
}
|
640
|
+
|
641
|
+
if (rounding === void 0) {
|
642
|
+
rounding = exports.Rounding.ROUND_DOWN;
|
643
|
+
}
|
644
|
+
|
645
|
+
return _Fraction.prototype.toSignificant.call(this, significantDigits, format, rounding);
|
646
|
+
};
|
647
|
+
|
648
|
+
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) {
|
649
|
+
if (decimalPlaces === void 0) {
|
650
|
+
decimalPlaces = this.currency.decimals;
|
651
|
+
}
|
652
|
+
|
653
|
+
if (rounding === void 0) {
|
654
|
+
rounding = exports.Rounding.ROUND_DOWN;
|
655
|
+
}
|
656
|
+
|
657
|
+
!(decimalPlaces <= this.currency.decimals) ? invariant(false, 'DECIMALS') : void 0;
|
658
|
+
return _Fraction.prototype.toFixed.call(this, decimalPlaces, format, rounding);
|
659
|
+
};
|
660
|
+
|
661
|
+
_proto.toExact = function toExact(format) {
|
662
|
+
if (format === void 0) {
|
663
|
+
format = {
|
664
|
+
groupSeparator: ''
|
665
|
+
};
|
666
|
+
}
|
667
|
+
|
668
|
+
Big$1.DP = this.currency.decimals;
|
669
|
+
return new Big$1(this.numerator.toString()).div(this.denominator.toString()).toFormat(format);
|
670
|
+
};
|
671
|
+
|
672
|
+
_createClass(CurrencyAmount, [{
|
673
|
+
key: "raw",
|
674
|
+
get: function get() {
|
675
|
+
return this.numerator;
|
676
|
+
}
|
677
|
+
}]);
|
678
|
+
|
679
|
+
return CurrencyAmount;
|
680
|
+
}(Fraction);
|
681
|
+
|
682
|
+
var TokenAmount = /*#__PURE__*/function (_CurrencyAmount) {
|
683
|
+
_inheritsLoose(TokenAmount, _CurrencyAmount);
|
684
|
+
|
685
|
+
// amount _must_ be raw, i.e. in the native representation
|
686
|
+
function TokenAmount(token, amount) {
|
687
|
+
var _this;
|
688
|
+
|
689
|
+
_this = _CurrencyAmount.call(this, token, amount) || this;
|
690
|
+
_this.token = token;
|
691
|
+
return _this;
|
692
|
+
}
|
693
|
+
|
694
|
+
var _proto = TokenAmount.prototype;
|
695
|
+
|
696
|
+
_proto.add = function add(other) {
|
697
|
+
!this.token.equals(other.token) ? invariant(false, 'TOKEN') : void 0;
|
698
|
+
return new TokenAmount(this.token, JSBI.add(this.raw, other.raw));
|
699
|
+
};
|
700
|
+
|
701
|
+
_proto.subtract = function subtract(other) {
|
702
|
+
!this.token.equals(other.token) ? invariant(false, 'TOKEN') : void 0;
|
703
|
+
return new TokenAmount(this.token, JSBI.subtract(this.raw, other.raw));
|
704
|
+
};
|
705
|
+
|
706
|
+
return TokenAmount;
|
707
|
+
}(CurrencyAmount);
|
708
|
+
|
709
|
+
var Price = /*#__PURE__*/function (_Fraction) {
|
710
|
+
_inheritsLoose(Price, _Fraction);
|
711
|
+
|
712
|
+
// denominator and numerator _must_ be raw, i.e. in the native representation
|
713
|
+
function Price(baseCurrency, quoteCurrency, denominator, numerator) {
|
714
|
+
var _this;
|
715
|
+
|
716
|
+
_this = _Fraction.call(this, numerator, denominator) || this;
|
717
|
+
_this.baseCurrency = baseCurrency;
|
718
|
+
_this.quoteCurrency = quoteCurrency;
|
719
|
+
_this.scalar = new Fraction(JSBI.exponentiate(TEN, JSBI.BigInt(baseCurrency.decimals)), JSBI.exponentiate(TEN, JSBI.BigInt(quoteCurrency.decimals)));
|
720
|
+
return _this;
|
721
|
+
}
|
722
|
+
|
723
|
+
Price.fromRoute = function fromRoute(route) {
|
724
|
+
var prices = [];
|
725
|
+
|
726
|
+
for (var _iterator = _createForOfIteratorHelperLoose(route.pairs.entries()), _step; !(_step = _iterator()).done;) {
|
727
|
+
var _step$value = _step.value,
|
728
|
+
i = _step$value[0],
|
729
|
+
pair = _step$value[1];
|
730
|
+
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));
|
731
|
+
}
|
732
|
+
|
733
|
+
return prices.slice(1).reduce(function (accumulator, currentValue) {
|
734
|
+
return accumulator.multiply(currentValue);
|
735
|
+
}, prices[0]);
|
736
|
+
};
|
737
|
+
|
738
|
+
var _proto = Price.prototype;
|
739
|
+
|
740
|
+
_proto.invert = function invert() {
|
741
|
+
return new Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator);
|
742
|
+
};
|
743
|
+
|
744
|
+
_proto.multiply = function multiply(other) {
|
745
|
+
!currencyEquals(this.quoteCurrency, other.baseCurrency) ? invariant(false, 'TOKEN') : void 0;
|
746
|
+
|
747
|
+
var fraction = _Fraction.prototype.multiply.call(this, other);
|
748
|
+
|
749
|
+
return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
|
750
|
+
} // performs floor division on overflow
|
751
|
+
;
|
752
|
+
|
753
|
+
_proto.quote = function quote(currencyAmount) {
|
754
|
+
!currencyEquals(currencyAmount.currency, this.baseCurrency) ? invariant(false, 'TOKEN') : void 0;
|
755
|
+
|
756
|
+
if (this.quoteCurrency instanceof Token) {
|
757
|
+
return new TokenAmount(this.quoteCurrency, _Fraction.prototype.multiply.call(this, currencyAmount.raw).quotient);
|
758
|
+
}
|
759
|
+
|
760
|
+
return CurrencyAmount.ether(_Fraction.prototype.multiply.call(this, currencyAmount.raw).quotient);
|
761
|
+
};
|
762
|
+
|
763
|
+
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
|
764
|
+
if (significantDigits === void 0) {
|
765
|
+
significantDigits = 6;
|
766
|
+
}
|
767
|
+
|
768
|
+
return this.adjusted.toSignificant(significantDigits, format, rounding);
|
769
|
+
};
|
770
|
+
|
771
|
+
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) {
|
772
|
+
if (decimalPlaces === void 0) {
|
773
|
+
decimalPlaces = 4;
|
774
|
+
}
|
775
|
+
|
776
|
+
return this.adjusted.toFixed(decimalPlaces, format, rounding);
|
777
|
+
};
|
778
|
+
|
779
|
+
_createClass(Price, [{
|
780
|
+
key: "raw",
|
781
|
+
get: function get() {
|
782
|
+
return new Fraction(this.numerator, this.denominator);
|
783
|
+
}
|
784
|
+
}, {
|
785
|
+
key: "adjusted",
|
786
|
+
get: function get() {
|
787
|
+
return _Fraction.prototype.multiply.call(this, this.scalar);
|
788
|
+
}
|
789
|
+
}]);
|
790
|
+
|
791
|
+
return Price;
|
792
|
+
}(Fraction);
|
793
|
+
|
794
|
+
var PAIR_ADDRESS_CACHE = {};
|
795
|
+
var Pair = /*#__PURE__*/function () {
|
796
|
+
function Pair(tokenAmountA, tokenAmountB) {
|
797
|
+
var tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) // does safety checks
|
798
|
+
? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA];
|
799
|
+
this.liquidityToken = new Token(tokenAmounts[0].token.chainId, Pair.getAddress(tokenAmounts[0].token, tokenAmounts[1].token), 18, 'UNI-V2', 'Uniswap V2');
|
800
|
+
this.tokenAmounts = tokenAmounts;
|
801
|
+
}
|
802
|
+
|
803
|
+
Pair.getAddress = function getAddress(tokenA, tokenB) {
|
804
|
+
var _PAIR_ADDRESS_CACHE, _PAIR_ADDRESS_CACHE$t;
|
805
|
+
|
806
|
+
var tokens = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA]; // does safety checks
|
807
|
+
|
808
|
+
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) {
|
809
|
+
var _PAIR_ADDRESS_CACHE2, _extends2, _extends3;
|
810
|
+
|
811
|
+
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] = address.getCreate2Address(FACTORY_ADDRESS, solidity.keccak256(['bytes'], [solidity.pack(['address', 'address'], [tokens[0].address, tokens[1].address])]), INIT_CODE_HASH), _extends2)), _extends3));
|
812
|
+
}
|
813
|
+
|
814
|
+
return PAIR_ADDRESS_CACHE[tokens[0].address][tokens[1].address];
|
815
|
+
}
|
816
|
+
/**
|
817
|
+
* Returns true if the token is either token0 or token1
|
818
|
+
* @param token to check
|
819
|
+
*/
|
820
|
+
;
|
821
|
+
|
822
|
+
var _proto = Pair.prototype;
|
823
|
+
|
824
|
+
_proto.involvesToken = function involvesToken(token) {
|
825
|
+
return token.equals(this.token0) || token.equals(this.token1);
|
826
|
+
}
|
827
|
+
/**
|
828
|
+
* Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
|
829
|
+
*/
|
830
|
+
;
|
831
|
+
|
832
|
+
/**
|
833
|
+
* Return the price of the given token in terms of the other token in the pair.
|
834
|
+
* @param token token to return price of
|
835
|
+
*/
|
836
|
+
_proto.priceOf = function priceOf(token) {
|
837
|
+
!this.involvesToken(token) ? invariant(false, 'TOKEN') : void 0;
|
838
|
+
return token.equals(this.token0) ? this.token0Price : this.token1Price;
|
839
|
+
}
|
840
|
+
/**
|
841
|
+
* Returns the chain ID of the tokens in the pair.
|
842
|
+
*/
|
843
|
+
;
|
844
|
+
|
845
|
+
_proto.reserveOf = function reserveOf(token) {
|
846
|
+
!this.involvesToken(token) ? invariant(false, 'TOKEN') : void 0;
|
847
|
+
return token.equals(this.token0) ? this.reserve0 : this.reserve1;
|
848
|
+
};
|
849
|
+
|
850
|
+
_proto.getOutputAmount = function getOutputAmount(inputAmount) {
|
851
|
+
!this.involvesToken(inputAmount.token) ? invariant(false, 'TOKEN') : void 0;
|
852
|
+
|
853
|
+
if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO)) {
|
854
|
+
throw new InsufficientReservesError();
|
855
|
+
}
|
856
|
+
|
857
|
+
var inputReserve = this.reserveOf(inputAmount.token);
|
858
|
+
var outputReserve = this.reserveOf(inputAmount.token.equals(this.token0) ? this.token1 : this.token0);
|
859
|
+
var inputAmountWithFee = JSBI.multiply(inputAmount.raw, _997);
|
860
|
+
var numerator = JSBI.multiply(inputAmountWithFee, outputReserve.raw);
|
861
|
+
var denominator = JSBI.add(JSBI.multiply(inputReserve.raw, _1000), inputAmountWithFee);
|
862
|
+
var outputAmount = new TokenAmount(inputAmount.token.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator));
|
863
|
+
|
864
|
+
if (JSBI.equal(outputAmount.raw, ZERO)) {
|
865
|
+
throw new InsufficientInputAmountError();
|
866
|
+
}
|
867
|
+
|
868
|
+
return [outputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
|
869
|
+
};
|
870
|
+
|
871
|
+
_proto.getInputAmount = function getInputAmount(outputAmount) {
|
872
|
+
!this.involvesToken(outputAmount.token) ? invariant(false, 'TOKEN') : void 0;
|
873
|
+
|
874
|
+
if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO) || JSBI.greaterThanOrEqual(outputAmount.raw, this.reserveOf(outputAmount.token).raw)) {
|
875
|
+
throw new InsufficientReservesError();
|
876
|
+
}
|
877
|
+
|
878
|
+
var outputReserve = this.reserveOf(outputAmount.token);
|
879
|
+
var inputReserve = this.reserveOf(outputAmount.token.equals(this.token0) ? this.token1 : this.token0);
|
880
|
+
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.raw, outputAmount.raw), _1000);
|
881
|
+
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.raw, outputAmount.raw), _997);
|
882
|
+
var inputAmount = new TokenAmount(outputAmount.token.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE));
|
883
|
+
return [inputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
|
884
|
+
};
|
885
|
+
|
886
|
+
_proto.getLiquidityMinted = function getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) {
|
887
|
+
!totalSupply.token.equals(this.liquidityToken) ? invariant(false, 'LIQUIDITY') : void 0;
|
888
|
+
var tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) // does safety checks
|
889
|
+
? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA];
|
890
|
+
!(tokenAmounts[0].token.equals(this.token0) && tokenAmounts[1].token.equals(this.token1)) ? invariant(false, 'TOKEN') : void 0;
|
891
|
+
var liquidity;
|
892
|
+
|
893
|
+
if (JSBI.equal(totalSupply.raw, ZERO)) {
|
894
|
+
liquidity = JSBI.subtract(sqrt(JSBI.multiply(tokenAmounts[0].raw, tokenAmounts[1].raw)), MINIMUM_LIQUIDITY);
|
895
|
+
} else {
|
896
|
+
var amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].raw, totalSupply.raw), this.reserve0.raw);
|
897
|
+
var amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].raw, totalSupply.raw), this.reserve1.raw);
|
898
|
+
liquidity = JSBI.lessThanOrEqual(amount0, amount1) ? amount0 : amount1;
|
899
|
+
}
|
900
|
+
|
901
|
+
if (!JSBI.greaterThan(liquidity, ZERO)) {
|
902
|
+
throw new InsufficientInputAmountError();
|
903
|
+
}
|
904
|
+
|
905
|
+
return new TokenAmount(this.liquidityToken, liquidity);
|
906
|
+
};
|
907
|
+
|
908
|
+
_proto.getLiquidityValue = function getLiquidityValue(token, totalSupply, liquidity, feeOn, kLast) {
|
909
|
+
if (feeOn === void 0) {
|
910
|
+
feeOn = false;
|
911
|
+
}
|
912
|
+
|
913
|
+
!this.involvesToken(token) ? invariant(false, 'TOKEN') : void 0;
|
914
|
+
!totalSupply.token.equals(this.liquidityToken) ? invariant(false, 'TOTAL_SUPPLY') : void 0;
|
915
|
+
!liquidity.token.equals(this.liquidityToken) ? invariant(false, 'LIQUIDITY') : void 0;
|
916
|
+
!JSBI.lessThanOrEqual(liquidity.raw, totalSupply.raw) ? invariant(false, 'LIQUIDITY') : void 0;
|
917
|
+
var totalSupplyAdjusted;
|
918
|
+
|
919
|
+
if (!feeOn) {
|
920
|
+
totalSupplyAdjusted = totalSupply;
|
921
|
+
} else {
|
922
|
+
!!!kLast ? invariant(false, 'K_LAST') : void 0;
|
923
|
+
var kLastParsed = parseBigintIsh(kLast);
|
924
|
+
|
925
|
+
if (!JSBI.equal(kLastParsed, ZERO)) {
|
926
|
+
var rootK = sqrt(JSBI.multiply(this.reserve0.raw, this.reserve1.raw));
|
927
|
+
var rootKLast = sqrt(kLastParsed);
|
928
|
+
|
929
|
+
if (JSBI.greaterThan(rootK, rootKLast)) {
|
930
|
+
var numerator = JSBI.multiply(totalSupply.raw, JSBI.subtract(rootK, rootKLast));
|
931
|
+
var denominator = JSBI.add(JSBI.multiply(rootK, FIVE), rootKLast);
|
932
|
+
var feeLiquidity = JSBI.divide(numerator, denominator);
|
933
|
+
totalSupplyAdjusted = totalSupply.add(new TokenAmount(this.liquidityToken, feeLiquidity));
|
934
|
+
} else {
|
935
|
+
totalSupplyAdjusted = totalSupply;
|
936
|
+
}
|
937
|
+
} else {
|
938
|
+
totalSupplyAdjusted = totalSupply;
|
939
|
+
}
|
940
|
+
}
|
941
|
+
|
942
|
+
return new TokenAmount(token, JSBI.divide(JSBI.multiply(liquidity.raw, this.reserveOf(token).raw), totalSupplyAdjusted.raw));
|
943
|
+
};
|
944
|
+
|
945
|
+
_createClass(Pair, [{
|
946
|
+
key: "token0Price",
|
947
|
+
get: function get() {
|
948
|
+
return new Price(this.token0, this.token1, this.tokenAmounts[0].raw, this.tokenAmounts[1].raw);
|
949
|
+
}
|
950
|
+
/**
|
951
|
+
* Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
|
952
|
+
*/
|
953
|
+
|
954
|
+
}, {
|
955
|
+
key: "token1Price",
|
956
|
+
get: function get() {
|
957
|
+
return new Price(this.token1, this.token0, this.tokenAmounts[1].raw, this.tokenAmounts[0].raw);
|
958
|
+
}
|
959
|
+
}, {
|
960
|
+
key: "chainId",
|
961
|
+
get: function get() {
|
962
|
+
return this.token0.chainId;
|
963
|
+
}
|
964
|
+
}, {
|
965
|
+
key: "token0",
|
966
|
+
get: function get() {
|
967
|
+
return this.tokenAmounts[0].token;
|
968
|
+
}
|
969
|
+
}, {
|
970
|
+
key: "token1",
|
971
|
+
get: function get() {
|
972
|
+
return this.tokenAmounts[1].token;
|
973
|
+
}
|
974
|
+
}, {
|
975
|
+
key: "reserve0",
|
976
|
+
get: function get() {
|
977
|
+
return this.tokenAmounts[0];
|
978
|
+
}
|
979
|
+
}, {
|
980
|
+
key: "reserve1",
|
981
|
+
get: function get() {
|
982
|
+
return this.tokenAmounts[1];
|
983
|
+
}
|
984
|
+
}]);
|
985
|
+
|
986
|
+
return Pair;
|
987
|
+
}();
|
988
|
+
|
989
|
+
var Route = /*#__PURE__*/function () {
|
990
|
+
function Route(pairs, input, output) {
|
991
|
+
!(pairs.length > 0) ? invariant(false, 'PAIRS') : void 0;
|
992
|
+
!pairs.every(function (pair) {
|
993
|
+
return pair.chainId === pairs[0].chainId;
|
994
|
+
}) ? invariant(false, 'CHAIN_IDS') : void 0;
|
995
|
+
!(input instanceof Token && pairs[0].involvesToken(input) || input === ETHER && pairs[0].involvesToken(WETH[pairs[0].chainId])) ? invariant(false, 'INPUT') : void 0;
|
996
|
+
!(typeof output === 'undefined' || output instanceof Token && pairs[pairs.length - 1].involvesToken(output) || output === ETHER && pairs[pairs.length - 1].involvesToken(WETH[pairs[0].chainId])) ? invariant(false, 'OUTPUT') : void 0;
|
997
|
+
var path = [input instanceof Token ? input : WETH[pairs[0].chainId]];
|
998
|
+
|
999
|
+
for (var _iterator = _createForOfIteratorHelperLoose(pairs.entries()), _step; !(_step = _iterator()).done;) {
|
1000
|
+
var _step$value = _step.value,
|
1001
|
+
i = _step$value[0],
|
1002
|
+
pair = _step$value[1];
|
1003
|
+
var currentInput = path[i];
|
1004
|
+
!(currentInput.equals(pair.token0) || currentInput.equals(pair.token1)) ? invariant(false, 'PATH') : void 0;
|
1005
|
+
|
1006
|
+
var _output = currentInput.equals(pair.token0) ? pair.token1 : pair.token0;
|
1007
|
+
|
1008
|
+
path.push(_output);
|
1009
|
+
}
|
1010
|
+
|
1011
|
+
this.pairs = pairs;
|
1012
|
+
this.path = path;
|
1013
|
+
this.midPrice = Price.fromRoute(this);
|
1014
|
+
this.input = input;
|
1015
|
+
this.output = output !== null && output !== void 0 ? output : path[path.length - 1];
|
1016
|
+
}
|
1017
|
+
|
1018
|
+
_createClass(Route, [{
|
1019
|
+
key: "chainId",
|
1020
|
+
get: function get() {
|
1021
|
+
return this.pairs[0].chainId;
|
1022
|
+
}
|
1023
|
+
}]);
|
1024
|
+
|
1025
|
+
return Route;
|
1026
|
+
}();
|
1027
|
+
|
1028
|
+
var _100_PERCENT = /*#__PURE__*/new Fraction(_100);
|
1029
|
+
|
1030
|
+
var Percent = /*#__PURE__*/function (_Fraction) {
|
1031
|
+
_inheritsLoose(Percent, _Fraction);
|
1032
|
+
|
1033
|
+
function Percent() {
|
1034
|
+
return _Fraction.apply(this, arguments) || this;
|
1035
|
+
}
|
1036
|
+
|
1037
|
+
var _proto = Percent.prototype;
|
1038
|
+
|
1039
|
+
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
|
1040
|
+
if (significantDigits === void 0) {
|
1041
|
+
significantDigits = 5;
|
1042
|
+
}
|
1043
|
+
|
1044
|
+
return this.multiply(_100_PERCENT).toSignificant(significantDigits, format, rounding);
|
1045
|
+
};
|
1046
|
+
|
1047
|
+
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) {
|
1048
|
+
if (decimalPlaces === void 0) {
|
1049
|
+
decimalPlaces = 2;
|
1050
|
+
}
|
1051
|
+
|
1052
|
+
return this.multiply(_100_PERCENT).toFixed(decimalPlaces, format, rounding);
|
1053
|
+
};
|
1054
|
+
|
1055
|
+
return Percent;
|
1056
|
+
}(Fraction);
|
1057
|
+
|
1058
|
+
/**
|
1059
|
+
* Returns the percent difference between the mid price and the execution price, i.e. price impact.
|
1060
|
+
* @param midPrice mid price before the trade
|
1061
|
+
* @param inputAmount the input amount of the trade
|
1062
|
+
* @param outputAmount the output amount of the trade
|
1063
|
+
*/
|
1064
|
+
|
1065
|
+
function computePriceImpact(midPrice, inputAmount, outputAmount) {
|
1066
|
+
var exactQuote = midPrice.raw.multiply(inputAmount.raw); // calculate slippage := (exactQuote - outputAmount) / exactQuote
|
1067
|
+
|
1068
|
+
var slippage = exactQuote.subtract(outputAmount.raw).divide(exactQuote);
|
1069
|
+
return new Percent(slippage.numerator, slippage.denominator);
|
1070
|
+
} // comparator function that allows sorting trades by their output amounts, in decreasing order, and then input amounts
|
1071
|
+
// in increasing order. i.e. the best trades have the most outputs for the least inputs and are sorted first
|
1072
|
+
|
1073
|
+
|
1074
|
+
function inputOutputComparator(a, b) {
|
1075
|
+
// must have same input and output token for comparison
|
1076
|
+
!currencyEquals(a.inputAmount.currency, b.inputAmount.currency) ? invariant(false, 'INPUT_CURRENCY') : void 0;
|
1077
|
+
!currencyEquals(a.outputAmount.currency, b.outputAmount.currency) ? invariant(false, 'OUTPUT_CURRENCY') : void 0;
|
1078
|
+
|
1079
|
+
if (a.outputAmount.equalTo(b.outputAmount)) {
|
1080
|
+
if (a.inputAmount.equalTo(b.inputAmount)) {
|
1081
|
+
return 0;
|
1082
|
+
} // trade A requires less input than trade B, so A should come first
|
1083
|
+
|
1084
|
+
|
1085
|
+
if (a.inputAmount.lessThan(b.inputAmount)) {
|
1086
|
+
return -1;
|
1087
|
+
} else {
|
1088
|
+
return 1;
|
1089
|
+
}
|
1090
|
+
} else {
|
1091
|
+
// tradeA has less output than trade B, so should come second
|
1092
|
+
if (a.outputAmount.lessThan(b.outputAmount)) {
|
1093
|
+
return 1;
|
1094
|
+
} else {
|
1095
|
+
return -1;
|
1096
|
+
}
|
1097
|
+
}
|
1098
|
+
} // extension of the input output comparator that also considers other dimensions of the trade in ranking them
|
1099
|
+
|
1100
|
+
function tradeComparator(a, b) {
|
1101
|
+
var ioComp = inputOutputComparator(a, b);
|
1102
|
+
|
1103
|
+
if (ioComp !== 0) {
|
1104
|
+
return ioComp;
|
1105
|
+
} // consider lowest slippage next, since these are less likely to fail
|
1106
|
+
|
1107
|
+
|
1108
|
+
if (a.priceImpact.lessThan(b.priceImpact)) {
|
1109
|
+
return -1;
|
1110
|
+
} else if (a.priceImpact.greaterThan(b.priceImpact)) {
|
1111
|
+
return 1;
|
1112
|
+
} // finally consider the number of hops since each hop costs gas
|
1113
|
+
|
1114
|
+
|
1115
|
+
return a.route.path.length - b.route.path.length;
|
1116
|
+
}
|
1117
|
+
/**
|
1118
|
+
* Given a currency amount and a chain ID, returns the equivalent representation as the token amount.
|
1119
|
+
* In other words, if the currency is ETHER, returns the WETH token amount for the given chain. Otherwise, returns
|
1120
|
+
* the input currency amount.
|
1121
|
+
*/
|
1122
|
+
|
1123
|
+
function wrappedAmount(currencyAmount, chainId) {
|
1124
|
+
if (currencyAmount instanceof TokenAmount) return currencyAmount;
|
1125
|
+
if (currencyAmount.currency === ETHER) return new TokenAmount(WETH[chainId], currencyAmount.raw);
|
1126
|
+
invariant(false, 'CURRENCY') ;
|
1127
|
+
}
|
1128
|
+
|
1129
|
+
function wrappedCurrency(currency, chainId) {
|
1130
|
+
if (currency instanceof Token) return currency;
|
1131
|
+
if (currency === ETHER) return WETH[chainId];
|
1132
|
+
invariant(false, 'CURRENCY') ;
|
1133
|
+
}
|
1134
|
+
/**
|
1135
|
+
* Represents a trade executed against a list of pairs.
|
1136
|
+
* Does not account for slippage, i.e. trades that front run this trade and move the price.
|
1137
|
+
*/
|
1138
|
+
|
1139
|
+
|
1140
|
+
var Trade = /*#__PURE__*/function () {
|
1141
|
+
function Trade(route, amount, tradeType) {
|
1142
|
+
var amounts = new Array(route.path.length);
|
1143
|
+
var nextPairs = new Array(route.pairs.length);
|
1144
|
+
|
1145
|
+
if (tradeType === exports.TradeType.EXACT_INPUT) {
|
1146
|
+
!currencyEquals(amount.currency, route.input) ? invariant(false, 'INPUT') : void 0;
|
1147
|
+
amounts[0] = wrappedAmount(amount, route.chainId);
|
1148
|
+
|
1149
|
+
for (var i = 0; i < route.path.length - 1; i++) {
|
1150
|
+
var pair = route.pairs[i];
|
1151
|
+
|
1152
|
+
var _pair$getOutputAmount = pair.getOutputAmount(amounts[i]),
|
1153
|
+
outputAmount = _pair$getOutputAmount[0],
|
1154
|
+
nextPair = _pair$getOutputAmount[1];
|
1155
|
+
|
1156
|
+
amounts[i + 1] = outputAmount;
|
1157
|
+
nextPairs[i] = nextPair;
|
1158
|
+
}
|
1159
|
+
} else {
|
1160
|
+
!currencyEquals(amount.currency, route.output) ? invariant(false, 'OUTPUT') : void 0;
|
1161
|
+
amounts[amounts.length - 1] = wrappedAmount(amount, route.chainId);
|
1162
|
+
|
1163
|
+
for (var _i = route.path.length - 1; _i > 0; _i--) {
|
1164
|
+
var _pair = route.pairs[_i - 1];
|
1165
|
+
|
1166
|
+
var _pair$getInputAmount = _pair.getInputAmount(amounts[_i]),
|
1167
|
+
inputAmount = _pair$getInputAmount[0],
|
1168
|
+
_nextPair = _pair$getInputAmount[1];
|
1169
|
+
|
1170
|
+
amounts[_i - 1] = inputAmount;
|
1171
|
+
nextPairs[_i - 1] = _nextPair;
|
1172
|
+
}
|
1173
|
+
}
|
1174
|
+
|
1175
|
+
this.route = route;
|
1176
|
+
this.tradeType = tradeType;
|
1177
|
+
this.inputAmount = tradeType === exports.TradeType.EXACT_INPUT ? amount : route.input === ETHER ? CurrencyAmount.ether(amounts[0].raw) : amounts[0];
|
1178
|
+
this.outputAmount = tradeType === exports.TradeType.EXACT_OUTPUT ? amount : route.output === ETHER ? CurrencyAmount.ether(amounts[amounts.length - 1].raw) : amounts[amounts.length - 1];
|
1179
|
+
this.executionPrice = new Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.raw, this.outputAmount.raw);
|
1180
|
+
this.nextMidPrice = Price.fromRoute(new Route(nextPairs, route.input));
|
1181
|
+
this.priceImpact = computePriceImpact(route.midPrice, this.inputAmount, this.outputAmount);
|
1182
|
+
}
|
1183
|
+
/**
|
1184
|
+
* Constructs an exact in trade with the given amount in and route
|
1185
|
+
* @param route route of the exact in trade
|
1186
|
+
* @param amountIn the amount being passed in
|
1187
|
+
*/
|
1188
|
+
|
1189
|
+
|
1190
|
+
Trade.exactIn = function exactIn(route, amountIn) {
|
1191
|
+
return new Trade(route, amountIn, exports.TradeType.EXACT_INPUT);
|
1192
|
+
}
|
1193
|
+
/**
|
1194
|
+
* Constructs an exact out trade with the given amount out and route
|
1195
|
+
* @param route route of the exact out trade
|
1196
|
+
* @param amountOut the amount returned by the trade
|
1197
|
+
*/
|
1198
|
+
;
|
1199
|
+
|
1200
|
+
Trade.exactOut = function exactOut(route, amountOut) {
|
1201
|
+
return new Trade(route, amountOut, exports.TradeType.EXACT_OUTPUT);
|
1202
|
+
}
|
1203
|
+
/**
|
1204
|
+
* Get the minimum amount that must be received from this trade for the given slippage tolerance
|
1205
|
+
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
|
1206
|
+
*/
|
1207
|
+
;
|
1208
|
+
|
1209
|
+
var _proto = Trade.prototype;
|
1210
|
+
|
1211
|
+
_proto.minimumAmountOut = function minimumAmountOut(slippageTolerance) {
|
1212
|
+
!!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0;
|
1213
|
+
|
1214
|
+
if (this.tradeType === exports.TradeType.EXACT_OUTPUT) {
|
1215
|
+
return this.outputAmount;
|
1216
|
+
} else {
|
1217
|
+
var slippageAdjustedAmountOut = new Fraction(ONE).add(slippageTolerance).invert().multiply(this.outputAmount.raw).quotient;
|
1218
|
+
return this.outputAmount instanceof TokenAmount ? new TokenAmount(this.outputAmount.token, slippageAdjustedAmountOut) : CurrencyAmount.ether(slippageAdjustedAmountOut);
|
1219
|
+
}
|
1220
|
+
}
|
1221
|
+
/**
|
1222
|
+
* Get the maximum amount in that can be spent via this trade for the given slippage tolerance
|
1223
|
+
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
|
1224
|
+
*/
|
1225
|
+
;
|
1226
|
+
|
1227
|
+
_proto.maximumAmountIn = function maximumAmountIn(slippageTolerance) {
|
1228
|
+
!!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0;
|
1229
|
+
|
1230
|
+
if (this.tradeType === exports.TradeType.EXACT_INPUT) {
|
1231
|
+
return this.inputAmount;
|
1232
|
+
} else {
|
1233
|
+
var slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.raw).quotient;
|
1234
|
+
return this.inputAmount instanceof TokenAmount ? new TokenAmount(this.inputAmount.token, slippageAdjustedAmountIn) : CurrencyAmount.ether(slippageAdjustedAmountIn);
|
1235
|
+
}
|
1236
|
+
}
|
1237
|
+
/**
|
1238
|
+
* Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
|
1239
|
+
* amount to an output token, making at most `maxHops` hops.
|
1240
|
+
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
|
1241
|
+
* the amount in among multiple routes.
|
1242
|
+
* @param pairs the pairs to consider in finding the best trade
|
1243
|
+
* @param currencyAmountIn exact amount of input currency to spend
|
1244
|
+
* @param currencyOut the desired currency out
|
1245
|
+
* @param maxNumResults maximum number of results to return
|
1246
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
|
1247
|
+
* @param currentPairs used in recursion; the current list of pairs
|
1248
|
+
* @param originalAmountIn used in recursion; the original value of the currencyAmountIn parameter
|
1249
|
+
* @param bestTrades used in recursion; the current list of best trades
|
1250
|
+
*/
|
1251
|
+
;
|
1252
|
+
|
1253
|
+
Trade.bestTradeExactIn = function bestTradeExactIn(pairs, currencyAmountIn, currencyOut, _temp, // used in recursion.
|
1254
|
+
currentPairs, originalAmountIn, bestTrades) {
|
1255
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
1256
|
+
_ref$maxNumResults = _ref.maxNumResults,
|
1257
|
+
maxNumResults = _ref$maxNumResults === void 0 ? 3 : _ref$maxNumResults,
|
1258
|
+
_ref$maxHops = _ref.maxHops,
|
1259
|
+
maxHops = _ref$maxHops === void 0 ? 3 : _ref$maxHops;
|
1260
|
+
|
1261
|
+
if (currentPairs === void 0) {
|
1262
|
+
currentPairs = [];
|
1263
|
+
}
|
1264
|
+
|
1265
|
+
if (originalAmountIn === void 0) {
|
1266
|
+
originalAmountIn = currencyAmountIn;
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
if (bestTrades === void 0) {
|
1270
|
+
bestTrades = [];
|
1271
|
+
}
|
1272
|
+
|
1273
|
+
!(pairs.length > 0) ? invariant(false, 'PAIRS') : void 0;
|
1274
|
+
!(maxHops > 0) ? invariant(false, 'MAX_HOPS') : void 0;
|
1275
|
+
!(originalAmountIn === currencyAmountIn || currentPairs.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0;
|
1276
|
+
var chainId = currencyAmountIn instanceof TokenAmount ? currencyAmountIn.token.chainId : currencyOut instanceof Token ? currencyOut.chainId : undefined;
|
1277
|
+
!(chainId !== undefined) ? invariant(false, 'CHAIN_ID') : void 0;
|
1278
|
+
var amountIn = wrappedAmount(currencyAmountIn, chainId);
|
1279
|
+
var tokenOut = wrappedCurrency(currencyOut, chainId);
|
1280
|
+
|
1281
|
+
for (var i = 0; i < pairs.length; i++) {
|
1282
|
+
var pair = pairs[i]; // pair irrelevant
|
1283
|
+
|
1284
|
+
if (!pair.token0.equals(amountIn.token) && !pair.token1.equals(amountIn.token)) continue;
|
1285
|
+
if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue;
|
1286
|
+
var amountOut = void 0;
|
1287
|
+
|
1288
|
+
try {
|
1289
|
+
;
|
1290
|
+
|
1291
|
+
var _pair$getOutputAmount2 = pair.getOutputAmount(amountIn);
|
1292
|
+
|
1293
|
+
amountOut = _pair$getOutputAmount2[0];
|
1294
|
+
} catch (error) {
|
1295
|
+
// input too low
|
1296
|
+
if (error.isInsufficientInputAmountError) {
|
1297
|
+
continue;
|
1298
|
+
}
|
1299
|
+
|
1300
|
+
throw error;
|
1301
|
+
} // we have arrived at the output token, so this is the final trade of one of the paths
|
1302
|
+
|
1303
|
+
|
1304
|
+
if (amountOut.token.equals(tokenOut)) {
|
1305
|
+
sortedInsert(bestTrades, new Trade(new Route([].concat(currentPairs, [pair]), originalAmountIn.currency, currencyOut), originalAmountIn, exports.TradeType.EXACT_INPUT), maxNumResults, tradeComparator);
|
1306
|
+
} else if (maxHops > 1 && pairs.length > 1) {
|
1307
|
+
var pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length)); // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops
|
1308
|
+
|
1309
|
+
Trade.bestTradeExactIn(pairsExcludingThisPair, amountOut, currencyOut, {
|
1310
|
+
maxNumResults: maxNumResults,
|
1311
|
+
maxHops: maxHops - 1
|
1312
|
+
}, [].concat(currentPairs, [pair]), originalAmountIn, bestTrades);
|
1313
|
+
}
|
1314
|
+
}
|
1315
|
+
|
1316
|
+
return bestTrades;
|
1317
|
+
}
|
1318
|
+
/**
|
1319
|
+
* similar to the above method but instead targets a fixed output amount
|
1320
|
+
* given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
|
1321
|
+
* to an output token amount, making at most `maxHops` hops
|
1322
|
+
* note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
|
1323
|
+
* the amount in among multiple routes.
|
1324
|
+
* @param pairs the pairs to consider in finding the best trade
|
1325
|
+
* @param currencyIn the currency to spend
|
1326
|
+
* @param currencyAmountOut the exact amount of currency out
|
1327
|
+
* @param maxNumResults maximum number of results to return
|
1328
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
|
1329
|
+
* @param currentPairs used in recursion; the current list of pairs
|
1330
|
+
* @param originalAmountOut used in recursion; the original value of the currencyAmountOut parameter
|
1331
|
+
* @param bestTrades used in recursion; the current list of best trades
|
1332
|
+
*/
|
1333
|
+
;
|
1334
|
+
|
1335
|
+
Trade.bestTradeExactOut = function bestTradeExactOut(pairs, currencyIn, currencyAmountOut, _temp2, // used in recursion.
|
1336
|
+
currentPairs, originalAmountOut, bestTrades) {
|
1337
|
+
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
1338
|
+
_ref2$maxNumResults = _ref2.maxNumResults,
|
1339
|
+
maxNumResults = _ref2$maxNumResults === void 0 ? 3 : _ref2$maxNumResults,
|
1340
|
+
_ref2$maxHops = _ref2.maxHops,
|
1341
|
+
maxHops = _ref2$maxHops === void 0 ? 3 : _ref2$maxHops;
|
1342
|
+
|
1343
|
+
if (currentPairs === void 0) {
|
1344
|
+
currentPairs = [];
|
1345
|
+
}
|
1346
|
+
|
1347
|
+
if (originalAmountOut === void 0) {
|
1348
|
+
originalAmountOut = currencyAmountOut;
|
1349
|
+
}
|
1350
|
+
|
1351
|
+
if (bestTrades === void 0) {
|
1352
|
+
bestTrades = [];
|
1353
|
+
}
|
1354
|
+
|
1355
|
+
!(pairs.length > 0) ? invariant(false, 'PAIRS') : void 0;
|
1356
|
+
!(maxHops > 0) ? invariant(false, 'MAX_HOPS') : void 0;
|
1357
|
+
!(originalAmountOut === currencyAmountOut || currentPairs.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0;
|
1358
|
+
var chainId = currencyAmountOut instanceof TokenAmount ? currencyAmountOut.token.chainId : currencyIn instanceof Token ? currencyIn.chainId : undefined;
|
1359
|
+
!(chainId !== undefined) ? invariant(false, 'CHAIN_ID') : void 0;
|
1360
|
+
var amountOut = wrappedAmount(currencyAmountOut, chainId);
|
1361
|
+
var tokenIn = wrappedCurrency(currencyIn, chainId);
|
1362
|
+
|
1363
|
+
for (var i = 0; i < pairs.length; i++) {
|
1364
|
+
var pair = pairs[i]; // pair irrelevant
|
1365
|
+
|
1366
|
+
if (!pair.token0.equals(amountOut.token) && !pair.token1.equals(amountOut.token)) continue;
|
1367
|
+
if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue;
|
1368
|
+
var amountIn = void 0;
|
1369
|
+
|
1370
|
+
try {
|
1371
|
+
;
|
1372
|
+
|
1373
|
+
var _pair$getInputAmount2 = pair.getInputAmount(amountOut);
|
1374
|
+
|
1375
|
+
amountIn = _pair$getInputAmount2[0];
|
1376
|
+
} catch (error) {
|
1377
|
+
// not enough liquidity in this pair
|
1378
|
+
if (error.isInsufficientReservesError) {
|
1379
|
+
continue;
|
1380
|
+
}
|
1381
|
+
|
1382
|
+
throw error;
|
1383
|
+
} // we have arrived at the input token, so this is the first trade of one of the paths
|
1384
|
+
|
1385
|
+
|
1386
|
+
if (amountIn.token.equals(tokenIn)) {
|
1387
|
+
sortedInsert(bestTrades, new Trade(new Route([pair].concat(currentPairs), currencyIn, originalAmountOut.currency), originalAmountOut, exports.TradeType.EXACT_OUTPUT), maxNumResults, tradeComparator);
|
1388
|
+
} else if (maxHops > 1 && pairs.length > 1) {
|
1389
|
+
var pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length)); // otherwise, consider all the other paths that arrive at this token as long as we have not exceeded maxHops
|
1390
|
+
|
1391
|
+
Trade.bestTradeExactOut(pairsExcludingThisPair, currencyIn, amountIn, {
|
1392
|
+
maxNumResults: maxNumResults,
|
1393
|
+
maxHops: maxHops - 1
|
1394
|
+
}, [pair].concat(currentPairs), originalAmountOut, bestTrades);
|
1395
|
+
}
|
1396
|
+
}
|
1397
|
+
|
1398
|
+
return bestTrades;
|
1399
|
+
};
|
1400
|
+
|
1401
|
+
return Trade;
|
1402
|
+
}();
|
1403
|
+
|
1404
|
+
function toHex(currencyAmount) {
|
1405
|
+
return "0x" + currencyAmount.raw.toString(16);
|
1406
|
+
}
|
1407
|
+
|
1408
|
+
var ZERO_HEX = '0x0';
|
1409
|
+
/**
|
1410
|
+
* Represents the Uniswap V2 Router, and has static methods for helping execute trades.
|
1411
|
+
*/
|
1412
|
+
|
1413
|
+
var Router = /*#__PURE__*/function () {
|
1414
|
+
/**
|
1415
|
+
* Cannot be constructed.
|
1416
|
+
*/
|
1417
|
+
function Router() {}
|
1418
|
+
/**
|
1419
|
+
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
1420
|
+
* @param trade to produce call parameters for
|
1421
|
+
* @param options options for the call parameters
|
1422
|
+
*/
|
1423
|
+
|
1424
|
+
|
1425
|
+
Router.swapCallParameters = function swapCallParameters(trade, options) {
|
1426
|
+
var etherIn = trade.inputAmount.currency === ETHER;
|
1427
|
+
var etherOut = trade.outputAmount.currency === ETHER; // the router does not support both ether in and out
|
1428
|
+
|
1429
|
+
!!(etherIn && etherOut) ? invariant(false, 'ETHER_IN_OUT') : void 0;
|
1430
|
+
!(!('ttl' in options) || options.ttl > 0) ? invariant(false, 'TTL') : void 0;
|
1431
|
+
var to = validateAndParseAddress(options.recipient);
|
1432
|
+
var amountIn = toHex(trade.maximumAmountIn(options.allowedSlippage));
|
1433
|
+
var amountOut = toHex(trade.minimumAmountOut(options.allowedSlippage));
|
1434
|
+
var path = trade.route.path.map(function (token) {
|
1435
|
+
return token.address;
|
1436
|
+
});
|
1437
|
+
var deadline = 'ttl' in options ? "0x" + (Math.floor(new Date().getTime() / 1000) + options.ttl).toString(16) : "0x" + options.deadline.toString(16);
|
1438
|
+
var useFeeOnTransfer = Boolean(options.feeOnTransfer);
|
1439
|
+
var methodName;
|
1440
|
+
var args;
|
1441
|
+
var value;
|
1442
|
+
|
1443
|
+
switch (trade.tradeType) {
|
1444
|
+
case exports.TradeType.EXACT_INPUT:
|
1445
|
+
if (etherIn) {
|
1446
|
+
methodName = useFeeOnTransfer ? 'swapExactETHForTokensSupportingFeeOnTransferTokens' : 'swapExactETHForTokens'; // (uint amountOutMin, address[] calldata path, address to, uint deadline)
|
1447
|
+
|
1448
|
+
args = [amountOut, path, to, deadline];
|
1449
|
+
value = amountIn;
|
1450
|
+
} else if (etherOut) {
|
1451
|
+
methodName = useFeeOnTransfer ? 'swapExactTokensForETHSupportingFeeOnTransferTokens' : 'swapExactTokensForETH'; // (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
|
1452
|
+
|
1453
|
+
args = [amountIn, amountOut, path, to, deadline];
|
1454
|
+
value = ZERO_HEX;
|
1455
|
+
} else {
|
1456
|
+
methodName = useFeeOnTransfer ? 'swapExactTokensForTokensSupportingFeeOnTransferTokens' : 'swapExactTokensForTokens'; // (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
|
1457
|
+
|
1458
|
+
args = [amountIn, amountOut, path, to, deadline];
|
1459
|
+
value = ZERO_HEX;
|
1460
|
+
}
|
1461
|
+
|
1462
|
+
break;
|
1463
|
+
|
1464
|
+
case exports.TradeType.EXACT_OUTPUT:
|
1465
|
+
!!useFeeOnTransfer ? invariant(false, 'EXACT_OUT_FOT') : void 0;
|
1466
|
+
|
1467
|
+
if (etherIn) {
|
1468
|
+
methodName = 'swapETHForExactTokens'; // (uint amountOut, address[] calldata path, address to, uint deadline)
|
1469
|
+
|
1470
|
+
args = [amountOut, path, to, deadline];
|
1471
|
+
value = amountIn;
|
1472
|
+
} else if (etherOut) {
|
1473
|
+
methodName = 'swapTokensForExactETH'; // (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
|
1474
|
+
|
1475
|
+
args = [amountOut, amountIn, path, to, deadline];
|
1476
|
+
value = ZERO_HEX;
|
1477
|
+
} else {
|
1478
|
+
methodName = 'swapTokensForExactTokens'; // (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
|
1479
|
+
|
1480
|
+
args = [amountOut, amountIn, path, to, deadline];
|
1481
|
+
value = ZERO_HEX;
|
1482
|
+
}
|
1483
|
+
|
1484
|
+
break;
|
1485
|
+
}
|
1486
|
+
|
1487
|
+
return {
|
1488
|
+
methodName: methodName,
|
1489
|
+
args: args,
|
1490
|
+
value: value
|
1491
|
+
};
|
1492
|
+
};
|
1493
|
+
|
1494
|
+
return Router;
|
1495
|
+
}();
|
1496
|
+
|
1497
|
+
var ERC20 = [
|
1498
|
+
{
|
1499
|
+
constant: true,
|
1500
|
+
inputs: [
|
1501
|
+
],
|
1502
|
+
name: "decimals",
|
1503
|
+
outputs: [
|
1504
|
+
{
|
1505
|
+
name: "",
|
1506
|
+
type: "uint8"
|
1507
|
+
}
|
1508
|
+
],
|
1509
|
+
payable: false,
|
1510
|
+
stateMutability: "view",
|
1511
|
+
type: "function"
|
1512
|
+
},
|
1513
|
+
{
|
1514
|
+
constant: true,
|
1515
|
+
inputs: [
|
1516
|
+
{
|
1517
|
+
name: "",
|
1518
|
+
type: "address"
|
1519
|
+
}
|
1520
|
+
],
|
1521
|
+
name: "balanceOf",
|
1522
|
+
outputs: [
|
1523
|
+
{
|
1524
|
+
name: "",
|
1525
|
+
type: "uint256"
|
1526
|
+
}
|
1527
|
+
],
|
1528
|
+
payable: false,
|
1529
|
+
stateMutability: "view",
|
1530
|
+
type: "function"
|
1531
|
+
}
|
1532
|
+
];
|
1533
|
+
|
1534
|
+
var _TOKEN_DECIMALS_CACHE;
|
1535
|
+
var TOKEN_DECIMALS_CACHE = (_TOKEN_DECIMALS_CACHE = {}, _TOKEN_DECIMALS_CACHE[exports.ChainId.MAINNET] = {
|
1536
|
+
'0xE0B7927c4aF23765Cb51314A0E0521A9645F0E2A': 9 // DGD
|
1537
|
+
|
1538
|
+
}, _TOKEN_DECIMALS_CACHE);
|
1539
|
+
/**
|
1540
|
+
* Contains methods for constructing instances of pairs and tokens from on-chain data.
|
1541
|
+
*/
|
1542
|
+
|
1543
|
+
var Fetcher = /*#__PURE__*/function () {
|
1544
|
+
/**
|
1545
|
+
* Cannot be constructed.
|
1546
|
+
*/
|
1547
|
+
function Fetcher() {}
|
1548
|
+
/**
|
1549
|
+
* Fetch information for a given token on the given chain, using the given ethers provider.
|
1550
|
+
* @param chainId chain of the token
|
1551
|
+
* @param address address of the token on the chain
|
1552
|
+
* @param provider provider used to fetch the token
|
1553
|
+
* @param symbol optional symbol of the token
|
1554
|
+
* @param name optional name of the token
|
1555
|
+
*/
|
1556
|
+
|
1557
|
+
|
1558
|
+
Fetcher.fetchTokenData = function fetchTokenData(chainId, address, provider, symbol, name) {
|
1559
|
+
try {
|
1560
|
+
var _TOKEN_DECIMALS_CACHE2, _TOKEN_DECIMALS_CACHE3;
|
1561
|
+
|
1562
|
+
var _temp3 = function _temp3(parsedDecimals) {
|
1563
|
+
return new Token(chainId, address, parsedDecimals, symbol, name);
|
1564
|
+
};
|
1565
|
+
|
1566
|
+
if (provider === undefined) provider = providers.getDefaultProvider(networks.getNetwork(chainId));
|
1567
|
+
|
1568
|
+
var _temp4 = typeof ((_TOKEN_DECIMALS_CACHE2 = TOKEN_DECIMALS_CACHE) === null || _TOKEN_DECIMALS_CACHE2 === void 0 ? void 0 : (_TOKEN_DECIMALS_CACHE3 = _TOKEN_DECIMALS_CACHE2[chainId]) === null || _TOKEN_DECIMALS_CACHE3 === void 0 ? void 0 : _TOKEN_DECIMALS_CACHE3[address]) === 'number';
|
1569
|
+
|
1570
|
+
return Promise.resolve(_temp4 ? _temp3(TOKEN_DECIMALS_CACHE[chainId][address]) : Promise.resolve(new contracts.Contract(address, ERC20, provider).decimals().then(function (decimals) {
|
1571
|
+
var _TOKEN_DECIMALS_CACHE4, _extends2, _extends3;
|
1572
|
+
|
1573
|
+
TOKEN_DECIMALS_CACHE = _extends({}, TOKEN_DECIMALS_CACHE, (_extends3 = {}, _extends3[chainId] = _extends({}, (_TOKEN_DECIMALS_CACHE4 = TOKEN_DECIMALS_CACHE) === null || _TOKEN_DECIMALS_CACHE4 === void 0 ? void 0 : _TOKEN_DECIMALS_CACHE4[chainId], (_extends2 = {}, _extends2[address] = decimals, _extends2)), _extends3));
|
1574
|
+
return decimals;
|
1575
|
+
})).then(_temp3));
|
1576
|
+
} catch (e) {
|
1577
|
+
return Promise.reject(e);
|
1578
|
+
}
|
1579
|
+
}
|
1580
|
+
/**
|
1581
|
+
* Fetches information about a pair and constructs a pair from the given two tokens.
|
1582
|
+
* @param tokenA first token
|
1583
|
+
* @param tokenB second token
|
1584
|
+
* @param provider the provider to use to fetch the data
|
1585
|
+
*/
|
1586
|
+
;
|
1587
|
+
|
1588
|
+
Fetcher.fetchPairData = function fetchPairData(tokenA, tokenB, provider) {
|
1589
|
+
try {
|
1590
|
+
if (provider === undefined) provider = providers.getDefaultProvider(networks.getNetwork(tokenA.chainId));
|
1591
|
+
!(tokenA.chainId === tokenB.chainId) ? "development" !== "production" ? invariant(false, 'CHAIN_ID') : invariant(false) : void 0;
|
1592
|
+
var address = Pair.getAddress(tokenA, tokenB);
|
1593
|
+
return Promise.resolve(new contracts.Contract(address, IUniswapV2Pair.abi, provider).getReserves()).then(function (_ref) {
|
1594
|
+
var reserves0 = _ref[0],
|
1595
|
+
reserves1 = _ref[1];
|
1596
|
+
var balances = tokenA.sortsBefore(tokenB) ? [reserves0, reserves1] : [reserves1, reserves0];
|
1597
|
+
return new Pair(new TokenAmount(tokenA, balances[0]), new TokenAmount(tokenB, balances[1]));
|
1598
|
+
});
|
1599
|
+
} catch (e) {
|
1600
|
+
return Promise.reject(e);
|
1601
|
+
}
|
1602
|
+
};
|
1603
|
+
|
1604
|
+
return Fetcher;
|
1605
|
+
}();
|
1606
|
+
|
1607
|
+
exports.JSBI = JSBI;
|
1608
|
+
exports.Currency = Currency;
|
1609
|
+
exports.CurrencyAmount = CurrencyAmount;
|
1610
|
+
exports.ETHER = ETHER;
|
1611
|
+
exports.FACTORY_ADDRESS = FACTORY_ADDRESS;
|
1612
|
+
exports.Fetcher = Fetcher;
|
1613
|
+
exports.Fraction = Fraction;
|
1614
|
+
exports.INIT_CODE_HASH = INIT_CODE_HASH;
|
1615
|
+
exports.InsufficientInputAmountError = InsufficientInputAmountError;
|
1616
|
+
exports.InsufficientReservesError = InsufficientReservesError;
|
1617
|
+
exports.MINIMUM_LIQUIDITY = MINIMUM_LIQUIDITY;
|
1618
|
+
exports.Pair = Pair;
|
1619
|
+
exports.Percent = Percent;
|
1620
|
+
exports.Price = Price;
|
1621
|
+
exports.Route = Route;
|
1622
|
+
exports.Router = Router;
|
1623
|
+
exports.Token = Token;
|
1624
|
+
exports.TokenAmount = TokenAmount;
|
1625
|
+
exports.Trade = Trade;
|
1626
|
+
exports.WETH = WETH;
|
1627
|
+
exports.currencyEquals = currencyEquals;
|
1628
|
+
exports.inputOutputComparator = inputOutputComparator;
|
1629
|
+
exports.tradeComparator = tradeComparator;
|
1630
|
+
//# sourceMappingURL=u-exchange-sdk.cjs.development.js.map
|