@curvefi/api 2.31.1 → 2.33.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.
Files changed (62) hide show
  1. package/lib/boosting.js +385 -135
  2. package/lib/constants/abis/stable_calc.json +151 -0
  3. package/lib/constants/abis/wbeth/swap.json +1086 -0
  4. package/lib/constants/aliases.js +33 -11
  5. package/lib/constants/coins/arbitrum.js +5 -5
  6. package/lib/constants/coins/aurora.js +5 -5
  7. package/lib/constants/coins/avalanche.js +6 -6
  8. package/lib/constants/coins/celo.js +5 -5
  9. package/lib/constants/coins/ethereum.js +10 -9
  10. package/lib/constants/coins/fantom.js +7 -7
  11. package/lib/constants/coins/kava.js +5 -5
  12. package/lib/constants/coins/moonbeam.js +5 -5
  13. package/lib/constants/coins/optimism.js +5 -5
  14. package/lib/constants/coins/polygon.js +6 -6
  15. package/lib/constants/coins/xdai.js +5 -5
  16. package/lib/constants/pools/arbitrum.js +1 -1
  17. package/lib/constants/pools/aurora.js +1 -1
  18. package/lib/constants/pools/avalanche.js +1 -1
  19. package/lib/constants/pools/celo.js +1 -1
  20. package/lib/constants/pools/ethereum.js +26 -1
  21. package/lib/constants/pools/fantom.js +1 -1
  22. package/lib/constants/pools/kava.js +1 -1
  23. package/lib/constants/pools/moonbeam.js +1 -1
  24. package/lib/constants/pools/optimism.js +1 -1
  25. package/lib/constants/pools/polygon.js +1 -1
  26. package/lib/constants/pools/xdai.js +1 -1
  27. package/lib/constants/utils.d.ts +1 -1
  28. package/lib/constants/utils.js +19 -18
  29. package/lib/curve.js +507 -281
  30. package/lib/external-api.js +132 -45
  31. package/lib/factory/common.js +3 -3
  32. package/lib/factory/constants-crypto.js +21 -21
  33. package/lib/factory/constants.js +32 -31
  34. package/lib/factory/deploy.js +336 -176
  35. package/lib/factory/factory-api.js +256 -180
  36. package/lib/factory/factory-crypto.js +309 -163
  37. package/lib/factory/factory.d.ts +1 -1
  38. package/lib/factory/factory.js +336 -186
  39. package/lib/index.js +98 -44
  40. package/lib/interfaces.d.ts +1 -1
  41. package/lib/pools/PoolTemplate.js +2882 -1511
  42. package/lib/pools/mixins/common.js +106 -22
  43. package/lib/pools/mixins/depositBalancedAmountsMixins.js +131 -48
  44. package/lib/pools/mixins/depositMixins.js +413 -144
  45. package/lib/pools/mixins/depositWrappedMixins.js +223 -72
  46. package/lib/pools/mixins/poolBalancesMixin.js +98 -22
  47. package/lib/pools/mixins/swapMixins.js +347 -125
  48. package/lib/pools/mixins/swapWrappedMixins.js +270 -88
  49. package/lib/pools/mixins/withdrawExpectedMixins.js +104 -23
  50. package/lib/pools/mixins/withdrawImbalanceMixins.js +316 -97
  51. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +187 -51
  52. package/lib/pools/mixins/withdrawMixins.js +385 -122
  53. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +88 -16
  54. package/lib/pools/mixins/withdrawOneCoinMixins.js +386 -123
  55. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +62 -8
  56. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +185 -53
  57. package/lib/pools/mixins/withdrawWrappedMixins.js +185 -50
  58. package/lib/pools/poolConstructor.js +25 -5
  59. package/lib/pools/utils.js +488 -298
  60. package/lib/router.js +636 -378
  61. package/lib/utils.js +675 -354
  62. package/package.json +1 -1
