@curvefi/api 2.23.0 → 2.24.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/router.js CHANGED
@@ -319,16 +319,16 @@ var sortByLength = function (a, b) { return a.steps.length - b.steps.length || b
319
319
  var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
320
320
  var ALL_POOLS, amplificationCoefficientDict, curCoins, nextCoins, routesByTvl, routesByLength, step, _loop_1, _i, curCoins_2, inCoin, routes;
321
321
  var _a, _b;
322
- var _c, _d, _e, _f, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
323
- return __generator(this, function (_t) {
324
- switch (_t.label) {
322
+ var _c, _d, _e, _f, _h, _j, _k, _l, _m, _o, _p, _q, _r;
323
+ return __generator(this, function (_s) {
324
+ switch (_s.label) {
325
325
  case 0:
326
326
  inputCoinAddress = inputCoinAddress.toLowerCase();
327
327
  outputCoinAddress = outputCoinAddress.toLowerCase();
328
328
  ALL_POOLS = Object.entries(__assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA));
329
329
  return [4 /*yield*/, (0, utils_2._getAmplificationCoefficientsFromApi)()];
330
330
  case 1:
331
- amplificationCoefficientDict = _t.sent();
331
+ amplificationCoefficientDict = _s.sent();
332
332
  curCoins = [inputCoinAddress];
333
333
  nextCoins = new Set();
334
334
  routesByTvl = (_a = {},
@@ -338,15 +338,15 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
338
338
  _b[inputCoinAddress] = [{ steps: [], minTvl: Infinity, totalTvl: 0 }],
339
339
  _b);
340
340
  step = 0;
341
- _t.label = 2;
341
+ _s.label = 2;
342
342
  case 2:
343
343
  if (!(step < 4)) return [3 /*break*/, 8];
344
344
  _loop_1 = function (inCoin) {
345
- var outCoin_1, newRoutesByTvl, newRoutesByLength, _loop_2, _u, ALL_POOLS_3, _v, poolId, poolData;
346
- return __generator(this, function (_w) {
347
- switch (_w.label) {
345
+ var outCoin_1, newRoutesByTvl, newRoutesByLength, _loop_2, _t, ALL_POOLS_3, _u, poolId, poolData;
346
+ return __generator(this, function (_v) {
347
+ switch (_v.label) {
348
348
  case 0:
349
- if ([curve_1.curve.constants.NATIVE_TOKEN.address, curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress].includes(inCoin)) {
349
+ if (curve_1.curve.chainId !== 42220 && [curve_1.curve.constants.NATIVE_TOKEN.address, curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress].includes(inCoin)) { // Exclude Celo
350
350
  outCoin_1 = inCoin === curve_1.curve.constants.NATIVE_TOKEN.address ? curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress : curve_1.curve.constants.NATIVE_TOKEN.address;
351
351
  newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, "wrapper", curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress, inCoin, outCoin_1, 0, 0, 15, ethers_1.ethers.constants.AddressZero, Infinity); });
352
352
  newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, "wrapper", curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress, inCoin, outCoin_1, 0, 0, 15, ethers_1.ethers.constants.AddressZero, Infinity); });
@@ -357,17 +357,17 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
357
357
  nextCoins.add(outCoin_1);
358
358
  }
359
359
  _loop_2 = function (poolId, poolData) {
360
- var wrapped_coin_addresses, underlying_coin_addresses, base_pool, meta_coin_addresses, token_address, is_lending, tvlMultiplier, inCoinIndexes, tvl, _x, poolAddress, coin_addresses, _loop_3, j, inCoinIndex, swapType_1, newRoutesByTvl, newRoutesByLength, _loop_4, j, _loop_5, j;
361
- return __generator(this, function (_y) {
362
- switch (_y.label) {
360
+ var wrapped_coin_addresses, underlying_coin_addresses, base_pool, meta_coin_addresses, token_address, is_aave_like_lending, tvlMultiplier, inCoinIndexes, tvl, _w, poolAddress, coin_addresses, _loop_3, j, inCoinIndex, swapType_1, newRoutesByTvl, newRoutesByLength, _loop_4, j, _loop_5, j;
361
+ return __generator(this, function (_x) {
362
+ switch (_x.label) {
363
363
  case 0:
364
364
  wrapped_coin_addresses = poolData.wrapped_coin_addresses.map(function (a) { return a.toLowerCase(); });
365
365
  underlying_coin_addresses = poolData.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
366
366
  base_pool = poolData.is_meta ? curve_1.curve.constants.POOLS_DATA[poolData.base_pool] : null;
367
367
  meta_coin_addresses = base_pool ? base_pool.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); }) : [];
368
368
  token_address = poolData.token_address.toLowerCase();
369
- is_lending = (_e = poolData.is_lending) !== null && _e !== void 0 ? _e : false;
370
- tvlMultiplier = poolData.is_crypto ? 1 : ((_f = amplificationCoefficientDict[poolData.swap_address]) !== null && _f !== void 0 ? _f : 1);
369
+ is_aave_like_lending = poolData.is_lending && wrapped_coin_addresses.length === 3 && !poolData.deposit_address;
370
+ tvlMultiplier = poolData.is_crypto ? 1 : ((_e = amplificationCoefficientDict[poolData.swap_address]) !== null && _e !== void 0 ? _e : 1);
371
371
  inCoinIndexes = {
372
372
  wrapped_coin: wrapped_coin_addresses.indexOf(inCoin),
373
373
  underlying_coin: underlying_coin_addresses.indexOf(inCoin),
@@ -376,15 +376,15 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
376
376
  // Skip pools which don't contain inCoin
377
377
  if (inCoinIndexes.wrapped_coin === -1 && inCoinIndexes.underlying_coin === -1 && inCoinIndexes.meta_coin === -1 && inCoin !== token_address)
378
378
  return [2 /*return*/, "continue"];
379
- _x = Number;
379
+ _w = Number;
380
380
  return [4 /*yield*/, ((0, pools_1.getPool)(poolId)).stats.totalLiquidity()];
381
381
  case 1:
382
- tvl = _x.apply(void 0, [_y.sent()]) * tvlMultiplier;
382
+ tvl = _w.apply(void 0, [_x.sent()]) * tvlMultiplier;
383
383
  // Skip empty pools
384
384
  if (tvl === 0)
385
385
  return [2 /*return*/, "continue"];
386
386
  poolAddress = poolData.is_fake ? poolData.deposit_address : poolData.swap_address;
387
- coin_addresses = (is_lending || poolData.is_fake) ? underlying_coin_addresses : wrapped_coin_addresses;
387
+ coin_addresses = (is_aave_like_lending || poolData.is_fake) ? underlying_coin_addresses : wrapped_coin_addresses;
388
388
  // LP -> wrapped coin (underlying for lending or fake pool) "swaps" (actually remove_liquidity_one_coin)
389
389
  if (coin_addresses.length < 6 && inCoin === token_address) {
390
390
  _loop_3 = function (j) {
@@ -395,12 +395,12 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
395
395
  var outputCoinIdx = coin_addresses.indexOf(outputCoinAddress);
396
396
  if (outputCoinIdx >= 0 && j !== outputCoinIdx)
397
397
  return "continue";
398
- var swapType = poolData.is_crypto ? 14 : is_lending ? 13 : 12;
398
+ var swapType = poolData.is_crypto ? 14 : is_aave_like_lending ? 13 : 12;
399
399
  var newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, coin_addresses[j], 0, j, swapType, ethers_1.ethers.constants.AddressZero, tvl); });
400
400
  var newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, coin_addresses[j], 0, j, swapType, ethers_1.ethers.constants.AddressZero, tvl); });
401
- routesByTvl[coin_addresses[j]] = __spreadArray(__spreadArray([], ((_h = routesByTvl[coin_addresses[j]]) !== null && _h !== void 0 ? _h : []), true), newRoutesByTvl, true);
401
+ routesByTvl[coin_addresses[j]] = __spreadArray(__spreadArray([], ((_f = routesByTvl[coin_addresses[j]]) !== null && _f !== void 0 ? _f : []), true), newRoutesByTvl, true);
402
402
  routesByTvl[coin_addresses[j]] = filterRoutes(routesByTvl[coin_addresses[j]], inputCoinAddress, sortByTvl);
403
- routesByLength[coin_addresses[j]] = __spreadArray(__spreadArray([], ((_j = routesByLength[coin_addresses[j]]) !== null && _j !== void 0 ? _j : []), true), newRoutesByLength, true);
403
+ routesByLength[coin_addresses[j]] = __spreadArray(__spreadArray([], ((_h = routesByLength[coin_addresses[j]]) !== null && _h !== void 0 ? _h : []), true), newRoutesByLength, true);
404
404
  routesByLength[coin_addresses[j]] = filterRoutes(routesByLength[coin_addresses[j]], inputCoinAddress, sortByLength);
405
405
  nextCoins.add(coin_addresses[j]);
406
406
  };
@@ -408,19 +408,19 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
408
408
  _loop_3(j);
409
409
  }
410
410
  }
411
- inCoinIndex = (is_lending || poolData.is_fake) ? inCoinIndexes.underlying_coin : inCoinIndexes.wrapped_coin;
411
+ inCoinIndex = (is_aave_like_lending || poolData.is_fake) ? inCoinIndexes.underlying_coin : inCoinIndexes.wrapped_coin;
412
412
  if (coin_addresses.length < 6 && inCoinIndex >= 0) {
413
413
  // Looking for outputCoinAddress only on the final step
414
414
  if (!(step === 3 && token_address !== outputCoinAddress)) {
415
- swapType_1 = is_lending ? 9
415
+ swapType_1 = is_aave_like_lending ? 9
416
416
  : coin_addresses.length === 2 ? 7
417
417
  : coin_addresses.length === 3 ? 8
418
418
  : coin_addresses.length === 4 ? 10 : 11;
419
419
  newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, token_address, coin_addresses.indexOf(inCoin), 0, swapType_1, ethers_1.ethers.constants.AddressZero, tvl); });
420
420
  newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, token_address, coin_addresses.indexOf(inCoin), 0, swapType_1, ethers_1.ethers.constants.AddressZero, tvl); });
421
- routesByTvl[token_address] = __spreadArray(__spreadArray([], ((_k = routesByTvl[token_address]) !== null && _k !== void 0 ? _k : []), true), newRoutesByTvl, true);
421
+ routesByTvl[token_address] = __spreadArray(__spreadArray([], ((_j = routesByTvl[token_address]) !== null && _j !== void 0 ? _j : []), true), newRoutesByTvl, true);
422
422
  routesByTvl[token_address] = filterRoutes(routesByTvl[token_address], inputCoinAddress, sortByTvl);
423
- routesByLength[token_address] = __spreadArray(__spreadArray([], ((_l = routesByLength[token_address]) !== null && _l !== void 0 ? _l : []), true), newRoutesByLength, true);
423
+ routesByLength[token_address] = __spreadArray(__spreadArray([], ((_k = routesByLength[token_address]) !== null && _k !== void 0 ? _k : []), true), newRoutesByLength, true);
424
424
  routesByLength[token_address] = filterRoutes(routesByLength[token_address], inputCoinAddress, sortByLength);
425
425
  nextCoins.add(token_address);
426
426
  }
@@ -443,9 +443,9 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
443
443
  var swapType = poolData.is_crypto ? 3 : 1;
444
444
  var newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolData.swap_address, inCoin, wrapped_coin_addresses[j], inCoinIndexes.wrapped_coin, j, swapType, ethers_1.ethers.constants.AddressZero, tvl); });
