@curvefi/api 2.24.0 → 2.24.1
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/factory/factory-api.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/interfaces.d.ts +1 -0
- package/lib/pools/PoolTemplate.d.ts +2 -2
- package/lib/pools/PoolTemplate.js +69 -59
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +32 -1
- package/package.json +1 -1
|
@@ -176,7 +176,7 @@ function getFactoryPoolsDataFromApi(isCrypto) {
|
|
|
176
176
|
poolGaugeDict = {};
|
|
177
177
|
for (_i = 0, _b = response.data.data.gauges; _i < _b.length; _i++) {
|
|
178
178
|
gaugeData = _b[_i];
|
|
179
|
-
poolGaugeDict[gaugeData.swap] = gaugeData.gauge;
|
|
179
|
+
poolGaugeDict[gaugeData.swap.toLowerCase()] = gaugeData.gauge.toLowerCase();
|
|
180
180
|
}
|
|
181
181
|
for (i = 0; i < rawPoolList.length; i++) {
|
|
182
182
|
rawPoolList[i].gaugeAddress = poolGaugeDict[rawPoolList[i].address];
|
package/lib/index.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ declare const curve: {
|
|
|
57
57
|
symbol: string;
|
|
58
58
|
}[]>;
|
|
59
59
|
factory: {
|
|
60
|
-
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 |
|
|
60
|
+
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 | 2 | 1 | 3, implementationIdx: 0 | 2 | 1 | 3) => Promise<ethers.ContractTransaction>;
|
|
61
61
|
deployMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number, fee: number, implementationIdx: 0 | 1) => Promise<ethers.ContractTransaction>;
|
|
62
62
|
deployGauge: (poolAddress: string) => Promise<ethers.ContractTransaction>;
|
|
63
63
|
getDeployedPlainPoolAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
@@ -65,7 +65,7 @@ declare const curve: {
|
|
|
65
65
|
getDeployedGaugeAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
66
66
|
fetchRecentlyDeployedPool: typeof fetchRecentlyDeployedFactoryPool;
|
|
67
67
|
estimateGas: {
|
|
68
|
-
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 |
|
|
68
|
+
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 | 2 | 1 | 3, implementationIdx: 0 | 2 | 1 | 3) => Promise<number>;
|
|
69
69
|
deployMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number, fee: number, implementationIdx: 0 | 1) => Promise<number>;
|
|
70
70
|
deployGauge: (poolAddress: string) => Promise<number>;
|
|
71
71
|
};
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -78,7 +78,7 @@ export declare class PoolTemplate {
|
|
|
78
78
|
day: string;
|
|
79
79
|
week: string;
|
|
80
80
|
}>;
|
|
81
|
-
tokenApy: () => Promise<[baseApy:
|
|
81
|
+
tokenApy: (useApi?: boolean) => Promise<[baseApy: number, boostedApy: number]>;
|
|
82
82
|
rewardsApy: () => Promise<IReward[]>;
|
|
83
83
|
};
|
|
84
84
|
wallet: {
|
|
@@ -132,7 +132,7 @@ export declare class PoolTemplate {
|
|
|
132
132
|
claimCrvEstimateGas(): Promise<number>;
|
|
133
133
|
claimCrv(): Promise<string>;
|
|
134
134
|
boost: (address?: string) => Promise<string>;
|
|
135
|
-
currentCrvApy: (address?: string) => Promise<
|
|
135
|
+
currentCrvApy: (address?: string) => Promise<number>;
|
|
136
136
|
maxBoostedStake: (...addresses: string[]) => Promise<IDict<string> | string>;
|
|
137
137
|
rewardTokens: (() => Promise<{
|
|
138
138
|
token: string;
|
|
@@ -279,64 +279,74 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
279
279
|
}
|
|
280
280
|
});
|
|
281
281
|
}); };
|
|
282
|
-
this.statsTokenApy = function () {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return [
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
]
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
282
|
+
this.statsTokenApy = function (useApi) {
|
|
283
|
+
if (useApi === void 0) { useApi = true; }
|
|
284
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
285
|
+
var crvAPYs, poolCrvApy, totalLiquidityUSD, inflationRateBN, workingSupplyBN, totalSupplyBN, gaugeContract, lpTokenContract, crvContract, currentWeek, _c, gaugeContract, lpTokenContract, gaugeControllerContract, weightBN, rateBN, crvPrice, baseApyBN, boostedApyBN;
|
|
286
|
+
var _d, _e;
|
|
287
|
+
var _f;
|
|
288
|
+
return __generator(this, function (_g) {
|
|
289
|
+
switch (_g.label) {
|
|
290
|
+
case 0:
|
|
291
|
+
if (this.rewardsOnly())
|
|
292
|
+
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use getRewardsApy instead"));
|
|
293
|
+
if (!(useApi && curve_1.curve.chainId === 1)) return [3 /*break*/, 2];
|
|
294
|
+
return [4 /*yield*/, (0, utils_1._getCrvApyFromApi)()];
|
|
295
|
+
case 1:
|
|
296
|
+
crvAPYs = _g.sent();
|
|
297
|
+
poolCrvApy = (_f = crvAPYs[this.gauge]) !== null && _f !== void 0 ? _f : [0, 0];
|
|
298
|
+
return [2 /*return*/, [poolCrvApy[0], poolCrvApy[1]]];
|
|
299
|
+
case 2: return [4 /*yield*/, this.statsTotalLiquidity()];
|
|
300
|
+
case 3:
|
|
301
|
+
totalLiquidityUSD = _g.sent();
|
|
302
|
+
if (Number(totalLiquidityUSD) === 0)
|
|
303
|
+
return [2 /*return*/, [0, 0]];
|
|
304
|
+
if (!(curve_1.curve.chainId !== 1)) return [3 /*break*/, 7];
|
|
305
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
306
|
+
lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
307
|
+
crvContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.crv].contract;
|
|
308
|
+
currentWeek = Math.floor(Date.now() / 1000 / WEEK);
|
|
309
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
310
|
+
gaugeContract.inflation_rate(currentWeek),
|
|
311
|
+
gaugeContract.working_supply(),
|
|
312
|
+
lpTokenContract.totalSupply(),
|
|
313
|
+
])];
|
|
314
|
+
case 4:
|
|
315
|
+
_d = (_g.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflationRateBN = _d[0], workingSupplyBN = _d[1], totalSupplyBN = _d[2];
|
|
316
|
+
if (!inflationRateBN.eq(0)) return [3 /*break*/, 6];
|
|
317
|
+
_c = utils_1.toBN;
|
|
318
|
+
return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve_1.curve.constantOptions)];
|
|
319
|
+
case 5:
|
|
320
|
+
inflationRateBN = _c.apply(void 0, [_g.sent()]).div(WEEK);
|
|
321
|
+
_g.label = 6;
|
|
322
|
+
case 6: return [3 /*break*/, 9];
|
|
323
|
+
case 7:
|
|
324
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
325
|
+
lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
326
|
+
gaugeControllerContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
327
|
+
weightBN = void 0;
|
|
328
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
329
|
+
gaugeContract.inflation_rate(),
|
|
330
|
+
gaugeControllerContract.gauge_relative_weight(this.gauge),
|
|
331
|
+
gaugeContract.working_supply(),
|
|
332
|
+
lpTokenContract.totalSupply(),
|
|
333
|
+
])];
|
|
334
|
+
case 8:
|
|
335
|
+
_e = (_g.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflationRateBN = _e[0], weightBN = _e[1], workingSupplyBN = _e[2], totalSupplyBN = _e[3];
|
|
336
|
+
inflationRateBN = inflationRateBN.times(weightBN);
|
|
337
|
+
_g.label = 9;
|
|
338
|
+
case 9:
|
|
339
|
+
rateBN = inflationRateBN.times(31536000).times(0.4).div(workingSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD));
|
|
340
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.curve.constants.ALIASES.crv)];
|
|
341
|
+
case 10:
|
|
342
|
+
crvPrice = _g.sent();
|
|
343
|
+
baseApyBN = rateBN.times(crvPrice);
|
|
344
|
+
boostedApyBN = baseApyBN.times(2.5);
|
|
345
|
+
return [2 /*return*/, [baseApyBN.times(100).toNumber(), boostedApyBN.times(100).toNumber()]];
|
|
346
|
+
}
|
|
347
|
+
});
|
|
338
348
|
});
|
|
339
|
-
}
|
|
349
|
+
};
|
|
340
350
|
this.statsRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
341
351
|
var apy, rewardTokens, _i, rewardTokens_1, rewardToken, contract, totalLiquidityUSD, rewardRate, rewardData, periodFinish, inflation, baseApy, network, promises, _c, mainPoolsRewards, allTypesExtendedPoolData, rewards, _d, _e, extendedPoolData, _f, _g, pool;
|
|
342
352
|
var _h;
|
|
@@ -648,8 +658,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
648
658
|
if (boost == "2.5")
|
|
649
659
|
return [2 /*return*/, maxApy];
|
|
650
660
|
if (boost === "NaN")
|
|
651
|
-
return [2 /*return*/,
|
|
652
|
-
return [2 /*return*/, (0, utils_1.BN)(baseApy).times((0, utils_1.BN)(boost)).
|
|
661
|
+
return [2 /*return*/, NaN];
|
|
662
|
+
return [2 /*return*/, (0, utils_1.BN)(baseApy).times((0, utils_1.BN)(boost)).toNumber()];
|
|
653
663
|
}
|
|
654
664
|
});
|
|
655
665
|
});
|
package/lib/utils.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (num
|
|
|
27
27
|
export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string) => Promise<string[]>;
|
|
28
28
|
export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
|
|
29
29
|
export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
|
|
30
|
+
export declare const _getCrvApyFromApi: () => Promise<IDict<[number, number]>>;
|
|
30
31
|
export declare const _getUsdRate: (assetId: string) => Promise<number>;
|
|
31
32
|
export declare const getUsdRate: (coin: string) => Promise<number>;
|
|
32
33
|
export declare const getTVL: (chainId?: number) => Promise<number>;
|
package/lib/utils.js
CHANGED
|
@@ -59,7 +59,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.getCoinNamesAndSymbols = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
62
|
+
exports.getCoinNamesAndSymbols = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getCrvApyFromApi = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
63
63
|
var axios_1 = __importDefault(require("axios"));
|
|
64
64
|
var ethers_1 = require("ethers");
|
|
65
65
|
var ethcall_1 = require("ethcall");
|
|
@@ -449,6 +449,37 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
|
|
|
449
449
|
});
|
|
450
450
|
}); };
|
|
451
451
|
exports._getUsdPricesFromApi = _getUsdPricesFromApi;
|
|
452
|
+
var _getCrvApyFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
453
|
+
var network, promises, allTypesExtendedPoolData, apyDict, _i, allTypesExtendedPoolData_2, extendedPoolData, _a, _b, pool;
|
|
454
|
+
var _c, _d;
|
|
455
|
+
return __generator(this, function (_e) {
|
|
456
|
+
switch (_e.label) {
|
|
457
|
+
case 0:
|
|
458
|
+
network = curve_1.curve.constants.NETWORK_NAME;
|
|
459
|
+
promises = [
|
|
460
|
+
(0, external_api_1._getPoolsFromApi)(network, "main"),
|
|
461
|
+
(0, external_api_1._getPoolsFromApi)(network, "crypto"),
|
|
462
|
+
(0, external_api_1._getPoolsFromApi)(network, "factory"),
|
|
463
|
+
(0, external_api_1._getPoolsFromApi)(network, "factory-crypto"),
|
|
464
|
+
];
|
|
465
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
466
|
+
case 1:
|
|
467
|
+
allTypesExtendedPoolData = _e.sent();
|
|
468
|
+
apyDict = {};
|
|
469
|
+
for (_i = 0, allTypesExtendedPoolData_2 = allTypesExtendedPoolData; _i < allTypesExtendedPoolData_2.length; _i++) {
|
|
470
|
+
extendedPoolData = allTypesExtendedPoolData_2[_i];
|
|
471
|
+
for (_a = 0, _b = extendedPoolData.poolData; _a < _b.length; _a++) {
|
|
472
|
+
pool = _b[_a];
|
|
473
|
+
if (pool.gaugeAddress) {
|
|
474
|
+
apyDict[pool.gaugeAddress] = [(_c = pool.gaugeCrvApy[0]) !== null && _c !== void 0 ? _c : 0, (_d = pool.gaugeCrvApy[1]) !== null && _d !== void 0 ? _d : 0];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return [2 /*return*/, apyDict];
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
}); };
|
|
482
|
+
exports._getCrvApyFromApi = _getCrvApyFromApi;
|
|
452
483
|
var _usdRatesCache = {};
|
|
453
484
|
var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
454
485
|
var pricesFromApi, chainName, nativeTokenName, url, response;
|