@@ -1,88 +1,239 @@
1
- import { curve } from "../../curve.js";
2
- import { _ensureAllowance, fromBN, getEthIndex, hasAllowance, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
3
- async function _depositWrappedCheck(amounts, estimateGas = false) {
4
- if (this.isFake) {
5
- throw Error(`depositWrappedExpected method doesn't exist for pool ${this.name} (id: ${this.name})`);
6
- }
7
- if (amounts.length !== this.wrappedCoinAddresses.length) {
8
- throw Error(`${this.name} pool has ${this.wrappedCoinAddresses.length} coins (amounts provided for ${amounts.length})`);
9
- }
10
- const balances = Object.values(await this.wallet.wrappedCoinBalances());
11
- for (let i = 0; i < balances.length; i++) {
12
- if (Number(balances[i]) < Number(amounts[i])) {
13
- throw Error(`Not enough ${this.wrappedCoins[i]}. Actual: ${balances[i]}, required: ${amounts[i]}`);
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];
14
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 };
15
46
  }
16
- if (estimateGas && !(await hasAllowance(this.wrappedCoinAddresses, amounts, curve.signerAddress, this.address))) {
17
- throw Error("Token allowance is needed to estimate gas");
18
- }
19
- if (!estimateGas)
20
- await curve.updateFeeData();
21
- return amounts.map((amount, i) => parseUnits(amount, this.wrappedDecimals[i]));
47
+ };
48
+ import { curve } from "../../curve.js";
49
+ import { _ensureAllowance, fromBN, getEthIndex, hasAllowance, toBN, parseUnits, mulBy1_3 } 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]); })];
89
+ }
90
+ });
91
+ });
22
92
  }
23
- async function _depositWrappedMinAmount(_amounts, slippage = 0.5) {
24
- // @ts-ignore
25
- const _expectedLpTokenAmount = await this._calcLpTokenAmount(_amounts, true, false);
26
- const minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
27
- return fromBN(minAmountBN);
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
+ });
106
+ });
28
107
  }
29
108
  // @ts-ignore
30
- export const depositWrapped2argsMixin = {
109
+ export var depositWrapped2argsMixin = {
31
110
  // @ts-ignore
32
- async _depositWrapped(_amounts, slippage, estimateGas = false) {
33
- if (!estimateGas)
34
- await _ensureAllowance(this.wrappedCoinAddresses, _amounts, this.address);
35
- // @ts-ignore
36
- const _minMintAmount = await _depositWrappedMinAmount.call(this, _amounts, slippage);
37
- const ethIndex = getEthIndex(this.wrappedCoinAddresses);
38
- const value = _amounts[ethIndex] || 0n;
39
- const contract = curve.contracts[this.address].contract;
40
- const gas = await contract.add_liquidity.estimateGas(_amounts, _minMintAmount, { ...curve.constantOptions, value });
41
- if (estimateGas)
42
- return Number(gas);
43
- const gasLimit = mulBy1_3(gas);
44
- return (await contract.add_liquidity(_amounts, _minMintAmount, { ...curve.options, gasLimit, value })).hash;
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*/, Number(gas)];
134
+ gasLimit = mulBy1_3(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
+ });
139
+ });
45
140
  },
46
- async depositWrappedEstimateGas(amounts) {
47
- // @ts-ignore
48
- const _amounts = await _depositWrappedCheck.call(this, amounts, true);
49
- // @ts-ignore
50
- return await this._depositWrapped(_amounts, 0.1, true);
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
+ });
155
+ });
51
156
  },
52
- async depositWrapped(amounts, slippage) {
53
- // @ts-ignore
54
- const _amounts = await _depositWrappedCheck.call(this, amounts);
55
- // @ts-ignore
56
- return await this._depositWrapped(_amounts, slippage);
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
+ });
171
+ });
57
172
  },
58
173
  };
59
174
  // @ts-ignore