445
445
  var newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, poolId, poolData.swap_address, inCoin, wrapped_coin_addresses[j], inCoinIndexes.wrapped_coin, j, swapType, ethers_1.ethers.constants.AddressZero, tvl); });
446
- routesByTvl[wrapped_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_m = routesByTvl[wrapped_coin_addresses[j]]) !== null && _m !== void 0 ? _m : []), true), newRoutesByTvl, true);
446
+ routesByTvl[wrapped_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_l = routesByTvl[wrapped_coin_addresses[j]]) !== null && _l !== void 0 ? _l : []), true), newRoutesByTvl, true);
447
447
  routesByTvl[wrapped_coin_addresses[j]] = filterRoutes(routesByTvl[wrapped_coin_addresses[j]], inputCoinAddress, sortByTvl);
448
- routesByLength[wrapped_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_o = routesByLength[wrapped_coin_addresses[j]]) !== null && _o !== void 0 ? _o : []), true), newRoutesByLength, true);
448
+ routesByLength[wrapped_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_m = routesByLength[wrapped_coin_addresses[j]]) !== null && _m !== void 0 ? _m : []), true), newRoutesByLength, true);
449
449
  routesByLength[wrapped_coin_addresses[j]] = filterRoutes(routesByLength[wrapped_coin_addresses[j]], inputCoinAddress, sortByLength);
