@curvefi/api 2.63.0 → 2.63.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/lib/boosting.js +247 -645
  2. package/lib/constants/L2Networks.js +1 -1
  3. package/lib/constants/aliases.js +19 -19
  4. package/lib/constants/coins/arbitrum.js +5 -5
  5. package/lib/constants/coins/aurora.js +5 -5
  6. package/lib/constants/coins/avalanche.js +6 -6
  7. package/lib/constants/coins/base.js +5 -5
  8. package/lib/constants/coins/bsc.js +5 -5
  9. package/lib/constants/coins/celo.js +5 -5
  10. package/lib/constants/coins/ethereum.js +9 -9
  11. package/lib/constants/coins/fantom.js +7 -7
  12. package/lib/constants/coins/fraxtal.js +5 -5
  13. package/lib/constants/coins/kava.js +5 -5
  14. package/lib/constants/coins/mantle.js +5 -5
  15. package/lib/constants/coins/moonbeam.js +5 -5
  16. package/lib/constants/coins/optimism.js +5 -5
  17. package/lib/constants/coins/polygon.js +6 -6
  18. package/lib/constants/coins/xdai.js +5 -5
  19. package/lib/constants/coins/xlayer.js +5 -5
  20. package/lib/constants/coins/zksync.js +5 -5
  21. package/lib/constants/pools/arbitrum.js +1 -1
  22. package/lib/constants/pools/aurora.js +1 -1
  23. package/lib/constants/pools/avalanche.js +1 -1
  24. package/lib/constants/pools/base.js +1 -1
  25. package/lib/constants/pools/bsc.js +1 -1
  26. package/lib/constants/pools/celo.js +1 -1
  27. package/lib/constants/pools/ethereum.js +2 -2
  28. package/lib/constants/pools/fantom.js +1 -1
  29. package/lib/constants/pools/fraxtal.js +1 -1
  30. package/lib/constants/pools/kava.js +1 -1
  31. package/lib/constants/pools/mantle.js +1 -1
  32. package/lib/constants/pools/moonbeam.js +1 -1
  33. package/lib/constants/pools/optimism.js +1 -1
  34. package/lib/constants/pools/polygon.js +1 -1
  35. package/lib/constants/pools/xdai.js +1 -1
  36. package/lib/constants/pools/xlayer.js +1 -1
  37. package/lib/constants/pools/zksync.js +1 -1
  38. package/lib/constants/tricryptoDeployImplementations.js +1 -1
  39. package/lib/constants/utils.js +18 -19
  40. package/lib/constants/volumeNetworks.js +1 -1
  41. package/lib/curve.d.ts +3 -1
  42. package/lib/curve.js +534 -909
  43. package/lib/dao.js +351 -705
  44. package/lib/external-api.js +127 -256
  45. package/lib/factory/common.js +4 -4
  46. package/lib/factory/constants-crypto.js +33 -33
  47. package/lib/factory/constants.js +34 -34
  48. package/lib/factory/deploy.js +542 -907
  49. package/lib/factory/factory-api.js +205 -269
  50. package/lib/factory/factory-crypto.js +202 -342
  51. package/lib/factory/factory-tricrypto.js +164 -286
  52. package/lib/factory/factory-twocrypto.js +151 -269
  53. package/lib/factory/factory.js +245 -385
  54. package/lib/index.js +109 -198
  55. package/lib/interfaces.d.ts +1 -6
  56. package/lib/pools/PoolTemplate.js +1773 -3025
  57. package/lib/pools/gaugePool.js +112 -251
  58. package/lib/pools/mixins/common.js +22 -93
  59. package/lib/pools/mixins/depositBalancedAmountsMixins.js +52 -118
  60. package/lib/pools/mixins/depositMixins.js +160 -386
  61. package/lib/pools/mixins/depositWrappedMixins.js +79 -205
  62. package/lib/pools/mixins/poolBalancesMixin.js +24 -87
  63. package/lib/pools/mixins/swapMixins.js +139 -324
  64. package/lib/pools/mixins/swapWrappedMixins.js +111 -265
  65. package/lib/pools/mixins/withdrawExpectedMixins.js +27 -91
  66. package/lib/pools/mixins/withdrawImbalanceMixins.js +111 -293
  67. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +58 -169
  68. package/lib/pools/mixins/withdrawMixins.js +139 -359
  69. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +20 -75
  70. package/lib/pools/mixins/withdrawOneCoinMixins.js +140 -360
  71. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +10 -51
  72. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +60 -167
  73. package/lib/pools/mixins/withdrawWrappedMixins.js +57 -167
  74. package/lib/pools/poolConstructor.js +5 -25
  75. package/lib/pools/utils.js +301 -469
  76. package/lib/route-finder.worker.d.ts +9 -0
  77. package/lib/route-finder.worker.js +112 -0
  78. package/lib/route-graph.worker.d.ts +11 -0
  79. package/lib/route-graph.worker.js +334 -0
  80. package/lib/router.js +323 -912
  81. package/lib/utils.d.ts +5 -4
  82. package/lib/utils.js +539 -918
  83. package/package.json +1 -1
