@curvefi/api 2.16.3 → 2.18.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 +180 -0
- package/lib/constants/abis/curve_lp_token_v5.json +444 -0
- package/lib/constants/abis/factory.json +0 -107
- package/lib/constants/abis/ren/meta_zap.json +195 -0
- package/lib/constants/coins/ethereum.js +4 -4
- package/lib/constants/pools/ethereum.js +3 -3
- package/lib/constants/pools/fantom.js +2 -2
- package/lib/curve.d.ts +2 -0
- package/lib/curve.js +40 -0
- package/lib/factory/constants.js +4 -3
- package/lib/factory/deploy.d.ts +13 -0
- package/lib/factory/deploy.js +358 -0
- package/lib/factory/factory-api.js +0 -17
- package/lib/factory/factory-crypto.d.ts +1 -1
- package/lib/factory/factory-crypto.js +60 -20
- package/lib/factory/factory.d.ts +1 -1
- package/lib/factory/factory.js +61 -22
- package/lib/index.d.ts +28 -0
- package/lib/index.js +55 -0
- package/lib/pools/PoolTemplate.js +1 -1
- package/lib/pools/utils.d.ts +9 -3
- package/lib/pools/utils.js +258 -13
- package/lib/utils.js +6 -3
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ declare function init(providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy', p
|
|
|
17
17
|
}): Promise<void>;
|
|
18
18
|
declare function fetchFactoryPools(useApi?: boolean): Promise<void>;
|
|
19
19
|
declare function fetchCryptoFactoryPools(useApi?: boolean): Promise<void>;
|
|
20
|
+
declare function fetchRecentlyDeployedFactoryPool(poolAddress: string): Promise<string>;
|
|
21
|
+
declare function fetchRecentlyDeployedCryptoFactoryPool(poolAddress: string): Promise<string>;
|
|
20
22
|
declare function setCustomFeeData(customFeeData: {
|
|
21
23
|
gasPrice?: number;
|
|
22
24
|
maxFeePerGas?: number;
|
|
@@ -42,6 +44,32 @@ declare const curve: {
|
|
|
42
44
|
getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
43
45
|
hasAllowance: (coins: string[], amounts: (string | number)[], address: string, spender: string) => Promise<boolean>;
|
|
44
46
|
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string) => Promise<string[]>;
|
|
47
|
+
factory: {
|
|
48
|
+
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3) => Promise<ethers.ContractTransaction>;
|
|
49
|
+
deployMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number, fee: number, implementationIdx: 0 | 1) => Promise<ethers.ContractTransaction>;
|
|
50
|
+
deployGauge: (poolAddress: string) => Promise<ethers.ContractTransaction>;
|
|
51
|
+
getDeployedPlainPoolAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
52
|
+
getDeployedMetaPoolAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
53
|
+
getDeployedGaugeAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
54
|
+
fetchRecentlyDeployedPool: typeof fetchRecentlyDeployedFactoryPool;
|
|
55
|
+
estimateGas: {
|
|
56
|
+
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3) => Promise<number>;
|
|
57
|
+
deployMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number, fee: number, implementationIdx: 0 | 1) => Promise<number>;
|
|
58
|
+
deployGauge: (poolAddress: string) => Promise<number>;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
cryptoFactory: {
|
|
62
|
+
deployPool: (name: string, symbol: string, coins: string[], A: number, gamma: number, midFee: number, outFee: number, allowedExtraProfit: number, feeGamma: number, adjustmentStep: number, maHalfTime: number, initialPrice: number) => Promise<ethers.ContractTransaction>;
|
|
63
|
+
deployGauge: (poolAddress: string) => Promise<ethers.ContractTransaction>;
|
|
64
|
+
getDeployed: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
65
|
+
getDeployedPoolAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
66
|
+
getDeployedGaugeAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
67
|
+
fetchRecentlyDeployedPool: typeof fetchRecentlyDeployedCryptoFactoryPool;
|
|
68
|
+
estimateGas: {
|
|
69
|
+
deployPool: (name: string, symbol: string, coins: string[], A: number, gamma: number, midFee: number, outFee: number, allowedExtraProfit: number, feeGamma: number, adjustmentStep: number, maHalfTime: number, initialPrice: number) => Promise<number>;
|
|
70
|
+
deployGauge: (poolAddress: string) => Promise<number>;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
45
73
|
estimateGas: {
|
|
46
74
|
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string) => Promise<number>;
|
|
47
75
|
};
|
package/lib/index.js
CHANGED
|
@@ -42,6 +42,7 @@ var router_1 = require("./router");
|
|
|
42
42
|
var curve_1 = require("./curve");
|
|
43
43
|
var boosting_1 = require("./boosting");
|
|
44
44
|
var utils_2 = require("./utils");
|
|
45
|
+
var deploy_1 = require("./factory/deploy");
|
|
45
46
|
function init(providerType, providerSettings, options) {
|
|
46
47
|
if (options === void 0) { options = {}; }
|
|
47
48
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -85,6 +86,26 @@ function fetchCryptoFactoryPools(useApi) {
|
|
|
85
86
|
});
|
|
86
87
|
});
|
|
87
88
|
}
|
|
89
|
+
function fetchRecentlyDeployedFactoryPool(poolAddress) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0: return [4 /*yield*/, curve_1.curve.fetchRecentlyDeployedFactoryPool(poolAddress)];
|
|
94
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function fetchRecentlyDeployedCryptoFactoryPool(poolAddress) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
switch (_a.label) {
|
|
103
|
+
case 0: return [4 /*yield*/, curve_1.curve.fetchRecentlyDeployedCryptoFactoryPool(poolAddress)];
|
|
104
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
88
109
|
function setCustomFeeData(customFeeData) {
|
|
89
110
|
curve_1.curve.setCustomFeeData(customFeeData);
|
|
90
111
|
}
|
|
@@ -108,6 +129,40 @@ var curve = {
|
|
|
108
129
|
getAllowance: utils_2.getAllowance,
|
|
109
130
|
hasAllowance: utils_2.hasAllowance,
|
|
110
131
|
ensureAllowance: utils_2.ensureAllowance,
|
|
132
|
+
factory: {
|
|
133
|
+
deployPlainPool: deploy_1.deployStablePlainPool,
|
|
134
|
+
deployMetaPool: deploy_1.deployStableMetaPool,
|
|
135
|
+
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
136
|
+
return [2 /*return*/, (0, deploy_1.deployGauge)(poolAddress, false)];
|
|
137
|
+
}); }); },
|
|
138
|
+
getDeployedPlainPoolAddress: deploy_1.getDeployedStablePlainPoolAddress,
|
|
139
|
+
getDeployedMetaPoolAddress: deploy_1.getDeployedStableMetaPoolAddress,
|
|
140
|
+
getDeployedGaugeAddress: deploy_1.getDeployedGaugeAddress,
|
|
141
|
+
fetchRecentlyDeployedPool: fetchRecentlyDeployedFactoryPool,
|
|
142
|
+
estimateGas: {
|
|
143
|
+
deployPlainPool: deploy_1.deployStablePlainPoolEstimateGas,
|
|
144
|
+
deployMetaPool: deploy_1.deployStableMetaPoolEstimateGas,
|
|
145
|
+
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
146
|
+
return [2 /*return*/, (0, deploy_1.deployGaugeEstimateGas)(poolAddress, false)];
|
|
147
|
+
}); }); },
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
cryptoFactory: {
|
|
151
|
+
deployPool: deploy_1.deployCryptoPool,
|
|
152
|
+
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
153
|
+
return [2 /*return*/, (0, deploy_1.deployGauge)(poolAddress, true)];
|
|
154
|
+
}); }); },
|
|
155
|
+
getDeployed: deploy_1.getDeployedStablePlainPoolAddress,
|
|
156
|
+
getDeployedPoolAddress: deploy_1.getDeployedCryptoPoolAddress,
|
|
157
|
+
getDeployedGaugeAddress: deploy_1.getDeployedGaugeAddress,
|
|
158
|
+
fetchRecentlyDeployedPool: fetchRecentlyDeployedCryptoFactoryPool,
|
|
159
|
+
estimateGas: {
|
|
160
|
+
deployPool: deploy_1.deployCryptoPoolEstimateGas,
|
|
161
|
+
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
162
|
+
return [2 /*return*/, (0, deploy_1.deployGaugeEstimateGas)(poolAddress, true)];
|
|
163
|
+
}); }); },
|
|
164
|
+
},
|
|
165
|
+
},
|
|
111
166
|
estimateGas: {
|
|
112
167
|
ensureAllowance: utils_2.ensureAllowanceEstimateGas,
|
|
113
168
|
},
|
|
@@ -1240,7 +1240,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1240
1240
|
return [4 /*yield*/, curve_1.curve.contracts[this.address].contract.price_scale(curve_1.curve.constantOptions)];
|
|
1241
1241
|
case 1:
|
|
1242
1242
|
priceScaleBN = _c.apply(void 0, [_d.sent()]);
|
|
1243
|
-
return [2 /*return*/, [amount1BN.toFixed(decimals[0]), amount1BN.div(priceScaleBN).toFixed(decimals[1])]];
|
|
1243
|
+
return [2 /*return*/, [(0, utils_1._cutZeros)(amount1BN.toFixed(decimals[0])), (0, utils_1._cutZeros)(amount1BN.div(priceScaleBN).toFixed(decimals[1]))]];
|
|
1244
1244
|
}
|
|
1245
1245
|
});
|
|
1246
1246
|
});
|
package/lib/pools/utils.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { ethers } from "ethers";
|
|
2
1
|
export declare const getPoolList: () => string[];
|
|
3
2
|
export declare const getFactoryPoolList: () => string[];
|
|
4
3
|
export declare const getCryptoFactoryPoolList: () => string[];
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const getUserPoolList: (address?: string) => Promise<string[]>;
|
|
4
|
+
export declare const getUserPoolListByLiquidity: (address?: string) => Promise<string[]>;
|
|
7
5
|
export declare const getUserLiquidityUSD: (pools: string[], address?: string) => Promise<string[]>;
|
|
6
|
+
export declare const getUserPoolListByClaimable: (address?: string) => Promise<string[]>;
|
|
7
|
+
export declare const getUserClaimable: (pools: string[], address?: string) => Promise<{
|
|
8
|
+
token: string;
|
|
9
|
+
symbol: string;
|
|
10
|
+
amount: string;
|
|
11
|
+
price: number;
|
|
12
|
+
}[][]>;
|
|
13
|
+
export declare const getUserPoolList: (address?: string) => Promise<string[]>;
|
package/lib/pools/utils.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -44,27 +55,32 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
44
55
|
}
|
|
45
56
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
57
|
};
|
|
58
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
|
+
};
|
|
47
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.
|
|
62
|
+
exports.getUserPoolList = exports.getUserClaimable = exports.getUserPoolListByClaimable = exports.getUserLiquidityUSD = exports.getUserPoolListByLiquidity = exports.getCryptoFactoryPoolList = exports.getFactoryPoolList = exports.getPoolList = void 0;
|
|
49
63
|
var ethers_1 = require("ethers");
|
|
50
64
|
var poolConstructor_1 = require("./poolConstructor");
|
|
51
65
|
var curve_1 = require("../curve");
|
|
52
66
|
var utils_1 = require("../utils");
|
|
67
|
+
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
53
68
|
var getPoolList = function () { return Object.keys(curve_1.curve.constants.POOLS_DATA); };
|
|
54
69
|
exports.getPoolList = getPoolList;
|
|
55
70
|
var getFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.FACTORY_POOLS_DATA); };
|
|
56
71
|
exports.getFactoryPoolList = getFactoryPoolList;
|
|
57
72
|
var getCryptoFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA); };
|
|
58
73
|
exports.getCryptoFactoryPoolList = getCryptoFactoryPoolList;
|
|
59
|
-
|
|
60
|
-
var
|
|
74
|
+
// _userLpBalance: { address: { poolId: { _lpBalance: 0, time: 0 } } }
|
|
75
|
+
var _userLpBalanceCache = {};
|
|
76
|
+
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(); };
|
|
61
77
|
var _getUserLpBalances = function (pools, address, useCache) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
78
|
var poolsToFetch, calls, _i, poolsToFetch_1, poolId, pool, _rawBalances, _a, poolsToFetch_2, poolId, pool, _balance, _lpBalances, _b, pools_1, poolId;
|
|
63
79
|
var _c;
|
|
64
80
|
return __generator(this, function (_d) {
|
|
65
81
|
switch (_d.label) {
|
|
66
82
|
case 0:
|
|
67
|
-
poolsToFetch = useCache ? pools.filter(function (poolId) { return
|
|
83
|
+
poolsToFetch = useCache ? pools.filter(function (poolId) { return _isUserLpBalanceCacheExpired(address, poolId); }) : pools;
|
|
68
84
|
if (!(poolsToFetch.length > 0)) return [3 /*break*/, 2];
|
|
69
85
|
calls = [];
|
|
70
86
|
for (_i = 0, poolsToFetch_1 = poolsToFetch; _i < poolsToFetch_1.length; _i++) {
|
|
@@ -83,23 +99,22 @@ var _getUserLpBalances = function (pools, address, useCache) { return __awaiter(
|
|
|
83
99
|
_balance = _rawBalances.shift();
|
|
84
100
|
if (pool.gauge !== ethers_1.ethers.constants.AddressZero)
|
|
85
101
|
_balance = _balance.add(_rawBalances.shift());
|
|
86
|
-
if (!
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
if (!_userLpBalanceCache[address])
|
|
103
|
+
_userLpBalanceCache[address] = {};
|
|
104
|
+
_userLpBalanceCache[address][poolId] = { '_lpBalance': _balance, 'time': Date.now() };
|
|
89
105
|
}
|
|
90
106
|
_d.label = 2;
|
|
91
107
|
case 2:
|
|
92
108
|
_lpBalances = [];
|
|
93
109
|
for (_b = 0, pools_1 = pools; _b < pools_1.length; _b++) {
|
|
94
110
|
poolId = pools_1[_b];
|
|
95
|
-
_lpBalances.push((_c =
|
|
111
|
+
_lpBalances.push((_c = _userLpBalanceCache[address]) === null || _c === void 0 ? void 0 : _c[poolId]._lpBalance);
|
|
96
112
|
}
|
|
97
113
|
return [2 /*return*/, _lpBalances];
|
|
98
114
|
}
|
|
99
115
|
});
|
|
100
116
|
}); };
|
|
101
|
-
|
|
102
|
-
var getUserPoolList = function (address) {
|
|
117
|
+
var getUserPoolListByLiquidity = function (address) {
|
|
103
118
|
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
104
119
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
105
120
|
var pools, _lpBalances, userPoolList, i;
|
|
@@ -107,7 +122,7 @@ var getUserPoolList = function (address) {
|
|
|
107
122
|
switch (_a.label) {
|
|
108
123
|
case 0:
|
|
109
124
|
pools = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
|
|
110
|
-
return [4 /*yield*/,
|
|
125
|
+
return [4 /*yield*/, _getUserLpBalances(pools, address, false)];
|
|
111
126
|
case 1:
|
|
112
127
|
_lpBalances = _a.sent();
|
|
113
128
|
userPoolList = [];
|
|
@@ -121,14 +136,14 @@ var getUserPoolList = function (address) {
|
|
|
121
136
|
});
|
|
122
137
|
});
|
|
123
138
|
};
|
|
124
|
-
exports.
|
|
139
|
+
exports.getUserPoolListByLiquidity = getUserPoolListByLiquidity;
|
|
125
140
|
var getUserLiquidityUSD = function (pools, address) {
|
|
126
141
|
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
127
142
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
128
143
|
var _lpBalances, userLiquidityUSD, i, pool, price;
|
|
129
144
|
return __generator(this, function (_a) {
|
|
130
145
|
switch (_a.label) {
|
|
131
|
-
case 0: return [4 /*yield*/,
|
|
146
|
+
case 0: return [4 /*yield*/, _getUserLpBalances(pools, address, true)];
|
|
132
147
|
case 1:
|
|
133
148
|
_lpBalances = _a.sent();
|
|
134
149
|
userLiquidityUSD = [];
|
|
@@ -151,3 +166,233 @@ var getUserLiquidityUSD = function (pools, address) {
|
|
|
151
166
|
});
|
|
152
167
|
};
|
|
153
168
|
exports.getUserLiquidityUSD = getUserLiquidityUSD;
|
|
169
|
+
// _userClaimable: { address: { poolId: { rewards: [ { token: '0x111...', 'symbol': 'TST', '', 'amount': 0 } ], time: 0 } }
|
|
170
|
+
var _userClaimableCache = {};
|
|
171
|
+
var _isUserClaimableCacheExpired = function (address, poolId) { var _a, _b; return (((_b = (_a = _userClaimableCache[address]) === null || _a === void 0 ? void 0 : _a[poolId]) === null || _b === void 0 ? void 0 : _b.time) || 0) + 600000 < Date.now(); };
|
|
172
|
+
var _getUserClaimable = function (pools, address, useCache) { return __awaiter(void 0, void 0, void 0, function () {
|
|
173
|
+
var poolsToFetch, hasCrvReward, _i, poolsToFetch_3, poolId, pool, gaugeContract, rewardCount, _a, poolsToFetch_4, poolId, pool, gaugeContract, rewardTokenCalls, i, pool, count, gaugeContract, rewardContract, rewardMulticallContract, method, rawRewardTokens, rewardTokens, i, j, rewardAddress, rewardInfoCalls, i, poolId, pool, gaugeContract, gaugeMulticallContract, _b, _c, token, tokenMulticallContract, rawRewardInfo, i, poolId, pool, gaugeContract, token, symbol, decimals, _amount, amount, _d, _e, token, symbol, decimals, _amount, _claimedAmount, amount, _claimable, _f, pools_2, poolId;
|
|
174
|
+
var _g;
|
|
175
|
+
var _h;
|
|
176
|
+
return __generator(this, function (_j) {
|
|
177
|
+
switch (_j.label) {
|
|
178
|
+
case 0:
|
|
179
|
+
poolsToFetch = useCache ? pools.filter(function (poolId) { return _isUserClaimableCacheExpired(address, poolId); }) : pools;
|
|
180
|
+
if (!(poolsToFetch.length > 0)) return [3 /*break*/, 3];
|
|
181
|
+
hasCrvReward = [];
|
|
182
|
+
for (_i = 0, poolsToFetch_3 = poolsToFetch; _i < poolsToFetch_3.length; _i++) {
|
|
183
|
+
poolId = poolsToFetch_3[_i];
|
|
184
|
+
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
185
|
+
if (curve_1.curve.chainId === 2222 || pool.gauge === ethers_1.ethers.constants.AddressZero) { // TODO remove this for Kava
|
|
186
|
+
hasCrvReward.push(false);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
190
|
+
hasCrvReward.push('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
191
|
+
}
|
|
192
|
+
rewardCount = [];
|
|
193
|
+
for (_a = 0, poolsToFetch_4 = poolsToFetch; _a < poolsToFetch_4.length; _a++) {
|
|
194
|
+
poolId = poolsToFetch_4[_a];
|
|
195
|
+
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
196
|
+
if (pool.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
197
|
+
rewardCount.push(0);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
201
|
+
if ("reward_tokens(uint256)" in gaugeContract) { // gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
202
|
+
rewardCount.push(8);
|
|
203
|
+
}
|
|
204
|
+
else if ('claimable_reward(address)' in gaugeContract) { // gauge_synthetix
|
|
205
|
+
rewardCount.push(-1);
|
|
206
|
+
}
|
|
207
|
+
else { // gauge
|
|
208
|
+
rewardCount.push(0);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
rewardTokenCalls = [];
|
|
212
|
+
for (i = 0; i < poolsToFetch.length; i++) {
|
|
213
|
+
pool = (0, poolConstructor_1.getPool)(poolsToFetch[i]);
|
|
214
|
+
if (rewardCount[i] !== -1) { // no_gauge, gauge, gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
215
|
+
for (count = 0; count < rewardCount[i]; count++) {
|
|
216
|
+
gaugeContract = curve_1.curve.contracts[pool.gauge].multicallContract;
|
|
217
|
+
rewardTokenCalls.push(gaugeContract.reward_tokens(count));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else { // gauge_synthetix
|
|
221
|
+
rewardCount[i] = 1;
|
|
222
|
+
rewardContract = curve_1.curve.contracts[pool.sRewardContract].contract;
|
|
223
|
+
rewardMulticallContract = curve_1.curve.contracts[pool.sRewardContract].multicallContract;
|
|
224
|
+
method = "snx()" in rewardContract ? "snx" : "rewardsToken" // susd, tbtc : dusd, musd, rsv, sbtc
|
|
225
|
+
;
|
|
226
|
+
rewardTokenCalls.push(rewardMulticallContract[method]());
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(rewardTokenCalls)];
|
|
230
|
+
case 1:
|
|
231
|
+
rawRewardTokens = (_j.sent()).map(function (t) { return t.toLowerCase(); });
|
|
232
|
+
rewardTokens = {};
|
|
233
|
+
for (i = 0; i < poolsToFetch.length; i++) {
|
|
234
|
+
rewardTokens[poolsToFetch[i]] = [];
|
|
235
|
+
for (j = 0; j < rewardCount[i]; j++) {
|
|
236
|
+
rewardAddress = rawRewardTokens.shift();
|
|
237
|
+
if (rewardAddress === ethers_1.ethers.constants.AddressZero)
|
|
238
|
+
continue;
|
|
239
|
+
rewardTokens[poolsToFetch[i]].push(rewardAddress);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
rewardInfoCalls = [];
|
|
243
|
+
for (i = 0; i < poolsToFetch.length; i++) {
|
|
244
|
+
poolId = poolsToFetch[i];
|
|
245
|
+
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
246
|
+
if (pool.gauge === ethers_1.ethers.constants.AddressZero)
|
|
247
|
+
continue;
|
|
248
|
+
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
249
|
+
gaugeMulticallContract = curve_1.curve.contracts[pool.gauge].multicallContract;
|
|
250
|
+
if (hasCrvReward[i]) {
|
|
251
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
|
|
252
|
+
}
|
|
253
|
+
for (_b = 0, _c = rewardTokens[poolId]; _b < _c.length; _b++) {
|
|
254
|
+
token = _c[_b];
|
|
255
|
+
(0, utils_1._setContracts)(token, ERC20_json_1.default);
|
|
256
|
+
tokenMulticallContract = curve_1.curve.contracts[token].multicallContract;
|
|
257
|
+
rewardInfoCalls.push(tokenMulticallContract.symbol(), tokenMulticallContract.decimals());
|
|
258
|
+
if ('claimable_reward(address,address)' in gaugeContract) {
|
|
259
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, token));
|
|
260
|
+
}
|
|
261
|
+
else if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
|
|
262
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(rewardInfoCalls)];
|
|
267
|
+
case 2:
|
|
268
|
+
rawRewardInfo = _j.sent();
|
|
269
|
+
for (i = 0; i < poolsToFetch.length; i++) {
|
|
270
|
+
poolId = poolsToFetch[i];
|
|
271
|
+
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
272
|
+
if (!_userClaimableCache[address])
|
|
273
|
+
_userClaimableCache[address] = (_g = {}, _g[poolId] = { rewards: [], time: Date.now() }, _g);
|
|
274
|
+
if (!_userClaimableCache[address][poolId])
|
|
275
|
+
_userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
|
|
276
|
+
if (pool.gauge === ethers_1.ethers.constants.AddressZero)
|
|
277
|
+
continue;
|
|
278
|
+
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
279
|
+
if (hasCrvReward[i]) {
|
|
280
|
+
token = curve_1.curve.constants.ALIASES.crv;
|
|
281
|
+
symbol = 'CRV';
|
|
282
|
+
decimals = 18;
|
|
283
|
+
_amount = rawRewardInfo.shift();
|
|
284
|
+
amount = ethers_1.ethers.utils.formatUnits(_amount, decimals);
|
|
285
|
+
if (Number(amount) > 0)
|
|
286
|
+
_userClaimableCache[address][poolId].rewards.push({ token: token, symbol: symbol, amount: amount });
|
|
287
|
+
}
|
|
288
|
+
for (_d = 0, _e = rewardTokens[poolId]; _d < _e.length; _d++) {
|
|
289
|
+
token = _e[_d];
|
|
290
|
+
symbol = rawRewardInfo.shift();
|
|
291
|
+
decimals = rawRewardInfo.shift();
|
|
292
|
+
_amount = rawRewardInfo.shift();
|
|
293
|
+
if ('claimable_reward(address)' in gaugeContract) {
|
|
294
|
+
_claimedAmount = rawRewardInfo.shift();
|
|
295
|
+
_amount = _amount.sub(_claimedAmount);
|
|
296
|
+
}
|
|
297
|
+
amount = ethers_1.ethers.utils.formatUnits(_amount, decimals);
|
|
298
|
+
if (Number(amount) > 0)
|
|
299
|
+
_userClaimableCache[address][poolId].rewards.push({ token: token, symbol: symbol, amount: amount });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
_j.label = 3;
|
|
303
|
+
case 3:
|
|
304
|
+
_claimable = [];
|
|
305
|
+
for (_f = 0, pools_2 = pools; _f < pools_2.length; _f++) {
|
|
306
|
+
poolId = pools_2[_f];
|
|
307
|
+
_claimable.push((_h = _userClaimableCache[address]) === null || _h === void 0 ? void 0 : _h[poolId].rewards);
|
|
308
|
+
}
|
|
309
|
+
return [2 /*return*/, _claimable];
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}); };
|
|
313
|
+
var getUserPoolListByClaimable = function (address) {
|
|
314
|
+
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
315
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
316
|
+
var pools, _claimable, userPoolList, i;
|
|
317
|
+
return __generator(this, function (_a) {
|
|
318
|
+
switch (_a.label) {
|
|
319
|
+
case 0:
|
|
320
|
+
pools = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
|
|
321
|
+
return [4 /*yield*/, _getUserClaimable(pools, address, false)];
|
|
322
|
+
case 1:
|
|
323
|
+
_claimable = _a.sent();
|
|
324
|
+
userPoolList = [];
|
|
325
|
+
for (i = 0; i < pools.length; i++) {
|
|
326
|
+
if (_claimable[i].length > 0) {
|
|
327
|
+
userPoolList.push(pools[i]);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return [2 /*return*/, userPoolList];
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
exports.getUserPoolListByClaimable = getUserPoolListByClaimable;
|
|
336
|
+
var getUserClaimable = function (pools, address) {
|
|
337
|
+
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
338
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
339
|
+
var _claimable, claimableWithPrice, i, _i, _a, c, price;
|
|
340
|
+
return __generator(this, function (_b) {
|
|
341
|
+
switch (_b.label) {
|
|
342
|
+
case 0: return [4 /*yield*/, _getUserClaimable(pools, address, true)];
|
|
343
|
+
case 1:
|
|
344
|
+
_claimable = _b.sent();
|
|
345
|
+
claimableWithPrice = [];
|
|
346
|
+
i = 0;
|
|
347
|
+
_b.label = 2;
|
|
348
|
+
case 2:
|
|
349
|
+
if (!(i < pools.length)) return [3 /*break*/, 7];
|
|
350
|
+
claimableWithPrice.push([]);
|
|
351
|
+
_i = 0, _a = _claimable[i];
|
|
352
|
+
_b.label = 3;
|
|
353
|
+
case 3:
|
|
354
|
+
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
355
|
+
c = _a[_i];
|
|
356
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(c.token)];
|
|
357
|
+
case 4:
|
|
358
|
+
price = _b.sent();
|
|
359
|
+
claimableWithPrice[claimableWithPrice.length - 1].push(__assign(__assign({}, c), { price: price }));
|
|
360
|
+
_b.label = 5;
|
|
361
|
+
case 5:
|
|
362
|
+
_i++;
|
|
363
|
+
return [3 /*break*/, 3];
|
|
364
|
+
case 6:
|
|
365
|
+
i++;
|
|
366
|
+
return [3 /*break*/, 2];
|
|
367
|
+
case 7: return [2 /*return*/, claimableWithPrice];
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
exports.getUserClaimable = getUserClaimable;
|
|
373
|
+
var getUserPoolList = function (address) {
|
|
374
|
+
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
375
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
376
|
+
var pools, _a, _lpBalances, _claimable, userPoolList, i;
|
|
377
|
+
return __generator(this, function (_b) {
|
|
378
|
+
switch (_b.label) {
|
|
379
|
+
case 0:
|
|
380
|
+
pools = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
|
|
381
|
+
return [4 /*yield*/, Promise.all([
|
|
382
|
+
_getUserLpBalances(pools, address, false),
|
|
383
|
+
_getUserClaimable(pools, address, false),
|
|
384
|
+
])];
|
|
385
|
+
case 1:
|
|
386
|
+
_a = _b.sent(), _lpBalances = _a[0], _claimable = _a[1];
|
|
387
|
+
userPoolList = [];
|
|
388
|
+
for (i = 0; i < pools.length; i++) {
|
|
389
|
+
if (_lpBalances[i].gt(0) || _claimable[i].length > 0) {
|
|
390
|
+
userPoolList.push(pools[i]);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return [2 /*return*/, userPoolList];
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
exports.getUserPoolList = getUserPoolList;
|
package/lib/utils.js
CHANGED
|
@@ -454,7 +454,10 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
454
454
|
var _a, _b;
|
|
455
455
|
return __generator(this, function (_c) {
|
|
456
456
|
switch (_c.label) {
|
|
457
|
-
case 0:
|
|
457
|
+
case 0:
|
|
458
|
+
if (curve_1.curve.chainId === 1 && assetId.toLowerCase() === '0x8762db106b2c2a0bccb3a80d1ed41273552616e8')
|
|
459
|
+
return [2 /*return*/, 0]; // RSR
|
|
460
|
+
return [4 /*yield*/, (0, exports._getUsdPricesFromApi)()];
|
|
458
461
|
case 1:
|
|
459
462
|
pricesFromApi = _c.sent();
|
|
460
463
|
if (assetId.toLowerCase() in pricesFromApi)
|
|
@@ -513,10 +516,10 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
513
516
|
case 2:
|
|
514
517
|
response = _c.sent();
|
|
515
518
|
try {
|
|
516
|
-
_usdRatesCache[assetId] = { 'rate': (_b = response.data[assetId]['usd']) !== null && _b !== void 0 ? _b :
|
|
519
|
+
_usdRatesCache[assetId] = { 'rate': (_b = response.data[assetId]['usd']) !== null && _b !== void 0 ? _b : 0, 'time': Date.now() };
|
|
517
520
|
}
|
|
518
521
|
catch (err) { // TODO pay attention!
|
|
519
|
-
_usdRatesCache[assetId] = { 'rate':
|
|
522
|
+
_usdRatesCache[assetId] = { 'rate': 0, 'time': Date.now() };
|
|
520
523
|
}
|
|
521
524
|
_c.label = 3;
|
|
522
525
|
case 3: return [2 /*return*/, _usdRatesCache[assetId]['rate']];
|