@curvefi/api 1.13.0 → 1.16.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 +98 -1
- package/lib/constants/abis/abis-ethereum.js +216 -16
- package/lib/constants/abis/abis-polygon.js +17 -1
- package/lib/constants/abis/json/aave/rewards.json +107 -0
- package/lib/constants/abis/json/atricrypto3/swap.json +63 -63
- package/lib/constants/abis/json/atricrypto3/zap.json +8 -8
- package/lib/constants/abis/json/busd/deposit.json +5 -10
- package/lib/constants/abis/json/busd/swap.json +18 -36
- package/lib/constants/abis/json/compound/deposit.json +5 -10
- package/lib/constants/abis/json/compound/migration.json +1 -2
- package/lib/constants/abis/json/compound/oldSwap.json +16 -32
- package/lib/constants/abis/json/compound/swap.json +18 -36
- package/lib/constants/abis/json/crveth/swap.json +61 -61
- package/lib/constants/abis/json/eurt/swap.json +29 -29
- package/lib/constants/abis/json/eurtusd/deposit.json +13 -13
- package/lib/constants/abis/json/eurtusd/swap.json +59 -59
- package/lib/constants/abis/json/gauge.json +1 -1
- package/lib/constants/abis/json/gauge_factory.json +879 -0
- package/lib/constants/abis/json/gauge_rewards_only.json +649 -0
- package/lib/constants/abis/json/gauge_synthetix.json +590 -0
- package/lib/constants/abis/json/gauge_v2.json +942 -0
- package/lib/constants/abis/json/gauge_v3.json +954 -0
- package/lib/constants/abis/json/gauge_v4.json +913 -0
- package/lib/constants/abis/json/iearn/deposit.json +5 -10
- package/lib/constants/abis/json/iearn/swap.json +18 -36
- package/lib/constants/abis/json/minter.json +165 -0
- package/lib/constants/abis/json/pax/deposit.json +5 -10
- package/lib/constants/abis/json/pax/swap.json +19 -38
- package/lib/constants/abis/json/ren/swap.json +19 -38
- package/lib/constants/abis/json/ren-polygon/swap.json +46 -46
- package/lib/constants/abis/json/reth/swap.json +38 -38
- package/lib/constants/abis/json/sbtc/swap.json +19 -38
- package/lib/constants/abis/json/streamer.json +257 -0
- package/lib/constants/abis/json/susdv2/deposit.json +5 -10
- package/lib/constants/abis/json/susdv2/swap.json +16 -32
- package/lib/constants/abis/json/tricrypto2/deposit.json +3 -3
- package/lib/constants/abis/json/tricrypto2/swap.json +60 -60
- package/lib/constants/abis/json/usdt/deposit.json +5 -10
- package/lib/constants/abis/json/usdt/swap.json +19 -37
- package/lib/constants/aliases.d.ts +2 -0
- package/lib/constants/aliases.js +3 -1
- package/lib/constants/coins-ethereum.js +7 -3
- package/lib/constants/coins-polygon.js +3 -2
- package/lib/curve.d.ts +1 -0
- package/lib/curve.js +47 -16
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/interfaces.d.ts +8 -0
- package/lib/pools.d.ts +41 -5
- package/lib/pools.js +357 -69
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +42 -29
- package/package.json +1 -1
package/lib/utils.d.ts
CHANGED
|
@@ -20,5 +20,6 @@ export declare const _ensureAllowance: (coins: string[], amounts: ethers.BigNumb
|
|
|
20
20
|
export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: string[], spender: string) => Promise<number>;
|
|
21
21
|
export declare const ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<string[]>;
|
|
22
22
|
export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
|
|
23
|
-
export declare const getCrvRate: () => Promise<number>;
|
|
24
23
|
export declare const _getUsdRate: (assetId: string) => Promise<number>;
|
|
24
|
+
export declare const _getStatsUrl: (isCrypto?: boolean) => string;
|
|
25
|
+
export declare const getPoolList: () => string[];
|
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.
|
|
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;
|
|
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"));
|
|
@@ -72,12 +72,12 @@ var BN = function (val) { return new bignumber_js_1.default(val); };
|
|
|
72
72
|
exports.BN = BN;
|
|
73
73
|
var toBN = function (n, decimals) {
|
|
74
74
|
if (decimals === void 0) { decimals = 18; }
|
|
75
|
-
return (0, exports.BN)(ethers_1.ethers.utils.formatUnits(n, decimals))
|
|
75
|
+
return (0, exports.BN)(ethers_1.ethers.utils.formatUnits(n, decimals));
|
|
76
76
|
};
|
|
77
77
|
exports.toBN = toBN;
|
|
78
78
|
var toStringFromBN = function (bn, decimals) {
|
|
79
79
|
if (decimals === void 0) { decimals = 18; }
|
|
80
|
-
return bn.
|
|
80
|
+
return bn.toFixed(decimals);
|
|
81
81
|
};
|
|
82
82
|
exports.toStringFromBN = toStringFromBN;
|
|
83
83
|
var fromBN = function (bn, decimals) {
|
|
@@ -373,41 +373,39 @@ var getPoolNameBySwapAddress = function (swapAddress) {
|
|
|
373
373
|
})[0][0];
|
|
374
374
|
};
|
|
375
375
|
exports.getPoolNameBySwapAddress = getPoolNameBySwapAddress;
|
|
376
|
-
var _crvRateCache = {
|
|
377
|
-
'rate': 0,
|
|
378
|
-
'time': 0,
|
|
379
|
-
};
|
|
380
|
-
var getCrvRate = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
381
|
-
var crvAddress, response;
|
|
382
|
-
return __generator(this, function (_a) {
|
|
383
|
-
switch (_a.label) {
|
|
384
|
-
case 0:
|
|
385
|
-
crvAddress = "0xd533a949740bb3306d119cc777fa900ba034cd52";
|
|
386
|
-
crvAddress = crvAddress.toLowerCase();
|
|
387
|
-
if (!(_crvRateCache.time + 60000 < Date.now())) return [3 /*break*/, 2];
|
|
388
|
-
return [4 /*yield*/, axios_1.default.get("https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=".concat(crvAddress, "&vs_currencies=usd"))];
|
|
389
|
-
case 1:
|
|
390
|
-
response = _a.sent();
|
|
391
|
-
_crvRateCache['rate'] = response.data[crvAddress]['usd'];
|
|
392
|
-
_crvRateCache['time'] = Date.now();
|
|
393
|
-
_a.label = 2;
|
|
394
|
-
case 2: return [2 /*return*/, _crvRateCache['rate']];
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
}); };
|
|
398
|
-
exports.getCrvRate = getCrvRate;
|
|
399
376
|
var _usdRatesCache = {};
|
|
400
377
|
var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
401
|
-
var url, response;
|
|
378
|
+
var chainName, url, response;
|
|
402
379
|
var _a;
|
|
403
380
|
return __generator(this, function (_b) {
|
|
404
381
|
switch (_b.label) {
|
|
405
382
|
case 0:
|
|
383
|
+
if (assetId === 'USD' || (curve_1.curve.chainId === 137 && (assetId.toLowerCase() === curve_2.COINS.am3crv.toLowerCase())))
|
|
384
|
+
return [2 /*return*/, 1];
|
|
385
|
+
chainName = {
|
|
386
|
+
1: 'ethereum',
|
|
387
|
+
137: 'polygon-pos',
|
|
388
|
+
1337: 'ethereum',
|
|
389
|
+
}[curve_1.curve.chainId];
|
|
390
|
+
if (chainName === undefined) {
|
|
391
|
+
throw Error('curve object is not initialized');
|
|
392
|
+
}
|
|
393
|
+
assetId = {
|
|
394
|
+
'EUR': curve_2.COINS.eurt,
|
|
395
|
+
'BTC': 'bitcoin',
|
|
396
|
+
'ETH': 'ethereum',
|
|
397
|
+
'LINK': 'link',
|
|
398
|
+
}[assetId] || assetId;
|
|
406
399
|
assetId = (0, exports.isEth)(assetId) ? "ethereum" : assetId.toLowerCase();
|
|
400
|
+
// No EURT on Coingecko Polygon
|
|
401
|
+
if (assetId.toLowerCase() === curve_2.COINS.eurt.toLowerCase()) {
|
|
402
|
+
chainName = 'ethereum';
|
|
403
|
+
assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
|
|
404
|
+
}
|
|
407
405
|
if (!((((_a = _usdRatesCache[assetId]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 600000 < Date.now())) return [3 /*break*/, 2];
|
|
408
|
-
url = assetId.toLowerCase()
|
|
406
|
+
url = ['bitcoin', 'ethereum', 'link'].includes(assetId.toLowerCase()) ?
|
|
409
407
|
"https://api.coingecko.com/api/v3/simple/price?ids=".concat(assetId, "&vs_currencies=usd") :
|
|
410
|
-
"https://api.coingecko.com/api/v3/simple/token_price/
|
|
408
|
+
"https://api.coingecko.com/api/v3/simple/token_price/".concat(chainName, "?contract_addresses=").concat(assetId, "&vs_currencies=usd");
|
|
411
409
|
return [4 /*yield*/, axios_1.default.get(url)];
|
|
412
410
|
case 1:
|
|
413
411
|
response = _b.sent();
|
|
@@ -418,3 +416,18 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
418
416
|
});
|
|
419
417
|
}); };
|
|
420
418
|
exports._getUsdRate = _getUsdRate;
|
|
419
|
+
var _getStatsUrl = function (isCrypto) {
|
|
420
|
+
if (isCrypto === void 0) { isCrypto = false; }
|
|
421
|
+
if (curve_1.curve.chainId === 1 || curve_1.curve.chainId === 1337) {
|
|
422
|
+
return isCrypto ? "https://stats.curve.fi/raw-stats-crypto/apys.json" : "https://stats.curve.fi/raw-stats/apys.json";
|
|
423
|
+
}
|
|
424
|
+
else if (curve_1.curve.chainId === 137) {
|
|
425
|
+
return "https://stats.curve.fi/raw-stats-polygon/apys.json";
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
throw Error("Unsupported network id".concat(curve_1.curve.chainId));
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
exports._getStatsUrl = _getStatsUrl;
|
|
432
|
+
var getPoolList = function () { return Object.keys(curve_1.POOLS_DATA); };
|
|
433
|
+
exports.getPoolList = getPoolList;
|