@@ -1,14 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18,296 +7,153 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
19
8
  });
20
9
  };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
10
  import { curve } from "../../curve.js";
49
11
  import { _ensureAllowance, _getCoinDecimals, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
50
12
  // @ts-ignore
51
- function _swapWrappedCheck(inputCoin, outputCoin, amount, estimateGas) {
52
- if (estimateGas === void 0) { estimateGas = false; }
53
- return __awaiter(this, void 0, void 0, function () {
54
- var i, j, inputCoinBalance, _a, _b, _c, _amount;
55
- return __generator(this, function (_d) {
56
- switch (_d.label) {
57
- case 0:
58
- i = this._getCoinIdx(inputCoin, false);
59
- j = this._getCoinIdx(outputCoin, false);
60
- _b = (_a = Object).values;
61
- return [4 /*yield*/, this.wallet.wrappedCoinBalances()];
62
- case 1:
63
- inputCoinBalance = _b.apply(_a, [_d.sent()])[i];
64
- if (Number(inputCoinBalance) < Number(amount)) {
65
- throw Error("Not enough ".concat(this.wrappedCoins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
66
- }
67
- _c = estimateGas;
68
- if (!_c) return [3 /*break*/, 3];
69
- return [4 /*yield*/, hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address)];
70
- case 2:
71
- _c = !(_d.sent());
72
- _d.label = 3;
73
- case 3:
74
- if (_c) {
75
- throw Error("Token allowance is needed to estimate gas");
76
- }
77
- if (!!estimateGas) return [3 /*break*/, 5];
78
- return [4 /*yield*/, curve.updateFeeData()];
79
- case 4:
80
- _d.sent();
81
- _d.label = 5;
82
- case 5:
83
- _amount = parseUnits(amount, this.wrappedDecimals[i]);
84
- return [2 /*return*/, [i, j, _amount]];
85
- }
86
- });
13
+ function _swapWrappedCheck(inputCoin, outputCoin, amount, estimateGas = false) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ // @ts-ignore
16
+ const i = this._getCoinIdx(inputCoin, false);
17
+ // @ts-ignore
18
+ const j = this._getCoinIdx(outputCoin, false);
19
+ const inputCoinBalance = Object.values(yield this.wallet.wrappedCoinBalances())[i];
20
+ if (Number(inputCoinBalance) < Number(amount)) {
21
+ throw Error(`Not enough ${this.wrappedCoins[i]}. Actual: ${inputCoinBalance}, required: ${amount}`);
22
+ }
23
+ if (estimateGas && !(yield hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address))) {
24
+ throw Error("Token allowance is needed to estimate gas");
25
+ }
26
+ if (!estimateGas)
27
+ yield curve.updateFeeData();
28
+ const _amount = parseUnits(amount, this.wrappedDecimals[i]);
29
+ return [i, j, _amount];
87
30
  });
88
31
  }
89
- function _swapWrappedMinAmount(i, j, _amount, slippage) {
90
- if (slippage === void 0) { slippage = 0.5; }
91
- return __awaiter(this, void 0, void 0, function () {
92
- var _expected, outputCoinDecimals, minAmountBN;
93
- return __generator(this, function (_a) {
94
- switch (_a.label) {
95
- case 0: return [4 /*yield*/, this._swapWrappedExpected(i, j, _amount)];
96
- case 1:
97
- _expected = _a.sent();
98
- outputCoinDecimals = _getCoinDecimals(this.wrappedCoinAddresses[j])[0];
99
- minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
100
- return [2 /*return*/, fromBN(minAmountBN, outputCoinDecimals)];
101
- }
102
- });
32
+ function _swapWrappedMinAmount(i, j, _amount, slippage = 0.5) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ // @ts-ignore
35
+ const _expected = yield this._swapWrappedExpected(i, j, _amount);
36
+ const [outputCoinDecimals] = _getCoinDecimals(this.wrappedCoinAddresses[j]);
37
+ const minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
38
+ return fromBN(minAmountBN, outputCoinDecimals);
103
39
  });
104
40
  }
105
41
  // @ts-ignore
106
- export var swapWrappedTricrypto2Mixin = {
42
+ export const swapWrappedTricrypto2Mixin = {
107
43
  // @ts-ignore
108
- _swapWrapped: function (i, j, _amount, slippage, estimateGas) {
109
- if (estimateGas === void 0) { estimateGas = false; }
110
- return __awaiter(this, void 0, void 0, function () {
111
- var _minRecvAmount, contract, value, gas, gasLimit;
112
- return __generator(this, function (_a) {
113
- switch (_a.label) {
114
- case 0:
115
- if (!!estimateGas) return [3 /*break*/, 2];
116
- return [4 /*yield*/, _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address)];
117
- case 1:
118
- _a.sent();
119
- _a.label = 2;
120
- case 2: return [4 /*yield*/, _swapWrappedMinAmount.call(this, i, j, _amount, slippage)];
121
- case 3:
122
- _minRecvAmount = _a.sent();
123
- contract = curve.contracts[this.address].contract;
124
- value = isEth(this.wrappedCoinAddresses[i]) ? _amount : curve.parseUnits("0");
125
- return [4 /*yield*/, contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve.constantOptions), { value: value }))];
126
- case 4:
127
- gas = _a.sent();
128
- if (estimateGas)
129
- return [2 /*return*/, smartNumber(gas)];
130
- gasLimit = mulBy1_3(DIGas(gas));
131
- return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
132
- case 5: return [2 /*return*/, (_a.sent()).hash];
133
- }
134
- });
44
+ _swapWrapped(i, j, _amount, slippage, estimateGas = false) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ if (!estimateGas)
47
+ yield _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
48
+ const _minRecvAmount = yield _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
49
+ const contract = curve.contracts[this.address].contract;
50
+ const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : curve.parseUnits("0");
51
+ const gas = yield contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, false, Object.assign(Object.assign({}, curve.constantOptions), { value }));
52
+ if (estimateGas)
53
+ return smartNumber(gas);
54
+ const gasLimit = mulBy1_3(DIGas(gas));
55
+ return (yield contract.exchange(i, j, _amount, _minRecvAmount, false, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
135
56
  });
136
57
  },
