@curvefi/api 1.4.0 → 1.5.1
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/boosting.js +8 -8
- package/lib/constants/abis/json/busd/swap.json +1 -2
- package/lib/constants/abis/json/compound/swap.json +1 -2
- package/lib/constants/abis/json/iearn/swap.json +1 -2
- package/lib/constants/abis/json/pax/swap.json +1 -2
- package/lib/constants/abis/json/ren/swap.json +1 -2
- package/lib/constants/abis/json/sbtc/swap.json +1 -2
- package/lib/constants/abis/json/susdv2/swap.json +1 -2
- package/lib/constants/abis/json/usdt/swap.json +1 -2
- package/lib/curve.d.ts +3 -1
- package/lib/curve.js +3 -2
- package/lib/pools.d.ts +45 -1
- package/lib/pools.js +734 -282
- package/lib/utils.js +4 -4
- package/package.json +1 -1
package/lib/pools.js
CHANGED
|
@@ -126,6 +126,17 @@ var Pool = /** @class */ (function () {
|
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
};
|
|
129
|
+
this.getVirtualPrice = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
130
|
+
var _virtualPrice;
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
switch (_a.label) {
|
|
133
|
+
case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.get_virtual_price(curve_1.curve.constantOptions)];
|
|
134
|
+
case 1:
|
|
135
|
+
_virtualPrice = _a.sent();
|
|
136
|
+
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_virtualPrice)];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}); };
|
|
129
140
|
this.addLiquidityExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
130
141
|
return __generator(this, function (_a) {
|
|
131
142
|
switch (_a.label) {
|
|
@@ -134,19 +145,52 @@ var Pool = /** @class */ (function () {
|
|
|
134
145
|
}
|
|
135
146
|
});
|
|
136
147
|
}); };
|
|
148
|
+
this.addLiquidityIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
149
|
+
var spender;
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
|
|
154
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, spender)];
|
|
155
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}); };
|
|
159
|
+
this.addLiquidityApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
160
|
+
var spender;
|
|
161
|
+
return __generator(this, function (_a) {
|
|
162
|
+
switch (_a.label) {
|
|
163
|
+
case 0:
|
|
164
|
+
spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
|
|
165
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, spender)];
|
|
166
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}); };
|
|
170
|
+
this.addLiquidityApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
171
|
+
var spender;
|
|
172
|
+
return __generator(this, function (_a) {
|
|
173
|
+
switch (_a.label) {
|
|
174
|
+
case 0:
|
|
175
|
+
spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
|
|
176
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, spender)];
|
|
177
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}); };
|
|
137
181
|
this.addLiquidityEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
138
|
-
var balances, _a,
|
|
182
|
+
var balances, _a, _c, i, _amounts;
|
|
139
183
|
var _this = this;
|
|
140
|
-
return __generator(this, function (
|
|
141
|
-
switch (
|
|
184
|
+
return __generator(this, function (_d) {
|
|
185
|
+
switch (_d.label) {
|
|
142
186
|
case 0:
|
|
143
187
|
if (amounts.length !== this.underlyingCoinAddresses.length) {
|
|
144
188
|
throw Error(this.name + " pool has " + this.underlyingCoinAddresses.length + " coins (amounts provided for " + amounts.length + ")");
|
|
145
189
|
}
|
|
146
|
-
|
|
190
|
+
_c = (_a = Object).values;
|
|
147
191
|
return [4 /*yield*/, this.underlyingCoinBalances()];
|
|
148
192
|
case 1:
|
|
149
|
-
balances =
|
|
193
|
+
balances = _c.apply(_a, [_d.sent()]);
|
|
150
194
|
for (i = 0; i < balances.length; i++) {
|
|
151
195
|
if (Number(balances[i]) < Number(amounts[i])) {
|
|
152
196
|
throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + balances[i] + ", required: " + amounts[i]);
|
|
@@ -154,7 +198,7 @@ var Pool = /** @class */ (function () {
|
|
|
154
198
|
}
|
|
155
199
|
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.swap)];
|
|
156
200
|
case 2:
|
|
157
|
-
if (!(
|
|
201
|
+
if (!(_d.sent())) {
|
|
158
202
|
throw Error("Token allowance is needed to estimate gas");
|
|
159
203
|
}
|
|
160
204
|
_amounts = amounts.map(function (amount, i) {
|
|
@@ -162,19 +206,60 @@ var Pool = /** @class */ (function () {
|
|
|
162
206
|
});
|
|
163
207
|
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 4];
|
|
164
208
|
return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
|
|
165
|
-
case 3: return [2 /*return*/,
|
|
209
|
+
case 3: return [2 /*return*/, _d.sent()];
|
|
166
210
|
case 4:
|
|
167
211
|
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 6];
|
|
168
212
|
return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
|
|
169
|
-
case 5: return [2 /*return*/,
|
|
213
|
+
case 5: return [2 /*return*/, _d.sent()];
|
|
170
214
|
case 6:
|
|
171
215
|
if (!this.isMeta) return [3 /*break*/, 8];
|
|
172
216
|
return [4 /*yield*/, this._addLiquidityMetaZap(_amounts, true)];
|
|
173
|
-
case 7: return [2 /*return*/,
|
|
217
|
+
case 7: return [2 /*return*/, _d.sent()];
|
|
174
218
|
case 8: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
|
|
175
219
|
case 9:
|
|
176
220
|
// Plain pools
|
|
177
|
-
return [2 /*return*/,
|
|
221
|
+
return [2 /*return*/, _d.sent()];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}); };
|
|
225
|
+
this.balancedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
226
|
+
var swapContract, contractCalls, _poolWrappedBalances, _poolUnderlyingBalances, _poolMetaCoinBalance, _poolUnderlyingBalance, basePool, _basePoolExpectedAmounts, _rates_1, poolBalances, walletBalances, _a, _c;
|
|
227
|
+
var _this = this;
|
|
228
|
+
return __generator(this, function (_d) {
|
|
229
|
+
switch (_d.label) {
|
|
230
|
+
case 0:
|
|
231
|
+
swapContract = curve_1.curve.contracts[this.swap].multicallContract;
|
|
232
|
+
contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
|
|
233
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
234
|
+
case 1:
|
|
235
|
+
_poolWrappedBalances = (_d.sent());
|
|
236
|
+
_poolUnderlyingBalances = [];
|
|
237
|
+
if (!this.isMeta) return [3 /*break*/, 3];
|
|
238
|
+
_poolWrappedBalances.unshift(_poolWrappedBalances.pop());
|
|
239
|
+
_poolMetaCoinBalance = _poolWrappedBalances[0], _poolUnderlyingBalance = _poolWrappedBalances.slice(1);
|
|
240
|
+
basePool = new Pool(this.basePool);
|
|
241
|
+
return [4 /*yield*/, basePool._calcExpectedAmounts(_poolMetaCoinBalance)];
|
|
242
|
+
case 2:
|
|
243
|
+
_basePoolExpectedAmounts = _d.sent();
|
|
244
|
+
_poolUnderlyingBalances = __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true);
|
|
245
|
+
return [3 /*break*/, 6];
|
|
246
|
+
case 3:
|
|
247
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
|
|
248
|
+
return [4 /*yield*/, this._getRates()];
|
|
249
|
+
case 4:
|
|
250
|
+
_rates_1 = _d.sent();
|
|
251
|
+
_poolUnderlyingBalances = _poolWrappedBalances.map(function (_b, i) { return _b.mul(_rates_1[i]).div(ethers_1.ethers.BigNumber.from(10).pow(18)); });
|
|
252
|
+
return [3 /*break*/, 6];
|
|
253
|
+
case 5:
|
|
254
|
+
_poolUnderlyingBalances = _poolWrappedBalances;
|
|
255
|
+
_d.label = 6;
|
|
256
|
+
case 6:
|
|
257
|
+
poolBalances = _poolUnderlyingBalances.map(function (_b, i) { return Number(ethers_1.ethers.utils.formatUnits(_b, _this.underlyingDecimals[i])); });
|
|
258
|
+
_c = (_a = Object).values;
|
|
259
|
+
return [4 /*yield*/, this.underlyingCoinBalances()];
|
|
260
|
+
case 7:
|
|
261
|
+
walletBalances = _c.apply(_a, [_d.sent()]).map(Number);
|
|
262
|
+
return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances)];
|
|
178
263
|
}
|
|
179
264
|
});
|
|
180
265
|
}); };
|
|
@@ -211,6 +296,25 @@ var Pool = /** @class */ (function () {
|
|
|
211
296
|
}
|
|
212
297
|
});
|
|
213
298
|
}); };
|
|
299
|
+
this.balancedWrappedAmounts = function (address) { return __awaiter(_this, void 0, void 0, function () {
|
|
300
|
+
var swapContract, contractCalls, poolBalances, walletBalances, _a, _c;
|
|
301
|
+
var _this = this;
|
|
302
|
+
return __generator(this, function (_d) {
|
|
303
|
+
switch (_d.label) {
|
|
304
|
+
case 0:
|
|
305
|
+
swapContract = curve_1.curve.contracts[this.swap].multicallContract;
|
|
306
|
+
contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
|
|
307
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
308
|
+
case 1:
|
|
309
|
+
poolBalances = (_d.sent()).map(function (_b, i) { return Number(ethers_1.ethers.utils.formatUnits(_b, _this.decimals[i])); });
|
|
310
|
+
_c = (_a = Object).values;
|
|
311
|
+
return [4 /*yield*/, this.coinBalances(address ? [address] : [])];
|
|
312
|
+
case 2:
|
|
313
|
+
walletBalances = _c.apply(_a, [_d.sent()]).map(Number);
|
|
314
|
+
return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances)];
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}); };
|
|
214
318
|
this.addLiquidityWrappedExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
215
319
|
return __generator(this, function (_a) {
|
|
216
320
|
switch (_a.label) {
|
|
@@ -219,27 +323,51 @@ var Pool = /** @class */ (function () {
|
|
|
219
323
|
}
|
|
220
324
|
});
|
|
221
325
|
}); };
|
|
326
|
+
this.addLiquidityWrappedIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
327
|
+
return __generator(this, function (_a) {
|
|
328
|
+
switch (_a.label) {
|
|
329
|
+
case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.swap)];
|
|
330
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}); };
|
|
334
|
+
this.addLiquidityWrappedApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
335
|
+
return __generator(this, function (_a) {
|
|
336
|
+
switch (_a.label) {
|
|
337
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, this.swap)];
|
|
338
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}); };
|
|
342
|
+
this.addLiquidityWrappedApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
343
|
+
return __generator(this, function (_a) {
|
|
344
|
+
switch (_a.label) {
|
|
345
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, this.swap)];
|
|
346
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}); };
|
|
222
350
|
this.addLiquidityWrappedEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
223
|
-
var balances, _a,
|
|
351
|
+
var balances, _a, _c, i, _amounts;
|
|
224
352
|
var _this = this;
|
|
225
|
-
return __generator(this, function (
|
|
226
|
-
switch (
|
|
353
|
+
return __generator(this, function (_d) {
|
|
354
|
+
switch (_d.label) {
|
|
227
355
|
case 0:
|
|
228
356
|
if (amounts.length !== this.coinAddresses.length) {
|
|
229
357
|
throw Error(this.name + " pool has " + this.coinAddresses.length + " coins (amounts provided for " + amounts.length + ")");
|
|
230
358
|
}
|
|
231
|
-
|
|
359
|
+
_c = (_a = Object).values;
|
|
232
360
|
return [4 /*yield*/, this.coinBalances()];
|
|
233
361
|
case 1:
|
|
234
|
-
balances =
|
|
362
|
+
balances = _c.apply(_a, [_d.sent()]);
|
|
235
363
|
for (i = 0; i < balances.length; i++) {
|
|
236
364
|
if (Number(balances[i]) < Number(amounts[i])) {
|
|
237
365
|
throw Error("Not enough " + this.coins[i] + ". Actual: " + balances[i] + ", required: " + amounts[i]);
|
|
238
366
|
}
|
|
239
367
|
}
|
|
240
|
-
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.
|
|
368
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.swap)];
|
|
241
369
|
case 2:
|
|
242
|
-
if (!(
|
|
370
|
+
if (!(_d.sent())) {
|
|
243
371
|
throw Error("Token allowance is needed to estimate gas");
|
|
244
372
|
}
|
|
245
373
|
_amounts = amounts.map(function (amount, i) {
|
|
@@ -247,11 +375,11 @@ var Pool = /** @class */ (function () {
|
|
|
247
375
|
});
|
|
248
376
|
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
|
|
249
377
|
return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
|
|
250
|
-
case 3: return [2 /*return*/,
|
|
378
|
+
case 3: return [2 /*return*/, _d.sent()];
|
|
251
379
|
case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
|
|
252
380
|
case 5:
|
|
253
381
|
// Lending pools with zap and metapools
|
|
254
|
-
return [2 /*return*/,
|
|
382
|
+
return [2 /*return*/, _d.sent()];
|
|
255
383
|
}
|
|
256
384
|
});
|
|
257
385
|
}); };
|
|
@@ -306,13 +434,46 @@ var Pool = /** @class */ (function () {
|
|
|
306
434
|
}
|
|
307
435
|
});
|
|
308
436
|
}); };
|
|
437
|
+
this.removeLiquidityIsApproved = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
438
|
+
return __generator(this, function (_a) {
|
|
439
|
+
switch (_a.label) {
|
|
440
|
+
case 0:
|
|
441
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !this.isMeta)
|
|
442
|
+
return [2 /*return*/, true];
|
|
443
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
444
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}); };
|
|
448
|
+
this.removeLiquidityApproveEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
449
|
+
return __generator(this, function (_a) {
|
|
450
|
+
switch (_a.label) {
|
|
451
|
+
case 0:
|
|
452
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !this.isMeta)
|
|
453
|
+
return [2 /*return*/, 0];
|
|
454
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
455
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}); };
|
|
459
|
+
this.removeLiquidityApprove = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
460
|
+
return __generator(this, function (_a) {
|
|
461
|
+
switch (_a.label) {
|
|
462
|
+
case 0:
|
|
463
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !this.isMeta)
|
|
464
|
+
return [2 /*return*/, []];
|
|
465
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
466
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
}); };
|
|
309
470
|
this.removeLiquidityEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
310
471
|
var lpTokenBalance, _a, _lpTokenAmount;
|
|
311
|
-
return __generator(this, function (
|
|
312
|
-
switch (
|
|
472
|
+
return __generator(this, function (_c) {
|
|
473
|
+
switch (_c.label) {
|
|
313
474
|
case 0: return [4 /*yield*/, this.lpTokenBalances()];
|
|
314
475
|
case 1:
|
|
315
|
-
lpTokenBalance = (
|
|
476
|
+
lpTokenBalance = (_c.sent())['lpToken'];
|
|
316
477
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
317
478
|
throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
|
|
318
479
|
}
|
|
@@ -320,8 +481,8 @@ var Pool = /** @class */ (function () {
|
|
|
320
481
|
if (!_a) return [3 /*break*/, 3];
|
|
321
482
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
322
483
|
case 2:
|
|
323
|
-
_a = !(
|
|
324
|
-
|
|
484
|
+
_a = !(_c.sent());
|
|
485
|
+
_c.label = 3;
|
|
325
486
|
case 3:
|
|
326
487
|
if (_a) {
|
|
327
488
|
throw Error("Token allowance is needed to estimate gas");
|
|
@@ -329,17 +490,17 @@ var Pool = /** @class */ (function () {
|
|
|
329
490
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
330
491
|
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 5];
|
|
331
492
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
|
|
332
|
-
case 4: return [2 /*return*/,
|
|
493
|
+
case 4: return [2 /*return*/, _c.sent()];
|
|
333
494
|
case 5:
|
|
334
495
|
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
|
|
335
496
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
|
|
336
|
-
case 6: return [2 /*return*/,
|
|
497
|
+
case 6: return [2 /*return*/, _c.sent()];
|
|
337
498
|
case 7:
|
|
338
499
|
if (!this.isMeta) return [3 /*break*/, 9];
|
|
339
500
|
return [4 /*yield*/, this._removeLiquidityMetaZap(_lpTokenAmount, true)];
|
|
340
|
-
case 8: return [2 /*return*/,
|
|
501
|
+
case 8: return [2 /*return*/, _c.sent()];
|
|
341
502
|
case 9: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
|
|
342
|
-
case 10: return [2 /*return*/,
|
|
503
|
+
case 10: return [2 /*return*/, _c.sent()];
|
|
343
504
|
}
|
|
344
505
|
});
|
|
345
506
|
}); };
|
|
@@ -397,7 +558,7 @@ var Pool = /** @class */ (function () {
|
|
|
397
558
|
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
|
|
398
559
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
|
|
399
560
|
case 2: return [2 /*return*/, _a.sent()];
|
|
400
|
-
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
|
|
561
|
+
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
|
|
401
562
|
case 4: return [2 /*return*/, _a.sent()];
|
|
402
563
|
}
|
|
403
564
|
});
|
|
@@ -427,17 +588,89 @@ var Pool = /** @class */ (function () {
|
|
|
427
588
|
}
|
|
428
589
|
});
|
|
429
590
|
}); };
|
|
591
|
+
this.removeLiquidityImbalanceIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
592
|
+
var _amounts, _maxBurnAmount, _maxBurnAmount;
|
|
593
|
+
var _this = this;
|
|
594
|
+
return __generator(this, function (_a) {
|
|
595
|
+
switch (_a.label) {
|
|
596
|
+
case 0:
|
|
597
|
+
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
598
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
|
|
599
|
+
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
|
|
600
|
+
case 1:
|
|
601
|
+
_maxBurnAmount = (_a.sent()).mul(101).div(100);
|
|
602
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], curve_1.curve.signerAddress, this.zap)];
|
|
603
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
604
|
+
case 3:
|
|
605
|
+
if (!this.isMeta) return [3 /*break*/, 6];
|
|
606
|
+
return [4 /*yield*/, this._calcLpTokenAmountZap(_amounts, false)];
|
|
607
|
+
case 4:
|
|
608
|
+
_maxBurnAmount = (_a.sent()).mul(101).div(100);
|
|
609
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], curve_1.curve.signerAddress, this.zap)];
|
|
610
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
611
|
+
case 6: return [2 /*return*/, true];
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
}); };
|
|
615
|
+
this.removeLiquidityImbalanceApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
616
|
+
var _amounts, _maxBurnAmount, _maxBurnAmount;
|
|
617
|
+
var _this = this;
|
|
618
|
+
return __generator(this, function (_a) {
|
|
619
|
+
switch (_a.label) {
|
|
620
|
+
case 0:
|
|
621
|
+
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
622
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
|
|
623
|
+
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
|
|
624
|
+
case 1:
|
|
625
|
+
_maxBurnAmount = (_a.sent()).mul(101).div(100);
|
|
626
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], this.zap)];
|
|
627
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
628
|
+
case 3:
|
|
629
|
+
if (!this.isMeta) return [3 /*break*/, 6];
|
|
630
|
+
return [4 /*yield*/, this._calcLpTokenAmountZap(_amounts, false)];
|
|
631
|
+
case 4:
|
|
632
|
+
_maxBurnAmount = (_a.sent()).mul(101).div(100);
|
|
633
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], this.zap)];
|
|
634
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
635
|
+
case 6: return [2 /*return*/, 0];
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
}); };
|
|
639
|
+
this.removeLiquidityImbalanceApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
640
|
+
var _amounts, _maxBurnAmount, _maxBurnAmount;
|
|
641
|
+
var _this = this;
|
|
642
|
+
return __generator(this, function (_a) {
|
|
643
|
+
switch (_a.label) {
|
|
644
|
+
case 0:
|
|
645
|
+
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
646
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
|
|
647
|
+
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
|
|
648
|
+
case 1:
|
|
649
|
+
_maxBurnAmount = (_a.sent()).mul(101).div(100);
|
|
650
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], this.zap)];
|
|
651
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
652
|
+
case 3:
|
|
653
|
+
if (!this.isMeta) return [3 /*break*/, 6];
|
|
654
|
+
return [4 /*yield*/, this._calcLpTokenAmountZap(_amounts, false)];
|
|
655
|
+
case 4:
|
|
656
|
+
_maxBurnAmount = (_a.sent()).mul(101).div(100);
|
|
657
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], this.zap)];
|
|
658
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
659
|
+
case 6: return [2 /*return*/, []];
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
}); };
|
|
430
663
|
this.removeLiquidityImbalanceEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
431
664
|
var lpTokenAmount, lpTokenBalance, _a, _amounts;
|
|
432
665
|
var _this = this;
|
|
433
|
-
return __generator(this, function (
|
|
434
|
-
switch (
|
|
666
|
+
return __generator(this, function (_c) {
|
|
667
|
+
switch (_c.label) {
|
|
435
668
|
case 0: return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
|
|
436
669
|
case 1:
|
|
437
|
-
lpTokenAmount =
|
|
670
|
+
lpTokenAmount = _c.sent();
|
|
438
671
|
return [4 /*yield*/, this.lpTokenBalances()];
|
|
439
672
|
case 2:
|
|
440
|
-
lpTokenBalance = (
|
|
673
|
+
lpTokenBalance = (_c.sent())['lpToken'];
|
|
441
674
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
442
675
|
throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
|
|
443
676
|
}
|
|
@@ -445,8 +678,8 @@ var Pool = /** @class */ (function () {
|
|
|
445
678
|
if (!_a) return [3 /*break*/, 4];
|
|
446
679
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
447
680
|
case 3:
|
|
448
|
-
_a = !(
|
|
449
|
-
|
|
681
|
+
_a = !(_c.sent());
|
|
682
|
+
_c.label = 4;
|
|
450
683
|
case 4:
|
|
451
684
|
if (_a) {
|
|
452
685
|
throw Error("Token allowance is needed to estimate gas");
|
|
@@ -454,17 +687,17 @@ var Pool = /** @class */ (function () {
|
|
|
454
687
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
455
688
|
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 6];
|
|
456
689
|
return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts, true)];
|
|
457
|
-
case 5: return [2 /*return*/,
|
|
690
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
458
691
|
case 6:
|
|
459
692
|
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 8];
|
|
460
693
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true, true)];
|
|
461
|
-
case 7: return [2 /*return*/,
|
|
694
|
+
case 7: return [2 /*return*/, _c.sent()];
|
|
462
695
|
case 8:
|
|
463
696
|
if (!this.isMeta) return [3 /*break*/, 10];
|
|
464
697
|
return [4 /*yield*/, this._removeLiquidityImbalanceMetaZap(_amounts, true)];
|
|
465
|
-
case 9: return [2 /*return*/,
|
|
698
|
+
case 9: return [2 /*return*/, _c.sent()];
|
|
466
699
|
case 10: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, true)];
|
|
467
|
-
case 11: return [2 /*return*/,
|
|
700
|
+
case 11: return [2 /*return*/, _c.sent()];
|
|
468
701
|
}
|
|
469
702
|
});
|
|
470
703
|
}); };
|
|
@@ -572,13 +805,46 @@ var Pool = /** @class */ (function () {
|
|
|
572
805
|
}
|
|
573
806
|
});
|
|
574
807
|
}); };
|
|
808
|
+
this.removeLiquidityOneCoinIsApproved = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
809
|
+
return __generator(this, function (_a) {
|
|
810
|
+
switch (_a.label) {
|
|
811
|
+
case 0:
|
|
812
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
|
|
813
|
+
return [2 /*return*/, true];
|
|
814
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
815
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
}); };
|
|
819
|
+
this.removeLiquidityOneCoinApproveEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
820
|
+
return __generator(this, function (_a) {
|
|
821
|
+
switch (_a.label) {
|
|
822
|
+
case 0:
|
|
823
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
|
|
824
|
+
return [2 /*return*/, 0];
|
|
825
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
826
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
}); };
|
|
830
|
+
this.removeLiquidityOneCoinApprove = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
831
|
+
return __generator(this, function (_a) {
|
|
832
|
+
switch (_a.label) {
|
|
833
|
+
case 0:
|
|
834
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
|
|
835
|
+
return [2 /*return*/, []];
|
|
836
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
837
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
}); };
|
|
575
841
|
this.removeLiquidityOneCoinEstimateGas = function (lpTokenAmount, coin) { return __awaiter(_this, void 0, void 0, function () {
|
|
576
842
|
var lpTokenBalance, _a, i, _lpTokenAmount;
|
|
577
|
-
return __generator(this, function (
|
|
578
|
-
switch (
|
|
843
|
+
return __generator(this, function (_c) {
|
|
844
|
+
switch (_c.label) {
|
|
579
845
|
case 0: return [4 /*yield*/, this.lpTokenBalances()];
|
|
580
846
|
case 1:
|
|
581
|
-
lpTokenBalance = (
|
|
847
|
+
lpTokenBalance = (_c.sent())['lpToken'];
|
|
582
848
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
583
849
|
throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
|
|
584
850
|
}
|
|
@@ -586,8 +852,8 @@ var Pool = /** @class */ (function () {
|
|
|
586
852
|
if (!_a) return [3 /*break*/, 3];
|
|
587
853
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
588
854
|
case 2:
|
|
589
|
-
_a = !(
|
|
590
|
-
|
|
855
|
+
_a = !(_c.sent());
|
|
856
|
+
_c.label = 3;
|
|
591
857
|
case 3:
|
|
592
858
|
if (_a) {
|
|
593
859
|
throw Error("Token allowance is needed to estimate gas");
|
|
@@ -596,15 +862,15 @@ var Pool = /** @class */ (function () {
|
|
|
596
862
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
597
863
|
if (!(['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 5];
|
|
598
864
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
|
|
599
|
-
case 4: return [2 /*return*/,
|
|
865
|
+
case 4: return [2 /*return*/, _c.sent()];
|
|
600
866
|
case 5:
|
|
601
867
|
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
|
|
602
868
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
|
|
603
|
-
case 6: return [2 /*return*/,
|
|
869
|
+
case 6: return [2 /*return*/, _c.sent()];
|
|
604
870
|
case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
605
871
|
case 8:
|
|
606
872
|
// Plain pools
|
|
607
|
-
return [2 /*return*/,
|
|
873
|
+
return [2 /*return*/, _c.sent()];
|
|
608
874
|
}
|
|
609
875
|
});
|
|
610
876
|
}); };
|
|
@@ -637,6 +903,9 @@ var Pool = /** @class */ (function () {
|
|
|
637
903
|
return __generator(this, function (_a) {
|
|
638
904
|
switch (_a.label) {
|
|
639
905
|
case 0:
|
|
906
|
+
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
|
|
907
|
+
throw Error(this.name + " pool doesn't have remove_liquidity_one_coin method for wrapped tokens");
|
|
908
|
+
}
|
|
640
909
|
i = this._getCoinIdx(coin, false);
|
|
641
910
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
642
911
|
if (!(this.name === 'ib')) return [3 /*break*/, 2];
|
|
@@ -696,6 +965,41 @@ var Pool = /** @class */ (function () {
|
|
|
696
965
|
}
|
|
697
966
|
});
|
|
698
967
|
}); };
|
|
968
|
+
this.gaugeDepositIsApproved = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
969
|
+
return __generator(this, function (_a) {
|
|
970
|
+
switch (_a.label) {
|
|
971
|
+
case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.gauge)];
|
|
972
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
}); };
|
|
976
|
+
this.gaugeDepositApproveEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
977
|
+
return __generator(this, function (_a) {
|
|
978
|
+
switch (_a.label) {
|
|
979
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.gauge)];
|
|
980
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
}); };
|
|
984
|
+
this.gaugeDepositApprove = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
985
|
+
return __generator(this, function (_a) {
|
|
986
|
+
switch (_a.label) {
|
|
987
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.gauge)];
|
|
988
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
}); };
|
|
992
|
+
this.gaugeDepositEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
993
|
+
var _lpTokenAmount;
|
|
994
|
+
return __generator(this, function (_a) {
|
|
995
|
+
switch (_a.label) {
|
|
996
|
+
case 0:
|
|
997
|
+
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
998
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.options)];
|
|
999
|
+
case 1: return [2 /*return*/, (_a.sent()).toNumber()];
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
}); };
|
|
699
1003
|
this.gaugeDeposit = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
700
1004
|
var _lpTokenAmount;
|
|
701
1005
|
return __generator(this, function (_a) {
|
|
@@ -710,6 +1014,17 @@ var Pool = /** @class */ (function () {
|
|
|
710
1014
|
}
|
|
711
1015
|
});
|
|
712
1016
|
}); };
|
|
1017
|
+
this.gaugeWithdrawEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1018
|
+
var _lpTokenAmount;
|
|
1019
|
+
return __generator(this, function (_a) {
|
|
1020
|
+
switch (_a.label) {
|
|
1021
|
+
case 0:
|
|
1022
|
+
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1023
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.options)];
|
|
1024
|
+
case 1: return [2 /*return*/, (_a.sent()).toNumber()];
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
}); };
|
|
713
1028
|
this.gaugeWithdraw = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
714
1029
|
var _lpTokenAmount;
|
|
715
1030
|
return __generator(this, function (_a) {
|
|
@@ -727,10 +1042,10 @@ var Pool = /** @class */ (function () {
|
|
|
727
1042
|
addresses[_a] = arguments[_a];
|
|
728
1043
|
}
|
|
729
1044
|
return __awaiter(_this, void 0, void 0, function () {
|
|
730
|
-
return __generator(this, function (
|
|
731
|
-
switch (
|
|
1045
|
+
return __generator(this, function (_c) {
|
|
1046
|
+
switch (_c.label) {
|
|
732
1047
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken', 'gauge'], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([this.lpToken, this.gauge], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
|
|
733
|
-
case 1: return [2 /*return*/,
|
|
1048
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
734
1049
|
}
|
|
735
1050
|
});
|
|
736
1051
|
});
|
|
@@ -741,10 +1056,10 @@ var Pool = /** @class */ (function () {
|
|
|
741
1056
|
addresses[_a] = arguments[_a];
|
|
742
1057
|
}
|
|
743
1058
|
return __awaiter(_this, void 0, void 0, function () {
|
|
744
|
-
return __generator(this, function (
|
|
745
|
-
switch (
|
|
1059
|
+
return __generator(this, function (_c) {
|
|
1060
|
+
switch (_c.label) {
|
|
746
1061
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
|
|
747
|
-
case 1: return [2 /*return*/,
|
|
1062
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
748
1063
|
}
|
|
749
1064
|
});
|
|
750
1065
|
});
|
|
@@ -755,10 +1070,10 @@ var Pool = /** @class */ (function () {
|
|
|
755
1070
|
addresses[_a] = arguments[_a];
|
|
756
1071
|
}
|
|
757
1072
|
return __awaiter(_this, void 0, void 0, function () {
|
|
758
|
-
return __generator(this, function (
|
|
759
|
-
switch (
|
|
1073
|
+
return __generator(this, function (_c) {
|
|
1074
|
+
switch (_c.label) {
|
|
760
1075
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.underlyingCoins, this.underlyingCoinAddresses], addresses, false))];
|
|
761
|
-
case 1: return [2 /*return*/,
|
|
1076
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
762
1077
|
}
|
|
763
1078
|
});
|
|
764
1079
|
});
|
|
@@ -769,10 +1084,10 @@ var Pool = /** @class */ (function () {
|
|
|
769
1084
|
addresses[_a] = arguments[_a];
|
|
770
1085
|
}
|
|
771
1086
|
return __awaiter(_this, void 0, void 0, function () {
|
|
772
|
-
return __generator(this, function (
|
|
773
|
-
switch (
|
|
1087
|
+
return __generator(this, function (_c) {
|
|
1088
|
+
switch (_c.label) {
|
|
774
1089
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.coins, this.coinAddresses], addresses, false))];
|
|
775
|
-
case 1: return [2 /*return*/,
|
|
1090
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
776
1091
|
}
|
|
777
1092
|
});
|
|
778
1093
|
});
|
|
@@ -783,10 +1098,10 @@ var Pool = /** @class */ (function () {
|
|
|
783
1098
|
addresses[_a] = arguments[_a];
|
|
784
1099
|
}
|
|
785
1100
|
return __awaiter(_this, void 0, void 0, function () {
|
|
786
|
-
return __generator(this, function (
|
|
787
|
-
switch (
|
|
1101
|
+
return __generator(this, function (_c) {
|
|
1102
|
+
switch (_c.label) {
|
|
788
1103
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray([], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
|
|
789
|
-
case 1: return [2 /*return*/,
|
|
1104
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
790
1105
|
}
|
|
791
1106
|
});
|
|
792
1107
|
});
|
|
@@ -806,40 +1121,73 @@ var Pool = /** @class */ (function () {
|
|
|
806
1121
|
}
|
|
807
1122
|
});
|
|
808
1123
|
}); };
|
|
1124
|
+
this.exchangeIsApproved = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1125
|
+
var i;
|
|
1126
|
+
return __generator(this, function (_a) {
|
|
1127
|
+
switch (_a.label) {
|
|
1128
|
+
case 0:
|
|
1129
|
+
i = this._getCoinIdx(inputCoin);
|
|
1130
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
1131
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
}); };
|
|
1135
|
+
this.exchangeApproveEstimateGas = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1136
|
+
var i;
|
|
1137
|
+
return __generator(this, function (_a) {
|
|
1138
|
+
switch (_a.label) {
|
|
1139
|
+
case 0:
|
|
1140
|
+
i = this._getCoinIdx(inputCoin);
|
|
1141
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
|
|
1142
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
}); };
|
|
1146
|
+
this.exchangeApprove = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1147
|
+
var i;
|
|
1148
|
+
return __generator(this, function (_a) {
|
|
1149
|
+
switch (_a.label) {
|
|
1150
|
+
case 0:
|
|
1151
|
+
i = this._getCoinIdx(inputCoin);
|
|
1152
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
|
|
1153
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1154
|
+
}
|
|
1155
|
+
});
|
|
1156
|
+
}); };
|
|
809
1157
|
this.exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
810
1158
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
811
1159
|
return __awaiter(_this, void 0, void 0, function () {
|
|
812
|
-
var i, j, inputCoinBalance, _a,
|
|
813
|
-
return __generator(this, function (
|
|
814
|
-
switch (
|
|
1160
|
+
var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value;
|
|
1161
|
+
return __generator(this, function (_d) {
|
|
1162
|
+
switch (_d.label) {
|
|
815
1163
|
case 0:
|
|
816
1164
|
if (this.name === 'tricrypto2') {
|
|
817
1165
|
throw Error("Use exchangeTricryptoEstimateGas method for tricrypto2 pool instead");
|
|
818
1166
|
}
|
|
819
1167
|
i = this._getCoinIdx(inputCoin);
|
|
820
1168
|
j = this._getCoinIdx(outputCoin);
|
|
821
|
-
|
|
1169
|
+
_c = (_a = Object).values;
|
|
822
1170
|
return [4 /*yield*/, this.underlyingCoinBalances()];
|
|
823
1171
|
case 1:
|
|
824
|
-
inputCoinBalance =
|
|
1172
|
+
inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
|
|
825
1173
|
if (Number(inputCoinBalance) < Number(amount)) {
|
|
826
1174
|
throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
|
|
827
1175
|
}
|
|
828
1176
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
829
1177
|
case 2:
|
|
830
|
-
if (!(
|
|
1178
|
+
if (!(_d.sent())) {
|
|
831
1179
|
throw Error("Token allowance is needed to estimate gas");
|
|
832
1180
|
}
|
|
833
1181
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
|
|
834
1182
|
return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
|
|
835
1183
|
case 3:
|
|
836
|
-
_expected =
|
|
1184
|
+
_expected = _d.sent();
|
|
837
1185
|
_minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
|
|
838
1186
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
839
1187
|
exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
|
|
840
1188
|
value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
841
|
-
return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.
|
|
842
|
-
case 4: return [2 /*return*/, (
|
|
1189
|
+
return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1190
|
+
case 4: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
843
1191
|
}
|
|
844
1192
|
});
|
|
845
1193
|
});
|
|
@@ -870,7 +1218,7 @@ var Pool = /** @class */ (function () {
|
|
|
870
1218
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
871
1219
|
case 3:
|
|
872
1220
|
_a.sent();
|
|
873
|
-
return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.
|
|
1221
|
+
return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
874
1222
|
case 4:
|
|
875
1223
|
gasLimit = (_a.sent()).mul(130).div(100);
|
|
876
1224
|
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
@@ -879,40 +1227,88 @@ var Pool = /** @class */ (function () {
|
|
|
879
1227
|
});
|
|
880
1228
|
});
|
|
881
1229
|
};
|
|
1230
|
+
this.exchangeTricryptoIsApproved = function (inputCoin, amount, useEth) {
|
|
1231
|
+
if (useEth === void 0) { useEth = false; }
|
|
1232
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
1233
|
+
var i;
|
|
1234
|
+
return __generator(this, function (_a) {
|
|
1235
|
+
switch (_a.label) {
|
|
1236
|
+
case 0:
|
|
1237
|
+
i = this._getCoinIdx(inputCoin);
|
|
1238
|
+
if (i === 2 && useEth)
|
|
1239
|
+
return [2 /*return*/, true];
|
|
1240
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
1241
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
});
|
|
1245
|
+
};
|
|
1246
|
+
this.exchangeTricryptoApproveEstimateGas = function (inputCoin, amount, useEth) {
|
|
1247
|
+
if (useEth === void 0) { useEth = false; }
|
|
1248
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
1249
|
+
var i;
|
|
1250
|
+
return __generator(this, function (_a) {
|
|
1251
|
+
switch (_a.label) {
|
|
1252
|
+
case 0:
|
|
1253
|
+
i = this._getCoinIdx(inputCoin);
|
|
1254
|
+
if (i === 2 && useEth)
|
|
1255
|
+
return [2 /*return*/, 0];
|
|
1256
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
|
|
1257
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
1260
|
+
});
|
|
1261
|
+
};
|
|
1262
|
+
this.exchangeTricryptoApprove = function (inputCoin, amount, useEth) {
|
|
1263
|
+
if (useEth === void 0) { useEth = false; }
|
|
1264
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
1265
|
+
var i;
|
|
1266
|
+
return __generator(this, function (_a) {
|
|
1267
|
+
switch (_a.label) {
|
|
1268
|
+
case 0:
|
|
1269
|
+
i = this._getCoinIdx(inputCoin);
|
|
1270
|
+
if (i === 2 && useEth)
|
|
1271
|
+
return [2 /*return*/, []];
|
|
1272
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
|
|
1273
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
});
|
|
1277
|
+
};
|
|
882
1278
|
this.exchangeTricryptoEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage, useEth) {
|
|
883
1279
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
884
1280
|
if (useEth === void 0) { useEth = false; }
|
|
885
1281
|
return __awaiter(_this, void 0, void 0, function () {
|
|
886
|
-
var i, j, inputCoinBalance, _a,
|
|
887
|
-
return __generator(this, function (
|
|
888
|
-
switch (
|
|
1282
|
+
var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, value;
|
|
1283
|
+
return __generator(this, function (_d) {
|
|
1284
|
+
switch (_d.label) {
|
|
889
1285
|
case 0:
|
|
890
1286
|
if (this.name !== 'tricrypto2') {
|
|
891
1287
|
throw Error("This method is for only tricrypto2 pool");
|
|
892
1288
|
}
|
|
893
1289
|
i = this._getCoinIdx(inputCoin);
|
|
894
1290
|
j = this._getCoinIdx(outputCoin);
|
|
895
|
-
|
|
1291
|
+
_c = (_a = Object).values;
|
|
896
1292
|
return [4 /*yield*/, this.underlyingCoinBalances()];
|
|
897
1293
|
case 1:
|
|
898
|
-
inputCoinBalance =
|
|
1294
|
+
inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
|
|
899
1295
|
if (Number(inputCoinBalance) < Number(amount)) {
|
|
900
1296
|
throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
|
|
901
1297
|
}
|
|
902
1298
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
903
1299
|
case 2:
|
|
904
|
-
if (!(
|
|
1300
|
+
if (!(_d.sent())) {
|
|
905
1301
|
throw Error("Token allowance is needed to estimate gas");
|
|
906
1302
|
}
|
|
907
1303
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
|
|
908
1304
|
return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
|
|
909
1305
|
case 3:
|
|
910
|
-
_expected =
|
|
1306
|
+
_expected = _d.sent();
|
|
911
1307
|
_minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
|
|
912
1308
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
913
1309
|
value = useEth && i == 2 ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
914
|
-
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.
|
|
915
|
-
case 4: return [2 /*return*/, (
|
|
1310
|
+
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1311
|
+
case 4: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
916
1312
|
}
|
|
917
1313
|
});
|
|
918
1314
|
});
|
|
@@ -946,7 +1342,7 @@ var Pool = /** @class */ (function () {
|
|
|
946
1342
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
947
1343
|
case 4:
|
|
948
1344
|
_a.sent();
|
|
949
|
-
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.
|
|
1345
|
+
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
950
1346
|
case 5:
|
|
951
1347
|
gasLimit = (_a.sent()).mul(130).div(100);
|
|
952
1348
|
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
@@ -970,36 +1366,69 @@ var Pool = /** @class */ (function () {
|
|
|
970
1366
|
}
|
|
971
1367
|
});
|
|
972
1368
|
}); };
|
|
1369
|
+
this.exchangeWrappedIsApproved = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1370
|
+
var i;
|
|
1371
|
+
return __generator(this, function (_a) {
|
|
1372
|
+
switch (_a.label) {
|
|
1373
|
+
case 0:
|
|
1374
|
+
i = this._getCoinIdx(inputCoin);
|
|
1375
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
1376
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
}); };
|
|
1380
|
+
this.exchangeWrappedApproveEstimateGas = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1381
|
+
var i;
|
|
1382
|
+
return __generator(this, function (_a) {
|
|
1383
|
+
switch (_a.label) {
|
|
1384
|
+
case 0:
|
|
1385
|
+
i = this._getCoinIdx(inputCoin);
|
|
1386
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.coinAddresses[i]], [amount], this.swap)];
|
|
1387
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1388
|
+
}
|
|
1389
|
+
});
|
|
1390
|
+
}); };
|
|
1391
|
+
this.exchangeWrappedApprove = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1392
|
+
var i;
|
|
1393
|
+
return __generator(this, function (_a) {
|
|
1394
|
+
switch (_a.label) {
|
|
1395
|
+
case 0:
|
|
1396
|
+
i = this._getCoinIdx(inputCoin);
|
|
1397
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.coinAddresses[i]], [amount], this.swap)];
|
|
1398
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1399
|
+
}
|
|
1400
|
+
});
|
|
1401
|
+
}); };
|
|
973
1402
|
this.exchangeWrappedEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
974
1403
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
975
1404
|
return __awaiter(_this, void 0, void 0, function () {
|
|
976
|
-
var i, j, inputCoinBalance, _a,
|
|
977
|
-
return __generator(this, function (
|
|
978
|
-
switch (
|
|
1405
|
+
var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, value;
|
|
1406
|
+
return __generator(this, function (_d) {
|
|
1407
|
+
switch (_d.label) {
|
|
979
1408
|
case 0:
|
|
980
1409
|
i = this._getCoinIdx(inputCoin, false);
|
|
981
1410
|
j = this._getCoinIdx(outputCoin, false);
|
|
982
|
-
|
|
1411
|
+
_c = (_a = Object).values;
|
|
983
1412
|
return [4 /*yield*/, this.coinBalances()];
|
|
984
1413
|
case 1:
|
|
985
|
-
inputCoinBalance =
|
|
1414
|
+
inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
|
|
986
1415
|
if (Number(inputCoinBalance) < Number(amount)) {
|
|
987
1416
|
throw Error("Not enough " + this.coins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
|
|
988
1417
|
}
|
|
989
1418
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
990
1419
|
case 2:
|
|
991
|
-
if (!(
|
|
1420
|
+
if (!(_d.sent())) {
|
|
992
1421
|
throw Error("Token allowance is needed to estimate gas");
|
|
993
1422
|
}
|
|
994
1423
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.decimals[i]);
|
|
995
1424
|
return [4 /*yield*/, this._getExchangeOutputWrapped(i, j, _amount)];
|
|
996
1425
|
case 3:
|
|
997
|
-
_expected =
|
|
1426
|
+
_expected = _d.sent();
|
|
998
1427
|
_minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
|
|
999
1428
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1000
1429
|
value = (0, utils_1.isEth)(this.coinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
1001
|
-
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.
|
|
1002
|
-
case 4: return [2 /*return*/, (
|
|
1430
|
+
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1431
|
+
case 4: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
1003
1432
|
}
|
|
1004
1433
|
});
|
|
1005
1434
|
});
|
|
@@ -1026,7 +1455,7 @@ var Pool = /** @class */ (function () {
|
|
|
1026
1455
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1027
1456
|
case 3:
|
|
1028
1457
|
_a.sent();
|
|
1029
|
-
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.
|
|
1458
|
+
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1030
1459
|
case 4:
|
|
1031
1460
|
gasLimit = (_a.sent()).mul(130).div(100);
|
|
1032
1461
|
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
@@ -1041,9 +1470,9 @@ var Pool = /** @class */ (function () {
|
|
|
1041
1470
|
addresses[_a] = arguments[_a];
|
|
1042
1471
|
}
|
|
1043
1472
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1044
|
-
var votingEscrowContract, gaugeContract, contractCalls, response,
|
|
1045
|
-
return __generator(this, function (
|
|
1046
|
-
switch (
|
|
1473
|
+
var votingEscrowContract, gaugeContract, contractCalls, response, _c, veTotalSupply, gaugeTotalSupply, resultBN, result, _d, _e, entry;
|
|
1474
|
+
return __generator(this, function (_f) {
|
|
1475
|
+
switch (_f.label) {
|
|
1047
1476
|
case 0:
|
|
1048
1477
|
if (addresses.length == 1 && Array.isArray(addresses[0]))
|
|
1049
1478
|
addresses = addresses[0];
|
|
@@ -1055,15 +1484,15 @@ var Pool = /** @class */ (function () {
|
|
|
1055
1484
|
});
|
|
1056
1485
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
1057
1486
|
case 1:
|
|
1058
|
-
response = (
|
|
1059
|
-
|
|
1487
|
+
response = (_f.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
|
|
1488
|
+
_c = response.splice(0, 2), veTotalSupply = _c[0], gaugeTotalSupply = _c[1];
|
|
1060
1489
|
resultBN = {};
|
|
1061
1490
|
addresses.forEach(function (acct, i) {
|
|
1062
1491
|
resultBN[acct] = response[i].div(veTotalSupply).times(gaugeTotalSupply);
|
|
1063
1492
|
});
|
|
1064
1493
|
result = {};
|
|
1065
|
-
for (
|
|
1066
|
-
entry = _d
|
|
1494
|
+
for (_d = 0, _e = Object.entries(resultBN); _d < _e.length; _d++) {
|
|
1495
|
+
entry = _e[_d];
|
|
1067
1496
|
result[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
|
|
1068
1497
|
}
|
|
1069
1498
|
return [2 /*return*/, result];
|
|
@@ -1077,9 +1506,9 @@ var Pool = /** @class */ (function () {
|
|
|
1077
1506
|
accounts[_a] = arguments[_a];
|
|
1078
1507
|
}
|
|
1079
1508
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1080
|
-
var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, response,
|
|
1081
|
-
return __generator(this, function (
|
|
1082
|
-
switch (
|
|
1509
|
+
var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, 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;
|
|
1510
|
+
return __generator(this, function (_k) {
|
|
1511
|
+
switch (_k.label) {
|
|
1083
1512
|
case 0:
|
|
1084
1513
|
if (accounts.length == 1 && Array.isArray(accounts[0]))
|
|
1085
1514
|
accounts = accounts[0];
|
|
@@ -1092,12 +1521,12 @@ var Pool = /** @class */ (function () {
|
|
|
1092
1521
|
});
|
|
1093
1522
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
1094
1523
|
case 1:
|
|
1095
|
-
response = (
|
|
1096
|
-
|
|
1524
|
+
response = (_k.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
|
|
1525
|
+
_c = response.splice(0, 2), veTotalSupply = _c[0], gaugeTotalSupply = _c[1];
|
|
1097
1526
|
votingPower = {};
|
|
1098
1527
|
totalBalance = (0, utils_1.BN)(0);
|
|
1099
|
-
for (
|
|
1100
|
-
acct = accounts_1[
|
|
1528
|
+
for (_d = 0, accounts_1 = accounts; _d < accounts_1.length; _d++) {
|
|
1529
|
+
acct = accounts_1[_d];
|
|
1101
1530
|
votingPower[acct] = response[0];
|
|
1102
1531
|
totalBalance = totalBalance.plus(response[1]).plus(response[2]);
|
|
1103
1532
|
response.splice(0, 3);
|
|
@@ -1105,8 +1534,8 @@ var Pool = /** @class */ (function () {
|
|
|
1105
1534
|
totalPower = Object.values(votingPower).reduce(function (sum, item) { return sum.plus(item); });
|
|
1106
1535
|
optimalBN = Object.fromEntries(accounts.map(function (acc) { return [acc, (0, utils_1.BN)(0)]; }));
|
|
1107
1536
|
if (totalBalance.lt(gaugeTotalSupply.times(totalPower).div(veTotalSupply))) {
|
|
1108
|
-
for (
|
|
1109
|
-
acct = accounts_2[
|
|
1537
|
+
for (_e = 0, accounts_2 = accounts; _e < accounts_2.length; _e++) {
|
|
1538
|
+
acct = accounts_2[_e];
|
|
1110
1539
|
amount = gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply).lt(totalBalance) ?
|
|
1111
1540
|
gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply) : totalBalance;
|
|
1112
1541
|
optimalBN[acct] = amount;
|
|
@@ -1118,16 +1547,16 @@ var Pool = /** @class */ (function () {
|
|
|
1118
1547
|
}
|
|
1119
1548
|
else {
|
|
1120
1549
|
if (totalPower.lt(0)) {
|
|
1121
|
-
for (
|
|
1122
|
-
acct = accounts_3[
|
|
1550
|
+
for (_f = 0, accounts_3 = accounts; _f < accounts_3.length; _f++) {
|
|
1551
|
+
acct = accounts_3[_f];
|
|
1123
1552
|
optimalBN[acct] = totalBalance.times(votingPower[acct]).div(totalPower);
|
|
1124
1553
|
}
|
|
1125
1554
|
}
|
|
1126
1555
|
optimalBN[accounts[0]] = optimalBN[accounts[0]].plus(totalBalance.minus(Object.values(optimalBN).reduce(function (sum, item) { return sum.plus(item); })));
|
|
1127
1556
|
}
|
|
1128
1557
|
optimal = {};
|
|
1129
|
-
for (
|
|
1130
|
-
entry = _g
|
|
1558
|
+
for (_g = 0, _h = Object.entries(optimalBN); _g < _h.length; _g++) {
|
|
1559
|
+
entry = _h[_g];
|
|
1131
1560
|
optimal[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
|
|
1132
1561
|
}
|
|
1133
1562
|
return [2 /*return*/, optimal];
|
|
@@ -1137,8 +1566,8 @@ var Pool = /** @class */ (function () {
|
|
|
1137
1566
|
};
|
|
1138
1567
|
this.boost = function (address) { return __awaiter(_this, void 0, void 0, function () {
|
|
1139
1568
|
var gaugeContract, _a, workingBalance, balance, boost;
|
|
1140
|
-
return __generator(this, function (
|
|
1141
|
-
switch (
|
|
1569
|
+
return __generator(this, function (_c) {
|
|
1570
|
+
switch (_c.label) {
|
|
1142
1571
|
case 0:
|
|
1143
1572
|
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
1144
1573
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
@@ -1146,7 +1575,7 @@ var Pool = /** @class */ (function () {
|
|
|
1146
1575
|
gaugeContract.balanceOf(address),
|
|
1147
1576
|
])];
|
|
1148
1577
|
case 1:
|
|
1149
|
-
_a = (
|
|
1578
|
+
_a = (_c.sent()).map(function (value) { return Number(ethers_1.ethers.utils.formatUnits(value)); }), workingBalance = _a[0], balance = _a[1];
|
|
1150
1579
|
boost = workingBalance / (0.4 * balance);
|
|
1151
1580
|
return [2 /*return*/, boost.toFixed(4).replace(/([0-9])0+$/, '$1')];
|
|
1152
1581
|
}
|
|
@@ -1154,8 +1583,8 @@ var Pool = /** @class */ (function () {
|
|
|
1154
1583
|
}); };
|
|
1155
1584
|
this.getApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1156
1585
|
var swapContract, gaugeContract, gaugeControllerContract, _a, inflation, weight, workingSupply, virtualPrice, rate, crvRate, baseApy, boostedApy;
|
|
1157
|
-
return __generator(this, function (
|
|
1158
|
-
switch (
|
|
1586
|
+
return __generator(this, function (_c) {
|
|
1587
|
+
switch (_c.label) {
|
|
1159
1588
|
case 0:
|
|
1160
1589
|
swapContract = curve_1.curve.contracts[this.swap].multicallContract;
|
|
1161
1590
|
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
@@ -1167,11 +1596,11 @@ var Pool = /** @class */ (function () {
|
|
|
1167
1596
|
swapContract.get_virtual_price(),
|
|
1168
1597
|
])];
|
|
1169
1598
|
case 1:
|
|
1170
|
-
_a = (
|
|
1599
|
+
_a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], virtualPrice = _a[3];
|
|
1171
1600
|
rate = inflation.times(weight).times(31536000).div(workingSupply).times(0.4).div(virtualPrice);
|
|
1172
1601
|
return [4 /*yield*/, (0, utils_1.getCrvRate)()];
|
|
1173
1602
|
case 2:
|
|
1174
|
-
crvRate =
|
|
1603
|
+
crvRate = _c.sent();
|
|
1175
1604
|
baseApy = rate.times(crvRate);
|
|
1176
1605
|
boostedApy = baseApy.times(2.5);
|
|
1177
1606
|
return [2 /*return*/, [baseApy.toFixed(4), boostedApy.toFixed(4)]];
|
|
@@ -1202,37 +1631,37 @@ var Pool = /** @class */ (function () {
|
|
|
1202
1631
|
return idx;
|
|
1203
1632
|
};
|
|
1204
1633
|
this._getRates = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1205
|
-
var _rates, i, addr, _a,
|
|
1206
|
-
return __generator(this, function (
|
|
1207
|
-
switch (
|
|
1634
|
+
var _rates, i, addr, _a, _c, _d, _e;
|
|
1635
|
+
return __generator(this, function (_f) {
|
|
1636
|
+
switch (_f.label) {
|
|
1208
1637
|
case 0:
|
|
1209
1638
|
_rates = [];
|
|
1210
1639
|
i = 0;
|
|
1211
|
-
|
|
1640
|
+
_f.label = 1;
|
|
1212
1641
|
case 1:
|
|
1213
1642
|
if (!(i < this.coinAddresses.length)) return [3 /*break*/, 9];
|
|
1214
1643
|
addr = this.coinAddresses[i];
|
|
1215
1644
|
if (!this.useLending[i]) return [3 /*break*/, 7];
|
|
1216
1645
|
if (!['compound', 'usdt', 'ib'].includes(this.name)) return [3 /*break*/, 3];
|
|
1217
|
-
|
|
1646
|
+
_c = (_a = _rates).push;
|
|
1218
1647
|
return [4 /*yield*/, curve_1.curve.contracts[addr].contract.exchangeRateStored()];
|
|
1219
1648
|
case 2:
|
|
1220
|
-
|
|
1649
|
+
_c.apply(_a, [_f.sent()]);
|
|
1221
1650
|
return [3 /*break*/, 6];
|
|
1222
1651
|
case 3:
|
|
1223
1652
|
if (!['y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 5];
|
|
1224
|
-
|
|
1653
|
+
_e = (_d = _rates).push;
|
|
1225
1654
|
return [4 /*yield*/, curve_1.curve.contracts[addr].contract.getPricePerFullShare()];
|
|
1226
1655
|
case 4:
|
|
1227
|
-
|
|
1656
|
+
_e.apply(_d, [_f.sent()]);
|
|
1228
1657
|
return [3 /*break*/, 6];
|
|
1229
1658
|
case 5:
|
|
1230
1659
|
_rates.push(ethers_1.ethers.BigNumber.from(10).pow(18)); // Aave ratio 1:1
|
|
1231
|
-
|
|
1660
|
+
_f.label = 6;
|
|
1232
1661
|
case 6: return [3 /*break*/, 8];
|
|
1233
1662
|
case 7:
|
|
1234
1663
|
_rates.push(ethers_1.ethers.BigNumber.from(10).pow(18));
|
|
1235
|
-
|
|
1664
|
+
_f.label = 8;
|
|
1236
1665
|
case 8:
|
|
1237
1666
|
i++;
|
|
1238
1667
|
return [3 /*break*/, 1];
|
|
@@ -1246,9 +1675,9 @@ var Pool = /** @class */ (function () {
|
|
|
1246
1675
|
addresses[_a - 2] = arguments[_a];
|
|
1247
1676
|
}
|
|
1248
1677
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1249
|
-
var coinNames, coinAddresses, i, rawBalances, balances,
|
|
1250
|
-
return __generator(this, function (
|
|
1251
|
-
switch (
|
|
1678
|
+
var coinNames, coinAddresses, i, rawBalances, balances, _c, addresses_1, address, _d, coinNames_1, coinName;
|
|
1679
|
+
return __generator(this, function (_e) {
|
|
1680
|
+
switch (_e.label) {
|
|
1252
1681
|
case 0:
|
|
1253
1682
|
coinNames = [];
|
|
1254
1683
|
coinAddresses = [];
|
|
@@ -1266,13 +1695,13 @@ var Pool = /** @class */ (function () {
|
|
|
1266
1695
|
addresses = (0, utils_1._prepareAddresses)(addresses);
|
|
1267
1696
|
return [4 /*yield*/, (0, utils_1._getBalances)(coinAddresses, addresses)];
|
|
1268
1697
|
case 1:
|
|
1269
|
-
rawBalances =
|
|
1698
|
+
rawBalances = _e.sent();
|
|
1270
1699
|
balances = {};
|
|
1271
|
-
for (
|
|
1272
|
-
address = addresses_1[
|
|
1700
|
+
for (_c = 0, addresses_1 = addresses; _c < addresses_1.length; _c++) {
|
|
1701
|
+
address = addresses_1[_c];
|
|
1273
1702
|
balances[address] = {};
|
|
1274
|
-
for (
|
|
1275
|
-
coinName = coinNames_1[
|
|
1703
|
+
for (_d = 0, coinNames_1 = coinNames; _d < coinNames_1.length; _d++) {
|
|
1704
|
+
coinName = coinNames_1[_d];
|
|
1276
1705
|
balances[address][coinName] = rawBalances[address].shift();
|
|
1277
1706
|
}
|
|
1278
1707
|
}
|
|
@@ -1281,12 +1710,24 @@ var Pool = /** @class */ (function () {
|
|
|
1281
1710
|
});
|
|
1282
1711
|
});
|
|
1283
1712
|
};
|
|
1713
|
+
this._balancedAmounts = function (poolBalances, walletBalances) {
|
|
1714
|
+
var poolBalancesRatios = poolBalances.map(function (b) { return b / poolBalances.reduce(function (a, b) { return a + b; }); });
|
|
1715
|
+
// Cross factors for each wallet balance used as reference to see the
|
|
1716
|
+
// max that can be used according to the lowest relative wallet balance
|
|
1717
|
+
var balancesAmountsForEachScenario = walletBalances.map(function (_, i) { return (walletBalances.map(function (_, j) { return (poolBalancesRatios[j] * walletBalances[i] / poolBalancesRatios[i]); })); });
|
|
1718
|
+
var firstCoinBalanceForEachScenario = balancesAmountsForEachScenario.map(function (_a) {
|
|
1719
|
+
var a = _a[0];
|
|
1720
|
+
return a;
|
|
1721
|
+
});
|
|
1722
|
+
var scenarioWithLowestBalances = firstCoinBalanceForEachScenario.indexOf(Math.min.apply(Math, firstCoinBalanceForEachScenario));
|
|
1723
|
+
return balancesAmountsForEachScenario[scenarioWithLowestBalances].map(String);
|
|
1724
|
+
};
|
|
1284
1725
|
this._calcLpTokenAmount = function (_amounts, isDeposit) {
|
|
1285
1726
|
if (isDeposit === void 0) { isDeposit = true; }
|
|
1286
1727
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1287
1728
|
return __generator(this, function (_a) {
|
|
1288
1729
|
switch (_a.label) {
|
|
1289
|
-
case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.
|
|
1730
|
+
case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1290
1731
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1291
1732
|
}
|
|
1292
1733
|
});
|
|
@@ -1301,9 +1742,9 @@ var Pool = /** @class */ (function () {
|
|
|
1301
1742
|
case 0:
|
|
1302
1743
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
1303
1744
|
if (!this.isFactory) return [3 /*break*/, 2];
|
|
1304
|
-
return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.
|
|
1745
|
+
return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1305
1746
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1306
|
-
case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.
|
|
1747
|
+
case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1307
1748
|
case 3: return [2 /*return*/, _a.sent()];
|
|
1308
1749
|
}
|
|
1309
1750
|
});
|
|
@@ -1321,7 +1762,7 @@ var Pool = /** @class */ (function () {
|
|
|
1321
1762
|
_wrapped_amounts = _underlying_amounts.map(function (amount, i) {
|
|
1322
1763
|
return amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates[i]);
|
|
1323
1764
|
});
|
|
1324
|
-
return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_wrapped_amounts, isDeposit, curve_1.curve.
|
|
1765
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_wrapped_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1325
1766
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1326
1767
|
}
|
|
1327
1768
|
});
|
|
@@ -1345,7 +1786,7 @@ var Pool = /** @class */ (function () {
|
|
|
1345
1786
|
ethIndex = (0, utils_1.getEthIndex)(this.coinAddresses);
|
|
1346
1787
|
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
1347
1788
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1348
|
-
return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.
|
|
1789
|
+
return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1349
1790
|
case 4:
|
|
1350
1791
|
gas = _a.sent();
|
|
1351
1792
|
if (estimateGas) {
|
|
@@ -1376,7 +1817,7 @@ var Pool = /** @class */ (function () {
|
|
|
1376
1817
|
ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
|
|
1377
1818
|
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
1378
1819
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
1379
|
-
return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.
|
|
1820
|
+
return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1380
1821
|
case 4:
|
|
1381
1822
|
gas = _a.sent();
|
|
1382
1823
|
if (estimateGas) {
|
|
@@ -1408,7 +1849,7 @@ var Pool = /** @class */ (function () {
|
|
|
1408
1849
|
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
1409
1850
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
1410
1851
|
if (!this.isFactory) return [3 /*break*/, 6];
|
|
1411
|
-
return [4 /*yield*/, contract.estimateGas.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.
|
|
1852
|
+
return [4 /*yield*/, contract.estimateGas.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1412
1853
|
case 4:
|
|
1413
1854
|
gas_1 = _a.sent();
|
|
1414
1855
|
if (estimateGas) {
|
|
@@ -1417,7 +1858,7 @@ var Pool = /** @class */ (function () {
|
|
|
1417
1858
|
gasLimit_1 = gas_1.mul(130).div(100);
|
|
1418
1859
|
return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_1, value: value }))];
|
|
1419
1860
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
1420
|
-
case 6: return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.
|
|
1861
|
+
case 6: return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1421
1862
|
case 7:
|
|
1422
1863
|
gas = _a.sent();
|
|
1423
1864
|
if (estimateGas) {
|
|
@@ -1435,71 +1876,71 @@ var Pool = /** @class */ (function () {
|
|
|
1435
1876
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
1436
1877
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1437
1878
|
var coinAddresses, _minMintAmount, _a, contract, ethIndex, value, gas, gasLimit;
|
|
1438
|
-
return __generator(this, function (
|
|
1439
|
-
switch (
|
|
1879
|
+
return __generator(this, function (_c) {
|
|
1880
|
+
switch (_c.label) {
|
|
1440
1881
|
case 0:
|
|
1441
1882
|
coinAddresses = useUnderlying ? this.underlyingCoinAddresses : this.coinAddresses;
|
|
1442
1883
|
if (!!estimateGas) return [3 /*break*/, 2];
|
|
1443
1884
|
return [4 /*yield*/, (0, utils_1._ensureAllowance)(coinAddresses, _amounts, this.swap)];
|
|
1444
1885
|
case 1:
|
|
1445
|
-
|
|
1446
|
-
|
|
1886
|
+
_c.sent();
|
|
1887
|
+
_c.label = 2;
|
|
1447
1888
|
case 2:
|
|
1448
1889
|
if (!useUnderlying) return [3 /*break*/, 4];
|
|
1449
1890
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts)];
|
|
1450
1891
|
case 3:
|
|
1451
|
-
_a =
|
|
1892
|
+
_a = _c.sent();
|
|
1452
1893
|
return [3 /*break*/, 6];
|
|
1453
1894
|
case 4: return [4 /*yield*/, this._calcLpTokenAmount(_amounts)];
|
|
1454
1895
|
case 5:
|
|
1455
|
-
_a =
|
|
1456
|
-
|
|
1896
|
+
_a = _c.sent();
|
|
1897
|
+
_c.label = 6;
|
|
1457
1898
|
case 6:
|
|
1458
1899
|
_minMintAmount = _a;
|
|
1459
1900
|
_minMintAmount = _minMintAmount.mul(99).div(100);
|
|
1460
1901
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1461
1902
|
ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
|
|
1462
1903
|
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
1463
|
-
return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, useUnderlying, __assign(__assign({}, curve_1.curve.
|
|
1904
|
+
return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, useUnderlying, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1464
1905
|
case 7:
|
|
1465
|
-
gas =
|
|
1906
|
+
gas = _c.sent();
|
|
1466
1907
|
if (estimateGas) {
|
|
1467
1908
|
return [2 /*return*/, gas.toNumber()];
|
|
1468
1909
|
}
|
|
1469
1910
|
gasLimit = gas.mul(130).div(100);
|
|
1470
1911
|
return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
|
|
1471
|
-
case 8: return [2 /*return*/, (
|
|
1912
|
+
case 8: return [2 /*return*/, (_c.sent()).hash];
|
|
1472
1913
|
}
|
|
1473
1914
|
});
|
|
1474
1915
|
});
|
|
1475
1916
|
};
|
|
1476
1917
|
this._calcExpectedAmounts = function (_lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1477
|
-
var coinBalancesBN, i, _balance, totalSupplyBN, _a, expectedAmountsBN,
|
|
1918
|
+
var coinBalancesBN, i, _balance, totalSupplyBN, _a, expectedAmountsBN, _c, coinBalancesBN_1, coinBalance;
|
|
1478
1919
|
var _this = this;
|
|
1479
|
-
return __generator(this, function (
|
|
1480
|
-
switch (
|
|
1920
|
+
return __generator(this, function (_d) {
|
|
1921
|
+
switch (_d.label) {
|
|
1481
1922
|
case 0:
|
|
1482
1923
|
coinBalancesBN = [];
|
|
1483
1924
|
i = 0;
|
|
1484
|
-
|
|
1925
|
+
_d.label = 1;
|
|
1485
1926
|
case 1:
|
|
1486
1927
|
if (!(i < this.coinAddresses.length)) return [3 /*break*/, 4];
|
|
1487
|
-
return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.balances(i, curve_1.curve.
|
|
1928
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.balances(i, curve_1.curve.constantOptions)];
|
|
1488
1929
|
case 2:
|
|
1489
|
-
_balance =
|
|
1930
|
+
_balance = _d.sent();
|
|
1490
1931
|
coinBalancesBN.push((0, utils_1.toBN)(_balance, this.decimals[i]));
|
|
1491
|
-
|
|
1932
|
+
_d.label = 3;
|
|
1492
1933
|
case 3:
|
|
1493
1934
|
i++;
|
|
1494
1935
|
return [3 /*break*/, 1];
|
|
1495
1936
|
case 4:
|
|
1496
1937
|
_a = utils_1.toBN;
|
|
1497
|
-
return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply(curve_1.curve.
|
|
1938
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply(curve_1.curve.constantOptions)];
|
|
1498
1939
|
case 5:
|
|
1499
|
-
totalSupplyBN = _a.apply(void 0, [
|
|
1940
|
+
totalSupplyBN = _a.apply(void 0, [_d.sent()]);
|
|
1500
1941
|
expectedAmountsBN = [];
|
|
1501
|
-
for (
|
|
1502
|
-
coinBalance = coinBalancesBN_1[
|
|
1942
|
+
for (_c = 0, coinBalancesBN_1 = coinBalancesBN; _c < coinBalancesBN_1.length; _c++) {
|
|
1943
|
+
coinBalance = coinBalancesBN_1[_c];
|
|
1503
1944
|
expectedAmountsBN.push(coinBalance.times((0, utils_1.toBN)(_lpTokenAmount)).div(totalSupplyBN));
|
|
1504
1945
|
}
|
|
1505
1946
|
return [2 /*return*/, expectedAmountsBN.map(function (amount, i) { return (0, utils_1.fromBN)(amount, _this.decimals[i]); })];
|
|
@@ -1571,7 +2012,7 @@ var Pool = /** @class */ (function () {
|
|
|
1571
2012
|
case 1:
|
|
1572
2013
|
_minAmounts = _a.sent();
|
|
1573
2014
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1574
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.
|
|
2015
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
|
|
1575
2016
|
case 2:
|
|
1576
2017
|
gas = _a.sent();
|
|
1577
2018
|
if (estimateGas) {
|
|
@@ -1600,7 +2041,7 @@ var Pool = /** @class */ (function () {
|
|
|
1600
2041
|
case 3:
|
|
1601
2042
|
_minAmounts = _a.sent();
|
|
1602
2043
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
1603
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.
|
|
2044
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
|
|
1604
2045
|
case 4:
|
|
1605
2046
|
gas = _a.sent();
|
|
1606
2047
|
if (estimateGas) {
|
|
@@ -1630,7 +2071,7 @@ var Pool = /** @class */ (function () {
|
|
|
1630
2071
|
_minAmounts = _a.sent();
|
|
1631
2072
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
1632
2073
|
if (!this.isFactory) return [3 /*break*/, 6];
|
|
1633
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, curve_1.curve.
|
|
2074
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
|
|
1634
2075
|
case 4:
|
|
1635
2076
|
gas_2 = _a.sent();
|
|
1636
2077
|
if (estimateGas) {
|
|
@@ -1639,7 +2080,7 @@ var Pool = /** @class */ (function () {
|
|
|
1639
2080
|
gasLimit_2 = gas_2.mul(130).div(100);
|
|
1640
2081
|
return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_2 }))];
|
|
1641
2082
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
1642
|
-
case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.
|
|
2083
|
+
case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
|
|
1643
2084
|
case 7:
|
|
1644
2085
|
gas = _a.sent();
|
|
1645
2086
|
if (estimateGas) {
|
|
@@ -1657,30 +2098,30 @@ var Pool = /** @class */ (function () {
|
|
|
1657
2098
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
1658
2099
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1659
2100
|
var _minAmounts, _a, contract, gas, gasLimit;
|
|
1660
|
-
return __generator(this, function (
|
|
1661
|
-
switch (
|
|
2101
|
+
return __generator(this, function (_c) {
|
|
2102
|
+
switch (_c.label) {
|
|
1662
2103
|
case 0:
|
|
1663
2104
|
if (!useUnderlying) return [3 /*break*/, 2];
|
|
1664
2105
|
return [4 /*yield*/, this._calcMinUnderlyingAmounts(_lpTokenAmount)];
|
|
1665
2106
|
case 1:
|
|
1666
|
-
_a =
|
|
2107
|
+
_a = _c.sent();
|
|
1667
2108
|
return [3 /*break*/, 4];
|
|
1668
2109
|
case 2: return [4 /*yield*/, this._calcMinAmounts(_lpTokenAmount)];
|
|
1669
2110
|
case 3:
|
|
1670
|
-
_a =
|
|
1671
|
-
|
|
2111
|
+
_a = _c.sent();
|
|
2112
|
+
_c.label = 4;
|
|
1672
2113
|
case 4:
|
|
1673
2114
|
_minAmounts = _a;
|
|
1674
2115
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1675
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, useUnderlying, curve_1.curve.
|
|
2116
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, useUnderlying, curve_1.curve.constantOptions)];
|
|
1676
2117
|
case 5:
|
|
1677
|
-
gas =
|
|
2118
|
+
gas = _c.sent();
|
|
1678
2119
|
if (estimateGas) {
|
|
1679
2120
|
return [2 /*return*/, gas.toNumber()];
|
|
1680
2121
|
}
|
|
1681
2122
|
gasLimit = gas.mul(130).div(100);
|
|
1682
2123
|
return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1683
|
-
case 6: return [2 /*return*/, (
|
|
2124
|
+
case 6: return [2 /*return*/, (_c.sent()).hash];
|
|
1684
2125
|
}
|
|
1685
2126
|
});
|
|
1686
2127
|
});
|
|
@@ -1695,7 +2136,7 @@ var Pool = /** @class */ (function () {
|
|
|
1695
2136
|
case 1:
|
|
1696
2137
|
_maxBurnAmount = (_a.sent()).mul(101).div(100);
|
|
1697
2138
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1698
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.
|
|
2139
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
|
|
1699
2140
|
case 2:
|
|
1700
2141
|
gas = _a.sent();
|
|
1701
2142
|
if (estimateGas) {
|
|
@@ -1724,7 +2165,7 @@ var Pool = /** @class */ (function () {
|
|
|
1724
2165
|
_a.label = 3;
|
|
1725
2166
|
case 3:
|
|
1726
2167
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
1727
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.
|
|
2168
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
|
|
1728
2169
|
case 4:
|
|
1729
2170
|
gas = _a.sent();
|
|
1730
2171
|
if (estimateGas) {
|
|
@@ -1754,7 +2195,7 @@ var Pool = /** @class */ (function () {
|
|
|
1754
2195
|
case 3:
|
|
1755
2196
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
1756
2197
|
if (!this.isFactory) return [3 /*break*/, 6];
|
|
1757
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, curve_1.curve.
|
|
2198
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
|
|
1758
2199
|
case 4:
|
|
1759
2200
|
gas_3 = _a.sent();
|
|
1760
2201
|
if (estimateGas) {
|
|
@@ -1763,7 +2204,7 @@ var Pool = /** @class */ (function () {
|
|
|
1763
2204
|
gasLimit_3 = gas_3.mul(130).div(100);
|
|
1764
2205
|
return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_3 }))];
|
|
1765
2206
|
case 5: return [2 /*return*/, (_a.sent())];
|
|
1766
|
-
case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.
|
|
2207
|
+
case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
|
|
1767
2208
|
case 7:
|
|
1768
2209
|
gas = _a.sent();
|
|
1769
2210
|
if (estimateGas) {
|
|
@@ -1781,31 +2222,31 @@ var Pool = /** @class */ (function () {
|
|
|
1781
2222
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
1782
2223
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1783
2224
|
var _maxBurnAmount, _a, contract, gas, gasLimit;
|
|
1784
|
-
return __generator(this, function (
|
|
1785
|
-
switch (
|
|
2225
|
+
return __generator(this, function (_c) {
|
|
2226
|
+
switch (_c.label) {
|
|
1786
2227
|
case 0:
|
|
1787
2228
|
if (!useUnderlying) return [3 /*break*/, 2];
|
|
1788
2229
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
|
|
1789
2230
|
case 1:
|
|
1790
|
-
_a =
|
|
2231
|
+
_a = _c.sent();
|
|
1791
2232
|
return [3 /*break*/, 4];
|
|
1792
2233
|
case 2: return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
|
|
1793
2234
|
case 3:
|
|
1794
|
-
_a =
|
|
1795
|
-
|
|
2235
|
+
_a = _c.sent();
|
|
2236
|
+
_c.label = 4;
|
|
1796
2237
|
case 4:
|
|
1797
2238
|
_maxBurnAmount = _a;
|
|
1798
2239
|
_maxBurnAmount = _maxBurnAmount.mul(101).div(100);
|
|
1799
2240
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1800
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, useUnderlying, curve_1.curve.
|
|
2241
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, useUnderlying, curve_1.curve.constantOptions)];
|
|
1801
2242
|
case 5:
|
|
1802
|
-
gas =
|
|
2243
|
+
gas = _c.sent();
|
|
1803
2244
|
if (estimateGas) {
|
|
1804
2245
|
return [2 /*return*/, gas.toNumber()];
|
|
1805
2246
|
}
|
|
1806
2247
|
gasLimit = gas.mul(130).div(100);
|
|
1807
2248
|
return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1808
|
-
case 6: return [2 /*return*/, (
|
|
2249
|
+
case 6: return [2 /*return*/, (_c.sent()).hash];
|
|
1809
2250
|
}
|
|
1810
2251
|
});
|
|
1811
2252
|
});
|
|
@@ -1813,7 +2254,7 @@ var Pool = /** @class */ (function () {
|
|
|
1813
2254
|
this._calcWithdrawOneCoinSwap = function (_lpTokenAmount, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
1814
2255
|
return __generator(this, function (_a) {
|
|
1815
2256
|
switch (_a.label) {
|
|
1816
|
-
case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.
|
|
2257
|
+
case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.constantOptions)];
|
|
1817
2258
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1818
2259
|
}
|
|
1819
2260
|
});
|
|
@@ -1825,9 +2266,9 @@ var Pool = /** @class */ (function () {
|
|
|
1825
2266
|
case 0:
|
|
1826
2267
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
1827
2268
|
if (!this.isFactory) return [3 /*break*/, 2];
|
|
1828
|
-
return [4 /*yield*/, contract.calc_withdraw_one_coin(this.swap, _lpTokenAmount, i, curve_1.curve.
|
|
2269
|
+
return [4 /*yield*/, contract.calc_withdraw_one_coin(this.swap, _lpTokenAmount, i, curve_1.curve.constantOptions)];
|
|
1829
2270
|
case 1: return [2 /*return*/, (_a.sent())];
|
|
1830
|
-
case 2: return [4 /*yield*/, contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.
|
|
2271
|
+
case 2: return [4 /*yield*/, contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.constantOptions)];
|
|
1831
2272
|
case 3: return [2 /*return*/, _a.sent()];
|
|
1832
2273
|
}
|
|
1833
2274
|
});
|
|
@@ -1837,7 +2278,7 @@ var Pool = /** @class */ (function () {
|
|
|
1837
2278
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1838
2279
|
return __generator(this, function (_a) {
|
|
1839
2280
|
switch (_a.label) {
|
|
1840
|
-
case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_withdraw_one_coin(_lpTokenAmount, i, useUnderlying, curve_1.curve.
|
|
2281
|
+
case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_withdraw_one_coin(_lpTokenAmount, i, useUnderlying, curve_1.curve.constantOptions)];
|
|
1841
2282
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1842
2283
|
}
|
|
1843
2284
|
});
|
|
@@ -1853,7 +2294,7 @@ var Pool = /** @class */ (function () {
|
|
|
1853
2294
|
case 1:
|
|
1854
2295
|
_minAmount = (_a.sent()).mul(99).div(100);
|
|
1855
2296
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1856
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.
|
|
2297
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
|
|
1857
2298
|
case 2:
|
|
1858
2299
|
gas = _a.sent();
|
|
1859
2300
|
if (estimateGas) {
|
|
@@ -1883,7 +2324,7 @@ var Pool = /** @class */ (function () {
|
|
|
1883
2324
|
_minAmount = (_a.sent()).mul(99).div(100);
|
|
1884
2325
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
1885
2326
|
if (!this.isFactory) return [3 /*break*/, 6];
|
|
1886
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, curve_1.curve.
|
|
2327
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
|
|
1887
2328
|
case 4:
|
|
1888
2329
|
gas_4 = _a.sent();
|
|
1889
2330
|
if (estimateGas) {
|
|
@@ -1892,7 +2333,7 @@ var Pool = /** @class */ (function () {
|
|
|
1892
2333
|
gasLimit_4 = gas_4.mul(130).div(100);
|
|
1893
2334
|
return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_4 }))];
|
|
1894
2335
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
1895
|
-
case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.
|
|
2336
|
+
case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
|
|
1896
2337
|
case 7:
|
|
1897
2338
|
gas = _a.sent();
|
|
1898
2339
|
if (estimateGas) {
|
|
@@ -1910,31 +2351,31 @@ var Pool = /** @class */ (function () {
|
|
|
1910
2351
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
1911
2352
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1912
2353
|
var _minAmount, _a, contract, gas, gasLimit;
|
|
1913
|
-
return __generator(this, function (
|
|
1914
|
-
switch (
|
|
2354
|
+
return __generator(this, function (_c) {
|
|
2355
|
+
switch (_c.label) {
|
|
1915
2356
|
case 0:
|
|
1916
2357
|
if (!(this.name === 'ib')) return [3 /*break*/, 2];
|
|
1917
2358
|
return [4 /*yield*/, this._calcWithdrawOneCoin(_lpTokenAmount, i, useUnderlying)];
|
|
1918
2359
|
case 1:
|
|
1919
|
-
_a =
|
|
2360
|
+
_a = _c.sent();
|
|
1920
2361
|
return [3 /*break*/, 4];
|
|
1921
2362
|
case 2: return [4 /*yield*/, this._calcWithdrawOneCoinSwap(_lpTokenAmount, i)];
|
|
1922
2363
|
case 3:
|
|
1923
|
-
_a =
|
|
1924
|
-
|
|
2364
|
+
_a = _c.sent();
|
|
2365
|
+
_c.label = 4;
|
|
1925
2366
|
case 4:
|
|
1926
2367
|
_minAmount = _a;
|
|
1927
2368
|
_minAmount = _minAmount.mul(99).div(100);
|
|
1928
2369
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1929
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, useUnderlying, curve_1.curve.
|
|
2370
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, useUnderlying, curve_1.curve.constantOptions)];
|
|
1930
2371
|
case 5:
|
|
1931
|
-
gas =
|
|
2372
|
+
gas = _c.sent();
|
|
1932
2373
|
if (estimateGas) {
|
|
1933
2374
|
return [2 /*return*/, gas.toNumber()];
|
|
1934
2375
|
}
|
|
1935
2376
|
gasLimit = gas.mul(130).div(100);
|
|
1936
2377
|
return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1937
|
-
case 6: return [2 /*return*/, (
|
|
2378
|
+
case 6: return [2 /*return*/, (_c.sent()).hash];
|
|
1938
2379
|
}
|
|
1939
2380
|
});
|
|
1940
2381
|
});
|
|
@@ -1946,9 +2387,9 @@ var Pool = /** @class */ (function () {
|
|
|
1946
2387
|
case 0:
|
|
1947
2388
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1948
2389
|
if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
|
|
1949
|
-
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.
|
|
2390
|
+
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
|
|
1950
2391
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1951
|
-
case 2: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.
|
|
2392
|
+
case 2: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
|
|
1952
2393
|
case 3: return [2 /*return*/, _a.sent()];
|
|
1953
2394
|
}
|
|
1954
2395
|
});
|
|
@@ -1956,7 +2397,7 @@ var Pool = /** @class */ (function () {
|
|
|
1956
2397
|
this._getExchangeOutputWrapped = function (i, j, _amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1957
2398
|
return __generator(this, function (_a) {
|
|
1958
2399
|
switch (_a.label) {
|
|
1959
|
-
case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.get_dy(i, j, _amount, curve_1.curve.
|
|
2400
|
+
case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
|
|
1960
2401
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1961
2402
|
}
|
|
1962
2403
|
});
|
|
@@ -1978,16 +2419,27 @@ var Pool = /** @class */ (function () {
|
|
|
1978
2419
|
this.basePool = poolData.base_pool || '';
|
|
1979
2420
|
this.isFactory = poolData.is_factory || false;
|
|
1980
2421
|
this.estimateGas = {
|
|
2422
|
+
addLiquidityApprove: this.addLiquidityApproveEstimateGas,
|
|
1981
2423
|
addLiquidity: this.addLiquidityEstimateGas,
|
|
2424
|
+
addLiquidityWrappedApprove: this.addLiquidityWrappedApproveEstimateGas,
|
|
1982
2425
|
addLiquidityWrapped: this.addLiquidityWrappedEstimateGas,
|
|
2426
|
+
gaugeDepositApprove: this.gaugeDepositApproveEstimateGas,
|
|
2427
|
+
gaugeDeposit: this.gaugeDepositEstimateGas,
|
|
2428
|
+
gaugeWithdraw: this.gaugeWithdrawEstimateGas,
|
|
2429
|
+
removeLiquidityApprove: this.removeLiquidityApproveEstimateGas,
|
|
1983
2430
|
removeLiquidity: this.removeLiquidityEstimateGas,
|
|
1984
2431
|
removeLiquidityWrapped: this.removeLiquidityWrappedEstimateGas,
|
|
2432
|
+
removeLiquidityImbalanceApprove: this.removeLiquidityImbalanceApproveEstimateGas,
|
|
1985
2433
|
removeLiquidityImbalance: this.removeLiquidityImbalanceEstimateGas,
|
|
1986
2434
|
removeLiquidityImbalanceWrapped: this.removeLiquidityImbalanceWrappedEstimateGas,
|
|
2435
|
+
removeLiquidityOneCoinApprove: this.removeLiquidityOneCoinApproveEstimateGas,
|
|
1987
2436
|
removeLiquidityOneCoin: this.removeLiquidityOneCoinEstimateGas,
|
|
1988
2437
|
removeLiquidityOneCoinWrapped: this.removeLiquidityOneCoinWrappedEstimateGas,
|
|
2438
|
+
exchangeApprove: this.exchangeApproveEstimateGas,
|
|
1989
2439
|
exchange: this.exchangeEstimateGas,
|
|
2440
|
+
exchangeTricryptoApprove: this.exchangeTricryptoApproveEstimateGas,
|
|
1990
2441
|
exchangeTricrypto: this.exchangeTricryptoEstimateGas,
|
|
2442
|
+
exchangeWrappedApprove: this.exchangeWrappedApproveEstimateGas,
|
|
1991
2443
|
exchangeWrapped: this.exchangeWrappedEstimateGas,
|
|
1992
2444
|
};
|
|
1993
2445
|
if (this.isMeta) {
|
|
@@ -2003,37 +2455,37 @@ exports.Pool = Pool;
|
|
|
2003
2455
|
// --------- Exchange Using All Pools ---------
|
|
2004
2456
|
var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2005
2457
|
var tricryptoCoins, addressProviderContract, registryExchangeAddress, registryExchangeContract, _amount, _a, poolAddress, output;
|
|
2006
|
-
return __generator(this, function (
|
|
2007
|
-
switch (
|
|
2458
|
+
return __generator(this, function (_c) {
|
|
2459
|
+
switch (_c.label) {
|
|
2008
2460
|
case 0:
|
|
2009
2461
|
tricryptoCoins = [coins_1.COINS.usdt.toLowerCase(), coins_1.COINS.wbtc.toLowerCase(), coins_1.COINS.weth.toLowerCase()];
|
|
2010
2462
|
if (tricryptoCoins.includes(inputCoinAddress.toLowerCase()) && tricryptoCoins.includes(outputCoinAddress.toLowerCase())) {
|
|
2011
2463
|
throw new Error("This pair can't be exchanged");
|
|
2012
2464
|
}
|
|
2013
2465
|
addressProviderContract = curve_1.curve.contracts[curve_1.ALIASES.address_provider].contract;
|
|
2014
|
-
return [4 /*yield*/, addressProviderContract.get_address(2, curve_1.curve.
|
|
2466
|
+
return [4 /*yield*/, addressProviderContract.get_address(2, curve_1.curve.constantOptions)];
|
|
2015
2467
|
case 1:
|
|
2016
|
-
registryExchangeAddress =
|
|
2468
|
+
registryExchangeAddress = _c.sent();
|
|
2017
2469
|
registryExchangeContract = new ethers_1.ethers.Contract(registryExchangeAddress, registry_exchange_json_1.default, curve_1.curve.signer || curve_1.curve.provider);
|
|
2018
2470
|
_amount = ethers_1.ethers.utils.parseUnits(amount.toString(), inputCoinDecimals);
|
|
2019
|
-
return [4 /*yield*/, registryExchangeContract.get_best_rate(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.
|
|
2471
|
+
return [4 /*yield*/, registryExchangeContract.get_best_rate(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
|
|
2020
2472
|
case 2:
|
|
2021
|
-
_a =
|
|
2473
|
+
_a = _c.sent(), poolAddress = _a[0], output = _a[1];
|
|
2022
2474
|
return [2 /*return*/, { poolAddress: poolAddress, output: output }];
|
|
2023
2475
|
}
|
|
2024
2476
|
});
|
|
2025
2477
|
}); };
|
|
2026
2478
|
exports._getBestPoolAndOutput = _getBestPoolAndOutput;
|
|
2027
2479
|
var getBestPoolAndOutput = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2028
|
-
var _a, inputCoinAddress, outputCoinAddress,
|
|
2029
|
-
return __generator(this, function (
|
|
2030
|
-
switch (
|
|
2480
|
+
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, output;
|
|
2481
|
+
return __generator(this, function (_e) {
|
|
2482
|
+
switch (_e.label) {
|
|
2031
2483
|
case 0:
|
|
2032
2484
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2033
|
-
|
|
2485
|
+
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2034
2486
|
return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
|
|
2035
2487
|
case 1:
|
|
2036
|
-
|
|
2488
|
+
_d = _e.sent(), poolAddress = _d.poolAddress, _output = _d.output;
|
|
2037
2489
|
output = ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals);
|
|
2038
2490
|
return [2 /*return*/, { poolAddress: poolAddress, output: output }];
|
|
2039
2491
|
}
|
|
@@ -2052,35 +2504,35 @@ exports.exchangeExpected = exchangeExpected;
|
|
|
2052
2504
|
var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
2053
2505
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
2054
2506
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
2055
|
-
var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, addressProviderContract, registryAddress, registryContract, poolAddress, poolName,
|
|
2056
|
-
return __generator(this, function (
|
|
2057
|
-
switch (
|
|
2507
|
+
var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, addressProviderContract, registryAddress, registryContract, poolAddress, poolName, _c, _i, _j, is_underlying, i, j, pool;
|
|
2508
|
+
return __generator(this, function (_d) {
|
|
2509
|
+
switch (_d.label) {
|
|
2058
2510
|
case 0:
|
|
2059
2511
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2060
2512
|
inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
|
|
2061
2513
|
addressProviderContract = curve_1.curve.contracts[curve_1.ALIASES.address_provider].contract;
|
|
2062
2514
|
return [4 /*yield*/, addressProviderContract.get_registry()];
|
|
2063
2515
|
case 1:
|
|
2064
|
-
registryAddress =
|
|
2516
|
+
registryAddress = _d.sent();
|
|
2065
2517
|
registryContract = new ethers_1.ethers.Contract(registryAddress, registry_json_1.default, curve_1.curve.signer);
|
|
2066
2518
|
return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
|
|
2067
2519
|
case 2:
|
|
2068
|
-
poolAddress = (
|
|
2520
|
+
poolAddress = (_d.sent()).poolAddress;
|
|
2069
2521
|
if (poolAddress === "0x0000000000000000000000000000000000000000") {
|
|
2070
2522
|
throw new Error("This pair can't be exchanged");
|
|
2071
2523
|
}
|
|
2072
2524
|
poolName = (0, utils_1.getPoolNameBySwapAddress)(poolAddress);
|
|
2073
2525
|
return [4 /*yield*/, registryContract.get_coin_indices(poolAddress, inputCoinAddress, outputCoinAddress)];
|
|
2074
2526
|
case 3:
|
|
2075
|
-
|
|
2527
|
+
_c = _d.sent(), _i = _c[0], _j = _c[1], is_underlying = _c[2];
|
|
2076
2528
|
i = Number(_i.toString());
|
|
2077
2529
|
j = Number(_j.toString());
|
|
2078
2530
|
pool = new Pool(poolName);
|
|
2079
2531
|
if (!is_underlying) return [3 /*break*/, 5];
|
|
2080
2532
|
return [4 /*yield*/, pool.estimateGas.exchange(i, j, amount, maxSlippage)];
|
|
2081
|
-
case 4: return [2 /*return*/,
|
|
2533
|
+
case 4: return [2 /*return*/, _d.sent()];
|
|
2082
2534
|
case 5: return [4 /*yield*/, pool.estimateGas.exchangeWrapped(i, j, amount, maxSlippage)];
|
|
2083
|
-
case 6: return [2 /*return*/,
|
|
2535
|
+
case 6: return [2 /*return*/, _d.sent()];
|
|
2084
2536
|
}
|
|
2085
2537
|
});
|
|
2086
2538
|
});
|
|
@@ -2089,35 +2541,35 @@ exports.exchangeEstimateGas = exchangeEstimateGas;
|
|
|
2089
2541
|
var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
2090
2542
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
2091
2543
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
2092
|
-
var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, addressProviderContract, registryAddress, registryContract, poolAddress, poolName,
|
|
2093
|
-
return __generator(this, function (
|
|
2094
|
-
switch (
|
|
2544
|
+
var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, addressProviderContract, registryAddress, registryContract, poolAddress, poolName, _c, _i, _j, is_underlying, i, j, pool;
|
|
2545
|
+
return __generator(this, function (_d) {
|
|
2546
|
+
switch (_d.label) {
|
|
2095
2547
|
case 0:
|
|
2096
2548
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2097
2549
|
inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
|
|
2098
2550
|
addressProviderContract = curve_1.curve.contracts[curve_1.ALIASES.address_provider].contract;
|
|
2099
2551
|
return [4 /*yield*/, addressProviderContract.get_registry()];
|
|
2100
2552
|
case 1:
|
|
2101
|
-
registryAddress =
|
|
2553
|
+
registryAddress = _d.sent();
|
|
2102
2554
|
registryContract = new ethers_1.ethers.Contract(registryAddress, registry_json_1.default, curve_1.curve.signer);
|
|
2103
2555
|
return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
|
|
2104
2556
|
case 2:
|
|
2105
|
-
poolAddress = (
|
|
2557
|
+
poolAddress = (_d.sent()).poolAddress;
|
|
2106
2558
|
if (poolAddress === "0x0000000000000000000000000000000000000000") {
|
|
2107
2559
|
throw new Error("This pair can't be exchanged");
|
|
2108
2560
|
}
|
|
2109
2561
|
poolName = (0, utils_1.getPoolNameBySwapAddress)(poolAddress);
|
|
2110
2562
|
return [4 /*yield*/, registryContract.get_coin_indices(poolAddress, inputCoinAddress, outputCoinAddress)];
|
|
2111
2563
|
case 3:
|
|
2112
|
-
|
|
2564
|
+
_c = _d.sent(), _i = _c[0], _j = _c[1], is_underlying = _c[2];
|
|
2113
2565
|
i = Number(_i.toString());
|
|
2114
2566
|
j = Number(_j.toString());
|
|
2115
2567
|
pool = new Pool(poolName);
|
|
2116
2568
|
if (!is_underlying) return [3 /*break*/, 5];
|
|
2117
2569
|
return [4 /*yield*/, pool.exchange(i, j, amount, maxSlippage)];
|
|
2118
|
-
case 4: return [2 /*return*/,
|
|
2570
|
+
case 4: return [2 /*return*/, _d.sent()];
|
|
2119
2571
|
case 5: return [4 /*yield*/, pool.exchangeWrapped(i, j, amount, maxSlippage)];
|
|
2120
|
-
case 6: return [2 /*return*/,
|
|
2572
|
+
case 6: return [2 /*return*/, _d.sent()];
|
|
2121
2573
|
}
|
|
2122
2574
|
});
|
|
2123
2575
|
});
|
|
@@ -2126,14 +2578,14 @@ exports.exchange = exchange;
|
|
|
2126
2578
|
// --------- Cross-Asset Exchange ---------
|
|
2127
2579
|
var crossAssetExchangeAvailable = function (inputCoin, outputCoin) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2128
2580
|
var _a, inputCoinAddress, outputCoinAddress, routerContract;
|
|
2129
|
-
return __generator(this, function (
|
|
2130
|
-
switch (
|
|
2581
|
+
return __generator(this, function (_c) {
|
|
2582
|
+
switch (_c.label) {
|
|
2131
2583
|
case 0:
|
|
2132
2584
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2133
2585
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|
|
2134
2586
|
case 1:
|
|
2135
|
-
routerContract =
|
|
2136
|
-
return [2 /*return*/, routerContract.can_route(inputCoinAddress, outputCoinAddress, curve_1.curve.
|
|
2587
|
+
routerContract = _c.sent();
|
|
2588
|
+
return [2 /*return*/, routerContract.can_route(inputCoinAddress, outputCoinAddress, curve_1.curve.constantOptions)];
|
|
2137
2589
|
}
|
|
2138
2590
|
});
|
|
2139
2591
|
}); };
|
|
@@ -2150,24 +2602,24 @@ var _getSmallAmountForCoin = function (coinAddress) {
|
|
|
2150
2602
|
};
|
|
2151
2603
|
exports._getSmallAmountForCoin = _getSmallAmountForCoin;
|
|
2152
2604
|
var _crossAssetExchangeInfo = function (inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2153
|
-
var routerContract, _amount, amountBN, _a, route, indices, _expected, expectedBN, exchangeRateBN, _smallAmount, smallAmountBN,
|
|
2154
|
-
return __generator(this, function (
|
|
2155
|
-
switch (
|
|
2605
|
+
var routerContract, _amount, amountBN, _a, route, indices, _expected, expectedBN, exchangeRateBN, _smallAmount, smallAmountBN, _c, _expectedSmall, expectedSmallBN, exchangeSmallRateBN, slippage;
|
|
2606
|
+
return __generator(this, function (_d) {
|
|
2607
|
+
switch (_d.label) {
|
|
2156
2608
|
case 0: return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|
|
2157
2609
|
case 1:
|
|
2158
|
-
routerContract =
|
|
2610
|
+
routerContract = _d.sent();
|
|
2159
2611
|
_amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
|
|
2160
2612
|
amountBN = (0, utils_1.toBN)(_amount, inputCoinDecimals);
|
|
2161
|
-
return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.
|
|
2613
|
+
return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
|
|
2162
2614
|
case 2:
|
|
2163
|
-
_a =
|
|
2615
|
+
_a = _d.sent(), route = _a[0], indices = _a[1], _expected = _a[2];
|
|
2164
2616
|
expectedBN = (0, utils_1.toBN)(_expected, outputCoinDecimals);
|
|
2165
2617
|
exchangeRateBN = expectedBN.div(amountBN);
|
|
2166
2618
|
_smallAmount = ethers_1.ethers.utils.parseUnits((0, exports._getSmallAmountForCoin)(inputCoinAddress), inputCoinDecimals);
|
|
2167
2619
|
smallAmountBN = (0, utils_1.toBN)(_smallAmount, inputCoinDecimals);
|
|
2168
|
-
return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _smallAmount, curve_1.curve.
|
|
2620
|
+
return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _smallAmount, curve_1.curve.constantOptions)];
|
|
2169
2621
|
case 3:
|
|
2170
|
-
|
|
2622
|
+
_c = _d.sent(), _expectedSmall = _c[2];
|
|
2171
2623
|
expectedSmallBN = (0, utils_1.toBN)(_expectedSmall, outputCoinDecimals);
|
|
2172
2624
|
exchangeSmallRateBN = expectedSmallBN.div(smallAmountBN);
|
|
2173
2625
|
slippage = 1 - exchangeRateBN.div(exchangeSmallRateBN).toNumber();
|
|
@@ -2177,15 +2629,15 @@ var _crossAssetExchangeInfo = function (inputCoinAddress, outputCoinAddress, inp
|
|
|
2177
2629
|
}); };
|
|
2178
2630
|
exports._crossAssetExchangeInfo = _crossAssetExchangeInfo;
|
|
2179
2631
|
var crossAssetExchangeOutputAndSlippage = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2180
|
-
var _a, inputCoinAddress, outputCoinAddress,
|
|
2181
|
-
return __generator(this, function (
|
|
2182
|
-
switch (
|
|
2632
|
+
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, _expected, slippage, output;
|
|
2633
|
+
return __generator(this, function (_e) {
|
|
2634
|
+
switch (_e.label) {
|
|
2183
2635
|
case 0:
|
|
2184
2636
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2185
|
-
|
|
2637
|
+
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2186
2638
|
return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
|
|
2187
2639
|
case 1:
|
|
2188
|
-
|
|
2640
|
+
_d = _e.sent(), _expected = _d._expected, slippage = _d.slippage;
|
|
2189
2641
|
output = ethers_1.ethers.utils.formatUnits(_expected, outputCoinDecimals);
|
|
2190
2642
|
return [2 /*return*/, { output: output, slippage: slippage }];
|
|
2191
2643
|
}
|
|
@@ -2193,19 +2645,19 @@ var crossAssetExchangeOutputAndSlippage = function (inputCoin, outputCoin, amoun
|
|
|
2193
2645
|
}); };
|
|
2194
2646
|
exports.crossAssetExchangeOutputAndSlippage = crossAssetExchangeOutputAndSlippage;
|
|
2195
2647
|
var crossAssetExchangeExpected = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2196
|
-
var _a, inputCoinAddress, outputCoinAddress,
|
|
2197
|
-
return __generator(this, function (
|
|
2198
|
-
switch (
|
|
2648
|
+
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, routerContract, _amount, _d, _expected;
|
|
2649
|
+
return __generator(this, function (_e) {
|
|
2650
|
+
switch (_e.label) {
|
|
2199
2651
|
case 0:
|
|
2200
2652
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2201
|
-
|
|
2653
|
+
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2202
2654
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|
|
2203
2655
|
case 1:
|
|
2204
|
-
routerContract =
|
|
2656
|
+
routerContract = _e.sent();
|
|
2205
2657
|
_amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
|
|
2206
|
-
return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.
|
|
2658
|
+
return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
|
|
2207
2659
|
case 2:
|
|
2208
|
-
|
|
2660
|
+
_d = _e.sent(), _expected = _d[2];
|
|
2209
2661
|
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, outputCoinDecimals)];
|
|
2210
2662
|
}
|
|
2211
2663
|
});
|
|
@@ -2214,38 +2666,38 @@ exports.crossAssetExchangeExpected = crossAssetExchangeExpected;
|
|
|
2214
2666
|
var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
2215
2667
|
if (maxSlippage === void 0) { maxSlippage = 0.02; }
|
|
2216
2668
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
2217
|
-
var _a, inputCoinAddress, outputCoinAddress, inputCoinBalance,
|
|
2218
|
-
return __generator(this, function (
|
|
2219
|
-
switch (
|
|
2669
|
+
var _a, inputCoinAddress, outputCoinAddress, inputCoinBalance, _c, inputCoinDecimals, outputCoinDecimals, _amount, _d, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract;
|
|
2670
|
+
return __generator(this, function (_e) {
|
|
2671
|
+
switch (_e.label) {
|
|
2220
2672
|
case 0: return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
|
|
2221
2673
|
case 1:
|
|
2222
|
-
if (!(
|
|
2674
|
+
if (!(_e.sent()))
|
|
2223
2675
|
throw Error("Such exchange is not available");
|
|
2224
2676
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2225
2677
|
return [4 /*yield*/, (0, utils_1._getBalances)([inputCoinAddress], [curve_1.curve.signerAddress])];
|
|
2226
2678
|
case 2:
|
|
2227
|
-
inputCoinBalance = (
|
|
2679
|
+
inputCoinBalance = (_e.sent())[curve_1.curve.signerAddress];
|
|
2228
2680
|
if (Number(inputCoinBalance) < Number(amount)) {
|
|
2229
2681
|
throw Error("Not enough " + inputCoin + ". Actual: " + inputCoinBalance + ", required: " + amount);
|
|
2230
2682
|
}
|
|
2231
2683
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoinAddress], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.router)];
|
|
2232
2684
|
case 3:
|
|
2233
|
-
if (!(
|
|
2685
|
+
if (!(_e.sent())) {
|
|
2234
2686
|
throw Error("Token allowance is needed to estimate gas");
|
|
2235
2687
|
}
|
|
2236
|
-
|
|
2688
|
+
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2237
2689
|
_amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
|
|
2238
2690
|
return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
|
|
2239
2691
|
case 4:
|
|
2240
|
-
|
|
2692
|
+
_d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
|
|
2241
2693
|
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times((1 - maxSlippage));
|
|
2242
2694
|
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
2243
2695
|
value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
|
|
2244
2696
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|
|
2245
2697
|
case 5:
|
|
2246
|
-
routerContract =
|
|
2247
|
-
return [4 /*yield*/, routerContract.estimateGas.exchange(_amount, route, indices, _minRecvAmount, __assign(__assign({}, curve_1.curve.
|
|
2248
|
-
case 6: return [2 /*return*/, (
|
|
2698
|
+
routerContract = _e.sent();
|
|
2699
|
+
return [4 /*yield*/, routerContract.estimateGas.exchange(_amount, route, indices, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2700
|
+
case 6: return [2 /*return*/, (_e.sent()).toNumber()];
|
|
2249
2701
|
}
|
|
2250
2702
|
});
|
|
2251
2703
|
});
|
|
@@ -2254,36 +2706,36 @@ exports.crossAssetExchangeEstimateGas = crossAssetExchangeEstimateGas;
|
|
|
2254
2706
|
var crossAssetExchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
2255
2707
|
if (maxSlippage === void 0) { maxSlippage = 0.02; }
|
|
2256
2708
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
2257
|
-
var _a, inputCoinAddress, outputCoinAddress,
|
|
2258
|
-
return __generator(this, function (
|
|
2259
|
-
switch (
|
|
2709
|
+
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _amount, _d, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract, gasLimit;
|
|
2710
|
+
return __generator(this, function (_e) {
|
|
2711
|
+
switch (_e.label) {
|
|
2260
2712
|
case 0: return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
|
|
2261
2713
|
case 1:
|
|
2262
|
-
if (!(
|
|
2714
|
+
if (!(_e.sent()))
|
|
2263
2715
|
throw Error("Such exchange is not available");
|
|
2264
2716
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2265
|
-
|
|
2717
|
+
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2266
2718
|
_amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
|
|
2267
2719
|
return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
|
|
2268
2720
|
case 2:
|
|
2269
|
-
|
|
2721
|
+
_d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
|
|
2270
2722
|
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times((1 - maxSlippage));
|
|
2271
2723
|
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
2272
2724
|
value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
|
|
2273
2725
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|
|
2274
2726
|
case 3:
|
|
2275
|
-
routerContract =
|
|
2727
|
+
routerContract = _e.sent();
|
|
2276
2728
|
return [4 /*yield*/, (0, utils_1._ensureAllowance)([inputCoinAddress], [_amount], curve_1.ALIASES.router)];
|
|
2277
2729
|
case 4:
|
|
2278
|
-
|
|
2730
|
+
_e.sent();
|
|
2279
2731
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
2280
2732
|
case 5:
|
|
2281
|
-
|
|
2282
|
-
return [4 /*yield*/, routerContract.estimateGas.exchange(_amount, route, indices, _minRecvAmount, __assign(__assign({}, curve_1.curve.
|
|
2733
|
+
_e.sent();
|
|
2734
|
+
return [4 /*yield*/, routerContract.estimateGas.exchange(_amount, route, indices, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2283
2735
|
case 6:
|
|
2284
|
-
gasLimit = (
|
|
2736
|
+
gasLimit = (_e.sent()).mul(130).div(100);
|
|
2285
2737
|
return [4 /*yield*/, routerContract.exchange(_amount, route, indices, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
2286
|
-
case 7: return [2 /*return*/, (
|
|
2738
|
+
case 7: return [2 /*return*/, (_e.sent()).hash];
|
|
2287
2739
|
}
|
|
2288
2740
|
});
|
|
2289
2741
|
});
|