@curvefi/api 2.58.5 → 2.58.7

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/index.d.ts CHANGED
@@ -43,7 +43,8 @@ declare const curve: {
43
43
  getUsdRate: (coin: string) => Promise<number>;
44
44
  getGasPriceFromL1: () => Promise<number>;
45
45
  getGasPriceFromL2: () => Promise<number>;
46
- getGasInfoForL2: () => Promise<Record<string, number>>;
46
+ getGasInfoForL2: () => Promise<Record<string, number | null>>;
47
+ getGasPriceByLastTransactions: () => Promise<number>;
47
48
  getTVL: (network?: import("./interfaces.js").INetworkName | import("./interfaces.js").IChainId) => Promise<number>;
48
49
  getBalances: (coins: string[], ...addresses: string[] | string[][]) => Promise<string[] | import("./interfaces.js").IDict<string[]>>;
49
50
  getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
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, getGasPriceFromL2, getGasInfoForL2, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, getBasePools, } from "./utils.js";
42
+ import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getGasPriceFromL1, getGasPriceFromL2, getGasInfoForL2, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, getBasePools, getGasPriceByLastTransactions, } 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, deployStableNgPlainPool, deployStableNgPlainPoolEstimateGas, deployStableNgMetaPool, deployStableNgMetaPoolEstimateGas, deployTwocryptoPool, deployTwocryptoPoolEstimateGas, getDeployedTwocryptoPoolAddress, } from './factory/deploy.js';
44
44
  import { crvSupplyStats, userCrv, userVeCrv, crvLockIsApproved, crvLockApproveEstimateGas, crvLockApprove, calcCrvUnlockTime, createCrvLockEstimateGas, createCrvLock, increaseCrvLockedAmountEstimateGas, increaseCrvLockedAmount, increaseCrvUnlockTimeEstimateGas, increaseCrvUnlockTime, withdrawLockedCrvEstimateGas as daoWithdrawLockedCrvEstimateGas, withdrawLockedCrv as daoWithdrawLockedCrv, claimableFees as daoClaimableFees, claimFeesEstimateGas as daoClaimFeesEstimateGas, claimFees as daoClaimFees, getVotingGaugeList, userGaugeVotes, voteForGaugeNextTime, voteForGaugeEstimateGas, voteForGauge, getProposalList, getProposal, userProposalVotes, voteForProposalEstimateGas, voteForProposal, } from "./dao.js";
45
45
  function init(providerType, providerSettings, options) {
@@ -81,6 +81,7 @@ var curve = {
81
81
  getGasPriceFromL1: getGasPriceFromL1,
82
82
  getGasPriceFromL2: getGasPriceFromL2,
83
83
  getGasInfoForL2: getGasInfoForL2,
84
+ getGasPriceByLastTransactions: getGasPriceByLastTransactions,
84
85
  getTVL: getTVL,
85
86
  getBalances: getBalances,
86
87
  getAllowance: getAllowance,
package/lib/utils.d.ts CHANGED
@@ -39,9 +39,10 @@ export declare const _getRewardsFromApi: () => Promise<IDict<IRewardFromApi[]>>;
39
39
  export declare const _getUsdRate: (assetId: string) => Promise<number>;
40
40
  export declare const getUsdRate: (coin: string) => Promise<number>;
41
41
  export declare const getBaseFeeByLastBlock: () => Promise<number>;
42
+ export declare const getGasPriceByLastTransactions: () => Promise<number>;
42
43
  export declare const getGasPriceFromL1: () => Promise<number>;
43
44
  export declare const getGasPriceFromL2: () => Promise<number>;
44
- export declare const getGasInfoForL2: () => Promise<Record<string, number>>;
45
+ export declare const getGasInfoForL2: () => Promise<Record<string, number | null>>;
45
46
  export declare const getTxCostsUsd: (ethUsdRate: number, gasPrice: number, gas: number | number[], gasPriceL1?: number) => number;
46
47
  export declare const getTVL: (network?: INetworkName | IChainId) => Promise<number>;
47
48
  export declare const getVolumeApiController: (network: INetworkName) => Promise<IVolumeAndAPYs>;
package/lib/utils.js CHANGED
@@ -729,6 +729,52 @@ export var getBaseFeeByLastBlock = function () { return __awaiter(void 0, void 0
729
729
  }
730
730
  });
731
731
  }); };