137
- swapWrappedEstimateGas: function (inputCoin, outputCoin, amount) {
138
- return __awaiter(this, void 0, void 0, function () {
139
- var _a, i, j, _amount;
140
- return __generator(this, function (_b) {
141
- switch (_b.label) {
142
- case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true)];
143
- case 1:
144
- _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
145
- return [4 /*yield*/, this._swapWrapped(i, j, _amount, 0.1, true)];
146
- case 2:
147
- // @ts-ignore
148
- return [2 /*return*/, _b.sent()];
149
- }
150
- });
58
+ swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ // @ts-ignore
61
+ const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
62
+ // @ts-ignore
63
+ return yield this._swapWrapped(i, j, _amount, 0.1, true);
151
64
  });
152
65
  },
153
- swapWrapped: function (inputCoin, outputCoin, amount, slippage) {
154
- return __awaiter(this, void 0, void 0, function () {
155
- var _a, i, j, _amount;
156
- return __generator(this, function (_b) {
157
- switch (_b.label) {
158
- case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount)];
159
- case 1:
160
- _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
161
- return [4 /*yield*/, this._swapWrapped(i, j, _amount, slippage)];
162
- case 2:
163
- // @ts-ignore
164
- return [2 /*return*/, _b.sent()];
165
- }
166
- });
66
+ swapWrapped(inputCoin, outputCoin, amount, slippage) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ // @ts-ignore
69
+ const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
70
+ // @ts-ignore
71
+ return yield this._swapWrapped(i, j, _amount, slippage);
167
72
  });
168
73
  },
169
74
  };
170
75
  // @ts-ignore
