@curvefi/api 2.32.0 → 2.33.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 (59) hide show
  1. package/lib/boosting.js +385 -135
  2. package/lib/constants/aliases.js +22 -11
  3. package/lib/constants/coins/arbitrum.js +5 -5
  4. package/lib/constants/coins/aurora.js +5 -5
  5. package/lib/constants/coins/avalanche.js +6 -6
  6. package/lib/constants/coins/celo.js +5 -5
  7. package/lib/constants/coins/ethereum.js +10 -9
  8. package/lib/constants/coins/fantom.js +7 -7
  9. package/lib/constants/coins/kava.js +5 -5
  10. package/lib/constants/coins/moonbeam.js +5 -5
  11. package/lib/constants/coins/optimism.js +5 -5
  12. package/lib/constants/coins/polygon.js +6 -6
  13. package/lib/constants/coins/xdai.js +5 -5
  14. package/lib/constants/pools/arbitrum.js +1 -1
  15. package/lib/constants/pools/aurora.js +1 -1
  16. package/lib/constants/pools/avalanche.js +1 -1
  17. package/lib/constants/pools/celo.js +1 -1
  18. package/lib/constants/pools/ethereum.js +1 -1
  19. package/lib/constants/pools/fantom.js +1 -1
  20. package/lib/constants/pools/kava.js +1 -1
  21. package/lib/constants/pools/moonbeam.js +1 -1
  22. package/lib/constants/pools/optimism.js +1 -1
  23. package/lib/constants/pools/polygon.js +1 -1
  24. package/lib/constants/pools/xdai.js +1 -1
  25. package/lib/constants/utils.js +19 -18
  26. package/lib/curve.js +506 -282
  27. package/lib/external-api.js +132 -45
  28. package/lib/factory/common.js +3 -3
  29. package/lib/factory/constants-crypto.js +21 -21
  30. package/lib/factory/constants.js +32 -31
  31. package/lib/factory/deploy.js +336 -176
  32. package/lib/factory/factory-api.js +256 -180
  33. package/lib/factory/factory-crypto.js +309 -163
  34. package/lib/factory/factory.d.ts +1 -1
  35. package/lib/factory/factory.js +336 -186
  36. package/lib/index.js +98 -44
  37. package/lib/interfaces.d.ts +5 -0
  38. package/lib/pools/PoolTemplate.js +2879 -1468
  39. package/lib/pools/mixins/common.js +106 -22
  40. package/lib/pools/mixins/depositBalancedAmountsMixins.js +131 -48
  41. package/lib/pools/mixins/depositMixins.js +413 -144
  42. package/lib/pools/mixins/depositWrappedMixins.js +223 -72
  43. package/lib/pools/mixins/poolBalancesMixin.js +98 -22
  44. package/lib/pools/mixins/swapMixins.js +347 -125
  45. package/lib/pools/mixins/swapWrappedMixins.js +270 -88
  46. package/lib/pools/mixins/withdrawExpectedMixins.js +104 -23
  47. package/lib/pools/mixins/withdrawImbalanceMixins.js +316 -97
  48. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +187 -51
  49. package/lib/pools/mixins/withdrawMixins.js +385 -122
  50. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +88 -16
  51. package/lib/pools/mixins/withdrawOneCoinMixins.js +386 -123
  52. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +62 -8
  53. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +185 -53
  54. package/lib/pools/mixins/withdrawWrappedMixins.js +185 -50
  55. package/lib/pools/poolConstructor.js +25 -5
  56. package/lib/pools/utils.js +488 -299
  57. package/lib/router.js +675 -212
  58. package/lib/utils.js +675 -354
  59. package/package.json +1 -2
@@ -1,111 +1,293 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
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
+ };
1
48
  import { curve } from "../../curve.js";
2
49
  import { _ensureAllowance, _getCoinDecimals, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, } from "../../utils.js";
3
50
  // @ts-ignore
