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