171
- export var swapWrappedMixin = {
76
+ export const swapWrappedMixin = {
172
77
  // @ts-ignore
173
- _swapWrapped: function (i, j, _amount, slippage, estimateGas) {
174
- if (estimateGas === void 0) { estimateGas = false; }
175
- return __awaiter(this, void 0, void 0, function () {
176
- var _minRecvAmount, contract, value, gas, gasLimit;
177
- return __generator(this, function (_a) {
178
- switch (_a.label) {
179
- case 0:
180
- if (!!estimateGas) return [3 /*break*/, 2];
181
- return [4 /*yield*/, _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address)];
182
- case 1:
183
- _a.sent();
184
- _a.label = 2;
185
- case 2: return [4 /*yield*/, _swapWrappedMinAmount.call(this, i, j, _amount, slippage)];
186
- case 3:
187
- _minRecvAmount = _a.sent();
188
- contract = curve.contracts[this.address].contract;
189
- value = isEth(this.wrappedCoinAddresses[i]) ? _amount : curve.parseUnits("0");
190
- return [4 /*yield*/, contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.constantOptions), { value: value }))];
191
- case 4:
192
- gas = _a.sent();
193
- if (estimateGas)
194
- return [2 /*return*/, smartNumber(gas)];
195
- gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
196
- return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
197
- case 5: return [2 /*return*/, (_a.sent()).hash];
198
- }
199
- });
78
+ _swapWrapped(i, j, _amount, slippage, estimateGas = false) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ if (!estimateGas)
81
+ yield _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
82
+ const _minRecvAmount = yield _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
83
+ const contract = curve.contracts[this.address].contract;
84
+ const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : curve.parseUnits("0");
85
+ const gas = yield contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.constantOptions), { value }));
86
+ if (estimateGas)
87
+ return smartNumber(gas);
88
+ const gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
89
+ return (yield contract.exchange(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
200
90
  });
201
91
  },
202
- swapWrappedEstimateGas: function (inputCoin, outputCoin, amount) {
203
- return __awaiter(this, void 0, void 0, function () {
204
- var _a, i, j, _amount;
205
- return __generator(this, function (_b) {
206
- switch (_b.label) {
207
- case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true)];
208
- case 1:
209
- _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
210
- return [4 /*yield*/, this._swapWrapped(i, j, _amount, 0.1, true)];
211
- case 2:
212
- // @ts-ignore
213
- return [2 /*return*/, _b.sent()];
214
- }
215
- });
92
+ swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ // @ts-ignore
95
+ const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
96
+ // @ts-ignore
97
+ return yield this._swapWrapped(i, j, _amount, 0.1, true);
216
98
  });
217
99
  },
218
- swapWrapped: function (inputCoin, outputCoin, amount, slippage) {
219
- return __awaiter(this, void 0, void 0, function () {
220
- var _a, i, j, _amount;
221
- return __generator(this, function (_b) {
222
- switch (_b.label) {
223
- case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount)];
224
- case 1:
225
- _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
226
- return [4 /*yield*/, this._swapWrapped(i, j, _amount, slippage)];
227
- case 2:
228
- // @ts-ignore
229
- return [2 /*return*/, _b.sent()];
230
- }
231
- });
100
+ swapWrapped(inputCoin, outputCoin, amount, slippage) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ // @ts-ignore
103
+ const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
104
+ // @ts-ignore
105
+ return yield this._swapWrapped(i, j, _amount, slippage);
232
106
  });
233
107
  },
234
108
  };
235
109
  // @ts-ignore
236
- export var swapWrappedExpectedAndApproveMixin = {
237
- swapWrappedExpected: function (inputCoin, outputCoin, amount) {
238
- return __awaiter(this, void 0, void 0, function () {
239
- var i, j, _amount, _expected;
240
- return __generator(this, function (_a) {
241
- switch (_a.label) {
242
- case 0:
243
- i = this._getCoinIdx(inputCoin, false);
244
- j = this._getCoinIdx(outputCoin, false);
245
- _amount = parseUnits(amount, this.wrappedDecimals[i]);
246
- return [4 /*yield*/, this._swapWrappedExpected(i, j, _amount)];
247
- case 1:
248
- _expected = _a.sent();
249
- return [2 /*return*/, curve.formatUnits(_expected, this.wrappedDecimals[j])];
250
- }
251
- });
110
+ export const swapWrappedExpectedAndApproveMixin = {
111
+ swapWrappedExpected(inputCoin, outputCoin, amount) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ // @ts-ignore
114
+ const i = this._getCoinIdx(inputCoin, false);
115
+ // @ts-ignore
116
+ const j = this._getCoinIdx(outputCoin, false);
117
+ const _amount = parseUnits(amount, this.wrappedDecimals[i]);
118
+ // @ts-ignore
119
+ const _expected = yield this._swapWrappedExpected(i, j, _amount);
120
+ return curve.formatUnits(_expected, this.wrappedDecimals[j]);
252
121
  });
253
122
  },
254
- swapWrappedIsApproved: function (inputCoin, amount) {
255
- return __awaiter(this, void 0, void 0, function () {
256
- var i;
257
- return __generator(this, function (_a) {
258
- switch (_a.label) {
259
- case 0:
260
- i = this._getCoinIdx(inputCoin, false);
261
- return [4 /*yield*/, hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address)];
262
- case 1: return [2 /*return*/, _a.sent()];
263
- }
264
- });
123
+ swapWrappedIsApproved(inputCoin, amount) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ // @ts-ignore
126
+ const i = this._getCoinIdx(inputCoin, false);
127
+ return yield hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address);
265
128
  });
266
129
  },