60
- export const depositWrapped3argsMixin = {
175
+ export var depositWrapped3argsMixin = {
61
176
  // @ts-ignore
62
- async _depositWrapped(_amounts, slippage, estimateGas = false) {
63
- if (!estimateGas)
64
- await _ensureAllowance(this.wrappedCoinAddresses, _amounts, this.address);
65
- // @ts-ignore
66
- const _minMintAmount = await _depositWrappedMinAmount.call(this, _amounts, slippage);
67
- const ethIndex = getEthIndex(this.wrappedCoinAddresses);
68
- const value = _amounts[ethIndex] || 0n;
69
- const contract = curve.contracts[this.address].contract;
70
- const gas = await contract.add_liquidity.estimateGas(_amounts, _minMintAmount, false, { ...curve.constantOptions, value });
71
- if (estimateGas)
72
- return Number(gas);
73
- const gasLimit = mulBy1_3(gas);
74
- return (await contract.add_liquidity(_amounts, _minMintAmount, false, { ...curve.options, gasLimit, value })).hash;
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*/, Number(gas)];
200
+ gasLimit = mulBy1_3(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
+ });
205
+ });
75
206
  },
76
- async depositWrappedEstimateGas(amounts) {
77
- // @ts-ignore
78
- const _amounts = await _depositWrappedCheck.call(this, amounts, true);
79
- // @ts-ignore
80
- return await this._depositWrapped(_amounts, 0.1, true);
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
+ });
221
+ });
81
222
  },
82
- async depositWrapped(amounts, slippage) {
83
- // @ts-ignore
84
- const _amounts = await _depositWrappedCheck.call(this, amounts);
85
- // @ts-ignore
86
- return await this._depositWrapped(_amounts, slippage);
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
+ });
237
+ });
87
238
  },
88
239
  };
@@ -1,31 +1,107 @@
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
+ };
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
+ };
1
46
  import { curve } from "../../curve.js";
2
47
  import { PoolTemplate } from "../PoolTemplate.js";
3
48
  import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
4
49
  // @ts-ignore
5
- export const poolBalancesMetaMixin = {
6
- async statsUnderlyingBalances() {
7
- const swapContract = curve.contracts[this.address].multicallContract;
8
- const contractCalls = this.wrappedCoins.map((_, i) => swapContract.balances(i));
9
- const _poolWrappedBalances = await curve.multicallProvider.all(contractCalls);
10
- const [_poolMetaCoinBalance] = _poolWrappedBalances.splice(this.metaCoinIdx, 1);
11
- const _poolUnderlyingBalances = _poolWrappedBalances;
12
- const basePool = new PoolTemplate(this.basePool);
13
- const _basePoolExpectedAmounts = basePool.isMeta ?
14
- await _calcExpectedUnderlyingAmountsMeta.call(basePool, _poolMetaCoinBalance) :
15
- await _calcExpectedAmounts.call(basePool, _poolMetaCoinBalance);
16
- _poolUnderlyingBalances.splice(this.metaCoinIdx, 0, ..._basePoolExpectedAmounts);
17
- return _poolUnderlyingBalances.map((_b, i) => curve.formatUnits(_b, this.underlyingDecimals[i]));
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
+ });
81
+ });
18
82
  },
19
83
  };
20
84
  // @ts-ignore
21
- export const poolBalancesLendingMixin = {
22
- async statsUnderlyingBalances() {
23
- const swapContract = curve.contracts[this.address].multicallContract;
24
- const contractCalls = this.wrappedCoins.map((_, i) => swapContract.balances(i));
25
- const _poolWrappedBalances = await curve.multicallProvider.all(contractCalls);
26
- // @ts-ignore
27
- const _rates = await this._getRates();
28
- const _poolUnderlyingBalances = _poolWrappedBalances.map((_b, i) => _b * _rates[i] / (10n ** 18n));
29
- return _poolUnderlyingBalances.map((_b, i) => curve.formatUnits(_b, this.underlyingDecimals[i]));
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
+ });
105
+ });
30
106
  },
31
107
  };