4
- async function _swapWrappedCheck(inputCoin, outputCoin, amount, estimateGas = false) {
5
- // @ts-ignore
6
- const i = this._getCoinIdx(inputCoin, false);
7
- // @ts-ignore
8
- const j = this._getCoinIdx(outputCoin, false);
9
- const inputCoinBalance = Object.values(await this.wallet.wrappedCoinBalances())[i];
10
- if (Number(inputCoinBalance) < Number(amount)) {
11
- throw Error(`Not enough ${this.wrappedCoins[i]}. Actual: ${inputCoinBalance}, required: ${amount}`);
12
- }
13
- if (estimateGas && !(await hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address))) {
14
- throw Error("Token allowance is needed to estimate gas");
15
- }
16
- if (!estimateGas)
17
- await curve.updateFeeData();
18
- const _amount = parseUnits(amount, this.wrappedDecimals[i]);
19
- return [i, j, _amount];
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
+ });
87
+ });
20
88
  }
21
- async function _swapWrappedMinAmount(i, j, _amount, slippage = 0.5) {
22
- // @ts-ignore
23
- const _expected = await this._swapWrappedExpected(i, j, _amount);
24
- const [outputCoinDecimals] = _getCoinDecimals(this.wrappedCoinAddresses[j]);
25
- const minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
26
- return fromBN(minAmountBN, outputCoinDecimals);
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
+ });
103
+ });
27
104
  }
28
105
  // @ts-ignore
29
- export const swapWrappedTricrypto2Mixin = {
106
+ export var swapWrappedTricrypto2Mixin = {
30
107
  // @ts-ignore
31
- async _swapWrapped(i, j, _amount, slippage, estimateGas = false) {
32
- if (!estimateGas)
33
- await _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
34
- const _minRecvAmount = await _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
35
- const contract = curve.contracts[this.address].contract;
36
- const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : 0n;
37
- const gas = await contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, false, { ...curve.constantOptions, value });
38
- if (estimateGas)
39
- return Number(gas);
40
- const gasLimit = mulBy1_3(gas);
41
- return (await contract.exchange(i, j, _amount, _minRecvAmount, false, { ...curve.options, value, gasLimit })).hash;
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*/, Number(gas)];
130
+ gasLimit = mulBy1_3(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
+ });
135
+ });
42
136
  },
43
- async swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
44
- // @ts-ignore
45
- const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
46
- // @ts-ignore
47
- return await this._swapWrapped(i, j, _amount, 0.1, true);
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
+ });
151
+ });
48
152
  },
49
- async swapWrapped(inputCoin, outputCoin, amount, slippage) {
50
- // @ts-ignore
51
- const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
52
- // @ts-ignore
53
- return await this._swapWrapped(i, j, _amount, slippage);
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
+ });
167
+ });
54
168
  },
55
169
  };
56
170
  // @ts-ignore
57
- export const swapWrappedMixin = {
171
+ export var swapWrappedMixin = {
58
172
  // @ts-ignore
59
- async _swapWrapped(i, j, _amount, slippage, estimateGas = false) {
60
- if (!estimateGas)
61
- await _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
62
- const _minRecvAmount = await _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
63
- const contract = curve.contracts[this.address].contract;
64
- const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : 0n;
65
- const gas = await contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, { ...curve.constantOptions, value });
66
- if (estimateGas)
67
- return Number(gas);
68
- const gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * 140n / 100n : mulBy1_3(gas);
69
- return (await contract.exchange(i, j, _amount, _minRecvAmount, { ...curve.options, value, gasLimit })).hash;
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*/, Number(gas)];
195
+ gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(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
+ });
200
+ });
70
201
  },
71
- async swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
72
- // @ts-ignore
73
- const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
74
- // @ts-ignore
75
- return await this._swapWrapped(i, j, _amount, 0.1, true);
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
+ });
216
+ });
76
217
  },