267
- swapWrappedApproveEstimateGas: function (inputCoin, amount) {
268
- return __awaiter(this, void 0, void 0, function () {
269
- var i;
270
- return __generator(this, function (_a) {
271
- switch (_a.label) {
272
- case 0:
273
- i = this._getCoinIdx(inputCoin, false);
274
- return [4 /*yield*/, ensureAllowanceEstimateGas([this.wrappedCoinAddresses[i]], [amount], this.address)];
275
- case 1: return [2 /*return*/, _a.sent()];
276
- }
277
- });
130
+ swapWrappedApproveEstimateGas(inputCoin, amount) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ // @ts-ignore
133
+ const i = this._getCoinIdx(inputCoin, false);
134
+ return yield ensureAllowanceEstimateGas([this.wrappedCoinAddresses[i]], [amount], this.address);
278
135
  });
279
136
  },
280
- swapWrappedApprove: function (inputCoin, amount) {
281
- return __awaiter(this, void 0, void 0, function () {
282
- var i;
283
- return __generator(this, function (_a) {
284
- switch (_a.label) {
285
- case 0:
286
- i = this._getCoinIdx(inputCoin, false);
287
- return [4 /*yield*/, ensureAllowance([this.wrappedCoinAddresses[i]], [amount], this.address)];
288
- case 1: return [2 /*return*/, _a.sent()];
289
- }
290
- });
137
+ swapWrappedApprove(inputCoin, amount) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ // @ts-ignore
140
+ const i = this._getCoinIdx(inputCoin, false);
141
+ return yield ensureAllowance([this.wrappedCoinAddresses[i]], [amount], this.address);
291
142
  });
292
143
  },
293
144
  };
294
145
  // @ts-ignore
