@curvefi/api 2.8.0 → 2.8.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/README.md +0 -2
- package/lib/pools/PoolTemplate.d.ts +1 -0
- package/lib/pools/PoolTemplate.js +564 -502
- package/lib/router.js +13 -3
- package/package.json +1 -1
|
@@ -75,9 +75,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
75
75
|
function PoolTemplate(id) {
|
|
76
76
|
var _this = this;
|
|
77
77
|
this.statsParameters = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
78
|
-
var multicallContract, lpMulticallContract, calls, additionalCalls,
|
|
79
|
-
return __generator(this, function (
|
|
80
|
-
switch (
|
|
78
|
+
var multicallContract, lpMulticallContract, calls, additionalCalls, _c, _lpTokenSupply, _virtualPrice, _fee, _adminFee, _A, _gamma, _d, lpTokenSupply, virtualPrice, fee, adminFee, A, gamma, A_PRECISION, _e, _future_A, _initial_A, _future_A_time, _initial_A_time, _f, future_A, initial_A, future_A_time, initial_A_time;
|
|
79
|
+
return __generator(this, function (_g) {
|
|
80
|
+
switch (_g.label) {
|
|
81
81
|
case 0:
|
|
82
82
|
multicallContract = curve_1.curve.contracts[this.address].multicallContract;
|
|
83
83
|
lpMulticallContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
@@ -96,25 +96,25 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
96
96
|
}
|
|
97
97
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
98
98
|
case 1:
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
_c = _g.sent(), _lpTokenSupply = _c[0], _virtualPrice = _c[1], _fee = _c[2], _adminFee = _c[3], _A = _c[4], _gamma = _c[5];
|
|
100
|
+
_d = [
|
|
101
101
|
ethers_1.ethers.utils.formatUnits(_lpTokenSupply),
|
|
102
102
|
ethers_1.ethers.utils.formatUnits(_virtualPrice),
|
|
103
103
|
ethers_1.ethers.utils.formatUnits(_fee, 8),
|
|
104
104
|
ethers_1.ethers.utils.formatUnits(_adminFee.mul(_fee)),
|
|
105
105
|
ethers_1.ethers.utils.formatUnits(_A, 0),
|
|
106
106
|
_gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
|
|
107
|
-
], lpTokenSupply =
|
|
107
|
+
], lpTokenSupply = _d[0], virtualPrice = _d[1], fee = _d[2], adminFee = _d[3], A = _d[4], gamma = _d[5];
|
|
108
108
|
A_PRECISION = curve_1.curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.id) ? 1 : 100;
|
|
109
109
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(additionalCalls)];
|
|
110
110
|
case 2:
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
_e = _g.sent(), _future_A = _e[0], _initial_A = _e[1], _future_A_time = _e[2], _initial_A_time = _e[3];
|
|
112
|
+
_f = [
|
|
113
113
|
_future_A ? String(Number(ethers_1.ethers.utils.formatUnits(_future_A, 0)) / A_PRECISION) : undefined,
|
|
114
114
|
_initial_A ? String(Number(ethers_1.ethers.utils.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined,
|
|
115
115
|
_future_A_time ? Number(ethers_1.ethers.utils.formatUnits(_future_A_time, 0)) * 1000 : undefined,
|
|
116
116
|
_initial_A_time ? Number(ethers_1.ethers.utils.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
|
|
117
|
-
], future_A =
|
|
117
|
+
], future_A = _f[0], initial_A = _f[1], future_A_time = _f[2], initial_A_time = _f[3];
|
|
118
118
|
return [2 /*return*/, { lpTokenSupply: lpTokenSupply, virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, future_A: future_A, initial_A: initial_A, future_A_time: future_A_time, initial_A_time: initial_A_time, gamma: gamma }];
|
|
119
119
|
}
|
|
120
120
|
});
|
|
@@ -122,10 +122,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
122
122
|
this.statsTotalLiquidity = function (useApi) {
|
|
123
123
|
if (useApi === void 0) { useApi = true; }
|
|
124
124
|
return __awaiter(_this, void 0, void 0, function () {
|
|
125
|
-
var network, poolType, poolsData, totalLiquidity_1, balances, promises, _i,
|
|
125
|
+
var network, poolType, poolsData, totalLiquidity_1, balances, promises, _i, _c, addr, prices, totalLiquidity;
|
|
126
126
|
var _this = this;
|
|
127
|
-
return __generator(this, function (
|
|
128
|
-
switch (
|
|
127
|
+
return __generator(this, function (_d) {
|
|
128
|
+
switch (_d.label) {
|
|
129
129
|
case 0:
|
|
130
130
|
if (!useApi) return [3 /*break*/, 2];
|
|
131
131
|
network = curve_1.curve.constants.NETWORK_NAME;
|
|
@@ -135,7 +135,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
135
135
|
"factory-crypto";
|
|
136
136
|
return [4 /*yield*/, (0, external_api_1._getPoolsFromApi)(network, poolType)];
|
|
137
137
|
case 1:
|
|
138
|
-
poolsData = (
|
|
138
|
+
poolsData = (_d.sent()).poolData;
|
|
139
139
|
try {
|
|
140
140
|
totalLiquidity_1 = poolsData.filter(function (data) { return data.address.toLowerCase() === _this.address.toLowerCase(); })[0].usdTotal;
|
|
141
141
|
return [2 /*return*/, String(totalLiquidity_1)];
|
|
@@ -143,18 +143,18 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
143
143
|
catch (err) {
|
|
144
144
|
console.log(err.message);
|
|
145
145
|
}
|
|
146
|
-
|
|
146
|
+
_d.label = 2;
|
|
147
147
|
case 2: return [4 /*yield*/, this.statsUnderlyingBalances()];
|
|
148
148
|
case 3:
|
|
149
|
-
balances =
|
|
149
|
+
balances = _d.sent();
|
|
150
150
|
promises = [];
|
|
151
|
-
for (_i = 0,
|
|
152
|
-
addr =
|
|
151
|
+
for (_i = 0, _c = this.underlyingCoinAddresses; _i < _c.length; _i++) {
|
|
152
|
+
addr = _c[_i];
|
|
153
153
|
promises.push((0, utils_1._getUsdRate)(addr));
|
|
154
154
|
}
|
|
155
155
|
return [4 /*yield*/, Promise.all(promises)];
|
|
156
156
|
case 4:
|
|
157
|
-
prices =
|
|
157
|
+
prices = _d.sent();
|
|
158
158
|
totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
|
|
159
159
|
return [2 /*return*/, totalLiquidity.toFixed(8)];
|
|
160
160
|
}
|
|
@@ -164,13 +164,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
164
164
|
this.statsVolume = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
165
165
|
var network, poolsData, poolData;
|
|
166
166
|
var _this = this;
|
|
167
|
-
return __generator(this, function (
|
|
168
|
-
switch (
|
|
167
|
+
return __generator(this, function (_c) {
|
|
168
|
+
switch (_c.label) {
|
|
169
169
|
case 0:
|
|
170
170
|
network = curve_1.curve.constants.NETWORK_NAME;
|
|
171
171
|
return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
172
172
|
case 1:
|
|
173
|
-
poolsData = (
|
|
173
|
+
poolsData = (_c.sent());
|
|
174
174
|
poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
|
|
175
175
|
if (!poolData)
|
|
176
176
|
throw Error("Can't get base APY for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
@@ -181,13 +181,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
181
181
|
this.statsBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
182
182
|
var network, poolsData, poolData;
|
|
183
183
|
var _this = this;
|
|
184
|
-
return __generator(this, function (
|
|
185
|
-
switch (
|
|
184
|
+
return __generator(this, function (_c) {
|
|
185
|
+
switch (_c.label) {
|
|
186
186
|
case 0:
|
|
187
187
|
network = curve_1.curve.constants.NETWORK_NAME;
|
|
188
188
|
return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
189
189
|
case 1:
|
|
190
|
-
poolsData = (
|
|
190
|
+
poolsData = (_c.sent());
|
|
191
191
|
poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
|
|
192
192
|
if (!poolData)
|
|
193
193
|
throw Error("Can't get base APY for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
@@ -199,15 +199,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
199
199
|
});
|
|
200
200
|
}); };
|
|
201
201
|
this.statsTokenApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
202
|
-
var totalLiquidityUSD, gaugeContract_1, crvContract, week, currentWeek, inflationRateBN,
|
|
203
|
-
return __generator(this, function (
|
|
204
|
-
switch (
|
|
202
|
+
var totalLiquidityUSD, gaugeContract_1, crvContract, week, currentWeek, inflationRateBN, _c, _d, crvRate_1, apy, gaugeContract, lpTokenContract, gaugeControllerContract, _e, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
|
|
203
|
+
return __generator(this, function (_f) {
|
|
204
|
+
switch (_f.label) {
|
|
205
205
|
case 0:
|
|
206
206
|
if (this.rewardsOnly())
|
|
207
207
|
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use getRewardsApy instead"));
|
|
208
208
|
return [4 /*yield*/, this.statsTotalLiquidity()];
|
|
209
209
|
case 1:
|
|
210
|
-
totalLiquidityUSD =
|
|
210
|
+
totalLiquidityUSD = _f.sent();
|
|
211
211
|
if (Number(totalLiquidityUSD) === 0)
|
|
212
212
|
return [2 /*return*/, ["0", "0"]];
|
|
213
213
|
if (!(curve_1.curve.chainId !== 1)) return [3 /*break*/, 6];
|
|
@@ -215,19 +215,19 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
215
215
|
crvContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.crv].contract;
|
|
216
216
|
week = 7 * 86400;
|
|
217
217
|
currentWeek = Math.floor(Date.now() / 1000 / week);
|
|
218
|
-
|
|
218
|
+
_c = utils_1.toBN;
|
|
219
219
|
return [4 /*yield*/, gaugeContract_1.inflation_rate(currentWeek, curve_1.curve.constantOptions)];
|
|
220
220
|
case 2:
|
|
221
|
-
inflationRateBN =
|
|
221
|
+
inflationRateBN = _c.apply(void 0, [_f.sent()]);
|
|
222
222
|
if (!inflationRateBN.eq(0)) return [3 /*break*/, 4];
|
|
223
|
-
|
|
223
|
+
_d = utils_1.toBN;
|
|
224
224
|
return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve_1.curve.constantOptions)];
|
|
225
225
|
case 3:
|
|
226
|
-
inflationRateBN =
|
|
227
|
-
|
|
226
|
+
inflationRateBN = _d.apply(void 0, [_f.sent()]).div(week);
|
|
227
|
+
_f.label = 4;
|
|
228
228
|
case 4: return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.curve.constants.ALIASES.crv)];
|
|
229
229
|
case 5:
|
|
230
|
-
crvRate_1 =
|
|
230
|
+
crvRate_1 = _f.sent();
|
|
231
231
|
apy = inflationRateBN.times(31536000).times(crvRate_1).div(Number(totalLiquidityUSD));
|
|
232
232
|
return [2 /*return*/, [apy.times(100).toFixed(4), apy.times(100).toFixed(4)]];
|
|
233
233
|
case 6:
|
|
@@ -241,13 +241,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
241
241
|
lpTokenContract.totalSupply(),
|
|
242
242
|
])];
|
|
243
243
|
case 7:
|
|
244
|
-
|
|
244
|
+
_e = (_f.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _e[0], weight = _e[1], workingSupply = _e[2], totalSupply = _e[3];
|
|
245
245
|
if (Number(workingSupply) === 0)
|
|
246
246
|
return [2 /*return*/, ["0", "0"]];
|
|
247
247
|
rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
|
|
248
248
|
return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.curve.constants.ALIASES.crv)];
|
|
249
249
|
case 8:
|
|
250
|
-
crvRate =
|
|
250
|
+
crvRate = _f.sent();
|
|
251
251
|
baseApy = rate.times(crvRate);
|
|
252
252
|
boostedApy = baseApy.times(2.5);
|
|
253
253
|
return [2 /*return*/, [baseApy.times(100).toFixed(4), boostedApy.times(100).toFixed(4)]];
|
|
@@ -255,10 +255,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
255
255
|
});
|
|
256
256
|
}); };
|
|
257
257
|
this.statsRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
258
|
-
var apy, rewardTokens, _i, rewardTokens_1, rewardToken, contract, totalLiquidityUSD, rewardRate, rewardData, periodFinish, inflation, baseApy, network, promises,
|
|
259
|
-
var
|
|
260
|
-
return __generator(this, function (
|
|
261
|
-
switch (
|
|
258
|
+
var apy, rewardTokens, _i, rewardTokens_1, rewardToken, contract, totalLiquidityUSD, rewardRate, rewardData, periodFinish, inflation, baseApy, network, promises, _c, mainPoolsRewards, allTypesExtendedPoolData, rewards, _d, _e, extendedPoolData, _f, _g, pool;
|
|
259
|
+
var _h;
|
|
260
|
+
return __generator(this, function (_j) {
|
|
261
|
+
switch (_j.label) {
|
|
262
262
|
case 0:
|
|
263
263
|
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
264
264
|
return [2 /*return*/, []];
|
|
@@ -266,22 +266,22 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
266
266
|
apy = [];
|
|
267
267
|
return [4 /*yield*/, this.rewardTokens()];
|
|
268
268
|
case 1:
|
|
269
|
-
rewardTokens =
|
|
269
|
+
rewardTokens = _j.sent();
|
|
270
270
|
_i = 0, rewardTokens_1 = rewardTokens;
|
|
271
|
-
|
|
271
|
+
_j.label = 2;
|
|
272
272
|
case 2:
|
|
273
273
|
if (!(_i < rewardTokens_1.length)) return [3 /*break*/, 7];
|
|
274
274
|
rewardToken = rewardTokens_1[_i];
|
|
275
275
|
contract = curve_1.curve.contracts[this.sRewardContract || this.gauge].contract;
|
|
276
276
|
return [4 /*yield*/, this.statsTotalLiquidity()];
|
|
277
277
|
case 3:
|
|
278
|
-
totalLiquidityUSD =
|
|
278
|
+
totalLiquidityUSD = _j.sent();
|
|
279
279
|
return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken.token)];
|
|
280
280
|
case 4:
|
|
281
|
-
rewardRate =
|
|
281
|
+
rewardRate = _j.sent();
|
|
282
282
|
return [4 /*yield*/, contract.reward_data(rewardToken.token, curve_1.curve.constantOptions)];
|
|
283
283
|
case 5:
|
|
284
|
-
rewardData =
|
|
284
|
+
rewardData = _j.sent();
|
|
285
285
|
periodFinish = Number(ethers_1.ethers.utils.formatUnits(rewardData.period_finish, 0)) * 1000;
|
|
286
286
|
inflation = (0, utils_1.toBN)(rewardData.rate, rewardToken.decimals);
|
|
287
287
|
baseApy = periodFinish > Date.now() ? inflation.times(31536000).times(rewardRate).div(Number(totalLiquidityUSD)) : (0, utils_1.BN)(0);
|
|
@@ -291,7 +291,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
291
291
|
symbol: rewardToken.symbol,
|
|
292
292
|
apy: Number(baseApy.times(100).toFixed(4)),
|
|
293
293
|
});
|
|
294
|
-
|
|
294
|
+
_j.label = 6;
|
|
295
295
|
case 6:
|
|
296
296
|
_i++;
|
|
297
297
|
return [3 /*break*/, 2];
|
|
@@ -307,29 +307,99 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
307
307
|
];
|
|
308
308
|
return [4 /*yield*/, Promise.all(promises)];
|
|
309
309
|
case 9:
|
|
310
|
-
|
|
310
|
+
_c = _j.sent(), mainPoolsRewards = _c[0], allTypesExtendedPoolData = _c.slice(1);
|
|
311
311
|
rewards = mainPoolsRewards;
|
|
312
|
-
for (
|
|
313
|
-
extendedPoolData = _d
|
|
314
|
-
for (
|
|
315
|
-
pool = _f
|
|
312
|
+
for (_d = 0, _e = allTypesExtendedPoolData; _d < _e.length; _d++) {
|
|
313
|
+
extendedPoolData = _e[_d];
|
|
314
|
+
for (_f = 0, _g = extendedPoolData.poolData; _f < _g.length; _f++) {
|
|
315
|
+
pool = _g[_f];
|
|
316
316
|
if (pool.gaugeAddress && pool.gaugeRewards) {
|
|
317
317
|
rewards[pool.gaugeAddress.toLowerCase()] = pool.gaugeRewards;
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
-
return [2 /*return*/, (
|
|
321
|
+
return [2 /*return*/, (_h = rewards[this.gauge.toLowerCase()]) !== null && _h !== void 0 ? _h : []];
|
|
322
322
|
}
|
|
323
323
|
});
|
|
324
324
|
}); };
|
|
325
|
+
this._calcLpTokenAmount = (0, memoizee_1.default)(function (_amounts, isDeposit, useUnderlying) {
|
|
326
|
+
if (isDeposit === void 0) { isDeposit = true; }
|
|
327
|
+
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
328
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
329
|
+
var _rates_1, N_coins, decimals, calcContractAddress, calcContract, poolContract, lpContract, calls, res, _c, _totalSupply, _fee, _lpTokenAmount, balances, _d, totalSupplyBN, feeBN, lpTokenAmountBN, balancesBN, amountsBN, feesBN, i, _fees, _lpTokenFee;
|
|
330
|
+
return __generator(this, function (_e) {
|
|
331
|
+
switch (_e.label) {
|
|
332
|
+
case 0:
|
|
333
|
+
if (!(!this.isMeta && useUnderlying)) return [3 /*break*/, 2];
|
|
334
|
+
return [4 /*yield*/, this._getRates()];
|
|
335
|
+
case 1:
|
|
336
|
+
_rates_1 = _e.sent();
|
|
337
|
+
_amounts = _amounts.map(function (_amount, i) {
|
|
338
|
+
return _amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates_1[i]);
|
|
339
|
+
});
|
|
340
|
+
_e.label = 2;
|
|
341
|
+
case 2:
|
|
342
|
+
if (!this.isCrypto) return [3 /*break*/, 4];
|
|
343
|
+
return [4 /*yield*/, this._pureCalcLpTokenAmount(_amounts, isDeposit, useUnderlying)];
|
|
344
|
+
case 3: return [2 /*return*/, _e.sent()];
|
|
345
|
+
case 4:
|
|
346
|
+
N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
|
|
347
|
+
decimals = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
|
|
348
|
+
calcContractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
|
|
349
|
+
calcContract = curve_1.curve.contracts[calcContractAddress].multicallContract;
|
|
350
|
+
poolContract = curve_1.curve.contracts[this.address].multicallContract;
|
|
351
|
+
lpContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
352
|
+
calls = [lpContract.totalSupply(), poolContract.fee()];
|
|
353
|
+
// lpAmount before fees
|
|
354
|
+
if (this.isMetaFactory && useUnderlying) {
|
|
355
|
+
calls.push(calcContract.calc_token_amount(this.address, _amounts, isDeposit));
|
|
356
|
+
}
|
|
357
|
+
else if (calcContract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) {
|
|
358
|
+
calls.push(calcContract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions));
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
calls.push(calcContract.calc_token_amount(_amounts, curve_1.curve.constantOptions));
|
|
362
|
+
}
|
|
363
|
+
return [4 /*yield*/, Promise.all([
|
|
364
|
+
curve_1.curve.multicallProvider.all(calls),
|
|
365
|
+
useUnderlying ? this.stats.underlyingBalances() : this.stats.wrappedBalances(),
|
|
366
|
+
])];
|
|
367
|
+
case 5:
|
|
368
|
+
res = _e.sent();
|
|
369
|
+
_c = res[0], _totalSupply = _c[0], _fee = _c[1], _lpTokenAmount = _c[2];
|
|
370
|
+
balances = res[1];
|
|
371
|
+
_d = [(0, utils_1.toBN)(_totalSupply), (0, utils_1.toBN)(_fee, 10).times(N_coins).div(4 * (N_coins - 1)), (0, utils_1.toBN)(_lpTokenAmount)], totalSupplyBN = _d[0], feeBN = _d[1], lpTokenAmountBN = _d[2];
|
|
372
|
+
balancesBN = balances.map(function (b) { return (0, utils_1.BN)(b); });
|
|
373
|
+
amountsBN = _amounts.map(function (_a, i) { return (0, utils_1.toBN)(_a, decimals[i]); });
|
|
374
|
+
feesBN = [];
|
|
375
|
+
for (i = 0; i < N_coins; i++) {
|
|
376
|
+
feesBN[i] = balancesBN[i].times(lpTokenAmountBN).div(totalSupplyBN).minus(amountsBN[i]).times(feeBN);
|
|
377
|
+
if (feesBN[i].lt(0))
|
|
378
|
+
feesBN[i] = feesBN[i].times(-1);
|
|
379
|
+
}
|
|
380
|
+
_fees = feesBN.map(function (fBN, i) { return (0, utils_1.fromBN)(fBN, decimals[i]); });
|
|
381
|
+
return [4 /*yield*/, this._pureCalcLpTokenAmount(_fees, !isDeposit, useUnderlying)];
|
|
382
|
+
case 6:
|
|
383
|
+
_lpTokenFee = _e.sent();
|
|
384
|
+
if (isDeposit)
|
|
385
|
+
_lpTokenFee = _lpTokenFee.mul(-1);
|
|
386
|
+
return [2 /*return*/, _lpTokenAmount.add(_lpTokenFee)];
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
}, {
|
|
391
|
+
primitive: true,
|
|
392
|
+
promise: true,
|
|
393
|
+
maxAge: 1 * 60 * 1000, // 1m
|
|
394
|
+
});
|
|
325
395
|
// ---------------- CRV PROFIT, CLAIM, BOOSTING ----------------
|
|
326
396
|
this.crvProfit = function (address) {
|
|
327
397
|
if (address === void 0) { address = ""; }
|
|
328
398
|
return __awaiter(_this, void 0, void 0, function () {
|
|
329
|
-
var inflationRateBN, workingSupplyBN, workingBalanceBN, gaugeContract, crvContract, currentWeek,
|
|
330
|
-
var
|
|
331
|
-
return __generator(this, function (
|
|
332
|
-
switch (
|
|
399
|
+
var inflationRateBN, workingSupplyBN, workingBalanceBN, gaugeContract, crvContract, currentWeek, _c, gaugeContract, gaugeControllerContract, weightBN, crvPrice, dailyIncome, weeklyIncome, monthlyIncome, annualIncome;
|
|
400
|
+
var _d, _e;
|
|
401
|
+
return __generator(this, function (_f) {
|
|
402
|
+
switch (_f.label) {
|
|
333
403
|
case 0:
|
|
334
404
|
if (this.rewardsOnly())
|
|
335
405
|
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use rewardsProfit instead"));
|
|
@@ -346,13 +416,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
346
416
|
gaugeContract.working_supply(),
|
|
347
417
|
])];
|
|
348
418
|
case 1:
|
|
349
|
-
|
|
419
|
+
_d = (_f.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflationRateBN = _d[0], workingBalanceBN = _d[1], workingSupplyBN = _d[2];
|
|
350
420
|
if (!inflationRateBN.eq(0)) return [3 /*break*/, 3];
|
|
351
|
-
|
|
421
|
+
_c = utils_1.toBN;
|
|
352
422
|
return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve_1.curve.constantOptions)];
|
|
353
423
|
case 2:
|
|
354
|
-
inflationRateBN =
|
|
355
|
-
|
|
424
|
+
inflationRateBN = _c.apply(void 0, [_f.sent()]).div(WEEK);
|
|
425
|
+
_f.label = 3;
|
|
356
426
|
case 3: return [3 /*break*/, 6];
|
|
357
427
|
case 4:
|
|
358
428
|
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
@@ -365,12 +435,12 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
365
435
|
gaugeContract.working_supply(),
|
|
366
436
|
])];
|
|
367
437
|
case 5:
|
|
368
|
-
|
|
438
|
+
_e = (_f.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflationRateBN = _e[0], weightBN = _e[1], workingBalanceBN = _e[2], workingSupplyBN = _e[3];
|
|
369
439
|
inflationRateBN = inflationRateBN.times(weightBN);
|
|
370
|
-
|
|
440
|
+
_f.label = 6;
|
|
371
441
|
case 6: return [4 /*yield*/, (0, utils_1._getUsdRate)('CRV')];
|
|
372
442
|
case 7:
|
|
373
|
-
crvPrice =
|
|
443
|
+
crvPrice = _f.sent();
|
|
374
444
|
if (workingSupplyBN.eq(0))
|
|
375
445
|
return [2 /*return*/, {
|
|
376
446
|
day: "0.0",
|
|
@@ -401,9 +471,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
401
471
|
this.boost = function (address) {
|
|
402
472
|
if (address === void 0) { address = ""; }
|
|
403
473
|
return __awaiter(_this, void 0, void 0, function () {
|
|
404
|
-
var gaugeContract,
|
|
405
|
-
return __generator(this, function (
|
|
406
|
-
switch (
|
|
474
|
+
var gaugeContract, _c, workingBalanceBN, balanceBN, boostBN;
|
|
475
|
+
return __generator(this, function (_d) {
|
|
476
|
+
switch (_d.label) {
|
|
407
477
|
case 0:
|
|
408
478
|
if (curve_1.curve.chainId !== 1)
|
|
409
479
|
throw Error("Boosting is available only on Ethereum network");
|
|
@@ -418,7 +488,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
418
488
|
gaugeContract.balanceOf(address),
|
|
419
489
|
])];
|
|
420
490
|
case 1:
|
|
421
|
-
|
|
491
|
+
_c = (_d.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), workingBalanceBN = _c[0], balanceBN = _c[1];
|
|
422
492
|
boostBN = workingBalanceBN.div(0.4).div(balanceBN);
|
|
423
493
|
return [2 /*return*/, boostBN.toFixed(4).replace(/([0-9])0+$/, '$1')];
|
|
424
494
|
}
|
|
@@ -428,21 +498,21 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
428
498
|
this.currentCrvApy = function (address) {
|
|
429
499
|
if (address === void 0) { address = ""; }
|
|
430
500
|
return __awaiter(_this, void 0, void 0, function () {
|
|
431
|
-
var
|
|
432
|
-
return __generator(this, function (
|
|
433
|
-
switch (
|
|
501
|
+
var _c, baseApy, maxApy, boost;
|
|
502
|
+
return __generator(this, function (_d) {
|
|
503
|
+
switch (_d.label) {
|
|
434
504
|
case 0:
|
|
435
505
|
address = address || curve_1.curve.signerAddress;
|
|
436
506
|
if (!address)
|
|
437
507
|
throw Error("Need to connect wallet or pass address into args");
|
|
438
508
|
return [4 /*yield*/, this.statsTokenApy()];
|
|
439
509
|
case 1:
|
|
440
|
-
|
|
510
|
+
_c = _d.sent(), baseApy = _c[0], maxApy = _c[1];
|
|
441
511
|
if (curve_1.curve.chainId !== 1)
|
|
442
512
|
return [2 /*return*/, baseApy];
|
|
443
513
|
return [4 /*yield*/, this.boost(address)];
|
|
444
514
|
case 2:
|
|
445
|
-
boost =
|
|
515
|
+
boost = _d.sent();
|
|
446
516
|
if (boost == "2.5")
|
|
447
517
|
return [2 /*return*/, maxApy];
|
|
448
518
|
if (boost === "NaN")
|
|
@@ -458,9 +528,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
458
528
|
addresses[_i] = arguments[_i];
|
|
459
529
|
}
|
|
460
530
|
return __awaiter(_this, void 0, void 0, function () {
|
|
461
|
-
var votingEscrowContract, gaugeContract, contractCalls, _response, responseBN,
|
|
462
|
-
return __generator(this, function (
|
|
463
|
-
switch (
|
|
531
|
+
var votingEscrowContract, gaugeContract, contractCalls, _response, responseBN, _c, veTotalSupplyBN, gaugeTotalSupplyBN, resultBN, result, _d, _e, entry;
|
|
532
|
+
return __generator(this, function (_f) {
|
|
533
|
+
switch (_f.label) {
|
|
464
534
|
case 0:
|
|
465
535
|
if (curve_1.curve.chainId !== 1)
|
|
466
536
|
throw Error("Boosting is available only on Ethereum network");
|
|
@@ -480,16 +550,16 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
480
550
|
});
|
|
481
551
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
482
552
|
case 1:
|
|
483
|
-
_response =
|
|
553
|
+
_response = _f.sent();
|
|
484
554
|
responseBN = _response.map(function (value) { return (0, utils_1.toBN)(value); });
|
|
485
|
-
|
|
555
|
+
_c = responseBN.splice(0, 2), veTotalSupplyBN = _c[0], gaugeTotalSupplyBN = _c[1];
|
|
486
556
|
resultBN = {};
|
|
487
557
|
addresses.forEach(function (acct, i) {
|
|
488
558
|
resultBN[acct] = responseBN[i].div(veTotalSupplyBN).times(gaugeTotalSupplyBN);
|
|
489
559
|
});
|
|
490
560
|
result = {};
|
|
491
|
-
for (
|
|
492
|
-
entry = _d
|
|
561
|
+
for (_d = 0, _e = Object.entries(resultBN); _d < _e.length; _d++) {
|
|
562
|
+
entry = _e[_d];
|
|
493
563
|
result[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
|
|
494
564
|
}
|
|
495
565
|
return [2 /*return*/, addresses.length === 1 ? result[addresses[0]] : result];
|
|
@@ -499,9 +569,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
499
569
|
};
|
|
500
570
|
// ---------------- REWARDS PROFIT, CLAIM ----------------
|
|
501
571
|
this.rewardTokens = (0, memoizee_1.default)(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
502
|
-
var gaugeContract, gaugeMulticallContract, rewardCount,
|
|
503
|
-
return __generator(this, function (
|
|
504
|
-
switch (
|
|
572
|
+
var gaugeContract, gaugeMulticallContract, rewardCount, _c, _d, _e, tokenCalls, i, tokens, tokenInfoCalls, _i, tokens_1, token, tokenMulticallContract, tokenInfo_1, i, rewardContract, method, token, tokenMulticallContract, _f, symbol, decimals;
|
|
573
|
+
return __generator(this, function (_g) {
|
|
574
|
+
switch (_g.label) {
|
|
505
575
|
case 0:
|
|
506
576
|
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
507
577
|
return [2 /*return*/, []];
|
|
@@ -510,12 +580,12 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
510
580
|
if (!("reward_tokens(uint256)" in gaugeContract)) return [3 /*break*/, 5];
|
|
511
581
|
rewardCount = 8;
|
|
512
582
|
if (!("reward_count()" in gaugeContract)) return [3 /*break*/, 2];
|
|
513
|
-
|
|
514
|
-
|
|
583
|
+
_c = Number;
|
|
584
|
+
_e = (_d = ethers_1.ethers.utils).formatUnits;
|
|
515
585
|
return [4 /*yield*/, gaugeContract.reward_count(curve_1.curve.constantOptions)];
|
|
516
586
|
case 1:
|
|
517
|
-
rewardCount =
|
|
518
|
-
|
|
587
|
+
rewardCount = _c.apply(void 0, [_e.apply(_d, [_g.sent(), 0])]);
|
|
588
|
+
_g.label = 2;
|
|
519
589
|
case 2:
|
|
520
590
|
tokenCalls = [];
|
|
521
591
|
for (i = 0; i < rewardCount; i++) {
|
|
@@ -523,7 +593,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
523
593
|
}
|
|
524
594
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(tokenCalls)];
|
|
525
595
|
case 3:
|
|
526
|
-
tokens = (
|
|
596
|
+
tokens = (_g.sent())
|
|
527
597
|
.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })
|
|
528
598
|
.map(function (addr) { return addr.toLowerCase(); });
|
|
529
599
|
tokenInfoCalls = [];
|
|
@@ -535,7 +605,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
535
605
|
}
|
|
536
606
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(tokenInfoCalls)];
|
|
537
607
|
case 4:
|
|
538
|
-
tokenInfo_1 =
|
|
608
|
+
tokenInfo_1 = _g.sent();
|
|
539
609
|
for (i = 0; i < tokens.length; i++) {
|
|
540
610
|
curve_1.curve.constants.DECIMALS[tokens[i]] = tokenInfo_1[(i * 2) + 1];
|
|
541
611
|
}
|
|
@@ -547,7 +617,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
547
617
|
;
|
|
548
618
|
return [4 /*yield*/, rewardContract[method](curve_1.curve.constantOptions)];
|
|
549
619
|
case 6:
|
|
550
|
-
token = (
|
|
620
|
+
token = (_g.sent()).toLowerCase();
|
|
551
621
|
(0, utils_1._setContracts)(token, ERC20_json_1.default);
|
|
552
622
|
tokenMulticallContract = curve_1.curve.contracts[token].multicallContract;
|
|
553
623
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
@@ -555,7 +625,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
555
625
|
tokenMulticallContract.decimals(),
|
|
556
626
|
])];
|
|
557
627
|
case 7:
|
|
558
|
-
|
|
628
|
+
_f = _g.sent(), symbol = _f[0], decimals = _f[1];
|
|
559
629
|
return [2 /*return*/, [{ token: token, symbol: symbol, decimals: decimals }]];
|
|
560
630
|
case 8: return [2 /*return*/, []]; // gauge
|
|
561
631
|
}
|
|
@@ -567,9 +637,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
567
637
|
this.rewardsProfit = function (address) {
|
|
568
638
|
if (address === void 0) { address = ""; }
|
|
569
639
|
return __awaiter(_this, void 0, void 0, function () {
|
|
570
|
-
var rewardTokens, gaugeContract, result, calls, _i, rewardTokens_2, rewardToken, res, balanceBN, totalSupplyBN,
|
|
571
|
-
return __generator(this, function (
|
|
572
|
-
switch (
|
|
640
|
+
var rewardTokens, gaugeContract, result, calls, _i, rewardTokens_2, rewardToken, res, balanceBN, totalSupplyBN, _c, rewardTokens_3, rewardToken, _rewardData, periodFinish, inflationRateBN, tokenPrice, rewardToken, sRewardContract, _d, _inflationRate, _periodFinish, _balance, _totalSupply, periodFinish, inflationRateBN, balanceBN, totalSupplyBN, tokenPrice, _e, rewardTokens_4, rewardToken, tokenPrice;
|
|
641
|
+
return __generator(this, function (_f) {
|
|
642
|
+
switch (_f.label) {
|
|
573
643
|
case 0:
|
|
574
644
|
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
575
645
|
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
@@ -578,7 +648,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
578
648
|
throw Error("Need to connect wallet or pass address into args");
|
|
579
649
|
return [4 /*yield*/, this.rewardTokens()];
|
|
580
650
|
case 1:
|
|
581
|
-
rewardTokens =
|
|
651
|
+
rewardTokens = _f.sent();
|
|
582
652
|
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
583
653
|
result = [];
|
|
584
654
|
if (!('reward_data(address)' in curve_1.curve.contracts[this.gauge].contract)) return [3 /*break*/, 7];
|
|
@@ -589,20 +659,20 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
589
659
|
}
|
|
590
660
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
591
661
|
case 2:
|
|
592
|
-
res =
|
|
662
|
+
res = _f.sent();
|
|
593
663
|
balanceBN = (0, utils_1.toBN)(res.shift());
|
|
594
664
|
totalSupplyBN = (0, utils_1.toBN)(res.shift());
|
|
595
|
-
|
|
596
|
-
|
|
665
|
+
_c = 0, rewardTokens_3 = rewardTokens;
|
|
666
|
+
_f.label = 3;
|
|
597
667
|
case 3:
|
|
598
|
-
if (!(
|
|
599
|
-
rewardToken = rewardTokens_3[
|
|
668
|
+
if (!(_c < rewardTokens_3.length)) return [3 /*break*/, 6];
|
|
669
|
+
rewardToken = rewardTokens_3[_c];
|
|
600
670
|
_rewardData = res.shift();
|
|
601
671
|
periodFinish = Number(ethers_1.ethers.utils.formatUnits(_rewardData.period_finish, 0)) * 1000;
|
|
602
672
|
inflationRateBN = periodFinish > Date.now() ? (0, utils_1.toBN)(_rewardData.rate, rewardToken.decimals) : (0, utils_1.BN)(0);
|
|
603
673
|
return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken.token)];
|
|
604
674
|
case 4:
|
|
605
|
-
tokenPrice =
|
|
675
|
+
tokenPrice = _f.sent();
|
|
606
676
|
result.push({
|
|
607
677
|
day: inflationRateBN.times(DAY).times(balanceBN).div(totalSupplyBN).toString(),
|
|
608
678
|
week: inflationRateBN.times(WEEK).times(balanceBN).div(totalSupplyBN).toString(),
|
|
@@ -612,9 +682,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
612
682
|
symbol: rewardToken.symbol,
|
|
613
683
|
price: tokenPrice,
|
|
614
684
|
});
|
|
615
|
-
|
|
685
|
+
_f.label = 5;
|
|
616
686
|
case 5:
|
|
617
|
-
|
|
687
|
+
_c++;
|
|
618
688
|
return [3 /*break*/, 3];
|
|
619
689
|
case 6: return [3 /*break*/, 14];
|
|
620
690
|
case 7:
|
|
@@ -628,14 +698,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
628
698
|
gaugeContract.totalSupply(),
|
|
629
699
|
])];
|
|
630
700
|
case 8:
|
|
631
|
-
|
|
701
|
+
_d = _f.sent(), _inflationRate = _d[0], _periodFinish = _d[1], _balance = _d[2], _totalSupply = _d[3];
|
|
632
702
|
periodFinish = Number(ethers_1.ethers.utils.formatUnits(_periodFinish, 0)) * 1000;
|
|
633
703
|
inflationRateBN = periodFinish > Date.now() ? (0, utils_1.toBN)(_inflationRate, rewardToken.decimals) : (0, utils_1.BN)(0);
|
|
634
704
|
balanceBN = (0, utils_1.toBN)(_balance);
|
|
635
705
|
totalSupplyBN = (0, utils_1.toBN)(_totalSupply);
|
|
636
706
|
return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken.token)];
|
|
637
707
|
case 9:
|
|
638
|
-
tokenPrice =
|
|
708
|
+
tokenPrice = _f.sent();
|
|
639
709
|
result.push({
|
|
640
710
|
day: inflationRateBN.times(DAY).times(balanceBN).div(totalSupplyBN).toString(),
|
|
641
711
|
week: inflationRateBN.times(WEEK).times(balanceBN).div(totalSupplyBN).toString(),
|
|
@@ -648,14 +718,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
648
718
|
return [3 /*break*/, 14];
|
|
649
719
|
case 10:
|
|
650
720
|
if (!['aave', 'saave', 'ankreth'].includes(this.id)) return [3 /*break*/, 14];
|
|
651
|
-
|
|
652
|
-
|
|
721
|
+
_e = 0, rewardTokens_4 = rewardTokens;
|
|
722
|
+
_f.label = 11;
|
|
653
723
|
case 11:
|
|
654
|
-
if (!(
|
|
655
|
-
rewardToken = rewardTokens_4[
|
|
724
|
+
if (!(_e < rewardTokens_4.length)) return [3 /*break*/, 14];
|
|
725
|
+
rewardToken = rewardTokens_4[_e];
|
|
656
726
|
return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken.token)];
|
|
657
727
|
case 12:
|
|
658
|
-
tokenPrice =
|
|
728
|
+
tokenPrice = _f.sent();
|
|
659
729
|
result.push({
|
|
660
730
|
day: "0",
|
|
661
731
|
week: "0",
|
|
@@ -665,9 +735,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
665
735
|
symbol: rewardToken.symbol,
|
|
666
736
|
price: tokenPrice,
|
|
667
737
|
});
|
|
668
|
-
|
|
738
|
+
_f.label = 13;
|
|
669
739
|
case 13:
|
|
670
|
-
|
|
740
|
+
_e++;
|
|
671
741
|
return [3 /*break*/, 11];
|
|
672
742
|
case 14: return [2 /*return*/, result];
|
|
673
743
|
}
|
|
@@ -681,9 +751,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
681
751
|
accounts[_i] = arguments[_i];
|
|
682
752
|
}
|
|
683
753
|
return __awaiter(_this, void 0, void 0, function () {
|
|
684
|
-
var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, _response, response,
|
|
685
|
-
return __generator(this, function (
|
|
686
|
-
switch (
|
|
754
|
+
var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, _response, response, _c, veTotalSupply, gaugeTotalSupply, votingPower, totalBalance, _d, accounts_1, acct, totalPower, optimalBN, _e, accounts_2, acct, amount, _f, accounts_3, acct, optimal, _g, _h, entry;
|
|
755
|
+
return __generator(this, function (_j) {
|
|
756
|
+
switch (_j.label) {
|
|
687
757
|
case 0:
|
|
688
758
|
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
689
759
|
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
@@ -698,13 +768,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
698
768
|
});
|
|
699
769
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
700
770
|
case 1:
|
|
701
|
-
_response =
|
|
771
|
+
_response = _j.sent();
|
|
702
772
|
response = _response.map(function (value) { return (0, utils_1.toBN)(value); });
|
|
703
|
-
|
|
773
|
+
_c = response.splice(0, 2), veTotalSupply = _c[0], gaugeTotalSupply = _c[1];
|
|
704
774
|
votingPower = {};
|
|
705
775
|
totalBalance = (0, utils_1.BN)(0);
|
|
706
|
-
for (
|
|
707
|
-
acct = accounts_1[
|
|
776
|
+
for (_d = 0, accounts_1 = accounts; _d < accounts_1.length; _d++) {
|
|
777
|
+
acct = accounts_1[_d];
|
|
708
778
|
votingPower[acct] = response[0];
|
|
709
779
|
totalBalance = totalBalance.plus(response[1]).plus(response[2]);
|
|
710
780
|
response.splice(0, 3);
|
|
@@ -712,8 +782,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
712
782
|
totalPower = Object.values(votingPower).reduce(function (sum, item) { return sum.plus(item); });
|
|
713
783
|
optimalBN = Object.fromEntries(accounts.map(function (acc) { return [acc, (0, utils_1.BN)(0)]; }));
|
|
714
784
|
if (totalBalance.lt(gaugeTotalSupply.times(totalPower).div(veTotalSupply))) {
|
|
715
|
-
for (
|
|
716
|
-
acct = accounts_2[
|
|
785
|
+
for (_e = 0, accounts_2 = accounts; _e < accounts_2.length; _e++) {
|
|
786
|
+
acct = accounts_2[_e];
|
|
717
787
|
amount = gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply).lt(totalBalance) ?
|
|
718
788
|
gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply) : totalBalance;
|
|
719
789
|
optimalBN[acct] = amount;
|
|
@@ -725,16 +795,16 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
725
795
|
}
|
|
726
796
|
else {
|
|
727
797
|
if (totalPower.lt(0)) {
|
|
728
|
-
for (
|
|
729
|
-
acct = accounts_3[
|
|
798
|
+
for (_f = 0, accounts_3 = accounts; _f < accounts_3.length; _f++) {
|
|
799
|
+
acct = accounts_3[_f];
|
|
730
800
|
optimalBN[acct] = totalBalance.times(votingPower[acct]).div(totalPower);
|
|
731
801
|
}
|
|
732
802
|
}
|
|
733
803
|
optimalBN[accounts[0]] = optimalBN[accounts[0]].plus(totalBalance.minus(Object.values(optimalBN).reduce(function (sum, item) { return sum.plus(item); })));
|
|
734
804
|
}
|
|
735
805
|
optimal = {};
|
|
736
|
-
for (
|
|
737
|
-
entry = _g
|
|
806
|
+
for (_g = 0, _h = Object.entries(optimalBN); _g < _h.length; _g++) {
|
|
807
|
+
entry = _h[_g];
|
|
738
808
|
optimal[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
|
|
739
809
|
}
|
|
740
810
|
return [2 /*return*/, optimal];
|
|
@@ -769,37 +839,37 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
769
839
|
return idx;
|
|
770
840
|
};
|
|
771
841
|
this._getRates = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
772
|
-
var _rates, i, addr,
|
|
773
|
-
return __generator(this, function (
|
|
774
|
-
switch (
|
|
842
|
+
var _rates, i, addr, _c, _d, _e, _f;
|
|
843
|
+
return __generator(this, function (_g) {
|
|
844
|
+
switch (_g.label) {
|
|
775
845
|
case 0:
|
|
776
846
|
_rates = [];
|
|
777
847
|
i = 0;
|
|
778
|
-
|
|
848
|
+
_g.label = 1;
|
|
779
849
|
case 1:
|
|
780
850
|
if (!(i < this.wrappedCoinAddresses.length)) return [3 /*break*/, 9];
|
|
781
851
|
addr = this.wrappedCoinAddresses[i];
|
|
782
852
|
if (!this.useLending[i]) return [3 /*break*/, 7];
|
|
783
853
|
if (!['compound', 'usdt', 'ib'].includes(this.id)) return [3 /*break*/, 3];
|
|
784
|
-
|
|
854
|
+
_d = (_c = _rates).push;
|
|
785
855
|
return [4 /*yield*/, curve_1.curve.contracts[addr].contract.exchangeRateStored()];
|
|
786
856
|
case 2:
|
|
787
|
-
|
|
857
|
+
_d.apply(_c, [_g.sent()]);
|
|
788
858
|
return [3 /*break*/, 6];
|
|
789
859
|
case 3:
|
|
790
860
|
if (!['y', 'busd', 'pax'].includes(this.id)) return [3 /*break*/, 5];
|
|
791
|
-
|
|
861
|
+
_f = (_e = _rates).push;
|
|
792
862
|
return [4 /*yield*/, curve_1.curve.contracts[addr].contract.getPricePerFullShare()];
|
|
793
863
|
case 4:
|
|
794
|
-
|
|
864
|
+
_f.apply(_e, [_g.sent()]);
|
|
795
865
|
return [3 /*break*/, 6];
|
|
796
866
|
case 5:
|
|
797
867
|
_rates.push(ethers_1.ethers.BigNumber.from(10).pow(18)); // Aave ratio 1:1
|
|
798
|
-
|
|
868
|
+
_g.label = 6;
|
|
799
869
|
case 6: return [3 /*break*/, 8];
|
|
800
870
|
case 7:
|
|
801
871
|
_rates.push(ethers_1.ethers.BigNumber.from(10).pow(18));
|
|
802
|
-
|
|
872
|
+
_g.label = 8;
|
|
803
873
|
case 8:
|
|
804
874
|
i++;
|
|
805
875
|
return [3 /*break*/, 1];
|
|
@@ -813,9 +883,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
813
883
|
addresses[_i - 2] = arguments[_i];
|
|
814
884
|
}
|
|
815
885
|
return __awaiter(_this, void 0, void 0, function () {
|
|
816
|
-
var coinNames, coinAddresses, i, rawBalances, balances,
|
|
817
|
-
return __generator(this, function (
|
|
818
|
-
switch (
|
|
886
|
+
var coinNames, coinAddresses, i, rawBalances, balances, _c, addresses_1, address, _d, coinNames_1, coinName;
|
|
887
|
+
return __generator(this, function (_e) {
|
|
888
|
+
switch (_e.label) {
|
|
819
889
|
case 0:
|
|
820
890
|
coinNames = [];
|
|
821
891
|
coinAddresses = [];
|
|
@@ -829,13 +899,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
829
899
|
addresses = (0, utils_1._prepareAddresses)(addresses);
|
|
830
900
|
return [4 /*yield*/, (0, utils_1._getBalances)(coinAddresses, addresses)];
|
|
831
901
|
case 1:
|
|
832
|
-
rawBalances =
|
|
902
|
+
rawBalances = _e.sent();
|
|
833
903
|
balances = {};
|
|
834
|
-
for (
|
|
835
|
-
address = addresses_1[
|
|
904
|
+
for (_c = 0, addresses_1 = addresses; _c < addresses_1.length; _c++) {
|
|
905
|
+
address = addresses_1[_c];
|
|
836
906
|
balances[address] = {};
|
|
837
|
-
for (
|
|
838
|
-
coinName = coinNames_1[
|
|
907
|
+
for (_d = 0, coinNames_1 = coinNames; _d < coinNames_1.length; _d++) {
|
|
908
|
+
coinName = coinNames_1[_d];
|
|
839
909
|
balances[address][coinName] = rawBalances[address].shift();
|
|
840
910
|
}
|
|
841
911
|
}
|
|
@@ -846,34 +916,34 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
846
916
|
};
|
|
847
917
|
// Used by mixin. Don't delete it!!!
|
|
848
918
|
this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
849
|
-
var promises, _i,
|
|
850
|
-
return __generator(this, function (
|
|
851
|
-
switch (
|
|
919
|
+
var promises, _i, _c, addr;
|
|
920
|
+
return __generator(this, function (_d) {
|
|
921
|
+
switch (_d.label) {
|
|
852
922
|
case 0:
|
|
853
923
|
promises = [];
|
|
854
|
-
for (_i = 0,
|
|
855
|
-
addr =
|
|
924
|
+
for (_i = 0, _c = this.underlyingCoinAddresses; _i < _c.length; _i++) {
|
|
925
|
+
addr = _c[_i];
|
|
856
926
|
promises.push((0, utils_1._getUsdRate)(addr));
|
|
857
927
|
}
|
|
858
928
|
return [4 /*yield*/, Promise.all(promises)];
|
|
859
|
-
case 1: return [2 /*return*/,
|
|
929
|
+
case 1: return [2 /*return*/, _d.sent()];
|
|
860
930
|
}
|
|
861
931
|
});
|
|
862
932
|
}); };
|
|
863
933
|
// Used by mixin. Don't delete it!!!
|
|
864
934
|
// NOTE! It may crash!
|
|
865
935
|
this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
866
|
-
var promises, _i,
|
|
867
|
-
return __generator(this, function (
|
|
868
|
-
switch (
|
|
936
|
+
var promises, _i, _c, addr;
|
|
937
|
+
return __generator(this, function (_d) {
|
|
938
|
+
switch (_d.label) {
|
|
869
939
|
case 0:
|
|
870
940
|
promises = [];
|
|
871
|
-
for (_i = 0,
|
|
872
|
-
addr =
|
|
941
|
+
for (_i = 0, _c = this.wrappedCoinAddresses; _i < _c.length; _i++) {
|
|
942
|
+
addr = _c[_i];
|
|
873
943
|
promises.push((0, utils_1._getUsdRate)(addr));
|
|
874
944
|
}
|
|
875
945
|
return [4 /*yield*/, Promise.all(promises)];
|
|
876
|
-
case 1: return [2 /*return*/,
|
|
946
|
+
case 1: return [2 /*return*/, _d.sent()];
|
|
877
947
|
}
|
|
878
948
|
});
|
|
879
949
|
}); };
|
|
@@ -960,14 +1030,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
960
1030
|
return __awaiter(this, void 0, void 0, function () {
|
|
961
1031
|
var swapContract, contractCalls, _wrappedBalances;
|
|
962
1032
|
var _this = this;
|
|
963
|
-
return __generator(this, function (
|
|
964
|
-
switch (
|
|
1033
|
+
return __generator(this, function (_c) {
|
|
1034
|
+
switch (_c.label) {
|
|
965
1035
|
case 0:
|
|
966
1036
|
swapContract = curve_1.curve.contracts[this.address].multicallContract;
|
|
967
1037
|
contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
|
|
968
1038
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
969
1039
|
case 1:
|
|
970
|
-
_wrappedBalances =
|
|
1040
|
+
_wrappedBalances = _c.sent();
|
|
971
1041
|
return [2 /*return*/, _wrappedBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.wrappedDecimals[i]); })];
|
|
972
1042
|
}
|
|
973
1043
|
});
|
|
@@ -976,42 +1046,34 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
976
1046
|
// OVERRIDE
|
|
977
1047
|
PoolTemplate.prototype.statsUnderlyingBalances = function () {
|
|
978
1048
|
return __awaiter(this, void 0, void 0, function () {
|
|
979
|
-
return __generator(this, function (
|
|
980
|
-
switch (
|
|
1049
|
+
return __generator(this, function (_c) {
|
|
1050
|
+
switch (_c.label) {
|
|
981
1051
|
case 0: return [4 /*yield*/, this.statsWrappedBalances()];
|
|
982
|
-
case 1: return [2 /*return*/,
|
|
1052
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
983
1053
|
}
|
|
984
1054
|
});
|
|
985
1055
|
});
|
|
986
1056
|
};
|
|
987
|
-
PoolTemplate.prototype.
|
|
1057
|
+
PoolTemplate.prototype._pureCalcLpTokenAmount = function (_amounts, isDeposit, useUnderlying) {
|
|
988
1058
|
if (isDeposit === void 0) { isDeposit = true; }
|
|
989
1059
|
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
990
1060
|
return __awaiter(this, void 0, void 0, function () {
|
|
991
|
-
var
|
|
992
|
-
return __generator(this, function (
|
|
993
|
-
switch (
|
|
1061
|
+
var calcContractAddress, N_coins, contract;
|
|
1062
|
+
return __generator(this, function (_c) {
|
|
1063
|
+
switch (_c.label) {
|
|
994
1064
|
case 0:
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
_amounts = _amounts.map(function (_amount, i) {
|
|
1000
|
-
return _amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates_1[i]);
|
|
1001
|
-
});
|
|
1002
|
-
_a.label = 2;
|
|
1003
|
-
case 2:
|
|
1004
|
-
contractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
|
|
1005
|
-
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
1006
|
-
if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/, 4];
|
|
1065
|
+
calcContractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
|
|
1066
|
+
N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
|
|
1067
|
+
contract = curve_1.curve.contracts[calcContractAddress].contract;
|
|
1068
|
+
if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/, 2];
|
|
1007
1069
|
return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1008
|
-
case
|
|
1009
|
-
case
|
|
1010
|
-
if (!contract["calc_token_amount(uint256[".concat(
|
|
1070
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1071
|
+
case 2:
|
|
1072
|
+
if (!contract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 4];
|
|
1011
1073
|
return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1012
|
-
case
|
|
1013
|
-
case
|
|
1014
|
-
case
|
|
1074
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
1075
|
+
case 4: return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
1076
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
1015
1077
|
}
|
|
1016
1078
|
});
|
|
1017
1079
|
});
|
|
@@ -1021,8 +1083,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1021
1083
|
return __awaiter(this, void 0, void 0, function () {
|
|
1022
1084
|
var _underlyingAmounts, _expected;
|
|
1023
1085
|
var _this = this;
|
|
1024
|
-
return __generator(this, function (
|
|
1025
|
-
switch (
|
|
1086
|
+
return __generator(this, function (_c) {
|
|
1087
|
+
switch (_c.label) {
|
|
1026
1088
|
case 0:
|
|
1027
1089
|
if (amounts.length !== this.underlyingCoinAddresses.length) {
|
|
1028
1090
|
throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
@@ -1030,7 +1092,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1030
1092
|
_underlyingAmounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
|
|
1031
1093
|
return [4 /*yield*/, this._calcLpTokenAmount(_underlyingAmounts, isDeposit, true)];
|
|
1032
1094
|
case 1:
|
|
1033
|
-
_expected =
|
|
1095
|
+
_expected = _c.sent();
|
|
1034
1096
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected)];
|
|
1035
1097
|
}
|
|
1036
1098
|
});
|
|
@@ -1041,8 +1103,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1041
1103
|
return __awaiter(this, void 0, void 0, function () {
|
|
1042
1104
|
var _amounts, _expected;
|
|
1043
1105
|
var _this = this;
|
|
1044
|
-
return __generator(this, function (
|
|
1045
|
-
switch (
|
|
1106
|
+
return __generator(this, function (_c) {
|
|
1107
|
+
switch (_c.label) {
|
|
1046
1108
|
case 0:
|
|
1047
1109
|
if (amounts.length !== this.wrappedCoinAddresses.length) {
|
|
1048
1110
|
throw Error("".concat(this.name, " pool has ").concat(this.wrappedCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
@@ -1053,7 +1115,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1053
1115
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.wrappedDecimals[i]); });
|
|
1054
1116
|
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, isDeposit, false)];
|
|
1055
1117
|
case 1:
|
|
1056
|
-
_expected =
|
|
1118
|
+
_expected = _c.sent();
|
|
1057
1119
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected)];
|
|
1058
1120
|
}
|
|
1059
1121
|
});
|
|
@@ -1062,17 +1124,17 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1062
1124
|
// ---------------- DEPOSIT ----------------
|
|
1063
1125
|
PoolTemplate.prototype.depositBalancedAmounts = function () {
|
|
1064
1126
|
return __awaiter(this, void 0, void 0, function () {
|
|
1065
|
-
return __generator(this, function (
|
|
1127
|
+
return __generator(this, function (_c) {
|
|
1066
1128
|
throw Error("depositBalancedAmounts method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1067
1129
|
});
|
|
1068
1130
|
});
|
|
1069
1131
|
};
|
|
1070
1132
|
PoolTemplate.prototype.depositExpected = function (amounts) {
|
|
1071
1133
|
return __awaiter(this, void 0, void 0, function () {
|
|
1072
|
-
return __generator(this, function (
|
|
1073
|
-
switch (
|
|
1134
|
+
return __generator(this, function (_c) {
|
|
1135
|
+
switch (_c.label) {
|
|
1074
1136
|
case 0: return [4 /*yield*/, this.calcLpTokenAmount(amounts)];
|
|
1075
|
-
case 1: return [2 /*return*/,
|
|
1137
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1076
1138
|
}
|
|
1077
1139
|
});
|
|
1078
1140
|
});
|
|
@@ -1080,37 +1142,37 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1080
1142
|
// OVERRIDE
|
|
1081
1143
|
PoolTemplate.prototype.depositBonus = function (amounts) {
|
|
1082
1144
|
return __awaiter(this, void 0, void 0, function () {
|
|
1083
|
-
return __generator(this, function (
|
|
1145
|
+
return __generator(this, function (_c) {
|
|
1084
1146
|
throw Error("depositBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1085
1147
|
});
|
|
1086
1148
|
});
|
|
1087
1149
|
};
|
|
1088
1150
|
PoolTemplate.prototype.depositIsApproved = function (amounts) {
|
|
1089
1151
|
return __awaiter(this, void 0, void 0, function () {
|
|
1090
|
-
return __generator(this, function (
|
|
1091
|
-
switch (
|
|
1152
|
+
return __generator(this, function (_c) {
|
|
1153
|
+
switch (_c.label) {
|
|
1092
1154
|
case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.address)];
|
|
1093
|
-
case 1: return [2 /*return*/,
|
|
1155
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1094
1156
|
}
|
|
1095
1157
|
});
|
|
1096
1158
|
});
|
|
1097
1159
|
};
|
|
1098
1160
|
PoolTemplate.prototype.depositApproveEstimateGas = function (amounts) {
|
|
1099
1161
|
return __awaiter(this, void 0, void 0, function () {
|
|
1100
|
-
return __generator(this, function (
|
|
1101
|
-
switch (
|
|
1162
|
+
return __generator(this, function (_c) {
|
|
1163
|
+
switch (_c.label) {
|
|
1102
1164
|
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, this.zap || this.address)];
|
|
1103
|
-
case 1: return [2 /*return*/,
|
|
1165
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1104
1166
|
}
|
|
1105
1167
|
});
|
|
1106
1168
|
});
|
|
1107
1169
|
};
|
|
1108
1170
|
PoolTemplate.prototype.depositApprove = function (amounts) {
|
|
1109
1171
|
return __awaiter(this, void 0, void 0, function () {
|
|
1110
|
-
return __generator(this, function (
|
|
1111
|
-
switch (
|
|
1172
|
+
return __generator(this, function (_c) {
|
|
1173
|
+
switch (_c.label) {
|
|
1112
1174
|
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, this.zap || this.address)];
|
|
1113
|
-
case 1: return [2 /*return*/,
|
|
1175
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1114
1176
|
}
|
|
1115
1177
|
});
|
|
1116
1178
|
});
|
|
@@ -1118,7 +1180,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1118
1180
|
// OVERRIDE
|
|
1119
1181
|
PoolTemplate.prototype.depositEstimateGas = function (amounts) {
|
|
1120
1182
|
return __awaiter(this, void 0, void 0, function () {
|
|
1121
|
-
return __generator(this, function (
|
|
1183
|
+
return __generator(this, function (_c) {
|
|
1122
1184
|
throw Error("depositEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1123
1185
|
});
|
|
1124
1186
|
});
|
|
@@ -1127,7 +1189,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1127
1189
|
PoolTemplate.prototype.deposit = function (amounts, slippage) {
|
|
1128
1190
|
if (slippage === void 0) { slippage = 0.5; }
|
|
1129
1191
|
return __awaiter(this, void 0, void 0, function () {
|
|
1130
|
-
return __generator(this, function (
|
|
1192
|
+
return __generator(this, function (_c) {
|
|
1131
1193
|
throw Error("deposit method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1132
1194
|
});
|
|
1133
1195
|
});
|
|
@@ -1135,21 +1197,21 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1135
1197
|
// ---------------- DEPOSIT WRAPPED ----------------
|
|
1136
1198
|
PoolTemplate.prototype.depositWrappedBalancedAmounts = function () {
|
|
1137
1199
|
return __awaiter(this, void 0, void 0, function () {
|
|
1138
|
-
return __generator(this, function (
|
|
1200
|
+
return __generator(this, function (_c) {
|
|
1139
1201
|
throw Error("depositWrappedBalancedAmounts method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1140
1202
|
});
|
|
1141
1203
|
});
|
|
1142
1204
|
};
|
|
1143
1205
|
PoolTemplate.prototype.depositWrappedExpected = function (amounts) {
|
|
1144
1206
|
return __awaiter(this, void 0, void 0, function () {
|
|
1145
|
-
return __generator(this, function (
|
|
1146
|
-
switch (
|
|
1207
|
+
return __generator(this, function (_c) {
|
|
1208
|
+
switch (_c.label) {
|
|
1147
1209
|
case 0:
|
|
1148
1210
|
if (this.isFake) {
|
|
1149
1211
|
throw Error("depositWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1150
1212
|
}
|
|
1151
1213
|
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts)];
|
|
1152
|
-
case 1: return [2 /*return*/,
|
|
1214
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1153
1215
|
}
|
|
1154
1216
|
});
|
|
1155
1217
|
});
|
|
@@ -1157,49 +1219,49 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1157
1219
|
// OVERRIDE
|
|
1158
1220
|
PoolTemplate.prototype.depositWrappedBonus = function (amounts) {
|
|
1159
1221
|
return __awaiter(this, void 0, void 0, function () {
|
|
1160
|
-
return __generator(this, function (
|
|
1222
|
+
return __generator(this, function (_c) {
|
|
1161
1223
|
throw Error("depositWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1162
1224
|
});
|
|
1163
1225
|
});
|
|
1164
1226
|
};
|
|
1165
1227
|
PoolTemplate.prototype.depositWrappedIsApproved = function (amounts) {
|
|
1166
1228
|
return __awaiter(this, void 0, void 0, function () {
|
|
1167
|
-
return __generator(this, function (
|
|
1168
|
-
switch (
|
|
1229
|
+
return __generator(this, function (_c) {
|
|
1230
|
+
switch (_c.label) {
|
|
1169
1231
|
case 0:
|
|
1170
1232
|
if (this.isFake) {
|
|
1171
1233
|
throw Error("depositWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1172
1234
|
}
|
|
1173
1235
|
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.signerAddress, this.address)];
|
|
1174
|
-
case 1: return [2 /*return*/,
|
|
1236
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1175
1237
|
}
|
|
1176
1238
|
});
|
|
1177
1239
|
});
|
|
1178
1240
|
};
|
|
1179
1241
|
PoolTemplate.prototype.depositWrappedApproveEstimateGas = function (amounts) {
|
|
1180
1242
|
return __awaiter(this, void 0, void 0, function () {
|
|
1181
|
-
return __generator(this, function (
|
|
1182
|
-
switch (
|
|
1243
|
+
return __generator(this, function (_c) {
|
|
1244
|
+
switch (_c.label) {
|
|
1183
1245
|
case 0:
|
|
1184
1246
|
if (this.isFake) {
|
|
1185
1247
|
throw Error("depositWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1186
1248
|
}
|
|
1187
1249
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.wrappedCoinAddresses, amounts, this.address)];
|
|
1188
|
-
case 1: return [2 /*return*/,
|
|
1250
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1189
1251
|
}
|
|
1190
1252
|
});
|
|
1191
1253
|
});
|
|
1192
1254
|
};
|
|
1193
1255
|
PoolTemplate.prototype.depositWrappedApprove = function (amounts) {
|
|
1194
1256
|
return __awaiter(this, void 0, void 0, function () {
|
|
1195
|
-
return __generator(this, function (
|
|
1196
|
-
switch (
|
|
1257
|
+
return __generator(this, function (_c) {
|
|
1258
|
+
switch (_c.label) {
|
|
1197
1259
|
case 0:
|
|
1198
1260
|
if (this.isFake) {
|
|
1199
1261
|
throw Error("depositWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1200
1262
|
}
|
|
1201
1263
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.wrappedCoinAddresses, amounts, this.address)];
|
|
1202
|
-
case 1: return [2 /*return*/,
|
|
1264
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1203
1265
|
}
|
|
1204
1266
|
});
|
|
1205
1267
|
});
|
|
@@ -1207,7 +1269,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1207
1269
|
// OVERRIDE
|
|
1208
1270
|
PoolTemplate.prototype.depositWrappedEstimateGas = function (amounts) {
|
|
1209
1271
|
return __awaiter(this, void 0, void 0, function () {
|
|
1210
|
-
return __generator(this, function (
|
|
1272
|
+
return __generator(this, function (_c) {
|
|
1211
1273
|
throw Error("depositWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1212
1274
|
});
|
|
1213
1275
|
});
|
|
@@ -1216,7 +1278,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1216
1278
|
PoolTemplate.prototype.depositWrapped = function (amounts, slippage) {
|
|
1217
1279
|
if (slippage === void 0) { slippage = 0.5; }
|
|
1218
1280
|
return __awaiter(this, void 0, void 0, function () {
|
|
1219
|
-
return __generator(this, function (
|
|
1281
|
+
return __generator(this, function (_c) {
|
|
1220
1282
|
throw Error("depositWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1221
1283
|
});
|
|
1222
1284
|
});
|
|
@@ -1224,42 +1286,42 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1224
1286
|
// ---------------- STAKING ----------------
|
|
1225
1287
|
PoolTemplate.prototype.stakeIsApproved = function (lpTokenAmount) {
|
|
1226
1288
|
return __awaiter(this, void 0, void 0, function () {
|
|
1227
|
-
return __generator(this, function (
|
|
1228
|
-
switch (
|
|
1289
|
+
return __generator(this, function (_c) {
|
|
1290
|
+
switch (_c.label) {
|
|
1229
1291
|
case 0:
|
|
1230
1292
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1231
1293
|
throw Error("stakeIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1232
1294
|
}
|
|
1233
1295
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.gauge)];
|
|
1234
|
-
case 1: return [2 /*return*/,
|
|
1296
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1235
1297
|
}
|
|
1236
1298
|
});
|
|
1237
1299
|
});
|
|
1238
1300
|
};
|
|
1239
1301
|
PoolTemplate.prototype.stakeApproveEstimateGas = function (lpTokenAmount) {
|
|
1240
1302
|
return __awaiter(this, void 0, void 0, function () {
|
|
1241
|
-
return __generator(this, function (
|
|
1242
|
-
switch (
|
|
1303
|
+
return __generator(this, function (_c) {
|
|
1304
|
+
switch (_c.label) {
|
|
1243
1305
|
case 0:
|
|
1244
1306
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1245
1307
|
throw Error("stakeApproveEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1246
1308
|
}
|
|
1247
1309
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.gauge)];
|
|
1248
|
-
case 1: return [2 /*return*/,
|
|
1310
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1249
1311
|
}
|
|
1250
1312
|
});
|
|
1251
1313
|
});
|
|
1252
1314
|
};
|
|
1253
1315
|
PoolTemplate.prototype.stakeApprove = function (lpTokenAmount) {
|
|
1254
1316
|
return __awaiter(this, void 0, void 0, function () {
|
|
1255
|
-
return __generator(this, function (
|
|
1256
|
-
switch (
|
|
1317
|
+
return __generator(this, function (_c) {
|
|
1318
|
+
switch (_c.label) {
|
|
1257
1319
|
case 0:
|
|
1258
1320
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1259
1321
|
throw Error("stakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1260
1322
|
}
|
|
1261
1323
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.gauge)];
|
|
1262
|
-
case 1: return [2 /*return*/,
|
|
1324
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1263
1325
|
}
|
|
1264
1326
|
});
|
|
1265
1327
|
});
|
|
@@ -1267,15 +1329,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1267
1329
|
PoolTemplate.prototype.stakeEstimateGas = function (lpTokenAmount) {
|
|
1268
1330
|
return __awaiter(this, void 0, void 0, function () {
|
|
1269
1331
|
var _lpTokenAmount;
|
|
1270
|
-
return __generator(this, function (
|
|
1271
|
-
switch (
|
|
1332
|
+
return __generator(this, function (_c) {
|
|
1333
|
+
switch (_c.label) {
|
|
1272
1334
|
case 0:
|
|
1273
1335
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1274
1336
|
throw Error("stakeEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1275
1337
|
}
|
|
1276
1338
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
1277
1339
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1278
|
-
case 1: return [2 /*return*/, (
|
|
1340
|
+
case 1: return [2 /*return*/, (_c.sent()).toNumber()];
|
|
1279
1341
|
}
|
|
1280
1342
|
});
|
|
1281
1343
|
});
|
|
@@ -1283,8 +1345,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1283
1345
|
PoolTemplate.prototype.stake = function (lpTokenAmount) {
|
|
1284
1346
|
return __awaiter(this, void 0, void 0, function () {
|
|
1285
1347
|
var _lpTokenAmount, gasLimit;
|
|
1286
|
-
return __generator(this, function (
|
|
1287
|
-
switch (
|
|
1348
|
+
return __generator(this, function (_c) {
|
|
1349
|
+
switch (_c.label) {
|
|
1288
1350
|
case 0:
|
|
1289
1351
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1290
1352
|
throw Error("stake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1292,12 +1354,12 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1292
1354
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
1293
1355
|
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.gauge)];
|
|
1294
1356
|
case 1:
|
|
1295
|
-
|
|
1357
|
+
_c.sent();
|
|
1296
1358
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1297
1359
|
case 2:
|
|
1298
|
-
gasLimit = (
|
|
1360
|
+
gasLimit = (_c.sent()).mul(150).div(100);
|
|
1299
1361
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1300
|
-
case 3: return [2 /*return*/, (
|
|
1362
|
+
case 3: return [2 /*return*/, (_c.sent()).hash];
|
|
1301
1363
|
}
|
|
1302
1364
|
});
|
|
1303
1365
|
});
|
|
@@ -1305,15 +1367,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1305
1367
|
PoolTemplate.prototype.unstakeEstimateGas = function (lpTokenAmount) {
|
|
1306
1368
|
return __awaiter(this, void 0, void 0, function () {
|
|
1307
1369
|
var _lpTokenAmount;
|
|
1308
|
-
return __generator(this, function (
|
|
1309
|
-
switch (
|
|
1370
|
+
return __generator(this, function (_c) {
|
|
1371
|
+
switch (_c.label) {
|
|
1310
1372
|
case 0:
|
|
1311
1373
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1312
1374
|
throw Error("unstakeEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1313
1375
|
}
|
|
1314
1376
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
1315
1377
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1316
|
-
case 1: return [2 /*return*/, (
|
|
1378
|
+
case 1: return [2 /*return*/, (_c.sent()).toNumber()];
|
|
1317
1379
|
}
|
|
1318
1380
|
});
|
|
1319
1381
|
});
|
|
@@ -1321,8 +1383,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1321
1383
|
PoolTemplate.prototype.unstake = function (lpTokenAmount) {
|
|
1322
1384
|
return __awaiter(this, void 0, void 0, function () {
|
|
1323
1385
|
var _lpTokenAmount, gasLimit;
|
|
1324
|
-
return __generator(this, function (
|
|
1325
|
-
switch (
|
|
1386
|
+
return __generator(this, function (_c) {
|
|
1387
|
+
switch (_c.label) {
|
|
1326
1388
|
case 0:
|
|
1327
1389
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1328
1390
|
throw Error("unstake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1330,9 +1392,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1330
1392
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
1331
1393
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1332
1394
|
case 1:
|
|
1333
|
-
gasLimit = (
|
|
1395
|
+
gasLimit = (_c.sent()).mul(200).div(100);
|
|
1334
1396
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1335
|
-
case 2: return [2 /*return*/, (
|
|
1397
|
+
case 2: return [2 /*return*/, (_c.sent()).hash];
|
|
1336
1398
|
}
|
|
1337
1399
|
});
|
|
1338
1400
|
});
|
|
@@ -1340,31 +1402,31 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1340
1402
|
PoolTemplate.prototype.claimableCrv = function (address) {
|
|
1341
1403
|
if (address === void 0) { address = ""; }
|
|
1342
1404
|
return __awaiter(this, void 0, void 0, function () {
|
|
1343
|
-
var
|
|
1344
|
-
return __generator(this, function (
|
|
1345
|
-
switch (
|
|
1405
|
+
var _c, _d;
|
|
1406
|
+
return __generator(this, function (_e) {
|
|
1407
|
+
switch (_e.label) {
|
|
1346
1408
|
case 0:
|
|
1347
1409
|
if (this.rewardsOnly())
|
|
1348
1410
|
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimableRewards instead"));
|
|
1349
1411
|
address = address || curve_1.curve.signerAddress;
|
|
1350
1412
|
if (!address)
|
|
1351
1413
|
throw Error("Need to connect wallet or pass address into args");
|
|
1352
|
-
|
|
1414
|
+
_d = (_c = ethers_1.ethers.utils).formatUnits;
|
|
1353
1415
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.claimable_tokens(address, curve_1.curve.constantOptions)];
|
|
1354
|
-
case 1: return [2 /*return*/,
|
|
1416
|
+
case 1: return [2 /*return*/, _d.apply(_c, [_e.sent()])];
|
|
1355
1417
|
}
|
|
1356
1418
|
});
|
|
1357
1419
|
});
|
|
1358
1420
|
};
|
|
1359
1421
|
PoolTemplate.prototype.claimCrvEstimateGas = function () {
|
|
1360
1422
|
return __awaiter(this, void 0, void 0, function () {
|
|
1361
|
-
return __generator(this, function (
|
|
1362
|
-
switch (
|
|
1423
|
+
return __generator(this, function (_c) {
|
|
1424
|
+
switch (_c.label) {
|
|
1363
1425
|
case 0:
|
|
1364
1426
|
if (this.rewardsOnly())
|
|
1365
1427
|
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimRewards instead"));
|
|
1366
1428
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
|
|
1367
|
-
case 1: return [2 /*return*/, (
|
|
1429
|
+
case 1: return [2 /*return*/, (_c.sent()).toNumber()];
|
|
1368
1430
|
}
|
|
1369
1431
|
});
|
|
1370
1432
|
});
|
|
@@ -1372,17 +1434,17 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1372
1434
|
PoolTemplate.prototype.claimCrv = function () {
|
|
1373
1435
|
return __awaiter(this, void 0, void 0, function () {
|
|
1374
1436
|
var contract, gasLimit;
|
|
1375
|
-
return __generator(this, function (
|
|
1376
|
-
switch (
|
|
1437
|
+
return __generator(this, function (_c) {
|
|
1438
|
+
switch (_c.label) {
|
|
1377
1439
|
case 0:
|
|
1378
1440
|
if (this.rewardsOnly())
|
|
1379
1441
|
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimRewards instead"));
|
|
1380
1442
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract;
|
|
1381
1443
|
return [4 /*yield*/, contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
|
|
1382
1444
|
case 1:
|
|
1383
|
-
gasLimit = (
|
|
1445
|
+
gasLimit = (_c.sent()).mul(130).div(100);
|
|
1384
1446
|
return [4 /*yield*/, contract.mint(this.gauge, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1385
|
-
case 2: return [2 /*return*/, (
|
|
1447
|
+
case 2: return [2 /*return*/, (_c.sent()).hash];
|
|
1386
1448
|
}
|
|
1387
1449
|
});
|
|
1388
1450
|
});
|
|
@@ -1392,8 +1454,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1392
1454
|
if (address === void 0) { address = ""; }
|
|
1393
1455
|
return __awaiter(this, void 0, void 0, function () {
|
|
1394
1456
|
var gaugeContract, rewardTokens, rewards, _i, rewardTokens_5, rewardToken, _amount, rewardToken, _totalAmount, _claimedAmount;
|
|
1395
|
-
return __generator(this, function (
|
|
1396
|
-
switch (
|
|
1457
|
+
return __generator(this, function (_c) {
|
|
1458
|
+
switch (_c.label) {
|
|
1397
1459
|
case 0:
|
|
1398
1460
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1399
1461
|
throw Error("claimableRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1404,23 +1466,23 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1404
1466
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1405
1467
|
return [4 /*yield*/, this.rewardTokens()];
|
|
1406
1468
|
case 1:
|
|
1407
|
-
rewardTokens =
|
|
1469
|
+
rewardTokens = _c.sent();
|
|
1408
1470
|
rewards = [];
|
|
1409
1471
|
if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 6];
|
|
1410
1472
|
_i = 0, rewardTokens_5 = rewardTokens;
|
|
1411
|
-
|
|
1473
|
+
_c.label = 2;
|
|
1412
1474
|
case 2:
|
|
1413
1475
|
if (!(_i < rewardTokens_5.length)) return [3 /*break*/, 5];
|
|
1414
1476
|
rewardToken = rewardTokens_5[_i];
|
|
1415
1477
|
return [4 /*yield*/, gaugeContract.claimable_reward(address, rewardToken.token, curve_1.curve.constantOptions)];
|
|
1416
1478
|
case 3:
|
|
1417
|
-
_amount =
|
|
1479
|
+
_amount = _c.sent();
|
|
1418
1480
|
rewards.push({
|
|
1419
1481
|
token: rewardToken.token,
|
|
1420
1482
|
symbol: rewardToken.symbol,
|
|
1421
1483
|
amount: ethers_1.ethers.utils.formatUnits(_amount, rewardToken.decimals),
|
|
1422
1484
|
});
|
|
1423
|
-
|
|
1485
|
+
_c.label = 4;
|
|
1424
1486
|
case 4:
|
|
1425
1487
|
_i++;
|
|
1426
1488
|
return [3 /*break*/, 2];
|
|
@@ -1430,16 +1492,16 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1430
1492
|
rewardToken = rewardTokens[0];
|
|
1431
1493
|
return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
|
|
1432
1494
|
case 7:
|
|
1433
|
-
_totalAmount =
|
|
1495
|
+
_totalAmount = _c.sent();
|
|
1434
1496
|
return [4 /*yield*/, gaugeContract.claimed_rewards_for(address, curve_1.curve.constantOptions)];
|
|
1435
1497
|
case 8:
|
|
1436
|
-
_claimedAmount =
|
|
1498
|
+
_claimedAmount = _c.sent();
|
|
1437
1499
|
rewards.push({
|
|
1438
1500
|
token: rewardToken.token,
|
|
1439
1501
|
symbol: rewardToken.symbol,
|
|
1440
1502
|
amount: ethers_1.ethers.utils.formatUnits(_totalAmount.sub(_claimedAmount), rewardToken.decimals),
|
|
1441
1503
|
});
|
|
1442
|
-
|
|
1504
|
+
_c.label = 9;
|
|
1443
1505
|
case 9: return [2 /*return*/, rewards];
|
|
1444
1506
|
}
|
|
1445
1507
|
});
|
|
@@ -1448,8 +1510,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1448
1510
|
PoolTemplate.prototype.claimRewardsEstimateGas = function () {
|
|
1449
1511
|
return __awaiter(this, void 0, void 0, function () {
|
|
1450
1512
|
var gaugeContract;
|
|
1451
|
-
return __generator(this, function (
|
|
1452
|
-
switch (
|
|
1513
|
+
return __generator(this, function (_c) {
|
|
1514
|
+
switch (_c.label) {
|
|
1453
1515
|
case 0:
|
|
1454
1516
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1455
1517
|
throw Error("claimRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1458,7 +1520,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1458
1520
|
if (!("claim_rewards()" in gaugeContract))
|
|
1459
1521
|
throw Error("".concat(this.name, " pool doesn't have such method"));
|
|
1460
1522
|
return [4 /*yield*/, gaugeContract.estimateGas.claim_rewards(curve_1.curve.constantOptions)];
|
|
1461
|
-
case 1: return [2 /*return*/, (
|
|
1523
|
+
case 1: return [2 /*return*/, (_c.sent()).toNumber()];
|
|
1462
1524
|
}
|
|
1463
1525
|
});
|
|
1464
1526
|
});
|
|
@@ -1466,8 +1528,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1466
1528
|
PoolTemplate.prototype.claimRewards = function () {
|
|
1467
1529
|
return __awaiter(this, void 0, void 0, function () {
|
|
1468
1530
|
var gaugeContract, gasLimit;
|
|
1469
|
-
return __generator(this, function (
|
|
1470
|
-
switch (
|
|
1531
|
+
return __generator(this, function (_c) {
|
|
1532
|
+
switch (_c.label) {
|
|
1471
1533
|
case 0:
|
|
1472
1534
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1473
1535
|
throw Error("claimRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1477,9 +1539,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1477
1539
|
throw Error("".concat(this.name, " pool doesn't have such method"));
|
|
1478
1540
|
return [4 /*yield*/, gaugeContract.estimateGas.claim_rewards(curve_1.curve.constantOptions)];
|
|
1479
1541
|
case 1:
|
|
1480
|
-
gasLimit = (
|
|
1542
|
+
gasLimit = (_c.sent()).mul(130).div(100);
|
|
1481
1543
|
return [4 /*yield*/, gaugeContract.claim_rewards(__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1482
|
-
case 2: return [2 /*return*/, (
|
|
1544
|
+
case 2: return [2 /*return*/, (_c.sent()).hash];
|
|
1483
1545
|
}
|
|
1484
1546
|
});
|
|
1485
1547
|
});
|
|
@@ -1487,28 +1549,28 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1487
1549
|
// ---------------- DEPOSIT & STAKE ----------------
|
|
1488
1550
|
PoolTemplate.prototype.depositAndStakeExpected = function (amounts) {
|
|
1489
1551
|
return __awaiter(this, void 0, void 0, function () {
|
|
1490
|
-
return __generator(this, function (
|
|
1491
|
-
switch (
|
|
1552
|
+
return __generator(this, function (_c) {
|
|
1553
|
+
switch (_c.label) {
|
|
1492
1554
|
case 0:
|
|
1493
1555
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1494
1556
|
throw Error("depositAndStakeExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1495
1557
|
}
|
|
1496
1558
|
return [4 /*yield*/, this.depositExpected(amounts)];
|
|
1497
|
-
case 1: return [2 /*return*/,
|
|
1559
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1498
1560
|
}
|
|
1499
1561
|
});
|
|
1500
1562
|
});
|
|
1501
1563
|
};
|
|
1502
1564
|
PoolTemplate.prototype.depositAndStakeBonus = function (amounts) {
|
|
1503
1565
|
return __awaiter(this, void 0, void 0, function () {
|
|
1504
|
-
return __generator(this, function (
|
|
1505
|
-
switch (
|
|
1566
|
+
return __generator(this, function (_c) {
|
|
1567
|
+
switch (_c.label) {
|
|
1506
1568
|
case 0:
|
|
1507
1569
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1508
1570
|
throw Error("depositAndStakeBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1509
1571
|
}
|
|
1510
1572
|
return [4 /*yield*/, this.depositBonus(amounts)];
|
|
1511
|
-
case 1: return [2 /*return*/,
|
|
1573
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1512
1574
|
}
|
|
1513
1575
|
});
|
|
1514
1576
|
});
|
|
@@ -1516,20 +1578,20 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1516
1578
|
PoolTemplate.prototype.depositAndStakeIsApproved = function (amounts) {
|
|
1517
1579
|
return __awaiter(this, void 0, void 0, function () {
|
|
1518
1580
|
var coinsAllowance, gaugeContract, gaugeAllowance;
|
|
1519
|
-
return __generator(this, function (
|
|
1520
|
-
switch (
|
|
1581
|
+
return __generator(this, function (_c) {
|
|
1582
|
+
switch (_c.label) {
|
|
1521
1583
|
case 0:
|
|
1522
1584
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1523
1585
|
throw Error("depositAndStakeIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1524
1586
|
}
|
|
1525
1587
|
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1526
1588
|
case 1:
|
|
1527
|
-
coinsAllowance =
|
|
1589
|
+
coinsAllowance = _c.sent();
|
|
1528
1590
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1529
1591
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
|
|
1530
1592
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1531
1593
|
case 2:
|
|
1532
|
-
gaugeAllowance =
|
|
1594
|
+
gaugeAllowance = _c.sent();
|
|
1533
1595
|
return [2 /*return*/, coinsAllowance && gaugeAllowance];
|
|
1534
1596
|
case 3: return [2 /*return*/, coinsAllowance];
|
|
1535
1597
|
}
|
|
@@ -1539,24 +1601,24 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1539
1601
|
PoolTemplate.prototype.depositAndStakeApproveEstimateGas = function (amounts) {
|
|
1540
1602
|
return __awaiter(this, void 0, void 0, function () {
|
|
1541
1603
|
var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
|
|
1542
|
-
return __generator(this, function (
|
|
1543
|
-
switch (
|
|
1604
|
+
return __generator(this, function (_c) {
|
|
1605
|
+
switch (_c.label) {
|
|
1544
1606
|
case 0:
|
|
1545
1607
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1546
1608
|
throw Error("depositAndStakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1547
1609
|
}
|
|
1548
1610
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1549
1611
|
case 1:
|
|
1550
|
-
approveCoinsGas =
|
|
1612
|
+
approveCoinsGas = _c.sent();
|
|
1551
1613
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1552
1614
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
|
|
1553
1615
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1554
1616
|
case 2:
|
|
1555
|
-
gaugeAllowance =
|
|
1617
|
+
gaugeAllowance = _c.sent();
|
|
1556
1618
|
if (!!gaugeAllowance) return [3 /*break*/, 4];
|
|
1557
1619
|
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
1558
1620
|
case 3:
|
|
1559
|
-
approveGaugeGas = (
|
|
1621
|
+
approveGaugeGas = (_c.sent()).toNumber();
|
|
1560
1622
|
return [2 /*return*/, approveCoinsGas + approveGaugeGas];
|
|
1561
1623
|
case 4: return [2 /*return*/, approveCoinsGas];
|
|
1562
1624
|
}
|
|
@@ -1566,27 +1628,27 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1566
1628
|
PoolTemplate.prototype.depositAndStakeApprove = function (amounts) {
|
|
1567
1629
|
return __awaiter(this, void 0, void 0, function () {
|
|
1568
1630
|
var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
|
|
1569
|
-
return __generator(this, function (
|
|
1570
|
-
switch (
|
|
1631
|
+
return __generator(this, function (_c) {
|
|
1632
|
+
switch (_c.label) {
|
|
1571
1633
|
case 0:
|
|
1572
1634
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1573
1635
|
throw Error("depositAndStakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1574
1636
|
}
|
|
1575
1637
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1576
1638
|
case 1:
|
|
1577
|
-
approveCoinsTx =
|
|
1639
|
+
approveCoinsTx = _c.sent();
|
|
1578
1640
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1579
1641
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
|
|
1580
1642
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1581
1643
|
case 2:
|
|
1582
|
-
gaugeAllowance =
|
|
1644
|
+
gaugeAllowance = _c.sent();
|
|
1583
1645
|
if (!!gaugeAllowance) return [3 /*break*/, 5];
|
|
1584
1646
|
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
1585
1647
|
case 3:
|
|
1586
|
-
gasLimit = (
|
|
1648
|
+
gasLimit = (_c.sent()).mul(130).div(100);
|
|
1587
1649
|
return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1588
1650
|
case 4:
|
|
1589
|
-
approveGaugeTx = (
|
|
1651
|
+
approveGaugeTx = (_c.sent()).hash;
|
|
1590
1652
|
return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
|
|
1591
1653
|
case 5: return [2 /*return*/, approveCoinsTx];
|
|
1592
1654
|
}
|
|
@@ -1595,28 +1657,28 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1595
1657
|
};
|
|
1596
1658
|
PoolTemplate.prototype.depositAndStakeEstimateGas = function (amounts) {
|
|
1597
1659
|
return __awaiter(this, void 0, void 0, function () {
|
|
1598
|
-
return __generator(this, function (
|
|
1599
|
-
switch (
|
|
1660
|
+
return __generator(this, function (_c) {
|
|
1661
|
+
switch (_c.label) {
|
|
1600
1662
|
case 0:
|
|
1601
1663
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1602
1664
|
throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1603
1665
|
}
|
|
1604
1666
|
return [4 /*yield*/, this._depositAndStake(amounts, true, true)];
|
|
1605
|
-
case 1: return [2 /*return*/,
|
|
1667
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1606
1668
|
}
|
|
1607
1669
|
});
|
|
1608
1670
|
});
|
|
1609
1671
|
};
|
|
1610
1672
|
PoolTemplate.prototype.depositAndStake = function (amounts) {
|
|
1611
1673
|
return __awaiter(this, void 0, void 0, function () {
|
|
1612
|
-
return __generator(this, function (
|
|
1613
|
-
switch (
|
|
1674
|
+
return __generator(this, function (_c) {
|
|
1675
|
+
switch (_c.label) {
|
|
1614
1676
|
case 0:
|
|
1615
1677
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1616
1678
|
throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1617
1679
|
}
|
|
1618
1680
|
return [4 /*yield*/, this._depositAndStake(amounts, true, false)];
|
|
1619
|
-
case 1: return [2 /*return*/,
|
|
1681
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1620
1682
|
}
|
|
1621
1683
|
});
|
|
1622
1684
|
});
|
|
@@ -1624,8 +1686,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1624
1686
|
// ---------------- DEPOSIT & STAKE WRAPPED ----------------
|
|
1625
1687
|
PoolTemplate.prototype.depositAndStakeWrappedExpected = function (amounts) {
|
|
1626
1688
|
return __awaiter(this, void 0, void 0, function () {
|
|
1627
|
-
return __generator(this, function (
|
|
1628
|
-
switch (
|
|
1689
|
+
return __generator(this, function (_c) {
|
|
1690
|
+
switch (_c.label) {
|
|
1629
1691
|
case 0:
|
|
1630
1692
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1631
1693
|
throw Error("depositAndStakeWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1633,15 +1695,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1633
1695
|
if (this.isPlain || this.isFake)
|
|
1634
1696
|
throw Error("depositAndStakeWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1635
1697
|
return [4 /*yield*/, this.depositWrappedExpected(amounts)];
|
|
1636
|
-
case 1: return [2 /*return*/,
|
|
1698
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1637
1699
|
}
|
|
1638
1700
|
});
|
|
1639
1701
|
});
|
|
1640
1702
|
};
|
|
1641
1703
|
PoolTemplate.prototype.depositAndStakeWrappedBonus = function (amounts) {
|
|
1642
1704
|
return __awaiter(this, void 0, void 0, function () {
|
|
1643
|
-
return __generator(this, function (
|
|
1644
|
-
switch (
|
|
1705
|
+
return __generator(this, function (_c) {
|
|
1706
|
+
switch (_c.label) {
|
|
1645
1707
|
case 0:
|
|
1646
1708
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1647
1709
|
throw Error("depositAndStakeWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1649,7 +1711,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1649
1711
|
if (this.isPlain || this.isFake)
|
|
1650
1712
|
throw Error("depositAndStakeWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1651
1713
|
return [4 /*yield*/, this.depositWrappedBonus(amounts)];
|
|
1652
|
-
case 1: return [2 /*return*/,
|
|
1714
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1653
1715
|
}
|
|
1654
1716
|
});
|
|
1655
1717
|
});
|
|
@@ -1657,8 +1719,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1657
1719
|
PoolTemplate.prototype.depositAndStakeWrappedIsApproved = function (amounts) {
|
|
1658
1720
|
return __awaiter(this, void 0, void 0, function () {
|
|
1659
1721
|
var coinsAllowance, gaugeContract, gaugeAllowance;
|
|
1660
|
-
return __generator(this, function (
|
|
1661
|
-
switch (
|
|
1722
|
+
return __generator(this, function (_c) {
|
|
1723
|
+
switch (_c.label) {
|
|
1662
1724
|
case 0:
|
|
1663
1725
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1664
1726
|
throw Error("depositAndStakeWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1667,12 +1729,12 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1667
1729
|
throw Error("depositAndStakeWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1668
1730
|
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1669
1731
|
case 1:
|
|
1670
|
-
coinsAllowance =
|
|
1732
|
+
coinsAllowance = _c.sent();
|
|
1671
1733
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1672
1734
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
|
|
1673
1735
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1674
1736
|
case 2:
|
|
1675
|
-
gaugeAllowance =
|
|
1737
|
+
gaugeAllowance = _c.sent();
|
|
1676
1738
|
return [2 /*return*/, coinsAllowance && gaugeAllowance];
|
|
1677
1739
|
case 3: return [2 /*return*/, coinsAllowance];
|
|
1678
1740
|
}
|
|
@@ -1682,8 +1744,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1682
1744
|
PoolTemplate.prototype.depositAndStakeWrappedApproveEstimateGas = function (amounts) {
|
|
1683
1745
|
return __awaiter(this, void 0, void 0, function () {
|
|
1684
1746
|
var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
|
|
1685
|
-
return __generator(this, function (
|
|
1686
|
-
switch (
|
|
1747
|
+
return __generator(this, function (_c) {
|
|
1748
|
+
switch (_c.label) {
|
|
1687
1749
|
case 0:
|
|
1688
1750
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1689
1751
|
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1692,16 +1754,16 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1692
1754
|
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1693
1755
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.wrappedCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1694
1756
|
case 1:
|
|
1695
|
-
approveCoinsGas =
|
|
1757
|
+
approveCoinsGas = _c.sent();
|
|
1696
1758
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1697
1759
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
|
|
1698
1760
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1699
1761
|
case 2:
|
|
1700
|
-
gaugeAllowance =
|
|
1762
|
+
gaugeAllowance = _c.sent();
|
|
1701
1763
|
if (!!gaugeAllowance) return [3 /*break*/, 4];
|
|
1702
1764
|
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
1703
1765
|
case 3:
|
|
1704
|
-
approveGaugeGas = (
|
|
1766
|
+
approveGaugeGas = (_c.sent()).toNumber();
|
|
1705
1767
|
return [2 /*return*/, approveCoinsGas + approveGaugeGas];
|
|
1706
1768
|
case 4: return [2 /*return*/, approveCoinsGas];
|
|
1707
1769
|
}
|
|
@@ -1711,8 +1773,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1711
1773
|
PoolTemplate.prototype.depositAndStakeWrappedApprove = function (amounts) {
|
|
1712
1774
|
return __awaiter(this, void 0, void 0, function () {
|
|
1713
1775
|
var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
|
|
1714
|
-
return __generator(this, function (
|
|
1715
|
-
switch (
|
|
1776
|
+
return __generator(this, function (_c) {
|
|
1777
|
+
switch (_c.label) {
|
|
1716
1778
|
case 0:
|
|
1717
1779
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1718
1780
|
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1721,19 +1783,19 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1721
1783
|
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1722
1784
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1723
1785
|
case 1:
|
|
1724
|
-
approveCoinsTx =
|
|
1786
|
+
approveCoinsTx = _c.sent();
|
|
1725
1787
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1726
1788
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
|
|
1727
1789
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1728
1790
|
case 2:
|
|
1729
|
-
gaugeAllowance =
|
|
1791
|
+
gaugeAllowance = _c.sent();
|
|
1730
1792
|
if (!!gaugeAllowance) return [3 /*break*/, 5];
|
|
1731
1793
|
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
1732
1794
|
case 3:
|
|
1733
|
-
gasLimit = (
|
|
1795
|
+
gasLimit = (_c.sent()).mul(130).div(100);
|
|
1734
1796
|
return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1735
1797
|
case 4:
|
|
1736
|
-
approveGaugeTx = (
|
|
1798
|
+
approveGaugeTx = (_c.sent()).hash;
|
|
1737
1799
|
return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
|
|
1738
1800
|
case 5: return [2 /*return*/, approveCoinsTx];
|
|
1739
1801
|
}
|
|
@@ -1742,8 +1804,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1742
1804
|
};
|
|
1743
1805
|
PoolTemplate.prototype.depositAndStakeWrappedEstimateGas = function (amounts) {
|
|
1744
1806
|
return __awaiter(this, void 0, void 0, function () {
|
|
1745
|
-
return __generator(this, function (
|
|
1746
|
-
switch (
|
|
1807
|
+
return __generator(this, function (_c) {
|
|
1808
|
+
switch (_c.label) {
|
|
1747
1809
|
case 0:
|
|
1748
1810
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1749
1811
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1751,15 +1813,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1751
1813
|
if (this.isPlain || this.isFake)
|
|
1752
1814
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1753
1815
|
return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
|
|
1754
|
-
case 1: return [2 /*return*/,
|
|
1816
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1755
1817
|
}
|
|
1756
1818
|
});
|
|
1757
1819
|
});
|
|
1758
1820
|
};
|
|
1759
1821
|
PoolTemplate.prototype.depositAndStakeWrapped = function (amounts) {
|
|
1760
1822
|
return __awaiter(this, void 0, void 0, function () {
|
|
1761
|
-
return __generator(this, function (
|
|
1762
|
-
switch (
|
|
1823
|
+
return __generator(this, function (_c) {
|
|
1824
|
+
switch (_c.label) {
|
|
1763
1825
|
case 0:
|
|
1764
1826
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1765
1827
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1767,16 +1829,16 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1767
1829
|
if (this.isPlain || this.isFake)
|
|
1768
1830
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1769
1831
|
return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
|
|
1770
|
-
case 1: return [2 /*return*/,
|
|
1832
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1771
1833
|
}
|
|
1772
1834
|
});
|
|
1773
1835
|
});
|
|
1774
1836
|
};
|
|
1775
1837
|
PoolTemplate.prototype._depositAndStake = function (amounts, isUnderlying, estimateGas) {
|
|
1776
1838
|
return __awaiter(this, void 0, void 0, function () {
|
|
1777
|
-
var coinAddresses, coins, decimals, depositAddress, balances,
|
|
1778
|
-
return __generator(this, function (
|
|
1779
|
-
switch (
|
|
1839
|
+
var coinAddresses, coins, decimals, depositAddress, balances, _c, _d, _e, _f, _g, i, allowance, _h, _amounts, contract, useUnderlying, _minMintAmount, _j, _k, _l, _m, _o, ethIndex, value, i, _gas, gasLimit;
|
|
1840
|
+
return __generator(this, function (_p) {
|
|
1841
|
+
switch (_p.label) {
|
|
1780
1842
|
case 0:
|
|
1781
1843
|
coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.wrappedCoinAddresses, true);
|
|
1782
1844
|
coins = isUnderlying ? this.underlyingCoins : this.wrappedCoinAddresses;
|
|
@@ -1786,19 +1848,19 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1786
1848
|
throw Error("".concat(this.name, " pool has ").concat(coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
1787
1849
|
}
|
|
1788
1850
|
if (!isUnderlying) return [3 /*break*/, 2];
|
|
1789
|
-
|
|
1851
|
+
_e = (_d = Object).values;
|
|
1790
1852
|
return [4 /*yield*/, this.walletUnderlyingCoinBalances()];
|
|
1791
1853
|
case 1:
|
|
1792
|
-
|
|
1854
|
+
_c = _e.apply(_d, [_p.sent()]);
|
|
1793
1855
|
return [3 /*break*/, 4];
|
|
1794
1856
|
case 2:
|
|
1795
|
-
|
|
1857
|
+
_g = (_f = Object).values;
|
|
1796
1858
|
return [4 /*yield*/, this.walletWrappedCoinBalances()];
|
|
1797
1859
|
case 3:
|
|
1798
|
-
|
|
1799
|
-
|
|
1860
|
+
_c = _g.apply(_f, [_p.sent()]);
|
|
1861
|
+
_p.label = 4;
|
|
1800
1862
|
case 4:
|
|
1801
|
-
balances =
|
|
1863
|
+
balances = _c;
|
|
1802
1864
|
for (i = 0; i < balances.length; i++) {
|
|
1803
1865
|
if (Number(balances[i]) < Number(amounts[i])) {
|
|
1804
1866
|
throw Error("Not enough ".concat(coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
|
|
@@ -1807,14 +1869,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1807
1869
|
if (!isUnderlying) return [3 /*break*/, 6];
|
|
1808
1870
|
return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
|
|
1809
1871
|
case 5:
|
|
1810
|
-
|
|
1872
|
+
_h = _p.sent();
|
|
1811
1873
|
return [3 /*break*/, 8];
|
|
1812
1874
|
case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
|
|
1813
1875
|
case 7:
|
|
1814
|
-
|
|
1815
|
-
|
|
1876
|
+
_h = _p.sent();
|
|
1877
|
+
_p.label = 8;
|
|
1816
1878
|
case 8:
|
|
1817
|
-
allowance =
|
|
1879
|
+
allowance = _h;
|
|
1818
1880
|
if (estimateGas && !allowance) {
|
|
1819
1881
|
throw Error("Token allowance is needed to estimate gas");
|
|
1820
1882
|
}
|
|
@@ -1822,30 +1884,30 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1822
1884
|
if (!isUnderlying) return [3 /*break*/, 10];
|
|
1823
1885
|
return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
|
|
1824
1886
|
case 9:
|
|
1825
|
-
|
|
1887
|
+
_p.sent();
|
|
1826
1888
|
return [3 /*break*/, 12];
|
|
1827
1889
|
case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
|
|
1828
1890
|
case 11:
|
|
1829
|
-
|
|
1830
|
-
|
|
1891
|
+
_p.sent();
|
|
1892
|
+
_p.label = 12;
|
|
1831
1893
|
case 12:
|
|
1832
1894
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, decimals[i]); });
|
|
1833
1895
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.deposit_and_stake].contract;
|
|
1834
1896
|
useUnderlying = isUnderlying && (this.isLending || (this.isCrypto && !this.isPlain)) && !this.zap;
|
|
1835
1897
|
if (!isUnderlying) return [3 /*break*/, 14];
|
|
1836
|
-
|
|
1898
|
+
_l = (_k = ethers_1.ethers.utils).parseUnits;
|
|
1837
1899
|
return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
|
|
1838
1900
|
case 13:
|
|
1839
|
-
|
|
1901
|
+
_j = _l.apply(_k, [_p.sent()]).mul(99).div(100);
|
|
1840
1902
|
return [3 /*break*/, 16];
|
|
1841
1903
|
case 14:
|
|
1842
|
-
|
|
1904
|
+
_o = (_m = ethers_1.ethers.utils).parseUnits;
|
|
1843
1905
|
return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
|
|
1844
1906
|
case 15:
|
|
1845
|
-
|
|
1846
|
-
|
|
1907
|
+
_j = _o.apply(_m, [_p.sent()]).mul(99).div(100);
|
|
1908
|
+
_p.label = 16;
|
|
1847
1909
|
case 16:
|
|
1848
|
-
_minMintAmount =
|
|
1910
|
+
_minMintAmount = _j;
|
|
1849
1911
|
ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
|
|
1850
1912
|
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
1851
1913
|
for (i = 0; i < 5; i++) {
|
|
@@ -1854,15 +1916,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1854
1916
|
}
|
|
1855
1917
|
return [4 /*yield*/, contract.estimateGas.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.address : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1856
1918
|
case 17:
|
|
1857
|
-
_gas = (
|
|
1919
|
+
_gas = (_p.sent());
|
|
1858
1920
|
if (estimateGas)
|
|
1859
1921
|
return [2 /*return*/, _gas.toNumber()];
|
|
1860
1922
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1861
1923
|
case 18:
|
|
1862
|
-
|
|
1924
|
+
_p.sent();
|
|
1863
1925
|
gasLimit = _gas.mul(200).div(100);
|
|
1864
1926
|
return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.address : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
|
|
1865
|
-
case 19: return [2 /*return*/, (
|
|
1927
|
+
case 19: return [2 /*return*/, (_p.sent()).hash];
|
|
1866
1928
|
}
|
|
1867
1929
|
});
|
|
1868
1930
|
});
|
|
@@ -1871,46 +1933,46 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1871
1933
|
// OVERRIDE
|
|
1872
1934
|
PoolTemplate.prototype.withdrawExpected = function (lpTokenAmount) {
|
|
1873
1935
|
return __awaiter(this, void 0, void 0, function () {
|
|
1874
|
-
return __generator(this, function (
|
|
1936
|
+
return __generator(this, function (_c) {
|
|
1875
1937
|
throw Error("withdrawExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1876
1938
|
});
|
|
1877
1939
|
});
|
|
1878
1940
|
};
|
|
1879
1941
|
PoolTemplate.prototype.withdrawIsApproved = function (lpTokenAmount) {
|
|
1880
1942
|
return __awaiter(this, void 0, void 0, function () {
|
|
1881
|
-
return __generator(this, function (
|
|
1882
|
-
switch (
|
|
1943
|
+
return __generator(this, function (_c) {
|
|
1944
|
+
switch (_c.label) {
|
|
1883
1945
|
case 0:
|
|
1884
1946
|
if (!this.zap)
|
|
1885
1947
|
return [2 /*return*/, true];
|
|
1886
1948
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
1887
|
-
case 1: return [2 /*return*/,
|
|
1949
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1888
1950
|
}
|
|
1889
1951
|
});
|
|
1890
1952
|
});
|
|
1891
1953
|
};
|
|
1892
1954
|
PoolTemplate.prototype.withdrawApproveEstimateGas = function (lpTokenAmount) {
|
|
1893
1955
|
return __awaiter(this, void 0, void 0, function () {
|
|
1894
|
-
return __generator(this, function (
|
|
1895
|
-
switch (
|
|
1956
|
+
return __generator(this, function (_c) {
|
|
1957
|
+
switch (_c.label) {
|
|
1896
1958
|
case 0:
|
|
1897
1959
|
if (!this.zap)
|
|
1898
1960
|
return [2 /*return*/, 0];
|
|
1899
1961
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
1900
|
-
case 1: return [2 /*return*/,
|
|
1962
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1901
1963
|
}
|
|
1902
1964
|
});
|
|
1903
1965
|
});
|
|
1904
1966
|
};
|
|
1905
1967
|
PoolTemplate.prototype.withdrawApprove = function (lpTokenAmount) {
|
|
1906
1968
|
return __awaiter(this, void 0, void 0, function () {
|
|
1907
|
-
return __generator(this, function (
|
|
1908
|
-
switch (
|
|
1969
|
+
return __generator(this, function (_c) {
|
|
1970
|
+
switch (_c.label) {
|
|
1909
1971
|
case 0:
|
|
1910
1972
|
if (!this.zap)
|
|
1911
1973
|
return [2 /*return*/, []];
|
|
1912
1974
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
1913
|
-
case 1: return [2 /*return*/,
|
|
1975
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1914
1976
|
}
|
|
1915
1977
|
});
|
|
1916
1978
|
});
|
|
@@ -1918,7 +1980,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1918
1980
|
// OVERRIDE
|
|
1919
1981
|
PoolTemplate.prototype.withdrawEstimateGas = function (lpTokenAmount) {
|
|
1920
1982
|
return __awaiter(this, void 0, void 0, function () {
|
|
1921
|
-
return __generator(this, function (
|
|
1983
|
+
return __generator(this, function (_c) {
|
|
1922
1984
|
throw Error("withdraw method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1923
1985
|
});
|
|
1924
1986
|
});
|
|
@@ -1927,7 +1989,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1927
1989
|
PoolTemplate.prototype.withdraw = function (lpTokenAmount, slippage) {
|
|
1928
1990
|
if (slippage === void 0) { slippage = 0.5; }
|
|
1929
1991
|
return __awaiter(this, void 0, void 0, function () {
|
|
1930
|
-
return __generator(this, function (
|
|
1992
|
+
return __generator(this, function (_c) {
|
|
1931
1993
|
throw Error("withdraw method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1932
1994
|
});
|
|
1933
1995
|
});
|
|
@@ -1936,7 +1998,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1936
1998
|
// OVERRIDE
|
|
1937
1999
|
PoolTemplate.prototype.withdrawWrappedExpected = function (lpTokenAmount) {
|
|
1938
2000
|
return __awaiter(this, void 0, void 0, function () {
|
|
1939
|
-
return __generator(this, function (
|
|
2001
|
+
return __generator(this, function (_c) {
|
|
1940
2002
|
throw Error("withdrawWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1941
2003
|
});
|
|
1942
2004
|
});
|
|
@@ -1944,7 +2006,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1944
2006
|
// OVERRIDE
|
|
1945
2007
|
PoolTemplate.prototype.withdrawWrappedEstimateGas = function (lpTokenAmount) {
|
|
1946
2008
|
return __awaiter(this, void 0, void 0, function () {
|
|
1947
|
-
return __generator(this, function (
|
|
2009
|
+
return __generator(this, function (_c) {
|
|
1948
2010
|
throw Error("withdrawWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1949
2011
|
});
|
|
1950
2012
|
});
|
|
@@ -1953,7 +2015,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1953
2015
|
PoolTemplate.prototype.withdrawWrapped = function (lpTokenAmount, slippage) {
|
|
1954
2016
|
if (slippage === void 0) { slippage = 0.5; }
|
|
1955
2017
|
return __awaiter(this, void 0, void 0, function () {
|
|
1956
|
-
return __generator(this, function (
|
|
2018
|
+
return __generator(this, function (_c) {
|
|
1957
2019
|
throw Error("withdrawWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1958
2020
|
});
|
|
1959
2021
|
});
|
|
@@ -1961,13 +2023,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1961
2023
|
// ---------------- WITHDRAW IMBALANCE ----------------
|
|
1962
2024
|
PoolTemplate.prototype.withdrawImbalanceExpected = function (amounts) {
|
|
1963
2025
|
return __awaiter(this, void 0, void 0, function () {
|
|
1964
|
-
return __generator(this, function (
|
|
1965
|
-
switch (
|
|
2026
|
+
return __generator(this, function (_c) {
|
|
2027
|
+
switch (_c.label) {
|
|
1966
2028
|
case 0:
|
|
1967
2029
|
if (this.isCrypto)
|
|
1968
2030
|
throw Error("withdrawImbalanceExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1969
2031
|
return [4 /*yield*/, this.calcLpTokenAmount(amounts, false)];
|
|
1970
|
-
case 1: return [2 /*return*/,
|
|
2032
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1971
2033
|
}
|
|
1972
2034
|
});
|
|
1973
2035
|
});
|
|
@@ -1975,7 +2037,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1975
2037
|
// OVERRIDE
|
|
1976
2038
|
PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
|
|
1977
2039
|
return __awaiter(this, void 0, void 0, function () {
|
|
1978
|
-
return __generator(this, function (
|
|
2040
|
+
return __generator(this, function (_c) {
|
|
1979
2041
|
throw Error("withdrawImbalanceBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1980
2042
|
});
|
|
1981
2043
|
});
|
|
@@ -1984,8 +2046,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1984
2046
|
return __awaiter(this, void 0, void 0, function () {
|
|
1985
2047
|
var _amounts, _maxBurnAmount;
|
|
1986
2048
|
var _this = this;
|
|
1987
|
-
return __generator(this, function (
|
|
1988
|
-
switch (
|
|
2049
|
+
return __generator(this, function (_c) {
|
|
2050
|
+
switch (_c.label) {
|
|
1989
2051
|
case 0:
|
|
1990
2052
|
if (this.isCrypto)
|
|
1991
2053
|
throw Error("withdrawImbalanceIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
@@ -1993,9 +2055,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1993
2055
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
|
|
1994
2056
|
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
|
|
1995
2057
|
case 1:
|
|
1996
|
-
_maxBurnAmount = (
|
|
2058
|
+
_maxBurnAmount = (_c.sent()).mul(101).div(100);
|
|
1997
2059
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], curve_1.curve.signerAddress, this.zap)];
|
|
1998
|
-
case 2: return [2 /*return*/,
|
|
2060
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
1999
2061
|
case 3: return [2 /*return*/, true];
|
|
2000
2062
|
}
|
|
2001
2063
|
});
|
|
@@ -2005,8 +2067,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2005
2067
|
return __awaiter(this, void 0, void 0, function () {
|
|
2006
2068
|
var _amounts, _maxBurnAmount;
|
|
2007
2069
|
var _this = this;
|
|
2008
|
-
return __generator(this, function (
|
|
2009
|
-
switch (
|
|
2070
|
+
return __generator(this, function (_c) {
|
|
2071
|
+
switch (_c.label) {
|
|
2010
2072
|
case 0:
|
|
2011
2073
|
if (this.isCrypto)
|
|
2012
2074
|
throw Error("withdrawImbalanceApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
@@ -2014,9 +2076,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2014
2076
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
|
|
2015
2077
|
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
|
|
2016
2078
|
case 1:
|
|
2017
|
-
_maxBurnAmount = (
|
|
2079
|
+
_maxBurnAmount = (_c.sent()).mul(101).div(100);
|
|
2018
2080
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], this.zap)];
|
|
2019
|
-
case 2: return [2 /*return*/,
|
|
2081
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2020
2082
|
case 3: return [2 /*return*/, 0];
|
|
2021
2083
|
}
|
|
2022
2084
|
});
|
|
@@ -2026,8 +2088,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2026
2088
|
return __awaiter(this, void 0, void 0, function () {
|
|
2027
2089
|
var _amounts, _maxBurnAmount;
|
|
2028
2090
|
var _this = this;
|
|
2029
|
-
return __generator(this, function (
|
|
2030
|
-
switch (
|
|
2091
|
+
return __generator(this, function (_c) {
|
|
2092
|
+
switch (_c.label) {
|
|
2031
2093
|
case 0:
|
|
2032
2094
|
if (this.isCrypto)
|
|
2033
2095
|
throw Error("withdrawImbalanceApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
@@ -2035,9 +2097,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2035
2097
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
|
|
2036
2098
|
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
|
|
2037
2099
|
case 1:
|
|
2038
|
-
_maxBurnAmount = (
|
|
2100
|
+
_maxBurnAmount = (_c.sent()).mul(101).div(100);
|
|
2039
2101
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], this.zap)];
|
|
2040
|
-
case 2: return [2 /*return*/,
|
|
2102
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2041
2103
|
case 3: return [2 /*return*/, []];
|
|
2042
2104
|
}
|
|
2043
2105
|
});
|
|
@@ -2046,7 +2108,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2046
2108
|
// OVERRIDE
|
|
2047
2109
|
PoolTemplate.prototype.withdrawImbalanceEstimateGas = function (amounts) {
|
|
2048
2110
|
return __awaiter(this, void 0, void 0, function () {
|
|
2049
|
-
return __generator(this, function (
|
|
2111
|
+
return __generator(this, function (_c) {
|
|
2050
2112
|
throw Error("withdrawImbalance method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2051
2113
|
});
|
|
2052
2114
|
});
|
|
@@ -2055,7 +2117,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2055
2117
|
PoolTemplate.prototype.withdrawImbalance = function (amounts, slippage) {
|
|
2056
2118
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2057
2119
|
return __awaiter(this, void 0, void 0, function () {
|
|
2058
|
-
return __generator(this, function (
|
|
2120
|
+
return __generator(this, function (_c) {
|
|
2059
2121
|
throw Error("withdrawImbalance method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2060
2122
|
});
|
|
2061
2123
|
});
|
|
@@ -2063,13 +2125,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2063
2125
|
// ---------------- WITHDRAW IMBALANCE WRAPPED ----------------
|
|
2064
2126
|
PoolTemplate.prototype.withdrawImbalanceWrappedExpected = function (amounts) {
|
|
2065
2127
|
return __awaiter(this, void 0, void 0, function () {
|
|
2066
|
-
return __generator(this, function (
|
|
2067
|
-
switch (
|
|
2128
|
+
return __generator(this, function (_c) {
|
|
2129
|
+
switch (_c.label) {
|
|
2068
2130
|
case 0:
|
|
2069
2131
|
if (this.isCrypto)
|
|
2070
2132
|
throw Error("withdrawImbalanceWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2071
2133
|
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts, false)];
|
|
2072
|
-
case 1: return [2 /*return*/,
|
|
2134
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2073
2135
|
}
|
|
2074
2136
|
});
|
|
2075
2137
|
});
|
|
@@ -2077,7 +2139,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2077
2139
|
// OVERRIDE
|
|
2078
2140
|
PoolTemplate.prototype.withdrawImbalanceWrappedBonus = function (amounts) {
|
|
2079
2141
|
return __awaiter(this, void 0, void 0, function () {
|
|
2080
|
-
return __generator(this, function (
|
|
2142
|
+
return __generator(this, function (_c) {
|
|
2081
2143
|
throw Error("withdrawImbalanceWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2082
2144
|
});
|
|
2083
2145
|
});
|
|
@@ -2085,7 +2147,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2085
2147
|
// OVERRIDE
|
|
2086
2148
|
PoolTemplate.prototype.withdrawImbalanceWrappedEstimateGas = function (amounts) {
|
|
2087
2149
|
return __awaiter(this, void 0, void 0, function () {
|
|
2088
|
-
return __generator(this, function (
|
|
2150
|
+
return __generator(this, function (_c) {
|
|
2089
2151
|
throw Error("withdrawImbalanceWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2090
2152
|
});
|
|
2091
2153
|
});
|
|
@@ -2094,7 +2156,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2094
2156
|
PoolTemplate.prototype.withdrawImbalanceWrapped = function (amounts, slippage) {
|
|
2095
2157
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2096
2158
|
return __awaiter(this, void 0, void 0, function () {
|
|
2097
|
-
return __generator(this, function (
|
|
2159
|
+
return __generator(this, function (_c) {
|
|
2098
2160
|
throw Error("withdrawImbalanceWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2099
2161
|
});
|
|
2100
2162
|
});
|
|
@@ -2103,7 +2165,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2103
2165
|
// OVERRIDE
|
|
2104
2166
|
PoolTemplate.prototype._withdrawOneCoinExpected = function (_lpTokenAmount, i) {
|
|
2105
2167
|
return __awaiter(this, void 0, void 0, function () {
|
|
2106
|
-
return __generator(this, function (
|
|
2168
|
+
return __generator(this, function (_c) {
|
|
2107
2169
|
throw Error("withdrawOneCoinExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2108
2170
|
});
|
|
2109
2171
|
});
|
|
@@ -2111,14 +2173,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2111
2173
|
PoolTemplate.prototype.withdrawOneCoinExpected = function (lpTokenAmount, coin) {
|
|
2112
2174
|
return __awaiter(this, void 0, void 0, function () {
|
|
2113
2175
|
var i, _lpTokenAmount, _expected;
|
|
2114
|
-
return __generator(this, function (
|
|
2115
|
-
switch (
|
|
2176
|
+
return __generator(this, function (_c) {
|
|
2177
|
+
switch (_c.label) {
|
|
2116
2178
|
case 0:
|
|
2117
2179
|
i = this._getCoinIdx(coin);
|
|
2118
2180
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
2119
2181
|
return [4 /*yield*/, this._withdrawOneCoinExpected(_lpTokenAmount, i)];
|
|
2120
2182
|
case 1:
|
|
2121
|
-
_expected =
|
|
2183
|
+
_expected = _c.sent();
|
|
2122
2184
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.underlyingDecimals[i])];
|
|
2123
2185
|
}
|
|
2124
2186
|
});
|
|
@@ -2127,46 +2189,46 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2127
2189
|
// OVERRIDE
|
|
2128
2190
|
PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
|
|
2129
2191
|
return __awaiter(this, void 0, void 0, function () {
|
|
2130
|
-
return __generator(this, function (
|
|
2192
|
+
return __generator(this, function (_c) {
|
|
2131
2193
|
throw Error("withdrawOneCoinBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2132
2194
|
});
|
|
2133
2195
|
});
|
|
2134
2196
|
};
|
|
2135
2197
|
PoolTemplate.prototype.withdrawOneCoinIsApproved = function (lpTokenAmount) {
|
|
2136
2198
|
return __awaiter(this, void 0, void 0, function () {
|
|
2137
|
-
return __generator(this, function (
|
|
2138
|
-
switch (
|
|
2199
|
+
return __generator(this, function (_c) {
|
|
2200
|
+
switch (_c.label) {
|
|
2139
2201
|
case 0:
|
|
2140
2202
|
if (!this.zap)
|
|
2141
2203
|
return [2 /*return*/, true];
|
|
2142
2204
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
2143
|
-
case 1: return [2 /*return*/,
|
|
2205
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2144
2206
|
}
|
|
2145
2207
|
});
|
|
2146
2208
|
});
|
|
2147
2209
|
};
|
|
2148
2210
|
PoolTemplate.prototype.withdrawOneCoinApproveEstimateGas = function (lpTokenAmount) {
|
|
2149
2211
|
return __awaiter(this, void 0, void 0, function () {
|
|
2150
|
-
return __generator(this, function (
|
|
2151
|
-
switch (
|
|
2212
|
+
return __generator(this, function (_c) {
|
|
2213
|
+
switch (_c.label) {
|
|
2152
2214
|
case 0:
|
|
2153
2215
|
if (!this.zap)
|
|
2154
2216
|
return [2 /*return*/, 0];
|
|
2155
2217
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
2156
|
-
case 1: return [2 /*return*/,
|
|
2218
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2157
2219
|
}
|
|
2158
2220
|
});
|
|
2159
2221
|
});
|
|
2160
2222
|
};
|
|
2161
2223
|
PoolTemplate.prototype.withdrawOneCoinApprove = function (lpTokenAmount) {
|
|
2162
2224
|
return __awaiter(this, void 0, void 0, function () {
|
|
2163
|
-
return __generator(this, function (
|
|
2164
|
-
switch (
|
|
2225
|
+
return __generator(this, function (_c) {
|
|
2226
|
+
switch (_c.label) {
|
|
2165
2227
|
case 0:
|
|
2166
2228
|
if (!this.zap)
|
|
2167
2229
|
return [2 /*return*/, []];
|
|
2168
2230
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
2169
|
-
case 1: return [2 /*return*/,
|
|
2231
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2170
2232
|
}
|
|
2171
2233
|
});
|
|
2172
2234
|
});
|
|
@@ -2174,7 +2236,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2174
2236
|
// OVERRIDE
|
|
2175
2237
|
PoolTemplate.prototype.withdrawOneCoinEstimateGas = function (lpTokenAmount, coin) {
|
|
2176
2238
|
return __awaiter(this, void 0, void 0, function () {
|
|
2177
|
-
return __generator(this, function (
|
|
2239
|
+
return __generator(this, function (_c) {
|
|
2178
2240
|
throw Error("withdrawOneCoin method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2179
2241
|
});
|
|
2180
2242
|
});
|
|
@@ -2183,7 +2245,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2183
2245
|
PoolTemplate.prototype.withdrawOneCoin = function (lpTokenAmount, coin, slippage) {
|
|
2184
2246
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2185
2247
|
return __awaiter(this, void 0, void 0, function () {
|
|
2186
|
-
return __generator(this, function (
|
|
2248
|
+
return __generator(this, function (_c) {
|
|
2187
2249
|
throw Error("withdrawOneCoin method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2188
2250
|
});
|
|
2189
2251
|
});
|
|
@@ -2192,7 +2254,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2192
2254
|
// OVERRIDE
|
|
2193
2255
|
PoolTemplate.prototype._withdrawOneCoinWrappedExpected = function (_lpTokenAmount, i) {
|
|
2194
2256
|
return __awaiter(this, void 0, void 0, function () {
|
|
2195
|
-
return __generator(this, function (
|
|
2257
|
+
return __generator(this, function (_c) {
|
|
2196
2258
|
throw Error("withdrawOneCoinWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2197
2259
|
});
|
|
2198
2260
|
});
|
|
@@ -2200,14 +2262,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2200
2262
|
PoolTemplate.prototype.withdrawOneCoinWrappedExpected = function (lpTokenAmount, coin) {
|
|
2201
2263
|
return __awaiter(this, void 0, void 0, function () {
|
|
2202
2264
|
var i, _lpTokenAmount, _expected;
|
|
2203
|
-
return __generator(this, function (
|
|
2204
|
-
switch (
|
|
2265
|
+
return __generator(this, function (_c) {
|
|
2266
|
+
switch (_c.label) {
|
|
2205
2267
|
case 0:
|
|
2206
2268
|
i = this._getCoinIdx(coin, false);
|
|
2207
2269
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
2208
2270
|
return [4 /*yield*/, this._withdrawOneCoinWrappedExpected(_lpTokenAmount, i)];
|
|
2209
2271
|
case 1:
|
|
2210
|
-
_expected =
|
|
2272
|
+
_expected = _c.sent();
|
|
2211
2273
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.wrappedDecimals[i])];
|
|
2212
2274
|
}
|
|
2213
2275
|
});
|
|
@@ -2216,7 +2278,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2216
2278
|
// OVERRIDE
|
|
2217
2279
|
PoolTemplate.prototype.withdrawOneCoinWrappedBonus = function (lpTokenAmount, coin) {
|
|
2218
2280
|
return __awaiter(this, void 0, void 0, function () {
|
|
2219
|
-
return __generator(this, function (
|
|
2281
|
+
return __generator(this, function (_c) {
|
|
2220
2282
|
throw Error("withdrawOneCoinWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2221
2283
|
});
|
|
2222
2284
|
});
|
|
@@ -2224,7 +2286,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2224
2286
|
// OVERRIDE
|
|
2225
2287
|
PoolTemplate.prototype.withdrawOneCoinWrappedEstimateGas = function (lpTokenAmount, coin) {
|
|
2226
2288
|
return __awaiter(this, void 0, void 0, function () {
|
|
2227
|
-
return __generator(this, function (
|
|
2289
|
+
return __generator(this, function (_c) {
|
|
2228
2290
|
throw Error("withdrawOneCoinWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2229
2291
|
});
|
|
2230
2292
|
});
|
|
@@ -2233,7 +2295,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2233
2295
|
PoolTemplate.prototype.withdrawOneCoinWrapped = function (lpTokenAmount, coin, slippage) {
|
|
2234
2296
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2235
2297
|
return __awaiter(this, void 0, void 0, function () {
|
|
2236
|
-
return __generator(this, function (
|
|
2298
|
+
return __generator(this, function (_c) {
|
|
2237
2299
|
throw Error("withdrawOneCoinWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2238
2300
|
});
|
|
2239
2301
|
});
|
|
@@ -2245,14 +2307,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2245
2307
|
addresses[_i] = arguments[_i];
|
|
2246
2308
|
}
|
|
2247
2309
|
return __awaiter(this, void 0, void 0, function () {
|
|
2248
|
-
return __generator(this, function (
|
|
2249
|
-
switch (
|
|
2310
|
+
return __generator(this, function (_c) {
|
|
2311
|
+
switch (_c.label) {
|
|
2250
2312
|
case 0:
|
|
2251
2313
|
if (!(this.gauge === ethers_1.ethers.constants.AddressZero)) return [3 /*break*/, 2];
|
|
2252
2314
|
return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken'], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true), __spreadArray(__spreadArray([this.lpToken], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true)], addresses, false))];
|
|
2253
|
-
case 1: return [2 /*return*/,
|
|
2315
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2254
2316
|
case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken', 'gauge'], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true), __spreadArray(__spreadArray([this.lpToken, this.gauge], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true)], addresses, false))];
|
|
2255
|
-
case 3: return [2 /*return*/,
|
|
2317
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
2256
2318
|
}
|
|
2257
2319
|
});
|
|
2258
2320
|
});
|
|
@@ -2263,14 +2325,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2263
2325
|
addresses[_i] = arguments[_i];
|
|
2264
2326
|
}
|
|
2265
2327
|
return __awaiter(this, void 0, void 0, function () {
|
|
2266
|
-
return __generator(this, function (
|
|
2267
|
-
switch (
|
|
2328
|
+
return __generator(this, function (_c) {
|
|
2329
|
+
switch (_c.label) {
|
|
2268
2330
|
case 0:
|
|
2269
2331
|
if (!(this.gauge === ethers_1.ethers.constants.AddressZero)) return [3 /*break*/, 2];
|
|
2270
2332
|
return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken'], [this.lpToken]], addresses, false))];
|
|
2271
|
-
case 1: return [2 /*return*/,
|
|
2333
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2272
2334
|
case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
|
|
2273
|
-
case 3: return [2 /*return*/,
|
|
2335
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
2274
2336
|
}
|
|
2275
2337
|
});
|
|
2276
2338
|
});
|
|
@@ -2281,10 +2343,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2281
2343
|
addresses[_i] = arguments[_i];
|
|
2282
2344
|
}
|
|
2283
2345
|
return __awaiter(this, void 0, void 0, function () {
|
|
2284
|
-
return __generator(this, function (
|
|
2285
|
-
switch (
|
|
2346
|
+
return __generator(this, function (_c) {
|
|
2347
|
+
switch (_c.label) {
|
|
2286
2348
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.underlyingCoinAddresses, this.underlyingCoinAddresses], addresses, false))];
|
|
2287
|
-
case 1: return [2 /*return*/,
|
|
2349
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2288
2350
|
}
|
|
2289
2351
|
});
|
|
2290
2352
|
});
|
|
@@ -2295,10 +2357,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2295
2357
|
addresses[_i] = arguments[_i];
|
|
2296
2358
|
}
|
|
2297
2359
|
return __awaiter(this, void 0, void 0, function () {
|
|
2298
|
-
return __generator(this, function (
|
|
2299
|
-
switch (
|
|
2360
|
+
return __generator(this, function (_c) {
|
|
2361
|
+
switch (_c.label) {
|
|
2300
2362
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.wrappedCoinAddresses, this.wrappedCoinAddresses], addresses, false))];
|
|
2301
|
-
case 1: return [2 /*return*/,
|
|
2363
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2302
2364
|
}
|
|
2303
2365
|
});
|
|
2304
2366
|
});
|
|
@@ -2309,10 +2371,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2309
2371
|
addresses[_i] = arguments[_i];
|
|
2310
2372
|
}
|
|
2311
2373
|
return __awaiter(this, void 0, void 0, function () {
|
|
2312
|
-
return __generator(this, function (
|
|
2313
|
-
switch (
|
|
2374
|
+
return __generator(this, function (_c) {
|
|
2375
|
+
switch (_c.label) {
|
|
2314
2376
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray([], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true), __spreadArray(__spreadArray([], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true)], addresses, false))];
|
|
2315
|
-
case 1: return [2 /*return*/,
|
|
2377
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2316
2378
|
}
|
|
2317
2379
|
});
|
|
2318
2380
|
});
|
|
@@ -2321,11 +2383,11 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2321
2383
|
PoolTemplate.prototype._userLpTotalBalance = function (address) {
|
|
2322
2384
|
return __awaiter(this, void 0, void 0, function () {
|
|
2323
2385
|
var lpBalances, lpTotalBalanceBN;
|
|
2324
|
-
return __generator(this, function (
|
|
2325
|
-
switch (
|
|
2386
|
+
return __generator(this, function (_c) {
|
|
2387
|
+
switch (_c.label) {
|
|
2326
2388
|
case 0: return [4 /*yield*/, this.walletLpTokenBalances(address)];
|
|
2327
2389
|
case 1:
|
|
2328
|
-
lpBalances =
|
|
2390
|
+
lpBalances = _c.sent();
|
|
2329
2391
|
lpTotalBalanceBN = (0, utils_1.BN)(lpBalances.lpToken);
|
|
2330
2392
|
if ('gauge' in lpBalances)
|
|
2331
2393
|
lpTotalBalanceBN = lpTotalBalanceBN.plus((0, utils_1.BN)(lpBalances.gauge));
|
|
@@ -2338,17 +2400,17 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2338
2400
|
if (address === void 0) { address = ""; }
|
|
2339
2401
|
return __awaiter(this, void 0, void 0, function () {
|
|
2340
2402
|
var lpTotalBalanceBN;
|
|
2341
|
-
return __generator(this, function (
|
|
2342
|
-
switch (
|
|
2403
|
+
return __generator(this, function (_c) {
|
|
2404
|
+
switch (_c.label) {
|
|
2343
2405
|
case 0:
|
|
2344
2406
|
address = address || curve_1.curve.signerAddress;
|
|
2345
2407
|
if (!address)
|
|
2346
2408
|
throw Error("Need to connect wallet or pass address into args");
|
|
2347
2409
|
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2348
2410
|
case 1:
|
|
2349
|
-
lpTotalBalanceBN =
|
|
2411
|
+
lpTotalBalanceBN = _c.sent();
|
|
2350
2412
|
return [4 /*yield*/, this.withdrawExpected(lpTotalBalanceBN.toString())];
|
|
2351
|
-
case 2: return [2 /*return*/,
|
|
2413
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2352
2414
|
}
|
|
2353
2415
|
});
|
|
2354
2416
|
});
|
|
@@ -2357,17 +2419,17 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2357
2419
|
if (address === void 0) { address = ""; }
|
|
2358
2420
|
return __awaiter(this, void 0, void 0, function () {
|
|
2359
2421
|
var lpTotalBalanceBN;
|
|
2360
|
-
return __generator(this, function (
|
|
2361
|
-
switch (
|
|
2422
|
+
return __generator(this, function (_c) {
|
|
2423
|
+
switch (_c.label) {
|
|
2362
2424
|
case 0:
|
|
2363
2425
|
address = address || curve_1.curve.signerAddress;
|
|
2364
2426
|
if (!address)
|
|
2365
2427
|
throw Error("Need to connect wallet or pass address into args");
|
|
2366
2428
|
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2367
2429
|
case 1:
|
|
2368
|
-
lpTotalBalanceBN =
|
|
2430
|
+
lpTotalBalanceBN = _c.sent();
|
|
2369
2431
|
return [4 /*yield*/, this.withdrawWrappedExpected(lpTotalBalanceBN.toString())];
|
|
2370
|
-
case 2: return [2 /*return*/,
|
|
2432
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2371
2433
|
}
|
|
2372
2434
|
});
|
|
2373
2435
|
});
|
|
@@ -2375,20 +2437,20 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2375
2437
|
PoolTemplate.prototype.userLiquidityUSD = function (address) {
|
|
2376
2438
|
if (address === void 0) { address = ""; }
|
|
2377
2439
|
return __awaiter(this, void 0, void 0, function () {
|
|
2378
|
-
var balances, promises, _i,
|
|
2379
|
-
return __generator(this, function (
|
|
2380
|
-
switch (
|
|
2440
|
+
var balances, promises, _i, _c, addr, prices, totalLiquidity;
|
|
2441
|
+
return __generator(this, function (_d) {
|
|
2442
|
+
switch (_d.label) {
|
|
2381
2443
|
case 0: return [4 /*yield*/, this.userBalances(address)];
|
|
2382
2444
|
case 1:
|
|
2383
|
-
balances =
|
|
2445
|
+
balances = _d.sent();
|
|
2384
2446
|
promises = [];
|
|
2385
|
-
for (_i = 0,
|
|
2386
|
-
addr =
|
|
2447
|
+
for (_i = 0, _c = this.underlyingCoinAddresses; _i < _c.length; _i++) {
|
|
2448
|
+
addr = _c[_i];
|
|
2387
2449
|
promises.push((0, utils_1._getUsdRate)(addr));
|
|
2388
2450
|
}
|
|
2389
2451
|
return [4 /*yield*/, Promise.all(promises)];
|
|
2390
2452
|
case 2:
|
|
2391
|
-
prices =
|
|
2453
|
+
prices = _d.sent();
|
|
2392
2454
|
totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
|
|
2393
2455
|
return [2 /*return*/, totalLiquidity.toFixed(8)];
|
|
2394
2456
|
}
|
|
@@ -2398,19 +2460,19 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2398
2460
|
PoolTemplate.prototype.baseProfit = function (address) {
|
|
2399
2461
|
if (address === void 0) { address = ""; }
|
|
2400
2462
|
return __awaiter(this, void 0, void 0, function () {
|
|
2401
|
-
var apyData, apyBN, totalLiquidityBN,
|
|
2402
|
-
return __generator(this, function (
|
|
2403
|
-
switch (
|
|
2463
|
+
var apyData, apyBN, totalLiquidityBN, _c, annualProfitBN, monthlyProfitBN, weeklyProfitBN, daylyProfitBN;
|
|
2464
|
+
return __generator(this, function (_d) {
|
|
2465
|
+
switch (_d.label) {
|
|
2404
2466
|
case 0: return [4 /*yield*/, this.statsBaseApy()];
|
|
2405
2467
|
case 1:
|
|
2406
|
-
apyData =
|
|
2468
|
+
apyData = _d.sent();
|
|
2407
2469
|
if (!('week' in apyData))
|
|
2408
2470
|
return [2 /*return*/, { day: "0", week: "0", month: "0", year: "0" }];
|
|
2409
2471
|
apyBN = (0, utils_1.BN)(apyData.week).div(100);
|
|
2410
|
-
|
|
2472
|
+
_c = utils_1.BN;
|
|
2411
2473
|
return [4 /*yield*/, this.userLiquidityUSD(address)];
|
|
2412
2474
|
case 2:
|
|
2413
|
-
totalLiquidityBN =
|
|
2475
|
+
totalLiquidityBN = _c.apply(void 0, [_d.sent()]);
|
|
2414
2476
|
annualProfitBN = apyBN.times(totalLiquidityBN);
|
|
2415
2477
|
monthlyProfitBN = annualProfitBN.div(12);
|
|
2416
2478
|
weeklyProfitBN = annualProfitBN.div(52);
|
|
@@ -2428,10 +2490,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2428
2490
|
PoolTemplate.prototype.userShare = function (address) {
|
|
2429
2491
|
if (address === void 0) { address = ""; }
|
|
2430
2492
|
return __awaiter(this, void 0, void 0, function () {
|
|
2431
|
-
var withGauge, userLpBalance, userLpTotalBalanceBN, totalLp, gaugeLp,
|
|
2432
|
-
var
|
|
2433
|
-
return __generator(this, function (
|
|
2434
|
-
switch (
|
|
2493
|
+
var withGauge, userLpBalance, userLpTotalBalanceBN, totalLp, gaugeLp, _c, _d;
|
|
2494
|
+
var _e;
|
|
2495
|
+
return __generator(this, function (_f) {
|
|
2496
|
+
switch (_f.label) {
|
|
2435
2497
|
case 0:
|
|
2436
2498
|
withGauge = this.gauge !== ethers_1.ethers.constants.AddressZero;
|
|
2437
2499
|
address = address || curve_1.curve.signerAddress;
|
|
@@ -2439,7 +2501,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2439
2501
|
throw Error("Need to connect wallet or pass address into args");
|
|
2440
2502
|
return [4 /*yield*/, this.walletLpTokenBalances(address)];
|
|
2441
2503
|
case 1:
|
|
2442
|
-
userLpBalance =
|
|
2504
|
+
userLpBalance = _f.sent();
|
|
2443
2505
|
userLpTotalBalanceBN = (0, utils_1.BN)(userLpBalance.lpToken);
|
|
2444
2506
|
if (withGauge)
|
|
2445
2507
|
userLpTotalBalanceBN = userLpTotalBalanceBN.plus((0, utils_1.BN)(userLpBalance.gauge));
|
|
@@ -2449,14 +2511,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2449
2511
|
curve_1.curve.contracts[this.gauge].multicallContract.totalSupply(),
|
|
2450
2512
|
])];
|
|
2451
2513
|
case 2:
|
|
2452
|
-
|
|
2514
|
+
_e = (_f.sent()).map(function (_supply) { return ethers_1.ethers.utils.formatUnits(_supply); }), totalLp = _e[0], gaugeLp = _e[1];
|
|
2453
2515
|
return [3 /*break*/, 5];
|
|
2454
2516
|
case 3:
|
|
2455
|
-
|
|
2517
|
+
_d = (_c = ethers_1.ethers.utils).formatUnits;
|
|
2456
2518
|
return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply()];
|
|
2457
2519
|
case 4:
|
|
2458
|
-
totalLp =
|
|
2459
|
-
|
|
2520
|
+
totalLp = _d.apply(_c, [_f.sent()]);
|
|
2521
|
+
_f.label = 5;
|
|
2460
2522
|
case 5: return [2 /*return*/, {
|
|
2461
2523
|
lpUser: userLpTotalBalanceBN.toString(),
|
|
2462
2524
|
lpTotal: totalLp,
|
|
@@ -2473,16 +2535,16 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2473
2535
|
PoolTemplate.prototype._swapExpected = function (i, j, _amount) {
|
|
2474
2536
|
return __awaiter(this, void 0, void 0, function () {
|
|
2475
2537
|
var contractAddress, contract;
|
|
2476
|
-
return __generator(this, function (
|
|
2477
|
-
switch (
|
|
2538
|
+
return __generator(this, function (_c) {
|
|
2539
|
+
switch (_c.label) {
|
|
2478
2540
|
case 0:
|
|
2479
2541
|
contractAddress = this.isCrypto && this.isMeta ? this.zap : this.address;
|
|
2480
2542
|
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
2481
2543
|
if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
|
|
2482
2544
|
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
|
|
2483
|
-
case 1: return [2 /*return*/,
|
|
2545
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2484
2546
|
case 2: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
|
|
2485
|
-
case 3: return [2 /*return*/,
|
|
2547
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
2486
2548
|
}
|
|
2487
2549
|
});
|
|
2488
2550
|
});
|
|
@@ -2490,15 +2552,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2490
2552
|
PoolTemplate.prototype.swapExpected = function (inputCoin, outputCoin, amount) {
|
|
2491
2553
|
return __awaiter(this, void 0, void 0, function () {
|
|
2492
2554
|
var i, j, _amount, _expected;
|
|
2493
|
-
return __generator(this, function (
|
|
2494
|
-
switch (
|
|
2555
|
+
return __generator(this, function (_c) {
|
|
2556
|
+
switch (_c.label) {
|
|
2495
2557
|
case 0:
|
|
2496
2558
|
i = this._getCoinIdx(inputCoin);
|
|
2497
2559
|
j = this._getCoinIdx(outputCoin);
|
|
2498
2560
|
_amount = (0, utils_1.parseUnits)(amount, this.underlyingDecimals[i]);
|
|
2499
2561
|
return [4 /*yield*/, this._swapExpected(i, j, _amount)];
|
|
2500
2562
|
case 1:
|
|
2501
|
-
_expected =
|
|
2563
|
+
_expected = _c.sent();
|
|
2502
2564
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.underlyingDecimals[j])];
|
|
2503
2565
|
}
|
|
2504
2566
|
});
|
|
@@ -2506,17 +2568,17 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2506
2568
|
};
|
|
2507
2569
|
PoolTemplate.prototype.swapPriceImpact = function (inputCoin, outputCoin, amount) {
|
|
2508
2570
|
return __awaiter(this, void 0, void 0, function () {
|
|
2509
|
-
var i, j,
|
|
2510
|
-
return __generator(this, function (
|
|
2511
|
-
switch (
|
|
2571
|
+
var i, j, _c, inputCoinDecimals, outputCoinDecimals, _amount, _output, target, amountIntBN, outputIntBN, k, smallAmountIntBN, _smallAmount, _smallOutput, amountBN, outputBN, smallAmountBN, smallOutputBN, rateBN, smallRateBN, slippageBN;
|
|
2572
|
+
return __generator(this, function (_d) {
|
|
2573
|
+
switch (_d.label) {
|
|
2512
2574
|
case 0:
|
|
2513
2575
|
i = this._getCoinIdx(inputCoin);
|
|
2514
2576
|
j = this._getCoinIdx(outputCoin);
|
|
2515
|
-
|
|
2577
|
+
_c = [this.underlyingDecimals[i], this.underlyingDecimals[j]], inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2516
2578
|
_amount = (0, utils_1.parseUnits)(amount, inputCoinDecimals);
|
|
2517
2579
|
return [4 /*yield*/, this._swapExpected(i, j, _amount)];
|
|
2518
2580
|
case 1:
|
|
2519
|
-
_output =
|
|
2581
|
+
_output = _d.sent();
|
|
2520
2582
|
target = (0, utils_1.BN)(Math.pow(10, 15));
|
|
2521
2583
|
amountIntBN = (0, utils_1.BN)(amount).times(Math.pow(10, inputCoinDecimals));
|
|
2522
2584
|
outputIntBN = (0, utils_1.toBN)(_output, 0);
|
|
@@ -2527,7 +2589,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2527
2589
|
_smallAmount = (0, utils_1.fromBN)(smallAmountIntBN.div(Math.pow(10, inputCoinDecimals)), inputCoinDecimals);
|
|
2528
2590
|
return [4 /*yield*/, this._swapExpected(i, j, _smallAmount)];
|
|
2529
2591
|
case 2:
|
|
2530
|
-
_smallOutput =
|
|
2592
|
+
_smallOutput = _d.sent();
|
|
2531
2593
|
amountBN = (0, utils_1.BN)(amount);
|
|
2532
2594
|
outputBN = (0, utils_1.toBN)(_output, outputCoinDecimals);
|
|
2533
2595
|
smallAmountBN = (0, utils_1.toBN)(_smallAmount, inputCoinDecimals);
|
|
@@ -2546,13 +2608,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2546
2608
|
PoolTemplate.prototype.swapIsApproved = function (inputCoin, amount) {
|
|
2547
2609
|
return __awaiter(this, void 0, void 0, function () {
|
|
2548
2610
|
var contractAddress, i;
|
|
2549
|
-
return __generator(this, function (
|
|
2550
|
-
switch (
|
|
2611
|
+
return __generator(this, function (_c) {
|
|
2612
|
+
switch (_c.label) {
|
|
2551
2613
|
case 0:
|
|
2552
2614
|
contractAddress = this._swapContractAddress();
|
|
2553
2615
|
i = this._getCoinIdx(inputCoin);
|
|
2554
2616
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
|
|
2555
|
-
case 1: return [2 /*return*/,
|
|
2617
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2556
2618
|
}
|
|
2557
2619
|
});
|
|
2558
2620
|
});
|
|
@@ -2560,13 +2622,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2560
2622
|
PoolTemplate.prototype.swapApproveEstimateGas = function (inputCoin, amount) {
|
|
2561
2623
|
return __awaiter(this, void 0, void 0, function () {
|
|
2562
2624
|
var contractAddress, i;
|
|
2563
|
-
return __generator(this, function (
|
|
2564
|
-
switch (
|
|
2625
|
+
return __generator(this, function (_c) {
|
|
2626
|
+
switch (_c.label) {
|
|
2565
2627
|
case 0:
|
|
2566
2628
|
contractAddress = this._swapContractAddress();
|
|
2567
2629
|
i = this._getCoinIdx(inputCoin);
|
|
2568
2630
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
2569
|
-
case 1: return [2 /*return*/,
|
|
2631
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2570
2632
|
}
|
|
2571
2633
|
});
|
|
2572
2634
|
});
|
|
@@ -2574,13 +2636,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2574
2636
|
PoolTemplate.prototype.swapApprove = function (inputCoin, amount) {
|
|
2575
2637
|
return __awaiter(this, void 0, void 0, function () {
|
|
2576
2638
|
var contractAddress, i;
|
|
2577
|
-
return __generator(this, function (
|
|
2578
|
-
switch (
|
|
2639
|
+
return __generator(this, function (_c) {
|
|
2640
|
+
switch (_c.label) {
|
|
2579
2641
|
case 0:
|
|
2580
2642
|
contractAddress = this._swapContractAddress();
|
|
2581
2643
|
i = this._getCoinIdx(inputCoin);
|
|
2582
2644
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
2583
|
-
case 1: return [2 /*return*/,
|
|
2645
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2584
2646
|
}
|
|
2585
2647
|
});
|
|
2586
2648
|
});
|
|
@@ -2588,7 +2650,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2588
2650
|
// OVERRIDE
|
|
2589
2651
|
PoolTemplate.prototype.swapEstimateGas = function (inputCoin, outputCoin, amount) {
|
|
2590
2652
|
return __awaiter(this, void 0, void 0, function () {
|
|
2591
|
-
return __generator(this, function (
|
|
2653
|
+
return __generator(this, function (_c) {
|
|
2592
2654
|
throw Error("swap method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2593
2655
|
});
|
|
2594
2656
|
});
|
|
@@ -2597,7 +2659,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2597
2659
|
PoolTemplate.prototype.swap = function (inputCoin, outputCoin, amount, slippage) {
|
|
2598
2660
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2599
2661
|
return __awaiter(this, void 0, void 0, function () {
|
|
2600
|
-
return __generator(this, function (
|
|
2662
|
+
return __generator(this, function (_c) {
|
|
2601
2663
|
throw Error("swap method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2602
2664
|
});
|
|
2603
2665
|
});
|
|
@@ -2605,10 +2667,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2605
2667
|
// ---------------- SWAP WRAPPED ----------------
|
|
2606
2668
|
PoolTemplate.prototype._swapWrappedExpected = function (i, j, _amount) {
|
|
2607
2669
|
return __awaiter(this, void 0, void 0, function () {
|
|
2608
|
-
return __generator(this, function (
|
|
2609
|
-
switch (
|
|
2670
|
+
return __generator(this, function (_c) {
|
|
2671
|
+
switch (_c.label) {
|
|
2610
2672
|
case 0: return [4 /*yield*/, curve_1.curve.contracts[this.address].contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
|
|
2611
|
-
case 1: return [2 /*return*/,
|
|
2673
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2612
2674
|
}
|
|
2613
2675
|
});
|
|
2614
2676
|
});
|
|
@@ -2616,27 +2678,27 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2616
2678
|
// OVERRIDE
|
|
2617
2679
|
PoolTemplate.prototype.swapWrappedExpected = function (inputCoin, outputCoin, amount) {
|
|
2618
2680
|
return __awaiter(this, void 0, void 0, function () {
|
|
2619
|
-
return __generator(this, function (
|
|
2681
|
+
return __generator(this, function (_c) {
|
|
2620
2682
|
throw Error("swapWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2621
2683
|
});
|
|
2622
2684
|
});
|
|
2623
2685
|
};
|
|
2624
2686
|
PoolTemplate.prototype.swapWrappedPriceImpact = function (inputCoin, outputCoin, amount) {
|
|
2625
2687
|
return __awaiter(this, void 0, void 0, function () {
|
|
2626
|
-
var i, j,
|
|
2627
|
-
return __generator(this, function (
|
|
2628
|
-
switch (
|
|
2688
|
+
var i, j, _c, inputCoinDecimals, outputCoinDecimals, _amount, _output, target, amountIntBN, outputIntBN, k, smallAmountIntBN, _smallAmount, _smallOutput, amountBN, outputBN, smallAmountBN, smallOutputBN, rateBN, smallRateBN, slippageBN;
|
|
2689
|
+
return __generator(this, function (_d) {
|
|
2690
|
+
switch (_d.label) {
|
|
2629
2691
|
case 0:
|
|
2630
2692
|
if (this.isPlain || this.isFake) {
|
|
2631
2693
|
throw Error("swapWrappedPriceImpact method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2632
2694
|
}
|
|
2633
2695
|
i = this._getCoinIdx(inputCoin, false);
|
|
2634
2696
|
j = this._getCoinIdx(outputCoin, false);
|
|
2635
|
-
|
|
2697
|
+
_c = [this.wrappedDecimals[i], this.wrappedDecimals[j]], inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2636
2698
|
_amount = (0, utils_1.parseUnits)(amount, inputCoinDecimals);
|
|
2637
2699
|
return [4 /*yield*/, this._swapWrappedExpected(i, j, _amount)];
|
|
2638
2700
|
case 1:
|
|
2639
|
-
_output =
|
|
2701
|
+
_output = _d.sent();
|
|
2640
2702
|
target = (0, utils_1.BN)(Math.pow(10, 15));
|
|
2641
2703
|
amountIntBN = (0, utils_1.BN)(amount).times(Math.pow(10, inputCoinDecimals));
|
|
2642
2704
|
outputIntBN = (0, utils_1.toBN)(_output, 0);
|
|
@@ -2647,7 +2709,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2647
2709
|
_smallAmount = (0, utils_1.fromBN)(smallAmountIntBN.div(Math.pow(10, inputCoinDecimals)), inputCoinDecimals);
|
|
2648
2710
|
return [4 /*yield*/, this._swapWrappedExpected(i, j, _smallAmount)];
|
|
2649
2711
|
case 2:
|
|
2650
|
-
_smallOutput =
|
|
2712
|
+
_smallOutput = _d.sent();
|
|
2651
2713
|
amountBN = (0, utils_1.BN)(amount);
|
|
2652
2714
|
outputBN = (0, utils_1.toBN)(_output, outputCoinDecimals);
|
|
2653
2715
|
smallAmountBN = (0, utils_1.toBN)(_smallAmount, inputCoinDecimals);
|
|
@@ -2663,7 +2725,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2663
2725
|
// OVERRIDE
|
|
2664
2726
|
PoolTemplate.prototype.swapWrappedIsApproved = function (inputCoin, amount) {
|
|
2665
2727
|
return __awaiter(this, void 0, void 0, function () {
|
|
2666
|
-
return __generator(this, function (
|
|
2728
|
+
return __generator(this, function (_c) {
|
|
2667
2729
|
throw Error("swapWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2668
2730
|
});
|
|
2669
2731
|
});
|
|
@@ -2671,7 +2733,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2671
2733
|
// OVERRIDE
|
|
2672
2734
|
PoolTemplate.prototype.swapWrappedApproveEstimateGas = function (inputCoin, amount) {
|
|
2673
2735
|
return __awaiter(this, void 0, void 0, function () {
|
|
2674
|
-
return __generator(this, function (
|
|
2736
|
+
return __generator(this, function (_c) {
|
|
2675
2737
|
throw Error("swapWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2676
2738
|
});
|
|
2677
2739
|
});
|
|
@@ -2679,7 +2741,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2679
2741
|
// OVERRIDE
|
|
2680
2742
|
PoolTemplate.prototype.swapWrappedApprove = function (inputCoin, amount) {
|
|
2681
2743
|
return __awaiter(this, void 0, void 0, function () {
|
|
2682
|
-
return __generator(this, function (
|
|
2744
|
+
return __generator(this, function (_c) {
|
|
2683
2745
|
throw Error("swapWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2684
2746
|
});
|
|
2685
2747
|
});
|
|
@@ -2687,7 +2749,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2687
2749
|
// OVERRIDE
|
|
2688
2750
|
PoolTemplate.prototype.swapWrappedEstimateGas = function (inputCoin, outputCoin, amount) {
|
|
2689
2751
|
return __awaiter(this, void 0, void 0, function () {
|
|
2690
|
-
return __generator(this, function (
|
|
2752
|
+
return __generator(this, function (_c) {
|
|
2691
2753
|
throw Error("swapWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2692
2754
|
});
|
|
2693
2755
|
});
|
|
@@ -2696,7 +2758,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2696
2758
|
PoolTemplate.prototype.swapWrapped = function (inputCoin, outputCoin, amount, slippage) {
|
|
2697
2759
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2698
2760
|
return __awaiter(this, void 0, void 0, function () {
|
|
2699
|
-
return __generator(this, function (
|
|
2761
|
+
return __generator(this, function (_c) {
|
|
2700
2762
|
throw Error("swapWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2701
2763
|
});
|
|
2702
2764
|
});
|