450
450
  nextCoins.add(wrapped_coin_addresses[j]);
451
451
  };
@@ -458,9 +458,9 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
458
458
  poolData.deposit_address : poolData.swap_address;
459
459
  if (!(!poolData.is_plain && inCoinIndexes.underlying_coin >= 0)) return [3 /*break*/, 5];
460
460
  _loop_5 = function (j) {
461
- var outputCoinIdx, tvl_1, _z, hasEth, swapType, newRoutesByTvl, newRoutesByLength;
462
- return __generator(this, function (_0) {
463
- switch (_0.label) {
461
+ var outputCoinIdx, tvl_1, _y, hasEth, swapType, newRoutesByTvl, newRoutesByLength;
462
+ return __generator(this, function (_z) {
463
+ switch (_z.label) {
464
464
  case 0:
465
465
  if (j === inCoinIndexes.underlying_coin)
466
466
  return [2 /*return*/, "continue"];
@@ -473,10 +473,10 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
473
473
  outputCoinIdx = underlying_coin_addresses.indexOf(outputCoinAddress);
474
474
  if (outputCoinIdx >= 0 && j !== outputCoinIdx)
475
475
  return [2 /*return*/, "continue"];
476
- _z = Number;
476
+ _y = Number;
477
477
  return [4 /*yield*/, ((0, pools_1.getPool)(poolId)).stats.totalLiquidity()];
478
478
  case 1:
479
- tvl_1 = _z.apply(void 0, [_0.sent()]);
479
+ tvl_1 = _y.apply(void 0, [_z.sent()]);
480
480
  if (tvl_1 === 0)
481
481
  return [2 /*return*/, "continue"];
482
482
  hasEth = (inCoin === curve_1.curve.constants.NATIVE_TOKEN.address || underlying_coin_addresses[j] === curve_1.curve.constants.NATIVE_TOKEN.address);
@@ -487,9 +487,9 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
487
487
  : 2;
488
488
  newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, underlying_coin_addresses[j], inCoinIndexes.underlying_coin, j, swapType, (swapType === 5 || swapType === 6) ? poolData.swap_address : ethers_1.ethers.constants.AddressZero, tvl_1); });
489
489
  newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, underlying_coin_addresses[j], inCoinIndexes.underlying_coin, j, swapType, (swapType === 5 || swapType === 6) ? poolData.swap_address : ethers_1.ethers.constants.AddressZero, tvl_1); });
490
- routesByTvl[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_p = routesByTvl[underlying_coin_addresses[j]]) !== null && _p !== void 0 ? _p : []), true), newRoutesByTvl, true);
490
+ routesByTvl[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_o = routesByTvl[underlying_coin_addresses[j]]) !== null && _o !== void 0 ? _o : []), true), newRoutesByTvl, true);
491
491
  routesByTvl[underlying_coin_addresses[j]] = filterRoutes(routesByTvl[underlying_coin_addresses[j]], inputCoinAddress, sortByTvl);
