@curvefi/api 2.58.4 → 2.58.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/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,
@@ -1843,13 +1843,16 @@ var PoolTemplate = /** @class */ (function () {
1843
1843
  if (this.rewardsOnly())
1844
1844
  throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimRewards instead"));
1845
1845
  contract = curve.chainId === 1 ? curve.contracts[curve.constants.ALIASES.minter].contract : curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
1846
+ return [4 /*yield*/, curve.updateFeeData()];
1847
+ case 1:
1848
+ _e.sent();
1846
1849
  _c = mulBy1_3;
1847
1850
  _d = DIGas;
1848
1851
  return [4 /*yield*/, contract.mint.estimateGas(this.gauge, curve.constantOptions)];
1849
- case 1:
1852
+ case 2:
1850
1853
  gasLimit = _c.apply(void 0, [_d.apply(void 0, [_e.sent()])]);
1851
1854
  return [4 /*yield*/, contract.mint(this.gauge, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
1852
- case 2: return [2 /*return*/, (_e.sent()).hash];
1855
+ case 3: return [2 /*return*/, (_e.sent()).hash];
1853
1856
  }
1854
1857
  });
1855
1858
  });
@@ -1943,13 +1946,16 @@ var PoolTemplate = /** @class */ (function () {
1943
1946
  gaugeContract = curve.contracts[this.gauge].contract;
1944
1947
  if (!("claim_rewards()" in gaugeContract))
1945
1948
  throw Error("".concat(this.name, " pool doesn't have such method"));
1949
+ return [4 /*yield*/, curve.updateFeeData()];
1950
+ case 1:
1951
+ _e.sent();
1946
1952
  _c = mulBy1_3;
1947
1953
  _d = DIGas;
1948
1954
  return [4 /*yield*/, gaugeContract.claim_rewards.estimateGas(curve.constantOptions)];
1949
- case 1:
1955
+ case 2:
1950
1956
  gasLimit = _c.apply(void 0, [_d.apply(void 0, [_e.sent()])]);
1951
1957
  return [4 /*yield*/, gaugeContract.claim_rewards(__assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
1952
- case 2: return [2 /*return*/, (_e.sent()).hash];
1958
+ case 3: return [2 /*return*/, (_e.sent()).hash];
1953
1959
  }
1954
1960
  });
1955
1961
  });
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,53 @@ 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
+ console.log(tx, tx === null || tx === void 0 ? void 0 : tx.gasPrice);
762
+ if (!tx)
763
+ return [3 /*break*/, 6];
764
+ totalGasPrice = totalGasPrice + Number(tx.gasPrice);
765
+ transactionsCount++;
766
+ if (transactionsCount >= txAmount)
767
+ return [3 /*break*/, 7]; // Limit to txAmount transactions
768
+ _b.label = 6;
769
+ case 6:
770
+ _i++;
771
+ return [3 /*break*/, 4];
772
+ case 7:
773
+ i--;
774
+ return [3 /*break*/, 2];
775
+ case 8: return [2 /*return*/, Number((totalGasPrice / transactionsCount / 1e9).toFixed(2))];
776
+ }
777
+ });
778
+ }); };
732
779
  export var getGasPriceFromL1 = function () { return __awaiter(void 0, void 0, void 0, function () {
733
780
  return __generator(this, function (_a) {
734
781
  if (L2Networks.includes(curve.chainId) && curve.L1WeightedGasPrice) {
@@ -749,17 +796,21 @@ export var getGasPriceFromL2 = function () { return __awaiter(void 0, void 0, vo
749
796
  return [4 /*yield*/, getBaseFeeByLastBlock()];
750
797
  case 1: return [2 /*return*/, _a.sent()];
751
798
  case 2:
752
- if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 4];
799
+ if (!(curve.chainId === 196)) return [3 /*break*/, 4];
800
+ return [4 /*yield*/, getGasPriceByLastTransactions()]; // gwei
801
+ case 3: return [2 /*return*/, _a.sent()]; // gwei
802
+ case 4:
803
+ if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 6];
753
804
  return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.gas_oracle_blob].contract.gasPrice({ "gasPrice": "0x2000000" })];
754
- case 3:
805
+ case 5:
755
806
  gasPrice = _a.sent();
756
807
  return [2 /*return*/, Number(gasPrice)];
757
- case 4: throw Error("This method exists only for L2 networks");
808
+ case 6: throw Error("This method exists only for L2 networks");
758
809
  }
759
810
  });
760
811
  }); };
761
812
  export var getGasInfoForL2 = function () { return __awaiter(void 0, void 0, void 0, function () {
762
- var baseFee;
813
+ var baseFee, gasPrice;
763
814
  return __generator(this, function (_a) {
764
815
  switch (_a.label) {
765
816
  case 0:
@@ -771,7 +822,17 @@ export var getGasInfoForL2 = function () { return __awaiter(void 0, void 0, void
771
822
  maxFeePerGas: Number(((baseFee * 1.1) + 0.01).toFixed(2)),
772
823
  maxPriorityFeePerGas: 0.01,
773
824
  }];
774
- case 2: throw Error("This method exists only for L2 networks");
825
+ case 2:
826
+ if (!(curve.chainId === 196)) return [3 /*break*/, 4];
827
+ return [4 /*yield*/, getGasPriceByLastTransactions()];
828
+ case 3:
829
+ gasPrice = _a.sent();
830
+ return [2 /*return*/, {
831
+ gasPrice: gasPrice,
832
+ maxFeePerGas: null,
833
+ maxPriorityFeePerGas: null,
834
+ }];
835
+ case 4: throw Error("This method exists only for L2 networks");
775
836
  }
776
837
  });
777
838
  }); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.58.4",
3
+ "version": "2.58.6",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",