@curvefi/api 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/pools.js CHANGED
@@ -46,10 +46,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
50
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
51
- to[j] = from[i];
52
- return to;
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
53
57
  };
54
58
  var __importDefault = (this && this.__importDefault) || function (mod) {
55
59
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -122,6 +126,17 @@ var Pool = /** @class */ (function () {
122
126
  });
123
127
  });
124
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
+ }); };
125
140
  this.addLiquidityExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
126
141
  return __generator(this, function (_a) {
127
142
  switch (_a.label) {
@@ -130,27 +145,60 @@ var Pool = /** @class */ (function () {
130
145
  }
131
146
  });
132
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
+ }); };
133
181
  this.addLiquidityEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
134
- var balances, _a, _b, i, _amounts;
182
+ var balances, _a, _c, i, _amounts;
135
183
  var _this = this;
136
- return __generator(this, function (_c) {
137
- switch (_c.label) {
184
+ return __generator(this, function (_d) {
185
+ switch (_d.label) {
138
186
  case 0:
139
187
  if (amounts.length !== this.underlyingCoinAddresses.length) {
140
188
  throw Error(this.name + " pool has " + this.underlyingCoinAddresses.length + " coins (amounts provided for " + amounts.length + ")");
141
189
  }
142
- _b = (_a = Object).values;
190
+ _c = (_a = Object).values;
143
191
  return [4 /*yield*/, this.underlyingCoinBalances()];
144
192
  case 1:
145
- balances = _b.apply(_a, [_c.sent()]);
193
+ balances = _c.apply(_a, [_d.sent()]);
146
194
  for (i = 0; i < balances.length; i++) {
147
195
  if (Number(balances[i]) < Number(amounts[i])) {
148
196
  throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + balances[i] + ", required: " + amounts[i]);
149
197
  }
150
198
  }
151
- return [4 /*yield*/, utils_1.hasAllowance(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.swap)];
199
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.swap)];
152
200
  case 2:
153
- if (!(_c.sent())) {
201
+ if (!(_d.sent())) {
154
202
  throw Error("Token allowance is needed to estimate gas");
155
203
  }
156
204
  _amounts = amounts.map(function (amount, i) {
@@ -158,19 +206,60 @@ var Pool = /** @class */ (function () {
158
206
  });
159
207
  if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 4];
160
208
  return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
161
- case 3: return [2 /*return*/, _c.sent()];
209
+ case 3: return [2 /*return*/, _d.sent()];
162
210
  case 4:
163
211
  if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 6];
164
212
  return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
165
- case 5: return [2 /*return*/, _c.sent()];
213
+ case 5: return [2 /*return*/, _d.sent()];
166
214
  case 6:
167
215
  if (!this.isMeta) return [3 /*break*/, 8];
168
216
  return [4 /*yield*/, this._addLiquidityMetaZap(_amounts, true)];
169
- case 7: return [2 /*return*/, _c.sent()];
217
+ case 7: return [2 /*return*/, _d.sent()];
170
218
  case 8: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
171
219
  case 9:
172
220
  // Plain pools
173
- return [2 /*return*/, _c.sent()];
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)];
174
263
  }
175
264
  });
176
265
  }); };
@@ -186,24 +275,46 @@ var Pool = /** @class */ (function () {
186
275
  _amounts = amounts.map(function (amount, i) {
187
276
  return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
188
277
  });
189
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 2];
278
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
279
+ case 1:
280
+ _a.sent();
281
+ if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
190
282
  return [4 /*yield*/, this._addLiquidityZap(_amounts)];
191
- case 1: return [2 /*return*/, _a.sent()];
192
- case 2:
193
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
283
+ case 2: return [2 /*return*/, _a.sent()];
284
+ case 3:
285
+ if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
194
286
  return [4 /*yield*/, this._addLiquidity(_amounts, true)];
195
- case 3: return [2 /*return*/, _a.sent()];
196
- case 4:
197
- if (!this.isMeta) return [3 /*break*/, 6];
287
+ case 4: return [2 /*return*/, _a.sent()];
288
+ case 5:
289
+ if (!this.isMeta) return [3 /*break*/, 7];
198
290
  return [4 /*yield*/, this._addLiquidityMetaZap(_amounts)];
199
- case 5: return [2 /*return*/, _a.sent()];
200
- case 6: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
201
- case 7:
291
+ case 6: return [2 /*return*/, _a.sent()];
292
+ case 7: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
293
+ case 8:
202
294
  // Plain pools
203
295
  return [2 /*return*/, _a.sent()];
204
296
  }
205
297
  });
206
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
+ }); };
207
318
  this.addLiquidityWrappedExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
208
319
  return __generator(this, function (_a) {
209
320
  switch (_a.label) {
@@ -212,27 +323,51 @@ var Pool = /** @class */ (function () {
212
323
  }
213
324
  });
214
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
+ }); };
215
350
  this.addLiquidityWrappedEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
216
- var balances, _a, _b, i, _amounts;
351
+ var balances, _a, _c, i, _amounts;
217
352
  var _this = this;
218
- return __generator(this, function (_c) {
219
- switch (_c.label) {
353
+ return __generator(this, function (_d) {
354
+ switch (_d.label) {
220
355
  case 0:
221
356
  if (amounts.length !== this.coinAddresses.length) {
222
357
  throw Error(this.name + " pool has " + this.coinAddresses.length + " coins (amounts provided for " + amounts.length + ")");
223
358
  }
224
- _b = (_a = Object).values;
359
+ _c = (_a = Object).values;
225
360
  return [4 /*yield*/, this.coinBalances()];
226
361
  case 1:
227
- balances = _b.apply(_a, [_c.sent()]);
362
+ balances = _c.apply(_a, [_d.sent()]);
228
363
  for (i = 0; i < balances.length; i++) {
229
364
  if (Number(balances[i]) < Number(amounts[i])) {
230
365
  throw Error("Not enough " + this.coins[i] + ". Actual: " + balances[i] + ", required: " + amounts[i]);
231
366
  }
232
367
  }
233
- return [4 /*yield*/, utils_1.hasAllowance(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.swap)];
368
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.swap)];
234
369
  case 2:
235
- if (!(_c.sent())) {
370
+ if (!(_d.sent())) {
236
371
  throw Error("Token allowance is needed to estimate gas");
237
372
  }
238
373
  _amounts = amounts.map(function (amount, i) {
@@ -240,11 +375,11 @@ var Pool = /** @class */ (function () {
240
375
  });
241
376
  if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
242
377
  return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
243
- case 3: return [2 /*return*/, _c.sent()];
378
+ case 3: return [2 /*return*/, _d.sent()];
244
379
  case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
245
380
  case 5:
246
381
  // Lending pools with zap and metapools
247
- return [2 /*return*/, _c.sent()];
382
+ return [2 /*return*/, _d.sent()];
248
383
  }
249
384
  });
250
385
  }); };
@@ -260,11 +395,14 @@ var Pool = /** @class */ (function () {
260
395
  _amounts = amounts.map(function (amount, i) {
261
396
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
262
397
  });
263
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
398
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
399
+ case 1:
400
+ _a.sent();
401
+ if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
264
402
  return [4 /*yield*/, this._addLiquidity(_amounts, false)];
265
- case 1: return [2 /*return*/, _a.sent()];
266
- case 2: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
267
- case 3:
403
+ case 2: return [2 /*return*/, _a.sent()];
404
+ case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
405
+ case 4:
268
406
  // Lending pools with zap and metapools
269
407
  return [2 /*return*/, _a.sent()];
270
408
  }
@@ -296,22 +434,55 @@ var Pool = /** @class */ (function () {
296
434
  }
297
435
  });
298
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
+ }); };
299
470
  this.removeLiquidityEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
300
471
  var lpTokenBalance, _a, _lpTokenAmount;
301
- return __generator(this, function (_b) {
302
- switch (_b.label) {
472
+ return __generator(this, function (_c) {
473
+ switch (_c.label) {
303
474
  case 0: return [4 /*yield*/, this.lpTokenBalances()];
304
475
  case 1:
305
- lpTokenBalance = (_b.sent())['lpToken'];
476
+ lpTokenBalance = (_c.sent())['lpToken'];
306
477
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
307
478
  throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
308
479
  }
309
480
  _a = this.zap;
310
481
  if (!_a) return [3 /*break*/, 3];
311
- return [4 /*yield*/, utils_1.hasAllowance([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
482
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
312
483
  case 2:
313
- _a = !(_b.sent());
314
- _b.label = 3;
484
+ _a = !(_c.sent());
485
+ _c.label = 3;
315
486
  case 3:
316
487
  if (_a) {
317
488
  throw Error("Token allowance is needed to estimate gas");
@@ -319,17 +490,17 @@ var Pool = /** @class */ (function () {
319
490
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
320
491
  if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 5];
321
492
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
322
- case 4: return [2 /*return*/, _b.sent()];
493
+ case 4: return [2 /*return*/, _c.sent()];
323
494
  case 5:
324
495
  if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
325
496
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
326
- case 6: return [2 /*return*/, _b.sent()];
497
+ case 6: return [2 /*return*/, _c.sent()];
327
498
  case 7:
328
499
  if (!this.isMeta) return [3 /*break*/, 9];
329
500
  return [4 /*yield*/, this._removeLiquidityMetaZap(_lpTokenAmount, true)];
330
- case 8: return [2 /*return*/, _b.sent()];
501
+ case 8: return [2 /*return*/, _c.sent()];
331
502
  case 9: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
332
- case 10: return [2 /*return*/, _b.sent()];
503
+ case 10: return [2 /*return*/, _c.sent()];
333
504
  }
334
505
  });
335
506
  }); };
@@ -339,19 +510,22 @@ var Pool = /** @class */ (function () {
339
510
  switch (_a.label) {
340
511
  case 0:
341
512
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
342
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 2];
513
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
514
+ case 1:
515
+ _a.sent();
516
+ if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
343
517
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
344
- case 1: return [2 /*return*/, _a.sent()];
345
- case 2:
346
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
518
+ case 2: return [2 /*return*/, _a.sent()];
519
+ case 3:
520
+ if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
347
521
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
348
- case 3: return [2 /*return*/, _a.sent()];
349
- case 4:
350
- if (!this.isMeta) return [3 /*break*/, 6];
522
+ case 4: return [2 /*return*/, _a.sent()];
523
+ case 5:
524
+ if (!this.isMeta) return [3 /*break*/, 7];
351
525
  return [4 /*yield*/, this._removeLiquidityMetaZap(_lpTokenAmount)];
352
- case 5: return [2 /*return*/, _a.sent()];
353
- case 6: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
354
- case 7: return [2 /*return*/, _a.sent()];
526
+ case 6: return [2 /*return*/, _a.sent()];
527
+ case 7: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
528
+ case 8: return [2 /*return*/, _a.sent()];
355
529
  }
356
530
  });
357
531
  }); };
@@ -395,11 +569,14 @@ var Pool = /** @class */ (function () {
395
569
  switch (_a.label) {
396
570
  case 0:
397
571
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
398
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
572
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
573
+ case 1:
574
+ _a.sent();
575
+ if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
399
576
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
400
- case 1: return [2 /*return*/, _a.sent()];
401
- case 2: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
402
- case 3: return [2 /*return*/, _a.sent()];
577
+ case 2: return [2 /*return*/, _a.sent()];
578
+ case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
579
+ case 4: return [2 /*return*/, _a.sent()];
403
580
  }
404
581
  });
405
582
  }); };
@@ -411,26 +588,98 @@ var Pool = /** @class */ (function () {
411
588
  }
412
589
  });
413
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
+ }); };
414
663
  this.removeLiquidityImbalanceEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
415
664
  var lpTokenAmount, lpTokenBalance, _a, _amounts;
416
665
  var _this = this;
417
- return __generator(this, function (_b) {
418
- switch (_b.label) {
666
+ return __generator(this, function (_c) {
667
+ switch (_c.label) {
419
668
  case 0: return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
420
669
  case 1:
421
- lpTokenAmount = _b.sent();
670
+ lpTokenAmount = _c.sent();
422
671
  return [4 /*yield*/, this.lpTokenBalances()];
423
672
  case 2:
424
- lpTokenBalance = (_b.sent())['lpToken'];
673
+ lpTokenBalance = (_c.sent())['lpToken'];
425
674
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
426
675
  throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
427
676
  }
428
677
  _a = this.zap;
429
678
  if (!_a) return [3 /*break*/, 4];
430
- return [4 /*yield*/, utils_1.hasAllowance([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
679
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
431
680
  case 3:
432
- _a = !(_b.sent());
433
- _b.label = 4;
681
+ _a = !(_c.sent());
682
+ _c.label = 4;
434
683
  case 4:
435
684
  if (_a) {
436
685
  throw Error("Token allowance is needed to estimate gas");
@@ -438,17 +687,17 @@ var Pool = /** @class */ (function () {
438
687
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
439
688
  if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 6];
440
689
  return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts, true)];
441
- case 5: return [2 /*return*/, _b.sent()];
690
+ case 5: return [2 /*return*/, _c.sent()];
442
691
  case 6:
443
692
  if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 8];
444
693
  return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true, true)];
445
- case 7: return [2 /*return*/, _b.sent()];
694
+ case 7: return [2 /*return*/, _c.sent()];
446
695
  case 8:
447
696
  if (!this.isMeta) return [3 /*break*/, 10];
448
697
  return [4 /*yield*/, this._removeLiquidityImbalanceMetaZap(_amounts, true)];
449
- case 9: return [2 /*return*/, _b.sent()];
698
+ case 9: return [2 /*return*/, _c.sent()];
450
699
  case 10: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, true)];
451
- case 11: return [2 /*return*/, _b.sent()];
700
+ case 11: return [2 /*return*/, _c.sent()];
452
701
  }
453
702
  });