295
- export var swapWrappedRequiredMixin = {
296
- swapWrappedRequired: function (inputCoin, outputCoin, amount) {
297
- return __awaiter(this, void 0, void 0, function () {
298
- var i, j, _amount, _required;
299
- return __generator(this, function (_a) {
300
- switch (_a.label) {
301
- case 0:
302
- i = this._getCoinIdx(inputCoin, false);
303
- j = this._getCoinIdx(outputCoin, false);
304
- _amount = parseUnits(amount, this.wrappedDecimals[j]);
305
- return [4 /*yield*/, this._swapRequired(i, j, _amount, false)];
306
- case 1:
307
- _required = _a.sent();
308
- return [2 /*return*/, curve.formatUnits(_required, this.wrappedDecimals[i])];
309
- }
310
- });
146
+ export const swapWrappedRequiredMixin = {
147
+ swapWrappedRequired(inputCoin, outputCoin, amount) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ // @ts-ignore
150
+ const i = this._getCoinIdx(inputCoin, false);
151
+ // @ts-ignore
152
+ const j = this._getCoinIdx(outputCoin, false);
153
+ const _amount = parseUnits(amount, this.wrappedDecimals[j]);
154
+ // @ts-ignore
155
+ const _required = yield this._swapRequired(i, j, _amount, false);
156
+ return curve.formatUnits(_required, this.wrappedDecimals[i]);
311
157
  });
312
158
  },
313
159
  };
@@ -7,113 +7,49 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
10
  import { curve } from "../../curve.js";
38
11
  import { parseUnits } from "../../utils.js";
39
12
  import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
40
13
  // @ts-ignore
41
- export var withdrawExpectedMixin = {
42
- withdrawExpected: function (lpTokenAmount) {
43
- return __awaiter(this, void 0, void 0, function () {
44
- var _lpTokenAmount, _expected;
45
- var _this = this;
46
- return __generator(this, function (_a) {
47
- switch (_a.label) {
48
- case 0:
49
- _lpTokenAmount = parseUnits(lpTokenAmount);
50
- return [4 /*yield*/, _calcExpectedAmounts.call(this, _lpTokenAmount)];
51
- case 1:
52
- _expected = _a.sent();
53
- return [2 /*return*/, _expected.map(function (amount, i) { return curve.formatUnits(amount, _this.underlyingDecimals[i]); })];
54
- }
55
- });
14
+ export const withdrawExpectedMixin = {
15
+ withdrawExpected(lpTokenAmount) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const _lpTokenAmount = parseUnits(lpTokenAmount);
18
+ const _expected = yield _calcExpectedAmounts.call(this, _lpTokenAmount);
19
+ return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
56
20
  });
57
21
  },
58
22
  };
59
23
  // @ts-ignore
60
- export var withdrawExpectedLendingOrCryptoMixin = {
61
- withdrawExpected: function (lpTokenAmount) {
62
- return __awaiter(this, void 0, void 0, function () {
63
- var _lpTokenAmount, _expectedAmounts, _rates, _expected;
64
- var _this = this;
65
- return __generator(this, function (_a) {
66
- switch (_a.label) {
67
- case 0:
68
- _lpTokenAmount = parseUnits(lpTokenAmount);
69
- return [4 /*yield*/, _calcExpectedAmounts.call(this, _lpTokenAmount)];
70
- case 1:
71
- _expectedAmounts = _a.sent();
72
- return [4 /*yield*/, this._getRates()];
73
- case 2:
74
- _rates = _a.sent();
75
- _expected = _expectedAmounts.map(function (_amount, i) { return _amount * _rates[i] / curve.parseUnits(String(Math.pow(10, 18)), 0); });
76
- return [2 /*return*/, _expected.map(function (amount, i) { return curve.formatUnits(amount, _this.underlyingDecimals[i]); })];
77
- }
78
- });
24
+ export const withdrawExpectedLendingOrCryptoMixin = {
25
+ withdrawExpected(lpTokenAmount) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const _lpTokenAmount = parseUnits(lpTokenAmount);
28
+ const _expectedAmounts = yield _calcExpectedAmounts.call(this, _lpTokenAmount);
29
+ // @ts-ignore
30
+ const _rates = yield this._getRates();
31
+ const _expected = _expectedAmounts.map((_amount, i) => _amount * _rates[i] / curve.parseUnits(String(Math.pow(10, 18)), 0));
32
+ return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
79
33
  });
80
34
  },
81
35
  };
82
36
  // @ts-ignore
83
- export var withdrawExpectedMetaMixin = {
84
- withdrawExpected: function (lpTokenAmount) {
85
- return __awaiter(this, void 0, void 0, function () {
86
- var _lpTokenAmount, _expected;
87
- var _this = this;
88
- return __generator(this, function (_a) {
89
- switch (_a.label) {
90
- case 0:
91
- _lpTokenAmount = parseUnits(lpTokenAmount);
92
- return [4 /*yield*/, _calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount)];
93
- case 1:
94
- _expected = _a.sent();
95
- return [2 /*return*/, _expected.map(function (amount, i) { return curve.formatUnits(amount, _this.underlyingDecimals[i]); })];
96
- }
97
- });
37
+ export const withdrawExpectedMetaMixin = {
38
+ withdrawExpected(lpTokenAmount) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const _lpTokenAmount = parseUnits(lpTokenAmount);
41
+ const _expected = yield _calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount);
42
+ return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
98
43
  });
99
44
  },
100
45
  };
101
46
  // @ts-ignore
102
- export var withdrawWrappedExpectedMixin = {
103
- withdrawWrappedExpected: function (lpTokenAmount) {
104
- return __awaiter(this, void 0, void 0, function () {
105
- var _lpTokenAmount, _expected;
106
- var _this = this;
107
- return __generator(this, function (_a) {
108
- switch (_a.label) {
109
- case 0:
110
- _lpTokenAmount = parseUnits(lpTokenAmount);
111
- return [4 /*yield*/, _calcExpectedAmounts.call(this, _lpTokenAmount)];
112
- case 1:
113
- _expected = _a.sent();
114
- return [2 /*return*/, _expected.map(function (amount, i) { return curve.formatUnits(amount, _this.wrappedDecimals[i]); })];
115
- }
116
- });
47
+ export const withdrawWrappedExpectedMixin = {
48
+ withdrawWrappedExpected(lpTokenAmount) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const _lpTokenAmount = parseUnits(lpTokenAmount);
51
+ const _expected = yield _calcExpectedAmounts.call(this, _lpTokenAmount);
52
+ return _expected.map((amount, i) => curve.formatUnits(amount, this.wrappedDecimals[i]));
117
53
  });
118
54
  },
119
55
  };