@curvefi/api 2.48.1 → 2.49.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/README.md +21 -0
- package/lib/boosting.js +61 -53
- package/lib/constants/L2Networks.d.ts +1 -0
- package/lib/constants/L2Networks.js +1 -0
- package/lib/constants/abis/gas_oracle_optimism.json +1 -0
- package/lib/constants/aliases.js +1 -0
- package/lib/curve.js +36 -4
- package/lib/external-api.d.ts +2 -0
- package/lib/factory/deploy.js +15 -15
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/lib/interfaces.d.ts +1 -0
- package/lib/pools/PoolTemplate.d.ts +1 -0
- package/lib/pools/PoolTemplate.js +2 -1
- package/lib/pools/mixins/depositMixins.js +11 -11
- package/lib/pools/mixins/depositWrappedMixins.js +5 -5
- package/lib/pools/mixins/swapMixins.js +9 -9
- package/lib/pools/mixins/swapWrappedMixins.js +6 -6
- package/lib/pools/mixins/withdrawImbalanceMixins.js +9 -9
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +5 -5
- package/lib/pools/mixins/withdrawMixins.js +11 -11
- package/lib/pools/mixins/withdrawOneCoinMixins.js +11 -11
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +5 -5
- package/lib/pools/mixins/withdrawWrappedMixins.js +5 -5
- package/lib/router.js +11 -10
- package/lib/utils.d.ts +3 -0
- package/lib/utils.js +58 -26
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -61,6 +61,7 @@ import BigNumber from 'bignumber.js';
|
|
|
61
61
|
import { curve, NETWORK_CONSTANTS } from "./curve.js";
|
|
62
62
|
import { _getFactoryAPYsAndVolumes, _getLegacyAPYsAndVolumes, _getAllPoolsFromApi, _getSubgraphData } from "./external-api.js";
|
|
63
63
|
import ERC20Abi from './constants/abis/ERC20.json' assert { type: 'json' };
|
|
64
|
+
import { L2Networks } from './constants/L2Networks';
|
|
64
65
|
export var ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
65
66
|
// export const MAX_ALLOWANCE = curve.parseUnits(new BigNumber(2).pow(256).minus(1).toFixed(), 0);
|
|
66
67
|
export var MAX_ALLOWANCE = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935"); // 2**256 - 1
|
|
@@ -102,6 +103,22 @@ export var fromBN = function (bn, decimals) {
|
|
|
102
103
|
export var isEth = function (address) { return address.toLowerCase() === ETH_ADDRESS.toLowerCase(); };
|
|
103
104
|
export var getEthIndex = function (addresses) { return addresses.map(function (address) { return address.toLowerCase(); }).indexOf(ETH_ADDRESS.toLowerCase()); };
|
|
104
105
|
export var mulBy1_3 = function (n) { return n * curve.parseUnits("130", 0) / curve.parseUnits("100", 0); };
|
|
106
|
+
export var smartNumber = function (abstractNumber) {
|
|
107
|
+
if (Array.isArray(abstractNumber)) {
|
|
108
|
+
return [Number(abstractNumber[0]), Number(abstractNumber[1])];
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return Number(abstractNumber);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
export var DIGas = function (gas) {
|
|
115
|
+
if (Array.isArray(gas)) {
|
|
116
|
+
return gas[0];
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return gas;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
105
122
|
// coins can be either addresses or symbols
|
|
106
123
|
export var _getCoinAddressesNoCheck = function () {
|
|
107
124
|
var coins = [];
|
|
@@ -281,17 +298,17 @@ export var hasAllowance = function (coins, amounts, address, spender) { return _
|
|
|
281
298
|
export var _ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
282
299
|
if (isMax === void 0) { isMax = true; }
|
|
283
300
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
284
|
-
var address, allowance, txHashes, i, contract, _approveAmount, gasLimit_1, _a, _b, _c,
|
|
285
|
-
return __generator(this, function (
|
|
286
|
-
switch (
|
|
301
|
+
var address, allowance, txHashes, i, contract, _approveAmount, gasLimit_1, _a, _b, _c, _d, gasLimit, _e, _f, _g, _h;
|
|
302
|
+
return __generator(this, function (_j) {
|
|
303
|
+
switch (_j.label) {
|
|
287
304
|
case 0:
|
|
288
305
|
address = curve.signerAddress;
|
|
289
306
|
return [4 /*yield*/, _getAllowance(coins, address, spender)];
|
|
290
307
|
case 1:
|
|
291
|
-
allowance =
|
|
308
|
+
allowance = _j.sent();
|
|
292
309
|
txHashes = [];
|
|
293
310
|
i = 0;
|
|
294
|
-
|
|
311
|
+
_j.label = 2;
|
|
295
312
|
case 2:
|
|
296
313
|
if (!(i < allowance.length)) return [3 /*break*/, 10];
|
|
297
314
|
if (!(allowance[i] < amounts[i])) return [3 /*break*/, 9];
|
|
@@ -299,27 +316,29 @@ export var _ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
|
299
316
|
_approveAmount = isMax ? MAX_ALLOWANCE : amounts[i];
|
|
300
317
|
return [4 /*yield*/, curve.updateFeeData()];
|
|
301
318
|
case 3:
|
|
302
|
-
|
|
319
|
+
_j.sent();
|
|
303
320
|
if (!(allowance[i] > curve.parseUnits("0"))) return [3 /*break*/, 6];
|
|
304
321
|
_a = mulBy1_3;
|
|
322
|
+
_b = DIGas;
|
|
305
323
|
return [4 /*yield*/, contract.approve.estimateGas(spender, curve.parseUnits("0"), curve.constantOptions)];
|
|
306
324
|
case 4:
|
|
307
|
-
gasLimit_1 = _a.apply(void 0, [
|
|
308
|
-
|
|
325
|
+
gasLimit_1 = _a.apply(void 0, [_b.apply(void 0, [_j.sent()])]);
|
|
326
|
+
_d = (_c = txHashes).push;
|
|
309
327
|
return [4 /*yield*/, contract.approve(spender, curve.parseUnits("0"), __assign(__assign({}, curve.options), { gasLimit: gasLimit_1 }))];
|
|
310
328
|
case 5:
|
|
311
|
-
|
|
312
|
-
|
|
329
|
+
_d.apply(_c, [(_j.sent()).hash]);
|
|
330
|
+
_j.label = 6;
|
|
313
331
|
case 6:
|
|
314
|
-
|
|
332
|
+
_e = mulBy1_3;
|
|
333
|
+
_f = DIGas;
|
|
315
334
|
return [4 /*yield*/, contract.approve.estimateGas(spender, _approveAmount, curve.constantOptions)];
|
|
316
335
|
case 7:
|
|
317
|
-
gasLimit =
|
|
318
|
-
|
|
336
|
+
gasLimit = _e.apply(void 0, [_f.apply(void 0, [_j.sent()])]);
|
|
337
|
+
_h = (_g = txHashes).push;
|
|
319
338
|
return [4 /*yield*/, contract.approve(spender, _approveAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
320
339
|
case 8:
|
|
321
|
-
|
|
322
|
-
|
|
340
|
+
_h.apply(_g, [(_j.sent()).hash]);
|
|
341
|
+
_j.label = 9;
|
|
323
342
|
case 9:
|
|
324
343
|
i++;
|
|
325
344
|
return [3 /*break*/, 2];
|
|
@@ -332,9 +351,9 @@ export var _ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
|
332
351
|
export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax) {
|
|
333
352
|
if (isMax === void 0) { isMax = true; }
|
|
334
353
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
335
|
-
var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _approveAmount, _a, _b, _c, _d;
|
|
336
|
-
return __generator(this, function (
|
|
337
|
-
switch (
|
|
354
|
+
var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _approveAmount, _a, _b, _c, _d, _e, _f;
|
|
355
|
+
return __generator(this, function (_g) {
|
|
356
|
+
switch (_g.label) {
|
|
338
357
|
case 0:
|
|
339
358
|
coinAddresses = _getCoinAddresses(coins);
|
|
340
359
|
decimals = _getCoinDecimals(coinAddresses);
|
|
@@ -342,10 +361,10 @@ export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax
|
|
|
342
361
|
address = curve.signerAddress;
|
|
343
362
|
return [4 /*yield*/, _getAllowance(coinAddresses, address, spender)];
|
|
344
363
|
case 1:
|
|
345
|
-
allowance =
|
|
364
|
+
allowance = _g.sent();
|
|
346
365
|
gas = 0;
|
|
347
366
|
i = 0;
|
|
348
|
-
|
|
367
|
+
_g.label = 2;
|
|
349
368
|
case 2:
|
|
350
369
|
if (!(i < allowance.length)) return [3 /*break*/, 7];
|
|
351
370
|
if (!(allowance[i] < _amounts[i])) return [3 /*break*/, 6];
|
|
@@ -354,17 +373,19 @@ export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax
|
|
|
354
373
|
if (!(allowance[i] > curve.parseUnits("0"))) return [3 /*break*/, 4];
|
|
355
374
|
_a = gas;
|
|
356
375
|
_b = Number;
|
|
376
|
+
_c = DIGas;
|
|
357
377
|
return [4 /*yield*/, contract.approve.estimateGas(spender, curve.parseUnits("0"), curve.constantOptions)];
|
|
358
378
|
case 3:
|
|
359
|
-
gas = _a + _b.apply(void 0, [
|
|
360
|
-
|
|
379
|
+
gas = _a + _b.apply(void 0, [_c.apply(void 0, [_g.sent()])]);
|
|
380
|
+
_g.label = 4;
|
|
361
381
|
case 4:
|
|
362
|
-
|
|
363
|
-
|
|
382
|
+
_d = gas;
|
|
383
|
+
_e = Number;
|
|
384
|
+
_f = DIGas;
|
|
364
385
|
return [4 /*yield*/, contract.approve.estimateGas(spender, _approveAmount, curve.constantOptions)];
|
|
365
386
|
case 5:
|
|
366
|
-
gas =
|
|
367
|
-
|
|
387
|
+
gas = _d + _e.apply(void 0, [_f.apply(void 0, [_g.sent()])]);
|
|
388
|
+
_g.label = 6;
|
|
368
389
|
case 6:
|
|
369
390
|
i++;
|
|
370
391
|
return [3 /*break*/, 2];
|
|
@@ -645,6 +666,17 @@ export var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void
|
|
|
645
666
|
}
|
|
646
667
|
});
|
|
647
668
|
}); };
|
|
669
|
+
export var getGasPriceFromL1 = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
670
|
+
return __generator(this, function (_a) {
|
|
671
|
+
switch (_a.label) {
|
|
672
|
+
case 0:
|
|
673
|
+
if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 2];
|
|
674
|
+
return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.gas_oracle].contract.gasPrice()];
|
|
675
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
676
|
+
case 2: throw Error("This method exists only for L2 networks");
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
}); };
|
|
648
680
|
var _getNetworkName = function (network) {
|
|
649
681
|
if (network === void 0) { network = curve.chainId; }
|
|
650
682
|
if (typeof network === "number" && NETWORK_CONSTANTS[network]) {
|