454
703
  }); };
@@ -459,19 +708,22 @@ var Pool = /** @class */ (function () {
459
708
  switch (_a.label) {
460
709
  case 0:
461
710
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
462
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 2];
711
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
712
+ case 1:
713
+ _a.sent();
714
+ if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
463
715
  return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts)];
464
- case 1: return [2 /*return*/, _a.sent()];
465
- case 2:
466
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
716
+ case 2: return [2 /*return*/, _a.sent()];
717
+ case 3:
718
+ if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
467
719
  return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true)];
468
- case 3: return [2 /*return*/, _a.sent()];
469
- case 4:
470
- if (!this.isMeta) return [3 /*break*/, 6];
720
+ case 4: return [2 /*return*/, _a.sent()];
721
+ case 5:
722
+ if (!this.isMeta) return [3 /*break*/, 7];
471
723
  return [4 /*yield*/, this._removeLiquidityImbalanceMetaZap(_amounts)];
472
- case 5: return [2 /*return*/, _a.sent()];
473
- case 6: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts)];
474
- case 7: return [2 /*return*/, _a.sent()];
724
+ case 6: return [2 /*return*/, _a.sent()];
725
+ case 7: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts)];
726
+ case 8: return [2 /*return*/, _a.sent()];
475
727
  }
476
728
  });
477
729
  }); };
@@ -515,11 +767,14 @@ var Pool = /** @class */ (function () {
515
767
  switch (_a.label) {
516
768
  case 0:
517
769
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]); });
518
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
770
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
771
+ case 1:
772
+ _a.sent();
773
+ if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
519
774
  return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, false, estimateGas)];
520
- case 1: return [2 /*return*/, _a.sent()];
521
- case 2: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, estimateGas)];
522
- case 3: return [2 /*return*/, _a.sent()];
775
+ case 2: return [2 /*return*/, _a.sent()];
776
+ case 3: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, estimateGas)];
777
+ case 4: return [2 /*return*/, _a.sent()];
523
778
  }
524
779
  });
525
780
  });
@@ -550,22 +805,55 @@ var Pool = /** @class */ (function () {
550
805
  }
551
806
  });
552
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
+ }); };
553
841
  this.removeLiquidityOneCoinEstimateGas = function (lpTokenAmount, coin) { return __awaiter(_this, void 0, void 0, function () {
554
842
  var lpTokenBalance, _a, i, _lpTokenAmount;
555
- return __generator(this, function (_b) {
556
- switch (_b.label) {
843
+ return __generator(this, function (_c) {
844
+ switch (_c.label) {
557
845
  case 0: return [4 /*yield*/, this.lpTokenBalances()];
558
846
  case 1:
559
- lpTokenBalance = (_b.sent())['lpToken'];
847
+ lpTokenBalance = (_c.sent())['lpToken'];
560
848
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
561
849
  throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
562
850
  }
563
851
  _a = this.zap;
564
852
  if (!_a) return [3 /*break*/, 3];
565
- return [4 /*yield*/, utils_1.hasAllowance([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
853
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
566
854
  case 2:
567
- _a = !(_b.sent());
568
- _b.label = 3;
855
+ _a = !(_c.sent());
856
+ _c.label = 3;
569
857
  case 3:
570
858
  if (_a) {
571
859
  throw Error("Token allowance is needed to estimate gas");
@@ -574,15 +862,15 @@ var Pool = /** @class */ (function () {
574
862
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
575
863
  if (!(['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 5];
576
864
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
577
- case 4: return [2 /*return*/, _b.sent()];
865
+ case 4: return [2 /*return*/, _c.sent()];
578
866
  case 5:
579
867
  if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
580
868
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
581
- case 6: return [2 /*return*/, _b.sent()];
869
+ case 6: return [2 /*return*/, _c.sent()];
582
870
  case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
583
871
  case 8:
584
872
  // Plain pools
585
- return [2 /*return*/, _b.sent()];
873
+ return [2 /*return*/, _c.sent()];
586
874
  }
587
875
  });
588
876
  }); };
@@ -593,15 +881,18 @@ var Pool = /** @class */ (function () {
593
881
  case 0:
594
882
  i = this._getCoinIdx(coin);
595
883
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
596
- if (!(['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 2];
884
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
885
+ case 1:
886
+ _a.sent();
887
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 3];
597
888
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
598
- case 1: return [2 /*return*/, _a.sent()];
599
- case 2:
600
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
889
+ case 2: return [2 /*return*/, _a.sent()];
890
+ case 3:
891
+ if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
601
892
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
602
- case 3: return [2 /*return*/, _a.sent()];
603
- case 4: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
604
- case 5:
893
+ case 4: return [2 /*return*/, _a.sent()];
894
+ case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
895
+ case 6:
605
896
  // Plain pools
606
897
  return [2 /*return*/, _a.sent()];
607
898
  }
@@ -659,12 +950,50 @@ var Pool = /** @class */ (function () {
659
950
  if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
660
951
  throw Error(this.name + " pool doesn't have remove_liquidity_one_coin method for wrapped tokens");
661
952
  }
953
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
954
+ case 1:
955
+ _a.sent();
662
956
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
663
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
957
+ if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
664
958
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
959
+ case 2: return [2 /*return*/, _a.sent()];
960
+ case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
961
+ case 4: return [2 /*return*/, _a.sent()];
962
+ }
963
+ });
964
+ }); };
965
+ this.gaugeDepositIsApproved = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
966
+ return __generator(this, function (_a) {
967
+ switch (_a.label) {
968
+ case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.gauge)];
665
969
  case 1: return [2 /*return*/, _a.sent()];
666
- case 2: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
667
- case 3: return [2 /*return*/, _a.sent()];
970
+ }
971
+ });
972
+ }); };
973
+ this.gaugeDepositApproveEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
974
+ return __generator(this, function (_a) {
975
+ switch (_a.label) {
976
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.gauge)];
977
+ case 1: return [2 /*return*/, _a.sent()];
978
+ }
979
+ });
980
+ }); };
981
+ this.gaugeDepositApprove = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
982
+ return __generator(this, function (_a) {
983
+ switch (_a.label) {
984
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.gauge)];
985
+ case 1: return [2 /*return*/, _a.sent()];
986
+ }
987
+ });
988
+ }); };
989
+ this.gaugeDepositEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
990
+ var _lpTokenAmount;
991
+ return __generator(this, function (_a) {
992
+ switch (_a.label) {
993
+ case 0:
994
+ _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
995
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.options)];
996
+ case 1: return [2 /*return*/, (_a.sent()).toNumber()];
668
997
  }
669
998
  });
670
999
  }); };
@@ -674,7 +1003,7 @@ var Pool = /** @class */ (function () {
674
1003
  switch (_a.label) {
675
1004
  case 0:
676
1005
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
677
- return [4 /*yield*/, utils_1._ensureAllowance([this.lpToken], [_lpTokenAmount], this.gauge)];
1006
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.gauge)];
678
1007
  case 1:
679
1008
  _a.sent();
680
1009
  return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, curve_1.curve.options)];
@@ -682,6 +1011,17 @@ var Pool = /** @class */ (function () {
682
1011
  }
683
1012
  });
684
1013
  }); };
1014
+ this.gaugeWithdrawEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
1015
+ var _lpTokenAmount;
1016
+ return __generator(this, function (_a) {
1017
+ switch (_a.label) {
1018
+ case 0:
1019
+ _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1020
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.options)];
1021
+ case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1022
+ }
1023
+ });
1024
+ }); };
685
1025
  this.gaugeWithdraw = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
686
1026
  var _lpTokenAmount;
687
1027
  return __generator(this, function (_a) {
@@ -699,10 +1039,10 @@ var Pool = /** @class */ (function () {
699
1039
  addresses[_a] = arguments[_a];
700
1040
  }
701
1041
  return __awaiter(_this, void 0, void 0, function () {
702
- return __generator(this, function (_b) {
703
- switch (_b.label) {
704
- case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken', 'gauge'], this.underlyingCoins), this.coins), __spreadArray(__spreadArray([this.lpToken, this.gauge], this.underlyingCoinAddresses), this.coinAddresses)], addresses))];
705
- case 1: return [2 /*return*/, _b.sent()];
1042
+ return __generator(this, function (_c) {
1043
+ switch (_c.label) {
1044
+ 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))];
1045
+ case 1: return [2 /*return*/, _c.sent()];
706
1046
  }
707
1047
  });
708
1048
  });
@@ -713,10 +1053,10 @@ var Pool = /** @class */ (function () {
713
1053
  addresses[_a] = arguments[_a];
714
1054
  }
715
1055
  return __awaiter(_this, void 0, void 0, function () {
716
- return __generator(this, function (_b) {
717
- switch (_b.label) {
718
- case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses))];
719
- case 1: return [2 /*return*/, _b.sent()];
1056
+ return __generator(this, function (_c) {
1057
+ switch (_c.label) {
1058
+ case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
1059
+ case 1: return [2 /*return*/, _c.sent()];
720
1060
  }
721
1061
  });
722
1062
  });
@@ -727,10 +1067,10 @@ var Pool = /** @class */ (function () {
727
1067
  addresses[_a] = arguments[_a];
728
1068
  }
729
1069
  return __awaiter(_this, void 0, void 0, function () {
730
- return __generator(this, function (_b) {
731
- switch (_b.label) {
732
- case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.underlyingCoins, this.underlyingCoinAddresses], addresses))];
733
- case 1: return [2 /*return*/, _b.sent()];
1070
+ return __generator(this, function (_c) {
1071
+ switch (_c.label) {
1072
+ case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.underlyingCoins, this.underlyingCoinAddresses], addresses, false))];
1073
+ case 1: return [2 /*return*/, _c.sent()];
734
1074
  }
735
1075
  });
736
1076
  });
@@ -741,10 +1081,10 @@ var Pool = /** @class */ (function () {
741
1081
  addresses[_a] = arguments[_a];
742
1082
  }
743
1083
  return __awaiter(_this, void 0, void 0, function () {
744
- return __generator(this, function (_b) {
745
- switch (_b.label) {
746
- case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.coins, this.coinAddresses], addresses))];
747
- case 1: return [2 /*return*/, _b.sent()];
1084
+ return __generator(this, function (_c) {
1085
+ switch (_c.label) {
1086
+ case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.coins, this.coinAddresses], addresses, false))];
1087
+ case 1: return [2 /*return*/, _c.sent()];
748
1088
  }
749
1089
  });
750
1090
  });
@@ -755,10 +1095,10 @@ var Pool = /** @class */ (function () {
755
1095
  addresses[_a] = arguments[_a];
756
1096
  }
757
1097
  return __awaiter(_this, void 0, void 0, function () {
758
- return __generator(this, function (_b) {
759
- switch (_b.label) {
760
- case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray([], this.underlyingCoins), this.coins), __spreadArray(__spreadArray([], this.underlyingCoinAddresses), this.coinAddresses)], addresses))];
761
- case 1: return [2 /*return*/, _b.sent()];
1098
+ return __generator(this, function (_c) {
1099
+ switch (_c.label) {
1100
+ 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))];
1101
+ case 1: return [2 /*return*/, _c.sent()];
762
1102
  }
763
1103
  });
764
1104
  });
@@ -778,40 +1118,73 @@ var Pool = /** @class */ (function () {
778
1118
  }
779
1119
  });
780
1120
  }); };
1121
+ this.exchangeIsApproved = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1122
+ var i;
1123
+ return __generator(this, function (_a) {
1124
+ switch (_a.label) {
1125
+ case 0:
1126
+ i = this._getCoinIdx(inputCoin);
1127
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1128
+ case 1: return [2 /*return*/, _a.sent()];
1129
+ }
1130
+ });
1131
+ }); };
1132
+ this.exchangeApproveEstimateGas = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1133
+ var i;
1134
+ return __generator(this, function (_a) {
1135
+ switch (_a.label) {
1136
+ case 0:
1137
+ i = this._getCoinIdx(inputCoin);
1138
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1139
+ case 1: return [2 /*return*/, _a.sent()];
1140
+ }
1141
+ });
1142
+ }); };
1143
+ this.exchangeApprove = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1144
+ var i;
1145
+ return __generator(this, function (_a) {
1146
+ switch (_a.label) {
1147
+ case 0:
1148
+ i = this._getCoinIdx(inputCoin);
1149
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1150
+ case 1: return [2 /*return*/, _a.sent()];
1151
+ }
1152
+ });
1153
+ }); };
781
1154
  this.exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
