@curvefi/api 2.8.1 → 2.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/constants/abis/atricrypto3/base_pool_zap.json +216 -0
- package/lib/constants/abis/gauge_v5.json +1 -1
- package/lib/factory/common.d.ts +1 -0
- package/lib/factory/common.js +12 -1
- package/lib/factory/constants.js +5 -0
- package/lib/factory/factory-api.js +101 -30
- package/lib/factory/factory-crypto.js +75 -22
- package/lib/factory/factory.js +31 -12
- package/lib/pools/PoolTemplate.d.ts +1 -0
- package/lib/pools/PoolTemplate.js +577 -503
- package/lib/pools/mixins/common.d.ts +1 -0
- package/lib/pools/mixins/common.js +30 -1
- package/lib/pools/mixins/poolBalancesMixin.js +14 -6
- package/lib/pools/mixins/withdrawExpectedMixins.js +17 -15
- package/lib/pools/poolConstructor.js +1 -1
- package/lib/utils.js +3 -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: 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,37 @@ 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
|
-
_rates_1 = _a.sent();
|
|
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;
|
|
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;
|
|
1006
1068
|
if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/, 4];
|
|
1069
|
+
if (!contract["calc_token_amount(address,uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 2];
|
|
1007
1070
|
return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1008
|
-
case
|
|
1071
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1072
|
+
case 2: return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, curve_1.curve.constantOptions)];
|
|
1073
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
1009
1074
|
case 4:
|
|
1010
|
-
if (!contract["calc_token_amount(uint256[".concat(
|
|
1075
|
+
if (!contract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 6];
|
|
1011
1076
|
return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1012
|
-
case 5: return [2 /*return*/,
|
|
1077
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
1013
1078
|
case 6: return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
1014
|
-
case 7: return [2 /*return*/,
|
|
1079
|
+
case 7: return [2 /*return*/, _c.sent()];
|
|
1015
1080
|
}
|
|
1016
1081
|
});
|
|
1017
1082
|
});
|
|
@@ -1021,8 +1086,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1021
1086
|
return __awaiter(this, void 0, void 0, function () {
|
|
1022
1087
|
var _underlyingAmounts, _expected;
|
|
1023
1088
|
var _this = this;
|
|
1024
|
-
return __generator(this, function (
|
|
1025
|
-
switch (
|
|
1089
|
+
return __generator(this, function (_c) {
|
|
1090
|
+
switch (_c.label) {
|
|
1026
1091
|
case 0:
|
|
1027
1092
|
if (amounts.length !== this.underlyingCoinAddresses.length) {
|
|
1028
1093
|
throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
@@ -1030,7 +1095,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1030
1095
|
_underlyingAmounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
|
|
1031
1096
|
return [4 /*yield*/, this._calcLpTokenAmount(_underlyingAmounts, isDeposit, true)];
|
|
1032
1097
|
case 1:
|
|
1033
|
-
_expected =
|
|
1098
|
+
_expected = _c.sent();
|
|
1034
1099
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected)];
|
|
1035
1100
|
}
|
|
1036
1101
|
});
|
|
@@ -1041,8 +1106,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1041
1106
|
return __awaiter(this, void 0, void 0, function () {
|
|
1042
1107
|
var _amounts, _expected;
|
|
1043
1108
|
var _this = this;
|
|
1044
|
-
return __generator(this, function (
|
|
1045
|
-
switch (
|
|
1109
|
+
return __generator(this, function (_c) {
|
|
1110
|
+
switch (_c.label) {
|
|
1046
1111
|
case 0:
|
|
1047
1112
|
if (amounts.length !== this.wrappedCoinAddresses.length) {
|
|
1048
1113
|
throw Error("".concat(this.name, " pool has ").concat(this.wrappedCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
@@ -1053,7 +1118,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1053
1118
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.wrappedDecimals[i]); });
|
|
1054
1119
|
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, isDeposit, false)];
|
|
1055
1120
|
case 1:
|
|
1056
|
-
_expected =
|
|
1121
|
+
_expected = _c.sent();
|
|
1057
1122
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected)];
|
|
1058
1123
|
}
|
|
1059
1124
|
});
|
|
@@ -1062,17 +1127,17 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1062
1127
|
// ---------------- DEPOSIT ----------------
|
|
1063
1128
|
PoolTemplate.prototype.depositBalancedAmounts = function () {
|
|
1064
1129
|
return __awaiter(this, void 0, void 0, function () {
|
|
1065
|
-
return __generator(this, function (
|
|
1130
|
+
return __generator(this, function (_c) {
|
|
1066
1131
|
throw Error("depositBalancedAmounts method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1067
1132
|
});
|
|
1068
1133
|
});
|
|
1069
1134
|
};
|
|
1070
1135
|
PoolTemplate.prototype.depositExpected = function (amounts) {
|
|
1071
1136
|
return __awaiter(this, void 0, void 0, function () {
|
|
1072
|
-
return __generator(this, function (
|
|
1073
|
-
switch (
|
|
1137
|
+
return __generator(this, function (_c) {
|
|
1138
|
+
switch (_c.label) {
|
|
1074
1139
|
case 0: return [4 /*yield*/, this.calcLpTokenAmount(amounts)];
|
|
1075
|
-
case 1: return [2 /*return*/,
|
|
1140
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1076
1141
|
}
|
|
1077
1142
|
});
|
|
1078
1143
|
});
|
|
@@ -1080,37 +1145,37 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1080
1145
|
// OVERRIDE
|
|
1081
1146
|
PoolTemplate.prototype.depositBonus = function (amounts) {
|
|
1082
1147
|
return __awaiter(this, void 0, void 0, function () {
|
|
1083
|
-
return __generator(this, function (
|
|
1148
|
+
return __generator(this, function (_c) {
|
|
1084
1149
|
throw Error("depositBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1085
1150
|
});
|
|
1086
1151
|
});
|
|
1087
1152
|
};
|
|
1088
1153
|
PoolTemplate.prototype.depositIsApproved = function (amounts) {
|
|
1089
1154
|
return __awaiter(this, void 0, void 0, function () {
|
|
1090
|
-
return __generator(this, function (
|
|
1091
|
-
switch (
|
|
1155
|
+
return __generator(this, function (_c) {
|
|
1156
|
+
switch (_c.label) {
|
|
1092
1157
|
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*/,
|
|
1158
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1094
1159
|
}
|
|
1095
1160
|
});
|
|
1096
1161
|
});
|
|
1097
1162
|
};
|
|
1098
1163
|
PoolTemplate.prototype.depositApproveEstimateGas = function (amounts) {
|
|
1099
1164
|
return __awaiter(this, void 0, void 0, function () {
|
|
1100
|
-
return __generator(this, function (
|
|
1101
|
-
switch (
|
|
1165
|
+
return __generator(this, function (_c) {
|
|
1166
|
+
switch (_c.label) {
|
|
1102
1167
|
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, this.zap || this.address)];
|
|
1103
|
-
case 1: return [2 /*return*/,
|
|
1168
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1104
1169
|
}
|
|
1105
1170
|
});
|
|
1106
1171
|
});
|
|
1107
1172
|
};
|
|
1108
1173
|
PoolTemplate.prototype.depositApprove = function (amounts) {
|
|
1109
1174
|
return __awaiter(this, void 0, void 0, function () {
|
|
1110
|
-
return __generator(this, function (
|
|
1111
|
-
switch (
|
|
1175
|
+
return __generator(this, function (_c) {
|
|
1176
|
+
switch (_c.label) {
|
|
1112
1177
|
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, this.zap || this.address)];
|
|
1113
|
-
case 1: return [2 /*return*/,
|
|
1178
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1114
1179
|
}
|
|
1115
1180
|
});
|
|
1116
1181
|
});
|
|
@@ -1118,7 +1183,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1118
1183
|
// OVERRIDE
|
|
1119
1184
|
PoolTemplate.prototype.depositEstimateGas = function (amounts) {
|
|
1120
1185
|
return __awaiter(this, void 0, void 0, function () {
|
|
1121
|
-
return __generator(this, function (
|
|
1186
|
+
return __generator(this, function (_c) {
|
|
1122
1187
|
throw Error("depositEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1123
1188
|
});
|
|
1124
1189
|
});
|
|
@@ -1127,7 +1192,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1127
1192
|
PoolTemplate.prototype.deposit = function (amounts, slippage) {
|
|
1128
1193
|
if (slippage === void 0) { slippage = 0.5; }
|
|
1129
1194
|
return __awaiter(this, void 0, void 0, function () {
|
|
1130
|
-
return __generator(this, function (
|
|
1195
|
+
return __generator(this, function (_c) {
|
|
1131
1196
|
throw Error("deposit method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1132
1197
|
});
|
|
1133
1198
|
});
|
|
@@ -1135,21 +1200,21 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1135
1200
|
// ---------------- DEPOSIT WRAPPED ----------------
|
|
1136
1201
|
PoolTemplate.prototype.depositWrappedBalancedAmounts = function () {
|
|
1137
1202
|
return __awaiter(this, void 0, void 0, function () {
|
|
1138
|
-
return __generator(this, function (
|
|
1203
|
+
return __generator(this, function (_c) {
|
|
1139
1204
|
throw Error("depositWrappedBalancedAmounts method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1140
1205
|
});
|
|
1141
1206
|
});
|
|
1142
1207
|
};
|
|
1143
1208
|
PoolTemplate.prototype.depositWrappedExpected = function (amounts) {
|
|
1144
1209
|
return __awaiter(this, void 0, void 0, function () {
|
|
1145
|
-
return __generator(this, function (
|
|
1146
|
-
switch (
|
|
1210
|
+
return __generator(this, function (_c) {
|
|
1211
|
+
switch (_c.label) {
|
|
1147
1212
|
case 0:
|
|
1148
1213
|
if (this.isFake) {
|
|
1149
1214
|
throw Error("depositWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1150
1215
|
}
|
|
1151
1216
|
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts)];
|
|
1152
|
-
case 1: return [2 /*return*/,
|
|
1217
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1153
1218
|
}
|
|
1154
1219
|
});
|
|
1155
1220
|
});
|
|
@@ -1157,49 +1222,49 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1157
1222
|
// OVERRIDE
|
|
1158
1223
|
PoolTemplate.prototype.depositWrappedBonus = function (amounts) {
|
|
1159
1224
|
return __awaiter(this, void 0, void 0, function () {
|
|
1160
|
-
return __generator(this, function (
|
|
1225
|
+
return __generator(this, function (_c) {
|
|
1161
1226
|
throw Error("depositWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1162
1227
|
});
|
|
1163
1228
|
});
|
|
1164
1229
|
};
|
|
1165
1230
|
PoolTemplate.prototype.depositWrappedIsApproved = function (amounts) {
|
|
1166
1231
|
return __awaiter(this, void 0, void 0, function () {
|
|
1167
|
-
return __generator(this, function (
|
|
1168
|
-
switch (
|
|
1232
|
+
return __generator(this, function (_c) {
|
|
1233
|
+
switch (_c.label) {
|
|
1169
1234
|
case 0:
|
|
1170
1235
|
if (this.isFake) {
|
|
1171
1236
|
throw Error("depositWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1172
1237
|
}
|
|
1173
1238
|
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.signerAddress, this.address)];
|
|
1174
|
-
case 1: return [2 /*return*/,
|
|
1239
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1175
1240
|
}
|
|
1176
1241
|
});
|
|
1177
1242
|
});
|
|
1178
1243
|
};
|
|
1179
1244
|
PoolTemplate.prototype.depositWrappedApproveEstimateGas = function (amounts) {
|
|
1180
1245
|
return __awaiter(this, void 0, void 0, function () {
|
|
1181
|
-
return __generator(this, function (
|
|
1182
|
-
switch (
|
|
1246
|
+
return __generator(this, function (_c) {
|
|
1247
|
+
switch (_c.label) {
|
|
1183
1248
|
case 0:
|
|
1184
1249
|
if (this.isFake) {
|
|
1185
1250
|
throw Error("depositWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1186
1251
|
}
|
|
1187
1252
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.wrappedCoinAddresses, amounts, this.address)];
|
|
1188
|
-
case 1: return [2 /*return*/,
|
|
1253
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1189
1254
|
}
|
|
1190
1255
|
});
|
|
1191
1256
|
});
|
|
1192
1257
|
};
|
|
1193
1258
|
PoolTemplate.prototype.depositWrappedApprove = function (amounts) {
|
|
1194
1259
|
return __awaiter(this, void 0, void 0, function () {
|
|
1195
|
-
return __generator(this, function (
|
|
1196
|
-
switch (
|
|
1260
|
+
return __generator(this, function (_c) {
|
|
1261
|
+
switch (_c.label) {
|
|
1197
1262
|
case 0:
|
|
1198
1263
|
if (this.isFake) {
|
|
1199
1264
|
throw Error("depositWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1200
1265
|
}
|
|
1201
1266
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.wrappedCoinAddresses, amounts, this.address)];
|
|
1202
|
-
case 1: return [2 /*return*/,
|
|
1267
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1203
1268
|
}
|
|
1204
1269
|
});
|
|
1205
1270
|
});
|
|
@@ -1207,7 +1272,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1207
1272
|
// OVERRIDE
|
|
1208
1273
|
PoolTemplate.prototype.depositWrappedEstimateGas = function (amounts) {
|
|
1209
1274
|
return __awaiter(this, void 0, void 0, function () {
|
|
1210
|
-
return __generator(this, function (
|
|
1275
|
+
return __generator(this, function (_c) {
|
|
1211
1276
|
throw Error("depositWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1212
1277
|
});
|
|
1213
1278
|
});
|
|
@@ -1216,7 +1281,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1216
1281
|
PoolTemplate.prototype.depositWrapped = function (amounts, slippage) {
|
|
1217
1282
|
if (slippage === void 0) { slippage = 0.5; }
|
|
1218
1283
|
return __awaiter(this, void 0, void 0, function () {
|
|
1219
|
-
return __generator(this, function (
|
|
1284
|
+
return __generator(this, function (_c) {
|
|
1220
1285
|
throw Error("depositWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1221
1286
|
});
|
|
1222
1287
|
});
|
|
@@ -1224,42 +1289,42 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1224
1289
|
// ---------------- STAKING ----------------
|
|
1225
1290
|
PoolTemplate.prototype.stakeIsApproved = function (lpTokenAmount) {
|
|
1226
1291
|
return __awaiter(this, void 0, void 0, function () {
|
|
1227
|
-
return __generator(this, function (
|
|
1228
|
-
switch (
|
|
1292
|
+
return __generator(this, function (_c) {
|
|
1293
|
+
switch (_c.label) {
|
|
1229
1294
|
case 0:
|
|
1230
1295
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1231
1296
|
throw Error("stakeIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1232
1297
|
}
|
|
1233
1298
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.gauge)];
|
|
1234
|
-
case 1: return [2 /*return*/,
|
|
1299
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1235
1300
|
}
|
|
1236
1301
|
});
|
|
1237
1302
|
});
|
|
1238
1303
|
};
|
|
1239
1304
|
PoolTemplate.prototype.stakeApproveEstimateGas = function (lpTokenAmount) {
|
|
1240
1305
|
return __awaiter(this, void 0, void 0, function () {
|
|
1241
|
-
return __generator(this, function (
|
|
1242
|
-
switch (
|
|
1306
|
+
return __generator(this, function (_c) {
|
|
1307
|
+
switch (_c.label) {
|
|
1243
1308
|
case 0:
|
|
1244
1309
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1245
1310
|
throw Error("stakeApproveEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1246
1311
|
}
|
|
1247
1312
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.gauge)];
|
|
1248
|
-
case 1: return [2 /*return*/,
|
|
1313
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1249
1314
|
}
|
|
1250
1315
|
});
|
|
1251
1316
|
});
|
|
1252
1317
|
};
|
|
1253
1318
|
PoolTemplate.prototype.stakeApprove = function (lpTokenAmount) {
|
|
1254
1319
|
return __awaiter(this, void 0, void 0, function () {
|
|
1255
|
-
return __generator(this, function (
|
|
1256
|
-
switch (
|
|
1320
|
+
return __generator(this, function (_c) {
|
|
1321
|
+
switch (_c.label) {
|
|
1257
1322
|
case 0:
|
|
1258
1323
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1259
1324
|
throw Error("stakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1260
1325
|
}
|
|
1261
1326
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.gauge)];
|
|
1262
|
-
case 1: return [2 /*return*/,
|
|
1327
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1263
1328
|
}
|
|
1264
1329
|
});
|
|
1265
1330
|
});
|
|
@@ -1267,15 +1332,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1267
1332
|
PoolTemplate.prototype.stakeEstimateGas = function (lpTokenAmount) {
|
|
1268
1333
|
return __awaiter(this, void 0, void 0, function () {
|
|
1269
1334
|
var _lpTokenAmount;
|
|
1270
|
-
return __generator(this, function (
|
|
1271
|
-
switch (
|
|
1335
|
+
return __generator(this, function (_c) {
|
|
1336
|
+
switch (_c.label) {
|
|
1272
1337
|
case 0:
|
|
1273
1338
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1274
1339
|
throw Error("stakeEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1275
1340
|
}
|
|
1276
1341
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
1277
1342
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1278
|
-
case 1: return [2 /*return*/, (
|
|
1343
|
+
case 1: return [2 /*return*/, (_c.sent()).toNumber()];
|
|
1279
1344
|
}
|
|
1280
1345
|
});
|
|
1281
1346
|
});
|
|
@@ -1283,8 +1348,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1283
1348
|
PoolTemplate.prototype.stake = function (lpTokenAmount) {
|
|
1284
1349
|
return __awaiter(this, void 0, void 0, function () {
|
|
1285
1350
|
var _lpTokenAmount, gasLimit;
|
|
1286
|
-
return __generator(this, function (
|
|
1287
|
-
switch (
|
|
1351
|
+
return __generator(this, function (_c) {
|
|
1352
|
+
switch (_c.label) {
|
|
1288
1353
|
case 0:
|
|
1289
1354
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1290
1355
|
throw Error("stake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1292,12 +1357,12 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1292
1357
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
1293
1358
|
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.gauge)];
|
|
1294
1359
|
case 1:
|
|
1295
|
-
|
|
1360
|
+
_c.sent();
|
|
1296
1361
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1297
1362
|
case 2:
|
|
1298
|
-
gasLimit = (
|
|
1363
|
+
gasLimit = (_c.sent()).mul(150).div(100);
|
|
1299
1364
|
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*/, (
|
|
1365
|
+
case 3: return [2 /*return*/, (_c.sent()).hash];
|
|
1301
1366
|
}
|
|
1302
1367
|
});
|
|
1303
1368
|
});
|
|
@@ -1305,15 +1370,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1305
1370
|
PoolTemplate.prototype.unstakeEstimateGas = function (lpTokenAmount) {
|
|
1306
1371
|
return __awaiter(this, void 0, void 0, function () {
|
|
1307
1372
|
var _lpTokenAmount;
|
|
1308
|
-
return __generator(this, function (
|
|
1309
|
-
switch (
|
|
1373
|
+
return __generator(this, function (_c) {
|
|
1374
|
+
switch (_c.label) {
|
|
1310
1375
|
case 0:
|
|
1311
1376
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1312
1377
|
throw Error("unstakeEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1313
1378
|
}
|
|
1314
1379
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
1315
1380
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1316
|
-
case 1: return [2 /*return*/, (
|
|
1381
|
+
case 1: return [2 /*return*/, (_c.sent()).toNumber()];
|
|
1317
1382
|
}
|
|
1318
1383
|
});
|
|
1319
1384
|
});
|
|
@@ -1321,8 +1386,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1321
1386
|
PoolTemplate.prototype.unstake = function (lpTokenAmount) {
|
|
1322
1387
|
return __awaiter(this, void 0, void 0, function () {
|
|
1323
1388
|
var _lpTokenAmount, gasLimit;
|
|
1324
|
-
return __generator(this, function (
|
|
1325
|
-
switch (
|
|
1389
|
+
return __generator(this, function (_c) {
|
|
1390
|
+
switch (_c.label) {
|
|
1326
1391
|
case 0:
|
|
1327
1392
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1328
1393
|
throw Error("unstake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1330,9 +1395,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1330
1395
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
1331
1396
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1332
1397
|
case 1:
|
|
1333
|
-
gasLimit = (
|
|
1398
|
+
gasLimit = (_c.sent()).mul(200).div(100);
|
|
1334
1399
|
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*/, (
|
|
1400
|
+
case 2: return [2 /*return*/, (_c.sent()).hash];
|
|
1336
1401
|
}
|
|
1337
1402
|
});
|
|
1338
1403
|
});
|
|
@@ -1340,31 +1405,31 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1340
1405
|
PoolTemplate.prototype.claimableCrv = function (address) {
|
|
1341
1406
|
if (address === void 0) { address = ""; }
|
|
1342
1407
|
return __awaiter(this, void 0, void 0, function () {
|
|
1343
|
-
var
|
|
1344
|
-
return __generator(this, function (
|
|
1345
|
-
switch (
|
|
1408
|
+
var _c, _d;
|
|
1409
|
+
return __generator(this, function (_e) {
|
|
1410
|
+
switch (_e.label) {
|
|
1346
1411
|
case 0:
|
|
1347
1412
|
if (this.rewardsOnly())
|
|
1348
1413
|
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimableRewards instead"));
|
|
1349
1414
|
address = address || curve_1.curve.signerAddress;
|
|
1350
1415
|
if (!address)
|
|
1351
1416
|
throw Error("Need to connect wallet or pass address into args");
|
|
1352
|
-
|
|
1417
|
+
_d = (_c = ethers_1.ethers.utils).formatUnits;
|
|
1353
1418
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.claimable_tokens(address, curve_1.curve.constantOptions)];
|
|
1354
|
-
case 1: return [2 /*return*/,
|
|
1419
|
+
case 1: return [2 /*return*/, _d.apply(_c, [_e.sent()])];
|
|
1355
1420
|
}
|
|
1356
1421
|
});
|
|
1357
1422
|
});
|
|
1358
1423
|
};
|
|
1359
1424
|
PoolTemplate.prototype.claimCrvEstimateGas = function () {
|
|
1360
1425
|
return __awaiter(this, void 0, void 0, function () {
|
|
1361
|
-
return __generator(this, function (
|
|
1362
|
-
switch (
|
|
1426
|
+
return __generator(this, function (_c) {
|
|
1427
|
+
switch (_c.label) {
|
|
1363
1428
|
case 0:
|
|
1364
1429
|
if (this.rewardsOnly())
|
|
1365
1430
|
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimRewards instead"));
|
|
1366
1431
|
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*/, (
|
|
1432
|
+
case 1: return [2 /*return*/, (_c.sent()).toNumber()];
|
|
1368
1433
|
}
|
|
1369
1434
|
});
|
|
1370
1435
|
});
|
|
@@ -1372,17 +1437,17 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1372
1437
|
PoolTemplate.prototype.claimCrv = function () {
|
|
1373
1438
|
return __awaiter(this, void 0, void 0, function () {
|
|
1374
1439
|
var contract, gasLimit;
|
|
1375
|
-
return __generator(this, function (
|
|
1376
|
-
switch (
|
|
1440
|
+
return __generator(this, function (_c) {
|
|
1441
|
+
switch (_c.label) {
|
|
1377
1442
|
case 0:
|
|
1378
1443
|
if (this.rewardsOnly())
|
|
1379
1444
|
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimRewards instead"));
|
|
1380
1445
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract;
|
|
1381
1446
|
return [4 /*yield*/, contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
|
|
1382
1447
|
case 1:
|
|
1383
|
-
gasLimit = (
|
|
1448
|
+
gasLimit = (_c.sent()).mul(130).div(100);
|
|
1384
1449
|
return [4 /*yield*/, contract.mint(this.gauge, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1385
|
-
case 2: return [2 /*return*/, (
|
|
1450
|
+
case 2: return [2 /*return*/, (_c.sent()).hash];
|
|
1386
1451
|
}
|
|
1387
1452
|
});
|
|
1388
1453
|
});
|
|
@@ -1392,8 +1457,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1392
1457
|
if (address === void 0) { address = ""; }
|
|
1393
1458
|
return __awaiter(this, void 0, void 0, function () {
|
|
1394
1459
|
var gaugeContract, rewardTokens, rewards, _i, rewardTokens_5, rewardToken, _amount, rewardToken, _totalAmount, _claimedAmount;
|
|
1395
|
-
return __generator(this, function (
|
|
1396
|
-
switch (
|
|
1460
|
+
return __generator(this, function (_c) {
|
|
1461
|
+
switch (_c.label) {
|
|
1397
1462
|
case 0:
|
|
1398
1463
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1399
1464
|
throw Error("claimableRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1404,23 +1469,23 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1404
1469
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1405
1470
|
return [4 /*yield*/, this.rewardTokens()];
|
|
1406
1471
|
case 1:
|
|
1407
|
-
rewardTokens =
|
|
1472
|
+
rewardTokens = _c.sent();
|
|
1408
1473
|
rewards = [];
|
|
1409
1474
|
if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 6];
|
|
1410
1475
|
_i = 0, rewardTokens_5 = rewardTokens;
|
|
1411
|
-
|
|
1476
|
+
_c.label = 2;
|
|
1412
1477
|
case 2:
|
|
1413
1478
|
if (!(_i < rewardTokens_5.length)) return [3 /*break*/, 5];
|
|
1414
1479
|
rewardToken = rewardTokens_5[_i];
|
|
1415
1480
|
return [4 /*yield*/, gaugeContract.claimable_reward(address, rewardToken.token, curve_1.curve.constantOptions)];
|
|
1416
1481
|
case 3:
|
|
1417
|
-
_amount =
|
|
1482
|
+
_amount = _c.sent();
|
|
1418
1483
|
rewards.push({
|
|
1419
1484
|
token: rewardToken.token,
|
|
1420
1485
|
symbol: rewardToken.symbol,
|
|
1421
1486
|
amount: ethers_1.ethers.utils.formatUnits(_amount, rewardToken.decimals),
|
|
1422
1487
|
});
|
|
1423
|
-
|
|
1488
|
+
_c.label = 4;
|
|
1424
1489
|
case 4:
|
|
1425
1490
|
_i++;
|
|
1426
1491
|
return [3 /*break*/, 2];
|
|
@@ -1430,16 +1495,16 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1430
1495
|
rewardToken = rewardTokens[0];
|
|
1431
1496
|
return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
|
|
1432
1497
|
case 7:
|
|
1433
|
-
_totalAmount =
|
|
1498
|
+
_totalAmount = _c.sent();
|
|
1434
1499
|
return [4 /*yield*/, gaugeContract.claimed_rewards_for(address, curve_1.curve.constantOptions)];
|
|
1435
1500
|
case 8:
|
|
1436
|
-
_claimedAmount =
|
|
1501
|
+
_claimedAmount = _c.sent();
|
|
1437
1502
|
rewards.push({
|
|
1438
1503
|
token: rewardToken.token,
|
|
1439
1504
|
symbol: rewardToken.symbol,
|
|
1440
1505
|
amount: ethers_1.ethers.utils.formatUnits(_totalAmount.sub(_claimedAmount), rewardToken.decimals),
|
|
1441
1506
|
});
|
|
1442
|
-
|
|
1507
|
+
_c.label = 9;
|
|
1443
1508
|
case 9: return [2 /*return*/, rewards];
|
|
1444
1509
|
}
|
|
1445
1510
|
});
|
|
@@ -1448,8 +1513,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1448
1513
|
PoolTemplate.prototype.claimRewardsEstimateGas = function () {
|
|
1449
1514
|
return __awaiter(this, void 0, void 0, function () {
|
|
1450
1515
|
var gaugeContract;
|
|
1451
|
-
return __generator(this, function (
|
|
1452
|
-
switch (
|
|
1516
|
+
return __generator(this, function (_c) {
|
|
1517
|
+
switch (_c.label) {
|
|
1453
1518
|
case 0:
|
|
1454
1519
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1455
1520
|
throw Error("claimRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1458,7 +1523,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1458
1523
|
if (!("claim_rewards()" in gaugeContract))
|
|
1459
1524
|
throw Error("".concat(this.name, " pool doesn't have such method"));
|
|
1460
1525
|
return [4 /*yield*/, gaugeContract.estimateGas.claim_rewards(curve_1.curve.constantOptions)];
|
|
1461
|
-
case 1: return [2 /*return*/, (
|
|
1526
|
+
case 1: return [2 /*return*/, (_c.sent()).toNumber()];
|
|
1462
1527
|
}
|
|
1463
1528
|
});
|
|
1464
1529
|
});
|
|
@@ -1466,8 +1531,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1466
1531
|
PoolTemplate.prototype.claimRewards = function () {
|
|
1467
1532
|
return __awaiter(this, void 0, void 0, function () {
|
|
1468
1533
|
var gaugeContract, gasLimit;
|
|
1469
|
-
return __generator(this, function (
|
|
1470
|
-
switch (
|
|
1534
|
+
return __generator(this, function (_c) {
|
|
1535
|
+
switch (_c.label) {
|
|
1471
1536
|
case 0:
|
|
1472
1537
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1473
1538
|
throw Error("claimRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1477,9 +1542,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1477
1542
|
throw Error("".concat(this.name, " pool doesn't have such method"));
|
|
1478
1543
|
return [4 /*yield*/, gaugeContract.estimateGas.claim_rewards(curve_1.curve.constantOptions)];
|
|
1479
1544
|
case 1:
|
|
1480
|
-
gasLimit = (
|
|
1545
|
+
gasLimit = (_c.sent()).mul(130).div(100);
|
|
1481
1546
|
return [4 /*yield*/, gaugeContract.claim_rewards(__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1482
|
-
case 2: return [2 /*return*/, (
|
|
1547
|
+
case 2: return [2 /*return*/, (_c.sent()).hash];
|
|
1483
1548
|
}
|
|
1484
1549
|
});
|
|
1485
1550
|
});
|
|
@@ -1487,28 +1552,28 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1487
1552
|
// ---------------- DEPOSIT & STAKE ----------------
|
|
1488
1553
|
PoolTemplate.prototype.depositAndStakeExpected = function (amounts) {
|
|
1489
1554
|
return __awaiter(this, void 0, void 0, function () {
|
|
1490
|
-
return __generator(this, function (
|
|
1491
|
-
switch (
|
|
1555
|
+
return __generator(this, function (_c) {
|
|
1556
|
+
switch (_c.label) {
|
|
1492
1557
|
case 0:
|
|
1493
1558
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1494
1559
|
throw Error("depositAndStakeExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1495
1560
|
}
|
|
1496
1561
|
return [4 /*yield*/, this.depositExpected(amounts)];
|
|
1497
|
-
case 1: return [2 /*return*/,
|
|
1562
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1498
1563
|
}
|
|
1499
1564
|
});
|
|
1500
1565
|
});
|
|
1501
1566
|
};
|
|
1502
1567
|
PoolTemplate.prototype.depositAndStakeBonus = function (amounts) {
|
|
1503
1568
|
return __awaiter(this, void 0, void 0, function () {
|
|
1504
|
-
return __generator(this, function (
|
|
1505
|
-
switch (
|
|
1569
|
+
return __generator(this, function (_c) {
|
|
1570
|
+
switch (_c.label) {
|
|
1506
1571
|
case 0:
|
|
1507
1572
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1508
1573
|
throw Error("depositAndStakeBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1509
1574
|
}
|
|
1510
1575
|
return [4 /*yield*/, this.depositBonus(amounts)];
|
|
1511
|
-
case 1: return [2 /*return*/,
|
|
1576
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1512
1577
|
}
|
|
1513
1578
|
});
|
|
1514
1579
|
});
|
|
@@ -1516,20 +1581,20 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1516
1581
|
PoolTemplate.prototype.depositAndStakeIsApproved = function (amounts) {
|
|
1517
1582
|
return __awaiter(this, void 0, void 0, function () {
|
|
1518
1583
|
var coinsAllowance, gaugeContract, gaugeAllowance;
|
|
1519
|
-
return __generator(this, function (
|
|
1520
|
-
switch (
|
|
1584
|
+
return __generator(this, function (_c) {
|
|
1585
|
+
switch (_c.label) {
|
|
1521
1586
|
case 0:
|
|
1522
1587
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1523
1588
|
throw Error("depositAndStakeIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1524
1589
|
}
|
|
1525
1590
|
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1526
1591
|
case 1:
|
|
1527
|
-
coinsAllowance =
|
|
1592
|
+
coinsAllowance = _c.sent();
|
|
1528
1593
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1529
1594
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
|
|
1530
1595
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1531
1596
|
case 2:
|
|
1532
|
-
gaugeAllowance =
|
|
1597
|
+
gaugeAllowance = _c.sent();
|
|
1533
1598
|
return [2 /*return*/, coinsAllowance && gaugeAllowance];
|
|
1534
1599
|
case 3: return [2 /*return*/, coinsAllowance];
|
|
1535
1600
|
}
|
|
@@ -1539,24 +1604,24 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1539
1604
|
PoolTemplate.prototype.depositAndStakeApproveEstimateGas = function (amounts) {
|
|
1540
1605
|
return __awaiter(this, void 0, void 0, function () {
|
|
1541
1606
|
var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
|
|
1542
|
-
return __generator(this, function (
|
|
1543
|
-
switch (
|
|
1607
|
+
return __generator(this, function (_c) {
|
|
1608
|
+
switch (_c.label) {
|
|
1544
1609
|
case 0:
|
|
1545
1610
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1546
1611
|
throw Error("depositAndStakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1547
1612
|
}
|
|
1548
1613
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1549
1614
|
case 1:
|
|
1550
|
-
approveCoinsGas =
|
|
1615
|
+
approveCoinsGas = _c.sent();
|
|
1551
1616
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1552
1617
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
|
|
1553
1618
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1554
1619
|
case 2:
|
|
1555
|
-
gaugeAllowance =
|
|
1620
|
+
gaugeAllowance = _c.sent();
|
|
1556
1621
|
if (!!gaugeAllowance) return [3 /*break*/, 4];
|
|
1557
1622
|
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
1558
1623
|
case 3:
|
|
1559
|
-
approveGaugeGas = (
|
|
1624
|
+
approveGaugeGas = (_c.sent()).toNumber();
|
|
1560
1625
|
return [2 /*return*/, approveCoinsGas + approveGaugeGas];
|
|
1561
1626
|
case 4: return [2 /*return*/, approveCoinsGas];
|
|
1562
1627
|
}
|
|
@@ -1566,27 +1631,27 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1566
1631
|
PoolTemplate.prototype.depositAndStakeApprove = function (amounts) {
|
|
1567
1632
|
return __awaiter(this, void 0, void 0, function () {
|
|
1568
1633
|
var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
|
|
1569
|
-
return __generator(this, function (
|
|
1570
|
-
switch (
|
|
1634
|
+
return __generator(this, function (_c) {
|
|
1635
|
+
switch (_c.label) {
|
|
1571
1636
|
case 0:
|
|
1572
1637
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1573
1638
|
throw Error("depositAndStakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1574
1639
|
}
|
|
1575
1640
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1576
1641
|
case 1:
|
|
1577
|
-
approveCoinsTx =
|
|
1642
|
+
approveCoinsTx = _c.sent();
|
|
1578
1643
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1579
1644
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
|
|
1580
1645
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1581
1646
|
case 2:
|
|
1582
|
-
gaugeAllowance =
|
|
1647
|
+
gaugeAllowance = _c.sent();
|
|
1583
1648
|
if (!!gaugeAllowance) return [3 /*break*/, 5];
|
|
1584
1649
|
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
1585
1650
|
case 3:
|
|
1586
|
-
gasLimit = (
|
|
1651
|
+
gasLimit = (_c.sent()).mul(130).div(100);
|
|
1587
1652
|
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
1653
|
case 4:
|
|
1589
|
-
approveGaugeTx = (
|
|
1654
|
+
approveGaugeTx = (_c.sent()).hash;
|
|
1590
1655
|
return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
|
|
1591
1656
|
case 5: return [2 /*return*/, approveCoinsTx];
|
|
1592
1657
|
}
|
|
@@ -1595,28 +1660,28 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1595
1660
|
};
|
|
1596
1661
|
PoolTemplate.prototype.depositAndStakeEstimateGas = function (amounts) {
|
|
1597
1662
|
return __awaiter(this, void 0, void 0, function () {
|
|
1598
|
-
return __generator(this, function (
|
|
1599
|
-
switch (
|
|
1663
|
+
return __generator(this, function (_c) {
|
|
1664
|
+
switch (_c.label) {
|
|
1600
1665
|
case 0:
|
|
1601
1666
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1602
1667
|
throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1603
1668
|
}
|
|
1604
1669
|
return [4 /*yield*/, this._depositAndStake(amounts, true, true)];
|
|
1605
|
-
case 1: return [2 /*return*/,
|
|
1670
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1606
1671
|
}
|
|
1607
1672
|
});
|
|
1608
1673
|
});
|
|
1609
1674
|
};
|
|
1610
1675
|
PoolTemplate.prototype.depositAndStake = function (amounts) {
|
|
1611
1676
|
return __awaiter(this, void 0, void 0, function () {
|
|
1612
|
-
return __generator(this, function (
|
|
1613
|
-
switch (
|
|
1677
|
+
return __generator(this, function (_c) {
|
|
1678
|
+
switch (_c.label) {
|
|
1614
1679
|
case 0:
|
|
1615
1680
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1616
1681
|
throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1617
1682
|
}
|
|
1618
1683
|
return [4 /*yield*/, this._depositAndStake(amounts, true, false)];
|
|
1619
|
-
case 1: return [2 /*return*/,
|
|
1684
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1620
1685
|
}
|
|
1621
1686
|
});
|
|
1622
1687
|
});
|
|
@@ -1624,8 +1689,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1624
1689
|
// ---------------- DEPOSIT & STAKE WRAPPED ----------------
|
|
1625
1690
|
PoolTemplate.prototype.depositAndStakeWrappedExpected = function (amounts) {
|
|
1626
1691
|
return __awaiter(this, void 0, void 0, function () {
|
|
1627
|
-
return __generator(this, function (
|
|
1628
|
-
switch (
|
|
1692
|
+
return __generator(this, function (_c) {
|
|
1693
|
+
switch (_c.label) {
|
|
1629
1694
|
case 0:
|
|
1630
1695
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1631
1696
|
throw Error("depositAndStakeWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1633,15 +1698,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1633
1698
|
if (this.isPlain || this.isFake)
|
|
1634
1699
|
throw Error("depositAndStakeWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1635
1700
|
return [4 /*yield*/, this.depositWrappedExpected(amounts)];
|
|
1636
|
-
case 1: return [2 /*return*/,
|
|
1701
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1637
1702
|
}
|
|
1638
1703
|
});
|
|
1639
1704
|
});
|
|
1640
1705
|
};
|
|
1641
1706
|
PoolTemplate.prototype.depositAndStakeWrappedBonus = function (amounts) {
|
|
1642
1707
|
return __awaiter(this, void 0, void 0, function () {
|
|
1643
|
-
return __generator(this, function (
|
|
1644
|
-
switch (
|
|
1708
|
+
return __generator(this, function (_c) {
|
|
1709
|
+
switch (_c.label) {
|
|
1645
1710
|
case 0:
|
|
1646
1711
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1647
1712
|
throw Error("depositAndStakeWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1649,7 +1714,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1649
1714
|
if (this.isPlain || this.isFake)
|
|
1650
1715
|
throw Error("depositAndStakeWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1651
1716
|
return [4 /*yield*/, this.depositWrappedBonus(amounts)];
|
|
1652
|
-
case 1: return [2 /*return*/,
|
|
1717
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1653
1718
|
}
|
|
1654
1719
|
});
|
|
1655
1720
|
});
|
|
@@ -1657,8 +1722,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1657
1722
|
PoolTemplate.prototype.depositAndStakeWrappedIsApproved = function (amounts) {
|
|
1658
1723
|
return __awaiter(this, void 0, void 0, function () {
|
|
1659
1724
|
var coinsAllowance, gaugeContract, gaugeAllowance;
|
|
1660
|
-
return __generator(this, function (
|
|
1661
|
-
switch (
|
|
1725
|
+
return __generator(this, function (_c) {
|
|
1726
|
+
switch (_c.label) {
|
|
1662
1727
|
case 0:
|
|
1663
1728
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1664
1729
|
throw Error("depositAndStakeWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1667,12 +1732,12 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1667
1732
|
throw Error("depositAndStakeWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1668
1733
|
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1669
1734
|
case 1:
|
|
1670
|
-
coinsAllowance =
|
|
1735
|
+
coinsAllowance = _c.sent();
|
|
1671
1736
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1672
1737
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
|
|
1673
1738
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1674
1739
|
case 2:
|
|
1675
|
-
gaugeAllowance =
|
|
1740
|
+
gaugeAllowance = _c.sent();
|
|
1676
1741
|
return [2 /*return*/, coinsAllowance && gaugeAllowance];
|
|
1677
1742
|
case 3: return [2 /*return*/, coinsAllowance];
|
|
1678
1743
|
}
|
|
@@ -1682,8 +1747,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1682
1747
|
PoolTemplate.prototype.depositAndStakeWrappedApproveEstimateGas = function (amounts) {
|
|
1683
1748
|
return __awaiter(this, void 0, void 0, function () {
|
|
1684
1749
|
var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
|
|
1685
|
-
return __generator(this, function (
|
|
1686
|
-
switch (
|
|
1750
|
+
return __generator(this, function (_c) {
|
|
1751
|
+
switch (_c.label) {
|
|
1687
1752
|
case 0:
|
|
1688
1753
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1689
1754
|
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1692,16 +1757,16 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1692
1757
|
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1693
1758
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.wrappedCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1694
1759
|
case 1:
|
|
1695
|
-
approveCoinsGas =
|
|
1760
|
+
approveCoinsGas = _c.sent();
|
|
1696
1761
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1697
1762
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
|
|
1698
1763
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1699
1764
|
case 2:
|
|
1700
|
-
gaugeAllowance =
|
|
1765
|
+
gaugeAllowance = _c.sent();
|
|
1701
1766
|
if (!!gaugeAllowance) return [3 /*break*/, 4];
|
|
1702
1767
|
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
1703
1768
|
case 3:
|
|
1704
|
-
approveGaugeGas = (
|
|
1769
|
+
approveGaugeGas = (_c.sent()).toNumber();
|
|
1705
1770
|
return [2 /*return*/, approveCoinsGas + approveGaugeGas];
|
|
1706
1771
|
case 4: return [2 /*return*/, approveCoinsGas];
|
|
1707
1772
|
}
|
|
@@ -1711,8 +1776,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1711
1776
|
PoolTemplate.prototype.depositAndStakeWrappedApprove = function (amounts) {
|
|
1712
1777
|
return __awaiter(this, void 0, void 0, function () {
|
|
1713
1778
|
var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
|
|
1714
|
-
return __generator(this, function (
|
|
1715
|
-
switch (
|
|
1779
|
+
return __generator(this, function (_c) {
|
|
1780
|
+
switch (_c.label) {
|
|
1716
1781
|
case 0:
|
|
1717
1782
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1718
1783
|
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1721,19 +1786,19 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1721
1786
|
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1722
1787
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
|
|
1723
1788
|
case 1:
|
|
1724
|
-
approveCoinsTx =
|
|
1789
|
+
approveCoinsTx = _c.sent();
|
|
1725
1790
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1726
1791
|
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
|
|
1727
1792
|
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
|
|
1728
1793
|
case 2:
|
|
1729
|
-
gaugeAllowance =
|
|
1794
|
+
gaugeAllowance = _c.sent();
|
|
1730
1795
|
if (!!gaugeAllowance) return [3 /*break*/, 5];
|
|
1731
1796
|
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
1732
1797
|
case 3:
|
|
1733
|
-
gasLimit = (
|
|
1798
|
+
gasLimit = (_c.sent()).mul(130).div(100);
|
|
1734
1799
|
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
1800
|
case 4:
|
|
1736
|
-
approveGaugeTx = (
|
|
1801
|
+
approveGaugeTx = (_c.sent()).hash;
|
|
1737
1802
|
return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
|
|
1738
1803
|
case 5: return [2 /*return*/, approveCoinsTx];
|
|
1739
1804
|
}
|
|
@@ -1742,8 +1807,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1742
1807
|
};
|
|
1743
1808
|
PoolTemplate.prototype.depositAndStakeWrappedEstimateGas = function (amounts) {
|
|
1744
1809
|
return __awaiter(this, void 0, void 0, function () {
|
|
1745
|
-
return __generator(this, function (
|
|
1746
|
-
switch (
|
|
1810
|
+
return __generator(this, function (_c) {
|
|
1811
|
+
switch (_c.label) {
|
|
1747
1812
|
case 0:
|
|
1748
1813
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1749
1814
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1751,15 +1816,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1751
1816
|
if (this.isPlain || this.isFake)
|
|
1752
1817
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1753
1818
|
return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
|
|
1754
|
-
case 1: return [2 /*return*/,
|
|
1819
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1755
1820
|
}
|
|
1756
1821
|
});
|
|
1757
1822
|
});
|
|
1758
1823
|
};
|
|
1759
1824
|
PoolTemplate.prototype.depositAndStakeWrapped = function (amounts) {
|
|
1760
1825
|
return __awaiter(this, void 0, void 0, function () {
|
|
1761
|
-
return __generator(this, function (
|
|
1762
|
-
switch (
|
|
1826
|
+
return __generator(this, function (_c) {
|
|
1827
|
+
switch (_c.label) {
|
|
1763
1828
|
case 0:
|
|
1764
1829
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1765
1830
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
@@ -1767,16 +1832,16 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1767
1832
|
if (this.isPlain || this.isFake)
|
|
1768
1833
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1769
1834
|
return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
|
|
1770
|
-
case 1: return [2 /*return*/,
|
|
1835
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1771
1836
|
}
|
|
1772
1837
|
});
|
|
1773
1838
|
});
|
|
1774
1839
|
};
|
|
1775
1840
|
PoolTemplate.prototype._depositAndStake = function (amounts, isUnderlying, estimateGas) {
|
|
1776
1841
|
return __awaiter(this, void 0, void 0, function () {
|
|
1777
|
-
var coinAddresses, coins, decimals, depositAddress, balances,
|
|
1778
|
-
return __generator(this, function (
|
|
1779
|
-
switch (
|
|
1842
|
+
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;
|
|
1843
|
+
return __generator(this, function (_p) {
|
|
1844
|
+
switch (_p.label) {
|
|
1780
1845
|
case 0:
|
|
1781
1846
|
coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.wrappedCoinAddresses, true);
|
|
1782
1847
|
coins = isUnderlying ? this.underlyingCoins : this.wrappedCoinAddresses;
|
|
@@ -1786,19 +1851,19 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1786
1851
|
throw Error("".concat(this.name, " pool has ").concat(coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
1787
1852
|
}
|
|
1788
1853
|
if (!isUnderlying) return [3 /*break*/, 2];
|
|
1789
|
-
|
|
1854
|
+
_e = (_d = Object).values;
|
|
1790
1855
|
return [4 /*yield*/, this.walletUnderlyingCoinBalances()];
|
|
1791
1856
|
case 1:
|
|
1792
|
-
|
|
1857
|
+
_c = _e.apply(_d, [_p.sent()]);
|
|
1793
1858
|
return [3 /*break*/, 4];
|
|
1794
1859
|
case 2:
|
|
1795
|
-
|
|
1860
|
+
_g = (_f = Object).values;
|
|
1796
1861
|
return [4 /*yield*/, this.walletWrappedCoinBalances()];
|
|
1797
1862
|
case 3:
|
|
1798
|
-
|
|
1799
|
-
|
|
1863
|
+
_c = _g.apply(_f, [_p.sent()]);
|
|
1864
|
+
_p.label = 4;
|
|
1800
1865
|
case 4:
|
|
1801
|
-
balances =
|
|
1866
|
+
balances = _c;
|
|
1802
1867
|
for (i = 0; i < balances.length; i++) {
|
|
1803
1868
|
if (Number(balances[i]) < Number(amounts[i])) {
|
|
1804
1869
|
throw Error("Not enough ".concat(coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
|
|
@@ -1807,14 +1872,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1807
1872
|
if (!isUnderlying) return [3 /*break*/, 6];
|
|
1808
1873
|
return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
|
|
1809
1874
|
case 5:
|
|
1810
|
-
|
|
1875
|
+
_h = _p.sent();
|
|
1811
1876
|
return [3 /*break*/, 8];
|
|
1812
1877
|
case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
|
|
1813
1878
|
case 7:
|
|
1814
|
-
|
|
1815
|
-
|
|
1879
|
+
_h = _p.sent();
|
|
1880
|
+
_p.label = 8;
|
|
1816
1881
|
case 8:
|
|
1817
|
-
allowance =
|
|
1882
|
+
allowance = _h;
|
|
1818
1883
|
if (estimateGas && !allowance) {
|
|
1819
1884
|
throw Error("Token allowance is needed to estimate gas");
|
|
1820
1885
|
}
|
|
@@ -1822,30 +1887,30 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1822
1887
|
if (!isUnderlying) return [3 /*break*/, 10];
|
|
1823
1888
|
return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
|
|
1824
1889
|
case 9:
|
|
1825
|
-
|
|
1890
|
+
_p.sent();
|
|
1826
1891
|
return [3 /*break*/, 12];
|
|
1827
1892
|
case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
|
|
1828
1893
|
case 11:
|
|
1829
|
-
|
|
1830
|
-
|
|
1894
|
+
_p.sent();
|
|
1895
|
+
_p.label = 12;
|
|
1831
1896
|
case 12:
|
|
1832
1897
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, decimals[i]); });
|
|
1833
1898
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.deposit_and_stake].contract;
|
|
1834
1899
|
useUnderlying = isUnderlying && (this.isLending || (this.isCrypto && !this.isPlain)) && !this.zap;
|
|
1835
1900
|
if (!isUnderlying) return [3 /*break*/, 14];
|
|
1836
|
-
|
|
1901
|
+
_l = (_k = ethers_1.ethers.utils).parseUnits;
|
|
1837
1902
|
return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
|
|
1838
1903
|
case 13:
|
|
1839
|
-
|
|
1904
|
+
_j = _l.apply(_k, [_p.sent()]).mul(99).div(100);
|
|
1840
1905
|
return [3 /*break*/, 16];
|
|
1841
1906
|
case 14:
|
|
1842
|
-
|
|
1907
|
+
_o = (_m = ethers_1.ethers.utils).parseUnits;
|
|
1843
1908
|
return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
|
|
1844
1909
|
case 15:
|
|
1845
|
-
|
|
1846
|
-
|
|
1910
|
+
_j = _o.apply(_m, [_p.sent()]).mul(99).div(100);
|
|
1911
|
+
_p.label = 16;
|
|
1847
1912
|
case 16:
|
|
1848
|
-
_minMintAmount =
|
|
1913
|
+
_minMintAmount = _j;
|
|
1849
1914
|
ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
|
|
1850
1915
|
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
1851
1916
|
for (i = 0; i < 5; i++) {
|
|
@@ -1854,15 +1919,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1854
1919
|
}
|
|
1855
1920
|
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
1921
|
case 17:
|
|
1857
|
-
_gas = (
|
|
1922
|
+
_gas = (_p.sent());
|
|
1858
1923
|
if (estimateGas)
|
|
1859
1924
|
return [2 /*return*/, _gas.toNumber()];
|
|
1860
1925
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1861
1926
|
case 18:
|
|
1862
|
-
|
|
1927
|
+
_p.sent();
|
|
1863
1928
|
gasLimit = _gas.mul(200).div(100);
|
|
1864
1929
|
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*/, (
|
|
1930
|
+
case 19: return [2 /*return*/, (_p.sent()).hash];
|
|
1866
1931
|
}
|
|
1867
1932
|
});
|
|
1868
1933
|
});
|
|
@@ -1871,46 +1936,46 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1871
1936
|
// OVERRIDE
|
|
1872
1937
|
PoolTemplate.prototype.withdrawExpected = function (lpTokenAmount) {
|
|
1873
1938
|
return __awaiter(this, void 0, void 0, function () {
|
|
1874
|
-
return __generator(this, function (
|
|
1939
|
+
return __generator(this, function (_c) {
|
|
1875
1940
|
throw Error("withdrawExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1876
1941
|
});
|
|
1877
1942
|
});
|
|
1878
1943
|
};
|
|
1879
1944
|
PoolTemplate.prototype.withdrawIsApproved = function (lpTokenAmount) {
|
|
1880
1945
|
return __awaiter(this, void 0, void 0, function () {
|
|
1881
|
-
return __generator(this, function (
|
|
1882
|
-
switch (
|
|
1946
|
+
return __generator(this, function (_c) {
|
|
1947
|
+
switch (_c.label) {
|
|
1883
1948
|
case 0:
|
|
1884
1949
|
if (!this.zap)
|
|
1885
1950
|
return [2 /*return*/, true];
|
|
1886
1951
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
1887
|
-
case 1: return [2 /*return*/,
|
|
1952
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1888
1953
|
}
|
|
1889
1954
|
});
|
|
1890
1955
|
});
|
|
1891
1956
|
};
|
|
1892
1957
|
PoolTemplate.prototype.withdrawApproveEstimateGas = function (lpTokenAmount) {
|
|
1893
1958
|
return __awaiter(this, void 0, void 0, function () {
|
|
1894
|
-
return __generator(this, function (
|
|
1895
|
-
switch (
|
|
1959
|
+
return __generator(this, function (_c) {
|
|
1960
|
+
switch (_c.label) {
|
|
1896
1961
|
case 0:
|
|
1897
1962
|
if (!this.zap)
|
|
1898
1963
|
return [2 /*return*/, 0];
|
|
1899
1964
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
1900
|
-
case 1: return [2 /*return*/,
|
|
1965
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1901
1966
|
}
|
|
1902
1967
|
});
|
|
1903
1968
|
});
|
|
1904
1969
|
};
|
|
1905
1970
|
PoolTemplate.prototype.withdrawApprove = function (lpTokenAmount) {
|
|
1906
1971
|
return __awaiter(this, void 0, void 0, function () {
|
|
1907
|
-
return __generator(this, function (
|
|
1908
|
-
switch (
|
|
1972
|
+
return __generator(this, function (_c) {
|
|
1973
|
+
switch (_c.label) {
|
|
1909
1974
|
case 0:
|
|
1910
1975
|
if (!this.zap)
|
|
1911
1976
|
return [2 /*return*/, []];
|
|
1912
1977
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
1913
|
-
case 1: return [2 /*return*/,
|
|
1978
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1914
1979
|
}
|
|
1915
1980
|
});
|
|
1916
1981
|
});
|
|
@@ -1918,7 +1983,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1918
1983
|
// OVERRIDE
|
|
1919
1984
|
PoolTemplate.prototype.withdrawEstimateGas = function (lpTokenAmount) {
|
|
1920
1985
|
return __awaiter(this, void 0, void 0, function () {
|
|
1921
|
-
return __generator(this, function (
|
|
1986
|
+
return __generator(this, function (_c) {
|
|
1922
1987
|
throw Error("withdraw method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1923
1988
|
});
|
|
1924
1989
|
});
|
|
@@ -1927,7 +1992,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1927
1992
|
PoolTemplate.prototype.withdraw = function (lpTokenAmount, slippage) {
|
|
1928
1993
|
if (slippage === void 0) { slippage = 0.5; }
|
|
1929
1994
|
return __awaiter(this, void 0, void 0, function () {
|
|
1930
|
-
return __generator(this, function (
|
|
1995
|
+
return __generator(this, function (_c) {
|
|
1931
1996
|
throw Error("withdraw method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1932
1997
|
});
|
|
1933
1998
|
});
|
|
@@ -1936,7 +2001,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1936
2001
|
// OVERRIDE
|
|
1937
2002
|
PoolTemplate.prototype.withdrawWrappedExpected = function (lpTokenAmount) {
|
|
1938
2003
|
return __awaiter(this, void 0, void 0, function () {
|
|
1939
|
-
return __generator(this, function (
|
|
2004
|
+
return __generator(this, function (_c) {
|
|
1940
2005
|
throw Error("withdrawWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1941
2006
|
});
|
|
1942
2007
|
});
|
|
@@ -1944,7 +2009,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1944
2009
|
// OVERRIDE
|
|
1945
2010
|
PoolTemplate.prototype.withdrawWrappedEstimateGas = function (lpTokenAmount) {
|
|
1946
2011
|
return __awaiter(this, void 0, void 0, function () {
|
|
1947
|
-
return __generator(this, function (
|
|
2012
|
+
return __generator(this, function (_c) {
|
|
1948
2013
|
throw Error("withdrawWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1949
2014
|
});
|
|
1950
2015
|
});
|
|
@@ -1953,7 +2018,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1953
2018
|
PoolTemplate.prototype.withdrawWrapped = function (lpTokenAmount, slippage) {
|
|
1954
2019
|
if (slippage === void 0) { slippage = 0.5; }
|
|
1955
2020
|
return __awaiter(this, void 0, void 0, function () {
|
|
1956
|
-
return __generator(this, function (
|
|
2021
|
+
return __generator(this, function (_c) {
|
|
1957
2022
|
throw Error("withdrawWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1958
2023
|
});
|
|
1959
2024
|
});
|
|
@@ -1961,13 +2026,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1961
2026
|
// ---------------- WITHDRAW IMBALANCE ----------------
|
|
1962
2027
|
PoolTemplate.prototype.withdrawImbalanceExpected = function (amounts) {
|
|
1963
2028
|
return __awaiter(this, void 0, void 0, function () {
|
|
1964
|
-
return __generator(this, function (
|
|
1965
|
-
switch (
|
|
2029
|
+
return __generator(this, function (_c) {
|
|
2030
|
+
switch (_c.label) {
|
|
1966
2031
|
case 0:
|
|
1967
2032
|
if (this.isCrypto)
|
|
1968
2033
|
throw Error("withdrawImbalanceExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1969
2034
|
return [4 /*yield*/, this.calcLpTokenAmount(amounts, false)];
|
|
1970
|
-
case 1: return [2 /*return*/,
|
|
2035
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1971
2036
|
}
|
|
1972
2037
|
});
|
|
1973
2038
|
});
|
|
@@ -1975,7 +2040,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1975
2040
|
// OVERRIDE
|
|
1976
2041
|
PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
|
|
1977
2042
|
return __awaiter(this, void 0, void 0, function () {
|
|
1978
|
-
return __generator(this, function (
|
|
2043
|
+
return __generator(this, function (_c) {
|
|
1979
2044
|
throw Error("withdrawImbalanceBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1980
2045
|
});
|
|
1981
2046
|
});
|
|
@@ -1984,8 +2049,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1984
2049
|
return __awaiter(this, void 0, void 0, function () {
|
|
1985
2050
|
var _amounts, _maxBurnAmount;
|
|
1986
2051
|
var _this = this;
|
|
1987
|
-
return __generator(this, function (
|
|
1988
|
-
switch (
|
|
2052
|
+
return __generator(this, function (_c) {
|
|
2053
|
+
switch (_c.label) {
|
|
1989
2054
|
case 0:
|
|
1990
2055
|
if (this.isCrypto)
|
|
1991
2056
|
throw Error("withdrawImbalanceIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
@@ -1993,9 +2058,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1993
2058
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
|
|
1994
2059
|
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
|
|
1995
2060
|
case 1:
|
|
1996
|
-
_maxBurnAmount = (
|
|
2061
|
+
_maxBurnAmount = (_c.sent()).mul(101).div(100);
|
|
1997
2062
|
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*/,
|
|
2063
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
1999
2064
|
case 3: return [2 /*return*/, true];
|
|
2000
2065
|
}
|
|
2001
2066
|
});
|
|
@@ -2005,8 +2070,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2005
2070
|
return __awaiter(this, void 0, void 0, function () {
|
|
2006
2071
|
var _amounts, _maxBurnAmount;
|
|
2007
2072
|
var _this = this;
|
|
2008
|
-
return __generator(this, function (
|
|
2009
|
-
switch (
|
|
2073
|
+
return __generator(this, function (_c) {
|
|
2074
|
+
switch (_c.label) {
|
|
2010
2075
|
case 0:
|
|
2011
2076
|
if (this.isCrypto)
|
|
2012
2077
|
throw Error("withdrawImbalanceApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
@@ -2014,9 +2079,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2014
2079
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
|
|
2015
2080
|
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
|
|
2016
2081
|
case 1:
|
|
2017
|
-
_maxBurnAmount = (
|
|
2082
|
+
_maxBurnAmount = (_c.sent()).mul(101).div(100);
|
|
2018
2083
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], this.zap)];
|
|
2019
|
-
case 2: return [2 /*return*/,
|
|
2084
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2020
2085
|
case 3: return [2 /*return*/, 0];
|
|
2021
2086
|
}
|
|
2022
2087
|
});
|
|
@@ -2026,8 +2091,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2026
2091
|
return __awaiter(this, void 0, void 0, function () {
|
|
2027
2092
|
var _amounts, _maxBurnAmount;
|
|
2028
2093
|
var _this = this;
|
|
2029
|
-
return __generator(this, function (
|
|
2030
|
-
switch (
|
|
2094
|
+
return __generator(this, function (_c) {
|
|
2095
|
+
switch (_c.label) {
|
|
2031
2096
|
case 0:
|
|
2032
2097
|
if (this.isCrypto)
|
|
2033
2098
|
throw Error("withdrawImbalanceApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
@@ -2035,9 +2100,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2035
2100
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
|
|
2036
2101
|
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
|
|
2037
2102
|
case 1:
|
|
2038
|
-
_maxBurnAmount = (
|
|
2103
|
+
_maxBurnAmount = (_c.sent()).mul(101).div(100);
|
|
2039
2104
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], this.zap)];
|
|
2040
|
-
case 2: return [2 /*return*/,
|
|
2105
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2041
2106
|
case 3: return [2 /*return*/, []];
|
|
2042
2107
|
}
|
|
2043
2108
|
});
|
|
@@ -2046,7 +2111,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2046
2111
|
// OVERRIDE
|
|
2047
2112
|
PoolTemplate.prototype.withdrawImbalanceEstimateGas = function (amounts) {
|
|
2048
2113
|
return __awaiter(this, void 0, void 0, function () {
|
|
2049
|
-
return __generator(this, function (
|
|
2114
|
+
return __generator(this, function (_c) {
|
|
2050
2115
|
throw Error("withdrawImbalance method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2051
2116
|
});
|
|
2052
2117
|
});
|
|
@@ -2055,7 +2120,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2055
2120
|
PoolTemplate.prototype.withdrawImbalance = function (amounts, slippage) {
|
|
2056
2121
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2057
2122
|
return __awaiter(this, void 0, void 0, function () {
|
|
2058
|
-
return __generator(this, function (
|
|
2123
|
+
return __generator(this, function (_c) {
|
|
2059
2124
|
throw Error("withdrawImbalance method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2060
2125
|
});
|
|
2061
2126
|
});
|
|
@@ -2063,13 +2128,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2063
2128
|
// ---------------- WITHDRAW IMBALANCE WRAPPED ----------------
|
|
2064
2129
|
PoolTemplate.prototype.withdrawImbalanceWrappedExpected = function (amounts) {
|
|
2065
2130
|
return __awaiter(this, void 0, void 0, function () {
|
|
2066
|
-
return __generator(this, function (
|
|
2067
|
-
switch (
|
|
2131
|
+
return __generator(this, function (_c) {
|
|
2132
|
+
switch (_c.label) {
|
|
2068
2133
|
case 0:
|
|
2069
2134
|
if (this.isCrypto)
|
|
2070
2135
|
throw Error("withdrawImbalanceWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2071
2136
|
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts, false)];
|
|
2072
|
-
case 1: return [2 /*return*/,
|
|
2137
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2073
2138
|
}
|
|
2074
2139
|
});
|
|
2075
2140
|
});
|
|
@@ -2077,7 +2142,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2077
2142
|
// OVERRIDE
|
|
2078
2143
|
PoolTemplate.prototype.withdrawImbalanceWrappedBonus = function (amounts) {
|
|
2079
2144
|
return __awaiter(this, void 0, void 0, function () {
|
|
2080
|
-
return __generator(this, function (
|
|
2145
|
+
return __generator(this, function (_c) {
|
|
2081
2146
|
throw Error("withdrawImbalanceWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2082
2147
|
});
|
|
2083
2148
|
});
|
|
@@ -2085,7 +2150,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2085
2150
|
// OVERRIDE
|
|
2086
2151
|
PoolTemplate.prototype.withdrawImbalanceWrappedEstimateGas = function (amounts) {
|
|
2087
2152
|
return __awaiter(this, void 0, void 0, function () {
|
|
2088
|
-
return __generator(this, function (
|
|
2153
|
+
return __generator(this, function (_c) {
|
|
2089
2154
|
throw Error("withdrawImbalanceWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2090
2155
|
});
|
|
2091
2156
|
});
|
|
@@ -2094,7 +2159,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2094
2159
|
PoolTemplate.prototype.withdrawImbalanceWrapped = function (amounts, slippage) {
|
|
2095
2160
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2096
2161
|
return __awaiter(this, void 0, void 0, function () {
|
|
2097
|
-
return __generator(this, function (
|
|
2162
|
+
return __generator(this, function (_c) {
|
|
2098
2163
|
throw Error("withdrawImbalanceWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2099
2164
|
});
|
|
2100
2165
|
});
|
|
@@ -2103,7 +2168,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2103
2168
|
// OVERRIDE
|
|
2104
2169
|
PoolTemplate.prototype._withdrawOneCoinExpected = function (_lpTokenAmount, i) {
|
|
2105
2170
|
return __awaiter(this, void 0, void 0, function () {
|
|
2106
|
-
return __generator(this, function (
|
|
2171
|
+
return __generator(this, function (_c) {
|
|
2107
2172
|
throw Error("withdrawOneCoinExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2108
2173
|
});
|
|
2109
2174
|
});
|
|
@@ -2111,14 +2176,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2111
2176
|
PoolTemplate.prototype.withdrawOneCoinExpected = function (lpTokenAmount, coin) {
|
|
2112
2177
|
return __awaiter(this, void 0, void 0, function () {
|
|
2113
2178
|
var i, _lpTokenAmount, _expected;
|
|
2114
|
-
return __generator(this, function (
|
|
2115
|
-
switch (
|
|
2179
|
+
return __generator(this, function (_c) {
|
|
2180
|
+
switch (_c.label) {
|
|
2116
2181
|
case 0:
|
|
2117
2182
|
i = this._getCoinIdx(coin);
|
|
2118
2183
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
2119
2184
|
return [4 /*yield*/, this._withdrawOneCoinExpected(_lpTokenAmount, i)];
|
|
2120
2185
|
case 1:
|
|
2121
|
-
_expected =
|
|
2186
|
+
_expected = _c.sent();
|
|
2122
2187
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.underlyingDecimals[i])];
|
|
2123
2188
|
}
|
|
2124
2189
|
});
|
|
@@ -2127,46 +2192,46 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2127
2192
|
// OVERRIDE
|
|
2128
2193
|
PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
|
|
2129
2194
|
return __awaiter(this, void 0, void 0, function () {
|
|
2130
|
-
return __generator(this, function (
|
|
2195
|
+
return __generator(this, function (_c) {
|
|
2131
2196
|
throw Error("withdrawOneCoinBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2132
2197
|
});
|
|
2133
2198
|
});
|
|
2134
2199
|
};
|
|
2135
2200
|
PoolTemplate.prototype.withdrawOneCoinIsApproved = function (lpTokenAmount) {
|
|
2136
2201
|
return __awaiter(this, void 0, void 0, function () {
|
|
2137
|
-
return __generator(this, function (
|
|
2138
|
-
switch (
|
|
2202
|
+
return __generator(this, function (_c) {
|
|
2203
|
+
switch (_c.label) {
|
|
2139
2204
|
case 0:
|
|
2140
2205
|
if (!this.zap)
|
|
2141
2206
|
return [2 /*return*/, true];
|
|
2142
2207
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
2143
|
-
case 1: return [2 /*return*/,
|
|
2208
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2144
2209
|
}
|
|
2145
2210
|
});
|
|
2146
2211
|
});
|
|
2147
2212
|
};
|
|
2148
2213
|
PoolTemplate.prototype.withdrawOneCoinApproveEstimateGas = function (lpTokenAmount) {
|
|
2149
2214
|
return __awaiter(this, void 0, void 0, function () {
|
|
2150
|
-
return __generator(this, function (
|
|
2151
|
-
switch (
|
|
2215
|
+
return __generator(this, function (_c) {
|
|
2216
|
+
switch (_c.label) {
|
|
2152
2217
|
case 0:
|
|
2153
2218
|
if (!this.zap)
|
|
2154
2219
|
return [2 /*return*/, 0];
|
|
2155
2220
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
2156
|
-
case 1: return [2 /*return*/,
|
|
2221
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2157
2222
|
}
|
|
2158
2223
|
});
|
|
2159
2224
|
});
|
|
2160
2225
|
};
|
|
2161
2226
|
PoolTemplate.prototype.withdrawOneCoinApprove = function (lpTokenAmount) {
|
|
2162
2227
|
return __awaiter(this, void 0, void 0, function () {
|
|
2163
|
-
return __generator(this, function (
|
|
2164
|
-
switch (
|
|
2228
|
+
return __generator(this, function (_c) {
|
|
2229
|
+
switch (_c.label) {
|
|
2165
2230
|
case 0:
|
|
2166
2231
|
if (!this.zap)
|
|
2167
2232
|
return [2 /*return*/, []];
|
|
2168
2233
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
2169
|
-
case 1: return [2 /*return*/,
|
|
2234
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2170
2235
|
}
|
|
2171
2236
|
});
|
|
2172
2237
|
});
|
|
@@ -2174,7 +2239,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2174
2239
|
// OVERRIDE
|
|
2175
2240
|
PoolTemplate.prototype.withdrawOneCoinEstimateGas = function (lpTokenAmount, coin) {
|
|
2176
2241
|
return __awaiter(this, void 0, void 0, function () {
|
|
2177
|
-
return __generator(this, function (
|
|
2242
|
+
return __generator(this, function (_c) {
|
|
2178
2243
|
throw Error("withdrawOneCoin method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2179
2244
|
});
|
|
2180
2245
|
});
|
|
@@ -2183,7 +2248,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2183
2248
|
PoolTemplate.prototype.withdrawOneCoin = function (lpTokenAmount, coin, slippage) {
|
|
2184
2249
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2185
2250
|
return __awaiter(this, void 0, void 0, function () {
|
|
2186
|
-
return __generator(this, function (
|
|
2251
|
+
return __generator(this, function (_c) {
|
|
2187
2252
|
throw Error("withdrawOneCoin method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2188
2253
|
});
|
|
2189
2254
|
});
|
|
@@ -2192,7 +2257,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2192
2257
|
// OVERRIDE
|
|
2193
2258
|
PoolTemplate.prototype._withdrawOneCoinWrappedExpected = function (_lpTokenAmount, i) {
|
|
2194
2259
|
return __awaiter(this, void 0, void 0, function () {
|
|
2195
|
-
return __generator(this, function (
|
|
2260
|
+
return __generator(this, function (_c) {
|
|
2196
2261
|
throw Error("withdrawOneCoinWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2197
2262
|
});
|
|
2198
2263
|
});
|
|
@@ -2200,14 +2265,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2200
2265
|
PoolTemplate.prototype.withdrawOneCoinWrappedExpected = function (lpTokenAmount, coin) {
|
|
2201
2266
|
return __awaiter(this, void 0, void 0, function () {
|
|
2202
2267
|
var i, _lpTokenAmount, _expected;
|
|
2203
|
-
return __generator(this, function (
|
|
2204
|
-
switch (
|
|
2268
|
+
return __generator(this, function (_c) {
|
|
2269
|
+
switch (_c.label) {
|
|
2205
2270
|
case 0:
|
|
2206
2271
|
i = this._getCoinIdx(coin, false);
|
|
2207
2272
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
2208
2273
|
return [4 /*yield*/, this._withdrawOneCoinWrappedExpected(_lpTokenAmount, i)];
|
|
2209
2274
|
case 1:
|
|
2210
|
-
_expected =
|
|
2275
|
+
_expected = _c.sent();
|
|
2211
2276
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.wrappedDecimals[i])];
|
|
2212
2277
|
}
|
|
2213
2278
|
});
|
|
@@ -2216,7 +2281,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2216
2281
|
// OVERRIDE
|
|
2217
2282
|
PoolTemplate.prototype.withdrawOneCoinWrappedBonus = function (lpTokenAmount, coin) {
|
|
2218
2283
|
return __awaiter(this, void 0, void 0, function () {
|
|
2219
|
-
return __generator(this, function (
|
|
2284
|
+
return __generator(this, function (_c) {
|
|
2220
2285
|
throw Error("withdrawOneCoinWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2221
2286
|
});
|
|
2222
2287
|
});
|
|
@@ -2224,7 +2289,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2224
2289
|
// OVERRIDE
|
|
2225
2290
|
PoolTemplate.prototype.withdrawOneCoinWrappedEstimateGas = function (lpTokenAmount, coin) {
|
|
2226
2291
|
return __awaiter(this, void 0, void 0, function () {
|
|
2227
|
-
return __generator(this, function (
|
|
2292
|
+
return __generator(this, function (_c) {
|
|
2228
2293
|
throw Error("withdrawOneCoinWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2229
2294
|
});
|
|
2230
2295
|
});
|
|
@@ -2233,7 +2298,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2233
2298
|
PoolTemplate.prototype.withdrawOneCoinWrapped = function (lpTokenAmount, coin, slippage) {
|
|
2234
2299
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2235
2300
|
return __awaiter(this, void 0, void 0, function () {
|
|
2236
|
-
return __generator(this, function (
|
|
2301
|
+
return __generator(this, function (_c) {
|
|
2237
2302
|
throw Error("withdrawOneCoinWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2238
2303
|
});
|
|
2239
2304
|
});
|
|
@@ -2245,14 +2310,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2245
2310
|
addresses[_i] = arguments[_i];
|
|
2246
2311
|
}
|
|
2247
2312
|
return __awaiter(this, void 0, void 0, function () {
|
|
2248
|
-
return __generator(this, function (
|
|
2249
|
-
switch (
|
|
2313
|
+
return __generator(this, function (_c) {
|
|
2314
|
+
switch (_c.label) {
|
|
2250
2315
|
case 0:
|
|
2251
2316
|
if (!(this.gauge === ethers_1.ethers.constants.AddressZero)) return [3 /*break*/, 2];
|
|
2252
2317
|
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*/,
|
|
2318
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2254
2319
|
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*/,
|
|
2320
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
2256
2321
|
}
|
|
2257
2322
|
});
|
|
2258
2323
|
});
|
|
@@ -2263,14 +2328,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2263
2328
|
addresses[_i] = arguments[_i];
|
|
2264
2329
|
}
|
|
2265
2330
|
return __awaiter(this, void 0, void 0, function () {
|
|
2266
|
-
return __generator(this, function (
|
|
2267
|
-
switch (
|
|
2331
|
+
return __generator(this, function (_c) {
|
|
2332
|
+
switch (_c.label) {
|
|
2268
2333
|
case 0:
|
|
2269
2334
|
if (!(this.gauge === ethers_1.ethers.constants.AddressZero)) return [3 /*break*/, 2];
|
|
2270
2335
|
return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken'], [this.lpToken]], addresses, false))];
|
|
2271
|
-
case 1: return [2 /*return*/,
|
|
2336
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2272
2337
|
case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
|
|
2273
|
-
case 3: return [2 /*return*/,
|
|
2338
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
2274
2339
|
}
|
|
2275
2340
|
});
|
|
2276
2341
|
});
|
|
@@ -2281,10 +2346,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2281
2346
|
addresses[_i] = arguments[_i];
|
|
2282
2347
|
}
|
|
2283
2348
|
return __awaiter(this, void 0, void 0, function () {
|
|
2284
|
-
return __generator(this, function (
|
|
2285
|
-
switch (
|
|
2349
|
+
return __generator(this, function (_c) {
|
|
2350
|
+
switch (_c.label) {
|
|
2286
2351
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.underlyingCoinAddresses, this.underlyingCoinAddresses], addresses, false))];
|
|
2287
|
-
case 1: return [2 /*return*/,
|
|
2352
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2288
2353
|
}
|
|
2289
2354
|
});
|
|
2290
2355
|
});
|
|
@@ -2295,10 +2360,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2295
2360
|
addresses[_i] = arguments[_i];
|
|
2296
2361
|
}
|
|
2297
2362
|
return __awaiter(this, void 0, void 0, function () {
|
|
2298
|
-
return __generator(this, function (
|
|
2299
|
-
switch (
|
|
2363
|
+
return __generator(this, function (_c) {
|
|
2364
|
+
switch (_c.label) {
|
|
2300
2365
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.wrappedCoinAddresses, this.wrappedCoinAddresses], addresses, false))];
|
|
2301
|
-
case 1: return [2 /*return*/,
|
|
2366
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2302
2367
|
}
|
|
2303
2368
|
});
|
|
2304
2369
|
});
|
|
@@ -2309,10 +2374,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2309
2374
|
addresses[_i] = arguments[_i];
|
|
2310
2375
|
}
|
|
2311
2376
|
return __awaiter(this, void 0, void 0, function () {
|
|
2312
|
-
return __generator(this, function (
|
|
2313
|
-
switch (
|
|
2377
|
+
return __generator(this, function (_c) {
|
|
2378
|
+
switch (_c.label) {
|
|
2314
2379
|
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*/,
|
|
2380
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2316
2381
|
}
|
|
2317
2382
|
});
|
|
2318
2383
|
});
|
|
@@ -2321,15 +2386,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2321
2386
|
PoolTemplate.prototype._userLpTotalBalance = function (address) {
|
|
2322
2387
|
return __awaiter(this, void 0, void 0, function () {
|
|
2323
2388
|
var lpBalances, lpTotalBalanceBN;
|
|
2324
|
-
return __generator(this, function (
|
|
2325
|
-
switch (
|
|
2389
|
+
return __generator(this, function (_c) {
|
|
2390
|
+
switch (_c.label) {
|
|
2326
2391
|
case 0: return [4 /*yield*/, this.walletLpTokenBalances(address)];
|
|
2327
2392
|
case 1:
|
|
2328
|
-
lpBalances =
|
|
2393
|
+
lpBalances = _c.sent();
|
|
2329
2394
|
lpTotalBalanceBN = (0, utils_1.BN)(lpBalances.lpToken);
|
|
2330
2395
|
if ('gauge' in lpBalances)
|
|
2331
2396
|
lpTotalBalanceBN = lpTotalBalanceBN.plus((0, utils_1.BN)(lpBalances.gauge));
|
|
2332
|
-
return [2 /*return*/, lpTotalBalanceBN
|
|
2397
|
+
return [2 /*return*/, lpTotalBalanceBN];
|
|
2333
2398
|
}
|
|
2334
2399
|
});
|
|
2335
2400
|
});
|
|
@@ -2338,17 +2403,19 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2338
2403
|
if (address === void 0) { address = ""; }
|
|
2339
2404
|
return __awaiter(this, void 0, void 0, function () {
|
|
2340
2405
|
var lpTotalBalanceBN;
|
|
2341
|
-
return __generator(this, function (
|
|
2342
|
-
switch (
|
|
2406
|
+
return __generator(this, function (_c) {
|
|
2407
|
+
switch (_c.label) {
|
|
2343
2408
|
case 0:
|
|
2344
2409
|
address = address || curve_1.curve.signerAddress;
|
|
2345
2410
|
if (!address)
|
|
2346
2411
|
throw Error("Need to connect wallet or pass address into args");
|
|
2347
2412
|
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2348
2413
|
case 1:
|
|
2349
|
-
lpTotalBalanceBN =
|
|
2350
|
-
|
|
2351
|
-
|
|
2414
|
+
lpTotalBalanceBN = _c.sent();
|
|
2415
|
+
if (lpTotalBalanceBN.eq(0))
|
|
2416
|
+
return [2 /*return*/, this.underlyingCoins.map(function () { return "0"; })];
|
|
2417
|
+
return [4 /*yield*/, this.withdrawExpected(lpTotalBalanceBN.toFixed(18))];
|
|
2418
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2352
2419
|
}
|
|
2353
2420
|
});
|
|
2354
2421
|
});
|
|
@@ -2357,17 +2424,19 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2357
2424
|
if (address === void 0) { address = ""; }
|
|
2358
2425
|
return __awaiter(this, void 0, void 0, function () {
|
|
2359
2426
|
var lpTotalBalanceBN;
|
|
2360
|
-
return __generator(this, function (
|
|
2361
|
-
switch (
|
|
2427
|
+
return __generator(this, function (_c) {
|
|
2428
|
+
switch (_c.label) {
|
|
2362
2429
|
case 0:
|
|
2363
2430
|
address = address || curve_1.curve.signerAddress;
|
|
2364
2431
|
if (!address)
|
|
2365
2432
|
throw Error("Need to connect wallet or pass address into args");
|
|
2366
2433
|
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2367
2434
|
case 1:
|
|
2368
|
-
lpTotalBalanceBN =
|
|
2369
|
-
|
|
2370
|
-
|
|
2435
|
+
lpTotalBalanceBN = _c.sent();
|
|
2436
|
+
if (lpTotalBalanceBN.eq(0))
|
|
2437
|
+
return [2 /*return*/, this.underlyingCoins.map(function () { return "0"; })];
|
|
2438
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTotalBalanceBN.toFixed(18))];
|
|
2439
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2371
2440
|
}
|
|
2372
2441
|
});
|
|
2373
2442
|
});
|
|
@@ -2375,20 +2444,20 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2375
2444
|
PoolTemplate.prototype.userLiquidityUSD = function (address) {
|
|
2376
2445
|
if (address === void 0) { address = ""; }
|
|
2377
2446
|
return __awaiter(this, void 0, void 0, function () {
|
|
2378
|
-
var balances, promises, _i,
|
|
2379
|
-
return __generator(this, function (
|
|
2380
|
-
switch (
|
|
2447
|
+
var balances, promises, _i, _c, addr, prices, totalLiquidity;
|
|
2448
|
+
return __generator(this, function (_d) {
|
|
2449
|
+
switch (_d.label) {
|
|
2381
2450
|
case 0: return [4 /*yield*/, this.userBalances(address)];
|
|
2382
2451
|
case 1:
|
|
2383
|
-
balances =
|
|
2452
|
+
balances = _d.sent();
|
|
2384
2453
|
promises = [];
|
|
2385
|
-
for (_i = 0,
|
|
2386
|
-
addr =
|
|
2454
|
+
for (_i = 0, _c = this.underlyingCoinAddresses; _i < _c.length; _i++) {
|
|
2455
|
+
addr = _c[_i];
|
|
2387
2456
|
promises.push((0, utils_1._getUsdRate)(addr));
|
|
2388
2457
|
}
|
|
2389
2458
|
return [4 /*yield*/, Promise.all(promises)];
|
|
2390
2459
|
case 2:
|
|
2391
|
-
prices =
|
|
2460
|
+
prices = _d.sent();
|
|
2392
2461
|
totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
|
|
2393
2462
|
return [2 /*return*/, totalLiquidity.toFixed(8)];
|
|
2394
2463
|
}
|
|
@@ -2398,19 +2467,19 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2398
2467
|
PoolTemplate.prototype.baseProfit = function (address) {
|
|
2399
2468
|
if (address === void 0) { address = ""; }
|
|
2400
2469
|
return __awaiter(this, void 0, void 0, function () {
|
|
2401
|
-
var apyData, apyBN, totalLiquidityBN,
|
|
2402
|
-
return __generator(this, function (
|
|
2403
|
-
switch (
|
|
2470
|
+
var apyData, apyBN, totalLiquidityBN, _c, annualProfitBN, monthlyProfitBN, weeklyProfitBN, daylyProfitBN;
|
|
2471
|
+
return __generator(this, function (_d) {
|
|
2472
|
+
switch (_d.label) {
|
|
2404
2473
|
case 0: return [4 /*yield*/, this.statsBaseApy()];
|
|
2405
2474
|
case 1:
|
|
2406
|
-
apyData =
|
|
2475
|
+
apyData = _d.sent();
|
|
2407
2476
|
if (!('week' in apyData))
|
|
2408
2477
|
return [2 /*return*/, { day: "0", week: "0", month: "0", year: "0" }];
|
|
2409
2478
|
apyBN = (0, utils_1.BN)(apyData.week).div(100);
|
|
2410
|
-
|
|
2479
|
+
_c = utils_1.BN;
|
|
2411
2480
|
return [4 /*yield*/, this.userLiquidityUSD(address)];
|
|
2412
2481
|
case 2:
|
|
2413
|
-
totalLiquidityBN =
|
|
2482
|
+
totalLiquidityBN = _c.apply(void 0, [_d.sent()]);
|
|
2414
2483
|
annualProfitBN = apyBN.times(totalLiquidityBN);
|
|
2415
2484
|
monthlyProfitBN = annualProfitBN.div(12);
|
|
2416
2485
|
weeklyProfitBN = annualProfitBN.div(52);
|
|
@@ -2428,10 +2497,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2428
2497
|
PoolTemplate.prototype.userShare = function (address) {
|
|
2429
2498
|
if (address === void 0) { address = ""; }
|
|
2430
2499
|
return __awaiter(this, void 0, void 0, function () {
|
|
2431
|
-
var withGauge, userLpBalance, userLpTotalBalanceBN, totalLp, gaugeLp,
|
|
2432
|
-
var
|
|
2433
|
-
return __generator(this, function (
|
|
2434
|
-
switch (
|
|
2500
|
+
var withGauge, userLpBalance, userLpTotalBalanceBN, totalLp, gaugeLp, _c, _d;
|
|
2501
|
+
var _e;
|
|
2502
|
+
return __generator(this, function (_f) {
|
|
2503
|
+
switch (_f.label) {
|
|
2435
2504
|
case 0:
|
|
2436
2505
|
withGauge = this.gauge !== ethers_1.ethers.constants.AddressZero;
|
|
2437
2506
|
address = address || curve_1.curve.signerAddress;
|
|
@@ -2439,7 +2508,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2439
2508
|
throw Error("Need to connect wallet or pass address into args");
|
|
2440
2509
|
return [4 /*yield*/, this.walletLpTokenBalances(address)];
|
|
2441
2510
|
case 1:
|
|
2442
|
-
userLpBalance =
|
|
2511
|
+
userLpBalance = _f.sent();
|
|
2443
2512
|
userLpTotalBalanceBN = (0, utils_1.BN)(userLpBalance.lpToken);
|
|
2444
2513
|
if (withGauge)
|
|
2445
2514
|
userLpTotalBalanceBN = userLpTotalBalanceBN.plus((0, utils_1.BN)(userLpBalance.gauge));
|
|
@@ -2449,14 +2518,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2449
2518
|
curve_1.curve.contracts[this.gauge].multicallContract.totalSupply(),
|
|
2450
2519
|
])];
|
|
2451
2520
|
case 2:
|
|
2452
|
-
|
|
2521
|
+
_e = (_f.sent()).map(function (_supply) { return ethers_1.ethers.utils.formatUnits(_supply); }), totalLp = _e[0], gaugeLp = _e[1];
|
|
2453
2522
|
return [3 /*break*/, 5];
|
|
2454
2523
|
case 3:
|
|
2455
|
-
|
|
2524
|
+
_d = (_c = ethers_1.ethers.utils).formatUnits;
|
|
2456
2525
|
return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply()];
|
|
2457
2526
|
case 4:
|
|
2458
|
-
totalLp =
|
|
2459
|
-
|
|
2527
|
+
totalLp = _d.apply(_c, [_f.sent()]);
|
|
2528
|
+
_f.label = 5;
|
|
2460
2529
|
case 5: return [2 /*return*/, {
|
|
2461
2530
|
lpUser: userLpTotalBalanceBN.toString(),
|
|
2462
2531
|
lpTotal: totalLp,
|
|
@@ -2473,16 +2542,21 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2473
2542
|
PoolTemplate.prototype._swapExpected = function (i, j, _amount) {
|
|
2474
2543
|
return __awaiter(this, void 0, void 0, function () {
|
|
2475
2544
|
var contractAddress, contract;
|
|
2476
|
-
return __generator(this, function (
|
|
2477
|
-
switch (
|
|
2545
|
+
return __generator(this, function (_c) {
|
|
2546
|
+
switch (_c.label) {
|
|
2478
2547
|
case 0:
|
|
2479
2548
|
contractAddress = this.isCrypto && this.isMeta ? this.zap : this.address;
|
|
2480
2549
|
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
2481
2550
|
if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
|
|
2482
2551
|
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
|
|
2483
|
-
case 1: return [2 /*return*/,
|
|
2484
|
-
case 2:
|
|
2485
|
-
|
|
2552
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2553
|
+
case 2:
|
|
2554
|
+
if (!('get_dy(address,uint256,uint256,uint256)' in contract)) return [3 /*break*/, 4];
|
|
2555
|
+
return [4 /*yield*/, contract.get_dy(this.address, i, j, _amount, curve_1.curve.constantOptions)];
|
|
2556
|
+
case 3: // atricrypto3 based metapools
|
|
2557
|
+
return [2 /*return*/, _c.sent()];
|
|
2558
|
+
case 4: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
|
|
2559
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
2486
2560
|
}
|
|
2487
2561
|
});
|
|
2488
2562
|
});
|
|
@@ -2490,15 +2564,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2490
2564
|
PoolTemplate.prototype.swapExpected = function (inputCoin, outputCoin, amount) {
|
|
2491
2565
|
return __awaiter(this, void 0, void 0, function () {
|
|
2492
2566
|
var i, j, _amount, _expected;
|
|
2493
|
-
return __generator(this, function (
|
|
2494
|
-
switch (
|
|
2567
|
+
return __generator(this, function (_c) {
|
|
2568
|
+
switch (_c.label) {
|
|
2495
2569
|
case 0:
|
|
2496
2570
|
i = this._getCoinIdx(inputCoin);
|
|
2497
2571
|
j = this._getCoinIdx(outputCoin);
|
|
2498
2572
|
_amount = (0, utils_1.parseUnits)(amount, this.underlyingDecimals[i]);
|
|
2499
2573
|
return [4 /*yield*/, this._swapExpected(i, j, _amount)];
|
|
2500
2574
|
case 1:
|
|
2501
|
-
_expected =
|
|
2575
|
+
_expected = _c.sent();
|
|
2502
2576
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.underlyingDecimals[j])];
|
|
2503
2577
|
}
|
|
2504
2578
|
});
|
|
@@ -2506,17 +2580,17 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2506
2580
|
};
|
|
2507
2581
|
PoolTemplate.prototype.swapPriceImpact = function (inputCoin, outputCoin, amount) {
|
|
2508
2582
|
return __awaiter(this, void 0, void 0, function () {
|
|
2509
|
-
var i, j,
|
|
2510
|
-
return __generator(this, function (
|
|
2511
|
-
switch (
|
|
2583
|
+
var i, j, _c, inputCoinDecimals, outputCoinDecimals, _amount, _output, target, amountIntBN, outputIntBN, k, smallAmountIntBN, _smallAmount, _smallOutput, amountBN, outputBN, smallAmountBN, smallOutputBN, rateBN, smallRateBN, slippageBN;
|
|
2584
|
+
return __generator(this, function (_d) {
|
|
2585
|
+
switch (_d.label) {
|
|
2512
2586
|
case 0:
|
|
2513
2587
|
i = this._getCoinIdx(inputCoin);
|
|
2514
2588
|
j = this._getCoinIdx(outputCoin);
|
|
2515
|
-
|
|
2589
|
+
_c = [this.underlyingDecimals[i], this.underlyingDecimals[j]], inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2516
2590
|
_amount = (0, utils_1.parseUnits)(amount, inputCoinDecimals);
|
|
2517
2591
|
return [4 /*yield*/, this._swapExpected(i, j, _amount)];
|
|
2518
2592
|
case 1:
|
|
2519
|
-
_output =
|
|
2593
|
+
_output = _d.sent();
|
|
2520
2594
|
target = (0, utils_1.BN)(Math.pow(10, 15));
|
|
2521
2595
|
amountIntBN = (0, utils_1.BN)(amount).times(Math.pow(10, inputCoinDecimals));
|
|
2522
2596
|
outputIntBN = (0, utils_1.toBN)(_output, 0);
|
|
@@ -2527,7 +2601,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2527
2601
|
_smallAmount = (0, utils_1.fromBN)(smallAmountIntBN.div(Math.pow(10, inputCoinDecimals)), inputCoinDecimals);
|
|
2528
2602
|
return [4 /*yield*/, this._swapExpected(i, j, _smallAmount)];
|
|
2529
2603
|
case 2:
|
|
2530
|
-
_smallOutput =
|
|
2604
|
+
_smallOutput = _d.sent();
|
|
2531
2605
|
amountBN = (0, utils_1.BN)(amount);
|
|
2532
2606
|
outputBN = (0, utils_1.toBN)(_output, outputCoinDecimals);
|
|
2533
2607
|
smallAmountBN = (0, utils_1.toBN)(_smallAmount, inputCoinDecimals);
|
|
@@ -2546,13 +2620,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2546
2620
|
PoolTemplate.prototype.swapIsApproved = function (inputCoin, amount) {
|
|
2547
2621
|
return __awaiter(this, void 0, void 0, function () {
|
|
2548
2622
|
var contractAddress, i;
|
|
2549
|
-
return __generator(this, function (
|
|
2550
|
-
switch (
|
|
2623
|
+
return __generator(this, function (_c) {
|
|
2624
|
+
switch (_c.label) {
|
|
2551
2625
|
case 0:
|
|
2552
2626
|
contractAddress = this._swapContractAddress();
|
|
2553
2627
|
i = this._getCoinIdx(inputCoin);
|
|
2554
2628
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
|
|
2555
|
-
case 1: return [2 /*return*/,
|
|
2629
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2556
2630
|
}
|
|
2557
2631
|
});
|
|
2558
2632
|
});
|
|
@@ -2560,13 +2634,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2560
2634
|
PoolTemplate.prototype.swapApproveEstimateGas = function (inputCoin, amount) {
|
|
2561
2635
|
return __awaiter(this, void 0, void 0, function () {
|
|
2562
2636
|
var contractAddress, i;
|
|
2563
|
-
return __generator(this, function (
|
|
2564
|
-
switch (
|
|
2637
|
+
return __generator(this, function (_c) {
|
|
2638
|
+
switch (_c.label) {
|
|
2565
2639
|
case 0:
|
|
2566
2640
|
contractAddress = this._swapContractAddress();
|
|
2567
2641
|
i = this._getCoinIdx(inputCoin);
|
|
2568
2642
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
2569
|
-
case 1: return [2 /*return*/,
|
|
2643
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2570
2644
|
}
|
|
2571
2645
|
});
|
|
2572
2646
|
});
|
|
@@ -2574,13 +2648,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2574
2648
|
PoolTemplate.prototype.swapApprove = function (inputCoin, amount) {
|
|
2575
2649
|
return __awaiter(this, void 0, void 0, function () {
|
|
2576
2650
|
var contractAddress, i;
|
|
2577
|
-
return __generator(this, function (
|
|
2578
|
-
switch (
|
|
2651
|
+
return __generator(this, function (_c) {
|
|
2652
|
+
switch (_c.label) {
|
|
2579
2653
|
case 0:
|
|
2580
2654
|
contractAddress = this._swapContractAddress();
|
|
2581
2655
|
i = this._getCoinIdx(inputCoin);
|
|
2582
2656
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
2583
|
-
case 1: return [2 /*return*/,
|
|
2657
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2584
2658
|
}
|
|
2585
2659
|
});
|
|
2586
2660
|
});
|
|
@@ -2588,7 +2662,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2588
2662
|
// OVERRIDE
|
|
2589
2663
|
PoolTemplate.prototype.swapEstimateGas = function (inputCoin, outputCoin, amount) {
|
|
2590
2664
|
return __awaiter(this, void 0, void 0, function () {
|
|
2591
|
-
return __generator(this, function (
|
|
2665
|
+
return __generator(this, function (_c) {
|
|
2592
2666
|
throw Error("swap method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2593
2667
|
});
|
|
2594
2668
|
});
|
|
@@ -2597,7 +2671,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2597
2671
|
PoolTemplate.prototype.swap = function (inputCoin, outputCoin, amount, slippage) {
|
|
2598
2672
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2599
2673
|
return __awaiter(this, void 0, void 0, function () {
|
|
2600
|
-
return __generator(this, function (
|
|
2674
|
+
return __generator(this, function (_c) {
|
|
2601
2675
|
throw Error("swap method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2602
2676
|
});
|
|
2603
2677
|
});
|
|
@@ -2605,10 +2679,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2605
2679
|
// ---------------- SWAP WRAPPED ----------------
|
|
2606
2680
|
PoolTemplate.prototype._swapWrappedExpected = function (i, j, _amount) {
|
|
2607
2681
|
return __awaiter(this, void 0, void 0, function () {
|
|
2608
|
-
return __generator(this, function (
|
|
2609
|
-
switch (
|
|
2682
|
+
return __generator(this, function (_c) {
|
|
2683
|
+
switch (_c.label) {
|
|
2610
2684
|
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*/,
|
|
2685
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2612
2686
|
}
|
|
2613
2687
|
});
|
|
2614
2688
|
});
|
|
@@ -2616,27 +2690,27 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2616
2690
|
// OVERRIDE
|
|
2617
2691
|
PoolTemplate.prototype.swapWrappedExpected = function (inputCoin, outputCoin, amount) {
|
|
2618
2692
|
return __awaiter(this, void 0, void 0, function () {
|
|
2619
|
-
return __generator(this, function (
|
|
2693
|
+
return __generator(this, function (_c) {
|
|
2620
2694
|
throw Error("swapWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2621
2695
|
});
|
|
2622
2696
|
});
|
|
2623
2697
|
};
|
|
2624
2698
|
PoolTemplate.prototype.swapWrappedPriceImpact = function (inputCoin, outputCoin, amount) {
|
|
2625
2699
|
return __awaiter(this, void 0, void 0, function () {
|
|
2626
|
-
var i, j,
|
|
2627
|
-
return __generator(this, function (
|
|
2628
|
-
switch (
|
|
2700
|
+
var i, j, _c, inputCoinDecimals, outputCoinDecimals, _amount, _output, target, amountIntBN, outputIntBN, k, smallAmountIntBN, _smallAmount, _smallOutput, amountBN, outputBN, smallAmountBN, smallOutputBN, rateBN, smallRateBN, slippageBN;
|
|
2701
|
+
return __generator(this, function (_d) {
|
|
2702
|
+
switch (_d.label) {
|
|
2629
2703
|
case 0:
|
|
2630
2704
|
if (this.isPlain || this.isFake) {
|
|
2631
2705
|
throw Error("swapWrappedPriceImpact method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2632
2706
|
}
|
|
2633
2707
|
i = this._getCoinIdx(inputCoin, false);
|
|
2634
2708
|
j = this._getCoinIdx(outputCoin, false);
|
|
2635
|
-
|
|
2709
|
+
_c = [this.wrappedDecimals[i], this.wrappedDecimals[j]], inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2636
2710
|
_amount = (0, utils_1.parseUnits)(amount, inputCoinDecimals);
|
|
2637
2711
|
return [4 /*yield*/, this._swapWrappedExpected(i, j, _amount)];
|
|
2638
2712
|
case 1:
|
|
2639
|
-
_output =
|
|
2713
|
+
_output = _d.sent();
|
|
2640
2714
|
target = (0, utils_1.BN)(Math.pow(10, 15));
|
|
2641
2715
|
amountIntBN = (0, utils_1.BN)(amount).times(Math.pow(10, inputCoinDecimals));
|
|
2642
2716
|
outputIntBN = (0, utils_1.toBN)(_output, 0);
|
|
@@ -2647,7 +2721,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2647
2721
|
_smallAmount = (0, utils_1.fromBN)(smallAmountIntBN.div(Math.pow(10, inputCoinDecimals)), inputCoinDecimals);
|
|
2648
2722
|
return [4 /*yield*/, this._swapWrappedExpected(i, j, _smallAmount)];
|
|
2649
2723
|
case 2:
|
|
2650
|
-
_smallOutput =
|
|
2724
|
+
_smallOutput = _d.sent();
|
|
2651
2725
|
amountBN = (0, utils_1.BN)(amount);
|
|
2652
2726
|
outputBN = (0, utils_1.toBN)(_output, outputCoinDecimals);
|
|
2653
2727
|
smallAmountBN = (0, utils_1.toBN)(_smallAmount, inputCoinDecimals);
|
|
@@ -2663,7 +2737,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2663
2737
|
// OVERRIDE
|
|
2664
2738
|
PoolTemplate.prototype.swapWrappedIsApproved = function (inputCoin, amount) {
|
|
2665
2739
|
return __awaiter(this, void 0, void 0, function () {
|
|
2666
|
-
return __generator(this, function (
|
|
2740
|
+
return __generator(this, function (_c) {
|
|
2667
2741
|
throw Error("swapWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2668
2742
|
});
|
|
2669
2743
|
});
|
|
@@ -2671,7 +2745,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2671
2745
|
// OVERRIDE
|
|
2672
2746
|
PoolTemplate.prototype.swapWrappedApproveEstimateGas = function (inputCoin, amount) {
|
|
2673
2747
|
return __awaiter(this, void 0, void 0, function () {
|
|
2674
|
-
return __generator(this, function (
|
|
2748
|
+
return __generator(this, function (_c) {
|
|
2675
2749
|
throw Error("swapWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2676
2750
|
});
|
|
2677
2751
|
});
|
|
@@ -2679,7 +2753,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2679
2753
|
// OVERRIDE
|
|
2680
2754
|
PoolTemplate.prototype.swapWrappedApprove = function (inputCoin, amount) {
|
|
2681
2755
|
return __awaiter(this, void 0, void 0, function () {
|
|
2682
|
-
return __generator(this, function (
|
|
2756
|
+
return __generator(this, function (_c) {
|
|
2683
2757
|
throw Error("swapWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2684
2758
|
});
|
|
2685
2759
|
});
|
|
@@ -2687,7 +2761,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2687
2761
|
// OVERRIDE
|
|
2688
2762
|
PoolTemplate.prototype.swapWrappedEstimateGas = function (inputCoin, outputCoin, amount) {
|
|
2689
2763
|
return __awaiter(this, void 0, void 0, function () {
|
|
2690
|
-
return __generator(this, function (
|
|
2764
|
+
return __generator(this, function (_c) {
|
|
2691
2765
|
throw Error("swapWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2692
2766
|
});
|
|
2693
2767
|
});
|
|
@@ -2696,7 +2770,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2696
2770
|
PoolTemplate.prototype.swapWrapped = function (inputCoin, outputCoin, amount, slippage) {
|
|
2697
2771
|
if (slippage === void 0) { slippage = 0.5; }
|
|
2698
2772
|
return __awaiter(this, void 0, void 0, function () {
|
|
2699
|
-
return __generator(this, function (
|
|
2773
|
+
return __generator(this, function (_c) {
|
|
2700
2774
|
throw Error("swapWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2701
2775
|
});
|
|
2702
2776
|
});
|