@curvefi/api 2.57.3 → 2.57.5

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.
@@ -13,5 +13,5 @@ import { POOLS_DATA_CELO } from "./celo.js";
13
13
  import { POOLS_DATA_ZKSYNC } from "./zksync.js";
14
14
  import { POOLS_DATA_BASE } from "./base.js";
15
15
  import { POOLS_DATA_BSC } from "./bsc.js";
16
- import { POOLS_DATA_FRAXTAL } from "./fraxtal";
16
+ import { POOLS_DATA_FRAXTAL } from "./fraxtal.js";
17
17
  export { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, POOLS_DATA_ZKSYNC, POOLS_DATA_BASE, POOLS_DATA_BSC, POOLS_DATA_FRAXTAL, };
@@ -13,5 +13,5 @@ import { POOLS_DATA_CELO } from "./celo.js";
13
13
  import { POOLS_DATA_ZKSYNC } from "./zksync.js";
14
14
  import { POOLS_DATA_BASE } from "./base.js";
15
15
  import { POOLS_DATA_BSC } from "./bsc.js";
16
- import { POOLS_DATA_FRAXTAL } from "./fraxtal";
16
+ import { POOLS_DATA_FRAXTAL } from "./fraxtal.js";
17
17
  export { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, POOLS_DATA_ZKSYNC, POOLS_DATA_BASE, POOLS_DATA_BSC, POOLS_DATA_FRAXTAL, };
