@curvefi/api 1.17.0 → 1.19.0
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/README.md +57 -0
- package/lib/constants/abis/abis-ethereum.js +6 -6
- package/lib/constants/abis/json/factory-crypto/factory-crypto-pool-2.json +1112 -0
- package/lib/constants/abis/json/factory-crypto.json +635 -0
- package/lib/constants/abis/json/factory-v2/DepositZapMetaBtcPolygon.json +197 -0
- package/lib/constants/abis/json/factory-v2/DepositZapMetaUsdPolygon.json +197 -0
- package/lib/constants/abis/json/factory-v2/MetaBTC.json +919 -0
- package/lib/constants/abis/json/factory-v2/MetaBTCBalances.json +932 -0
- package/lib/constants/abis/json/factory-v2/MetaBTCBalancesRen.json +932 -0
- package/lib/constants/abis/json/factory-v2/MetaBTCRen.json +919 -0
- package/lib/constants/abis/json/factory-v2/MetaUSD.json +919 -0
- package/lib/constants/abis/json/factory-v2/MetaUSDBalances.json +932 -0
- package/lib/constants/abis/json/factory-v2/Plain2Balances.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain2Basic.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain2ETH.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain2Optimized.json +844 -0
- package/lib/constants/abis/json/factory-v2/Plain3Balances.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain3Basic.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain3ETH.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain3Optimized.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4Balances.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4Basic.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4ETH.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4Optimized.json +845 -0
- package/lib/constants/abis/json/factory.json +1063 -0
- package/lib/constants/aliases.d.ts +4 -0
- package/lib/constants/aliases.js +4 -0
- package/lib/constants/coins-polygon.js +3 -2
- package/lib/curve.d.ts +5 -0
- package/lib/curve.js +62 -0
- package/lib/factory-crypto.d.ts +32 -0
- package/lib/factory-crypto.js +377 -0
- package/lib/factory.d.ts +32 -0
- package/lib/factory.js +607 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +29 -0
- package/lib/interfaces.d.ts +16 -1
- package/lib/pools.d.ts +4 -0
- package/lib/pools.js +213 -98
- package/lib/utils.d.ts +9 -1
- package/lib/utils.js +123 -8
- package/package.json +4 -2
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import memoize from 'memoizee';
|
|
1
2
|
import { ethers } from 'ethers';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { DictInterface } from './interfaces';
|
|
4
|
+
import { DictInterface, IStats } from './interfaces';
|
|
4
5
|
export declare const MAX_ALLOWANCE: ethers.BigNumber;
|
|
5
6
|
export declare const BN: (val: number | string) => BigNumber;
|
|
6
7
|
export declare const toBN: (n: ethers.BigNumber, decimals?: number) => BigNumber;
|
|
@@ -21,5 +22,12 @@ export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: stri
|
|
|
21
22
|
export declare const ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<string[]>;
|
|
22
23
|
export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
|
|
23
24
|
export declare const _getUsdRate: (assetId: string) => Promise<number>;
|
|
25
|
+
export declare const _getFactoryStatsUrl: () => string;
|
|
24
26
|
export declare const _getStatsUrl: (isCrypto?: boolean) => string;
|
|
27
|
+
export declare const _getStats: ((statsUrl: string) => Promise<IStats>) & memoize.Memoized<(statsUrl: string) => Promise<IStats>>;
|
|
28
|
+
export declare const _getFactoryStatsEthereum: ((statsUrl: string) => Promise<IStats>) & memoize.Memoized<(statsUrl: string) => Promise<IStats>>;
|
|
29
|
+
export declare const _getFactoryStatsPolygon: ((statsUrl: string) => Promise<IStats>) & memoize.Memoized<(statsUrl: string) => Promise<IStats>>;
|
|
25
30
|
export declare const getPoolList: () => string[];
|
|
31
|
+
export declare const getFactoryPoolList: () => string[];
|
|
32
|
+
export declare const getCryptoFactoryPoolList: () => string[];
|
|
33
|
+
export declare const getUsdRate: (coin: string) => Promise<number>;
|
package/lib/utils.js
CHANGED
|
@@ -59,8 +59,9 @@ 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.getPoolList = exports._getStatsUrl = exports._getUsdRate = 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.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
|
|
62
|
+
exports.getUsdRate = exports.getCryptoFactoryPoolList = exports.getFactoryPoolList = exports.getPoolList = exports._getFactoryStatsPolygon = exports._getFactoryStatsEthereum = exports._getStats = exports._getStatsUrl = exports._getFactoryStatsUrl = exports._getUsdRate = 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.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
|
|
63
63
|
var axios_1 = __importDefault(require("axios"));
|
|
64
|
+
var memoizee_1 = __importDefault(require("memoizee"));
|
|
64
65
|
var ethers_1 = require("ethers");
|
|
65
66
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
66
67
|
var curve_1 = require("./curve");
|
|
@@ -117,7 +118,7 @@ var _getCoinDecimals = function () {
|
|
|
117
118
|
if (coinAddresses.length == 1 && Array.isArray(coinAddresses[0]))
|
|
118
119
|
coinAddresses = coinAddresses[0];
|
|
119
120
|
coinAddresses = coinAddresses;
|
|
120
|
-
return coinAddresses.map(function (coinAddr) { return curve_2.DECIMALS_LOWER_CASE[coinAddr.toLowerCase()]
|
|
121
|
+
return coinAddresses.map(function (coinAddr) { var _a; return (_a = curve_2.DECIMALS_LOWER_CASE[coinAddr.toLowerCase()]) !== null && _a !== void 0 ? _a : 18; });
|
|
121
122
|
};
|
|
122
123
|
exports._getCoinDecimals = _getCoinDecimals;
|
|
123
124
|
var _getBalances = function (coins, addresses) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -376,9 +377,9 @@ exports.getPoolNameBySwapAddress = getPoolNameBySwapAddress;
|
|
|
376
377
|
var _usdRatesCache = {};
|
|
377
378
|
var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
378
379
|
var chainName, url, response;
|
|
379
|
-
var _a;
|
|
380
|
-
return __generator(this, function (
|
|
381
|
-
switch (
|
|
380
|
+
var _a, _b;
|
|
381
|
+
return __generator(this, function (_c) {
|
|
382
|
+
switch (_c.label) {
|
|
382
383
|
case 0:
|
|
383
384
|
if (assetId === 'USD' || (curve_1.curve.chainId === 137 && (assetId.toLowerCase() === curve_2.COINS.am3crv.toLowerCase())))
|
|
384
385
|
return [2 /*return*/, 1];
|
|
@@ -408,14 +409,31 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
408
409
|
"https://api.coingecko.com/api/v3/simple/token_price/".concat(chainName, "?contract_addresses=").concat(assetId, "&vs_currencies=usd");
|
|
409
410
|
return [4 /*yield*/, axios_1.default.get(url)];
|
|
410
411
|
case 1:
|
|
411
|
-
response =
|
|
412
|
-
|
|
413
|
-
|
|
412
|
+
response = _c.sent();
|
|
413
|
+
try {
|
|
414
|
+
_usdRatesCache[assetId] = { 'rate': (_b = response.data[assetId]['usd']) !== null && _b !== void 0 ? _b : 1, 'time': Date.now() };
|
|
415
|
+
}
|
|
416
|
+
catch (err) { // TODO pay attention!
|
|
417
|
+
_usdRatesCache[assetId] = { 'rate': 1, 'time': Date.now() };
|
|
418
|
+
}
|
|
419
|
+
_c.label = 2;
|
|
414
420
|
case 2: return [2 /*return*/, _usdRatesCache[assetId]['rate']];
|
|
415
421
|
}
|
|
416
422
|
});
|
|
417
423
|
}); };
|
|
418
424
|
exports._getUsdRate = _getUsdRate;
|
|
425
|
+
var _getFactoryStatsUrl = function () {
|
|
426
|
+
if (curve_1.curve.chainId === 1 || curve_1.curve.chainId === 1337) {
|
|
427
|
+
return "https://curve-api-hplkiejxx-curvefi.vercel.app/api/getSubgraphData";
|
|
428
|
+
}
|
|
429
|
+
else if (curve_1.curve.chainId === 137) {
|
|
430
|
+
return "https://api.curve.fi/api/getFactoryAPYs-polygon";
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
throw Error("Unsupported network id".concat(curve_1.curve.chainId));
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
exports._getFactoryStatsUrl = _getFactoryStatsUrl;
|
|
419
437
|
var _getStatsUrl = function (isCrypto) {
|
|
420
438
|
if (isCrypto === void 0) { isCrypto = false; }
|
|
421
439
|
if (curve_1.curve.chainId === 1 || curve_1.curve.chainId === 1337) {
|
|
@@ -429,5 +447,102 @@ var _getStatsUrl = function (isCrypto) {
|
|
|
429
447
|
}
|
|
430
448
|
};
|
|
431
449
|
exports._getStatsUrl = _getStatsUrl;
|
|
450
|
+
exports._getStats = (0, memoizee_1.default)(function (statsUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
451
|
+
var rawData, data;
|
|
452
|
+
return __generator(this, function (_a) {
|
|
453
|
+
switch (_a.label) {
|
|
454
|
+
case 0: return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
455
|
+
case 1:
|
|
456
|
+
rawData = (_a.sent()).data;
|
|
457
|
+
data = {};
|
|
458
|
+
Object.keys(rawData.apy.day).forEach(function (poolName) {
|
|
459
|
+
var _a;
|
|
460
|
+
data[poolName] = {
|
|
461
|
+
volume: (_a = rawData.volume[poolName]) !== null && _a !== void 0 ? _a : 0,
|
|
462
|
+
apy: {
|
|
463
|
+
day: rawData.apy.day[poolName],
|
|
464
|
+
week: rawData.apy.week[poolName],
|
|
465
|
+
month: rawData.apy.month[poolName],
|
|
466
|
+
total: rawData.apy.total[poolName],
|
|
467
|
+
},
|
|
468
|
+
};
|
|
469
|
+
});
|
|
470
|
+
return [2 /*return*/, data];
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
}); }, {
|
|
474
|
+
promise: true,
|
|
475
|
+
maxAge: 10 * 60 * 1000, // 10m
|
|
476
|
+
});
|
|
477
|
+
exports._getFactoryStatsEthereum = (0, memoizee_1.default)(function (statsUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
478
|
+
var rawData, data;
|
|
479
|
+
return __generator(this, function (_a) {
|
|
480
|
+
switch (_a.label) {
|
|
481
|
+
case 0: return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
482
|
+
case 1:
|
|
483
|
+
rawData = (_a.sent()).data.data.poolList;
|
|
484
|
+
data = {};
|
|
485
|
+
rawData.forEach(function (item) {
|
|
486
|
+
var _a, _b, _c, _d, _e;
|
|
487
|
+
data[item.address.toLowerCase()] = {
|
|
488
|
+
volume: (_a = item.volumeUSD) !== null && _a !== void 0 ? _a : 0,
|
|
489
|
+
apy: {
|
|
490
|
+
day: (_b = item.latestDailyApy) !== null && _b !== void 0 ? _b : 0,
|
|
491
|
+
week: (_c = item.latestWeeklyApy) !== null && _c !== void 0 ? _c : 0,
|
|
492
|
+
month: (_d = item.latestWeeklyApy) !== null && _d !== void 0 ? _d : 0,
|
|
493
|
+
total: (_e = item.latestWeeklyApy) !== null && _e !== void 0 ? _e : 0,
|
|
494
|
+
},
|
|
495
|
+
};
|
|
496
|
+
});
|
|
497
|
+
return [2 /*return*/, data];
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}); }, {
|
|
501
|
+
promise: true,
|
|
502
|
+
maxAge: 10 * 60 * 1000, // 10m
|
|
503
|
+
});
|
|
504
|
+
exports._getFactoryStatsPolygon = (0, memoizee_1.default)(function (statsUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
505
|
+
var rawData, data;
|
|
506
|
+
return __generator(this, function (_a) {
|
|
507
|
+
switch (_a.label) {
|
|
508
|
+
case 0: return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
509
|
+
case 1:
|
|
510
|
+
rawData = (_a.sent()).data.data.poolDetails;
|
|
511
|
+
data = {};
|
|
512
|
+
rawData.forEach(function (item) {
|
|
513
|
+
var _a, _b, _c, _d, _e;
|
|
514
|
+
data[item.poolAddress.toLowerCase()] = {
|
|
515
|
+
volume: (_a = item.volume) !== null && _a !== void 0 ? _a : 0,
|
|
516
|
+
apy: {
|
|
517
|
+
day: (_b = item.apy) !== null && _b !== void 0 ? _b : 0,
|
|
518
|
+
week: (_c = item.apy) !== null && _c !== void 0 ? _c : 0,
|
|
519
|
+
month: (_d = item.apy) !== null && _d !== void 0 ? _d : 0,
|
|
520
|
+
total: (_e = item.apy) !== null && _e !== void 0 ? _e : 0,
|
|
521
|
+
},
|
|
522
|
+
};
|
|
523
|
+
});
|
|
524
|
+
return [2 /*return*/, data];
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
}); }, {
|
|
528
|
+
promise: true,
|
|
529
|
+
maxAge: 10 * 60 * 1000, // 10m
|
|
530
|
+
});
|
|
432
531
|
var getPoolList = function () { return Object.keys(curve_1.POOLS_DATA); };
|
|
433
532
|
exports.getPoolList = getPoolList;
|
|
533
|
+
var getFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.FACTORY_POOLS_DATA); };
|
|
534
|
+
exports.getFactoryPoolList = getFactoryPoolList;
|
|
535
|
+
var getCryptoFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA); };
|
|
536
|
+
exports.getCryptoFactoryPoolList = getCryptoFactoryPoolList;
|
|
537
|
+
var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void 0, function () {
|
|
538
|
+
var coinAddress;
|
|
539
|
+
return __generator(this, function (_a) {
|
|
540
|
+
switch (_a.label) {
|
|
541
|
+
case 0:
|
|
542
|
+
coinAddress = (0, exports._getCoinAddresses)(coin)[0];
|
|
543
|
+
return [4 /*yield*/, (0, exports._getUsdRate)(coinAddress)];
|
|
544
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
}); };
|
|
548
|
+
exports.getUsdRate = getUsdRate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curvefi/api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "JavaScript library for curve.fi",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/chai": "^4.2.18",
|
|
13
|
+
"@types/memoizee": "^0.4.7",
|
|
13
14
|
"@types/mocha": "^8.2.2",
|
|
14
15
|
"@types/node": "^14.14.37",
|
|
15
16
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
"axios": "^0.21.1",
|
|
26
27
|
"bignumber.js": "^9.0.1",
|
|
27
28
|
"ethcall": "^4.2.5",
|
|
28
|
-
"ethers": "^5.4.6"
|
|
29
|
+
"ethers": "^5.4.6",
|
|
30
|
+
"memoizee": "^0.4.15"
|
|
29
31
|
}
|
|
30
32
|
}
|