@curvefi/api 2.28.3 → 2.30.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 +36 -10
- package/lib/boosting.js +4 -4
- package/lib/constants/coins/ethereum.js +1 -2
- package/lib/constants/pools/ethereum.js +26 -2
- package/lib/curve.d.ts +12 -6
- package/lib/curve.js +155 -117
- package/lib/external-api.d.ts +11 -1
- package/lib/external-api.js +13 -9
- package/lib/factory/constants.js +8 -0
- package/lib/factory/deploy.js +1 -1
- package/lib/factory/factory-api.js +2 -0
- package/lib/factory/factory-crypto.d.ts +1 -1
- package/lib/factory/factory-crypto.js +77 -175
- package/lib/factory/factory.d.ts +1 -1
- package/lib/factory/factory.js +98 -210
- package/lib/index.d.ts +18 -15
- package/lib/index.js +10 -53
- package/lib/interfaces.d.ts +3 -1
- package/lib/pools/PoolTemplate.js +2 -2
- package/lib/pools/utils.d.ts +0 -3
- package/lib/pools/utils.js +4 -10
- package/lib/utils.d.ts +10 -5
- package/lib/utils.js +199 -112
- package/package.json +1 -1
package/lib/interfaces.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { Contract as MulticallContract, Provider as MulticallProvider } from "et
|
|
|
3
3
|
export interface IDict<T> {
|
|
4
4
|
[index: string]: T;
|
|
5
5
|
}
|
|
6
|
-
export type INetworkName = "ethereum" | "polygon" | "avalanche";
|
|
6
|
+
export type INetworkName = "ethereum" | "optimism" | "xdai" | "polygon" | "fantom" | "moonbeam" | "kava" | "arbitrum" | "celo" | "avalanche" | "aurora";
|
|
7
|
+
export type IChainId = 1 | 10 | 100 | 137 | 250 | 1284 | 2222 | 42161 | 42220 | 43114 | 1313161554;
|
|
7
8
|
export type REFERENCE_ASSET = 'USD' | 'EUR' | 'BTC' | 'ETH' | 'LINK' | 'CRYPTO' | 'OTHER';
|
|
8
9
|
export interface IPoolData {
|
|
9
10
|
name: string;
|
|
@@ -16,6 +17,7 @@ export interface IPoolData {
|
|
|
16
17
|
deposit_address?: string;
|
|
17
18
|
sCurveRewards_address?: string;
|
|
18
19
|
reward_contract?: string;
|
|
20
|
+
implementation_address?: string;
|
|
19
21
|
is_plain?: boolean;
|
|
20
22
|
is_lending?: boolean;
|
|
21
23
|
is_meta?: boolean;
|
|
@@ -230,7 +230,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
230
230
|
network = curve_1.curve.constants.NETWORK_NAME;
|
|
231
231
|
return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
232
232
|
case 4:
|
|
233
|
-
poolsData = (_e.sent());
|
|
233
|
+
poolsData = (_e.sent()).poolsData;
|
|
234
234
|
poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
|
|
235
235
|
if (!poolData)
|
|
236
236
|
throw Error("Can't get Volume for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
@@ -268,7 +268,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
268
268
|
network = curve_1.curve.constants.NETWORK_NAME;
|
|
269
269
|
return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
270
270
|
case 3:
|
|
271
|
-
poolsData = (_d.sent());
|
|
271
|
+
poolsData = (_d.sent()).poolsData;
|
|
272
272
|
poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
|
|
273
273
|
if (!poolData)
|
|
274
274
|
throw Error("Can't get base APY for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
package/lib/pools/utils.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { IDict } from "../interfaces";
|
|
2
|
-
export declare const getPoolList: () => string[];
|
|
3
|
-
export declare const getFactoryPoolList: () => string[];
|
|
4
|
-
export declare const getCryptoFactoryPoolList: () => string[];
|
|
5
2
|
export declare const getUserPoolListByLiquidity: (address?: string) => Promise<string[]>;
|
|
6
3
|
export declare const getUserLiquidityUSD: (pools: string[], address?: string) => Promise<string[]>;
|
|
7
4
|
export declare const getUserPoolListByClaimable: (address?: string) => Promise<string[]>;
|
package/lib/pools/utils.js
CHANGED
|
@@ -59,19 +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._getAmplificationCoefficientsFromApi = exports.getUserPoolList = exports.getUserClaimable = exports.getUserPoolListByClaimable = exports.getUserLiquidityUSD = exports.getUserPoolListByLiquidity =
|
|
62
|
+
exports._getAmplificationCoefficientsFromApi = exports.getUserPoolList = exports.getUserClaimable = exports.getUserPoolListByClaimable = exports.getUserLiquidityUSD = exports.getUserPoolListByLiquidity = void 0;
|
|
63
63
|
var ethers_1 = require("ethers");
|
|
64
64
|
var poolConstructor_1 = require("./poolConstructor");
|
|
65
65
|
var curve_1 = require("../curve");
|
|
66
66
|
var utils_1 = require("../utils");
|
|
67
67
|
var external_api_1 = require("../external-api");
|
|
68
68
|
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
69
|
-
var getPoolList = function () { return Object.keys(curve_1.curve.constants.POOLS_DATA); };
|
|
70
|
-
exports.getPoolList = getPoolList;
|
|
71
|
-
var getFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.FACTORY_POOLS_DATA); };
|
|
72
|
-
exports.getFactoryPoolList = getFactoryPoolList;
|
|
73
|
-
var getCryptoFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA); };
|
|
74
|
-
exports.getCryptoFactoryPoolList = getCryptoFactoryPoolList;
|
|
75
69
|
// _userLpBalance: { address: { poolId: { _lpBalance: 0, time: 0 } } }
|
|
76
70
|
var _userLpBalanceCache = {};
|
|
77
71
|
var _isUserLpBalanceCacheExpired = function (address, poolId) { var _a, _b; return (((_b = (_a = _userLpBalanceCache[address]) === null || _a === void 0 ? void 0 : _a[poolId]) === null || _b === void 0 ? void 0 : _b.time) || 0) + 600000 < Date.now(); };
|
|
@@ -122,7 +116,7 @@ var getUserPoolListByLiquidity = function (address) {
|
|
|
122
116
|
return __generator(this, function (_a) {
|
|
123
117
|
switch (_a.label) {
|
|
124
118
|
case 0:
|
|
125
|
-
pools = __spreadArray(__spreadArray(__spreadArray([],
|
|
119
|
+
pools = __spreadArray(__spreadArray(__spreadArray([], curve_1.curve.getPoolList(), true), curve_1.curve.getFactoryPoolList(), true), curve_1.curve.getCryptoFactoryPoolList(), true);
|
|
126
120
|
return [4 /*yield*/, _getUserLpBalances(pools, address, false)];
|
|
127
121
|
case 1:
|
|
128
122
|
_lpBalances = _a.sent();
|
|
@@ -419,7 +413,7 @@ var getUserPoolListByClaimable = function (address) {
|
|
|
419
413
|
return __generator(this, function (_a) {
|
|
420
414
|
switch (_a.label) {
|
|
421
415
|
case 0:
|
|
422
|
-
pools = __spreadArray(__spreadArray(__spreadArray([],
|
|
416
|
+
pools = __spreadArray(__spreadArray(__spreadArray([], curve_1.curve.getPoolList(), true), curve_1.curve.getFactoryPoolList(), true), curve_1.curve.getCryptoFactoryPoolList(), true);
|
|
423
417
|
return [4 /*yield*/, _getUserClaimable(pools, address, false)];
|
|
424
418
|
case 1:
|
|
425
419
|
_claimable = _a.sent();
|
|
@@ -480,7 +474,7 @@ var getUserPoolList = function (address, useApi) {
|
|
|
480
474
|
return __generator(this, function (_b) {
|
|
481
475
|
switch (_b.label) {
|
|
482
476
|
case 0:
|
|
483
|
-
pools = __spreadArray(__spreadArray(__spreadArray([],
|
|
477
|
+
pools = __spreadArray(__spreadArray(__spreadArray([], curve_1.curve.getPoolList(), true), curve_1.curve.getFactoryPoolList(), true), curve_1.curve.getCryptoFactoryPoolList(), true);
|
|
484
478
|
return [4 /*yield*/, Promise.all([
|
|
485
479
|
_getUserLpBalances(pools, address, false),
|
|
486
480
|
useApi ? _getUserClaimableUseApi(pools, address, false) : _getUserClaimable(pools, address, false),
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { IDict, IRewardFromApi } from './interfaces';
|
|
3
|
+
import { IChainId, IDict, INetworkName, IRewardFromApi } from './interfaces';
|
|
4
4
|
export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
5
5
|
export declare const MAX_ALLOWANCE: ethers.BigNumber;
|
|
6
6
|
export declare const _cutZeros: (strn: string) => string;
|
|
@@ -22,16 +22,21 @@ export declare const getBalances: (coins: string[], ...addresses: string[] | str
|
|
|
22
22
|
export declare const _getAllowance: (coins: string[], address: string, spender: string) => Promise<ethers.BigNumber[]>;
|
|
23
23
|
export declare const getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
24
24
|
export declare const hasAllowance: (coins: string[], amounts: (number | string)[], address: string, spender: string) => Promise<boolean>;
|
|
25
|
-
export declare const _ensureAllowance: (coins: string[], amounts: ethers.BigNumber[], spender: string) => Promise<string[]>;
|
|
26
|
-
export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (number | string)[], spender: string) => Promise<number>;
|
|
27
|
-
export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string) => Promise<string[]>;
|
|
25
|
+
export declare const _ensureAllowance: (coins: string[], amounts: ethers.BigNumber[], spender: string, isMax?: boolean) => Promise<string[]>;
|
|
26
|
+
export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<number>;
|
|
27
|
+
export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<string[]>;
|
|
28
28
|
export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
|
|
29
29
|
export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
|
|
30
30
|
export declare const _getCrvApyFromApi: () => Promise<IDict<[number, number]>>;
|
|
31
31
|
export declare const _getRewardsFromApi: () => Promise<IDict<IRewardFromApi[]>>;
|
|
32
32
|
export declare const _getUsdRate: (assetId: string) => Promise<number>;
|
|
33
33
|
export declare const getUsdRate: (coin: string) => Promise<number>;
|
|
34
|
-
export declare const getTVL: (
|
|
34
|
+
export declare const getTVL: (network?: INetworkName | IChainId) => Promise<number>;
|
|
35
|
+
export declare const getVolume: (network?: INetworkName | IChainId) => Promise<{
|
|
36
|
+
totalVolume: number;
|
|
37
|
+
cryptoVolume: number;
|
|
38
|
+
cryptoShare: number;
|
|
39
|
+
}>;
|
|
35
40
|
export declare const _setContracts: (address: string, abi: any) => void;
|
|
36
41
|
export declare const _get_small_x: (_x: ethers.BigNumber, _y: ethers.BigNumber, x_decimals: number, y_decimals: number) => BigNumber;
|
|
37
42
|
export declare const _get_price_impact: (_x: ethers.BigNumber, _y: ethers.BigNumber, _small_x: ethers.BigNumber, _small_y: ethers.BigNumber, x_decimals: number, y_decimals: number) => BigNumber;
|
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.getCoinsData = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getRewardsFromApi = 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;
|
|
62
|
+
exports.getCoinsData = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getVolume = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getRewardsFromApi = 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");
|
|
@@ -301,104 +301,115 @@ var hasAllowance = function (coins, amounts, address, spender) { return __awaite
|
|
|
301
301
|
});
|
|
302
302
|
}); };
|
|
303
303
|
exports.hasAllowance = hasAllowance;
|
|
304
|
-
var _ensureAllowance = function (coins, amounts, spender
|
|
305
|
-
|
|
306
|
-
return
|
|
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
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
304
|
+
var _ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
305
|
+
if (isMax === void 0) { isMax = true; }
|
|
306
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
307
|
+
var address, allowance, txHashes, i, contract, _approveAmount, gasLimit_1, _a, _b, gasLimit, _c, _d;
|
|
308
|
+
return __generator(this, function (_e) {
|
|
309
|
+
switch (_e.label) {
|
|
310
|
+
case 0:
|
|
311
|
+
address = curve_1.curve.signerAddress;
|
|
312
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coins, address, spender)];
|
|
313
|
+
case 1:
|
|
314
|
+
allowance = _e.sent();
|
|
315
|
+
txHashes = [];
|
|
316
|
+
i = 0;
|
|
317
|
+
_e.label = 2;
|
|
318
|
+
case 2:
|
|
319
|
+
if (!(i < allowance.length)) return [3 /*break*/, 10];
|
|
320
|
+
if (!allowance[i].lt(amounts[i])) return [3 /*break*/, 9];
|
|
321
|
+
contract = curve_1.curve.contracts[coins[i]].contract;
|
|
322
|
+
_approveAmount = isMax ? exports.MAX_ALLOWANCE : amounts[i];
|
|
323
|
+
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
324
|
+
case 3:
|
|
325
|
+
_e.sent();
|
|
326
|
+
if (!allowance[i].gt(ethers_1.ethers.BigNumber.from(0))) return [3 /*break*/, 6];
|
|
327
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.constantOptions)];
|
|
328
|
+
case 4:
|
|
329
|
+
gasLimit_1 = (_e.sent()).mul(130).div(100);
|
|
330
|
+
_b = (_a = txHashes).push;
|
|
331
|
+
return [4 /*yield*/, contract.approve(spender, ethers_1.ethers.BigNumber.from(0), __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_1 }))];
|
|
332
|
+
case 5:
|
|
333
|
+
_b.apply(_a, [(_e.sent()).hash]);
|
|
334
|
+
_e.label = 6;
|
|
335
|
+
case 6: return [4 /*yield*/, contract.estimateGas.approve(spender, _approveAmount, curve_1.curve.constantOptions)];
|
|
336
|
+
case 7:
|
|
337
|
+
gasLimit = (_e.sent()).mul(130).div(100);
|
|
338
|
+
_d = (_c = txHashes).push;
|
|
339
|
+
return [4 /*yield*/, contract.approve(spender, _approveAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
340
|
+
case 8:
|
|
341
|
+
_d.apply(_c, [(_e.sent()).hash]);
|
|
342
|
+
_e.label = 9;
|
|
343
|
+
case 9:
|
|
344
|
+
i++;
|
|
345
|
+
return [3 /*break*/, 2];
|
|
346
|
+
case 10: return [2 /*return*/, txHashes];
|
|
347
|
+
}
|
|
348
|
+
});
|
|
345
349
|
});
|
|
346
|
-
}
|
|
350
|
+
};
|
|
347
351
|
exports._ensureAllowance = _ensureAllowance;
|
|
348
352
|
// coins can be either addresses or symbols
|
|
349
|
-
var ensureAllowanceEstimateGas = function (coins, amounts, spender
|
|
350
|
-
|
|
351
|
-
return
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
353
|
+
var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax) {
|
|
354
|
+
if (isMax === void 0) { isMax = true; }
|
|
355
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
356
|
+
var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _approveAmount, _a, _b;
|
|
357
|
+
return __generator(this, function (_c) {
|
|
358
|
+
switch (_c.label) {
|
|
359
|
+
case 0:
|
|
360
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
361
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
362
|
+
_amounts = amounts.map(function (a, i) { return (0, exports.parseUnits)(a, decimals[i]); });
|
|
363
|
+
address = curve_1.curve.signerAddress;
|
|
364
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
365
|
+
case 1:
|
|
366
|
+
allowance = _c.sent();
|
|
367
|
+
gas = 0;
|
|
368
|
+
i = 0;
|
|
369
|
+
_c.label = 2;
|
|
370
|
+
case 2:
|
|
371
|
+
if (!(i < allowance.length)) return [3 /*break*/, 7];
|
|
372
|
+
if (!allowance[i].lt(_amounts[i])) return [3 /*break*/, 6];
|
|
373
|
+
contract = curve_1.curve.contracts[coinAddresses[i]].contract;
|
|
374
|
+
_approveAmount = isMax ? exports.MAX_ALLOWANCE : _amounts[i];
|
|
375
|
+
if (!allowance[i].gt(ethers_1.ethers.BigNumber.from(0))) return [3 /*break*/, 4];
|
|
376
|
+
_a = gas;
|
|
377
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.constantOptions)];
|
|
378
|
+
case 3:
|
|
379
|
+
gas = _a + (_c.sent()).toNumber();
|
|
380
|
+
_c.label = 4;
|
|
381
|
+
case 4:
|
|
382
|
+
_b = gas;
|
|
383
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, _approveAmount, curve_1.curve.constantOptions)];
|
|
384
|
+
case 5:
|
|
385
|
+
gas = _b + (_c.sent()).toNumber();
|
|
386
|
+
_c.label = 6;
|
|
387
|
+
case 6:
|
|
388
|
+
i++;
|
|
389
|
+
return [3 /*break*/, 2];
|
|
390
|
+
case 7: return [2 /*return*/, gas];
|
|
391
|
+
}
|
|
392
|
+
});
|
|
385
393
|
});
|
|
386
|
-
}
|
|
394
|
+
};
|
|
387
395
|
exports.ensureAllowanceEstimateGas = ensureAllowanceEstimateGas;
|
|
388
396
|
// coins can be either addresses or symbols
|
|
389
|
-
var ensureAllowance = function (coins, amounts, spender
|
|
390
|
-
|
|
391
|
-
return
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
397
|
+
var ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
398
|
+
if (isMax === void 0) { isMax = true; }
|
|
399
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
400
|
+
var coinAddresses, decimals, _amounts;
|
|
401
|
+
return __generator(this, function (_a) {
|
|
402
|
+
switch (_a.label) {
|
|
403
|
+
case 0:
|
|
404
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
405
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
406
|
+
_amounts = amounts.map(function (a, i) { return (0, exports.parseUnits)(a, decimals[i]); });
|
|
407
|
+
return [4 /*yield*/, (0, exports._ensureAllowance)(coinAddresses, _amounts, spender, isMax)];
|
|
408
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
409
|
+
}
|
|
410
|
+
});
|
|
400
411
|
});
|
|
401
|
-
}
|
|
412
|
+
};
|
|
402
413
|
exports.ensureAllowance = ensureAllowance;
|
|
403
414
|
var getPoolNameBySwapAddress = function (swapAddress) {
|
|
404
415
|
var poolsData = __assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA);
|
|
@@ -408,6 +419,16 @@ var getPoolNameBySwapAddress = function (swapAddress) {
|
|
|
408
419
|
})[0][0];
|
|
409
420
|
};
|
|
410
421
|
exports.getPoolNameBySwapAddress = getPoolNameBySwapAddress;
|
|
422
|
+
var _getTokenAddressBySwapAddress = function (swapAddress) {
|
|
423
|
+
var poolsData = __assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA);
|
|
424
|
+
var res = Object.entries(poolsData).filter(function (_a) {
|
|
425
|
+
var _ = _a[0], poolData = _a[1];
|
|
426
|
+
return poolData.swap_address.toLowerCase() === swapAddress.toLowerCase();
|
|
427
|
+
});
|
|
428
|
+
if (res.length === 0)
|
|
429
|
+
return "";
|
|
430
|
+
return res[0][1].token_address;
|
|
431
|
+
};
|
|
411
432
|
var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
412
433
|
var network, promises, allTypesExtendedPoolData, priceDict, _i, allTypesExtendedPoolData_1, extendedPoolData, _a, _b, pool, lpTokenAddress, totalSupply, _c, _d, coin, _e, _f, coin;
|
|
413
434
|
var _g, _h;
|
|
@@ -608,27 +629,39 @@ var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void 0, func
|
|
|
608
629
|
});
|
|
609
630
|
}); };
|
|
610
631
|
exports.getUsdRate = getUsdRate;
|
|
611
|
-
var
|
|
612
|
-
if (
|
|
632
|
+
var _getNetworkName = function (network) {
|
|
633
|
+
if (network === void 0) { network = curve_1.curve.chainId; }
|
|
634
|
+
if (typeof network === "number" && curve_1.NETWORK_CONSTANTS[network]) {
|
|
635
|
+
return curve_1.NETWORK_CONSTANTS[network].NAME;
|
|
636
|
+
}
|
|
637
|
+
else if (typeof network === "string" && Object.values(curve_1.NETWORK_CONSTANTS).map(function (n) { return n.NAME; }).includes(network)) {
|
|
638
|
+
return network;
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
throw Error("Wrong network name or id: ".concat(network));
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
var _getChainId = function (network) {
|
|
645
|
+
if (network === void 0) { network = curve_1.curve.chainId; }
|
|
646
|
+
if (typeof network === "number" && curve_1.NETWORK_CONSTANTS[network]) {
|
|
647
|
+
return network;
|
|
648
|
+
}
|
|
649
|
+
else if (typeof network === "string" && Object.values(curve_1.NETWORK_CONSTANTS).map(function (n) { return n.NAME; }).includes(network)) {
|
|
650
|
+
var idx = Object.values(curve_1.NETWORK_CONSTANTS).map(function (n) { return n.NAME; }).indexOf(network);
|
|
651
|
+
return Number(Object.keys(curve_1.NETWORK_CONSTANTS)[idx]);
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
throw Error("Wrong network name or id: ".concat(network));
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
var getTVL = function (network) {
|
|
658
|
+
if (network === void 0) { network = curve_1.curve.chainId; }
|
|
613
659
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
614
|
-
var
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
switch (_b.label) {
|
|
660
|
+
var promises, allTypesExtendedPoolData;
|
|
661
|
+
return __generator(this, function (_a) {
|
|
662
|
+
switch (_a.label) {
|
|
618
663
|
case 0:
|
|
619
|
-
network = (
|
|
620
|
-
1: "ethereum",
|
|
621
|
-
10: 'optimism',
|
|
622
|
-
100: 'xdai',
|
|
623
|
-
137: "polygon",
|
|
624
|
-
250: "fantom",
|
|
625
|
-
1284: "moonbeam",
|
|
626
|
-
2222: 'kava',
|
|
627
|
-
42220: 'celo',
|
|
628
|
-
43114: "avalanche",
|
|
629
|
-
42161: "arbitrum",
|
|
630
|
-
1313161554: "aurora",
|
|
631
|
-
}[chainId]) !== null && _a !== void 0 ? _a : "ethereum";
|
|
664
|
+
network = _getNetworkName(network);
|
|
632
665
|
promises = [
|
|
633
666
|
(0, external_api_1._getPoolsFromApi)(network, "main"),
|
|
634
667
|
(0, external_api_1._getPoolsFromApi)(network, "crypto"),
|
|
@@ -637,13 +670,67 @@ var getTVL = function (chainId) {
|
|
|
637
670
|
];
|
|
638
671
|
return [4 /*yield*/, Promise.all(promises)];
|
|
639
672
|
case 1:
|
|
640
|
-
allTypesExtendedPoolData =
|
|
673
|
+
allTypesExtendedPoolData = _a.sent();
|
|
641
674
|
return [2 /*return*/, allTypesExtendedPoolData.reduce(function (sum, data) { var _a, _b; return sum + ((_b = (_a = data.tvl) !== null && _a !== void 0 ? _a : data.tvlAll) !== null && _b !== void 0 ? _b : 0); }, 0)];
|
|
642
675
|
}
|
|
643
676
|
});
|
|
644
677
|
});
|
|
645
678
|
};
|
|
646
679
|
exports.getTVL = getTVL;
|
|
680
|
+
var getVolume = function (network) {
|
|
681
|
+
if (network === void 0) { network = curve_1.curve.chainId; }
|
|
682
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
683
|
+
var chainId, _a, mainPoolsData, factoryPoolsData, volume, id, _i, factoryPoolsData_1, pool, lpToken, lpPrice, _b, _c, totalVolume, cryptoVolume, cryptoShare;
|
|
684
|
+
var _d;
|
|
685
|
+
return __generator(this, function (_e) {
|
|
686
|
+
switch (_e.label) {
|
|
687
|
+
case 0:
|
|
688
|
+
network = _getNetworkName(network);
|
|
689
|
+
if (!["moonbeam", "kava", "celo", "aurora"].includes(network)) return [3 /*break*/, 8];
|
|
690
|
+
chainId = _getChainId(network);
|
|
691
|
+
if (curve_1.curve.chainId !== chainId)
|
|
692
|
+
throw Error("To get volume for Moonbeam, Kava, Celo or Aurora connect to the network first");
|
|
693
|
+
return [4 /*yield*/, Promise.all([
|
|
694
|
+
(0, external_api_1._getLegacyAPYsAndVolumes)(network),
|
|
695
|
+
(0, external_api_1._getFactoryAPYsAndVolumes)(network),
|
|
696
|
+
])];
|
|
697
|
+
case 1:
|
|
698
|
+
_a = _e.sent(), mainPoolsData = _a[0], factoryPoolsData = _a[1];
|
|
699
|
+
volume = 0;
|
|
700
|
+
for (id in mainPoolsData) {
|
|
701
|
+
volume += (_d = mainPoolsData[id].volume) !== null && _d !== void 0 ? _d : 0;
|
|
702
|
+
}
|
|
703
|
+
_i = 0, factoryPoolsData_1 = factoryPoolsData;
|
|
704
|
+
_e.label = 2;
|
|
705
|
+
case 2:
|
|
706
|
+
if (!(_i < factoryPoolsData_1.length)) return [3 /*break*/, 7];
|
|
707
|
+
pool = factoryPoolsData_1[_i];
|
|
708
|
+
lpToken = _getTokenAddressBySwapAddress(pool.poolAddress);
|
|
709
|
+
if (!lpToken) return [3 /*break*/, 4];
|
|
710
|
+
return [4 /*yield*/, (0, exports._getUsdRate)(lpToken)];
|
|
711
|
+
case 3:
|
|
712
|
+
_b = _e.sent();
|
|
713
|
+
return [3 /*break*/, 5];
|
|
714
|
+
case 4:
|
|
715
|
+
_b = 0;
|
|
716
|
+
_e.label = 5;
|
|
717
|
+
case 5:
|
|
718
|
+
lpPrice = _b;
|
|
719
|
+
volume += pool.volume * lpPrice;
|
|
720
|
+
_e.label = 6;
|
|
721
|
+
case 6:
|
|
722
|
+
_i++;
|
|
723
|
+
return [3 /*break*/, 2];
|
|
724
|
+
case 7: return [2 /*return*/, { totalVolume: volume, cryptoVolume: 0, cryptoShare: 0 }];
|
|
725
|
+
case 8: return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
726
|
+
case 9:
|
|
727
|
+
_c = _e.sent(), totalVolume = _c.totalVolume, cryptoVolume = _c.cryptoVolume, cryptoShare = _c.cryptoShare;
|
|
728
|
+
return [2 /*return*/, { totalVolume: totalVolume, cryptoVolume: cryptoVolume, cryptoShare: cryptoShare }];
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
exports.getVolume = getVolume;
|
|
647
734
|
var _setContracts = function (address, abi) {
|
|
648
735
|
curve_1.curve.contracts[address] = {
|
|
649
736
|
contract: new ethers_1.Contract(address, abi, curve_1.curve.signer || curve_1.curve.provider),
|