@curvefi/api 2.49.4 → 2.49.6

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 CHANGED
@@ -1482,13 +1482,19 @@ For L2 networks `estimateGas` return array `[L2GasUsed, L1GasUsed]`, where `L2Ga
1482
1482
  Gas Price in L1 is required to calculate the fee.
1483
1483
  You can use `getGasPriceFromL1` for get Gas Price in L1.
1484
1484
  ````ts
1485
- const L1GasPrice = await curve.L1GasPrice()
1486
- // 13161051
1485
+ const L1GasPrice = await curve.getGasPriceFromL1()
1486
+ // 23348207475
1487
1487
  ````
1488
1488
 
1489
1489
  **Calculate fee**
1490
1490
  `fee = L2GasUsed*L2GasPrice + L1GasUsed*L1GasPrice`
1491
1491
 
1492
+ For OP and Base networks you can get `L2GasPrice` from `curve.getGasPriceFromL2`
1493
+ ````ts
1494
+ const L2GasPrice = await curve.getGasPriceFromL2()
1495
+ // 13161051
1496
+ ````
1497
+
1492
1498
 
1493
1499
  ## Factory
1494
1500
 
package/lib/index.d.ts CHANGED
@@ -41,6 +41,7 @@ declare const curve: {
41
41
  getPool: (poolId: string) => PoolTemplate;
42
42
  getUsdRate: (coin: string) => Promise<number>;
43
43
  getGasPriceFromL1: () => Promise<number>;
44
+ getGasPriceFromL2: () => Promise<number>;
44
45
  getTVL: (network?: import("./interfaces.js").INetworkName | import("./interfaces.js").IChainId) => Promise<number>;
45
46
  getBalances: (coins: string[], ...addresses: string[] | string[][]) => Promise<string[] | import("./interfaces.js").IDict<string[]>>;
46
47
  getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
@@ -203,7 +204,7 @@ declare const curve: {
203
204
  getSwappedAmount: (tx: ethers.ContractTransactionResponse, outputCoin: string) => Promise<string>;
204
205
  estimateGas: {
205
206
  approve: (inputCoin: string, amount: string | number) => Promise<number | number[]>;
206
- swap: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<number>;
207
+ swap: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<number | number[]>;
207
208
  };
208
209
  };
209
210
  };
package/lib/index.js CHANGED
@@ -39,7 +39,7 @@ import { getUserPoolListByLiquidity, getUserPoolListByClaimable, getUserPoolList
39
39
  import { getBestRouteAndOutput, getArgs, swapExpected, swapRequired, swapPriceImpact, swapIsApproved, swapApproveEstimateGas, swapApprove, swapEstimateGas, swap, getSwappedAmount, } from "./router.js";
40
40
  import { curve as _curve } from "./curve.js";
41
41
  import { getCrv, getLockedAmountAndUnlockTime, getVeCrv, getVeCrvPct, calcUnlockTime, createLockEstimateGas, createLock, isApproved, approveEstimateGas, approve, increaseAmountEstimateGas, increaseAmount, increaseUnlockTimeEstimateGas, increaseUnlockTime, withdrawLockedCrvEstimateGas, withdrawLockedCrv, claimableFees, claimFeesEstimateGas, claimFees, lastEthBlock, getAnycallBalance, topUpAnycall, topUpAnycallEstimateGas, lastBlockSent, blockToSend, sendBlockhash, sendBlockhashEstimateGas, submitProof, submitProofEstimateGas, } from "./boosting.js";
42
- import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getGasPriceFromL1, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, } from "./utils.js";
42
+ import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getGasPriceFromL1, getGasPriceFromL2, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, } from "./utils.js";
43
43
  import { deployStablePlainPool, deployStablePlainPoolEstimateGas, getDeployedStablePlainPoolAddress, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, getDeployedStableMetaPoolAddress, deployCryptoPool, deployCryptoPoolEstimateGas, getDeployedCryptoPoolAddress, deployTricryptoPool, deployTricryptoPoolEstimateGas, getDeployedTricryptoPoolAddress, deployGauge, deployGaugeEstimateGas, getDeployedGaugeAddress, deployGaugeSidechain, deployGaugeSidechainEstimateGas, deployGaugeMirror, deployGaugeMirrorEstimateGas, getDeployedGaugeMirrorAddress, getDeployedGaugeMirrorAddressByTx, } from './factory/deploy.js';
44
44
  function init(providerType, providerSettings, options) {
45
45
  if (options === void 0) { options = {}; }
@@ -77,6 +77,7 @@ var curve = {
77
77
  getPool: getPool,
78
78
  getUsdRate: getUsdRate,
79
79
  getGasPriceFromL1: getGasPriceFromL1,
80
+ getGasPriceFromL2: getGasPriceFromL2,
80
81
  getTVL: getTVL,
81
82
  getBalances: getBalances,
82
83
  getAllowance: getAllowance,
package/lib/router.d.ts CHANGED
@@ -19,6 +19,6 @@ export declare const swapPriceImpact: (inputCoin: string, outputCoin: string, am
19
19
  export declare const swapIsApproved: (inputCoin: string, amount: number | string) => Promise<boolean>;
20
20
  export declare const swapApproveEstimateGas: (inputCoin: string, amount: number | string) => Promise<number | number[]>;
21
21
  export declare const swapApprove: (inputCoin: string, amount: number | string) => Promise<string[]>;
22
- export declare const swapEstimateGas: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<number>;
22
+ export declare const swapEstimateGas: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<number | number[]>;
23
23
  export declare const swap: (inputCoin: string, outputCoin: string, amount: number | string, slippage?: number) => Promise<ethers.ContractTransactionResponse>;
24
24
  export declare const getSwappedAmount: (tx: ethers.ContractTransactionResponse, outputCoin: string) => Promise<string>;
package/lib/router.js CHANGED
@@ -58,9 +58,10 @@ import axios from "axios";
58
58
  import memoize from "memoizee";
59
59
  import { ethers } from "ethers";
60
60
  import { curve } from "./curve.js";
61
- import { _getCoinAddresses, _getCoinDecimals, _getUsdRate, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, BN, parseUnits, _cutZeros, ETH_ADDRESS, _get_small_x, _get_price_impact, DIGas, } from "./utils.js";
61
+ import { _getCoinAddresses, _getCoinDecimals, _getUsdRate, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, BN, parseUnits, _cutZeros, ETH_ADDRESS, _get_small_x, _get_price_impact, DIGas, smartNumber, getTxCostsUsd, getGasPriceFromL1, } from "./utils.js";
62
62
  import { getPool } from "./pools/index.js";
63
63
  import { _getAmplificationCoefficientsFromApi } from "./pools/utils.js";
64
+ import { L2Networks } from "./constants/L2Networks.js";
64
65
  var MAX_STEPS = 5;
65
66
  var ROUTE_LENGTH = (MAX_STEPS * 2) + 1;
66
67
  var GRAPH_MAX_EDGES = 3;
@@ -568,7 +569,7 @@ var _estimateGasForDifferentRoutes = function (routes, inputCoinAddress, outputC
568
569
  var routeKey = _getRouteKey(route, inputCoinAddress, outputCoinAddress);
569
570
  _estimatedGasForDifferentRoutesCache[routeKey] = { 'gas': _gasAmounts_1[i], 'time': Date.now() };
570
571
  });
571
- return [2 /*return*/, _gasAmounts_1.map(function (_g) { return Number(curve.formatUnits(DIGas(_g), 0)); })];
572
+ return [2 /*return*/, _gasAmounts_1.map(function (_g) { return smartNumber(_g); })];
572
573
  case 3:
573
574
  err_1 = _c.sent();
574
575
  return [2 /*return*/, routes.map(function () { return 0; })];
@@ -577,9 +578,9 @@ var _estimateGasForDifferentRoutes = function (routes, inputCoinAddress, outputC
577
578
  });
578
579
  }); };
579
580
  var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
580
- var _a, inputCoinDecimals, outputCoinDecimals, _amount, routesRaw, routes, calls, multicallContract, _i, routesRaw_1, r, _b, _route, _swapParams, _pools, _outputAmounts, i, err_2, contract, _outputs, _c, routesRaw_2, r, _d, _route, _swapParams, _pools, _e, _f, e_1, i, _h, gasAmounts, outputCoinUsdRate, gasData, ethUsdRate, gasPrice, expectedAmounts, expectedAmountsUsd, txCostsUsd;
581
- return __generator(this, function (_j) {
582
- switch (_j.label) {
581
+ var _a, inputCoinDecimals, outputCoinDecimals, _amount, routesRaw, routes, calls, multicallContract, _i, routesRaw_1, r, _b, _route, _swapParams, _pools, _outputAmounts, i, err_2, contract, _outputs, _c, routesRaw_2, r, _d, _route, _swapParams, _pools, _e, _f, e_1, i, _h, gasAmounts, outputCoinUsdRate, gasData, ethUsdRate, gasPrice, expectedAmounts, expectedAmountsUsd, L1GasPrice, _j, txCostsUsd;
582
+ return __generator(this, function (_k) {
583
+ switch (_k.label) {
583
584
  case 0:
584
585
  _a = _getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
585
586
  _amount = parseUnits(amount, inputCoinDecimals);
@@ -587,11 +588,11 @@ var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amoun
587
588
  return [2 /*return*/, []];
588
589
  return [4 /*yield*/, _findRoutes(inputCoinAddress, outputCoinAddress)];
589
590
  case 1:
590
- routesRaw = (_j.sent()).map(function (route) { return ({ route: route, _output: curve.parseUnits("0"), outputUsd: 0, txCostUsd: 0 }); });
591
+ routesRaw = (_k.sent()).map(function (route) { return ({ route: route, _output: curve.parseUnits("0"), outputUsd: 0, txCostUsd: 0 }); });
591
592
  routes = [];
592
- _j.label = 2;
593
+ _k.label = 2;
593
594
  case 2:
594
- _j.trys.push([2, 4, , 11]);
595
+ _k.trys.push([2, 4, , 11]);
595
596
  calls = [];
596
597
  multicallContract = curve.contracts[curve.constants.ALIASES.router].multicallContract;
597
598
  for (_i = 0, routesRaw_1 = routesRaw; _i < routesRaw_1.length; _i++) {
@@ -601,32 +602,32 @@ var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amoun
601
602
  }
602
603
  return [4 /*yield*/, curve.multicallProvider.all(calls)];
603
604
  case 3:
604
- _outputAmounts = _j.sent();
605
+ _outputAmounts = _k.sent();
605
606
  for (i = 0; i < _outputAmounts.length; i++) {
606
607
  routesRaw[i]._output = _outputAmounts[i];
607
608
  routes.push(routesRaw[i]);
608
609
  }
609
610
  return [3 /*break*/, 11];
610
611
  case 4:
611
- err_2 = _j.sent();
612
+ err_2 = _k.sent();
612
613
  contract = curve.contracts[curve.constants.ALIASES.router].contract;
613
614
  _outputs = [];
614
615
  _c = 0, routesRaw_2 = routesRaw;
615
- _j.label = 5;
616
+ _k.label = 5;
616
617
  case 5:
617
618
  if (!(_c < routesRaw_2.length)) return [3 /*break*/, 10];
618
619
  r = routesRaw_2[_c];
619
620
  _d = _getExchangeArgs(r.route), _route = _d._route, _swapParams = _d._swapParams, _pools = _d._pools;
620
- _j.label = 6;
621
+ _k.label = 6;
621
622
  case 6:
622
- _j.trys.push([6, 8, , 9]);
623
+ _k.trys.push([6, 8, , 9]);
623
624
  _f = (_e = _outputs).push;
624
625
  return [4 /*yield*/, contract.get_dy(_route, _swapParams, _amount, _pools, curve.constantOptions)];
625
626
  case 7:
626
- _f.apply(_e, [_j.sent()]);
627
+ _f.apply(_e, [_k.sent()]);
627
628
  return [3 /*break*/, 9];
628
629
  case 8:
629
- e_1 = _j.sent();
630
+ e_1 = _k.sent();
630
631
  _outputs.push(curve.parseUnits('-1', 0));
631
632
  return [3 /*break*/, 9];
632
633
  case 9:
@@ -654,11 +655,21 @@ var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amoun
654
655
  _getUsdRate(ETH_ADDRESS),
655
656
  ])];
656
657
  case 12:
657
- _h = _j.sent(), gasAmounts = _h[0], outputCoinUsdRate = _h[1], gasData = _h[2], ethUsdRate = _h[3];
658
+ _h = _k.sent(), gasAmounts = _h[0], outputCoinUsdRate = _h[1], gasData = _h[2], ethUsdRate = _h[3];
658
659
  gasPrice = gasData.data.data.gas.standard;
659
660
  expectedAmounts = (routes).map(function (route) { return Number(curve.formatUnits(route._output, outputCoinDecimals)); });
660
661
  expectedAmountsUsd = expectedAmounts.map(function (a) { return a * outputCoinUsdRate; });
661
- txCostsUsd = gasAmounts.map(function (a) { return ethUsdRate * a * gasPrice / 1e18; });
662
+ if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 14];
663
+ return [4 /*yield*/, getGasPriceFromL1()];
664
+ case 13:
665
+ _j = _k.sent();
666
+ return [3 /*break*/, 15];
667
+ case 14:
668
+ _j = 0;
669
+ _k.label = 15;
670
+ case 15:
671
+ L1GasPrice = _j;
672
+ txCostsUsd = gasAmounts.map(function (a) { return getTxCostsUsd(ethUsdRate, gasPrice, a, L1GasPrice); });
662
673
  routes.forEach(function (route, i) {
663
674
  route.outputUsd = expectedAmountsUsd[i];
664
675
  route.txCostUsd = txCostsUsd[i];
package/lib/utils.d.ts CHANGED
@@ -36,6 +36,8 @@ export declare const _getRewardsFromApi: () => Promise<IDict<IRewardFromApi[]>>;
36
36
  export declare const _getUsdRate: (assetId: string) => Promise<number>;
37
37
  export declare const getUsdRate: (coin: string) => Promise<number>;
38
38
  export declare const getGasPriceFromL1: () => Promise<number>;
39
+ export declare const getGasPriceFromL2: () => Promise<number>;
40
+ export declare const getTxCostsUsd: (ethUsdRate: number, gasPrice: number, gas: number | number[], gasPriceL1?: number) => number;
39
41
  export declare const getTVL: (network?: INetworkName | IChainId) => Promise<number>;
40
42
  export declare const getVolume: (network?: INetworkName | IChainId) => Promise<{
41
43
  totalVolume: number;
package/lib/utils.js CHANGED
@@ -683,16 +683,42 @@ export var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void
683
683
  });
684
684
  }); };
685
685
  export var getGasPriceFromL1 = function () { return __awaiter(void 0, void 0, void 0, function () {
686
+ var gasPrice;
687
+ return __generator(this, function (_a) {
688
+ switch (_a.label) {
689
+ case 0:
690
+ if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 2];
691
+ return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.gas_oracle].contract.l1BaseFee()];
692
+ case 1:
693
+ gasPrice = _a.sent();
694
+ return [2 /*return*/, Number(gasPrice) + 1e9]; // + 1 gwei
695
+ case 2: throw Error("This method exists only for L2 networks");
696
+ }
697
+ });
698
+ }); };
699
+ export var getGasPriceFromL2 = function () { return __awaiter(void 0, void 0, void 0, function () {
700
+ var gasPrice;
686
701
  return __generator(this, function (_a) {
687
702
  switch (_a.label) {
688
703
  case 0:
689
704
  if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 2];
690
705
  return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.gas_oracle].contract.gasPrice()];
691
- case 1: return [2 /*return*/, _a.sent()];
706
+ case 1:
707
+ gasPrice = _a.sent();
708
+ return [2 /*return*/, Number(gasPrice)];
692
709
  case 2: throw Error("This method exists only for L2 networks");
693
710
  }
694
711
  });
695
712
  }); };
713
+ export var getTxCostsUsd = function (ethUsdRate, gasPrice, gas, gasPriceL1) {
714
+ if (gasPriceL1 === void 0) { gasPriceL1 = 0; }
715
+ if (Array.isArray(gas)) {
716
+ return ethUsdRate * ((gas[0] * gasPrice / 1e18) + (gas[1] * gasPriceL1 / 1e18));
717
+ }
718
+ else {
719
+ return ethUsdRate * gas * gasPrice / 1e18;
720
+ }
721
+ };
696
722
  var _getNetworkName = function (network) {
697
723
  if (network === void 0) { network = curve.chainId; }
698
724
  if (typeof network === "number" && NETWORK_CONSTANTS[network]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.49.4",
3
+ "version": "2.49.6",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",