@curvefi/api 2.58.5 → 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 +2 -1
- package/lib/index.js +2 -1
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +66 -5
- package/package.json +1 -1
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,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 (!
|
|
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
|
|
805
|
+
case 5:
|
|
755
806
|
gasPrice = _a.sent();
|
|
756
807
|
return [2 /*return*/, Number(gasPrice)];
|
|
757
|
-
case
|
|
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:
|
|
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
|
}); };
|