732
+ export var getGasPriceByLastTransactions = function () { return __awaiter(void 0, void 0, void 0, function () {
733
+ var provider, latestBlockNumber, totalGasPrice, transactionsCount, txAmount, i, block, _i, _a, txHash, tx;
734
+ return __generator(this, function (_b) {
735
+ switch (_b.label) {
736
+ case 0:
737
+ provider = curve.provider;
738
+ return [4 /*yield*/, provider.getBlockNumber()];
739
+ case 1:
740
+ latestBlockNumber = _b.sent();
741
+ totalGasPrice = 0;
742
+ transactionsCount = 0;
743
+ txAmount = 15;
744
+ i = latestBlockNumber;
745
+ _b.label = 2;
746
+ case 2:
747
+ if (!(i > latestBlockNumber - txAmount && i >= 0)) return [3 /*break*/, 8];
748
+ return [4 /*yield*/, provider.getBlock(i)];
749
+ case 3:
750
+ block = _b.sent();
751
+ if (!block)
752
+ return [3 /*break*/, 7];
753
+ _i = 0, _a = block.transactions;
754
+ _b.label = 4;
755
+ case 4:
756
+ if (!(_i < _a.length)) return [3 /*break*/, 7];
757
+ txHash = _a[_i];
758
+ return [4 /*yield*/, provider.getTransaction(txHash)];
759
+ case 5:
760
+ tx = _b.sent();
761
+ if (!tx)
762
+ return [3 /*break*/, 6];
763
+ totalGasPrice = totalGasPrice + Number(tx.gasPrice);
764
+ transactionsCount++;
765
+ if (transactionsCount >= txAmount)
766
+ return [3 /*break*/, 7]; // Limit to txAmount transactions
767
+ _b.label = 6;
768
+ case 6:
769
+ _i++;
770
+ return [3 /*break*/, 4];
771
+ case 7:
772
+ i--;
773
+ return [3 /*break*/, 2];
774
+ case 8: return [2 /*return*/, Number((totalGasPrice / transactionsCount / 1e9).toFixed(2))];
775
+ }
776
+ });
777
+ }); };
732
778
  export var getGasPriceFromL1 = function () { return __awaiter(void 0, void 0, void 0, function () {
733
779
  return __generator(this, function (_a) {
734
780
  if (L2Networks.includes(curve.chainId) && curve.L1WeightedGasPrice) {
@@ -749,17 +795,21 @@ export var getGasPriceFromL2 = function () { return __awaiter(void 0, void 0, vo
749
795
  return [4 /*yield*/, getBaseFeeByLastBlock()];
750
796
  case 1: return [2 /*return*/, _a.sent()];
751
797
  case 2:
752
- if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 4];
798
+ if (!(curve.chainId === 196)) return [3 /*break*/, 4];
799
+ return [4 /*yield*/, getGasPriceByLastTransactions()]; // gwei
800
+ case 3: return [2 /*return*/, _a.sent()]; // gwei
801
+ case 4:
802
+ if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 6];
753
803
  return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.gas_oracle_blob].contract.gasPrice({ "gasPrice": "0x2000000" })];
754
- case 3:
804
+ case 5:
755
805
  gasPrice = _a.sent();
756
806
  return [2 /*return*/, Number(gasPrice)];
757
- case 4: throw Error("This method exists only for L2 networks");
807
+ case 6: throw Error("This method exists only for L2 networks");
758
808
  }
759
809
  });
760
810
  }); };
761
811
  export var getGasInfoForL2 = function () { return __awaiter(void 0, void 0, void 0, function () {
762
- var baseFee;
812
+ var baseFee, gasPrice;
763
813
  return __generator(this, function (_a) {
764
814
  switch (_a.label) {
765
815
  case 0:
@@ -771,7 +821,17 @@ export var getGasInfoForL2 = function () { return __awaiter(void 0, void 0, void
771
821
  maxFeePerGas: Number(((baseFee * 1.1) + 0.01).toFixed(2)),
772
822
  maxPriorityFeePerGas: 0.01,
773
823
  }];
774
- case 2: throw Error("This method exists only for L2 networks");
824
+ case 2:
825
+ if (!(curve.chainId === 196)) return [3 /*break*/, 4];
826
+ return [4 /*yield*/, getGasPriceByLastTransactions()];
827
+ case 3:
828
+ gasPrice = _a.sent();
829
+ return [2 /*return*/, {
830
+ gasPrice: gasPrice,
831
+ maxFeePerGas: null,
832
+ maxPriorityFeePerGas: null,
833
+ }];
834
+ case 4: throw Error("This method exists only for L2 networks");
775
835
  }
776
836
  });
777
837
  }); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.58.5",
3
+ "version": "2.58.7",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",