@curvefi/api 2.16.1 → 2.16.3
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/lib/factory/factory-api.js +3 -4
- package/lib/index.d.ts +2 -2
- package/lib/pools/PoolTemplate.js +2 -0
- package/lib/pools/utils.d.ts +1 -1
- package/lib/pools/utils.js +63 -68
- package/package.json +1 -1
|
@@ -65,7 +65,6 @@ var ethers_1 = require("ethers");
|
|
|
65
65
|
var ethcall_1 = require("ethcall");
|
|
66
66
|
var gauge_factory_json_1 = __importDefault(require("../constants/abis/gauge_factory.json"));
|
|
67
67
|
var gauge_child_json_1 = __importDefault(require("../constants/abis/gauge_child.json"));
|
|
68
|
-
var gauge_rewards_only_json_1 = __importDefault(require("../constants/abis/gauge_rewards_only.json"));
|
|
69
68
|
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
70
69
|
var factory_crypto_pool_2_json_1 = __importDefault(require("../constants/abis/factory-crypto/factory-crypto-pool-2.json"));
|
|
71
70
|
var constants_1 = require("./constants");
|
|
@@ -109,8 +108,8 @@ function setFactoryGaugeContracts(rawPoolList) {
|
|
|
109
108
|
if (pool.gaugeAddress) {
|
|
110
109
|
var addr = pool.gaugeAddress.toLowerCase();
|
|
111
110
|
_this.contracts[addr] = {
|
|
112
|
-
contract: new ethers_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default :
|
|
113
|
-
multicallContract: new ethcall_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default :
|
|
111
|
+
contract: new ethers_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default, _this.signer || _this.provider),
|
|
112
|
+
multicallContract: new ethcall_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default),
|
|
114
113
|
};
|
|
115
114
|
}
|
|
116
115
|
});
|
|
@@ -310,7 +309,7 @@ function getFactoryPoolsDataFromApi(isCrypto) {
|
|
|
310
309
|
underlying_decimals: coinDecimals,
|
|
311
310
|
wrapped_decimals: coinDecimals,
|
|
312
311
|
swap_abi: implementationABIDict[pool.implementationAddress],
|
|
313
|
-
gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default :
|
|
312
|
+
gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
314
313
|
};
|
|
315
314
|
}
|
|
316
315
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -32,8 +32,8 @@ declare const curve: {
|
|
|
32
32
|
getPoolList: () => string[];
|
|
33
33
|
getFactoryPoolList: () => string[];
|
|
34
34
|
getCryptoFactoryPoolList: () => string[];
|
|
35
|
-
getUserPoolList: (address?: string
|
|
36
|
-
getUserLiquidityUSD: (pools: string[], address?: string
|
|
35
|
+
getUserPoolList: (address?: string) => Promise<string[]>;
|
|
36
|
+
getUserLiquidityUSD: (pools: string[], address?: string) => Promise<string[]>;
|
|
37
37
|
PoolTemplate: typeof PoolTemplate;
|
|
38
38
|
getPool: (poolId: string) => PoolTemplate;
|
|
39
39
|
getUsdRate: (coin: string) => Promise<number>;
|
|
@@ -1116,6 +1116,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1116
1116
|
};
|
|
1117
1117
|
}
|
|
1118
1118
|
PoolTemplate.prototype.rewardsOnly = function () {
|
|
1119
|
+
if (curve_1.curve.chainId === 2222)
|
|
1120
|
+
return true; // TODO remove this for Kava
|
|
1119
1121
|
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1120
1122
|
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1121
1123
|
var gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
package/lib/pools/utils.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { ethers } from "ethers";
|
|
|
2
2
|
export declare const getPoolList: () => string[];
|
|
3
3
|
export declare const getFactoryPoolList: () => string[];
|
|
4
4
|
export declare const getCryptoFactoryPoolList: () => string[];
|
|
5
|
-
export declare const _getUserLpBalances: (pools: string[], address
|
|
5
|
+
export declare const _getUserLpBalances: (pools: string[], address: string, useCache: boolean) => Promise<ethers.BigNumber[]>;
|
|
6
6
|
export declare const getUserPoolList: (address?: string) => Promise<string[]>;
|
|
7
7
|
export declare const getUserLiquidityUSD: (pools: string[], address?: string) => Promise<string[]>;
|
package/lib/pools/utils.js
CHANGED
|
@@ -57,29 +57,18 @@ exports.getFactoryPoolList = getFactoryPoolList;
|
|
|
57
57
|
var getCryptoFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA); };
|
|
58
58
|
exports.getCryptoFactoryPoolList = getCryptoFactoryPoolList;
|
|
59
59
|
var _userLpBalance = {};
|
|
60
|
-
var _isUserLpBalanceExpired = function (address, poolId) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var _d;
|
|
67
|
-
return __generator(this, function (_e) {
|
|
68
|
-
switch (_e.label) {
|
|
60
|
+
var _isUserLpBalanceExpired = function (address, poolId) { var _a, _b; return (((_b = (_a = _userLpBalance[address]) === null || _a === void 0 ? void 0 : _a[poolId]) === null || _b === void 0 ? void 0 : _b.time) || 0) + 600000 < Date.now(); };
|
|
61
|
+
var _getUserLpBalances = function (pools, address, useCache) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
+
var poolsToFetch, calls, _i, poolsToFetch_1, poolId, pool, _rawBalances, _a, poolsToFetch_2, poolId, pool, _balance, _lpBalances, _b, pools_1, poolId;
|
|
63
|
+
var _c;
|
|
64
|
+
return __generator(this, function (_d) {
|
|
65
|
+
switch (_d.label) {
|
|
69
66
|
case 0:
|
|
70
|
-
|
|
71
|
-
address = curve_1.curve.signerAddress;
|
|
72
|
-
address = address;
|
|
73
|
-
poolsToFetch = [];
|
|
74
|
-
for (_i = 0, pools_1 = pools; _i < pools_1.length; _i++) {
|
|
75
|
-
poolId = pools_1[_i];
|
|
76
|
-
if (_isUserLpBalanceExpired(address, poolId))
|
|
77
|
-
poolsToFetch.push(poolId);
|
|
78
|
-
}
|
|
67
|
+
poolsToFetch = useCache ? pools.filter(function (poolId) { return _isUserLpBalanceExpired(address, poolId); }) : pools;
|
|
79
68
|
if (!(poolsToFetch.length > 0)) return [3 /*break*/, 2];
|
|
80
69
|
calls = [];
|
|
81
|
-
for (
|
|
82
|
-
poolId = poolsToFetch_1[
|
|
70
|
+
for (_i = 0, poolsToFetch_1 = poolsToFetch; _i < poolsToFetch_1.length; _i++) {
|
|
71
|
+
poolId = poolsToFetch_1[_i];
|
|
83
72
|
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
84
73
|
calls.push(curve_1.curve.contracts[pool.lpToken].multicallContract.balanceOf(address));
|
|
85
74
|
if (pool.gauge !== ethers_1.ethers.constants.AddressZero)
|
|
@@ -87,9 +76,9 @@ var _getUserLpBalances = function (pools, address) { return __awaiter(void 0, vo
|
|
|
87
76
|
}
|
|
88
77
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
89
78
|
case 1:
|
|
90
|
-
_rawBalances =
|
|
91
|
-
for (
|
|
92
|
-
poolId = poolsToFetch_2[
|
|
79
|
+
_rawBalances = _d.sent();
|
|
80
|
+
for (_a = 0, poolsToFetch_2 = poolsToFetch; _a < poolsToFetch_2.length; _a++) {
|
|
81
|
+
poolId = poolsToFetch_2[_a];
|
|
93
82
|
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
94
83
|
_balance = _rawBalances.shift();
|
|
95
84
|
if (pool.gauge !== ethers_1.ethers.constants.AddressZero)
|
|
@@ -98,61 +87,67 @@ var _getUserLpBalances = function (pools, address) { return __awaiter(void 0, vo
|
|
|
98
87
|
_userLpBalance[address] = {};
|
|
99
88
|
_userLpBalance[address][poolId] = { '_lpBalance': _balance, 'time': Date.now() };
|
|
100
89
|
}
|
|
101
|
-
|
|
90
|
+
_d.label = 2;
|
|
102
91
|
case 2:
|
|
103
92
|
_lpBalances = [];
|
|
104
|
-
for (
|
|
105
|
-
poolId =
|
|
106
|
-
_lpBalances.push((
|
|
93
|
+
for (_b = 0, pools_1 = pools; _b < pools_1.length; _b++) {
|
|
94
|
+
poolId = pools_1[_b];
|
|
95
|
+
_lpBalances.push((_c = _userLpBalance[address]) === null || _c === void 0 ? void 0 : _c[poolId]._lpBalance);
|
|
107
96
|
}
|
|
108
97
|
return [2 /*return*/, _lpBalances];
|
|
109
98
|
}
|
|
110
99
|
});
|
|
111
100
|
}); };
|
|
112
101
|
exports._getUserLpBalances = _getUserLpBalances;
|
|
113
|
-
var getUserPoolList = function (address) {
|
|
114
|
-
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
102
|
+
var getUserPoolList = function (address) {
|
|
103
|
+
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
104
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
105
|
+
var pools, _lpBalances, userPoolList, i;
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
switch (_a.label) {
|
|
108
|
+
case 0:
|
|
109
|
+
pools = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
|
|
110
|
+
return [4 /*yield*/, (0, exports._getUserLpBalances)(pools, address, false)];
|
|
111
|
+
case 1:
|
|
112
|
+
_lpBalances = _a.sent();
|
|
113
|
+
userPoolList = [];
|
|
114
|
+
for (i = 0; i < pools.length; i++) {
|
|
115
|
+
if (_lpBalances[i].gt(0)) {
|
|
116
|
+
userPoolList.push(pools[i]);
|
|
117
|
+
}
|
|
126
118
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
119
|
+
return [2 /*return*/, userPoolList];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
130
122
|
});
|
|
131
|
-
}
|
|
123
|
+
};
|
|
132
124
|
exports.getUserPoolList = getUserPoolList;
|
|
133
|
-
var getUserLiquidityUSD = function (pools, address) {
|
|
134
|
-
|
|
135
|
-
return
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
125
|
+
var getUserLiquidityUSD = function (pools, address) {
|
|
126
|
+
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
127
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
128
|
+
var _lpBalances, userLiquidityUSD, i, pool, price;
|
|
129
|
+
return __generator(this, function (_a) {
|
|
130
|
+
switch (_a.label) {
|
|
131
|
+
case 0: return [4 /*yield*/, (0, exports._getUserLpBalances)(pools, address, true)];
|
|
132
|
+
case 1:
|
|
133
|
+
_lpBalances = _a.sent();
|
|
134
|
+
userLiquidityUSD = [];
|
|
135
|
+
i = 0;
|
|
136
|
+
_a.label = 2;
|
|
137
|
+
case 2:
|
|
138
|
+
if (!(i < pools.length)) return [3 /*break*/, 5];
|
|
139
|
+
pool = (0, poolConstructor_1.getPool)(pools[i]);
|
|
140
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(pool.lpToken)];
|
|
141
|
+
case 3:
|
|
142
|
+
price = _a.sent();
|
|
143
|
+
userLiquidityUSD.push((0, utils_1.toBN)(_lpBalances[i]).times(price).toFixed(8));
|
|
144
|
+
_a.label = 4;
|
|
145
|
+
case 4:
|
|
146
|
+
i++;
|
|
147
|
+
return [3 /*break*/, 2];
|
|
148
|
+
case 5: return [2 /*return*/, userLiquidityUSD];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
156
151
|
});
|
|
157
|
-
}
|
|
152
|
+
};
|
|
158
153
|
exports.getUserLiquidityUSD = getUserLiquidityUSD;
|