@curvefi/api 2.1.0 → 2.3.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 +2 -0
- package/lib/constants/abis/dusd/sCurveRewards.json +472 -1
- package/lib/constants/abis/gauge_child.json +1039 -0
- package/lib/constants/abis/{gauge_rewards_only.json → minter_child.json} +159 -312
- package/lib/constants/abis/musd/sCurveRewards.json +482 -1
- package/lib/constants/abis/rsv/sCurveRewards.json +472 -1
- package/lib/constants/abis/sbtc/sCurveRewards.json +566 -1
- package/lib/constants/abis/susdv2/sCurveRewards.json +457 -1
- package/lib/constants/abis/tbtc/sCurveRewards.json +472 -1
- package/lib/constants/aliases.d.ts +1 -0
- package/lib/constants/aliases.js +14 -2
- 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 +106 -0
- package/lib/constants/pools/ethereum.js +0 -33
- package/lib/constants/pools/index.d.ts +2 -1
- package/lib/constants/pools/index.js +3 -1
- package/lib/constants/pools/polygon.js +19 -24
- package/lib/constants/utils.js +0 -9
- package/lib/curve.d.ts +5 -1
- package/lib/curve.js +47 -29
- 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 -46
- package/lib/factory/factory-crypto.js +7 -4
- package/lib/factory/factory.js +31 -163
- package/lib/interfaces.d.ts +37 -29
- package/lib/pools/PoolTemplate.d.ts +11 -1
- package/lib/pools/PoolTemplate.js +175 -104
- package/lib/pools/poolConstructor.js +3 -3
- package/lib/router.js +10 -10
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +36 -14
- package/package.json +1 -1
package/lib/interfaces.d.ts
CHANGED
|
@@ -3,33 +3,7 @@ import { Contract as MulticallContract, Provider as MulticallProvider } from "et
|
|
|
3
3
|
export interface IDict<T> {
|
|
4
4
|
[index: string]: T;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
provider: ethers.providers.Web3Provider | ethers.providers.JsonRpcProvider;
|
|
8
|
-
multicallProvider: MulticallProvider;
|
|
9
|
-
signer: ethers.Signer | null;
|
|
10
|
-
signerAddress: string;
|
|
11
|
-
chainId: number;
|
|
12
|
-
contracts: {
|
|
13
|
-
[index: string]: {
|
|
14
|
-
contract: Contract;
|
|
15
|
-
multicallContract: MulticallContract;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
feeData: {
|
|
19
|
-
gasPrice?: number;
|
|
20
|
-
maxFeePerGas?: number;
|
|
21
|
-
maxPriorityFeePerGas?: number;
|
|
22
|
-
};
|
|
23
|
-
constantOptions: {
|
|
24
|
-
gasLimit: number;
|
|
25
|
-
};
|
|
26
|
-
options: {
|
|
27
|
-
gasPrice?: number | ethers.BigNumber;
|
|
28
|
-
maxFeePerGas?: number | ethers.BigNumber;
|
|
29
|
-
maxPriorityFeePerGas?: number | ethers.BigNumber;
|
|
30
|
-
};
|
|
31
|
-
constants: IDict<any>;
|
|
32
|
-
}
|
|
6
|
+
export declare type INetworkName = "ethereum" | "polygon" | "avalanche";
|
|
33
7
|
export declare type REFERENCE_ASSET = 'USD' | 'EUR' | 'BTC' | 'ETH' | 'LINK' | 'CRYPTO' | 'OTHER';
|
|
34
8
|
export interface IPoolData {
|
|
35
9
|
name: string;
|
|
@@ -56,13 +30,47 @@ export interface IPoolData {
|
|
|
56
30
|
underlying_decimals: number[];
|
|
57
31
|
wrapped_decimals: number[];
|
|
58
32
|
use_lending?: boolean[];
|
|
59
|
-
reward_tokens?: string[];
|
|
60
|
-
reward_decimals?: number[];
|
|
61
33
|
swap_abi: any;
|
|
62
34
|
gauge_abi: any;
|
|
63
35
|
deposit_abi?: any;
|
|
64
36
|
sCurveRewards_abi?: any;
|
|
65
37
|
}
|
|
38
|
+
export interface ICurve {
|
|
39
|
+
provider: ethers.providers.Web3Provider | ethers.providers.JsonRpcProvider;
|
|
40
|
+
multicallProvider: MulticallProvider;
|
|
41
|
+
signer: ethers.Signer | null;
|
|
42
|
+
signerAddress: string;
|
|
43
|
+
chainId: number;
|
|
44
|
+
contracts: {
|
|
45
|
+
[index: string]: {
|
|
46
|
+
contract: Contract;
|
|
47
|
+
multicallContract: MulticallContract;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
feeData: {
|
|
51
|
+
gasPrice?: number;
|
|
52
|
+
maxFeePerGas?: number;
|
|
53
|
+
maxPriorityFeePerGas?: number;
|
|
54
|
+
};
|
|
55
|
+
constantOptions: {
|
|
56
|
+
gasLimit: number;
|
|
57
|
+
};
|
|
58
|
+
options: {
|
|
59
|
+
gasPrice?: number | ethers.BigNumber;
|
|
60
|
+
maxFeePerGas?: number | ethers.BigNumber;
|
|
61
|
+
maxPriorityFeePerGas?: number | ethers.BigNumber;
|
|
62
|
+
};
|
|
63
|
+
constants: {
|
|
64
|
+
NETWORK_NAME: INetworkName;
|
|
65
|
+
ALIASES: IDict<string>;
|
|
66
|
+
POOLS_DATA: IDict<IPoolData>;
|
|
67
|
+
FACTORY_POOLS_DATA: IDict<IPoolData>;
|
|
68
|
+
CRYPTO_FACTORY_POOLS_DATA: IDict<IPoolData>;
|
|
69
|
+
COINS: IDict<string>;
|
|
70
|
+
DECIMALS: IDict<number>;
|
|
71
|
+
GAUGES: string[];
|
|
72
|
+
};
|
|
73
|
+
}
|
|
66
74
|
export interface ICoinFromPoolDataApi {
|
|
67
75
|
address: string;
|
|
68
76
|
symbol: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import memoize from "memoizee";
|
|
1
2
|
import { IDict, IReward } from '../interfaces';
|
|
2
3
|
export declare class PoolTemplate {
|
|
3
4
|
id: string;
|
|
@@ -9,6 +10,7 @@ export declare class PoolTemplate {
|
|
|
9
10
|
lpToken: string;
|
|
10
11
|
gauge: string;
|
|
11
12
|
zap: string | null;
|
|
13
|
+
sRewardContract: string | null;
|
|
12
14
|
rewardContract: string | null;
|
|
13
15
|
isPlain: boolean;
|
|
14
16
|
isLending: boolean;
|
|
@@ -25,7 +27,6 @@ export declare class PoolTemplate {
|
|
|
25
27
|
underlyingDecimals: number[];
|
|
26
28
|
wrappedDecimals: number[];
|
|
27
29
|
useLending: boolean[];
|
|
28
|
-
rewardTokens: string[];
|
|
29
30
|
estimateGas: {
|
|
30
31
|
depositApprove: (amounts: (number | string)[]) => Promise<number>;
|
|
31
32
|
deposit: (amounts: (number | string)[]) => Promise<number>;
|
|
@@ -122,6 +123,15 @@ export declare class PoolTemplate {
|
|
|
122
123
|
claimableCrv(address?: string): Promise<string>;
|
|
123
124
|
claimCrvEstimateGas(): Promise<number>;
|
|
124
125
|
claimCrv(): Promise<string>;
|
|
126
|
+
rewardTokens: (() => Promise<{
|
|
127
|
+
token: string;
|
|
128
|
+
symbol: string;
|
|
129
|
+
decimals: number;
|
|
130
|
+
}[]>) & memoize.Memoized<() => Promise<{
|
|
131
|
+
token: string;
|
|
132
|
+
symbol: string;
|
|
133
|
+
decimals: number;
|
|
134
|
+
}[]>>;
|
|
125
135
|
claimableRewards(address?: string): Promise<{
|
|
126
136
|
token: string;
|
|
127
137
|
symbol: string;
|
|
@@ -62,9 +62,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
62
62
|
exports.PoolTemplate = void 0;
|
|
63
63
|
var ethers_1 = require("ethers");
|
|
64
64
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
65
|
+
var memoizee_1 = __importDefault(require("memoizee"));
|
|
65
66
|
var external_api_1 = require("../external-api");
|
|
66
67
|
var utils_1 = require("../utils");
|
|
67
68
|
var curve_1 = require("../curve");
|
|
69
|
+
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
68
70
|
var PoolTemplate = /** @class */ (function () {
|
|
69
71
|
function PoolTemplate(id) {
|
|
70
72
|
var _this = this;
|
|
@@ -119,7 +121,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
119
121
|
switch (_c.label) {
|
|
120
122
|
case 0:
|
|
121
123
|
if (!useApi) return [3 /*break*/, 2];
|
|
122
|
-
network = curve_1.curve.
|
|
124
|
+
network = curve_1.curve.constants.NETWORK_NAME;
|
|
123
125
|
poolType = !this.isFactory && !this.isCrypto ? "main" :
|
|
124
126
|
!this.isFactory ? "crypto" :
|
|
125
127
|
!(this.isCrypto && this.isFactory) ? "factory" :
|
|
@@ -158,7 +160,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
158
160
|
return __generator(this, function (_a) {
|
|
159
161
|
switch (_a.label) {
|
|
160
162
|
case 0:
|
|
161
|
-
network = curve_1.curve.
|
|
163
|
+
network = curve_1.curve.constants.NETWORK_NAME;
|
|
162
164
|
return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
163
165
|
case 1:
|
|
164
166
|
poolsData = (_a.sent());
|
|
@@ -175,7 +177,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
175
177
|
return __generator(this, function (_a) {
|
|
176
178
|
switch (_a.label) {
|
|
177
179
|
case 0:
|
|
178
|
-
network = curve_1.curve.
|
|
180
|
+
network = curve_1.curve.constants.NETWORK_NAME;
|
|
179
181
|
return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
180
182
|
case 1:
|
|
181
183
|
poolsData = (_a.sent());
|
|
@@ -190,36 +192,55 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
190
192
|
});
|
|
191
193
|
}); };
|
|
192
194
|
this.statsTokenApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
193
|
-
var gaugeContract, lpTokenContract, gaugeControllerContract,
|
|
194
|
-
return __generator(this, function (
|
|
195
|
-
switch (
|
|
195
|
+
var totalLiquidityUSD, gaugeContract_1, crvContract, week, currentWeek, inflationRateBN, _a, _c, crvRate_1, apy, gaugeContract, lpTokenContract, gaugeControllerContract, _d, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
|
|
196
|
+
return __generator(this, function (_e) {
|
|
197
|
+
switch (_e.label) {
|
|
196
198
|
case 0:
|
|
197
199
|
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
198
200
|
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
199
|
-
if (curve_1.curve.chainId === 137)
|
|
200
|
-
throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use getRewardsApy instead"));
|
|
201
|
-
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
202
|
-
lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
203
|
-
gaugeControllerContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
204
201
|
return [4 /*yield*/, this.statsTotalLiquidity()];
|
|
205
202
|
case 1:
|
|
206
|
-
totalLiquidityUSD =
|
|
203
|
+
totalLiquidityUSD = _e.sent();
|
|
207
204
|
if (Number(totalLiquidityUSD) === 0)
|
|
208
205
|
return [2 /*return*/, ["0", "0"]];
|
|
206
|
+
if (!(curve_1.curve.chainId !== 1)) return [3 /*break*/, 6];
|
|
207
|
+
gaugeContract_1 = curve_1.curve.contracts[this.gauge].contract;
|
|
208
|
+
crvContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.crv].contract;
|
|
209
|
+
week = 7 * 86400;
|
|
210
|
+
currentWeek = Math.floor(Date.now() / 1000 / week);
|
|
211
|
+
_a = utils_1.toBN;
|
|
212
|
+
return [4 /*yield*/, gaugeContract_1.inflation_rate(currentWeek, curve_1.curve.constantOptions)];
|
|
213
|
+
case 2:
|
|
214
|
+
inflationRateBN = _a.apply(void 0, [_e.sent()]);
|
|
215
|
+
if (!inflationRateBN.eq(0)) return [3 /*break*/, 4];
|
|
216
|
+
_c = utils_1.toBN;
|
|
217
|
+
return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve_1.curve.constantOptions)];
|
|
218
|
+
case 3:
|
|
219
|
+
inflationRateBN = _c.apply(void 0, [_e.sent()]).div(week);
|
|
220
|
+
_e.label = 4;
|
|
221
|
+
case 4: return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.curve.constants.ALIASES.crv)];
|
|
222
|
+
case 5:
|
|
223
|
+
crvRate_1 = _e.sent();
|
|
224
|
+
apy = inflationRateBN.times(31536000).times(crvRate_1).div(Number(totalLiquidityUSD));
|
|
225
|
+
return [2 /*return*/, [apy.times(100).toFixed(4), apy.times(100).toFixed(4)]];
|
|
226
|
+
case 6:
|
|
227
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
228
|
+
lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
229
|
+
gaugeControllerContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
209
230
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
210
231
|
gaugeContract.inflation_rate(),
|
|
211
232
|
gaugeControllerContract.gauge_relative_weight(this.gauge),
|
|
212
233
|
gaugeContract.working_supply(),
|
|
213
234
|
lpTokenContract.totalSupply(),
|
|
214
235
|
])];
|
|
215
|
-
case
|
|
216
|
-
|
|
236
|
+
case 7:
|
|
237
|
+
_d = (_e.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _d[0], weight = _d[1], workingSupply = _d[2], totalSupply = _d[3];
|
|
217
238
|
if (Number(workingSupply) === 0)
|
|
218
239
|
return [2 /*return*/, ["0", "0"]];
|
|
219
240
|
rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
|
|
220
241
|
return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.curve.constants.ALIASES.crv)];
|
|
221
|
-
case
|
|
222
|
-
crvRate =
|
|
242
|
+
case 8:
|
|
243
|
+
crvRate = _e.sent();
|
|
223
244
|
baseApy = rate.times(crvRate);
|
|
224
245
|
boostedApy = baseApy.times(2.5);
|
|
225
246
|
return [2 /*return*/, [baseApy.times(100).toFixed(4), boostedApy.times(100).toFixed(4)]];
|
|
@@ -227,47 +248,47 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
227
248
|
});
|
|
228
249
|
}); };
|
|
229
250
|
this.statsRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
230
|
-
var apy, _i,
|
|
231
|
-
var
|
|
232
|
-
return __generator(this, function (
|
|
233
|
-
switch (
|
|
251
|
+
var apy, rewardTokens, _i, rewardTokens_1, rewardToken, gaugeContract, totalLiquidityUSD, rewardRate, rewardData, periodFinish, inflation, baseApy, network, promises, _a, mainPoolsRewards, allTypesExtendedPoolData, rewards, _c, _d, extendedPoolData, _e, _f, pool;
|
|
252
|
+
var _g;
|
|
253
|
+
return __generator(this, function (_h) {
|
|
254
|
+
switch (_h.label) {
|
|
234
255
|
case 0:
|
|
235
|
-
if (!(curve_1.curve.chainId
|
|
256
|
+
if (![137, 43114].includes(curve_1.curve.chainId)) return [3 /*break*/, 8];
|
|
236
257
|
apy = [];
|
|
237
|
-
|
|
238
|
-
_k.label = 1;
|
|
258
|
+
return [4 /*yield*/, this.rewardTokens()];
|
|
239
259
|
case 1:
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return [4 /*yield*/, this.statsTotalLiquidity()];
|
|
260
|
+
rewardTokens = _h.sent();
|
|
261
|
+
_i = 0, rewardTokens_1 = rewardTokens;
|
|
262
|
+
_h.label = 2;
|
|
244
263
|
case 2:
|
|
245
|
-
|
|
246
|
-
|
|
264
|
+
if (!(_i < rewardTokens_1.length)) return [3 /*break*/, 7];
|
|
265
|
+
rewardToken = rewardTokens_1[_i];
|
|
266
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
267
|
+
return [4 /*yield*/, this.statsTotalLiquidity()];
|
|
247
268
|
case 3:
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return [4 /*yield*/, rewardContract.reward_data(curve_1.curve.constants.ALIASES.crv, curve_1.curve.constantOptions)];
|
|
269
|
+
totalLiquidityUSD = _h.sent();
|
|
270
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken.token)];
|
|
251
271
|
case 4:
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
|
|
255
|
-
return [4 /*yield*/, rewardTokenContract.symbol()];
|
|
272
|
+
rewardRate = _h.sent();
|
|
273
|
+
return [4 /*yield*/, gaugeContract.reward_data(rewardToken.token, curve_1.curve.constantOptions)];
|
|
256
274
|
case 5:
|
|
257
|
-
|
|
275
|
+
rewardData = _h.sent();
|
|
276
|
+
periodFinish = Number(ethers_1.ethers.utils.formatUnits(rewardData.period_finish, 0)) * 1000;
|
|
277
|
+
inflation = (0, utils_1.toBN)(rewardData.rate, rewardToken.decimals);
|
|
278
|
+
baseApy = periodFinish > Date.now() ? inflation.times(31536000).times(rewardRate).div(Number(totalLiquidityUSD)) : (0, utils_1.BN)(0);
|
|
258
279
|
apy.push({
|
|
259
280
|
gaugeAddress: this.gauge.toLowerCase(),
|
|
260
|
-
tokenAddress: rewardToken,
|
|
261
|
-
symbol: symbol,
|
|
281
|
+
tokenAddress: rewardToken.token,
|
|
282
|
+
symbol: rewardToken.symbol,
|
|
262
283
|
apy: Number(baseApy.times(100).toFixed(4)),
|
|
263
284
|
});
|
|
264
|
-
|
|
285
|
+
_h.label = 6;
|
|
265
286
|
case 6:
|
|
266
287
|
_i++;
|
|
267
|
-
return [3 /*break*/,
|
|
288
|
+
return [3 /*break*/, 2];
|
|
268
289
|
case 7: return [2 /*return*/, apy];
|
|
269
290
|
case 8:
|
|
270
|
-
network = curve_1.curve.
|
|
291
|
+
network = curve_1.curve.constants.NETWORK_NAME;
|
|
271
292
|
promises = [
|
|
272
293
|
(0, external_api_1._getMainPoolsGaugeRewards)(),
|
|
273
294
|
(0, external_api_1._getPoolsFromApi)(network, "main"),
|
|
@@ -277,21 +298,87 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
277
298
|
];
|
|
278
299
|
return [4 /*yield*/, Promise.all(promises)];
|
|
279
300
|
case 9:
|
|
280
|
-
|
|
301
|
+
_a = _h.sent(), mainPoolsRewards = _a[0], allTypesExtendedPoolData = _a.slice(1);
|
|
281
302
|
rewards = mainPoolsRewards;
|
|
282
|
-
for (
|
|
283
|
-
extendedPoolData =
|
|
284
|
-
for (
|
|
285
|
-
pool =
|
|
303
|
+
for (_c = 0, _d = allTypesExtendedPoolData; _c < _d.length; _c++) {
|
|
304
|
+
extendedPoolData = _d[_c];
|
|
305
|
+
for (_e = 0, _f = extendedPoolData.poolData; _e < _f.length; _e++) {
|
|
306
|
+
pool = _f[_e];
|
|
286
307
|
if (pool.gaugeAddress && pool.gaugeRewards) {
|
|
287
308
|
rewards[pool.gaugeAddress.toLowerCase()] = pool.gaugeRewards;
|
|
288
309
|
}
|
|
289
310
|
}
|
|
290
311
|
}
|
|
291
|
-
return [2 /*return*/, (
|
|
312
|
+
return [2 /*return*/, (_g = rewards[this.gauge.toLowerCase()]) !== null && _g !== void 0 ? _g : []];
|
|
292
313
|
}
|
|
293
314
|
});
|
|
294
315
|
}); };
|
|
316
|
+
this.rewardTokens = (0, memoizee_1.default)(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
317
|
+
var gaugeContract, gaugeMulticallContract, rewardCount, _a, _c, _d, tokenCalls, i, tokens, tokenInfoCalls, _i, tokens_1, token, tokenMulticallContract, tokenInfo_1, i, rewardContract, method, token, tokenMulticallContract, _e, symbol, decimals;
|
|
318
|
+
return __generator(this, function (_f) {
|
|
319
|
+
switch (_f.label) {
|
|
320
|
+
case 0:
|
|
321
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
322
|
+
return [2 /*return*/, []];
|
|
323
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
324
|
+
gaugeMulticallContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
325
|
+
if (!("reward_tokens(uint256)" in gaugeContract)) return [3 /*break*/, 5];
|
|
326
|
+
rewardCount = 8;
|
|
327
|
+
if (!("reward_count()" in gaugeContract)) return [3 /*break*/, 2];
|
|
328
|
+
_a = Number;
|
|
329
|
+
_d = (_c = ethers_1.ethers.utils).formatUnits;
|
|
330
|
+
return [4 /*yield*/, gaugeContract.reward_count(curve_1.curve.constantOptions)];
|
|
331
|
+
case 1:
|
|
332
|
+
rewardCount = _a.apply(void 0, [_d.apply(_c, [_f.sent(), 0])]);
|
|
333
|
+
_f.label = 2;
|
|
334
|
+
case 2:
|
|
335
|
+
tokenCalls = [];
|
|
336
|
+
for (i = 0; i < rewardCount; i++) {
|
|
337
|
+
tokenCalls.push(gaugeMulticallContract.reward_tokens(i));
|
|
338
|
+
}
|
|
339
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(tokenCalls)];
|
|
340
|
+
case 3:
|
|
341
|
+
tokens = (_f.sent())
|
|
342
|
+
.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })
|
|
343
|
+
.map(function (addr) { return addr.toLowerCase(); });
|
|
344
|
+
tokenInfoCalls = [];
|
|
345
|
+
for (_i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
346
|
+
token = tokens_1[_i];
|
|
347
|
+
(0, utils_1._setContracts)(token, ERC20_json_1.default);
|
|
348
|
+
tokenMulticallContract = curve_1.curve.contracts[token].multicallContract;
|
|
349
|
+
tokenInfoCalls.push(tokenMulticallContract.symbol(), tokenMulticallContract.decimals());
|
|
350
|
+
}
|
|
351
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(tokenInfoCalls)];
|
|
352
|
+
case 4:
|
|
353
|
+
tokenInfo_1 = _f.sent();
|
|
354
|
+
for (i = 0; i < tokens.length; i++) {
|
|
355
|
+
curve_1.curve.constants.DECIMALS[tokens[i]] = tokenInfo_1[(i * 2) + 1];
|
|
356
|
+
}
|
|
357
|
+
return [2 /*return*/, tokens.map(function (token, i) { return ({ token: token, symbol: tokenInfo_1[i * 2], decimals: tokenInfo_1[(i * 2) + 1] }); })];
|
|
358
|
+
case 5:
|
|
359
|
+
if (!('claimable_reward(address)' in gaugeContract)) return [3 /*break*/, 8];
|
|
360
|
+
rewardContract = curve_1.curve.contracts[this.sRewardContract].contract;
|
|
361
|
+
method = "snx()" in rewardContract ? "snx" : "rewardsToken" // susd, tbtc : dusd, musd, rsv, sbtc
|
|
362
|
+
;
|
|
363
|
+
return [4 /*yield*/, rewardContract[method](curve_1.curve.constantOptions)];
|
|
364
|
+
case 6:
|
|
365
|
+
token = (_f.sent()).toLowerCase();
|
|
366
|
+
(0, utils_1._setContracts)(token, ERC20_json_1.default);
|
|
367
|
+
tokenMulticallContract = curve_1.curve.contracts[token].multicallContract;
|
|
368
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
369
|
+
tokenMulticallContract.symbol(),
|
|
370
|
+
tokenMulticallContract.decimals(),
|
|
371
|
+
])];
|
|
372
|
+
case 7:
|
|
373
|
+
_e = _f.sent(), symbol = _e[0], decimals = _e[1];
|
|
374
|
+
return [2 /*return*/, [{ token: token, symbol: symbol, decimals: decimals }]];
|
|
375
|
+
case 8: return [2 /*return*/, []]; // gauge
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}); }, {
|
|
379
|
+
promise: true,
|
|
380
|
+
maxAge: 30 * 60 * 1000, // 30m
|
|
381
|
+
});
|
|
295
382
|
// ---------------- ... ----------------
|
|
296
383
|
this.gaugeMaxBoostedDeposit = function () {
|
|
297
384
|
var addresses = [];
|
|
@@ -637,6 +724,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
637
724
|
this.lpToken = poolData.token_address;
|
|
638
725
|
this.gauge = poolData.gauge_address;
|
|
639
726
|
this.zap = poolData.deposit_address || null;
|
|
727
|
+
this.sRewardContract = poolData.sCurveRewards_address || null;
|
|
640
728
|
this.rewardContract = poolData.reward_contract || null;
|
|
641
729
|
this.isPlain = poolData.is_plain || false;
|
|
642
730
|
this.isLending = poolData.is_lending || false;
|
|
@@ -653,7 +741,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
653
741
|
this.underlyingDecimals = poolData.underlying_decimals;
|
|
654
742
|
this.wrappedDecimals = poolData.wrapped_decimals;
|
|
655
743
|
this.useLending = poolData.use_lending || poolData.underlying_coin_addresses.map(function () { return false; });
|
|
656
|
-
this.rewardTokens = poolData.reward_tokens || [];
|
|
657
744
|
this.estimateGas = {
|
|
658
745
|
depositApprove: this.depositApproveEstimateGas.bind(this),
|
|
659
746
|
deposit: this.depositEstimateGas.bind(this),
|
|
@@ -1091,8 +1178,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1091
1178
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1092
1179
|
throw Error("claimableCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1093
1180
|
}
|
|
1094
|
-
if (curve_1.curve.chainId !== 1)
|
|
1095
|
-
throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use claimableRewards instead"));
|
|
1096
1181
|
address = address || curve_1.curve.signerAddress;
|
|
1097
1182
|
if (!address)
|
|
1098
1183
|
throw Error("Need to connect wallet or pass address into args");
|
|
@@ -1111,8 +1196,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1111
1196
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1112
1197
|
throw Error("claimCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1113
1198
|
}
|
|
1114
|
-
if (curve_1.curve.chainId !== 1)
|
|
1115
|
-
throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use claimRewards instead"));
|
|
1116
1199
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
|
|
1117
1200
|
case 1: return [2 /*return*/, (_a.sent()).toNumber()];
|
|
1118
1201
|
}
|
|
@@ -1121,32 +1204,30 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1121
1204
|
};
|
|
1122
1205
|
PoolTemplate.prototype.claimCrv = function () {
|
|
1123
1206
|
return __awaiter(this, void 0, void 0, function () {
|
|
1124
|
-
var gasLimit;
|
|
1207
|
+
var contract, gasLimit;
|
|
1125
1208
|
return __generator(this, function (_a) {
|
|
1126
1209
|
switch (_a.label) {
|
|
1127
1210
|
case 0:
|
|
1128
1211
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1129
1212
|
throw Error("claimCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1130
1213
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
return [4 /*yield*/, curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
|
|
1214
|
+
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract;
|
|
1215
|
+
return [4 /*yield*/, contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
|
|
1134
1216
|
case 1:
|
|
1135
1217
|
gasLimit = (_a.sent()).mul(130).div(100);
|
|
1136
|
-
return [4 /*yield*/,
|
|
1218
|
+
return [4 /*yield*/, contract.mint(this.gauge, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1137
1219
|
case 2: return [2 /*return*/, (_a.sent()).hash];
|
|
1138
1220
|
}
|
|
1139
1221
|
});
|
|
1140
1222
|
});
|
|
1141
1223
|
};
|
|
1142
1224
|
// TODO 1. Fix aave and saave error
|
|
1143
|
-
// TODO 2. Figure out Synthetix cumulative results
|
|
1144
1225
|
PoolTemplate.prototype.claimableRewards = function (address) {
|
|
1145
1226
|
if (address === void 0) { address = ""; }
|
|
1146
1227
|
return __awaiter(this, void 0, void 0, function () {
|
|
1147
|
-
var gaugeContract, rewards, _i,
|
|
1148
|
-
return __generator(this, function (
|
|
1149
|
-
switch (
|
|
1228
|
+
var gaugeContract, rewardTokens, rewards, _i, rewardTokens_2, rewardToken, amount, _a, _c, rewardToken, _totalAmount, _claimedAmount;
|
|
1229
|
+
return __generator(this, function (_d) {
|
|
1230
|
+
switch (_d.label) {
|
|
1150
1231
|
case 0:
|
|
1151
1232
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1152
1233
|
throw Error("claimableRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1155,56 +1236,46 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1155
1236
|
if (!address)
|
|
1156
1237
|
throw Error("Need to connect wallet or pass address into args");
|
|
1157
1238
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1158
|
-
|
|
1159
|
-
if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 7];
|
|
1160
|
-
_i = 0, _a = this.rewardTokens;
|
|
1161
|
-
_g.label = 1;
|
|
1239
|
+
return [4 /*yield*/, this.rewardTokens()];
|
|
1162
1240
|
case 1:
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1241
|
+
rewardTokens = _d.sent();
|
|
1242
|
+
rewards = [];
|
|
1243
|
+
if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 6];
|
|
1244
|
+
_i = 0, rewardTokens_2 = rewardTokens;
|
|
1245
|
+
_d.label = 2;
|
|
1167
1246
|
case 2:
|
|
1168
|
-
|
|
1169
|
-
|
|
1247
|
+
if (!(_i < rewardTokens_2.length)) return [3 /*break*/, 5];
|
|
1248
|
+
rewardToken = rewardTokens_2[_i];
|
|
1249
|
+
_c = (_a = ethers_1.ethers.utils).formatUnits;
|
|
1250
|
+
return [4 /*yield*/, gaugeContract.claimable_reward(address, rewardToken, curve_1.curve.constantOptions)];
|
|
1170
1251
|
case 3:
|
|
1171
|
-
|
|
1172
|
-
method = curve_1.curve.chainId === 1 ? "claimable_reward" : "claimable_reward_write";
|
|
1173
|
-
_d = (_c = ethers_1.ethers.utils).formatUnits;
|
|
1174
|
-
return [4 /*yield*/, gaugeContract[method](address, rewardToken, curve_1.curve.constantOptions)];
|
|
1175
|
-
case 4:
|
|
1176
|
-
amount = _d.apply(_c, [_g.sent(), decimals]);
|
|
1252
|
+
amount = _c.apply(_a, [_d.sent(), rewardToken.decimals]);
|
|
1177
1253
|
rewards.push({
|
|
1178
|
-
token: rewardToken,
|
|
1179
|
-
symbol: symbol,
|
|
1254
|
+
token: rewardToken.token,
|
|
1255
|
+
symbol: rewardToken.symbol,
|
|
1180
1256
|
amount: amount,
|
|
1181
1257
|
});
|
|
1182
|
-
|
|
1183
|
-
case
|
|
1258
|
+
_d.label = 4;
|
|
1259
|
+
case 4:
|
|
1184
1260
|
_i++;
|
|
1185
|
-
return [3 /*break*/,
|
|
1186
|
-
case
|
|
1261
|
+
return [3 /*break*/, 2];
|
|
1262
|
+
case 5: return [3 /*break*/, 9];
|
|
1263
|
+
case 6:
|
|
1264
|
+
if (!('claimable_reward(address)' in gaugeContract && rewardTokens.length > 0)) return [3 /*break*/, 9];
|
|
1265
|
+
rewardToken = rewardTokens[0];
|
|
1266
|
+
return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
|
|
1187
1267
|
case 7:
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
|
|
1191
|
-
return [4 /*yield*/, rewardTokenContract.symbol()];
|
|
1268
|
+
_totalAmount = _d.sent();
|
|
1269
|
+
return [4 /*yield*/, gaugeContract.claimed_rewards_for(address, curve_1.curve.constantOptions)];
|
|
1192
1270
|
case 8:
|
|
1193
|
-
|
|
1194
|
-
return [4 /*yield*/, rewardTokenContract.decimals()];
|
|
1195
|
-
case 9:
|
|
1196
|
-
decimals = _g.sent();
|
|
1197
|
-
_f = (_e = ethers_1.ethers.utils).formatUnits;
|
|
1198
|
-
return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
|
|
1199
|
-
case 10:
|
|
1200
|
-
amount = _f.apply(_e, [_g.sent(), decimals]);
|
|
1271
|
+
_claimedAmount = _d.sent();
|
|
1201
1272
|
rewards.push({
|
|
1202
|
-
token: rewardToken,
|
|
1203
|
-
symbol: symbol,
|
|
1204
|
-
amount:
|
|
1273
|
+
token: rewardToken.token,
|
|
1274
|
+
symbol: rewardToken.symbol,
|
|
1275
|
+
amount: ethers_1.ethers.utils.formatUnits(_totalAmount.sub(_claimedAmount), rewardToken.decimals),
|
|
1205
1276
|
});
|
|
1206
|
-
|
|
1207
|
-
case
|
|
1277
|
+
_d.label = 9;
|
|
1278
|
+
case 9: return [2 /*return*/, rewards];
|
|
1208
1279
|
}
|
|
1209
1280
|
});
|
|
1210
1281
|
});
|
|
@@ -2182,7 +2253,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2182
2253
|
return [4 /*yield*/, this._swapExpected(i, j, _amount)];
|
|
2183
2254
|
case 1:
|
|
2184
2255
|
_output = _c.sent();
|
|
2185
|
-
target = (0, utils_1.BN)(
|
|
2256
|
+
target = (0, utils_1.BN)(Math.pow(10, 15));
|
|
2186
2257
|
amountIntBN = (0, utils_1.BN)(amount).times(Math.pow(10, inputCoinDecimals));
|
|
2187
2258
|
outputIntBN = (0, utils_1.toBN)(_output, 0);
|
|
2188
2259
|
k = bignumber_js_1.default.min(bignumber_js_1.default.max(target.div(amountIntBN), target.div(outputIntBN)), 0.2);
|
|
@@ -2206,7 +2277,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2206
2277
|
});
|
|
2207
2278
|
};
|
|
2208
2279
|
PoolTemplate.prototype._swapContractAddress = function () {
|
|
2209
|
-
return (this.isCrypto && this.isMeta) || (curve_1.curve.chainId
|
|
2280
|
+
return (this.isCrypto && this.isMeta) || ([137, 43114].includes(curve_1.curve.chainId) && this.isMetaFactory) ? this.zap : this.address;
|
|
2210
2281
|
};
|
|
2211
2282
|
PoolTemplate.prototype.swapIsApproved = function (inputCoin, amount) {
|
|
2212
2283
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -2302,7 +2373,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2302
2373
|
return [4 /*yield*/, this._swapWrappedExpected(i, j, _amount)];
|
|
2303
2374
|
case 1:
|
|
2304
2375
|
_output = _c.sent();
|
|
2305
|
-
target = (0, utils_1.BN)(
|
|
2376
|
+
target = (0, utils_1.BN)(Math.pow(10, 15));
|
|
2306
2377
|
amountIntBN = (0, utils_1.BN)(amount).times(Math.pow(10, inputCoinDecimals));
|
|
2307
2378
|
outputIntBN = (0, utils_1.toBN)(_output, 0);
|
|
2308
2379
|
k = bignumber_js_1.default.min(bignumber_js_1.default.max(target.div(amountIntBN), target.div(outputIntBN)), 0.2);
|
|
@@ -44,7 +44,7 @@ var getPool = function (poolId) {
|
|
|
44
44
|
return Pool;
|
|
45
45
|
}(PoolTemplate_1.PoolTemplate));
|
|
46
46
|
// statsBalances
|
|
47
|
-
if (
|
|
47
|
+
if (poolDummy.isFake) {
|
|
48
48
|
Object.assign(Pool.prototype, poolBalancesMixin_1.poolBalancesAtricrypto3Mixin);
|
|
49
49
|
}
|
|
50
50
|
else if (poolDummy.isMeta) {
|
|
@@ -101,7 +101,7 @@ var getPool = function (poolId) {
|
|
|
101
101
|
Object.assign(Pool.prototype, depositWrappedMixins_1.depositWrapped2argsMixin);
|
|
102
102
|
}
|
|
103
103
|
// withdrawExpected
|
|
104
|
-
if (
|
|
104
|
+
if (poolDummy.isFake) {
|
|
105
105
|
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedAtricrypto3Mixin);
|
|
106
106
|
}
|
|
107
107
|
else if (poolDummy.isMeta) {
|
|
@@ -207,7 +207,7 @@ var getPool = function (poolId) {
|
|
|
207
207
|
if (poolId === 'tricrypto2') {
|
|
208
208
|
Object.assign(Pool.prototype, swapMixins_1.swapTricrypto2Mixin);
|
|
209
209
|
}
|
|
210
|
-
else if (curve_1.curve.chainId
|
|
210
|
+
else if ([137, 43114].includes(curve_1.curve.chainId) && poolDummy.isMetaFactory) {
|
|
211
211
|
Object.assign(Pool.prototype, swapMixins_1.swapMetaFactoryMixin);
|
|
212
212
|
}
|
|
213
213
|
else {
|