@uniswap/sdk-core 3.2.6 → 4.0.1
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/dist/sdk-core.cjs.development.js +200 -66
- package/dist/sdk-core.cjs.development.js.map +1 -1
- package/dist/sdk-core.cjs.production.min.js +1 -1
- package/dist/sdk-core.cjs.production.min.js.map +1 -1
- package/dist/sdk-core.esm.js +203 -66
- package/dist/sdk-core.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/sdk-core.esm.js
CHANGED
|
@@ -11,59 +11,42 @@ function _defineProperties(target, props) {
|
|
|
11
11
|
descriptor.enumerable = descriptor.enumerable || false;
|
|
12
12
|
descriptor.configurable = true;
|
|
13
13
|
if ("value" in descriptor) descriptor.writable = true;
|
|
14
|
-
Object.defineProperty(target,
|
|
14
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
+
|
|
17
18
|
function _createClass(Constructor, protoProps, staticProps) {
|
|
18
19
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
19
20
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
20
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
21
|
-
writable: false
|
|
22
|
-
});
|
|
23
21
|
return Constructor;
|
|
24
22
|
}
|
|
23
|
+
|
|
25
24
|
function _extends() {
|
|
26
|
-
_extends = Object.assign
|
|
25
|
+
_extends = Object.assign || function (target) {
|
|
27
26
|
for (var i = 1; i < arguments.length; i++) {
|
|
28
27
|
var source = arguments[i];
|
|
28
|
+
|
|
29
29
|
for (var key in source) {
|
|
30
30
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
31
31
|
target[key] = source[key];
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
|
|
35
36
|
return target;
|
|
36
37
|
};
|
|
38
|
+
|
|
37
39
|
return _extends.apply(this, arguments);
|
|
38
40
|
}
|
|
41
|
+
|
|
39
42
|
function _inheritsLoose(subClass, superClass) {
|
|
40
43
|
subClass.prototype = Object.create(superClass.prototype);
|
|
41
44
|
subClass.prototype.constructor = subClass;
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
function _setPrototypeOf(o, p) {
|
|
45
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
46
|
-
o.__proto__ = p;
|
|
47
|
-
return o;
|
|
48
|
-
};
|
|
49
|
-
return _setPrototypeOf(o, p);
|
|
50
|
-
}
|
|
51
|
-
function _toPrimitive(input, hint) {
|
|
52
|
-
if (typeof input !== "object" || input === null) return input;
|
|
53
|
-
var prim = input[Symbol.toPrimitive];
|
|
54
|
-
if (prim !== undefined) {
|
|
55
|
-
var res = prim.call(input, hint || "default");
|
|
56
|
-
if (typeof res !== "object") return res;
|
|
57
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
58
|
-
}
|
|
59
|
-
return (hint === "string" ? String : Number)(input);
|
|
60
|
-
}
|
|
61
|
-
function _toPropertyKey(arg) {
|
|
62
|
-
var key = _toPrimitive(arg, "string");
|
|
63
|
-
return typeof key === "symbol" ? key : String(key);
|
|
45
|
+
subClass.__proto__ = superClass;
|
|
64
46
|
}
|
|
65
47
|
|
|
66
48
|
var ChainId;
|
|
49
|
+
|
|
67
50
|
(function (ChainId) {
|
|
68
51
|
ChainId[ChainId["MAINNET"] = 1] = "MAINNET";
|
|
69
52
|
ChainId[ChainId["GOERLI"] = 5] = "GOERLI";
|
|
@@ -81,8 +64,10 @@ var ChainId;
|
|
|
81
64
|
ChainId[ChainId["BNB"] = 56] = "BNB";
|
|
82
65
|
ChainId[ChainId["AVALANCHE"] = 43114] = "AVALANCHE";
|
|
83
66
|
})(ChainId || (ChainId = {}));
|
|
67
|
+
|
|
84
68
|
var SUPPORTED_CHAINS = [ChainId.MAINNET, ChainId.OPTIMISM, ChainId.OPTIMISM_GOERLI, ChainId.ARBITRUM_ONE, ChainId.ARBITRUM_GOERLI, ChainId.POLYGON, ChainId.POLYGON_MUMBAI, ChainId.GOERLI, ChainId.SEPOLIA, ChainId.CELO_ALFAJORES, ChainId.CELO, ChainId.BNB, ChainId.AVALANCHE];
|
|
85
69
|
var NativeCurrencyName;
|
|
70
|
+
|
|
86
71
|
(function (NativeCurrencyName) {
|
|
87
72
|
// Strings match input for CLI
|
|
88
73
|
NativeCurrencyName["ETHER"] = "ETH";
|
|
@@ -96,22 +81,25 @@ var NativeCurrencyName;
|
|
|
96
81
|
|
|
97
82
|
var _CHAIN_TO_ADDRESSES_M, _GOVERNANCE_ALPHA_V1_, _GOVERNANCE_BRAVO_ADD, _MERKLE_DISTRIBUTOR_A, _ARGENT_WALLET_DETECT, _SOCKS_CONTROLLER_ADD;
|
|
98
83
|
var DEFAULT_NETWORKS = [ChainId.MAINNET, ChainId.GOERLI];
|
|
84
|
+
|
|
99
85
|
function constructSameAddressMap(address, additionalNetworks) {
|
|
100
86
|
if (additionalNetworks === void 0) {
|
|
101
87
|
additionalNetworks = [];
|
|
102
88
|
}
|
|
89
|
+
|
|
103
90
|
return DEFAULT_NETWORKS.concat(additionalNetworks).reduce(function (memo, chainId) {
|
|
104
91
|
memo[chainId] = address;
|
|
105
92
|
return memo;
|
|
106
93
|
}, {});
|
|
107
94
|
}
|
|
95
|
+
|
|
108
96
|
var UNI_ADDRESSES = /*#__PURE__*/constructSameAddressMap('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984', [ChainId.OPTIMISM, ChainId.ARBITRUM_ONE, ChainId.POLYGON, ChainId.POLYGON_MUMBAI, ChainId.SEPOLIA]);
|
|
109
97
|
var UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS = '0x8B799381ac40b838BBA4131ffB26197C432AFe78';
|
|
110
98
|
var V2_FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';
|
|
111
99
|
var V2_FACTORY_ADDRESSES = /*#__PURE__*/constructSameAddressMap(V2_FACTORY_ADDRESS);
|
|
112
100
|
var V2_ROUTER_ADDRESS = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D';
|
|
113
|
-
var V2_ROUTER_ADDRESSES = /*#__PURE__*/constructSameAddressMap(V2_ROUTER_ADDRESS);
|
|
114
|
-
|
|
101
|
+
var V2_ROUTER_ADDRESSES = /*#__PURE__*/constructSameAddressMap(V2_ROUTER_ADDRESS); // Networks that share most of the same addresses i.e. Mainnet, Goerli, Optimism, Arbitrum, Polygon
|
|
102
|
+
|
|
115
103
|
var DEFAULT_ADDRESSES = {
|
|
116
104
|
v3CoreFactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
|
|
117
105
|
multicallAddress: '0x1F98415757620B543A52E61c46B32eB19261F984',
|
|
@@ -119,19 +107,24 @@ var DEFAULT_ADDRESSES = {
|
|
|
119
107
|
v3MigratorAddress: '0xA5644E29708357803b5A882D272c41cC0dF92B34',
|
|
120
108
|
nonfungiblePositionManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
|
|
121
109
|
};
|
|
110
|
+
|
|
122
111
|
var MAINNET_ADDRESSES = /*#__PURE__*/_extends({}, DEFAULT_ADDRESSES, {
|
|
123
112
|
v1MixedRouteQuoterAddress: '0x84E44095eeBfEC7793Cd7d5b57B7e401D7f1cA2E'
|
|
124
113
|
});
|
|
114
|
+
|
|
125
115
|
var GOERLI_ADDRESSES = /*#__PURE__*/_extends({}, DEFAULT_ADDRESSES, {
|
|
126
116
|
v1MixedRouteQuoterAddress: '0xBa60b6e6fF25488308789E6e0A65D838be34194e'
|
|
127
117
|
});
|
|
118
|
+
|
|
128
119
|
var OPTIMISM_ADDRESSES = DEFAULT_ADDRESSES;
|
|
120
|
+
|
|
129
121
|
var ARBITRUM_ONE_ADDRESSES = /*#__PURE__*/_extends({}, DEFAULT_ADDRESSES, {
|
|
130
122
|
multicallAddress: '0xadF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB',
|
|
131
123
|
tickLensAddress: '0xbfd8137f7d1516D3ea5cA83523914859ec47F573'
|
|
132
124
|
});
|
|
133
|
-
|
|
134
|
-
// celo v3 addresses
|
|
125
|
+
|
|
126
|
+
var POLYGON_ADDRESSES = DEFAULT_ADDRESSES; // celo v3 addresses
|
|
127
|
+
|
|
135
128
|
var CELO_ADDRESSES = {
|
|
136
129
|
v3CoreFactoryAddress: '0xAfE208a311B21f13EF87E33A90049fC17A7acDEc',
|
|
137
130
|
multicallAddress: '0x633987602DE5C4F337e3DbF265303A1080324204',
|
|
@@ -139,8 +132,8 @@ var CELO_ADDRESSES = {
|
|
|
139
132
|
v3MigratorAddress: '0x3cFd4d48EDfDCC53D3f173F596f621064614C582',
|
|
140
133
|
nonfungiblePositionManagerAddress: '0x3d79EdAaBC0EaB6F08ED885C05Fc0B014290D95A',
|
|
141
134
|
tickLensAddress: '0x5f115D9113F88e0a0Db1b5033D90D4a9690AcD3D'
|
|
142
|
-
};
|
|
143
|
-
|
|
135
|
+
}; // BNB v3 addresses
|
|
136
|
+
|
|
144
137
|
var BNB_ADDRESSES = {
|
|
145
138
|
v3CoreFactoryAddress: '0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7',
|
|
146
139
|
multicallAddress: '0x963Df249eD09c358A4819E39d9Cd5736c3087184',
|
|
@@ -149,8 +142,8 @@ var BNB_ADDRESSES = {
|
|
|
149
142
|
nonfungiblePositionManagerAddress: '0x7b8A01B39D58278b5DE7e48c8449c9f4F5170613',
|
|
150
143
|
tickLensAddress: '0xD9270014D396281579760619CCf4c3af0501A47C',
|
|
151
144
|
swapRouter02Address: '0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2'
|
|
152
|
-
};
|
|
153
|
-
|
|
145
|
+
}; // optimism goerli addresses
|
|
146
|
+
|
|
154
147
|
var OPTIMISM_GOERLI_ADDRESSES = {
|
|
155
148
|
v3CoreFactoryAddress: '0xB656dA17129e7EB733A557f4EBc57B76CFbB5d10',
|
|
156
149
|
multicallAddress: '0x07F2D8a2a02251B62af965f22fC4744A5f96BCCd',
|
|
@@ -158,8 +151,8 @@ var OPTIMISM_GOERLI_ADDRESSES = {
|
|
|
158
151
|
v3MigratorAddress: '0xf6c55fBe84B1C8c3283533c53F51bC32F5C7Aba8',
|
|
159
152
|
nonfungiblePositionManagerAddress: '0x39Ca85Af2F383190cBf7d7c41ED9202D27426EF6',
|
|
160
153
|
tickLensAddress: '0xe6140Bd164b63E8BfCfc40D5dF952f83e171758e'
|
|
161
|
-
};
|
|
162
|
-
|
|
154
|
+
}; // arbitrum goerli v3 addresses
|
|
155
|
+
|
|
163
156
|
var ARBITRUM_GOERLI_ADDRESSES = {
|
|
164
157
|
v3CoreFactoryAddress: '0x4893376342d5D7b3e31d4184c08b265e5aB2A3f6',
|
|
165
158
|
multicallAddress: '0x8260CB40247290317a4c062F3542622367F206Ee',
|
|
@@ -167,8 +160,8 @@ var ARBITRUM_GOERLI_ADDRESSES = {
|
|
|
167
160
|
v3MigratorAddress: '0xA815919D2584Ac3F76ea9CB62E6Fd40a43BCe0C3',
|
|
168
161
|
nonfungiblePositionManagerAddress: '0x622e4726a167799826d1E1D150b076A7725f5D81',
|
|
169
162
|
tickLensAddress: '0xb52429333da969a0C79a60930a4Bf0020E5D1DE8'
|
|
170
|
-
};
|
|
171
|
-
|
|
163
|
+
}; // sepolia v3 addresses
|
|
164
|
+
|
|
172
165
|
var SEPOLIA_ADDRESSES = {
|
|
173
166
|
v3CoreFactoryAddress: '0x0227628f3F023bb0B980b67D528571c95c6DaC1c',
|
|
174
167
|
multicallAddress: '0xD7F33bCdb21b359c8ee6F0251d30E94832baAd07',
|
|
@@ -176,8 +169,8 @@ var SEPOLIA_ADDRESSES = {
|
|
|
176
169
|
v3MigratorAddress: '0x729004182cF005CEC8Bd85df140094b6aCbe8b15',
|
|
177
170
|
nonfungiblePositionManagerAddress: '0x1238536071E1c677A632429e3655c799b22cDA52',
|
|
178
171
|
tickLensAddress: '0xd7f33bcdb21b359c8ee6f0251d30e94832baad07'
|
|
179
|
-
};
|
|
180
|
-
|
|
172
|
+
}; // Avalanche v3 addresses
|
|
173
|
+
|
|
181
174
|
var AVALANCHE_ADDRESSES = {
|
|
182
175
|
v3CoreFactoryAddress: '0x740b1c1de25031C31FF4fC9A62f554A55cdC1baD',
|
|
183
176
|
multicallAddress: '0x0139141Cd4Ee88dF3Cdb65881D411bAE271Ef0C2',
|
|
@@ -189,15 +182,18 @@ var AVALANCHE_ADDRESSES = {
|
|
|
189
182
|
};
|
|
190
183
|
var CHAIN_TO_ADDRESSES_MAP = (_CHAIN_TO_ADDRESSES_M = {}, _CHAIN_TO_ADDRESSES_M[ChainId.MAINNET] = MAINNET_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.OPTIMISM] = OPTIMISM_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.ARBITRUM_ONE] = ARBITRUM_ONE_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.POLYGON] = POLYGON_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.POLYGON_MUMBAI] = POLYGON_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.GOERLI] = GOERLI_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.CELO] = CELO_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.CELO_ALFAJORES] = CELO_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.BNB] = BNB_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.OPTIMISM_GOERLI] = OPTIMISM_GOERLI_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.ARBITRUM_GOERLI] = ARBITRUM_GOERLI_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.SEPOLIA] = SEPOLIA_ADDRESSES, _CHAIN_TO_ADDRESSES_M[ChainId.AVALANCHE] = AVALANCHE_ADDRESSES, _CHAIN_TO_ADDRESSES_M);
|
|
191
184
|
/* V3 Contract Addresses */
|
|
185
|
+
|
|
192
186
|
var V3_CORE_FACTORY_ADDRESSES = /*#__PURE__*/_extends({}, /*#__PURE__*/SUPPORTED_CHAINS.reduce(function (memo, chainId) {
|
|
193
187
|
memo[chainId] = CHAIN_TO_ADDRESSES_MAP[chainId].v3CoreFactoryAddress;
|
|
194
188
|
return memo;
|
|
195
189
|
}, {}));
|
|
196
190
|
var V3_MIGRATOR_ADDRESSES = /*#__PURE__*/_extends({}, /*#__PURE__*/SUPPORTED_CHAINS.reduce(function (memo, chainId) {
|
|
197
191
|
var v3MigratorAddress = CHAIN_TO_ADDRESSES_MAP[chainId].v3MigratorAddress;
|
|
192
|
+
|
|
198
193
|
if (v3MigratorAddress) {
|
|
199
194
|
memo[chainId] = v3MigratorAddress;
|
|
200
195
|
}
|
|
196
|
+
|
|
201
197
|
return memo;
|
|
202
198
|
}, {}));
|
|
203
199
|
var MULTICALL_ADDRESSES = /*#__PURE__*/_extends({}, /*#__PURE__*/SUPPORTED_CHAINS.reduce(function (memo, chainId) {
|
|
@@ -207,14 +203,17 @@ var MULTICALL_ADDRESSES = /*#__PURE__*/_extends({}, /*#__PURE__*/SUPPORTED_CHAIN
|
|
|
207
203
|
/**
|
|
208
204
|
* The oldest V0 governance address
|
|
209
205
|
*/
|
|
206
|
+
|
|
210
207
|
var GOVERNANCE_ALPHA_V0_ADDRESSES = /*#__PURE__*/constructSameAddressMap('0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F');
|
|
211
208
|
/**
|
|
212
209
|
* The older V1 governance address
|
|
213
210
|
*/
|
|
211
|
+
|
|
214
212
|
var GOVERNANCE_ALPHA_V1_ADDRESSES = (_GOVERNANCE_ALPHA_V1_ = {}, _GOVERNANCE_ALPHA_V1_[ChainId.MAINNET] = '0xC4e172459f1E7939D522503B81AFAaC1014CE6F6', _GOVERNANCE_ALPHA_V1_);
|
|
215
213
|
/**
|
|
216
214
|
* The latest governor bravo that is currently admin of timelock
|
|
217
215
|
*/
|
|
216
|
+
|
|
218
217
|
var GOVERNANCE_BRAVO_ADDRESSES = (_GOVERNANCE_BRAVO_ADD = {}, _GOVERNANCE_BRAVO_ADD[ChainId.MAINNET] = '0x408ED6354d4973f66138C91495F2f2FCbd8724C3', _GOVERNANCE_BRAVO_ADD);
|
|
219
218
|
var TIMELOCK_ADDRESSES = /*#__PURE__*/constructSameAddressMap('0x1a9C8182C09F50C8318d769245beA52c32BE35BC');
|
|
220
219
|
var MERKLE_DISTRIBUTOR_ADDRESS = (_MERKLE_DISTRIBUTOR_A = {}, _MERKLE_DISTRIBUTOR_A[ChainId.MAINNET] = '0x090D4613473dEE047c3f2706764f49E0821D256e', _MERKLE_DISTRIBUTOR_A);
|
|
@@ -225,45 +224,56 @@ var QUOTER_ADDRESSES = /*#__PURE__*/_extends({}, /*#__PURE__*/SUPPORTED_CHAINS.r
|
|
|
225
224
|
}, {}));
|
|
226
225
|
var NONFUNGIBLE_POSITION_MANAGER_ADDRESSES = /*#__PURE__*/_extends({}, /*#__PURE__*/SUPPORTED_CHAINS.reduce(function (memo, chainId) {
|
|
227
226
|
var nonfungiblePositionManagerAddress = CHAIN_TO_ADDRESSES_MAP[chainId].nonfungiblePositionManagerAddress;
|
|
227
|
+
|
|
228
228
|
if (nonfungiblePositionManagerAddress) {
|
|
229
229
|
memo[chainId] = nonfungiblePositionManagerAddress;
|
|
230
230
|
}
|
|
231
|
+
|
|
231
232
|
return memo;
|
|
232
233
|
}, {}));
|
|
233
234
|
var ENS_REGISTRAR_ADDRESSES = /*#__PURE__*/_extends({}, /*#__PURE__*/constructSameAddressMap('0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e'));
|
|
234
235
|
var SOCKS_CONTROLLER_ADDRESSES = (_SOCKS_CONTROLLER_ADD = {}, _SOCKS_CONTROLLER_ADD[ChainId.MAINNET] = '0x65770b5283117639760beA3F867b69b3697a91dd', _SOCKS_CONTROLLER_ADD);
|
|
235
236
|
var TICK_LENS_ADDRESSES = /*#__PURE__*/_extends({}, /*#__PURE__*/SUPPORTED_CHAINS.reduce(function (memo, chainId) {
|
|
236
237
|
var tickLensAddress = CHAIN_TO_ADDRESSES_MAP[chainId].tickLensAddress;
|
|
238
|
+
|
|
237
239
|
if (tickLensAddress) {
|
|
238
240
|
memo[chainId] = tickLensAddress;
|
|
239
241
|
}
|
|
242
|
+
|
|
240
243
|
return memo;
|
|
241
244
|
}, {}));
|
|
242
245
|
var MIXED_ROUTE_QUOTER_V1_ADDRESSES = /*#__PURE__*/SUPPORTED_CHAINS.reduce(function (memo, chainId) {
|
|
243
246
|
var v1MixedRouteQuoterAddress = CHAIN_TO_ADDRESSES_MAP[chainId].v1MixedRouteQuoterAddress;
|
|
247
|
+
|
|
244
248
|
if (v1MixedRouteQuoterAddress) {
|
|
245
249
|
memo[chainId] = v1MixedRouteQuoterAddress;
|
|
246
250
|
}
|
|
251
|
+
|
|
247
252
|
return memo;
|
|
248
253
|
}, {});
|
|
249
254
|
var SWAP_ROUTER_02_ADDRESSES = function SWAP_ROUTER_02_ADDRESSES(chainId) {
|
|
250
255
|
if (chainId == ChainId.BNB) {
|
|
251
256
|
return CHAIN_TO_ADDRESSES_MAP[chainId].swapRouter02Address;
|
|
252
257
|
}
|
|
258
|
+
|
|
253
259
|
return '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45';
|
|
254
260
|
};
|
|
255
261
|
|
|
256
262
|
var TradeType;
|
|
263
|
+
|
|
257
264
|
(function (TradeType) {
|
|
258
265
|
TradeType[TradeType["EXACT_INPUT"] = 0] = "EXACT_INPUT";
|
|
259
266
|
TradeType[TradeType["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT";
|
|
260
267
|
})(TradeType || (TradeType = {}));
|
|
268
|
+
|
|
261
269
|
var Rounding;
|
|
270
|
+
|
|
262
271
|
(function (Rounding) {
|
|
263
272
|
Rounding[Rounding["ROUND_DOWN"] = 0] = "ROUND_DOWN";
|
|
264
273
|
Rounding[Rounding["ROUND_HALF_UP"] = 1] = "ROUND_HALF_UP";
|
|
265
274
|
Rounding[Rounding["ROUND_UP"] = 2] = "ROUND_UP";
|
|
266
275
|
})(Rounding || (Rounding = {}));
|
|
276
|
+
|
|
267
277
|
var MaxUint256 = /*#__PURE__*/JSBI.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
268
278
|
|
|
269
279
|
var _toSignificantRoundin, _toFixedRounding;
|
|
@@ -276,63 +286,80 @@ var Fraction = /*#__PURE__*/function () {
|
|
|
276
286
|
if (denominator === void 0) {
|
|
277
287
|
denominator = JSBI.BigInt(1);
|
|
278
288
|
}
|
|
289
|
+
|
|
279
290
|
this.numerator = JSBI.BigInt(numerator);
|
|
280
291
|
this.denominator = JSBI.BigInt(denominator);
|
|
281
292
|
}
|
|
293
|
+
|
|
282
294
|
Fraction.tryParseFraction = function tryParseFraction(fractionish) {
|
|
283
295
|
if (fractionish instanceof JSBI || typeof fractionish === 'number' || typeof fractionish === 'string') return new Fraction(fractionish);
|
|
284
296
|
if ('numerator' in fractionish && 'denominator' in fractionish) return fractionish;
|
|
285
297
|
throw new Error('Could not parse fraction');
|
|
286
|
-
}
|
|
287
|
-
// performs floor division
|
|
298
|
+
} // performs floor division
|
|
288
299
|
;
|
|
300
|
+
|
|
289
301
|
var _proto = Fraction.prototype;
|
|
302
|
+
|
|
290
303
|
_proto.invert = function invert() {
|
|
291
304
|
return new Fraction(this.denominator, this.numerator);
|
|
292
305
|
};
|
|
306
|
+
|
|
293
307
|
_proto.add = function add(other) {
|
|
294
308
|
var otherParsed = Fraction.tryParseFraction(other);
|
|
309
|
+
|
|
295
310
|
if (JSBI.equal(this.denominator, otherParsed.denominator)) {
|
|
296
311
|
return new Fraction(JSBI.add(this.numerator, otherParsed.numerator), this.denominator);
|
|
297
312
|
}
|
|
313
|
+
|
|
298
314
|
return new Fraction(JSBI.add(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator));
|
|
299
315
|
};
|
|
316
|
+
|
|
300
317
|
_proto.subtract = function subtract(other) {
|
|
301
318
|
var otherParsed = Fraction.tryParseFraction(other);
|
|
319
|
+
|
|
302
320
|
if (JSBI.equal(this.denominator, otherParsed.denominator)) {
|
|
303
321
|
return new Fraction(JSBI.subtract(this.numerator, otherParsed.numerator), this.denominator);
|
|
304
322
|
}
|
|
323
|
+
|
|
305
324
|
return new Fraction(JSBI.subtract(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator));
|
|
306
325
|
};
|
|
326
|
+
|
|
307
327
|
_proto.lessThan = function lessThan(other) {
|
|
308
328
|
var otherParsed = Fraction.tryParseFraction(other);
|
|
309
329
|
return JSBI.lessThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
|
|
310
330
|
};
|
|
331
|
+
|
|
311
332
|
_proto.equalTo = function equalTo(other) {
|
|
312
333
|
var otherParsed = Fraction.tryParseFraction(other);
|
|
313
334
|
return JSBI.equal(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
|
|
314
335
|
};
|
|
336
|
+
|
|
315
337
|
_proto.greaterThan = function greaterThan(other) {
|
|
316
338
|
var otherParsed = Fraction.tryParseFraction(other);
|
|
317
339
|
return JSBI.greaterThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
|
|
318
340
|
};
|
|
341
|
+
|
|
319
342
|
_proto.multiply = function multiply(other) {
|
|
320
343
|
var otherParsed = Fraction.tryParseFraction(other);
|
|
321
344
|
return new Fraction(JSBI.multiply(this.numerator, otherParsed.numerator), JSBI.multiply(this.denominator, otherParsed.denominator));
|
|
322
345
|
};
|
|
346
|
+
|
|
323
347
|
_proto.divide = function divide(other) {
|
|
324
348
|
var otherParsed = Fraction.tryParseFraction(other);
|
|
325
349
|
return new Fraction(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(this.denominator, otherParsed.numerator));
|
|
326
350
|
};
|
|
351
|
+
|
|
327
352
|
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
|
|
328
353
|
if (format === void 0) {
|
|
329
354
|
format = {
|
|
330
355
|
groupSeparator: ''
|
|
331
356
|
};
|
|
332
357
|
}
|
|
358
|
+
|
|
333
359
|
if (rounding === void 0) {
|
|
334
360
|
rounding = Rounding.ROUND_HALF_UP;
|
|
335
361
|
}
|
|
362
|
+
|
|
336
363
|
!Number.isInteger(significantDigits) ? process.env.NODE_ENV !== "production" ? invariant(false, significantDigits + " is not an integer.") : invariant(false) : void 0;
|
|
337
364
|
!(significantDigits > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, significantDigits + " is not positive.") : invariant(false) : void 0;
|
|
338
365
|
Decimal.set({
|
|
@@ -342,15 +369,18 @@ var Fraction = /*#__PURE__*/function () {
|
|
|
342
369
|
var quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits);
|
|
343
370
|
return quotient.toFormat(quotient.decimalPlaces(), format);
|
|
344
371
|
};
|
|
372
|
+
|
|
345
373
|
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) {
|
|
346
374
|
if (format === void 0) {
|
|
347
375
|
format = {
|
|
348
376
|
groupSeparator: ''
|
|
349
377
|
};
|
|
350
378
|
}
|
|
379
|
+
|
|
351
380
|
if (rounding === void 0) {
|
|
352
381
|
rounding = Rounding.ROUND_HALF_UP;
|
|
353
382
|
}
|
|
383
|
+
|
|
354
384
|
!Number.isInteger(decimalPlaces) ? process.env.NODE_ENV !== "production" ? invariant(false, decimalPlaces + " is not an integer.") : invariant(false) : void 0;
|
|
355
385
|
!(decimalPlaces >= 0) ? process.env.NODE_ENV !== "production" ? invariant(false, decimalPlaces + " is negative.") : invariant(false) : void 0;
|
|
356
386
|
Big.DP = decimalPlaces;
|
|
@@ -359,13 +389,15 @@ var Fraction = /*#__PURE__*/function () {
|
|
|
359
389
|
}
|
|
360
390
|
/**
|
|
361
391
|
* Helper method for converting any super class back to a fraction
|
|
362
|
-
|
|
392
|
+
*/
|
|
393
|
+
;
|
|
394
|
+
|
|
363
395
|
_createClass(Fraction, [{
|
|
364
396
|
key: "quotient",
|
|
365
397
|
get: function get() {
|
|
366
398
|
return JSBI.divide(this.numerator, this.denominator);
|
|
367
|
-
}
|
|
368
|
-
|
|
399
|
+
} // remainder after floor division
|
|
400
|
+
|
|
369
401
|
}, {
|
|
370
402
|
key: "remainder",
|
|
371
403
|
get: function get() {
|
|
@@ -377,14 +409,17 @@ var Fraction = /*#__PURE__*/function () {
|
|
|
377
409
|
return new Fraction(this.numerator, this.denominator);
|
|
378
410
|
}
|
|
379
411
|
}]);
|
|
412
|
+
|
|
380
413
|
return Fraction;
|
|
381
414
|
}();
|
|
382
415
|
|
|
383
416
|
var Big$1 = /*#__PURE__*/toFormat(_Big);
|
|
384
417
|
var CurrencyAmount = /*#__PURE__*/function (_Fraction) {
|
|
385
418
|
_inheritsLoose(CurrencyAmount, _Fraction);
|
|
419
|
+
|
|
386
420
|
function CurrencyAmount(currency, numerator, denominator) {
|
|
387
421
|
var _this;
|
|
422
|
+
|
|
388
423
|
_this = _Fraction.call(this, numerator, denominator) || this;
|
|
389
424
|
!JSBI.lessThanOrEqual(_this.quotient, MaxUint256) ? process.env.NODE_ENV !== "production" ? invariant(false, 'AMOUNT') : invariant(false) : void 0;
|
|
390
425
|
_this.currency = currency;
|
|
@@ -396,6 +431,8 @@ var CurrencyAmount = /*#__PURE__*/function (_Fraction) {
|
|
|
396
431
|
* @param currency the currency in the amount
|
|
397
432
|
* @param rawAmount the raw token or ether amount
|
|
398
433
|
*/
|
|
434
|
+
|
|
435
|
+
|
|
399
436
|
CurrencyAmount.fromRawAmount = function fromRawAmount(currency, rawAmount) {
|
|
400
437
|
return new CurrencyAmount(currency, rawAmount);
|
|
401
438
|
}
|
|
@@ -404,57 +441,79 @@ var CurrencyAmount = /*#__PURE__*/function (_Fraction) {
|
|
|
404
441
|
* @param currency the currency
|
|
405
442
|
* @param numerator the numerator of the fractional token amount
|
|
406
443
|
* @param denominator the denominator of the fractional token amount
|
|
407
|
-
|
|
444
|
+
*/
|
|
445
|
+
;
|
|
446
|
+
|
|
408
447
|
CurrencyAmount.fromFractionalAmount = function fromFractionalAmount(currency, numerator, denominator) {
|
|
409
448
|
return new CurrencyAmount(currency, numerator, denominator);
|
|
410
449
|
};
|
|
450
|
+
|
|
411
451
|
var _proto = CurrencyAmount.prototype;
|
|
452
|
+
|
|
412
453
|
_proto.add = function add(other) {
|
|
413
454
|
!this.currency.equals(other.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CURRENCY') : invariant(false) : void 0;
|
|
455
|
+
|
|
414
456
|
var added = _Fraction.prototype.add.call(this, other);
|
|
457
|
+
|
|
415
458
|
return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
|
|
416
459
|
};
|
|
460
|
+
|
|
417
461
|
_proto.subtract = function subtract(other) {
|
|
418
462
|
!this.currency.equals(other.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CURRENCY') : invariant(false) : void 0;
|
|
463
|
+
|
|
419
464
|
var subtracted = _Fraction.prototype.subtract.call(this, other);
|
|
465
|
+
|
|
420
466
|
return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
|
|
421
467
|
};
|
|
468
|
+
|
|
422
469
|
_proto.multiply = function multiply(other) {
|
|
423
470
|
var multiplied = _Fraction.prototype.multiply.call(this, other);
|
|
471
|
+
|
|
424
472
|
return CurrencyAmount.fromFractionalAmount(this.currency, multiplied.numerator, multiplied.denominator);
|
|
425
473
|
};
|
|
474
|
+
|
|
426
475
|
_proto.divide = function divide(other) {
|
|
427
476
|
var divided = _Fraction.prototype.divide.call(this, other);
|
|
477
|
+
|
|
428
478
|
return CurrencyAmount.fromFractionalAmount(this.currency, divided.numerator, divided.denominator);
|
|
429
479
|
};
|
|
480
|
+
|
|
430
481
|
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
|
|
431
482
|
if (significantDigits === void 0) {
|
|
432
483
|
significantDigits = 6;
|
|
433
484
|
}
|
|
485
|
+
|
|
434
486
|
if (rounding === void 0) {
|
|
435
487
|
rounding = Rounding.ROUND_DOWN;
|
|
436
488
|
}
|
|
489
|
+
|
|
437
490
|
return _Fraction.prototype.divide.call(this, this.decimalScale).toSignificant(significantDigits, format, rounding);
|
|
438
491
|
};
|
|
492
|
+
|
|
439
493
|
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) {
|
|
440
494
|
if (decimalPlaces === void 0) {
|
|
441
495
|
decimalPlaces = this.currency.decimals;
|
|
442
496
|
}
|
|
497
|
+
|
|
443
498
|
if (rounding === void 0) {
|
|
444
499
|
rounding = Rounding.ROUND_DOWN;
|
|
445
500
|
}
|
|
501
|
+
|
|
446
502
|
!(decimalPlaces <= this.currency.decimals) ? process.env.NODE_ENV !== "production" ? invariant(false, 'DECIMALS') : invariant(false) : void 0;
|
|
447
503
|
return _Fraction.prototype.divide.call(this, this.decimalScale).toFixed(decimalPlaces, format, rounding);
|
|
448
504
|
};
|
|
505
|
+
|
|
449
506
|
_proto.toExact = function toExact(format) {
|
|
450
507
|
if (format === void 0) {
|
|
451
508
|
format = {
|
|
452
509
|
groupSeparator: ''
|
|
453
510
|
};
|
|
454
511
|
}
|
|
512
|
+
|
|
455
513
|
Big$1.DP = this.currency.decimals;
|
|
456
514
|
return new Big$1(this.quotient.toString()).div(this.decimalScale.toString()).toFormat(format);
|
|
457
515
|
};
|
|
516
|
+
|
|
458
517
|
_createClass(CurrencyAmount, [{
|
|
459
518
|
key: "wrapped",
|
|
460
519
|
get: function get() {
|
|
@@ -462,6 +521,7 @@ var CurrencyAmount = /*#__PURE__*/function (_Fraction) {
|
|
|
462
521
|
return CurrencyAmount.fromFractionalAmount(this.currency.wrapped, this.numerator, this.denominator);
|
|
463
522
|
}
|
|
464
523
|
}]);
|
|
524
|
+
|
|
465
525
|
return CurrencyAmount;
|
|
466
526
|
}(Fraction);
|
|
467
527
|
|
|
@@ -470,60 +530,79 @@ var ONE_HUNDRED = /*#__PURE__*/new Fraction( /*#__PURE__*/JSBI.BigInt(100));
|
|
|
470
530
|
* Converts a fraction to a percent
|
|
471
531
|
* @param fraction the fraction to convert
|
|
472
532
|
*/
|
|
533
|
+
|
|
473
534
|
function toPercent(fraction) {
|
|
474
535
|
return new Percent(fraction.numerator, fraction.denominator);
|
|
475
536
|
}
|
|
537
|
+
|
|
476
538
|
var Percent = /*#__PURE__*/function (_Fraction) {
|
|
477
539
|
_inheritsLoose(Percent, _Fraction);
|
|
540
|
+
|
|
478
541
|
function Percent() {
|
|
479
542
|
var _this;
|
|
543
|
+
|
|
480
544
|
_this = _Fraction.apply(this, arguments) || this;
|
|
481
545
|
/**
|
|
482
546
|
* This boolean prevents a fraction from being interpreted as a Percent
|
|
483
547
|
*/
|
|
548
|
+
|
|
484
549
|
_this.isPercent = true;
|
|
485
550
|
return _this;
|
|
486
551
|
}
|
|
552
|
+
|
|
487
553
|
var _proto = Percent.prototype;
|
|
554
|
+
|
|
488
555
|
_proto.add = function add(other) {
|
|
489
556
|
return toPercent(_Fraction.prototype.add.call(this, other));
|
|
490
557
|
};
|
|
558
|
+
|
|
491
559
|
_proto.subtract = function subtract(other) {
|
|
492
560
|
return toPercent(_Fraction.prototype.subtract.call(this, other));
|
|
493
561
|
};
|
|
562
|
+
|
|
494
563
|
_proto.multiply = function multiply(other) {
|
|
495
564
|
return toPercent(_Fraction.prototype.multiply.call(this, other));
|
|
496
565
|
};
|
|
566
|
+
|
|
497
567
|
_proto.divide = function divide(other) {
|
|
498
568
|
return toPercent(_Fraction.prototype.divide.call(this, other));
|
|
499
569
|
};
|
|
570
|
+
|
|
500
571
|
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
|
|
501
572
|
if (significantDigits === void 0) {
|
|
502
573
|
significantDigits = 5;
|
|
503
574
|
}
|
|
575
|
+
|
|
504
576
|
return _Fraction.prototype.multiply.call(this, ONE_HUNDRED).toSignificant(significantDigits, format, rounding);
|
|
505
577
|
};
|
|
578
|
+
|
|
506
579
|
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) {
|
|
507
580
|
if (decimalPlaces === void 0) {
|
|
508
581
|
decimalPlaces = 2;
|
|
509
582
|
}
|
|
583
|
+
|
|
510
584
|
return _Fraction.prototype.multiply.call(this, ONE_HUNDRED).toFixed(decimalPlaces, format, rounding);
|
|
511
585
|
};
|
|
586
|
+
|
|
512
587
|
return Percent;
|
|
513
588
|
}(Fraction);
|
|
514
589
|
|
|
515
590
|
var Price = /*#__PURE__*/function (_Fraction) {
|
|
516
591
|
_inheritsLoose(Price, _Fraction);
|
|
592
|
+
|
|
517
593
|
/**
|
|
518
594
|
* Construct a price, either with the base and quote currency amount, or the
|
|
519
595
|
* @param args
|
|
520
596
|
*/
|
|
521
597
|
function Price() {
|
|
522
598
|
var _this;
|
|
599
|
+
|
|
523
600
|
var baseCurrency, quoteCurrency, denominator, numerator;
|
|
601
|
+
|
|
524
602
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
525
603
|
args[_key] = arguments[_key];
|
|
526
604
|
}
|
|
605
|
+
|
|
527
606
|
if (args.length === 4) {
|
|
528
607
|
baseCurrency = args[0];
|
|
529
608
|
quoteCurrency = args[1];
|
|
@@ -537,6 +616,7 @@ var Price = /*#__PURE__*/function (_Fraction) {
|
|
|
537
616
|
denominator = _ref[2];
|
|
538
617
|
numerator = _ref[3];
|
|
539
618
|
}
|
|
619
|
+
|
|
540
620
|
_this = _Fraction.call(this, numerator, denominator) || this;
|
|
541
621
|
_this.baseCurrency = baseCurrency;
|
|
542
622
|
_this.quoteCurrency = quoteCurrency;
|
|
@@ -546,56 +626,75 @@ var Price = /*#__PURE__*/function (_Fraction) {
|
|
|
546
626
|
/**
|
|
547
627
|
* Flip the price, switching the base and quote currency
|
|
548
628
|
*/
|
|
629
|
+
|
|
630
|
+
|
|
549
631
|
var _proto = Price.prototype;
|
|
632
|
+
|
|
550
633
|
_proto.invert = function invert() {
|
|
551
634
|
return new Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator);
|
|
552
635
|
}
|
|
553
636
|
/**
|
|
554
637
|
* Multiply the price by another price, returning a new price. The other price must have the same base currency as this price's quote currency
|
|
555
638
|
* @param other the other price
|
|
556
|
-
|
|
639
|
+
*/
|
|
640
|
+
;
|
|
641
|
+
|
|
557
642
|
_proto.multiply = function multiply(other) {
|
|
558
643
|
!this.quoteCurrency.equals(other.baseCurrency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
|
|
644
|
+
|
|
559
645
|
var fraction = _Fraction.prototype.multiply.call(this, other);
|
|
646
|
+
|
|
560
647
|
return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
|
|
561
648
|
}
|
|
562
649
|
/**
|
|
563
650
|
* Return the amount of quote currency corresponding to a given amount of the base currency
|
|
564
651
|
* @param currencyAmount the amount of base currency to quote against the price
|
|
565
|
-
|
|
652
|
+
*/
|
|
653
|
+
;
|
|
654
|
+
|
|
566
655
|
_proto.quote = function quote(currencyAmount) {
|
|
567
656
|
!currencyAmount.currency.equals(this.baseCurrency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
|
|
657
|
+
|
|
568
658
|
var result = _Fraction.prototype.multiply.call(this, currencyAmount);
|
|
659
|
+
|
|
569
660
|
return CurrencyAmount.fromFractionalAmount(this.quoteCurrency, result.numerator, result.denominator);
|
|
570
661
|
}
|
|
571
662
|
/**
|
|
572
663
|
* Get the value scaled by decimals for formatting
|
|
573
664
|
* @private
|
|
574
|
-
|
|
665
|
+
*/
|
|
666
|
+
;
|
|
667
|
+
|
|
575
668
|
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
|
|
576
669
|
if (significantDigits === void 0) {
|
|
577
670
|
significantDigits = 6;
|
|
578
671
|
}
|
|
672
|
+
|
|
579
673
|
return this.adjustedForDecimals.toSignificant(significantDigits, format, rounding);
|
|
580
674
|
};
|
|
675
|
+
|
|
581
676
|
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) {
|
|
582
677
|
if (decimalPlaces === void 0) {
|
|
583
678
|
decimalPlaces = 4;
|
|
584
679
|
}
|
|
680
|
+
|
|
585
681
|
return this.adjustedForDecimals.toFixed(decimalPlaces, format, rounding);
|
|
586
682
|
};
|
|
683
|
+
|
|
587
684
|
_createClass(Price, [{
|
|
588
685
|
key: "adjustedForDecimals",
|
|
589
686
|
get: function get() {
|
|
590
687
|
return _Fraction.prototype.multiply.call(this, this.scalar);
|
|
591
688
|
}
|
|
592
689
|
}]);
|
|
690
|
+
|
|
593
691
|
return Price;
|
|
594
692
|
}(Fraction);
|
|
595
693
|
|
|
596
694
|
/**
|
|
597
695
|
* A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
|
|
598
696
|
*/
|
|
697
|
+
|
|
599
698
|
var BaseCurrency =
|
|
600
699
|
/**
|
|
601
700
|
* Constructs an instance of the base class `BaseCurrency`.
|
|
@@ -616,15 +715,19 @@ function BaseCurrency(chainId, decimals, symbol, name) {
|
|
|
616
715
|
/**
|
|
617
716
|
* Represents the native currency of the chain on which it resides, e.g.
|
|
618
717
|
*/
|
|
718
|
+
|
|
619
719
|
var NativeCurrency = /*#__PURE__*/function (_BaseCurrency) {
|
|
620
720
|
_inheritsLoose(NativeCurrency, _BaseCurrency);
|
|
721
|
+
|
|
621
722
|
function NativeCurrency() {
|
|
622
723
|
var _this;
|
|
724
|
+
|
|
623
725
|
_this = _BaseCurrency.apply(this, arguments) || this;
|
|
624
726
|
_this.isNative = true;
|
|
625
727
|
_this.isToken = false;
|
|
626
728
|
return _this;
|
|
627
729
|
}
|
|
730
|
+
|
|
628
731
|
return NativeCurrency;
|
|
629
732
|
}(BaseCurrency);
|
|
630
733
|
|
|
@@ -632,31 +735,36 @@ var NativeCurrency = /*#__PURE__*/function (_BaseCurrency) {
|
|
|
632
735
|
* Validates an address and returns the parsed (checksummed) version of that address
|
|
633
736
|
* @param address the unchecksummed hex address
|
|
634
737
|
*/
|
|
738
|
+
|
|
635
739
|
function validateAndParseAddress(address) {
|
|
636
740
|
try {
|
|
637
741
|
return getAddress(address);
|
|
638
742
|
} catch (error) {
|
|
639
743
|
throw new Error(address + " is not a valid address.");
|
|
640
744
|
}
|
|
641
|
-
}
|
|
642
|
-
|
|
745
|
+
} // Checks a string starts with 0x, is 42 characters long and contains only hex characters after 0x
|
|
746
|
+
|
|
643
747
|
var startsWith0xLen42HexRegex = /^0x[0-9a-fA-F]{40}$/;
|
|
644
748
|
/**
|
|
645
749
|
* Checks if an address is valid by checking 0x prefix, length === 42 and hex encoding.
|
|
646
750
|
* @param address the unchecksummed hex address
|
|
647
751
|
*/
|
|
752
|
+
|
|
648
753
|
function checkValidAddress(address) {
|
|
649
754
|
if (startsWith0xLen42HexRegex.test(address)) {
|
|
650
755
|
return address;
|
|
651
756
|
}
|
|
757
|
+
|
|
652
758
|
throw new Error(address + " is not a valid address.");
|
|
653
759
|
}
|
|
654
760
|
|
|
655
761
|
/**
|
|
656
762
|
* Represents an ERC20 token with a unique address and some metadata.
|
|
657
763
|
*/
|
|
764
|
+
|
|
658
765
|
var Token = /*#__PURE__*/function (_BaseCurrency) {
|
|
659
766
|
_inheritsLoose(Token, _BaseCurrency);
|
|
767
|
+
|
|
660
768
|
/**
|
|
661
769
|
*
|
|
662
770
|
* @param chainId {@link BaseCurrency#chainId}
|
|
@@ -668,21 +776,27 @@ var Token = /*#__PURE__*/function (_BaseCurrency) {
|
|
|
668
776
|
*/
|
|
669
777
|
function Token(chainId, address, decimals, symbol, name, bypassChecksum) {
|
|
670
778
|
var _this;
|
|
779
|
+
|
|
671
780
|
_this = _BaseCurrency.call(this, chainId, decimals, symbol, name) || this;
|
|
672
781
|
_this.isNative = false;
|
|
673
782
|
_this.isToken = true;
|
|
783
|
+
|
|
674
784
|
if (bypassChecksum) {
|
|
675
785
|
_this.address = checkValidAddress(address);
|
|
676
786
|
} else {
|
|
677
787
|
_this.address = validateAndParseAddress(address);
|
|
678
788
|
}
|
|
789
|
+
|
|
679
790
|
return _this;
|
|
680
791
|
}
|
|
681
792
|
/**
|
|
682
793
|
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
|
|
683
794
|
* @param other other token to compare
|
|
684
795
|
*/
|
|
796
|
+
|
|
797
|
+
|
|
685
798
|
var _proto = Token.prototype;
|
|
799
|
+
|
|
686
800
|
_proto.equals = function equals(other) {
|
|
687
801
|
return other.isToken && this.chainId === other.chainId && this.address.toLowerCase() === other.address.toLowerCase();
|
|
688
802
|
}
|
|
@@ -691,7 +805,9 @@ var Token = /*#__PURE__*/function (_BaseCurrency) {
|
|
|
691
805
|
* @param other other token to compare
|
|
692
806
|
* @throws if the tokens have the same address
|
|
693
807
|
* @throws if the tokens are on different chains
|
|
694
|
-
|
|
808
|
+
*/
|
|
809
|
+
;
|
|
810
|
+
|
|
695
811
|
_proto.sortsBefore = function sortsBefore(other) {
|
|
696
812
|
!(this.chainId === other.chainId) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_IDS') : invariant(false) : void 0;
|
|
697
813
|
!(this.address.toLowerCase() !== other.address.toLowerCase()) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ADDRESSES') : invariant(false) : void 0;
|
|
@@ -699,13 +815,16 @@ var Token = /*#__PURE__*/function (_BaseCurrency) {
|
|
|
699
815
|
}
|
|
700
816
|
/**
|
|
701
817
|
* Return this token, which does not need to be wrapped
|
|
702
|
-
|
|
818
|
+
*/
|
|
819
|
+
;
|
|
820
|
+
|
|
703
821
|
_createClass(Token, [{
|
|
704
822
|
key: "wrapped",
|
|
705
823
|
get: function get() {
|
|
706
824
|
return this;
|
|
707
825
|
}
|
|
708
826
|
}]);
|
|
827
|
+
|
|
709
828
|
return Token;
|
|
710
829
|
}(BaseCurrency);
|
|
711
830
|
|
|
@@ -713,24 +832,32 @@ var _WETH;
|
|
|
713
832
|
/**
|
|
714
833
|
* Known WETH9 implementation addresses, used in our implementation of Ether#wrapped
|
|
715
834
|
*/
|
|
835
|
+
|
|
716
836
|
var WETH9 = (_WETH = {}, _WETH[1] = /*#__PURE__*/new Token(1, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH', 'Wrapped Ether'), _WETH[3] = /*#__PURE__*/new Token(3, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH', 'Wrapped Ether'), _WETH[4] = /*#__PURE__*/new Token(4, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH', 'Wrapped Ether'), _WETH[5] = /*#__PURE__*/new Token(5, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 18, 'WETH', 'Wrapped Ether'), _WETH[42] = /*#__PURE__*/new Token(42, '0xd0A1E359811322d97991E03f863a0C30C2cF029C', 18, 'WETH', 'Wrapped Ether'), _WETH[10] = /*#__PURE__*/new Token(10, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'), _WETH[69] = /*#__PURE__*/new Token(69, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'), _WETH[42161] = /*#__PURE__*/new Token(42161, '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', 18, 'WETH', 'Wrapped Ether'), _WETH[421611] = /*#__PURE__*/new Token(421611, '0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681', 18, 'WETH', 'Wrapped Ether'), _WETH);
|
|
717
837
|
|
|
718
838
|
/**
|
|
719
839
|
* Ether is the main usage of a 'native' currency, i.e. for Ethereum mainnet and all testnets
|
|
720
840
|
*/
|
|
841
|
+
|
|
721
842
|
var Ether = /*#__PURE__*/function (_NativeCurrency) {
|
|
722
843
|
_inheritsLoose(Ether, _NativeCurrency);
|
|
844
|
+
|
|
723
845
|
function Ether(chainId) {
|
|
724
846
|
return _NativeCurrency.call(this, chainId, 18, 'ETH', 'Ether') || this;
|
|
725
847
|
}
|
|
848
|
+
|
|
726
849
|
Ether.onChain = function onChain(chainId) {
|
|
727
850
|
var _this$_etherCache$cha;
|
|
851
|
+
|
|
728
852
|
return (_this$_etherCache$cha = this._etherCache[chainId]) != null ? _this$_etherCache$cha : this._etherCache[chainId] = new Ether(chainId);
|
|
729
853
|
};
|
|
854
|
+
|
|
730
855
|
var _proto = Ether.prototype;
|
|
856
|
+
|
|
731
857
|
_proto.equals = function equals(other) {
|
|
732
858
|
return other.isNative && other.chainId === this.chainId;
|
|
733
859
|
};
|
|
860
|
+
|
|
734
861
|
_createClass(Ether, [{
|
|
735
862
|
key: "wrapped",
|
|
736
863
|
get: function get() {
|
|
@@ -739,6 +866,7 @@ var Ether = /*#__PURE__*/function (_NativeCurrency) {
|
|
|
739
866
|
return weth9;
|
|
740
867
|
}
|
|
741
868
|
}]);
|
|
869
|
+
|
|
742
870
|
return Ether;
|
|
743
871
|
}(NativeCurrency);
|
|
744
872
|
Ether._etherCache = {};
|
|
@@ -749,39 +877,44 @@ Ether._etherCache = {};
|
|
|
749
877
|
* @param inputAmount the input amount of the trade
|
|
750
878
|
* @param outputAmount the output amount of the trade
|
|
751
879
|
*/
|
|
880
|
+
|
|
752
881
|
function computePriceImpact(midPrice, inputAmount, outputAmount) {
|
|
753
|
-
var quotedOutputAmount = midPrice.quote(inputAmount);
|
|
754
|
-
|
|
882
|
+
var quotedOutputAmount = midPrice.quote(inputAmount); // calculate price impact := (exactQuote - outputAmount) / exactQuote
|
|
883
|
+
|
|
755
884
|
var priceImpact = quotedOutputAmount.subtract(outputAmount).divide(quotedOutputAmount);
|
|
756
885
|
return new Percent(priceImpact.numerator, priceImpact.denominator);
|
|
757
886
|
}
|
|
758
887
|
|
|
759
|
-
// given an array of items sorted by `comparator`, insert an item into its sort index and constrain the size to
|
|
760
888
|
// `maxSize` by removing the last item
|
|
889
|
+
|
|
761
890
|
function sortedInsert(items, add, maxSize, comparator) {
|
|
762
|
-
!(maxSize > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MAX_SIZE_ZERO') : invariant(false) : void 0;
|
|
763
|
-
|
|
764
|
-
!(items.length <= maxSize) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ITEMS_SIZE') : invariant(false) : void 0;
|
|
765
|
-
|
|
891
|
+
!(maxSize > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MAX_SIZE_ZERO') : invariant(false) : void 0; // this is an invariant because the interface cannot return multiple removed items if items.length exceeds maxSize
|
|
892
|
+
|
|
893
|
+
!(items.length <= maxSize) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ITEMS_SIZE') : invariant(false) : void 0; // short circuit first item add
|
|
894
|
+
|
|
766
895
|
if (items.length === 0) {
|
|
767
896
|
items.push(add);
|
|
768
897
|
return null;
|
|
769
898
|
} else {
|
|
770
|
-
var isFull = items.length === maxSize;
|
|
771
|
-
|
|
899
|
+
var isFull = items.length === maxSize; // short circuit if full and the additional item does not come before the last item
|
|
900
|
+
|
|
772
901
|
if (isFull && comparator(items[items.length - 1], add) <= 0) {
|
|
773
902
|
return add;
|
|
774
903
|
}
|
|
904
|
+
|
|
775
905
|
var lo = 0,
|
|
776
|
-
|
|
906
|
+
hi = items.length;
|
|
907
|
+
|
|
777
908
|
while (lo < hi) {
|
|
778
909
|
var mid = lo + hi >>> 1;
|
|
910
|
+
|
|
779
911
|
if (comparator(items[mid], add) <= 0) {
|
|
780
912
|
lo = mid + 1;
|
|
781
913
|
} else {
|
|
782
914
|
hi = mid;
|
|
783
915
|
}
|
|
784
916
|
}
|
|
917
|
+
|
|
785
918
|
items.splice(lo, 0, add);
|
|
786
919
|
return isFull ? items.pop() : null;
|
|
787
920
|
}
|
|
@@ -795,20 +928,24 @@ var TWO = /*#__PURE__*/JSBI.BigInt(2);
|
|
|
795
928
|
* Computes floor(sqrt(value))
|
|
796
929
|
* @param value the value for which to compute the square root, rounded down
|
|
797
930
|
*/
|
|
931
|
+
|
|
798
932
|
function sqrt(value) {
|
|
799
|
-
!JSBI.greaterThanOrEqual(value, ZERO) ? process.env.NODE_ENV !== "production" ? invariant(false, 'NEGATIVE') : invariant(false) : void 0;
|
|
800
|
-
|
|
933
|
+
!JSBI.greaterThanOrEqual(value, ZERO) ? process.env.NODE_ENV !== "production" ? invariant(false, 'NEGATIVE') : invariant(false) : void 0; // rely on built in sqrt if possible
|
|
934
|
+
|
|
801
935
|
if (JSBI.lessThan(value, MAX_SAFE_INTEGER)) {
|
|
802
936
|
return JSBI.BigInt(Math.floor(Math.sqrt(JSBI.toNumber(value))));
|
|
803
937
|
}
|
|
938
|
+
|
|
804
939
|
var z;
|
|
805
940
|
var x;
|
|
806
941
|
z = value;
|
|
807
942
|
x = JSBI.add(JSBI.divide(value, TWO), ONE);
|
|
943
|
+
|
|
808
944
|
while (JSBI.lessThan(x, z)) {
|
|
809
945
|
z = x;
|
|
810
946
|
x = JSBI.divide(JSBI.add(JSBI.divide(value, x), x), TWO);
|
|
811
947
|
}
|
|
948
|
+
|
|
812
949
|
return z;
|
|
813
950
|
}
|
|
814
951
|
|