782
1155
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
783
1156
  return __awaiter(_this, void 0, void 0, function () {
784
- var i, j, inputCoinBalance, _a, _b, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value;
785
- return __generator(this, function (_c) {
786
- switch (_c.label) {
1157
+ var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value;
1158
+ return __generator(this, function (_d) {
1159
+ switch (_d.label) {
787
1160
  case 0:
788
1161
  if (this.name === 'tricrypto2') {
789
1162
  throw Error("Use exchangeTricryptoEstimateGas method for tricrypto2 pool instead");
790
1163
  }
791
1164
  i = this._getCoinIdx(inputCoin);
792
1165
  j = this._getCoinIdx(outputCoin);
793
- _b = (_a = Object).values;
1166
+ _c = (_a = Object).values;
794
1167
  return [4 /*yield*/, this.underlyingCoinBalances()];
795
1168
  case 1:
796
- inputCoinBalance = _b.apply(_a, [_c.sent()])[i];
1169
+ inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
797
1170
  if (Number(inputCoinBalance) < Number(amount)) {
798
1171
  throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
799
1172
  }
800
- return [4 /*yield*/, utils_1.hasAllowance([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1173
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
801
1174
  case 2:
802
- if (!(_c.sent())) {
1175
+ if (!(_d.sent())) {
803
1176
  throw Error("Token allowance is needed to estimate gas");
804
1177
  }
805
1178
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
806
1179
  return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
807
1180
  case 3:
808
- _expected = _c.sent();
1181
+ _expected = _d.sent();
809
1182
  _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
810
1183
  contract = curve_1.curve.contracts[this.swap].contract;
811
1184
  exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
812
- value = utils_1.isEth(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
813
- return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value }))];
814
- case 4: return [2 /*return*/, (_c.sent()).toNumber()];
1185
+ value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1186
+ return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1187
+ case 4: return [2 /*return*/, (_d.sent()).toNumber()];
815
1188
  }
816
1189
  });
817
1190
  });
@@ -833,17 +1206,68 @@ var Pool = /** @class */ (function () {
833
1206
  case 1:
834
1207
  _expected = _a.sent();
835
1208
  _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
836
- return [4 /*yield*/, utils_1._ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], this.swap)];
1209
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], this.swap)];
837
1210
  case 2:
838
1211
  _a.sent();
839
1212
  contract = curve_1.curve.contracts[this.swap].contract;
840
1213
  exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
841
- value = utils_1.isEth(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
842
- return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value }))];
1214
+ value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1215
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
843
1216
  case 3:
1217
+ _a.sent();
1218
+ return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1219
+ case 4:
844
1220
  gasLimit = (_a.sent()).mul(130).div(100);
845
1221
  return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
846
- case 4: return [2 /*return*/, (_a.sent()).hash];
1222
+ case 5: return [2 /*return*/, (_a.sent()).hash];
1223
+ }
1224
+ });
1225
+ });
1226
+ };
1227
+ this.exchangeTricryptoIsApproved = function (inputCoin, amount, useEth) {
1228
+ if (useEth === void 0) { useEth = false; }
1229
+ return __awaiter(_this, void 0, void 0, function () {
1230
+ var i;
1231
+ return __generator(this, function (_a) {
1232
+ switch (_a.label) {
1233
+ case 0:
1234
+ i = this._getCoinIdx(inputCoin);
1235
+ if (i === 2 && useEth)
1236
+ return [2 /*return*/, true];
1237
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1238
+ case 1: return [2 /*return*/, _a.sent()];
1239
+ }
1240
+ });
1241
+ });
1242
+ };
1243
+ this.exchangeTricryptoApproveEstimateGas = function (inputCoin, amount, useEth) {
1244
+ if (useEth === void 0) { useEth = false; }
1245
+ return __awaiter(_this, void 0, void 0, function () {
1246
+ var i;
1247
+ return __generator(this, function (_a) {
1248
+ switch (_a.label) {
1249
+ case 0:
1250
+ i = this._getCoinIdx(inputCoin);
1251
+ if (i === 2 && useEth)
1252
+ return [2 /*return*/, 0];
1253
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1254
+ case 1: return [2 /*return*/, _a.sent()];
1255
+ }
1256
+ });
1257
+ });
1258
+ };
1259
+ this.exchangeTricryptoApprove = function (inputCoin, amount, useEth) {
1260
+ if (useEth === void 0) { useEth = false; }
1261
+ return __awaiter(_this, void 0, void 0, function () {
1262
+ var i;
1263
+ return __generator(this, function (_a) {
1264
+ switch (_a.label) {
1265
+ case 0:
1266
+ i = this._getCoinIdx(inputCoin);
1267
+ if (i === 2 && useEth)
1268
+ return [2 /*return*/, []];
1269
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1270
+ case 1: return [2 /*return*/, _a.sent()];
847
1271
  }
848
1272
  });
849
1273
  });
@@ -852,36 +1276,36 @@ var Pool = /** @class */ (function () {
852
1276
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
853
1277
  if (useEth === void 0) { useEth = false; }
854
1278
  return __awaiter(_this, void 0, void 0, function () {
855
- var i, j, inputCoinBalance, _a, _b, _amount, _expected, _minRecvAmount, contract, value;
856
- return __generator(this, function (_c) {
857
- switch (_c.label) {
1279
+ var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, value;
1280
+ return __generator(this, function (_d) {
1281
+ switch (_d.label) {
858
1282
  case 0:
859
1283
  if (this.name !== 'tricrypto2') {
860
1284
  throw Error("This method is for only tricrypto2 pool");
861
1285
  }
862
1286
  i = this._getCoinIdx(inputCoin);
863
1287
  j = this._getCoinIdx(outputCoin);
864
- _b = (_a = Object).values;
1288
+ _c = (_a = Object).values;
865
1289
  return [4 /*yield*/, this.underlyingCoinBalances()];
866
1290
  case 1:
867
- inputCoinBalance = _b.apply(_a, [_c.sent()])[i];
1291
+ inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
868
1292
  if (Number(inputCoinBalance) < Number(amount)) {
869
1293
  throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
870
1294
  }
871
- return [4 /*yield*/, utils_1.hasAllowance([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1295
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
872
1296
  case 2:
873
- if (!(_c.sent())) {
1297
+ if (!(_d.sent())) {
874
1298
  throw Error("Token allowance is needed to estimate gas");
875
1299
  }
876
1300
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
877
1301
  return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
878
1302
  case 3:
879
- _expected = _c.sent();
1303
+ _expected = _d.sent();
880
1304
  _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
881
1305
  contract = curve_1.curve.contracts[this.swap].contract;
882
1306
  value = useEth && i == 2 ? _amount : ethers_1.ethers.BigNumber.from(0);
883
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.options), { value: value }))];
884
- case 4: return [2 /*return*/, (_c.sent()).toNumber()];
1307
+ return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1308
+ case 4: return [2 /*return*/, (_d.sent()).toNumber()];
885
1309
  }
886
1310
  });
887
1311
  });
@@ -905,18 +1329,21 @@ var Pool = /** @class */ (function () {
905
1329
  _expected = _a.sent();
906
1330
  _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
907
1331
  if (!(i !== 2 || !useEth)) return [3 /*break*/, 3];
908
- return [4 /*yield*/, utils_1._ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], this.swap)];
1332
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], this.swap)];
909
1333
  case 2:
910
1334
  _a.sent();
911
1335
  _a.label = 3;
912
1336
  case 3:
913
1337
  contract = curve_1.curve.contracts[this.swap].contract;
914
1338
  value = useEth && i == 2 ? _amount : ethers_1.ethers.BigNumber.from(0);
915
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.options), { value: value }))];
1339
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
916
1340
  case 4:
1341
+ _a.sent();
1342
+ return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1343
+ case 5:
917
1344
  gasLimit = (_a.sent()).mul(130).div(100);
918
1345
  return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
919
- case 5: return [2 /*return*/, (_a.sent()).hash];
1346
+ case 6: return [2 /*return*/, (_a.sent()).hash];
920
1347
  }
921
1348
  });
922
1349
  });
@@ -936,36 +1363,69 @@ var Pool = /** @class */ (function () {
936
1363
  }
937
1364
  });
938
1365
  }); };
1366
+ this.exchangeWrappedIsApproved = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1367
+ var i;
1368
+ return __generator(this, function (_a) {
1369
+ switch (_a.label) {
1370
+ case 0:
1371
+ i = this._getCoinIdx(inputCoin);
1372
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1373
+ case 1: return [2 /*return*/, _a.sent()];
1374
+ }
1375
+ });
1376
+ }); };
1377
+ this.exchangeWrappedApproveEstimateGas = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1378
+ var i;
1379
+ return __generator(this, function (_a) {
1380
+ switch (_a.label) {
1381
+ case 0:
1382
+ i = this._getCoinIdx(inputCoin);
1383
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.coinAddresses[i]], [amount], this.swap)];
1384
+ case 1: return [2 /*return*/, _a.sent()];
1385
+ }
1386
+ });
1387
+ }); };
1388
+ this.exchangeWrappedApprove = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1389
+ var i;
1390
+ return __generator(this, function (_a) {
1391
+ switch (_a.label) {
1392
+ case 0:
1393
+ i = this._getCoinIdx(inputCoin);
1394
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.coinAddresses[i]], [amount], this.swap)];
1395
+ case 1: return [2 /*return*/, _a.sent()];
1396
+ }
1397
+ });
1398
+ }); };
939
1399
  this.exchangeWrappedEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
940
1400
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
941
1401
  return __awaiter(_this, void 0, void 0, function () {
942
- var i, j, inputCoinBalance, _a, _b, _amount, _expected, _minRecvAmount, contract, value;
943
- return __generator(this, function (_c) {
944
- switch (_c.label) {
1402
+ var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, value;
1403
+ return __generator(this, function (_d) {
1404
+ switch (_d.label) {
945
1405
  case 0:
946
1406
  i = this._getCoinIdx(inputCoin, false);
947
1407
  j = this._getCoinIdx(outputCoin, false);
948
- _b = (_a = Object).values;
1408
+ _c = (_a = Object).values;
949
1409
  return [4 /*yield*/, this.coinBalances()];
950
1410
  case 1:
951
- inputCoinBalance = _b.apply(_a, [_c.sent()])[i];
1411
+ inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
952
1412
  if (Number(inputCoinBalance) < Number(amount)) {
953
1413
  throw Error("Not enough " + this.coins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
954
1414
  }
955
- return [4 /*yield*/, utils_1.hasAllowance([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1415
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
956
1416
  case 2:
957
- if (!(_c.sent())) {
1417
+ if (!(_d.sent())) {
958
1418
  throw Error("Token allowance is needed to estimate gas");
959
1419
  }
960
1420
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.decimals[i]);
961
1421
  return [4 /*yield*/, this._getExchangeOutputWrapped(i, j, _amount)];
962
1422
  case 3:
963
- _expected = _c.sent();
1423
+ _expected = _d.sent();
964
1424
  _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
965
1425
  contract = curve_1.curve.contracts[this.swap].contract;
966
- value = utils_1.isEth(this.coinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
967
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value }))];
968
- case 4: return [2 /*return*/, (_c.sent()).toNumber()];
1426
+ value = (0, utils_1.isEth)(this.coinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1427
+ return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1428
+ case 4: return [2 /*return*/, (_d.sent()).toNumber()];
969
1429
  }
970
1430
  });
971
1431
  });
@@ -984,16 +1444,19 @@ var Pool = /** @class */ (function () {
984
1444
  case 1:
985
1445
  _expected = _a.sent();
986
1446
  _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
987
- return [4 /*yield*/, utils_1._ensureAllowance([this.coinAddresses[i]], [_amount], this.swap)];
1447
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.coinAddresses[i]], [_amount], this.swap)];
988
1448
  case 2:
989
1449
  _a.sent();
990
1450
  contract = curve_1.curve.contracts[this.swap].contract;
991
- value = utils_1.isEth(this.coinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
992
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value }))];
1451
+ value = (0, utils_1.isEth)(this.coinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1452
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
993
1453
  case 3:
1454
+ _a.sent();
1455
+ return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1456
+ case 4:
994
1457
  gasLimit = (_a.sent()).mul(130).div(100);
995
1458
  return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
996
- case 4: return [2 /*return*/, (_a.sent()).hash];
1459
+ case 5: return [2 /*return*/, (_a.sent()).hash];
997
1460
  }
998
1461
  });
999
1462
  });