492
- routesByLength[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_q = routesByLength[underlying_coin_addresses[j]]) !== null && _q !== void 0 ? _q : []), true), newRoutesByLength, true);
492
+ routesByLength[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_p = routesByLength[underlying_coin_addresses[j]]) !== null && _p !== void 0 ? _p : []), true), newRoutesByLength, true);
493
493
  routesByLength[underlying_coin_addresses[j]] = filterRoutes(routesByLength[underlying_coin_addresses[j]], inputCoinAddress, sortByLength);
494
494
  nextCoins.add(underlying_coin_addresses[j]);
495
495
  return [2 /*return*/];
@@ -497,13 +497,13 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
497
497
  });
498
498
  };
499
499
  j = 0;
500
- _y.label = 2;
500
+ _x.label = 2;
501
501
  case 2:
502
502
  if (!(j < underlying_coin_addresses.length)) return [3 /*break*/, 5];
503
503
  return [5 /*yield**/, _loop_5(j)];
504
504
  case 3:
505
- _y.sent();
506
- _y.label = 4;
505
+ _x.sent();
506
+ _x.label = 4;
507
507
  case 4:
508
508
  j++;
509
509
  return [3 /*break*/, 2];
@@ -511,43 +511,43 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
511
511
  }
512
512
  });
513
513
  };
