@curvefi/api 2.34.1 → 2.34.3
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/curve.js +1 -1
- package/lib/router.js +40 -26
- package/package.json +1 -1
package/lib/curve.js
CHANGED
|
@@ -390,7 +390,7 @@ var Curve = /** @class */ (function () {
|
|
|
390
390
|
case 0:
|
|
391
391
|
if (this.chainId === 1313161554)
|
|
392
392
|
return [2 /*return*/, []];
|
|
393
|
-
currentPoolIds = Object.keys(this.constants.FACTORY_POOLS_DATA);
|
|
393
|
+
currentPoolIds = Object.keys(this.constants.FACTORY_POOLS_DATA).filter(function (id) { return !id.includes('crvusd'); });
|
|
394
394
|
lastPoolIdx = Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
|
|
395
395
|
_a = lowerCasePoolDataAddresses;
|
|
396
396
|
return [4 /*yield*/, getFactoryPoolData.call(this, lastPoolIdx + 1)];
|
package/lib/router.js
CHANGED
|
@@ -424,9 +424,9 @@ var _estimateGasForDifferentRoutes = function (routes, inputCoinAddress, outputC
|
|
|
424
424
|
});
|
|
425
425
|
}); };
|
|
426
426
|
var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
427
|
-
var _a, inputCoinDecimals, outputCoinDecimals, _amount, routesRaw, routes, calls, multicallContract, _i, routesRaw_1, r, _b, _route, _swapParams, _factorySwapAddresses, _outputAmounts, i, err_2,
|
|
428
|
-
return __generator(this, function (
|
|
429
|
-
switch (
|
|
427
|
+
var _a, inputCoinDecimals, outputCoinDecimals, _amount, routesRaw, routes, calls, multicallContract, _i, routesRaw_1, r, _b, _route, _swapParams, _factorySwapAddresses, _outputAmounts, i, err_2, contract, _outputs, _c, routesRaw_2, r, _d, _route, _swapParams, _factorySwapAddresses, _e, _f, e_1, i, _h, gasAmounts, outputCoinUsdRate, gasData, ethUsdRate, gasPrice, expectedAmounts, expectedAmountsUsd, txCostsUsd;
|
|
428
|
+
return __generator(this, function (_j) {
|
|
429
|
+
switch (_j.label) {
|
|
430
430
|
case 0:
|
|
431
431
|
_a = _getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
|
|
432
432
|
_amount = parseUnits(amount, inputCoinDecimals);
|
|
@@ -434,11 +434,11 @@ var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
434
434
|
return [2 /*return*/, []];
|
|
435
435
|
return [4 /*yield*/, _findAllRoutes(inputCoinAddress, outputCoinAddress)];
|
|
436
436
|
case 1:
|
|
437
|
-
routesRaw = (
|
|
437
|
+
routesRaw = (_j.sent()).map(function (route) { return ({ route: route, _output: curve.parseUnits("0"), outputUsd: 0, txCostUsd: 0 }); });
|
|
438
438
|
routes = [];
|
|
439
|
-
|
|
439
|
+
_j.label = 2;
|
|
440
440
|
case 2:
|
|
441
|
-
|
|
441
|
+
_j.trys.push([2, 4, , 11]);
|
|
442
442
|
calls = [];
|
|
443
443
|
multicallContract = curve.contracts[curve.constants.ALIASES.registry_exchange].multicallContract;
|
|
444
444
|
for (_i = 0, routesRaw_1 = routesRaw; _i < routesRaw_1.length; _i++) {
|
|
@@ -448,34 +448,48 @@ var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
448
448
|
}
|
|
449
449
|
return [4 /*yield*/, curve.multicallProvider.all(calls)];
|
|
450
450
|
case 3:
|
|
451
|
-
_outputAmounts =
|
|
451
|
+
_outputAmounts = _j.sent();
|
|
452
452
|
for (i = 0; i < _outputAmounts.length; i++) {
|
|
453
453
|
routesRaw[i]._output = _outputAmounts[i];
|
|
454
454
|
routes.push(routesRaw[i]);
|
|
455
455
|
}
|
|
456
|
-
return [3 /*break*/,
|
|
456
|
+
return [3 /*break*/, 11];
|
|
457
457
|
case 4:
|
|
458
|
-
err_2 =
|
|
459
|
-
promises = [];
|
|
458
|
+
err_2 = _j.sent();
|
|
460
459
|
contract = curve.contracts[curve.constants.ALIASES.registry_exchange].contract;
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
promises.push(contract.get_exchange_multiple_amount(_route, _swapParams, _amount, _factorySwapAddresses, curve.constantOptions));
|
|
465
|
-
}
|
|
466
|
-
return [4 /*yield*/, Promise.allSettled(promises)];
|
|
460
|
+
_outputs = [];
|
|
461
|
+
_c = 0, routesRaw_2 = routesRaw;
|
|
462
|
+
_j.label = 5;
|
|
467
463
|
case 5:
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
464
|
+
if (!(_c < routesRaw_2.length)) return [3 /*break*/, 10];
|
|
465
|
+
r = routesRaw_2[_c];
|
|
466
|
+
_d = _getExchangeMultipleArgs(r.route), _route = _d._route, _swapParams = _d._swapParams, _factorySwapAddresses = _d._factorySwapAddresses;
|
|
467
|
+
_j.label = 6;
|
|
468
|
+
case 6:
|
|
469
|
+
_j.trys.push([6, 8, , 9]);
|
|
470
|
+
_f = (_e = _outputs).push;
|
|
471
|
+
return [4 /*yield*/, contract.get_exchange_multiple_amount(_route, _swapParams, _amount, _factorySwapAddresses, curve.constantOptions)];
|
|
472
|
+
case 7:
|
|
473
|
+
_f.apply(_e, [_j.sent()]);
|
|
474
|
+
return [3 /*break*/, 9];
|
|
475
|
+
case 8:
|
|
476
|
+
e_1 = _j.sent();
|
|
477
|
+
_outputs.push(curve.parseUnits('-1', 0));
|
|
478
|
+
return [3 /*break*/, 9];
|
|
479
|
+
case 9:
|
|
480
|
+
_c++;
|
|
481
|
+
return [3 /*break*/, 5];
|
|
482
|
+
case 10:
|
|
483
|
+
for (i = 0; i < _outputs.length; i++) {
|
|
484
|
+
if (_outputs[i] < 0) {
|
|
471
485
|
console.log("Route ".concat((routesRaw[i].route.map(function (s) { return s.poolId; })).join(" --> "), " is unavailable"));
|
|
472
486
|
continue;
|
|
473
487
|
}
|
|
474
|
-
routesRaw[i]._output =
|
|
488
|
+
routesRaw[i]._output = _outputs[i];
|
|
475
489
|
routes.push(routesRaw[i]);
|
|
476
490
|
}
|
|
477
|
-
return [3 /*break*/,
|
|
478
|
-
case
|
|
491
|
+
return [3 /*break*/, 11];
|
|
492
|
+
case 11:
|
|
479
493
|
if (routes.length === 0)
|
|
480
494
|
return [2 /*return*/, []];
|
|
481
495
|
if (routes.length === 1)
|
|
@@ -486,8 +500,8 @@ var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
486
500
|
axios.get("https://api.curve.fi/api/getGas"),
|
|
487
501
|
_getUsdRate(ETH_ADDRESS),
|
|
488
502
|
])];
|
|
489
|
-
case
|
|
490
|
-
|
|
503
|
+
case 12:
|
|
504
|
+
_h = _j.sent(), gasAmounts = _h[0], outputCoinUsdRate = _h[1], gasData = _h[2], ethUsdRate = _h[3];
|
|
491
505
|
gasPrice = gasData.data.data.gas.standard;
|
|
492
506
|
expectedAmounts = (routes).map(function (route) { return Number(curve.formatUnits(route._output, outputCoinDecimals)); });
|
|
493
507
|
expectedAmountsUsd = expectedAmounts.map(function (a) { return a * outputCoinUsdRate; });
|
|
@@ -553,7 +567,7 @@ export var swapExpected = function (inputCoin, outputCoin, amount) { return __aw
|
|
|
553
567
|
});
|
|
554
568
|
}); };
|
|
555
569
|
export var swapPriceImpact = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
556
|
-
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _c, route, output, _amount, _output, smallAmountIntBN, amountIntBN, contract, _smallAmount, _d, _route, _swapParams, _factorySwapAddresses, _smallOutput,
|
|
570
|
+
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _c, route, output, _amount, _output, smallAmountIntBN, amountIntBN, contract, _smallAmount, _d, _route, _swapParams, _factorySwapAddresses, _smallOutput, e_2, priceImpactBN;
|
|
557
571
|
return __generator(this, function (_e) {
|
|
558
572
|
switch (_e.label) {
|
|
559
573
|
case 0:
|
|
@@ -579,7 +593,7 @@ export var swapPriceImpact = function (inputCoin, outputCoin, amount) { return _
|
|
|
579
593
|
_smallOutput = _e.sent();
|
|
580
594
|
return [3 /*break*/, 6];
|
|
581
595
|
case 4:
|
|
582
|
-
|
|
596
|
+
e_2 = _e.sent();
|
|
583
597
|
_smallAmount = curve.parseUnits("1", inputCoinDecimals); // Dirty hack
|
|
584
598
|
return [4 /*yield*/, contract.get_exchange_multiple_amount(_route, _swapParams, _smallAmount, _factorySwapAddresses, curve.constantOptions)];
|
|
585
599
|
case 5:
|