@curvefi/api 2.58.7 → 2.58.9
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/curve.js +38 -32
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +10 -45
- package/package.json +2 -2
package/lib/curve.js
CHANGED
|
@@ -112,7 +112,7 @@ import { lowerCasePoolDataAddresses, extractDecimals, extractGauges } from "./co
|
|
|
112
112
|
import { _getAllGauges, _getHiddenPools } from "./external-api.js";
|
|
113
113
|
import { L2Networks } from "./constants/L2Networks.js";
|
|
114
114
|
import { getTwocryptoFactoryPoolData } from "./factory/factory-twocrypto.js";
|
|
115
|
-
import { memoizedContract, memoizedMulticallContract } from "./utils.js";
|
|
115
|
+
import { getGasInfoForL2, memoizedContract, memoizedMulticallContract } from "./utils.js";
|
|
116
116
|
var _killGauges = function (poolsData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
117
117
|
var gaugeData, isKilled, gaugeStatuses, poolId;
|
|
118
118
|
return __generator(this, function (_a) {
|
|
@@ -903,9 +903,9 @@ var Curve = /** @class */ (function () {
|
|
|
903
903
|
var _a;
|
|
904
904
|
if (options === void 0) { options = {}; }
|
|
905
905
|
return __awaiter(this, void 0, void 0, function () {
|
|
906
|
-
var jsonRpcApiProviderOptions, _b, e_1, _c, network, poolId, _d, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _e, err_1, _i,
|
|
907
|
-
return __generator(this, function (
|
|
908
|
-
switch (
|
|
906
|
+
var jsonRpcApiProviderOptions, _b, e_1, _c, network, poolId, _d, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _e, err_1, _f, _i, _g, pool, _h, _j, coinAddr, _k, _l, coinAddr, _m, _o, coinAddr, _gaugeFactoryABI, factoryContract, _p, curveInstance_1, originalEstimate_1, oldEstimate, newEstimate;
|
|
907
|
+
return __generator(this, function (_q) {
|
|
908
|
+
switch (_q.label) {
|
|
909
909
|
case 0:
|
|
910
910
|
// @ts-ignore
|
|
911
911
|
this.provider = null;
|
|
@@ -960,16 +960,16 @@ var Curve = /** @class */ (function () {
|
|
|
960
960
|
return [3 /*break*/, 5];
|
|
961
961
|
case 1:
|
|
962
962
|
if (!!((_a = providerSettings.url) === null || _a === void 0 ? void 0 : _a.startsWith("https://rpc.gnosischain.com"))) return [3 /*break*/, 5];
|
|
963
|
-
|
|
963
|
+
_q.label = 2;
|
|
964
964
|
case 2:
|
|
965
|
-
|
|
965
|
+
_q.trys.push([2, 4, , 5]);
|
|
966
966
|
_b = this;
|
|
967
967
|
return [4 /*yield*/, this.provider.getSigner()];
|
|
968
968
|
case 3:
|
|
969
|
-
_b.signer =
|
|
969
|
+
_b.signer = _q.sent();
|
|
970
970
|
return [3 /*break*/, 5];
|
|
971
971
|
case 4:
|
|
972
|
-
e_1 =
|
|
972
|
+
e_1 = _q.sent();
|
|
973
973
|
this.signer = null;
|
|
974
974
|
return [3 /*break*/, 5];
|
|
975
975
|
case 5: return [3 /*break*/, 9];
|
|
@@ -980,7 +980,7 @@ var Curve = /** @class */ (function () {
|
|
|
980
980
|
_c = this;
|
|
981
981
|
return [4 /*yield*/, this.provider.getSigner()];
|
|
982
982
|
case 7:
|
|
983
|
-
_c.signer =
|
|
983
|
+
_c.signer = _q.sent();
|
|
984
984
|
return [3 /*break*/, 9];
|
|
985
985
|
case 8:
|
|
986
986
|
if (providerType.toLowerCase() === 'Infura'.toLowerCase()) {
|
|
@@ -997,10 +997,10 @@ var Curve = /** @class */ (function () {
|
|
|
997
997
|
else {
|
|
998
998
|
throw Error('Wrong providerType');
|
|
999
999
|
}
|
|
1000
|
-
|
|
1000
|
+
_q.label = 9;
|
|
1001
1001
|
case 9: return [4 /*yield*/, this.provider.getNetwork()];
|
|
1002
1002
|
case 10:
|
|
1003
|
-
network =
|
|
1003
|
+
network = _q.sent();
|
|
1004
1004
|
console.log("CURVE-JS IS CONNECTED TO NETWORK:", { name: network.name.toUpperCase(), chainId: Number(network.chainId) });
|
|
1005
1005
|
this.chainId = Number(network.chainId) === 133 || Number(network.chainId) === 31337 ? 1 : Number(network.chainId);
|
|
1006
1006
|
this.constants.NATIVE_TOKEN = NATIVE_TOKENS[this.chainId];
|
|
@@ -1027,29 +1027,35 @@ var Curve = /** @class */ (function () {
|
|
|
1027
1027
|
customAbiTokens = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], cTokens, true), yTokens, true), ycTokens, true), aTokens, true);
|
|
1028
1028
|
this.multicallProvider = new MulticallProvider(this.chainId, this.provider);
|
|
1029
1029
|
if (!this.signer) return [3 /*break*/, 15];
|
|
1030
|
-
|
|
1030
|
+
_q.label = 11;
|
|
1031
1031
|
case 11:
|
|
1032
|
-
|
|
1032
|
+
_q.trys.push([11, 13, , 14]);
|
|
1033
1033
|
_e = this;
|
|
1034
1034
|
return [4 /*yield*/, this.signer.getAddress()];
|
|
1035
1035
|
case 12:
|
|
1036
|
-
_e.signerAddress =
|
|
1036
|
+
_e.signerAddress = _q.sent();
|
|
1037
1037
|
return [3 /*break*/, 14];
|
|
1038
1038
|
case 13:
|
|
1039
|
-
err_1 =
|
|
1039
|
+
err_1 = _q.sent();
|
|
1040
1040
|
this.signer = null;
|
|
1041
1041
|
return [3 /*break*/, 14];
|
|
1042
1042
|
case 14: return [3 /*break*/, 16];
|
|
1043
1043
|
case 15:
|
|
1044
1044
|
this.signerAddress = '';
|
|
1045
|
-
|
|
1045
|
+
_q.label = 16;
|
|
1046
1046
|
case 16:
|
|
1047
1047
|
this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
|
|
1048
|
-
return [
|
|
1048
|
+
if (!(this.chainId === 196)) return [3 /*break*/, 18];
|
|
1049
|
+
_f = this.setCustomFeeData;
|
|
1050
|
+
return [4 /*yield*/, getGasInfoForL2()];
|
|
1049
1051
|
case 17:
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1052
|
+
_f.apply(this, [_q.sent()]);
|
|
1053
|
+
_q.label = 18;
|
|
1054
|
+
case 18: return [4 /*yield*/, this.updateFeeData()];
|
|
1055
|
+
case 19:
|
|
1056
|
+
_q.sent();
|
|
1057
|
+
for (_i = 0, _g = Object.values(__assign(__assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA)); _i < _g.length; _i++) {
|
|
1058
|
+
pool = _g[_i];
|
|
1053
1059
|
this.setContract(pool.swap_address, pool.swap_abi);
|
|
1054
1060
|
if (pool.token_address !== pool.swap_address) {
|
|
1055
1061
|
this.setContract(pool.token_address, ERC20Abi);
|
|
@@ -1060,12 +1066,12 @@ var Curve = /** @class */ (function () {
|
|
|
1060
1066
|
if (pool.deposit_address && !this.contracts[pool.deposit_address]) {
|
|
1061
1067
|
this.setContract(pool.deposit_address, pool.deposit_abi);
|
|
1062
1068
|
}
|
|
1063
|
-
for (
|
|
1064
|
-
coinAddr = _h
|
|
1069
|
+
for (_h = 0, _j = pool.underlying_coin_addresses; _h < _j.length; _h++) {
|
|
1070
|
+
coinAddr = _j[_h];
|
|
1065
1071
|
this.setContract(coinAddr, ERC20Abi);
|
|
1066
1072
|
}
|
|
1067
|
-
for (
|
|
1068
|
-
coinAddr = _k
|
|
1073
|
+
for (_k = 0, _l = pool.wrapped_coin_addresses; _k < _l.length; _k++) {
|
|
1074
|
+
coinAddr = _l[_k];
|
|
1069
1075
|
if (customAbiTokens.includes(coinAddr))
|
|
1070
1076
|
continue;
|
|
1071
1077
|
if (coinAddr in this.contracts)
|
|
@@ -1073,8 +1079,8 @@ var Curve = /** @class */ (function () {
|
|
|
1073
1079
|
this.setContract(coinAddr, ERC20Abi);
|
|
1074
1080
|
}
|
|
1075
1081
|
// TODO add all coins
|
|
1076
|
-
for (
|
|
1077
|
-
coinAddr = _m
|
|
1082
|
+
for (_m = 0, _o = pool.wrapped_coin_addresses; _m < _o.length; _m++) {
|
|
1083
|
+
coinAddr = _o[_m];
|
|
1078
1084
|
if (cTokens.includes(coinAddr)) {
|
|
1079
1085
|
this.setContract(coinAddr, cERC20Abi);
|
|
1080
1086
|
}
|
|
@@ -1114,15 +1120,15 @@ var Curve = /** @class */ (function () {
|
|
|
1114
1120
|
this.setContract(this.constants.ALIASES.crypto_calc, cryptoCalcZapABI);
|
|
1115
1121
|
this.setContract(this.constants.ALIASES.stable_calc, StableCalcZapABI);
|
|
1116
1122
|
this.setContract(this.constants.ALIASES.factory, factoryABI);
|
|
1117
|
-
if (!(this.chainId !== 1313161554 && this.chainId !== 252 && this.chainId !== 196)) return [3 /*break*/,
|
|
1123
|
+
if (!(this.chainId !== 1313161554 && this.chainId !== 252 && this.chainId !== 196)) return [3 /*break*/, 21];
|
|
1118
1124
|
factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
|
|
1119
|
-
|
|
1125
|
+
_p = this.constants.ALIASES;
|
|
1120
1126
|
return [4 /*yield*/, factoryContract.admin(this.constantOptions)];
|
|
1121
|
-
case
|
|
1122
|
-
|
|
1127
|
+
case 20:
|
|
1128
|
+
_p.factory_admin = (_q.sent()).toLowerCase();
|
|
1123
1129
|
this.setContract(this.constants.ALIASES.factory_admin, factoryAdminABI);
|
|
1124
|
-
|
|
1125
|
-
case
|
|
1130
|
+
_q.label = 21;
|
|
1131
|
+
case 21:
|
|
1126
1132
|
this.setContract(this.constants.ALIASES.crvusd_factory, factoryABI);
|
|
1127
1133
|
this.setContract(this.constants.ALIASES.eywa_factory, factoryEywaABI);
|
|
1128
1134
|
this.setContract(this.constants.ALIASES.crypto_factory, cryptoFactoryABI);
|
package/lib/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ declare const curve: {
|
|
|
44
44
|
getGasPriceFromL1: () => Promise<number>;
|
|
45
45
|
getGasPriceFromL2: () => Promise<number>;
|
|
46
46
|
getGasInfoForL2: () => Promise<Record<string, number | null>>;
|
|
47
|
-
|
|
47
|
+
getGasPrice: () => Promise<number>;
|
|
48
48
|
getTVL: (network?: import("./interfaces.js").INetworkName | import("./interfaces.js").IChainId) => Promise<number>;
|
|
49
49
|
getBalances: (coins: string[], ...addresses: string[] | string[][]) => Promise<string[] | import("./interfaces.js").IDict<string[]>>;
|
|
50
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,
|
|
42
|
+
import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getGasPriceFromL1, getGasPriceFromL2, getGasInfoForL2, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, getBasePools, getGasPrice, } 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,7 +81,7 @@ var curve = {
|
|
|
81
81
|
getGasPriceFromL1: getGasPriceFromL1,
|
|
82
82
|
getGasPriceFromL2: getGasPriceFromL2,
|
|
83
83
|
getGasInfoForL2: getGasInfoForL2,
|
|
84
|
-
|
|
84
|
+
getGasPrice: getGasPrice,
|
|
85
85
|
getTVL: getTVL,
|
|
86
86
|
getBalances: getBalances,
|
|
87
87
|
getAllowance: getAllowance,
|
package/lib/utils.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ 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
|
|
42
|
+
export declare const getGasPrice: () => Promise<number>;
|
|
43
43
|
export declare const getGasPriceFromL1: () => Promise<number>;
|
|
44
44
|
export declare const getGasPriceFromL2: () => Promise<number>;
|
|
45
45
|
export declare const getGasInfoForL2: () => Promise<Record<string, number | null>>;
|
package/lib/utils.js
CHANGED
|
@@ -729,49 +729,16 @@ export var getBaseFeeByLastBlock = function () { return __awaiter(void 0, void 0
|
|
|
729
729
|
}
|
|
730
730
|
});
|
|
731
731
|
}); };
|
|
732
|
-
export var
|
|
733
|
-
var provider,
|
|
734
|
-
return __generator(this, function (
|
|
735
|
-
switch (
|
|
732
|
+
export var getGasPrice = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
733
|
+
var provider, _a, _b;
|
|
734
|
+
return __generator(this, function (_c) {
|
|
735
|
+
switch (_c.label) {
|
|
736
736
|
case 0:
|
|
737
737
|
provider = curve.provider;
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
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))];
|
|
738
|
+
_a = Number;
|
|
739
|
+
_b = Number;
|
|
740
|
+
return [4 /*yield*/, provider.getFeeData()];
|
|
741
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [(_b.apply(void 0, [(_c.sent()).gasPrice]) / 1e9).toFixed(2)])];
|
|
775
742
|
}
|
|
776
743
|
});
|
|
777
744
|
}); };
|
|
@@ -796,7 +763,7 @@ export var getGasPriceFromL2 = function () { return __awaiter(void 0, void 0, vo
|
|
|
796
763
|
case 1: return [2 /*return*/, _a.sent()];
|
|
797
764
|
case 2:
|
|
798
765
|
if (!(curve.chainId === 196)) return [3 /*break*/, 4];
|
|
799
|
-
return [4 /*yield*/,
|
|
766
|
+
return [4 /*yield*/, getGasPrice()]; // gwei
|
|
800
767
|
case 3: return [2 /*return*/, _a.sent()]; // gwei
|
|
801
768
|
case 4:
|
|
802
769
|
if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 6];
|
|
@@ -823,13 +790,11 @@ export var getGasInfoForL2 = function () { return __awaiter(void 0, void 0, void
|
|
|
823
790
|
}];
|
|
824
791
|
case 2:
|
|
825
792
|
if (!(curve.chainId === 196)) return [3 /*break*/, 4];
|
|
826
|
-
return [4 /*yield*/,
|
|
793
|
+
return [4 /*yield*/, getGasPrice()];
|
|
827
794
|
case 3:
|
|
828
795
|
gasPrice = _a.sent();
|
|
829
796
|
return [2 /*return*/, {
|
|
830
797
|
gasPrice: gasPrice,
|
|
831
|
-
maxFeePerGas: null,
|
|
832
|
-
maxPriorityFeePerGas: null,
|
|
833
798
|
}];
|
|
834
799
|
case 4: throw Error("This method exists only for L2 networks");
|
|
835
800
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curvefi/api",
|
|
3
|
-
"version": "2.58.
|
|
3
|
+
"version": "2.58.9",
|
|
4
4
|
"description": "JavaScript library for curve.fi",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Macket",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"axios": "^0.21.1",
|
|
36
36
|
"bignumber.js": "^9.0.1",
|
|
37
|
-
"ethcall": "6.0.
|
|
37
|
+
"ethcall": "6.0.6",
|
|
38
38
|
"ethers": "^6.11.0",
|
|
39
39
|
"memoizee": "^0.4.15"
|
|
40
40
|
}
|