package/lib/curve.js CHANGED
@@ -110,7 +110,7 @@ import { COINS_FRAXTAL, cTokensFraxtal, yTokensFraxtal, ycTokensFraxtal, aTokens
110
110
  import { lowerCasePoolDataAddresses, extractDecimals, extractGauges } from "./constants/utils.js";
111
111
  import { _getAllGauges, _getHiddenPools } from "./external-api.js";
112
112
  import { L2Networks } from "./constants/L2Networks.js";
113
- import { getTwocryptoFactoryPoolData } from "./factory/factory-twocrypto";
113
+ import { getTwocryptoFactoryPoolData } from "./factory/factory-twocrypto.js";
114
114
  import { initContract, initMulticallContract } from "./utils.js";
115
115
  var _killGauges = function (poolsData) { return __awaiter(void 0, void 0, void 0, function () {
116
116
  var gaugeData, isKilled, gaugeStatuses, poolId;
package/lib/router.js CHANGED
@@ -95,15 +95,6 @@ var _handleSwapType = function (swapType) {
95
95
  return swapType.toString();
96
96
  };
97
97
  var SNX = {
98
- 1: {
99
- swap: "0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F".toLowerCase(),
100
- coins: [
101
- "0x57Ab1ec28D129707052df4dF418D58a2D46d5f51",
102
- "0xD71eCFF9342A5Ced620049e616c5035F1dB98620",
103
- "0x5e74C9036fb86BD7eCdcb084a0673EFc32eA31cb",
104
- "0xfE18be6b3Bd88A2D2A7f928d00292E7a9963CfC6", // sBTC
105
- ].map(function (a) { return a.toLowerCase(); }),
106
- },
107
98
  10: {
108
99
  swap: "0x8700dAec35aF8Ff88c16BdF0418774CB3D7599B4".toLowerCase(),
109
100
  coins: [
@@ -708,6 +699,14 @@ var _getOutputForRoute = memoize(function (route, _amount) { return __awaiter(vo
708
699
  promise: true,
709
700
  maxAge: 15 * 1000, // 15s
710
701
  });
702
+ var _routesCache = {};
703
+ var _getBestRouteAndOutput = function (inputCoin, outputCoin, amount) {
704
+ var _a = _getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
705
+ var key = "".concat(inputCoinAddress, "-").concat(outputCoinAddress, "-").concat(amount);
706
+ if (!(key in _routesCache))
707
+ throw Error("You must call getBestRouteAndOutput first");
708
+ return _routesCache[key];
709
+ };
711
710
  export var getBestRouteAndOutput = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
712
711
  var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, route, _output;
713
712
  return __generator(this, function (_c) {
@@ -723,6 +722,11 @@ export var getBestRouteAndOutput = function (inputCoin, outputCoin, amount) { re
723
722
  return [4 /*yield*/, _getOutputForRoute(route, parseUnits(amount, inputCoinDecimals))];
724
723
  case 2:
725
724
  _output = _c.sent();
725
+ _routesCache["".concat(inputCoinAddress, "-").concat(outputCoinAddress, "-").concat(amount)] = {
726
+ route: route,
727
+ output: curve.formatUnits(_output + BigInt(1), outputCoinDecimals),
728
+ timestamp: Date.now(),
729
+ };
726
730
  return [2 /*return*/, { route: route, output: curve.formatUnits(_output + BigInt(1), outputCoinDecimals) }];
727
731
  }
728
732
  });
@@ -779,9 +783,7 @@ export var swapPriceImpact = function (inputCoin, outputCoin, amount) { return _
779
783
  case 0:
780
784
  _a = _getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
781
785
  _b = _getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
782
- return [4 /*yield*/, getBestRouteAndOutput(inputCoinAddress, outputCoinAddress, amount)];
783
- case 1:
784
- _c = _e.sent(), route = _c.route, output = _c.output;
786
+ _c = _getBestRouteAndOutput(inputCoinAddress, outputCoinAddress, amount), route = _c.route, output = _c.output;
785
787
  _amount = parseUnits(amount, inputCoinDecimals);
786
788
  _output = parseUnits(output, outputCoinDecimals);
787
789
  smallAmountIntBN = _get_small_x(_amount, _output, inputCoinDecimals, outputCoinDecimals);
@@ -791,21 +793,21 @@ export var swapPriceImpact = function (inputCoin, outputCoin, amount) { return _
791
793
  contract = curve.contracts[curve.constants.ALIASES.router].contract;
792
794
  _smallAmount = fromBN(smallAmountIntBN.div(Math.pow(10, inputCoinDecimals)), inputCoinDecimals);
793
795
  _d = _getExchangeArgs(route), _route = _d._route, _swapParams = _d._swapParams, _pools = _d._pools;
794
- _e.label = 2;
795
- case 2:
796
- _e.trys.push([2, 4, , 6]);
796
+ _e.label = 1;
797
+ case 1:
798
+ _e.trys.push([1, 3, , 5]);
797
799
  return [4 /*yield*/, contract.get_dy(_route, _swapParams, _smallAmount, _pools, curve.constantOptions)];
798
- case 3:
800
+ case 2:
799
801
  _smallOutput = _e.sent();
800
- return [3 /*break*/, 6];
801
- case 4:
802
+ return [3 /*break*/, 5];
803
+ case 3:
802
804
  e_2 = _e.sent();
803
805
  _smallAmount = curve.parseUnits("1", inputCoinDecimals); // Dirty hack
804
806
  return [4 /*yield*/, contract.get_dy(_route, _swapParams, _smallAmount, _pools, curve.constantOptions)];
805
- case 5:
807
+ case 4:
806
808
  _smallOutput = _e.sent();
807
- return [3 /*break*/, 6];
808
- case 6:
809
+ return [3 /*break*/, 5];
810
+ case 5:
809
811
  priceImpactBN = _get_price_impact(_amount, _output, _smallAmount, _smallOutput, inputCoinDecimals, outputCoinDecimals);
810
812
  return [2 /*return*/, Number(_cutZeros(priceImpactBN.toFixed(4)))];
811
813
  }
@@ -842,14 +844,12 @@ export var swapEstimateGas = function (inputCoin, outputCoin, amount) { return _
842
844
  case 0:
843
845
  _a = _getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
844
846
  inputCoinDecimals = _getCoinDecimals(inputCoinAddress, outputCoinAddress)[0];
845
- return [4 /*yield*/, getBestRouteAndOutput(inputCoinAddress, outputCoinAddress, amount)];
846
- case 1:
847
- route = (_b.sent()).route;
847
+ route = _getBestRouteAndOutput(inputCoinAddress, outputCoinAddress, amount).route;
848
848
  if (route.length === 0)
849
849
  return [2 /*return*/, 0];
850
850
  _amount = parseUnits(amount, inputCoinDecimals);
851
851
  return [4 /*yield*/, _estimateGasForDifferentRoutes([route], inputCoinAddress, outputCoinAddress, _amount)];
852
- case 2:
852
+ case 1:
853
853
  gas = (_b.sent())[0];
854
854
  return [2 /*return*/, gas];
855
855
  }
@@ -867,9 +867,7 @@ export var swap = function (inputCoin, outputCoin, amount, slippage) {
867
867
  return [4 /*yield*/, swapApprove(inputCoin, amount)];
868
868
  case 1:
869
869
  _f.sent();
870
- return [4 /*yield*/, getBestRouteAndOutput(inputCoinAddress, outputCoinAddress, amount)];
871
- case 2:
872
- _c = _f.sent(), route = _c.route, output = _c.output;
870
+ _c = _getBestRouteAndOutput(inputCoinAddress, outputCoinAddress, amount), route = _c.route, output = _c.output;
873
871
  if (route.length === 0) {
874
872
  throw new Error("This pair can't be exchanged");
875
873
  }
@@ -880,14 +878,14 @@ export var swap = function (inputCoin, outputCoin, amount, slippage) {
880
878
  contract = curve.contracts[curve.constants.ALIASES.router].contract;
881
879
  value = isEth(inputCoinAddress) ? _amount : curve.parseUnits("0");
882
880
  return [4 /*yield*/, curve.updateFeeData()];
883
- case 3:
881
+ case 2:
884
882
  _f.sent();
885
883
  _e = DIGas;
886
884
  return [4 /*yield*/, contract.exchange.estimateGas(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve.constantOptions), { value: value }))];
887
- case 4:
885
+ case 3:
888
886
  gasLimit = (_e.apply(void 0, [_f.sent()])) * (curve.chainId === 1 ? curve.parseUnits("130", 0) : curve.parseUnits("160", 0)) / curve.parseUnits("100", 0);
889
887
  return [4 /*yield*/, contract.exchange(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
890
- case 5: return [2 /*return*/, _f.sent()];
888
+ case 4: return [2 /*return*/, _f.sent()];
891
889
  }
892
890
  });
893
891
  });
package/lib/utils.js CHANGED
@@ -1017,7 +1017,7 @@ var memoizedContract = function () {
1017
1017
  }
1018
1018
  };
1019
1019
  };
1020
- var memoizedulticallContract = function () {
1020
+ var memoizedMulticallContract = function () {
1021
1021
  var cache = {};
1022
1022
  return function (address, abi) {
1023
1023
  if (address in cache) {
@@ -1031,4 +1031,4 @@ var memoizedulticallContract = function () {
1031
1031
  };
1032
1032
  };
1033
1033
  export var initContract = memoizedContract();
1034
- export var initMulticallContract = memoizedulticallContract();
1034
+ export var initMulticallContract = memoizedMulticallContract();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.57.3",
3
+ "version": "2.57.5",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",