@@ -1004,9 +1467,9 @@ var Pool = /** @class */ (function () {
1004
1467
  addresses[_a] = arguments[_a];
1005
1468
  }
1006
1469
  return __awaiter(_this, void 0, void 0, function () {
1007
- var votingEscrowContract, gaugeContract, contractCalls, response, _b, veTotalSupply, gaugeTotalSupply, resultBN, result, _c, _d, entry;
1008
- return __generator(this, function (_e) {
1009
- switch (_e.label) {
1470
+ var votingEscrowContract, gaugeContract, contractCalls, response, _c, veTotalSupply, gaugeTotalSupply, resultBN, result, _d, _e, entry;
1471
+ return __generator(this, function (_f) {
1472
+ switch (_f.label) {
1010
1473
  case 0:
1011
1474
  if (addresses.length == 1 && Array.isArray(addresses[0]))
1012
1475
  addresses = addresses[0];
@@ -1018,16 +1481,16 @@ var Pool = /** @class */ (function () {
1018
1481
  });
1019
1482
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
1020
1483
  case 1:
1021
- response = (_e.sent()).map(function (value) { return utils_1.toBN(value); });
1022
- _b = response.splice(0, 2), veTotalSupply = _b[0], gaugeTotalSupply = _b[1];
1484
+ response = (_f.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
1485
+ _c = response.splice(0, 2), veTotalSupply = _c[0], gaugeTotalSupply = _c[1];
1023
1486
  resultBN = {};
1024
1487
  addresses.forEach(function (acct, i) {
1025
1488
  resultBN[acct] = response[i].div(veTotalSupply).times(gaugeTotalSupply);
1026
1489
  });
1027
1490
  result = {};
1028
- for (_c = 0, _d = Object.entries(resultBN); _c < _d.length; _c++) {
1029
- entry = _d[_c];
1030
- result[entry[0]] = utils_1.toStringFromBN(entry[1]);
1491
+ for (_d = 0, _e = Object.entries(resultBN); _d < _e.length; _d++) {
1492
+ entry = _e[_d];
1493
+ result[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
1031
1494
  }
1032
1495
  return [2 /*return*/, result];
1033
1496
  }
@@ -1040,9 +1503,9 @@ var Pool = /** @class */ (function () {
1040
1503
  accounts[_a] = arguments[_a];
1041
1504
  }
1042
1505
  return __awaiter(_this, void 0, void 0, function () {
1043
- var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, response, _b, veTotalSupply, gaugeTotalSupply, votingPower, totalBalance, _c, accounts_1, acct, totalPower, optimalBN, _d, accounts_2, acct, amount, _e, accounts_3, acct, optimal, _f, _g, entry;
1044
- return __generator(this, function (_h) {
1045
- switch (_h.label) {
1506
+ 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;
1507
+ return __generator(this, function (_k) {
1508
+ switch (_k.label) {
1046
1509
  case 0:
1047
1510
  if (accounts.length == 1 && Array.isArray(accounts[0]))
1048
1511
  accounts = accounts[0];
@@ -1055,21 +1518,21 @@ var Pool = /** @class */ (function () {
1055
1518
  });
1056
1519
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
1057
1520
  case 1:
1058
- response = (_h.sent()).map(function (value) { return utils_1.toBN(value); });
1059
- _b = response.splice(0, 2), veTotalSupply = _b[0], gaugeTotalSupply = _b[1];
1521
+ response = (_k.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
1522
+ _c = response.splice(0, 2), veTotalSupply = _c[0], gaugeTotalSupply = _c[1];
1060
1523
  votingPower = {};
1061
- totalBalance = utils_1.BN(0);
1062
- for (_c = 0, accounts_1 = accounts; _c < accounts_1.length; _c++) {
1063
- acct = accounts_1[_c];
1524
+ totalBalance = (0, utils_1.BN)(0);
1525
+ for (_d = 0, accounts_1 = accounts; _d < accounts_1.length; _d++) {
1526
+ acct = accounts_1[_d];
1064
1527
  votingPower[acct] = response[0];
1065
1528
  totalBalance = totalBalance.plus(response[1]).plus(response[2]);
1066
1529
  response.splice(0, 3);
1067
1530
  }
1068
1531
  totalPower = Object.values(votingPower).reduce(function (sum, item) { return sum.plus(item); });
1069
- optimalBN = Object.fromEntries(accounts.map(function (acc) { return [acc, utils_1.BN(0)]; }));
1532
+ optimalBN = Object.fromEntries(accounts.map(function (acc) { return [acc, (0, utils_1.BN)(0)]; }));
1070
1533
  if (totalBalance.lt(gaugeTotalSupply.times(totalPower).div(veTotalSupply))) {
1071
- for (_d = 0, accounts_2 = accounts; _d < accounts_2.length; _d++) {
1072
- acct = accounts_2[_d];
1534
+ for (_e = 0, accounts_2 = accounts; _e < accounts_2.length; _e++) {
1535
+ acct = accounts_2[_e];
1073
1536
  amount = gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply).lt(totalBalance) ?
1074
1537
  gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply) : totalBalance;
1075
1538
  optimalBN[acct] = amount;
@@ -1081,17 +1544,17 @@ var Pool = /** @class */ (function () {
1081
1544
  }
1082
1545
  else {
1083
1546
  if (totalPower.lt(0)) {
1084
- for (_e = 0, accounts_3 = accounts; _e < accounts_3.length; _e++) {
1085
- acct = accounts_3[_e];
1547
+ for (_f = 0, accounts_3 = accounts; _f < accounts_3.length; _f++) {
1548
+ acct = accounts_3[_f];
1086
1549
  optimalBN[acct] = totalBalance.times(votingPower[acct]).div(totalPower);
1087
1550
  }
1088
1551
  }
1089
1552
  optimalBN[accounts[0]] = optimalBN[accounts[0]].plus(totalBalance.minus(Object.values(optimalBN).reduce(function (sum, item) { return sum.plus(item); })));
1090
1553
  }
1091
1554
  optimal = {};
1092
- for (_f = 0, _g = Object.entries(optimalBN); _f < _g.length; _f++) {
1093
- entry = _g[_f];
1094
- optimal[entry[0]] = utils_1.toStringFromBN(entry[1]);
1555
+ for (_g = 0, _h = Object.entries(optimalBN); _g < _h.length; _g++) {
1556
+ entry = _h[_g];
1557
+ optimal[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
1095
1558
  }
1096
1559
  return [2 /*return*/, optimal];
1097
1560
  }
@@ -1100,8 +1563,8 @@ var Pool = /** @class */ (function () {
1100
1563
  };
1101
1564
  this.boost = function (address) { return __awaiter(_this, void 0, void 0, function () {
1102
1565
  var gaugeContract, _a, workingBalance, balance, boost;
1103
- return __generator(this, function (_b) {
1104
- switch (_b.label) {
1566
+ return __generator(this, function (_c) {
1567
+ switch (_c.label) {
1105
1568
  case 0:
1106
1569
  gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
1107
1570
  return [4 /*yield*/, curve_1.curve.multicallProvider.all([
@@ -1109,7 +1572,7 @@ var Pool = /** @class */ (function () {
1109
1572
  gaugeContract.balanceOf(address),
1110
1573
  ])];
1111
1574
  case 1:
1112
- _a = (_b.sent()).map(function (value) { return Number(ethers_1.ethers.utils.formatUnits(value)); }), workingBalance = _a[0], balance = _a[1];
1575
+ _a = (_c.sent()).map(function (value) { return Number(ethers_1.ethers.utils.formatUnits(value)); }), workingBalance = _a[0], balance = _a[1];
1113
1576
  boost = workingBalance / (0.4 * balance);
1114
1577
  return [2 /*return*/, boost.toFixed(4).replace(/([0-9])0+$/, '$1')];
1115
1578
  }
@@ -1117,8 +1580,8 @@ var Pool = /** @class */ (function () {
1117
1580
  }); };
1118
1581
  this.getApy = function () { return __awaiter(_this, void 0, void 0, function () {
1119
1582
  var swapContract, gaugeContract, gaugeControllerContract, _a, inflation, weight, workingSupply, virtualPrice, rate, crvRate, baseApy, boostedApy;
1120
- return __generator(this, function (_b) {
1121
- switch (_b.label) {
1583
+ return __generator(this, function (_c) {
1584
+ switch (_c.label) {
1122
1585
  case 0:
1123
1586
  swapContract = curve_1.curve.contracts[this.swap].multicallContract;
1124
1587
  gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
@@ -1130,11 +1593,11 @@ var Pool = /** @class */ (function () {
1130
1593
  swapContract.get_virtual_price(),
1131
1594
  ])];
1132
1595
  case 1:
1133
- _a = (_b.sent()).map(function (value) { return utils_1.toBN(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], virtualPrice = _a[3];
1596
+ _a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], virtualPrice = _a[3];
1134
1597
  rate = inflation.times(weight).times(31536000).div(workingSupply).times(0.4).div(virtualPrice);
1135
- return [4 /*yield*/, utils_1.getCrvRate()];
1598
+ return [4 /*yield*/, (0, utils_1.getCrvRate)()];
1136
1599
  case 2:
1137
- crvRate = _b.sent();
1600
+ crvRate = _c.sent();
1138
1601
  baseApy = rate.times(crvRate);
1139
1602
  boostedApy = baseApy.times(2.5);
1140
1603
  return [2 /*return*/, [baseApy.toFixed(4), boostedApy.toFixed(4)]];
@@ -1165,37 +1628,37 @@ var Pool = /** @class */ (function () {
1165
1628
  return idx;
1166
1629
  };
1167
1630
  this._getRates = function () { return __awaiter(_this, void 0, void 0, function () {
1168
- var _rates, i, addr, _a, _b, _c, _d;
1169
- return __generator(this, function (_e) {
1170
- switch (_e.label) {
1631
+ var _rates, i, addr, _a, _c, _d, _e;
1632
+ return __generator(this, function (_f) {
1633
+ switch (_f.label) {
1171
1634
  case 0:
1172
1635
  _rates = [];
1173
1636
  i = 0;
1174
- _e.label = 1;
1637
+ _f.label = 1;
1175
1638
  case 1:
1176
1639
  if (!(i < this.coinAddresses.length)) return [3 /*break*/, 9];
1177
1640
  addr = this.coinAddresses[i];
1178
1641
  if (!this.useLending[i]) return [3 /*break*/, 7];
1179
1642
  if (!['compound', 'usdt', 'ib'].includes(this.name)) return [3 /*break*/, 3];
1180
- _b = (_a = _rates).push;
1643
+ _c = (_a = _rates).push;
1181
1644
  return [4 /*yield*/, curve_1.curve.contracts[addr].contract.exchangeRateStored()];
1182
1645
  case 2:
1183
- _b.apply(_a, [_e.sent()]);
1646
+ _c.apply(_a, [_f.sent()]);
1184
1647
  return [3 /*break*/, 6];
1185
1648
  case 3:
1186
1649
  if (!['y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 5];
1187
- _d = (_c = _rates).push;
1650
+ _e = (_d = _rates).push;
1188
1651
  return [4 /*yield*/, curve_1.curve.contracts[addr].contract.getPricePerFullShare()];
1189
1652
  case 4:
1190
- _d.apply(_c, [_e.sent()]);
1653
+ _e.apply(_d, [_f.sent()]);
1191
1654
  return [3 /*break*/, 6];
1192
1655
  case 5:
1193
1656
  _rates.push(ethers_1.ethers.BigNumber.from(10).pow(18)); // Aave ratio 1:1
1194
- _e.label = 6;
1657
+ _f.label = 6;
1195
1658
  case 6: return [3 /*break*/, 8];
1196
1659
  case 7:
1197
1660
  _rates.push(ethers_1.ethers.BigNumber.from(10).pow(18));
1198
- _e.label = 8;
1661
+ _f.label = 8;
1199
1662
  case 8:
1200
1663
  i++;
1201
1664
  return [3 /*break*/, 1];
@@ -1209,9 +1672,9 @@ var Pool = /** @class */ (function () {
1209
1672
  addresses[_a - 2] = arguments[_a];
1210
1673
  }
1211
1674
  return __awaiter(_this, void 0, void 0, function () {
1212
- var coinNames, coinAddresses, i, rawBalances, balances, _b, addresses_1, address, _c, coinNames_1, coinName;
1213
- return __generator(this, function (_d) {
1214
- switch (_d.label) {
1675
+ var coinNames, coinAddresses, i, rawBalances, balances, _c, addresses_1, address, _d, coinNames_1, coinName;
1676
+ return __generator(this, function (_e) {
1677
+ switch (_e.label) {
1215
1678
  case 0:
1216
1679
  coinNames = [];
1217
1680
  coinAddresses = [];
@@ -1226,16 +1689,16 @@ var Pool = /** @class */ (function () {
1226
1689
  coinNames.push('ETH');
1227
1690
  coinAddresses.push('0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE');
1228
1691
  }
1229
- addresses = utils_1._prepareAddresses(addresses);
1230
- return [4 /*yield*/, utils_1._getBalances(coinAddresses, addresses)];
1692
+ addresses = (0, utils_1._prepareAddresses)(addresses);
1693
+ return [4 /*yield*/, (0, utils_1._getBalances)(coinAddresses, addresses)];
1231
1694
  case 1:
1232
- rawBalances = _d.sent();
1695
+ rawBalances = _e.sent();
1233
1696
  balances = {};
1234
- for (_b = 0, addresses_1 = addresses; _b < addresses_1.length; _b++) {
1235
- address = addresses_1[_b];
1697
+ for (_c = 0, addresses_1 = addresses; _c < addresses_1.length; _c++) {
1698
+ address = addresses_1[_c];
1236
1699
  balances[address] = {};
1237
- for (_c = 0, coinNames_1 = coinNames; _c < coinNames_1.length; _c++) {
1238
- coinName = coinNames_1[_c];
1700
+ for (_d = 0, coinNames_1 = coinNames; _d < coinNames_1.length; _d++) {
1701
+ coinName = coinNames_1[_d];
1239
1702
  balances[address][coinName] = rawBalances[address].shift();
1240
1703
  }
1241
1704
  }
@@ -1244,12 +1707,24 @@ var Pool = /** @class */ (function () {
1244
1707
  });
1245
1708
  });
1246
1709
  };
1710
+ this._balancedAmounts = function (poolBalances, walletBalances) {
1711
+ var poolBalancesRatios = poolBalances.map(function (b) { return b / poolBalances.reduce(function (a, b) { return a + b; }); });
1712
+ // Cross factors for each wallet balance used as reference to see the
1713
+ // max that can be used according to the lowest relative wallet balance
1714
+ var balancesAmountsForEachScenario = walletBalances.map(function (_, i) { return (walletBalances.map(function (_, j) { return (poolBalancesRatios[j] * walletBalances[i] / poolBalancesRatios[i]); })); });
1715
+ var firstCoinBalanceForEachScenario = balancesAmountsForEachScenario.map(function (_a) {
1716
+ var a = _a[0];
1717
+ return a;
1718
+ });
1719
+ var scenarioWithLowestBalances = firstCoinBalanceForEachScenario.indexOf(Math.min.apply(Math, firstCoinBalanceForEachScenario));
1720
+ return balancesAmountsForEachScenario[scenarioWithLowestBalances].map(String);
1721
+ };
1247
1722
  this._calcLpTokenAmount = function (_amounts, isDeposit) {
1248
1723
  if (isDeposit === void 0) { isDeposit = true; }
1249
1724
  return __awaiter(_this, void 0, void 0, function () {
1250
1725
  return __generator(this, function (_a) {
1251
1726
  switch (_a.label) {
1252
- case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.options)];
1727
+ case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1253
1728
  case 1: return [2 /*return*/, _a.sent()];
1254
1729
  }
1255
1730
  });
@@ -1264,9 +1739,9 @@ var Pool = /** @class */ (function () {
1264
1739
  case 0:
1265
1740
  contract = curve_1.curve.contracts[this.zap].contract;
1266
1741
  if (!this.isFactory) return [3 /*break*/, 2];
1267
- return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.options)];
1742
+ return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
1268
1743
  case 1: return [2 /*return*/, _a.sent()];
1269
- case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.options)];
1744
+ case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1270
1745
  case 3: return [2 /*return*/, _a.sent()];
1271
1746
  }
1272
1747
  });
@@ -1284,7 +1759,7 @@ var Pool = /** @class */ (function () {
1284
1759
  _wrapped_amounts = _underlying_amounts.map(function (amount, i) {
1285
1760
  return amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates[i]);
1286
1761
  });
1287
- return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_wrapped_amounts, isDeposit, curve_1.curve.options)];
1762
+ return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_wrapped_amounts, isDeposit, curve_1.curve.constantOptions)];
1288
1763
  case 2: return [2 /*return*/, _a.sent()];
1289
1764
  }
1290
1765
  });
@@ -1298,17 +1773,17 @@ var Pool = /** @class */ (function () {
1298
1773
  switch (_a.label) {
1299
1774
  case 0:
1300
1775
  if (!!estimateGas) return [3 /*break*/, 2];
1301
- return [4 /*yield*/, utils_1._ensureAllowance(this.coinAddresses, _amounts, this.swap)];
1776
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.coinAddresses, _amounts, this.swap)];
1302
1777
  case 1:
1303
1778
  _a.sent();
1304
1779
  _a.label = 2;
1305
1780
  case 2: return [4 /*yield*/, this._calcLpTokenAmount(_amounts)];
1306
1781
  case 3:
1307
1782
  _minMintAmount = (_a.sent()).mul(99).div(100);
1308
- ethIndex = utils_1.getEthIndex(this.coinAddresses);
1783
+ ethIndex = (0, utils_1.getEthIndex)(this.coinAddresses);
1309
1784
  value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
1310
1785
  contract = curve_1.curve.contracts[this.swap].contract;
1311
- return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { value: value }))];
1786
+ return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1312
1787
  case 4:
1313
1788
  gas = _a.sent();
1314
1789
  if (estimateGas) {
@@ -1329,17 +1804,17 @@ var Pool = /** @class */ (function () {
1329
1804
  switch (_a.label) {
1330
1805
  case 0:
1331
1806
  if (!!estimateGas) return [3 /*break*/, 2];
1332
- return [4 /*yield*/, utils_1._ensureAllowance(this.underlyingCoinAddresses, _amounts, this.zap)];
1807
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.underlyingCoinAddresses, _amounts, this.zap)];
1333
1808
  case 1:
1334
1809
  _a.sent();
1335
1810
  _a.label = 2;
1336
1811
  case 2: return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts)];
1337
1812
  case 3:
1338
1813
  _minMintAmount = (_a.sent()).mul(99).div(100);
1339
- ethIndex = utils_1.getEthIndex(this.underlyingCoinAddresses);
1814
+ ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
1340
1815
  value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
1341
1816
  contract = curve_1.curve.contracts[this.zap].contract;
1342
- return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { value: value }))];
1817
+ return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1343
1818
  case 4:
1344
1819
  gas = _a.sent();
1345
1820
  if (estimateGas) {
@@ -1360,18 +1835,18 @@ var Pool = /** @class */ (function () {
1360
1835
  switch (_a.label) {
1361
1836
  case 0:
1362
1837
  if (!!estimateGas) return [3 /*break*/, 2];
1363
- return [4 /*yield*/, utils_1._ensureAllowance(this.underlyingCoinAddresses, _amounts, this.zap)];
1838
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.underlyingCoinAddresses, _amounts, this.zap)];
1364
1839
  case 1:
1365
1840
  _a.sent();
1366
1841
  _a.label = 2;
1367
1842
  case 2: return [4 /*yield*/, this._calcLpTokenAmountZap(_amounts)];
1368
1843
  case 3:
1369
1844
  _minMintAmount = (_a.sent()).mul(99).div(100);
1370
- ethIndex = utils_1.getEthIndex(this.underlyingCoinAddresses);
1845
+ ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
1371
1846
  value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
1372
1847
  contract = curve_1.curve.contracts[this.zap].contract;
1373
1848
  if (!this.isFactory) return [3 /*break*/, 6];
1374
- return [4 /*yield*/, contract.estimateGas.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { value: value }))];
1849
+ return [4 /*yield*/, contract.estimateGas.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1375
1850
  case 4:
1376
1851
  gas_1 = _a.sent();
1377
1852
  if (estimateGas) {
@@ -1380,7 +1855,7 @@ var Pool = /** @class */ (function () {
1380
1855
  gasLimit_1 = gas_1.mul(130).div(100);
1381
1856
  return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_1, value: value }))];
1382
1857
  case 5: return [2 /*return*/, (_a.sent()).hash];
1383
- case 6: return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { value: value }))];
1858
+ case 6: return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1384
1859
  case 7:
1385
1860
  gas = _a.sent();
1386
1861
  if (estimateGas) {
@@ -1398,74 +1873,74 @@ var Pool = /** @class */ (function () {
1398
1873
  if (estimateGas === void 0) { estimateGas = false; }
1399
1874
  return __awaiter(_this, void 0, void 0, function () {
1400
1875
  var coinAddresses, _minMintAmount, _a, contract, ethIndex, value, gas, gasLimit;
1401
- return __generator(this, function (_b) {
1402
- switch (_b.label) {
1876
+ return __generator(this, function (_c) {
1877
+ switch (_c.label) {
1403
1878
  case 0:
1404
1879
  coinAddresses = useUnderlying ? this.underlyingCoinAddresses : this.coinAddresses;
1405
1880
  if (!!estimateGas) return [3 /*break*/, 2];
1406
- return [4 /*yield*/, utils_1._ensureAllowance(coinAddresses, _amounts, this.swap)];
1881
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)(coinAddresses, _amounts, this.swap)];
1407
1882
  case 1:
1408
- _b.sent();
1409
- _b.label = 2;
1883
+ _c.sent();
1884
+ _c.label = 2;
1410
1885
  case 2:
1411
1886
  if (!useUnderlying) return [3 /*break*/, 4];
1412
1887
  return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts)];
1413
1888
  case 3:
1414
- _a = _b.sent();
1889
+ _a = _c.sent();
1415
1890
  return [3 /*break*/, 6];
1416
1891
  case 4: return [4 /*yield*/, this._calcLpTokenAmount(_amounts)];
1417
1892
  case 5:
1418
- _a = _b.sent();
1419
- _b.label = 6;
1893
+ _a = _c.sent();
1894
+ _c.label = 6;
1420
1895
  case 6:
1421
1896
  _minMintAmount = _a;
1422
1897
  _minMintAmount = _minMintAmount.mul(99).div(100);
1423
1898
  contract = curve_1.curve.contracts[this.swap].contract;
1424
- ethIndex = utils_1.getEthIndex(this.underlyingCoinAddresses);
1899
+ ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
1425
1900
  value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
1426
- return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { value: value }))];
1901
+ return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, useUnderlying, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1427
1902
  case 7:
1428
- gas = _b.sent();
1903
+ gas = _c.sent();
1429
1904
  if (estimateGas) {
1430
1905
  return [2 /*return*/, gas.toNumber()];
1431
1906
  }
1432
1907
  gasLimit = gas.mul(130).div(100);
1433
1908
  return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
1434
- case 8: return [2 /*return*/, (_b.sent()).hash];
1909
+ case 8: return [2 /*return*/, (_c.sent()).hash];
1435
1910
  }
1436
1911
  });
1437
1912
  });
1438
1913
  };
1439
1914
  this._calcExpectedAmounts = function (_lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
1440
- var coinBalancesBN, i, _balance, totalSupplyBN, _a, expectedAmountsBN, _b, coinBalancesBN_1, coinBalance;
1915
+ var coinBalancesBN, i, _balance, totalSupplyBN, _a, expectedAmountsBN, _c, coinBalancesBN_1, coinBalance;
1441
1916
  var _this = this;
1442
- return __generator(this, function (_c) {
1443
- switch (_c.label) {
1917
+ return __generator(this, function (_d) {
1918
+ switch (_d.label) {
1444
1919
  case 0:
1445
1920
  coinBalancesBN = [];
1446
1921
  i = 0;
1447
- _c.label = 1;
1922
+ _d.label = 1;
1448
1923
  case 1:
1449
1924
  if (!(i < this.coinAddresses.length)) return [3 /*break*/, 4];
1450
- return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.balances(i, curve_1.curve.options)];
1925
+ return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.balances(i, curve_1.curve.constantOptions)];
1451
1926
  case 2:
1452
- _balance = _c.sent();
1453
- coinBalancesBN.push(utils_1.toBN(_balance, this.decimals[i]));
1454
- _c.label = 3;
1927
+ _balance = _d.sent();
1928
+ coinBalancesBN.push((0, utils_1.toBN)(_balance, this.decimals[i]));
1929
+ _d.label = 3;
1455
1930
  case 3:
1456
1931
  i++;
1457
1932
  return [3 /*break*/, 1];
1458
1933
  case 4:
1459
1934
  _a = utils_1.toBN;
1460
- return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply(curve_1.curve.options)];
1935
+ return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply(curve_1.curve.constantOptions)];
1461
1936
  case 5:
1462
- totalSupplyBN = _a.apply(void 0, [_c.sent()]);
1937
+ totalSupplyBN = _a.apply(void 0, [_d.sent()]);
1463
1938
  expectedAmountsBN = [];
1464
- for (_b = 0, coinBalancesBN_1 = coinBalancesBN; _b < coinBalancesBN_1.length; _b++) {
1465
- coinBalance = coinBalancesBN_1[_b];
1466
- expectedAmountsBN.push(coinBalance.times(utils_1.toBN(_lpTokenAmount)).div(totalSupplyBN));
1939
+ for (_c = 0, coinBalancesBN_1 = coinBalancesBN; _c < coinBalancesBN_1.length; _c++) {
1940
+ coinBalance = coinBalancesBN_1[_c];
1941
+ expectedAmountsBN.push(coinBalance.times((0, utils_1.toBN)(_lpTokenAmount)).div(totalSupplyBN));
1467
1942
  }
1468
- return [2 /*return*/, expectedAmountsBN.map(function (amount, i) { return utils_1.fromBN(amount, _this.decimals[i]); })];
1943
+ return [2 /*return*/, expectedAmountsBN.map(function (amount, i) { return (0, utils_1.fromBN)(amount, _this.decimals[i]); })];
1469
1944
  }
1470
1945
  });
1471
1946
  }); };
@@ -1512,7 +1987,7 @@ var Pool = /** @class */ (function () {
1512
1987
  return [4 /*yield*/, basePool._calcExpectedAmounts(_expectedMetaCoinAmount)];
1513
1988
  case 2:
1514
1989
  _basePoolExpectedAmounts = _a.sent();
1515
- return [2 /*return*/, __spreadArray(__spreadArray([], _expectedUnderlyingAmounts), _basePoolExpectedAmounts)];
1990
+ return [2 /*return*/, __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true)];
1516
1991
  }
1517
1992
  });
1518
1993
  }); };
@@ -1534,7 +2009,7 @@ var Pool = /** @class */ (function () {
1534
2009
  case 1:
1535
2010
  _minAmounts = _a.sent();
1536
2011
  contract = curve_1.curve.contracts[this.swap].contract;
1537
- return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.options)];
2012
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
1538
2013
  case 2:
1539
2014
  gas = _a.sent();
1540
2015
  if (estimateGas) {
@@ -1555,7 +2030,7 @@ var Pool = /** @class */ (function () {
1555
2030
  switch (_a.label) {
1556
2031
  case 0:
1557
2032
  if (!!estimateGas) return [3 /*break*/, 2];
1558
- return [4 /*yield*/, utils_1._ensureAllowance([this.lpToken], [_lpTokenAmount], this.zap)];
2033
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
1559
2034
  case 1:
1560
2035
  _a.sent();
1561
2036
  _a.label = 2;
@@ -1563,7 +2038,7 @@ var Pool = /** @class */ (function () {
1563
2038
  case 3:
1564
2039
  _minAmounts = _a.sent();
1565
2040
  contract = curve_1.curve.contracts[this.zap].contract;
1566
- return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.options)];
2041
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
1567
2042
  case 4:
1568
2043
  gas = _a.sent();
1569
2044
  if (estimateGas) {
@@ -1584,7 +2059,7 @@ var Pool = /** @class */ (function () {
1584
2059
  switch (_a.label) {
1585
2060
  case 0:
1586
2061
  if (!!estimateGas) return [3 /*break*/, 2];
1587
- return [4 /*yield*/, utils_1._ensureAllowance([this.lpToken], [_lpTokenAmount], this.zap)];
2062
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
1588
2063
  case 1:
1589
2064
  _a.sent();
1590
2065
  _a.label = 2;
@@ -1593,7 +2068,7 @@ var Pool = /** @class */ (function () {
1593
2068
  _minAmounts = _a.sent();
1594
2069
  contract = curve_1.curve.contracts[this.zap].contract;
1595
2070
  if (!this.isFactory) return [3 /*break*/, 6];
1596
- return [4 /*yield*/, contract.estimateGas.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, curve_1.curve.options)];
2071
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
1597
2072
  case 4:
1598
2073
  gas_2 = _a.sent();
1599
2074
  if (estimateGas) {
@@ -1602,7 +2077,7 @@ var Pool = /** @class */ (function () {
1602
2077
  gasLimit_2 = gas_2.mul(130).div(100);
1603
2078
  return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_2 }))];
1604
2079
  case 5: return [2 /*return*/, (_a.sent()).hash];
1605
- case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.options)];
2080
+ case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
1606
2081
  case 7:
1607
2082
  gas = _a.sent();
1608
2083
  if (estimateGas) {
@@ -1620,30 +2095,30 @@ var Pool = /** @class */ (function () {
1620
2095
  if (estimateGas === void 0) { estimateGas = false; }
1621
2096
  return __awaiter(_this, void 0, void 0, function () {
1622
2097
  var _minAmounts, _a, contract, gas, gasLimit;
1623
- return __generator(this, function (_b) {
1624
- switch (_b.label) {
2098
+ return __generator(this, function (_c) {
2099
+ switch (_c.label) {
1625
2100
  case 0:
1626
2101
  if (!useUnderlying) return [3 /*break*/, 2];
1627
2102
  return [4 /*yield*/, this._calcMinUnderlyingAmounts(_lpTokenAmount)];
1628
2103
  case 1:
1629
- _a = _b.sent();
2104
+ _a = _c.sent();
1630
2105
  return [3 /*break*/, 4];
1631
2106
  case 2: return [4 /*yield*/, this._calcMinAmounts(_lpTokenAmount)];
1632
2107
  case 3:
1633
- _a = _b.sent();
1634
- _b.label = 4;
2108
+ _a = _c.sent();
2109
+ _c.label = 4;
1635
2110
  case 4:
1636
2111
  _minAmounts = _a;
1637
2112
  contract = curve_1.curve.contracts[this.swap].contract;
1638
- return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, useUnderlying, curve_1.curve.options)];
2113
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, useUnderlying, curve_1.curve.constantOptions)];
1639
2114
  case 5:
1640
- gas = _b.sent();
2115
+ gas = _c.sent();
1641
2116
  if (estimateGas) {
1642
2117
  return [2 /*return*/, gas.toNumber()];
1643
2118
  }
1644
2119
  gasLimit = gas.mul(130).div(100);
1645
2120
  return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1646
- case 6: return [2 /*return*/, (_b.sent()).hash];
2121
+ case 6: return [2 /*return*/, (_c.sent()).hash];
1647
2122
  }
1648
2123
  });
1649
2124
  });
@@ -1658,7 +2133,7 @@ var Pool = /** @class */ (function () {
1658
2133
  case 1:
1659
2134
  _maxBurnAmount = (_a.sent()).mul(101).div(100);
1660
2135
  contract = curve_1.curve.contracts[this.swap].contract;
1661
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.options)];
2136
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
1662
2137
  case 2:
1663
2138
  gas = _a.sent();
1664
2139
  if (estimateGas) {
@@ -1681,13 +2156,13 @@ var Pool = /** @class */ (function () {
1681
2156
  case 1:
1682
2157
  _maxBurnAmount = (_a.sent()).mul(101).div(100);
1683
2158
  if (!!estimateGas) return [3 /*break*/, 3];
1684
- return [4 /*yield*/, utils_1._ensureAllowance([this.lpToken], [_maxBurnAmount], this.zap)];
2159
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_maxBurnAmount], this.zap)];
1685
2160
  case 2:
1686
2161
  _a.sent();
1687
2162
  _a.label = 3;
1688
2163
  case 3:
1689
2164
  contract = curve_1.curve.contracts[this.zap].contract;
1690
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.options)];
2165
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
1691
2166
  case 4:
1692
2167
  gas = _a.sent();
1693
2168
  if (estimateGas) {
@@ -1710,14 +2185,14 @@ var Pool = /** @class */ (function () {
1710
2185
  case 1:
1711
2186
  _maxBurnAmount = (_a.sent()).mul(101).div(100);
1712
2187
  if (!!estimateGas) return [3 /*break*/, 3];
1713
- return [4 /*yield*/, utils_1._ensureAllowance([this.lpToken], [_maxBurnAmount], this.zap)];
2188
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_maxBurnAmount], this.zap)];
1714
2189
  case 2:
1715
2190
  _a.sent();
1716
2191
  _a.label = 3;
1717
2192
  case 3:
1718
2193
  contract = curve_1.curve.contracts[this.zap].contract;
1719
2194
  if (!this.isFactory) return [3 /*break*/, 6];
1720
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, curve_1.curve.options)];
2195
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
1721
2196
  case 4:
1722
2197
  gas_3 = _a.sent();
1723
2198
  if (estimateGas) {
@@ -1726,7 +2201,7 @@ var Pool = /** @class */ (function () {
1726
2201
  gasLimit_3 = gas_3.mul(130).div(100);
1727
2202
  return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_3 }))];
1728
2203
  case 5: return [2 /*return*/, (_a.sent())];
1729
- case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.options)];
2204
+ case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
1730
2205
  case 7:
1731
2206
  gas = _a.sent();
1732
2207
  if (estimateGas) {
@@ -1744,31 +2219,31 @@ var Pool = /** @class */ (function () {
1744
2219
  if (estimateGas === void 0) { estimateGas = false; }
1745
2220
  return __awaiter(_this, void 0, void 0, function () {
1746
2221
  var _maxBurnAmount, _a, contract, gas, gasLimit;
1747
- return __generator(this, function (_b) {
1748
- switch (_b.label) {
2222
+ return __generator(this, function (_c) {
2223
+ switch (_c.label) {
1749
2224
  case 0:
1750
2225
  if (!useUnderlying) return [3 /*break*/, 2];
1751
2226
  return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
1752
2227
  case 1:
1753
- _a = _b.sent();
2228
+ _a = _c.sent();
1754
2229
  return [3 /*break*/, 4];
1755
2230
  case 2: return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
1756
2231
  case 3:
1757
- _a = _b.sent();
1758
- _b.label = 4;
2232
+ _a = _c.sent();
2233
+ _c.label = 4;
1759
2234
  case 4:
1760
2235
  _maxBurnAmount = _a;
1761
2236
  _maxBurnAmount = _maxBurnAmount.mul(101).div(100);
1762
2237
  contract = curve_1.curve.contracts[this.swap].contract;
1763
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, useUnderlying, curve_1.curve.options)];
2238
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, useUnderlying, curve_1.curve.constantOptions)];
1764
2239
  case 5:
1765
- gas = _b.sent();
2240
+ gas = _c.sent();
1766
2241
  if (estimateGas) {
1767
2242
  return [2 /*return*/, gas.toNumber()];
1768
2243
  }
1769
2244
  gasLimit = gas.mul(130).div(100);
1770
2245
  return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1771
- case 6: return [2 /*return*/, (_b.sent()).hash];
2246
+ case 6: return [2 /*return*/, (_c.sent()).hash];
1772
2247
  }
1773
2248
  });
1774
2249
  });
@@ -1776,7 +2251,7 @@ var Pool = /** @class */ (function () {
1776
2251
  this._calcWithdrawOneCoinSwap = function (_lpTokenAmount, i) { return __awaiter(_this, void 0, void 0, function () {
1777
2252
  return __generator(this, function (_a) {
1778
2253
  switch (_a.label) {
1779
- case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.options)];
2254
+ case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.constantOptions)];
1780
2255
  case 1: return [2 /*return*/, _a.sent()];
1781
2256
  }
1782
2257
  });
@@ -1788,9 +2263,9 @@ var Pool = /** @class */ (function () {
1788
2263
  case 0:
1789
2264
  contract = curve_1.curve.contracts[this.zap].contract;
1790
2265
  if (!this.isFactory) return [3 /*break*/, 2];
1791
- return [4 /*yield*/, contract.calc_withdraw_one_coin(this.swap, _lpTokenAmount, i, curve_1.curve.options)];
2266
+ return [4 /*yield*/, contract.calc_withdraw_one_coin(this.swap, _lpTokenAmount, i, curve_1.curve.constantOptions)];
1792
2267
  case 1: return [2 /*return*/, (_a.sent())];
1793
- case 2: return [4 /*yield*/, contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.options)];
2268
+ case 2: return [4 /*yield*/, contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.constantOptions)];
1794
2269
  case 3: return [2 /*return*/, _a.sent()];
1795
2270
  }
1796
2271
  });
@@ -1800,7 +2275,7 @@ var Pool = /** @class */ (function () {
1800
2275
  return __awaiter(_this, void 0, void 0, function () {
1801
2276
  return __generator(this, function (_a) {
1802
2277
  switch (_a.label) {
1803
- case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_withdraw_one_coin(_lpTokenAmount, i, useUnderlying, curve_1.curve.options)];
2278
+ case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_withdraw_one_coin(_lpTokenAmount, i, useUnderlying, curve_1.curve.constantOptions)];
1804
2279
  case 1: return [2 /*return*/, _a.sent()];
1805
2280
  }
1806
2281
  });
@@ -1816,7 +2291,7 @@ var Pool = /** @class */ (function () {
1816
2291
  case 1:
1817
2292
  _minAmount = (_a.sent()).mul(99).div(100);
1818
2293
  contract = curve_1.curve.contracts[this.swap].contract;
1819
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.options)];
2294
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
1820
2295
  case 2:
1821
2296
  gas = _a.sent();
1822
2297
  if (estimateGas) {
@@ -1837,7 +2312,7 @@ var Pool = /** @class */ (function () {
1837
2312
  switch (_a.label) {
1838
2313
  case 0:
1839
2314
  if (!!estimateGas) return [3 /*break*/, 2];
1840
- return [4 /*yield*/, utils_1._ensureAllowance([this.lpToken], [_lpTokenAmount], this.zap)];
2315
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
1841
2316
  case 1:
1842
2317
  _a.sent();
1843
2318
  _a.label = 2;
@@ -1846,7 +2321,7 @@ var Pool = /** @class */ (function () {
1846
2321
  _minAmount = (_a.sent()).mul(99).div(100);
1847
2322
  contract = curve_1.curve.contracts[this.zap].contract;
1848
2323
  if (!this.isFactory) return [3 /*break*/, 6];
1849
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, curve_1.curve.options)];
2324
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
1850
2325
  case 4:
1851
2326
  gas_4 = _a.sent();
1852
2327
  if (estimateGas) {
@@ -1855,7 +2330,7 @@ var Pool = /** @class */ (function () {
1855
2330
  gasLimit_4 = gas_4.mul(130).div(100);
1856
2331
  return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_4 }))];
1857
2332
  case 5: return [2 /*return*/, (_a.sent()).hash];
1858
- case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.options)];
2333
+ case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
1859
2334
  case 7:
1860
2335
  gas = _a.sent();
1861
2336
  if (estimateGas) {
@@ -1873,31 +2348,31 @@ var Pool = /** @class */ (function () {
1873
2348
  if (estimateGas === void 0) { estimateGas = false; }
1874
2349
  return __awaiter(_this, void 0, void 0, function () {
1875
2350
  var _minAmount, _a, contract, gas, gasLimit;
1876
- return __generator(this, function (_b) {
1877
- switch (_b.label) {
2351
+ return __generator(this, function (_c) {
2352
+ switch (_c.label) {
1878
2353
  case 0:
1879
2354
  if (!(this.name === 'ib')) return [3 /*break*/, 2];
1880
2355
  return [4 /*yield*/, this._calcWithdrawOneCoin(_lpTokenAmount, i, useUnderlying)];
1881
2356
  case 1:
1882
- _a = _b.sent();
2357
+ _a = _c.sent();
1883
2358
  return [3 /*break*/, 4];
1884
2359
  case 2: return [4 /*yield*/, this._calcWithdrawOneCoinSwap(_lpTokenAmount, i)];
1885
2360
  case 3:
1886
- _a = _b.sent();
1887
- _b.label = 4;
2361
+ _a = _c.sent();
2362
+ _c.label = 4;
1888
2363
  case 4:
1889
2364
  _minAmount = _a;
1890
2365
  _minAmount = _minAmount.mul(99).div(100);
1891
2366
  contract = curve_1.curve.contracts[this.swap].contract;
1892
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, useUnderlying, curve_1.curve.options)];
2367
+ return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, useUnderlying, curve_1.curve.constantOptions)];
1893
2368
  case 5:
1894
- gas = _b.sent();
2369
+ gas = _c.sent();
1895
2370
  if (estimateGas) {
1896
2371
  return [2 /*return*/, gas.toNumber()];
1897
2372
  }
1898
2373
  gasLimit = gas.mul(130).div(100);
1899
2374
  return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1900
- case 6: return [2 /*return*/, (_b.sent()).hash];
2375
+ case 6: return [2 /*return*/, (_c.sent()).hash];
1901
2376
  }
1902
2377
  });
1903
2378
  });
@@ -1909,9 +2384,9 @@ var Pool = /** @class */ (function () {
1909
2384
  case 0:
1910
2385
  contract = curve_1.curve.contracts[this.swap].contract;
1911
2386
  if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
1912
- return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.options)];
2387
+ return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
1913
2388
  case 1: return [2 /*return*/, _a.sent()];
1914
- case 2: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.options)];
2389
+ case 2: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
1915
2390
  case 3: return [2 /*return*/, _a.sent()];
1916
2391
  }
1917
2392
  });
@@ -1919,7 +2394,7 @@ var Pool = /** @class */ (function () {
1919
2394
  this._getExchangeOutputWrapped = function (i, j, _amount) { return __awaiter(_this, void 0, void 0, function () {
1920
2395
  return __generator(this, function (_a) {
1921
2396
  switch (_a.label) {
1922
- case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.get_dy(i, j, _amount, curve_1.curve.options)];
2397
+ case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
1923
2398
  case 1: return [2 /*return*/, _a.sent()];
1924
2399
  }
1925
2400
  });
@@ -1941,22 +2416,33 @@ var Pool = /** @class */ (function () {
1941
2416
  this.basePool = poolData.base_pool || '';
1942
2417
  this.isFactory = poolData.is_factory || false;
1943
2418
  this.estimateGas = {
2419
+ addLiquidityApprove: this.addLiquidityApproveEstimateGas,
1944
2420
  addLiquidity: this.addLiquidityEstimateGas,
2421
+ addLiquidityWrappedApprove: this.addLiquidityWrappedApproveEstimateGas,
1945
2422
  addLiquidityWrapped: this.addLiquidityWrappedEstimateGas,
2423
+ gaugeDepositApprove: this.gaugeDepositApproveEstimateGas,
2424
+ gaugeDeposit: this.gaugeDepositEstimateGas,
2425
+ gaugeWithdraw: this.gaugeWithdrawEstimateGas,
2426
+ removeLiquidityApprove: this.removeLiquidityApproveEstimateGas,
1946
2427
  removeLiquidity: this.removeLiquidityEstimateGas,
1947
2428
  removeLiquidityWrapped: this.removeLiquidityWrappedEstimateGas,
2429
+ removeLiquidityImbalanceApprove: this.removeLiquidityImbalanceApproveEstimateGas,
1948
2430
  removeLiquidityImbalance: this.removeLiquidityImbalanceEstimateGas,
1949
2431
  removeLiquidityImbalanceWrapped: this.removeLiquidityImbalanceWrappedEstimateGas,
2432
+ removeLiquidityOneCoinApprove: this.removeLiquidityOneCoinApproveEstimateGas,
1950
2433
  removeLiquidityOneCoin: this.removeLiquidityOneCoinEstimateGas,
1951
2434
  removeLiquidityOneCoinWrapped: this.removeLiquidityOneCoinWrappedEstimateGas,
2435
+ exchangeApprove: this.exchangeApproveEstimateGas,
1952
2436
  exchange: this.exchangeEstimateGas,
2437
+ exchangeTricryptoApprove: this.exchangeTricryptoApproveEstimateGas,
1953
2438
  exchangeTricrypto: this.exchangeTricryptoEstimateGas,
2439
+ exchangeWrappedApprove: this.exchangeWrappedApproveEstimateGas,
1954
2440
  exchangeWrapped: this.exchangeWrappedEstimateGas,
1955
2441
  };
1956
2442
  if (this.isMeta) {
1957
2443
  var metaCoins = poolData.meta_coin_addresses;
1958
2444
  var metaCoinDecimals = poolData.meta_coin_decimals;
1959
- this.underlyingCoinAddresses = __spreadArray([this.underlyingCoinAddresses[0]], metaCoins);
2445
+ this.underlyingCoinAddresses = __spreadArray([this.underlyingCoinAddresses[0]], metaCoins, true);
1960
2446
  this.underlyingDecimals = metaCoinDecimals;
1961
2447
  }
1962
2448
  }
@@ -1966,37 +2452,37 @@ exports.Pool = Pool;
1966
2452
  // --------- Exchange Using All Pools ---------
1967
2453
  var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount) { return __awaiter(void 0, void 0, void 0, function () {
1968
2454
  var tricryptoCoins, addressProviderContract, registryExchangeAddress, registryExchangeContract, _amount, _a, poolAddress, output;
1969
- return __generator(this, function (_b) {
1970
- switch (_b.label) {
2455
+ return __generator(this, function (_c) {
2456
+ switch (_c.label) {
1971
2457
  case 0:
1972
2458
  tricryptoCoins = [coins_1.COINS.usdt.toLowerCase(), coins_1.COINS.wbtc.toLowerCase(), coins_1.COINS.weth.toLowerCase()];
1973
2459
  if (tricryptoCoins.includes(inputCoinAddress.toLowerCase()) && tricryptoCoins.includes(outputCoinAddress.toLowerCase())) {
1974
2460
  throw new Error("This pair can't be exchanged");
1975
2461
  }
1976
2462
  addressProviderContract = curve_1.curve.contracts[curve_1.ALIASES.address_provider].contract;
1977
- return [4 /*yield*/, addressProviderContract.get_address(2, curve_1.curve.options)];
2463
+ return [4 /*yield*/, addressProviderContract.get_address(2, curve_1.curve.constantOptions)];
1978
2464
  case 1:
1979
- registryExchangeAddress = _b.sent();
2465
+ registryExchangeAddress = _c.sent();
1980
2466
  registryExchangeContract = new ethers_1.ethers.Contract(registryExchangeAddress, registry_exchange_json_1.default, curve_1.curve.signer || curve_1.curve.provider);
1981
2467
  _amount = ethers_1.ethers.utils.parseUnits(amount.toString(), inputCoinDecimals);
1982
- return [4 /*yield*/, registryExchangeContract.get_best_rate(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.options)];
2468
+ return [4 /*yield*/, registryExchangeContract.get_best_rate(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
1983
2469
  case 2:
1984
- _a = _b.sent(), poolAddress = _a[0], output = _a[1];
2470
+ _a = _c.sent(), poolAddress = _a[0], output = _a[1];
1985
2471
  return [2 /*return*/, { poolAddress: poolAddress, output: output }];
1986
2472
  }
1987
2473
  });
1988
2474
  }); };
1989
2475
  exports._getBestPoolAndOutput = _getBestPoolAndOutput;
1990
2476
  var getBestPoolAndOutput = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
1991
- var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _c, poolAddress, _output, output;
1992
- return __generator(this, function (_d) {
1993
- switch (_d.label) {
2477
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, output;
2478
+ return __generator(this, function (_e) {
2479
+ switch (_e.label) {
1994
2480
  case 0:
1995
- _a = utils_1._getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
1996
- _b = utils_1._getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
1997
- return [4 /*yield*/, exports._getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
2481
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2482
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2483
+ return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
1998
2484
  case 1:
1999
- _c = _d.sent(), poolAddress = _c.poolAddress, _output = _c.output;
2485
+ _d = _e.sent(), poolAddress = _d.poolAddress, _output = _d.output;
2000
2486
  output = ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals);
2001
2487
  return [2 /*return*/, { poolAddress: poolAddress, output: output }];
2002
2488
  }
@@ -2006,7 +2492,7 @@ exports.getBestPoolAndOutput = getBestPoolAndOutput;
2006
2492
  var exchangeExpected = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2007
2493
  return __generator(this, function (_a) {
2008
2494
  switch (_a.label) {
2009
- case 0: return [4 /*yield*/, exports.getBestPoolAndOutput(inputCoin, outputCoin, amount)];
2495
+ case 0: return [4 /*yield*/, (0, exports.getBestPoolAndOutput)(inputCoin, outputCoin, amount)];
2010
2496
  case 1: return [2 /*return*/, (_a.sent())['output']];
2011
2497
  }
2012
2498
  });
@@ -2015,35 +2501,35 @@ exports.exchangeExpected = exchangeExpected;
2015
2501
  var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
2016
2502
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
2017
2503
  return __awaiter(void 0, void 0, void 0, function () {
2018
- var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, addressProviderContract, registryAddress, registryContract, poolAddress, poolName, _b, _i, _j, is_underlying, i, j, pool;
2019
- return __generator(this, function (_c) {
2020
- switch (_c.label) {
2504
+ var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, addressProviderContract, registryAddress, registryContract, poolAddress, poolName, _c, _i, _j, is_underlying, i, j, pool;
2505
+ return __generator(this, function (_d) {
2506
+ switch (_d.label) {
2021
2507
  case 0:
2022
- _a = utils_1._getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2023
- inputCoinDecimals = utils_1._getCoinDecimals(inputCoinAddress)[0];
2508
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2509
+ inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
2024
2510
  addressProviderContract = curve_1.curve.contracts[curve_1.ALIASES.address_provider].contract;
2025
2511
  return [4 /*yield*/, addressProviderContract.get_registry()];
2026
2512
  case 1:
2027
- registryAddress = _c.sent();
2513
+ registryAddress = _d.sent();
2028
2514
  registryContract = new ethers_1.ethers.Contract(registryAddress, registry_json_1.default, curve_1.curve.signer);
2029
- return [4 /*yield*/, exports._getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
2515
+ return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
2030
2516
  case 2:
2031
- poolAddress = (_c.sent()).poolAddress;
2517
+ poolAddress = (_d.sent()).poolAddress;
2032
2518
  if (poolAddress === "0x0000000000000000000000000000000000000000") {
2033
2519
  throw new Error("This pair can't be exchanged");
2034
2520
  }
2035
- poolName = utils_1.getPoolNameBySwapAddress(poolAddress);
2521
+ poolName = (0, utils_1.getPoolNameBySwapAddress)(poolAddress);
2036
2522
  return [4 /*yield*/, registryContract.get_coin_indices(poolAddress, inputCoinAddress, outputCoinAddress)];
2037
2523
  case 3:
2038
- _b = _c.sent(), _i = _b[0], _j = _b[1], is_underlying = _b[2];
2524
+ _c = _d.sent(), _i = _c[0], _j = _c[1], is_underlying = _c[2];
2039
2525
  i = Number(_i.toString());
2040
2526
  j = Number(_j.toString());
2041
2527
  pool = new Pool(poolName);
2042
2528
  if (!is_underlying) return [3 /*break*/, 5];
2043
2529
  return [4 /*yield*/, pool.estimateGas.exchange(i, j, amount, maxSlippage)];
2044
- case 4: return [2 /*return*/, _c.sent()];
2530
+ case 4: return [2 /*return*/, _d.sent()];
2045
2531
  case 5: return [4 /*yield*/, pool.estimateGas.exchangeWrapped(i, j, amount, maxSlippage)];
2046
- case 6: return [2 /*return*/, _c.sent()];
2532
+ case 6: return [2 /*return*/, _d.sent()];
2047
2533
  }
2048
2534
  });
2049
2535
  });
@@ -2052,35 +2538,35 @@ exports.exchangeEstimateGas = exchangeEstimateGas;
2052
2538
  var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
2053
2539
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
2054
2540
  return __awaiter(void 0, void 0, void 0, function () {
2055
- var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, addressProviderContract, registryAddress, registryContract, poolAddress, poolName, _b, _i, _j, is_underlying, i, j, pool;
2056
- return __generator(this, function (_c) {
2057
- switch (_c.label) {
2541
+ var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, addressProviderContract, registryAddress, registryContract, poolAddress, poolName, _c, _i, _j, is_underlying, i, j, pool;
2542
+ return __generator(this, function (_d) {
2543
+ switch (_d.label) {
2058
2544
  case 0:
2059
- _a = utils_1._getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2060
- inputCoinDecimals = utils_1._getCoinDecimals(inputCoinAddress)[0];
2545
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2546
+ inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
2061
2547
  addressProviderContract = curve_1.curve.contracts[curve_1.ALIASES.address_provider].contract;
2062
2548
  return [4 /*yield*/, addressProviderContract.get_registry()];
2063
2549
  case 1:
2064
- registryAddress = _c.sent();
2550
+ registryAddress = _d.sent();
2065
2551
  registryContract = new ethers_1.ethers.Contract(registryAddress, registry_json_1.default, curve_1.curve.signer);
2066
- return [4 /*yield*/, exports._getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
2552
+ return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
2067
2553
  case 2:
2068
- poolAddress = (_c.sent()).poolAddress;
2554
+ poolAddress = (_d.sent()).poolAddress;
2069
2555
  if (poolAddress === "0x0000000000000000000000000000000000000000") {
2070
2556
  throw new Error("This pair can't be exchanged");
2071
2557
  }
2072
- poolName = utils_1.getPoolNameBySwapAddress(poolAddress);
2558
+ poolName = (0, utils_1.getPoolNameBySwapAddress)(poolAddress);
2073
2559
  return [4 /*yield*/, registryContract.get_coin_indices(poolAddress, inputCoinAddress, outputCoinAddress)];
2074
2560
  case 3:
2075
- _b = _c.sent(), _i = _b[0], _j = _b[1], is_underlying = _b[2];
2561
+ _c = _d.sent(), _i = _c[0], _j = _c[1], is_underlying = _c[2];
2076
2562
  i = Number(_i.toString());
2077
2563
  j = Number(_j.toString());
2078
2564
  pool = new Pool(poolName);
2079
2565
  if (!is_underlying) return [3 /*break*/, 5];
2080
2566
  return [4 /*yield*/, pool.exchange(i, j, amount, maxSlippage)];
2081
- case 4: return [2 /*return*/, _c.sent()];
2567
+ case 4: return [2 /*return*/, _d.sent()];
2082
2568
  case 5: return [4 /*yield*/, pool.exchangeWrapped(i, j, amount, maxSlippage)];
2083
- case 6: return [2 /*return*/, _c.sent()];
2569
+ case 6: return [2 /*return*/, _d.sent()];
2084
2570
  }
2085
2571
  });
2086
2572
  });
@@ -2089,14 +2575,14 @@ exports.exchange = exchange;
2089
2575
  // --------- Cross-Asset Exchange ---------
2090
2576
  var crossAssetExchangeAvailable = function (inputCoin, outputCoin) { return __awaiter(void 0, void 0, void 0, function () {
2091
2577
  var _a, inputCoinAddress, outputCoinAddress, routerContract;
2092
- return __generator(this, function (_b) {
2093
- switch (_b.label) {
2578
+ return __generator(this, function (_c) {
2579
+ switch (_c.label) {
2094
2580
  case 0:
2095
- _a = utils_1._getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2581
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2096
2582
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
2097
2583
  case 1:
2098
- routerContract = _b.sent();
2099
- return [2 /*return*/, routerContract.can_route(inputCoinAddress, outputCoinAddress, curve_1.curve.options)];
2584
+ routerContract = _c.sent();
2585
+ return [2 /*return*/, routerContract.can_route(inputCoinAddress, outputCoinAddress, curve_1.curve.constantOptions)];
2100
2586
  }
2101
2587
  });
2102
2588
  }); };
@@ -2113,25 +2599,25 @@ var _getSmallAmountForCoin = function (coinAddress) {
2113
2599
  };
2114
2600
  exports._getSmallAmountForCoin = _getSmallAmountForCoin;
2115
2601
  var _crossAssetExchangeInfo = function (inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount) { return __awaiter(void 0, void 0, void 0, function () {
2116
- var routerContract, _amount, amountBN, _a, route, indices, _expected, expectedBN, exchangeRateBN, _smallAmount, smallAmountBN, _b, _expectedSmall, expectedSmallBN, exchangeSmallRateBN, slippage;
2117
- return __generator(this, function (_c) {
2118
- switch (_c.label) {
2602
+ var routerContract, _amount, amountBN, _a, route, indices, _expected, expectedBN, exchangeRateBN, _smallAmount, smallAmountBN, _c, _expectedSmall, expectedSmallBN, exchangeSmallRateBN, slippage;
2603
+ return __generator(this, function (_d) {
2604
+ switch (_d.label) {
2119
2605
  case 0: return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
2120
2606
  case 1:
2121
- routerContract = _c.sent();
2607
+ routerContract = _d.sent();
2122
2608
  _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2123
- amountBN = utils_1.toBN(_amount, inputCoinDecimals);
2124
- return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.options)];
2609
+ amountBN = (0, utils_1.toBN)(_amount, inputCoinDecimals);
2610
+ return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
2125
2611
  case 2:
2126
- _a = _c.sent(), route = _a[0], indices = _a[1], _expected = _a[2];
2127
- expectedBN = utils_1.toBN(_expected, outputCoinDecimals);
2612
+ _a = _d.sent(), route = _a[0], indices = _a[1], _expected = _a[2];
2613
+ expectedBN = (0, utils_1.toBN)(_expected, outputCoinDecimals);
2128
2614
  exchangeRateBN = expectedBN.div(amountBN);
2129
- _smallAmount = ethers_1.ethers.utils.parseUnits(exports._getSmallAmountForCoin(inputCoinAddress), inputCoinDecimals);
2130
- smallAmountBN = utils_1.toBN(_smallAmount, inputCoinDecimals);
2131
- return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _smallAmount, curve_1.curve.options)];
2615
+ _smallAmount = ethers_1.ethers.utils.parseUnits((0, exports._getSmallAmountForCoin)(inputCoinAddress), inputCoinDecimals);
2616
+ smallAmountBN = (0, utils_1.toBN)(_smallAmount, inputCoinDecimals);
2617
+ return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _smallAmount, curve_1.curve.constantOptions)];
2132
2618
  case 3:
2133
- _b = _c.sent(), _expectedSmall = _b[2];
2134
- expectedSmallBN = utils_1.toBN(_expectedSmall, outputCoinDecimals);
2619
+ _c = _d.sent(), _expectedSmall = _c[2];
2620
+ expectedSmallBN = (0, utils_1.toBN)(_expectedSmall, outputCoinDecimals);
2135
2621
  exchangeSmallRateBN = expectedSmallBN.div(smallAmountBN);
2136
2622
  slippage = 1 - exchangeRateBN.div(exchangeSmallRateBN).toNumber();
2137
2623
  return [2 /*return*/, { route: route, indices: indices, _expected: _expected, slippage: slippage }];
@@ -2140,15 +2626,15 @@ var _crossAssetExchangeInfo = function (inputCoinAddress, outputCoinAddress, inp
2140
2626
  }); };
2141
2627
  exports._crossAssetExchangeInfo = _crossAssetExchangeInfo;
2142
2628
  var crossAssetExchangeOutputAndSlippage = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2143
- var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _c, _expected, slippage, output;
2144
- return __generator(this, function (_d) {
2145
- switch (_d.label) {
2629
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, _expected, slippage, output;
2630
+ return __generator(this, function (_e) {
2631
+ switch (_e.label) {
2146
2632
  case 0:
2147
- _a = utils_1._getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2148
- _b = utils_1._getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
2149
- return [4 /*yield*/, exports._crossAssetExchangeInfo(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2633
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2634
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2635
+ return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2150
2636
  case 1:
2151
- _c = _d.sent(), _expected = _c._expected, slippage = _c.slippage;
2637
+ _d = _e.sent(), _expected = _d._expected, slippage = _d.slippage;
2152
2638
  output = ethers_1.ethers.utils.formatUnits(_expected, outputCoinDecimals);
2153
2639
  return [2 /*return*/, { output: output, slippage: slippage }];
2154
2640
  }
@@ -2156,19 +2642,19 @@ var crossAssetExchangeOutputAndSlippage = function (inputCoin, outputCoin, amoun
2156
2642
  }); };
2157
2643
  exports.crossAssetExchangeOutputAndSlippage = crossAssetExchangeOutputAndSlippage;
2158
2644
  var crossAssetExchangeExpected = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2159
- var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, routerContract, _amount, _c, _expected;
2160
- return __generator(this, function (_d) {
2161
- switch (_d.label) {
2645
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, routerContract, _amount, _d, _expected;
2646
+ return __generator(this, function (_e) {
2647
+ switch (_e.label) {
2162
2648
  case 0:
2163
- _a = utils_1._getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2164
- _b = utils_1._getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
2649
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2650
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2165
2651
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
2166
2652
  case 1:
2167
- routerContract = _d.sent();
2653
+ routerContract = _e.sent();
2168
2654
  _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2169
- return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.options)];
2655
+ return [4 /*yield*/, routerContract.get_exchange_routing(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
2170
2656
  case 2:
2171
- _c = _d.sent(), _expected = _c[2];
2657
+ _d = _e.sent(), _expected = _d[2];
2172
2658
  return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, outputCoinDecimals)];
2173
2659
  }
2174
2660
  });
@@ -2177,38 +2663,38 @@ exports.crossAssetExchangeExpected = crossAssetExchangeExpected;
2177
2663
  var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
2178
2664
  if (maxSlippage === void 0) { maxSlippage = 0.02; }
2179
2665
  return __awaiter(void 0, void 0, void 0, function () {
2180
- var _a, inputCoinAddress, outputCoinAddress, inputCoinBalance, _b, inputCoinDecimals, outputCoinDecimals, _amount, _c, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract;
2181
- return __generator(this, function (_d) {
2182
- switch (_d.label) {
2183
- case 0: return [4 /*yield*/, exports.crossAssetExchangeAvailable(inputCoin, outputCoin)];
2666
+ var _a, inputCoinAddress, outputCoinAddress, inputCoinBalance, _c, inputCoinDecimals, outputCoinDecimals, _amount, _d, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract;
2667
+ return __generator(this, function (_e) {
2668
+ switch (_e.label) {
2669
+ case 0: return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
2184
2670
  case 1:
2185
- if (!(_d.sent()))
2671
+ if (!(_e.sent()))
2186
2672
  throw Error("Such exchange is not available");
2187
- _a = utils_1._getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2188
- return [4 /*yield*/, utils_1._getBalances([inputCoinAddress], [curve_1.curve.signerAddress])];
2673
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2674
+ return [4 /*yield*/, (0, utils_1._getBalances)([inputCoinAddress], [curve_1.curve.signerAddress])];
2189
2675
  case 2:
2190
- inputCoinBalance = (_d.sent())[curve_1.curve.signerAddress];
2676
+ inputCoinBalance = (_e.sent())[curve_1.curve.signerAddress];
2191
2677
  if (Number(inputCoinBalance) < Number(amount)) {
2192
2678
  throw Error("Not enough " + inputCoin + ". Actual: " + inputCoinBalance + ", required: " + amount);
2193
2679
  }
2194
- return [4 /*yield*/, utils_1.hasAllowance([inputCoinAddress], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.router)];
2680
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoinAddress], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.router)];
2195
2681
  case 3:
2196
- if (!(_d.sent())) {
2682
+ if (!(_e.sent())) {
2197
2683
  throw Error("Token allowance is needed to estimate gas");
2198
2684
  }
2199
- _b = utils_1._getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
2685
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2200
2686
  _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2201
- return [4 /*yield*/, exports._crossAssetExchangeInfo(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2687
+ return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2202
2688
  case 4:
2203
- _c = _d.sent(), route = _c.route, indices = _c.indices, _expected = _c._expected;
2204
- minRecvAmountBN = utils_1.toBN(_expected, outputCoinDecimals).times((1 - maxSlippage));
2205
- _minRecvAmount = utils_1.fromBN(minRecvAmountBN, outputCoinDecimals);
2206
- value = utils_1.isEth(inputCoinAddress) ? _amount : 0;
2689
+ _d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
2690
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times((1 - maxSlippage));
2691
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2692
+ value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
2207
2693
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
2208
2694
  case 5:
2209
- routerContract = _d.sent();
2210
- return [4 /*yield*/, routerContract.estimateGas.exchange(_amount, route, indices, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value }))];
2211
- case 6: return [2 /*return*/, (_d.sent()).toNumber()];
2695
+ routerContract = _e.sent();
2696
+ return [4 /*yield*/, routerContract.estimateGas.exchange(_amount, route, indices, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2697
+ case 6: return [2 /*return*/, (_e.sent()).toNumber()];
2212
2698
  }
2213
2699
  });
2214
2700
  });
@@ -2217,33 +2703,36 @@ exports.crossAssetExchangeEstimateGas = crossAssetExchangeEstimateGas;
2217
2703
  var crossAssetExchange = function (inputCoin, outputCoin, amount, maxSlippage) {
2218
2704
  if (maxSlippage === void 0) { maxSlippage = 0.02; }
2219
2705
  return __awaiter(void 0, void 0, void 0, function () {
2220
- var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _amount, _c, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract, gasLimit;
2221
- return __generator(this, function (_d) {
2222
- switch (_d.label) {
2223
- case 0: return [4 /*yield*/, exports.crossAssetExchangeAvailable(inputCoin, outputCoin)];
2706
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _amount, _d, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract, gasLimit;
2707
+ return __generator(this, function (_e) {
2708
+ switch (_e.label) {
2709
+ case 0: return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
2224
2710
  case 1:
2225
- if (!(_d.sent()))
2711
+ if (!(_e.sent()))
2226
2712
  throw Error("Such exchange is not available");
2227
- _a = utils_1._getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2228
- _b = utils_1._getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
2713
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2714
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2229
2715
  _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2230
- return [4 /*yield*/, exports._crossAssetExchangeInfo(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2716
+ return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2231
2717
  case 2:
2232
- _c = _d.sent(), route = _c.route, indices = _c.indices, _expected = _c._expected;
2233
- minRecvAmountBN = utils_1.toBN(_expected, outputCoinDecimals).times((1 - maxSlippage));
2234
- _minRecvAmount = utils_1.fromBN(minRecvAmountBN, outputCoinDecimals);
2235
- value = utils_1.isEth(inputCoinAddress) ? _amount : 0;
2718
+ _d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
2719
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times((1 - maxSlippage));
2720
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2721
+ value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
2236
2722
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
2237
2723
  case 3:
2238
- routerContract = _d.sent();
2239
- return [4 /*yield*/, utils_1._ensureAllowance([inputCoinAddress], [_amount], curve_1.ALIASES.router)];
2724
+ routerContract = _e.sent();
2725
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([inputCoinAddress], [_amount], curve_1.ALIASES.router)];
2240
2726
  case 4:
2241
- _d.sent();
2242
- return [4 /*yield*/, routerContract.estimateGas.exchange(_amount, route, indices, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value }))];
2727
+ _e.sent();
2728
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
2243
2729
  case 5:
2244
- gasLimit = (_d.sent()).mul(130).div(100);
2730
+ _e.sent();
2731
+ return [4 /*yield*/, routerContract.estimateGas.exchange(_amount, route, indices, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2732
+ case 6:
2733
+ gasLimit = (_e.sent()).mul(130).div(100);
2245
2734
  return [4 /*yield*/, routerContract.exchange(_amount, route, indices, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
2246
- case 6: return [2 /*return*/, (_d.sent()).hash];
2735
+ case 7: return [2 /*return*/, (_e.sent()).hash];
2247
2736
  }
2248
2737
  });
2249
2738
  });