77
- async swapWrapped(inputCoin, outputCoin, amount, slippage) {
78
- // @ts-ignore
79
- const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
80
- // @ts-ignore
81
- return await this._swapWrapped(i, j, _amount, slippage);
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
+ });
232
+ });
82
233
  },
83
234
  };
84
235
  // @ts-ignore
85
- export const swapWrappedExpectedAndApproveMixin = {
86
- async swapWrappedExpected(inputCoin, outputCoin, amount) {
87
- // @ts-ignore
88
- const i = this._getCoinIdx(inputCoin, false);
89
- // @ts-ignore
90
- const j = this._getCoinIdx(outputCoin, false);
91
- const _amount = parseUnits(amount, this.wrappedDecimals[i]);
92
- // @ts-ignore
93
- const _expected = await this._swapWrappedExpected(i, j, _amount);
94
- return curve.formatUnits(_expected, this.wrappedDecimals[j]);
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
+ });
252
+ });
95
253
  },
96
- async swapWrappedIsApproved(inputCoin, amount) {
97
- // @ts-ignore
98
- const i = this._getCoinIdx(inputCoin, false);
99
- return await hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address);
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
+ });
265
+ });
100
266
  },
101
- async swapWrappedApproveEstimateGas(inputCoin, amount) {
102
- // @ts-ignore
103
- const i = this._getCoinIdx(inputCoin, false);
104
- return await ensureAllowanceEstimateGas([this.wrappedCoinAddresses[i]], [amount], this.address);
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
+ });
278
+ });
105
279
  },
106
- async swapWrappedApprove(inputCoin, amount) {
107
- // @ts-ignore
108
- const i = this._getCoinIdx(inputCoin, false);
109
- return await ensureAllowance([this.wrappedCoinAddresses[i]], [amount], this.address);
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
+ });
291
+ });
110
292
  },
111
293
  };
@@ -1,38 +1,119 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
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
+ };
1
37
  import { curve } from "../../curve.js";
2
38
  import { parseUnits } from "../../utils.js";
3
39
  import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
4
40
  // @ts-ignore
5
- export const withdrawExpectedMixin = {
6
- async withdrawExpected(lpTokenAmount) {
7
- const _lpTokenAmount = parseUnits(lpTokenAmount);
8
- const _expected = await _calcExpectedAmounts.call(this, _lpTokenAmount);
9
- return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
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
+ });
56
+ });
10
57
  },
11
58
  };
12
59
  // @ts-ignore
13
- export const withdrawExpectedLendingOrCryptoMixin = {
14
- async withdrawExpected(lpTokenAmount) {
15
- const _lpTokenAmount = parseUnits(lpTokenAmount);
16
- const _expectedAmounts = await _calcExpectedAmounts.call(this, _lpTokenAmount);
17
- // @ts-ignore
18
- const _rates = await this._getRates();
19
- const _expected = _expectedAmounts.map((_amount, i) => _amount * _rates[i] / (10n ** 18n));
20
- return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
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
+ });
79
+ });
21
80
  },
22
81
  };
23
82
  // @ts-ignore
24
- export const withdrawExpectedMetaMixin = {
25
- async withdrawExpected(lpTokenAmount) {
26
- const _lpTokenAmount = parseUnits(lpTokenAmount);
27
- const _expected = await _calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount);
28
- return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
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
+ });
98
+ });
29
99
  },
30
100
  };
31
101
  // @ts-ignore
32
- export const withdrawWrappedExpectedMixin = {
33
- async withdrawWrappedExpected(lpTokenAmount) {
34
- const _lpTokenAmount = parseUnits(lpTokenAmount);
35
- const _expected = await _calcExpectedAmounts.call(this, _lpTokenAmount);
36
- return _expected.map((amount, i) => curve.formatUnits(amount, this.wrappedDecimals[i]));
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
+ });
117
+ });
37
118
  },
38
119
  };