@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,222 +7,107 @@ 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, fromBN, getEthIndex, hasAllowance, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
50
- function _depositWrappedCheck(amounts, estimateGas) {
51
- if (estimateGas === void 0) { estimateGas = false; }
52
- return __awaiter(this, void 0, void 0, function () {
53
- var balances, _a, _b, i, _c;
54
- var _this = this;
55
- return __generator(this, function (_d) {
56
- switch (_d.label) {
57
- case 0:
58
- if (this.isFake) {
59
- throw Error("depositWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
60
- }
61
- if (amounts.length !== this.wrappedCoinAddresses.length) {
62
- throw Error("".concat(this.name, " pool has ").concat(this.wrappedCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
63
- }
64
- _b = (_a = Object).values;
65
- return [4 /*yield*/, this.wallet.wrappedCoinBalances()];
66
- case 1:
67
- balances = _b.apply(_a, [_d.sent()]);
68
- for (i = 0; i < balances.length; i++) {
69
- if (Number(balances[i]) < Number(amounts[i])) {
70
- throw Error("Not enough ".concat(this.wrappedCoins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
71
- }
72
- }
73
- _c = estimateGas;
74
- if (!_c) return [3 /*break*/, 3];
75
- return [4 /*yield*/, hasAllowance(this.wrappedCoinAddresses, amounts, curve.signerAddress, this.address)];
76
- case 2:
77
- _c = !(_d.sent());
78
- _d.label = 3;
79
- case 3:
80
- if (_c) {
81
- throw Error("Token allowance is needed to estimate gas");
82
- }
83
- if (!!estimateGas) return [3 /*break*/, 5];
84
- return [4 /*yield*/, curve.updateFeeData()];
85
- case 4:
86
- _d.sent();
87
- _d.label = 5;
88
- case 5: return [2 /*return*/, amounts.map(function (amount, i) { return parseUnits(amount, _this.wrappedDecimals[i]); })];
12
+ function _depositWrappedCheck(amounts, estimateGas = false) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ if (this.isFake) {
15
+ throw Error(`depositWrappedExpected method doesn't exist for pool ${this.name} (id: ${this.name})`);
16
+ }
17
+ if (amounts.length !== this.wrappedCoinAddresses.length) {
18
+ throw Error(`${this.name} pool has ${this.wrappedCoinAddresses.length} coins (amounts provided for ${amounts.length})`);
19
+ }
20
+ const balances = Object.values(yield this.wallet.wrappedCoinBalances());
21
+ for (let i = 0; i < balances.length; i++) {
22
+ if (Number(balances[i]) < Number(amounts[i])) {
23
+ throw Error(`Not enough ${this.wrappedCoins[i]}. Actual: ${balances[i]}, required: ${amounts[i]}`);
89
24
  }
90
- });
25
+ }
26
+ if (estimateGas && !(yield hasAllowance(this.wrappedCoinAddresses, amounts, curve.signerAddress, this.address))) {
27
+ throw Error("Token allowance is needed to estimate gas");
28
+ }
29
+ if (!estimateGas)
30
+ yield curve.updateFeeData();
31
+ return amounts.map((amount, i) => parseUnits(amount, this.wrappedDecimals[i]));
91
32
  });
92
33
  }
93
- function _depositWrappedMinAmount(_amounts, slippage) {
94
- if (slippage === void 0) { slippage = 0.5; }
95
- return __awaiter(this, void 0, void 0, function () {
96
- var _expectedLpTokenAmount, minAmountBN;
97
- return __generator(this, function (_a) {
98
- switch (_a.label) {
99
- case 0: return [4 /*yield*/, this._calcLpTokenAmount(_amounts, true, false)];
100
- case 1:
101
- _expectedLpTokenAmount = _a.sent();
102
- minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
103
- return [2 /*return*/, fromBN(minAmountBN)];
104
- }
105
- });
34
+ function _depositWrappedMinAmount(_amounts, slippage = 0.5) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ // @ts-ignore
37
+ const _expectedLpTokenAmount = yield this._calcLpTokenAmount(_amounts, true, false);
38
+ const minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
39
+ return fromBN(minAmountBN);
106
40
  });
107
41
  }
108
42
  // @ts-ignore
109
- export var depositWrapped2argsMixin = {
43
+ export const depositWrapped2argsMixin = {
110
44
  // @ts-ignore
111
- _depositWrapped: function (_amounts, slippage, estimateGas) {
112
- if (estimateGas === void 0) { estimateGas = false; }
113
- return __awaiter(this, void 0, void 0, function () {
114
- var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
115
- return __generator(this, function (_a) {
116
- switch (_a.label) {
117
- case 0:
118
- if (!!estimateGas) return [3 /*break*/, 2];
119
- return [4 /*yield*/, _ensureAllowance(this.wrappedCoinAddresses, _amounts, this.address)];
120
- case 1:
121
- _a.sent();
122
- _a.label = 2;
123
- case 2: return [4 /*yield*/, _depositWrappedMinAmount.call(this, _amounts, slippage)];
124
- case 3:
125
- _minMintAmount = _a.sent();
126
- ethIndex = getEthIndex(this.wrappedCoinAddresses);
127
- value = _amounts[ethIndex] || curve.parseUnits("0");
128
- contract = curve.contracts[this.address].contract;
129
- return [4 /*yield*/, contract.add_liquidity.estimateGas(_amounts, _minMintAmount, __assign(__assign({}, curve.constantOptions), { value: value }))];
130
- case 4:
131
- gas = _a.sent();
132
- if (estimateGas)
133
- return [2 /*return*/, smartNumber(gas)];
134
- gasLimit = mulBy1_3(DIGas(gas));
135
- return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
136
- case 5: return [2 /*return*/, (_a.sent()).hash];
137
- }
138
- });
45
+ _depositWrapped(_amounts, slippage, estimateGas = false) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ if (!estimateGas)
48
+ yield _ensureAllowance(this.wrappedCoinAddresses, _amounts, this.address);
49
+ // @ts-ignore
50
+ const _minMintAmount = yield _depositWrappedMinAmount.call(this, _amounts, slippage);
51
+ const ethIndex = getEthIndex(this.wrappedCoinAddresses);
52
+ const value = _amounts[ethIndex] || curve.parseUnits("0");
53
+ const contract = curve.contracts[this.address].contract;
54
+ const gas = yield contract.add_liquidity.estimateGas(_amounts, _minMintAmount, Object.assign(Object.assign({}, curve.constantOptions), { value }));
55
+ if (estimateGas)
56
+ return smartNumber(gas);
57
+ const gasLimit = mulBy1_3(DIGas(gas));
58
+ return (yield contract.add_liquidity(_amounts, _minMintAmount, Object.assign(Object.assign({}, curve.options), { gasLimit, value }))).hash;
139
59
  });
140
60
  },
141
- depositWrappedEstimateGas: function (amounts) {
142
- return __awaiter(this, void 0, void 0, function () {
143
- var _amounts;
144
- return __generator(this, function (_a) {
145
- switch (_a.label) {
146
- case 0: return [4 /*yield*/, _depositWrappedCheck.call(this, amounts, true)];
147
- case 1:
148
- _amounts = _a.sent();
149
- return [4 /*yield*/, this._depositWrapped(_amounts, 0.1, true)];
150
- case 2:
151
- // @ts-ignore
152
- return [2 /*return*/, _a.sent()];
153
- }
154
- });
61
+ depositWrappedEstimateGas(amounts) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ // @ts-ignore
64
+ const _amounts = yield _depositWrappedCheck.call(this, amounts, true);
65
+ // @ts-ignore
66
+ return yield this._depositWrapped(_amounts, 0.1, true);
155
67
  });
156
68
  },
157
- depositWrapped: function (amounts, slippage) {
158
- return __awaiter(this, void 0, void 0, function () {
159
- var _amounts;
160
- return __generator(this, function (_a) {
161
- switch (_a.label) {
162
- case 0: return [4 /*yield*/, _depositWrappedCheck.call(this, amounts)];
163
- case 1:
164
- _amounts = _a.sent();
165
- return [4 /*yield*/, this._depositWrapped(_amounts, slippage)];
166
- case 2:
167
- // @ts-ignore
168
- return [2 /*return*/, _a.sent()];
169
- }
170
- });
69
+ depositWrapped(amounts, slippage) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ // @ts-ignore
72
+ const _amounts = yield _depositWrappedCheck.call(this, amounts);
73
+ // @ts-ignore
74
+ return yield this._depositWrapped(_amounts, slippage);
171
75
  });
172
76
  },
173
77
  };
174
78
  // @ts-ignore
175
- export var depositWrapped3argsMixin = {
79
+ export const depositWrapped3argsMixin = {
176
80
  // @ts-ignore
177
- _depositWrapped: function (_amounts, slippage, estimateGas) {
178
- if (estimateGas === void 0) { estimateGas = false; }
179
- return __awaiter(this, void 0, void 0, function () {
180
- var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
181
- return __generator(this, function (_a) {
182
- switch (_a.label) {
183
- case 0:
184
- if (!!estimateGas) return [3 /*break*/, 2];
185
- return [4 /*yield*/, _ensureAllowance(this.wrappedCoinAddresses, _amounts, this.address)];
186
- case 1:
187
- _a.sent();
188
- _a.label = 2;
189
- case 2: return [4 /*yield*/, _depositWrappedMinAmount.call(this, _amounts, slippage)];
190
- case 3:
191
- _minMintAmount = _a.sent();
192
- ethIndex = getEthIndex(this.wrappedCoinAddresses);
193
- value = _amounts[ethIndex] || curve.parseUnits("0");
194
- contract = curve.contracts[this.address].contract;
195
- return [4 /*yield*/, contract.add_liquidity.estimateGas(_amounts, _minMintAmount, false, __assign(__assign({}, curve.constantOptions), { value: value }))];
196
- case 4:
197
- gas = _a.sent();
198
- if (estimateGas)
199
- return [2 /*return*/, smartNumber(gas)];
200
- gasLimit = mulBy1_3(DIGas(gas));
201
- return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, false, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
202
- case 5: return [2 /*return*/, (_a.sent()).hash];
203
- }
204
- });
81
+ _depositWrapped(_amounts, slippage, estimateGas = false) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ if (!estimateGas)
84
+ yield _ensureAllowance(this.wrappedCoinAddresses, _amounts, this.address);
85
+ // @ts-ignore
86
+ const _minMintAmount = yield _depositWrappedMinAmount.call(this, _amounts, slippage);
87
+ const ethIndex = getEthIndex(this.wrappedCoinAddresses);
88
+ const value = _amounts[ethIndex] || curve.parseUnits("0");
89
+ const contract = curve.contracts[this.address].contract;
90
+ const gas = yield contract.add_liquidity.estimateGas(_amounts, _minMintAmount, false, Object.assign(Object.assign({}, curve.constantOptions), { value }));
91
+ if (estimateGas)
92
+ return smartNumber(gas);
93
+ const gasLimit = mulBy1_3(DIGas(gas));
94
+ return (yield contract.add_liquidity(_amounts, _minMintAmount, false, Object.assign(Object.assign({}, curve.options), { gasLimit, value }))).hash;
205
95
  });
206
96
  },
207
- depositWrappedEstimateGas: function (amounts) {
208
- return __awaiter(this, void 0, void 0, function () {
209
- var _amounts;
210
- return __generator(this, function (_a) {
211
- switch (_a.label) {
212
- case 0: return [4 /*yield*/, _depositWrappedCheck.call(this, amounts, true)];
213
- case 1:
214
- _amounts = _a.sent();
215
- return [4 /*yield*/, this._depositWrapped(_amounts, 0.1, true)];
216
- case 2:
217
- // @ts-ignore
218
- return [2 /*return*/, _a.sent()];
219
- }
220
- });
97
+ depositWrappedEstimateGas(amounts) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ // @ts-ignore
100
+ const _amounts = yield _depositWrappedCheck.call(this, amounts, true);
101
+ // @ts-ignore
102
+ return yield this._depositWrapped(_amounts, 0.1, true);
221
103
  });
222
104
  },
223
- depositWrapped: function (amounts, slippage) {
224
- return __awaiter(this, void 0, void 0, function () {
225
- var _amounts;
226
- return __generator(this, function (_a) {
227
- switch (_a.label) {
228
- case 0: return [4 /*yield*/, _depositWrappedCheck.call(this, amounts)];
229
- case 1:
230
- _amounts = _a.sent();
231
- return [4 /*yield*/, this._depositWrapped(_amounts, slippage)];
232
- case 2:
233
- // @ts-ignore
234
- return [2 /*return*/, _a.sent()];
235
- }
236
- });
105
+ depositWrapped(amounts, slippage) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ // @ts-ignore
108
+ const _amounts = yield _depositWrappedCheck.call(this, amounts);
109
+ // @ts-ignore
110
+ return yield this._depositWrapped(_amounts, slippage);
237
111
  });
238
112
  },
239
113
  };
@@ -7,101 +7,38 @@ 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
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
- if (ar || !(i in from)) {
40
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
- ar[i] = from[i];
42
- }
43
- }
44
- return to.concat(ar || Array.prototype.slice.call(from));
45
- };
46
10
  import { curve } from "../../curve.js";
47
11
  import { PoolTemplate } from "../PoolTemplate.js";
48
12
  import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
49
13
  // @ts-ignore
50
- export var poolBalancesMetaMixin = {
51
- statsUnderlyingBalances: function () {
52
- return __awaiter(this, void 0, void 0, function () {
53
- var swapContract, contractCalls, _poolWrappedBalances, _poolMetaCoinBalance, _poolUnderlyingBalances, basePool, _basePoolExpectedAmounts, _a;
54
- var _this = this;
55
- return __generator(this, function (_c) {
56
- switch (_c.label) {
57
- case 0:
58
- swapContract = curve.contracts[this.address].multicallContract;
59
- contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
60
- return [4 /*yield*/, curve.multicallProvider.all(contractCalls)];
61
- case 1:
62
- _poolWrappedBalances = _c.sent();
63
- _poolMetaCoinBalance = _poolWrappedBalances.splice(this.metaCoinIdx, 1)[0];
64
- _poolUnderlyingBalances = _poolWrappedBalances;
65
- basePool = new PoolTemplate(this.basePool);
66
- if (!basePool.isMeta) return [3 /*break*/, 3];
67
- return [4 /*yield*/, _calcExpectedUnderlyingAmountsMeta.call(basePool, _poolMetaCoinBalance)];
68
- case 2:
69
- _a = _c.sent();
70
- return [3 /*break*/, 5];
71
- case 3: return [4 /*yield*/, _calcExpectedAmounts.call(basePool, _poolMetaCoinBalance)];
72
- case 4:
73
- _a = _c.sent();
74
- _c.label = 5;
75
- case 5:
76
- _basePoolExpectedAmounts = _a;
77
- _poolUnderlyingBalances.splice.apply(_poolUnderlyingBalances, __spreadArray([this.metaCoinIdx, 0], _basePoolExpectedAmounts, false));
78
- return [2 /*return*/, _poolUnderlyingBalances.map(function (_b, i) { return curve.formatUnits(_b, _this.underlyingDecimals[i]); })];
79
- }
80
- });
14
+ export const poolBalancesMetaMixin = {
15
+ statsUnderlyingBalances() {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const swapContract = curve.contracts[this.address].multicallContract;
18
+ const contractCalls = this.wrappedCoins.map((_, i) => swapContract.balances(i));
19
+ const _poolWrappedBalances = yield curve.multicallProvider.all(contractCalls);
20
+ const [_poolMetaCoinBalance] = _poolWrappedBalances.splice(this.metaCoinIdx, 1);
21
+ const _poolUnderlyingBalances = _poolWrappedBalances;
22
+ const basePool = new PoolTemplate(this.basePool);
23
+ const _basePoolExpectedAmounts = basePool.isMeta ?
24
+ yield _calcExpectedUnderlyingAmountsMeta.call(basePool, _poolMetaCoinBalance) :
25
+ yield _calcExpectedAmounts.call(basePool, _poolMetaCoinBalance);
26
+ _poolUnderlyingBalances.splice(this.metaCoinIdx, 0, ..._basePoolExpectedAmounts);
27
+ return _poolUnderlyingBalances.map((_b, i) => curve.formatUnits(_b, this.underlyingDecimals[i]));
81
28
  });
82
29
  },
83
30
  };
84
31
  // @ts-ignore
85
- export var poolBalancesLendingMixin = {
86
- statsUnderlyingBalances: function () {
87
- return __awaiter(this, void 0, void 0, function () {
88
- var swapContract, contractCalls, _poolWrappedBalances, _rates, _poolUnderlyingBalances;
89
- var _this = this;
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0:
93
- swapContract = curve.contracts[this.address].multicallContract;
94
- contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
95
- return [4 /*yield*/, curve.multicallProvider.all(contractCalls)];
96
- case 1:
97
- _poolWrappedBalances = _a.sent();
98
- return [4 /*yield*/, this._getRates()];
99
- case 2:
100
- _rates = _a.sent();
101
- _poolUnderlyingBalances = _poolWrappedBalances.map(function (_b, i) { return _b * _rates[i] / curve.parseUnits(String(Math.pow(10, 18)), 0); });
102
- return [2 /*return*/, _poolUnderlyingBalances.map(function (_b, i) { return curve.formatUnits(_b, _this.underlyingDecimals[i]); })];
103
- }
104
- });
32
+ export const poolBalancesLendingMixin = {
33
+ statsUnderlyingBalances() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const swapContract = curve.contracts[this.address].multicallContract;
36
+ const contractCalls = this.wrappedCoins.map((_, i) => swapContract.balances(i));
37
+ const _poolWrappedBalances = yield curve.multicallProvider.all(contractCalls);
38
+ // @ts-ignore
39
+ const _rates = yield this._getRates();
40
+ const _poolUnderlyingBalances = _poolWrappedBalances.map((_b, i) => _b * _rates[i] / curve.parseUnits(String(Math.pow(10, 18)), 0));
41
+ return _poolUnderlyingBalances.map((_b, i) => curve.formatUnits(_b, this.underlyingDecimals[i]));
105
42
  });
106
43
  },
107
44
  };