514
- _u = 0, ALL_POOLS_3 = ALL_POOLS;
515
- _w.label = 1;
514
+ _t = 0, ALL_POOLS_3 = ALL_POOLS;
515
+ _v.label = 1;
516
516
  case 1:
517
- if (!(_u < ALL_POOLS_3.length)) return [3 /*break*/, 4];
518
- _v = ALL_POOLS_3[_u], poolId = _v[0], poolData = _v[1];
517
+ if (!(_t < ALL_POOLS_3.length)) return [3 /*break*/, 4];
518
+ _u = ALL_POOLS_3[_t], poolId = _u[0], poolData = _u[1];
519
519
  return [5 /*yield**/, _loop_2(poolId, poolData)];
520
520
  case 2:
521
- _w.sent();
522
- _w.label = 3;
521
+ _v.sent();
522
+ _v.label = 3;
523
523
  case 3:
524
- _u++;
524
+ _t++;
525
525
  return [3 /*break*/, 1];
526
526
  case 4: return [2 /*return*/];
527
527
  }
528
528
  });
529
529
  };
530
530
  _i = 0, curCoins_2 = curCoins;
531
- _t.label = 3;
531
+ _s.label = 3;
532
532
  case 3:
533
533
  if (!(_i < curCoins_2.length)) return [3 /*break*/, 6];
534
534
  inCoin = curCoins_2[_i];
535
535
  return [5 /*yield**/, _loop_1(inCoin)];
536
536
  case 4:
537
- _t.sent();
538
- _t.label = 5;
537
+ _s.sent();
538
+ _s.label = 5;
539
539
  case 5:
540
540
  _i++;
541
541
  return [3 /*break*/, 3];
542
542
  case 6:
543
543
  curCoins = Array.from(nextCoins);
544
544
  nextCoins = new Set();
545
- _t.label = 7;
545
+ _s.label = 7;
546
546
  case 7:
547
547
  step++;
548
548
  return [3 /*break*/, 2];
549
549
  case 8:
550
- routes = __spreadArray(__spreadArray([], ((_r = routesByTvl[outputCoinAddress]) !== null && _r !== void 0 ? _r : []), true), ((_s = routesByLength[outputCoinAddress]) !== null && _s !== void 0 ? _s : []), true);
550
+ routes = __spreadArray(__spreadArray([], ((_q = routesByTvl[outputCoinAddress]) !== null && _q !== void 0 ? _q : []), true), ((_r = routesByLength[outputCoinAddress]) !== null && _r !== void 0 ? _r : []), true);
551
551
  return [2 /*return*/, routes.map(function (r) { return r.steps; })];
552
552
  }
553
553
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.23.0",
3
+ "version": "2.24.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",