@curvefi/api 2.0.0 → 2.2.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/README.md +30 -7
- package/lib/constants/aliases.d.ts +1 -0
- package/lib/constants/aliases.js +13 -1
- package/lib/constants/coins/avalanche.d.ts +7 -0
- package/lib/constants/coins/avalanche.js +33 -0
- package/lib/constants/pools/avalanche.d.ts +4 -0
- package/lib/constants/pools/avalanche.js +113 -0
- package/lib/constants/pools/ethereum.js +0 -1
- package/lib/constants/pools/index.d.ts +2 -1
- package/lib/constants/pools/index.js +3 -1
- package/lib/curve.d.ts +5 -1
- package/lib/curve.js +27 -11
- package/lib/external-api.d.ts +3 -3
- package/lib/factory/common.d.ts +2 -0
- package/lib/factory/common.js +45 -0
- package/lib/factory/constants.d.ts +11 -11
- package/lib/factory/constants.js +60 -58
- package/lib/factory/factory-api.js +20 -39
- package/lib/factory/factory-crypto.js +7 -4
- package/lib/factory/factory.js +31 -163
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/interfaces.d.ts +37 -27
- package/lib/pools/PoolTemplate.d.ts +3 -0
- package/lib/pools/PoolTemplate.js +106 -24
- package/lib/pools/poolConstructor.js +3 -3
- package/lib/router.d.ts +1 -0
- package/lib/router.js +69 -42
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +32 -14
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -59,13 +59,13 @@ 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.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.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
|
|
62
|
+
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.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = 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 bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
66
66
|
var curve_1 = require("./curve");
|
|
67
67
|
var external_api_1 = require("./external-api");
|
|
68
|
-
|
|
68
|
+
exports.ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
69
69
|
exports.MAX_ALLOWANCE = ethers_1.ethers.BigNumber.from(2).pow(ethers_1.ethers.BigNumber.from(256)).sub(ethers_1.ethers.BigNumber.from(1));
|
|
70
70
|
// bignumber.js
|
|
71
71
|
var BN = function (val) { return new bignumber_js_1.default(val); };
|
|
@@ -86,6 +86,10 @@ var fromBN = function (bn, decimals) {
|
|
|
86
86
|
};
|
|
87
87
|
exports.fromBN = fromBN;
|
|
88
88
|
// Formatting numbers
|
|
89
|
+
var _cutZeros = function (strn) {
|
|
90
|
+
return strn.replace(/0+$/gi, '').replace(/\.$/gi, '');
|
|
91
|
+
};
|
|
92
|
+
exports._cutZeros = _cutZeros;
|
|
89
93
|
var checkNumber = function (n) {
|
|
90
94
|
if (Number(n) !== Number(n))
|
|
91
95
|
throw Error("".concat(n, " is not a number")); // NaN
|
|
@@ -106,9 +110,9 @@ var parseUnits = function (n, decimals) {
|
|
|
106
110
|
};
|
|
107
111
|
exports.parseUnits = parseUnits;
|
|
108
112
|
// -------------------
|
|
109
|
-
var isEth = function (address) { return address.toLowerCase() === ETH_ADDRESS.toLowerCase(); };
|
|
113
|
+
var isEth = function (address) { return address.toLowerCase() === exports.ETH_ADDRESS.toLowerCase(); };
|
|
110
114
|
exports.isEth = isEth;
|
|
111
|
-
var getEthIndex = function (addresses) { return addresses.map(function (address) { return address.toLowerCase(); }).indexOf(ETH_ADDRESS.toLowerCase()); };
|
|
115
|
+
var getEthIndex = function (addresses) { return addresses.map(function (address) { return address.toLowerCase(); }).indexOf(exports.ETH_ADDRESS.toLowerCase()); };
|
|
112
116
|
exports.getEthIndex = getEthIndex;
|
|
113
117
|
// coins can be either addresses or symbols
|
|
114
118
|
var _getCoinAddresses = function () {
|
|
@@ -400,7 +404,7 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
|
|
|
400
404
|
return __generator(this, function (_h) {
|
|
401
405
|
switch (_h.label) {
|
|
402
406
|
case 0:
|
|
403
|
-
network = curve_1.curve.
|
|
407
|
+
network = curve_1.curve.constants.NETWORK_NAME;
|
|
404
408
|
promises = [
|
|
405
409
|
(0, external_api_1._getPoolsFromApi)(network, "main"),
|
|
406
410
|
(0, external_api_1._getPoolsFromApi)(network, "crypto"),
|
|
@@ -434,7 +438,7 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
|
|
|
434
438
|
exports._getUsdPricesFromApi = _getUsdPricesFromApi;
|
|
435
439
|
var _usdRatesCache = {};
|
|
436
440
|
var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
437
|
-
var pricesFromApi, chainName, url, response;
|
|
441
|
+
var pricesFromApi, chainName, nativeTokenName, url, response;
|
|
438
442
|
var _a, _b;
|
|
439
443
|
return __generator(this, function (_c) {
|
|
440
444
|
switch (_c.label) {
|
|
@@ -448,7 +452,12 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
448
452
|
chainName = {
|
|
449
453
|
1: 'ethereum',
|
|
450
454
|
137: 'polygon-pos',
|
|
451
|
-
|
|
455
|
+
43114: 'avalanche',
|
|
456
|
+
}[curve_1.curve.chainId];
|
|
457
|
+
nativeTokenName = {
|
|
458
|
+
1: 'ethereum',
|
|
459
|
+
137: 'matic-network',
|
|
460
|
+
43114: 'avalanche-2',
|
|
452
461
|
}[curve_1.curve.chainId];
|
|
453
462
|
if (chainName === undefined) {
|
|
454
463
|
throw Error('curve object is not initialized');
|
|
@@ -459,14 +468,18 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
459
468
|
'ETH': 'ethereum',
|
|
460
469
|
'LINK': 'link',
|
|
461
470
|
}[assetId] || assetId;
|
|
462
|
-
assetId = (0, exports.isEth)(assetId) ?
|
|
471
|
+
assetId = (0, exports.isEth)(assetId) ? nativeTokenName : assetId.toLowerCase();
|
|
463
472
|
// No EURT on Coingecko Polygon
|
|
464
|
-
if (assetId.toLowerCase() === curve_1.curve.constants.COINS.eurt
|
|
473
|
+
if (curve_1.curve.chainId === 137 && assetId.toLowerCase() === curve_1.curve.constants.COINS.eurt) {
|
|
465
474
|
chainName = 'ethereum';
|
|
466
475
|
assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
|
|
467
476
|
}
|
|
477
|
+
// CRV
|
|
478
|
+
if (assetId.toLowerCase() === curve_1.curve.constants.ALIASES.crv) {
|
|
479
|
+
assetId = 'curve-dao-token';
|
|
480
|
+
}
|
|
468
481
|
if (!((((_a = _usdRatesCache[assetId]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 600000 < Date.now())) return [3 /*break*/, 3];
|
|
469
|
-
url = ['bitcoin', '
|
|
482
|
+
url = [nativeTokenName, 'bitcoin', 'link', 'curve-dao-token'].includes(assetId.toLowerCase()) ?
|
|
470
483
|
"https://api.coingecko.com/api/v3/simple/price?ids=".concat(assetId, "&vs_currencies=usd") :
|
|
471
484
|
"https://api.coingecko.com/api/v3/simple/token_price/".concat(chainName, "?contract_addresses=").concat(assetId, "&vs_currencies=usd");
|
|
472
485
|
return [4 /*yield*/, axios_1.default.get(url)];
|
|
@@ -500,10 +513,15 @@ var getTVL = function (chainId) {
|
|
|
500
513
|
if (chainId === void 0) { chainId = curve_1.curve.chainId; }
|
|
501
514
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
502
515
|
var network, promises, allTypesExtendedPoolData;
|
|
503
|
-
|
|
504
|
-
|
|
516
|
+
var _a;
|
|
517
|
+
return __generator(this, function (_b) {
|
|
518
|
+
switch (_b.label) {
|
|
505
519
|
case 0:
|
|
506
|
-
network =
|
|
520
|
+
network = (_a = {
|
|
521
|
+
1: "ethereum",
|
|
522
|
+
137: "polygon",
|
|
523
|
+
43114: "avalanche",
|
|
524
|
+
}[chainId]) !== null && _a !== void 0 ? _a : "ethereum";
|
|
507
525
|
promises = [
|
|
508
526
|
(0, external_api_1._getPoolsFromApi)(network, "main"),
|
|
509
527
|
(0, external_api_1._getPoolsFromApi)(network, "crypto"),
|
|
@@ -512,7 +530,7 @@ var getTVL = function (chainId) {
|
|
|
512
530
|
];
|
|
513
531
|
return [4 /*yield*/, Promise.all(promises)];
|
|
514
532
|
case 1:
|
|
515
|
-
allTypesExtendedPoolData =
|
|
533
|
+
allTypesExtendedPoolData = _b.sent();
|
|
516
534
|
return [2 /*return*/, allTypesExtendedPoolData.reduce(function (sum, data) { var _a; return sum + ((_a = data.tvl) !== null && _a !== void 0 ? _a : data.tvlAll); }, 0)];
|
|
517
535
|
}
|
|
518
536
|
});
|