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