@curvefi/api 1.3.0 → 1.5.0
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/lib/boosting.js +39 -27
- package/lib/constants/abis/json/busd/swap.json +1 -2
- package/lib/constants/abis/json/compound/swap.json +1 -2
- package/lib/constants/abis/json/iearn/swap.json +1 -2
- package/lib/constants/abis/json/pax/swap.json +1 -2
- package/lib/constants/abis/json/ren/swap.json +1 -2
- package/lib/constants/abis/json/sbtc/swap.json +1 -2
- package/lib/constants/abis/json/susdv2/swap.json +1 -2
- package/lib/constants/abis/json/usdt/swap.json +1 -2
- package/lib/curve.d.ts +18 -2
- package/lib/curve.js +76 -27
- package/lib/index.d.ts +8 -2
- package/lib/index.js +3 -3
- package/lib/pools.d.ts +45 -1
- package/lib/pools.js +908 -419
- package/lib/utils.js +49 -42
- package/package.json +2 -2
package/lib/utils.js
CHANGED
|
@@ -46,10 +46,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
50
|
-
for (var i = 0,
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
53
57
|
};
|
|
54
58
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
55
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -71,7 +75,7 @@ var BN = function (val) { return new bignumber_js_1.default(val); };
|
|
|
71
75
|
exports.BN = BN;
|
|
72
76
|
var toBN = function (n, decimals) {
|
|
73
77
|
if (decimals === void 0) { decimals = 18; }
|
|
74
|
-
return exports.BN(ethers_1.ethers.utils.formatUnits(n, decimals)).times(decimals);
|
|
78
|
+
return (0, exports.BN)(ethers_1.ethers.utils.formatUnits(n, decimals)).times(decimals);
|
|
75
79
|
};
|
|
76
80
|
exports.toBN = toBN;
|
|
77
81
|
var toStringFromBN = function (bn, decimals) {
|
|
@@ -81,7 +85,7 @@ var toStringFromBN = function (bn, decimals) {
|
|
|
81
85
|
exports.toStringFromBN = toStringFromBN;
|
|
82
86
|
var fromBN = function (bn, decimals) {
|
|
83
87
|
if (decimals === void 0) { decimals = 18; }
|
|
84
|
-
return ethers_1.ethers.utils.parseUnits(exports.toStringFromBN(bn, decimals), decimals);
|
|
88
|
+
return ethers_1.ethers.utils.parseUnits((0, exports.toStringFromBN)(bn, decimals), decimals);
|
|
85
89
|
};
|
|
86
90
|
exports.fromBN = fromBN;
|
|
87
91
|
// -------------------
|
|
@@ -99,7 +103,7 @@ var _getCoinAddresses = function () {
|
|
|
99
103
|
coins = coins[0];
|
|
100
104
|
coins = coins;
|
|
101
105
|
var coinAddresses = coins.map(function (c) { return coins_1.COINS[c.toLowerCase()] || c; });
|
|
102
|
-
var availableAddresses = __spreadArray(__spreadArray(__spreadArray([], Object.keys(coins_1.LOWER_CASE_DECIMALS).filter(function (c) { return c !== coins_1.COINS['snx'].toLowerCase(); })), LP_TOKENS), GAUGES);
|
|
106
|
+
var availableAddresses = __spreadArray(__spreadArray(__spreadArray([], Object.keys(coins_1.LOWER_CASE_DECIMALS).filter(function (c) { return c !== coins_1.COINS['snx'].toLowerCase(); }), true), LP_TOKENS, true), GAUGES, true);
|
|
103
107
|
for (var _a = 0, coinAddresses_1 = coinAddresses; _a < coinAddresses_1.length; _a++) {
|
|
104
108
|
var coinAddr = coinAddresses_1[_a];
|
|
105
109
|
if (!availableAddresses.includes(coinAddr.toLowerCase()))
|
|
@@ -124,9 +128,9 @@ var _getBalances = function (coins, addresses) { return __awaiter(void 0, void 0
|
|
|
124
128
|
return __generator(this, function (_e) {
|
|
125
129
|
switch (_e.label) {
|
|
126
130
|
case 0:
|
|
127
|
-
coinAddresses = exports._getCoinAddresses(coins);
|
|
128
|
-
decimals = exports._getCoinDecimals(coinAddresses);
|
|
129
|
-
ethIndex = exports.getEthIndex(coinAddresses);
|
|
131
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
132
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
133
|
+
ethIndex = (0, exports.getEthIndex)(coinAddresses);
|
|
130
134
|
if (ethIndex !== -1) {
|
|
131
135
|
coinAddresses.splice(ethIndex, 1);
|
|
132
136
|
}
|
|
@@ -157,7 +161,7 @@ var _getBalances = function (coins, addresses) { return __awaiter(void 0, void 0
|
|
|
157
161
|
_a++;
|
|
158
162
|
return [3 /*break*/, 2];
|
|
159
163
|
case 5:
|
|
160
|
-
response.splice.apply(response, __spreadArray([ethIndex * addresses.length, 0], ethBalances));
|
|
164
|
+
response.splice.apply(response, __spreadArray([ethIndex * addresses.length, 0], ethBalances, false));
|
|
161
165
|
_e.label = 6;
|
|
162
166
|
case 6:
|
|
163
167
|
_balances = {};
|
|
@@ -193,8 +197,8 @@ var getBalances = function (coins) {
|
|
|
193
197
|
return __generator(this, function (_a) {
|
|
194
198
|
switch (_a.label) {
|
|
195
199
|
case 0:
|
|
196
|
-
addresses = exports._prepareAddresses(addresses);
|
|
197
|
-
return [4 /*yield*/, exports._getBalances(coins, addresses)];
|
|
200
|
+
addresses = (0, exports._prepareAddresses)(addresses);
|
|
201
|
+
return [4 /*yield*/, (0, exports._getBalances)(coins, addresses)];
|
|
198
202
|
case 1:
|
|
199
203
|
balances = _a.sent();
|
|
200
204
|
return [2 /*return*/, addresses.length === 1 ? balances[addresses[0]] : balances];
|
|
@@ -208,8 +212,8 @@ var _getAllowance = function (coins, address, spender) { return __awaiter(void 0
|
|
|
208
212
|
return __generator(this, function (_a) {
|
|
209
213
|
switch (_a.label) {
|
|
210
214
|
case 0:
|
|
211
|
-
_coins = __spreadArray([], coins);
|
|
212
|
-
ethIndex = exports.getEthIndex(_coins);
|
|
215
|
+
_coins = __spreadArray([], coins, true);
|
|
216
|
+
ethIndex = (0, exports.getEthIndex)(_coins);
|
|
213
217
|
if (ethIndex !== -1) {
|
|
214
218
|
_coins.splice(ethIndex, 1);
|
|
215
219
|
}
|
|
@@ -239,9 +243,9 @@ var getAllowance = function (coins, address, spender) { return __awaiter(void 0,
|
|
|
239
243
|
return __generator(this, function (_a) {
|
|
240
244
|
switch (_a.label) {
|
|
241
245
|
case 0:
|
|
242
|
-
coinAddresses = exports._getCoinAddresses(coins);
|
|
243
|
-
decimals = exports._getCoinDecimals(coinAddresses);
|
|
244
|
-
return [4 /*yield*/, exports._getAllowance(coinAddresses, address, spender)];
|
|
246
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
247
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
248
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
245
249
|
case 1:
|
|
246
250
|
_allowance = _a.sent();
|
|
247
251
|
return [2 /*return*/, _allowance.map(function (a, i) { return ethers_1.ethers.utils.formatUnits(a, decimals[i]); })];
|
|
@@ -255,9 +259,9 @@ var hasAllowance = function (coins, amounts, address, spender) { return __awaite
|
|
|
255
259
|
return __generator(this, function (_a) {
|
|
256
260
|
switch (_a.label) {
|
|
257
261
|
case 0:
|
|
258
|
-
coinAddresses = exports._getCoinAddresses(coins);
|
|
259
|
-
decimals = exports._getCoinDecimals(coinAddresses);
|
|
260
|
-
return [4 /*yield*/, exports._getAllowance(coinAddresses, address, spender)];
|
|
262
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
263
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
264
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
261
265
|
case 1:
|
|
262
266
|
_allowance = _a.sent();
|
|
263
267
|
_amounts = amounts.map(function (a, i) { return ethers_1.ethers.utils.parseUnits(a, decimals[i]); });
|
|
@@ -272,37 +276,40 @@ var _ensureAllowance = function (coins, amounts, spender) { return __awaiter(voi
|
|
|
272
276
|
switch (_e.label) {
|
|
273
277
|
case 0:
|
|
274
278
|
address = curve_1.curve.signerAddress;
|
|
275
|
-
return [4 /*yield*/, exports._getAllowance(coins, address, spender)];
|
|
279
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coins, address, spender)];
|
|
276
280
|
case 1:
|
|
277
281
|
allowance = _e.sent();
|
|
278
282
|
txHashes = [];
|
|
279
283
|
i = 0;
|
|
280
284
|
_e.label = 2;
|
|
281
285
|
case 2:
|
|
282
|
-
if (!(i < allowance.length)) return [3 /*break*/,
|
|
283
|
-
if (!allowance[i].lt(amounts[i])) return [3 /*break*/,
|
|
286
|
+
if (!(i < allowance.length)) return [3 /*break*/, 10];
|
|
287
|
+
if (!allowance[i].lt(amounts[i])) return [3 /*break*/, 9];
|
|
284
288
|
contract = curve_1.curve.contracts[coins[i]].contract;
|
|
285
|
-
|
|
286
|
-
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.options)];
|
|
289
|
+
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
287
290
|
case 3:
|
|
291
|
+
_e.sent();
|
|
292
|
+
if (!allowance[i].gt(ethers_1.ethers.BigNumber.from(0))) return [3 /*break*/, 6];
|
|
293
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.constantOptions)];
|
|
294
|
+
case 4:
|
|
288
295
|
gasLimit_1 = (_e.sent()).mul(130).div(100);
|
|
289
296
|
_b = (_a = txHashes).push;
|
|
290
297
|
return [4 /*yield*/, contract.approve(spender, ethers_1.ethers.BigNumber.from(0), __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_1 }))];
|
|
291
|
-
case
|
|
298
|
+
case 5:
|
|
292
299
|
_b.apply(_a, [(_e.sent()).hash]);
|
|
293
|
-
_e.label =
|
|
294
|
-
case
|
|
295
|
-
case
|
|
300
|
+
_e.label = 6;
|
|
301
|
+
case 6: return [4 /*yield*/, contract.estimateGas.approve(spender, exports.MAX_ALLOWANCE, curve_1.curve.constantOptions)];
|
|
302
|
+
case 7:
|
|
296
303
|
gasLimit = (_e.sent()).mul(130).div(100);
|
|
297
304
|
_d = (_c = txHashes).push;
|
|
298
305
|
return [4 /*yield*/, contract.approve(spender, exports.MAX_ALLOWANCE, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
299
|
-
case 7:
|
|
300
|
-
_d.apply(_c, [(_e.sent()).hash]);
|
|
301
|
-
_e.label = 8;
|
|
302
306
|
case 8:
|
|
307
|
+
_d.apply(_c, [(_e.sent()).hash]);
|
|
308
|
+
_e.label = 9;
|
|
309
|
+
case 9:
|
|
303
310
|
i++;
|
|
304
311
|
return [3 /*break*/, 2];
|
|
305
|
-
case
|
|
312
|
+
case 10: return [2 /*return*/, txHashes];
|
|
306
313
|
}
|
|
307
314
|
});
|
|
308
315
|
}); };
|
|
@@ -313,11 +320,11 @@ var ensureAllowanceEstimateGas = function (coins, amounts, spender) { return __a
|
|
|
313
320
|
return __generator(this, function (_c) {
|
|
314
321
|
switch (_c.label) {
|
|
315
322
|
case 0:
|
|
316
|
-
coinAddresses = exports._getCoinAddresses(coins);
|
|
317
|
-
decimals = exports._getCoinDecimals(coinAddresses);
|
|
323
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
324
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
318
325
|
_amounts = amounts.map(function (a, i) { return ethers_1.ethers.utils.parseUnits(a, decimals[i]); });
|
|
319
326
|
address = curve_1.curve.signerAddress;
|
|
320
|
-
return [4 /*yield*/, exports._getAllowance(coinAddresses, address, spender)];
|
|
327
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
321
328
|
case 1:
|
|
322
329
|
allowance = _c.sent();
|
|
323
330
|
gas = 0;
|
|
@@ -329,13 +336,13 @@ var ensureAllowanceEstimateGas = function (coins, amounts, spender) { return __a
|
|
|
329
336
|
contract = curve_1.curve.contracts[coinAddresses[i]].contract;
|
|
330
337
|
if (!allowance[i].gt(ethers_1.ethers.BigNumber.from(0))) return [3 /*break*/, 4];
|
|
331
338
|
_a = gas;
|
|
332
|
-
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.
|
|
339
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.constantOptions)];
|
|
333
340
|
case 3:
|
|
334
341
|
gas = _a + (_c.sent()).toNumber();
|
|
335
342
|
_c.label = 4;
|
|
336
343
|
case 4:
|
|
337
344
|
_b = gas;
|
|
338
|
-
return [4 /*yield*/, contract.estimateGas.approve(spender, exports.MAX_ALLOWANCE, curve_1.curve.
|
|
345
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, exports.MAX_ALLOWANCE, curve_1.curve.constantOptions)];
|
|
339
346
|
case 5:
|
|
340
347
|
gas = _b + (_c.sent()).toNumber();
|
|
341
348
|
_c.label = 6;
|
|
@@ -353,10 +360,10 @@ var ensureAllowance = function (coins, amounts, spender) { return __awaiter(void
|
|
|
353
360
|
return __generator(this, function (_a) {
|
|
354
361
|
switch (_a.label) {
|
|
355
362
|
case 0:
|
|
356
|
-
coinAddresses = exports._getCoinAddresses(coins);
|
|
357
|
-
decimals = exports._getCoinDecimals(coinAddresses);
|
|
363
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
364
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
358
365
|
_amounts = amounts.map(function (a, i) { return ethers_1.ethers.utils.parseUnits(a, decimals[i]); });
|
|
359
|
-
return [4 /*yield*/, exports._ensureAllowance(coinAddresses, _amounts, spender)];
|
|
366
|
+
return [4 /*yield*/, (0, exports._ensureAllowance)(coinAddresses, _amounts, spender)];
|
|
360
367
|
case 1: return [2 /*return*/, _a.sent()];
|
|
361
368
|
}
|
|
362
369
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curvefi/api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "JavaScript library for curve.fi",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"axios": "^0.21.1",
|
|
25
25
|
"bignumber.js": "^9.0.1",
|
|
26
|
-
"ethers": "^5.
|
|
26
|
+
"ethers": "^5.4.6",
|
|
27
27
|
"ethers-multicall": "^0.1.6"
|
|
28
28
|
}
|
|
29
29
|
}
|