@curvefi/api 2.30.1 → 2.31.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 (100) hide show
  1. package/lib/boosting.js +137 -402
  2. package/lib/constants/abis/avaxcrypto/swap.json +1195 -0
  3. package/lib/constants/abis/avaxcrypto/zap.json +250 -0
  4. package/lib/constants/aliases.d.ts +11 -11
  5. package/lib/constants/aliases.js +12 -15
  6. package/lib/constants/coins/arbitrum.js +6 -9
  7. package/lib/constants/coins/aurora.js +6 -9
  8. package/lib/constants/coins/avalanche.js +12 -10
  9. package/lib/constants/coins/celo.js +6 -9
  10. package/lib/constants/coins/ethereum.js +10 -13
  11. package/lib/constants/coins/fantom.js +8 -11
  12. package/lib/constants/coins/kava.js +6 -9
  13. package/lib/constants/coins/moonbeam.js +6 -9
  14. package/lib/constants/coins/optimism.js +6 -9
  15. package/lib/constants/coins/polygon.js +7 -10
  16. package/lib/constants/coins/xdai.js +6 -9
  17. package/lib/constants/pools/arbitrum.d.ts +2 -4
  18. package/lib/constants/pools/arbitrum.js +22 -28
  19. package/lib/constants/pools/aurora.d.ts +2 -4
  20. package/lib/constants/pools/aurora.js +6 -12
  21. package/lib/constants/pools/avalanche.d.ts +2 -4
  22. package/lib/constants/pools/avalanche.js +51 -22
  23. package/lib/constants/pools/celo.d.ts +2 -4
  24. package/lib/constants/pools/celo.js +2 -5
  25. package/lib/constants/pools/ethereum.js +247 -253
  26. package/lib/constants/pools/fantom.d.ts +2 -4
  27. package/lib/constants/pools/fantom.js +28 -34
  28. package/lib/constants/pools/index.d.ts +11 -11
  29. package/lib/constants/pools/index.js +12 -25
  30. package/lib/constants/pools/kava.d.ts +2 -4
  31. package/lib/constants/pools/kava.js +2 -5
  32. package/lib/constants/pools/moonbeam.d.ts +2 -4
  33. package/lib/constants/pools/moonbeam.js +6 -12
  34. package/lib/constants/pools/optimism.d.ts +2 -4
  35. package/lib/constants/pools/optimism.js +9 -15
  36. package/lib/constants/pools/polygon.d.ts +2 -4
  37. package/lib/constants/pools/polygon.js +23 -28
  38. package/lib/constants/pools/xdai.d.ts +2 -4
  39. package/lib/constants/pools/xdai.js +25 -30
  40. package/lib/constants/utils.js +20 -29
  41. package/lib/curve.d.ts +9 -7
  42. package/lib/curve.js +397 -615
  43. package/lib/external-api.d.ts +1 -1
  44. package/lib/external-api.js +47 -140
  45. package/lib/factory/common.js +6 -10
  46. package/lib/factory/constants-crypto.js +48 -54
  47. package/lib/factory/constants.js +274 -280
  48. package/lib/factory/deploy.d.ts +8 -8
  49. package/lib/factory/deploy.js +177 -347
  50. package/lib/factory/factory-api.js +195 -278
  51. package/lib/factory/factory-crypto.js +170 -323
  52. package/lib/factory/factory.js +195 -350
  53. package/lib/index.d.ts +24 -25
  54. package/lib/index.js +87 -143
  55. package/lib/interfaces.d.ts +6 -5
  56. package/lib/interfaces.js +1 -2
  57. package/lib/pools/PoolTemplate.d.ts +1 -0
  58. package/lib/pools/PoolTemplate.js +1516 -2928
  59. package/lib/pools/index.d.ts +2 -2
  60. package/lib/pools/index.js +3 -7
  61. package/lib/pools/mixins/common.d.ts +3 -4
  62. package/lib/pools/mixins/common.js +23 -102
  63. package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +1 -1
  64. package/lib/pools/mixins/depositBalancedAmountsMixins.js +50 -139
  65. package/lib/pools/mixins/depositMixins.d.ts +1 -1
  66. package/lib/pools/mixins/depositMixins.js +145 -405
  67. package/lib/pools/mixins/depositWrappedMixins.d.ts +1 -1
  68. package/lib/pools/mixins/depositWrappedMixins.js +72 -227
  69. package/lib/pools/mixins/poolBalancesMixin.d.ts +1 -2
  70. package/lib/pools/mixins/poolBalancesMixin.js +25 -131
  71. package/lib/pools/mixins/swapMixins.d.ts +1 -1
  72. package/lib/pools/mixins/swapMixins.js +127 -353
  73. package/lib/pools/mixins/swapWrappedMixins.d.ts +1 -1
  74. package/lib/pools/mixins/swapWrappedMixins.js +90 -276
  75. package/lib/pools/mixins/withdrawExpectedMixins.d.ts +1 -2
  76. package/lib/pools/mixins/withdrawExpectedMixins.js +26 -154
  77. package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +1 -1
  78. package/lib/pools/mixins/withdrawImbalanceMixins.js +99 -321
  79. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +1 -1
  80. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +53 -192
  81. package/lib/pools/mixins/withdrawMixins.d.ts +1 -1
  82. package/lib/pools/mixins/withdrawMixins.js +124 -378
  83. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +1 -1
  84. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +17 -92
  85. package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +1 -1
  86. package/lib/pools/mixins/withdrawOneCoinMixins.js +125 -378
  87. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +1 -1
  88. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +9 -66
  89. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +1 -1
  90. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +55 -190
  91. package/lib/pools/mixins/withdrawWrappedMixins.d.ts +1 -1
  92. package/lib/pools/mixins/withdrawWrappedMixins.js +52 -191
  93. package/lib/pools/poolConstructor.d.ts +1 -1
  94. package/lib/pools/poolConstructor.js +79 -109
  95. package/lib/pools/utils.js +298 -500
  96. package/lib/router.d.ts +2 -2
  97. package/lib/router.js +406 -650
  98. package/lib/utils.d.ts +9 -9
  99. package/lib/utils.js +377 -731
  100. package/package.json +8 -8
@@ -1,243 +1,88 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
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]}`);
8
14
  }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
15
  }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.depositWrapped3argsMixin = exports.depositWrapped2argsMixin = void 0;
51
- var utils_1 = require("../../utils");
52
- var curve_1 = require("../../curve");
53
- var ethers_1 = require("ethers");
54
- function _depositWrappedCheck(amounts, estimateGas) {
55
- if (estimateGas === void 0) { estimateGas = false; }
56
- return __awaiter(this, void 0, void 0, function () {
57
- var balances, _a, _b, i, _c;
58
- var _this = this;
59
- return __generator(this, function (_d) {
60
- switch (_d.label) {
61
- case 0:
62
- if (this.isFake) {
63
- throw Error("depositWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
64
- }
65
- if (amounts.length !== this.wrappedCoinAddresses.length) {
66
- throw Error("".concat(this.name, " pool has ").concat(this.wrappedCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
67
- }
68
- _b = (_a = Object).values;
69
- return [4 /*yield*/, this.wallet.wrappedCoinBalances()];
70
- case 1:
71
- balances = _b.apply(_a, [_d.sent()]);
72
- for (i = 0; i < balances.length; i++) {
73
- if (Number(balances[i]) < Number(amounts[i])) {
74
- throw Error("Not enough ".concat(this.wrappedCoins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
75
- }
76
- }
77
- _c = estimateGas;
78
- if (!_c) return [3 /*break*/, 3];
79
- return [4 /*yield*/, (0, utils_1.hasAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.signerAddress, this.address)];
80
- case 2:
81
- _c = !(_d.sent());
82
- _d.label = 3;
83
- case 3:
84
- if (_c) {
85
- throw Error("Token allowance is needed to estimate gas");
86
- }
87
- if (!!estimateGas) return [3 /*break*/, 5];
88
- return [4 /*yield*/, curve_1.curve.updateFeeData()];
89
- case 4:
90
- _d.sent();
91
- _d.label = 5;
92
- case 5: return [2 /*return*/, amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.wrappedDecimals[i]); })];
93
- }
94
- });
95
- });
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]));
96
22
  }
97
- function _depositWrappedMinAmount(_amounts, slippage) {
98
- if (slippage === void 0) { slippage = 0.5; }
99
- return __awaiter(this, void 0, void 0, function () {
100
- var _expectedLpTokenAmount, minAmountBN;
101
- return __generator(this, function (_a) {
102
- switch (_a.label) {
103
- case 0: return [4 /*yield*/, this._calcLpTokenAmount(_amounts, true, false)];
104
- case 1:
105
- _expectedLpTokenAmount = _a.sent();
106
- minAmountBN = (0, utils_1.toBN)(_expectedLpTokenAmount).times(100 - slippage).div(100);
107
- return [2 /*return*/, (0, utils_1.fromBN)(minAmountBN)];
108
- }
109
- });
110
- });
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);
111
28
  }
112
29
  // @ts-ignore
113
- exports.depositWrapped2argsMixin = {
30
+ export const depositWrapped2argsMixin = {
114
31
  // @ts-ignore
115
- _depositWrapped: function (_amounts, slippage, estimateGas) {
116
- if (estimateGas === void 0) { estimateGas = false; }
117
- return __awaiter(this, void 0, void 0, function () {
118
- var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
119
- return __generator(this, function (_a) {
120
- switch (_a.label) {
121
- case 0:
122
- if (!!estimateGas) return [3 /*break*/, 2];
123
- return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.wrappedCoinAddresses, _amounts, this.address)];
124
- case 1:
125
- _a.sent();
126
- _a.label = 2;
127
- case 2: return [4 /*yield*/, _depositWrappedMinAmount.call(this, _amounts, slippage)];
128
- case 3:
129
- _minMintAmount = _a.sent();
130
- ethIndex = (0, utils_1.getEthIndex)(this.wrappedCoinAddresses);
131
- value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
132
- contract = curve_1.curve.contracts[this.address].contract;
133
- return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
134
- case 4:
135
- gas = _a.sent();
136
- if (estimateGas)
137
- return [2 /*return*/, gas.toNumber()];
138
- gasLimit = gas.mul(130).div(100);
139
- return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
140
- case 5: return [2 /*return*/, (_a.sent()).hash];
141
- }
142
- });
143
- });
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;
144
45
  },
145
- depositWrappedEstimateGas: function (amounts) {
146
- return __awaiter(this, void 0, void 0, function () {
147
- var _amounts;
148
- return __generator(this, function (_a) {
149
- switch (_a.label) {
150
- case 0: return [4 /*yield*/, _depositWrappedCheck.call(this, amounts, true)];
151
- case 1:
152
- _amounts = _a.sent();
153
- return [4 /*yield*/, this._depositWrapped(_amounts, 0.1, true)];
154
- case 2:
155
- // @ts-ignore
156
- return [2 /*return*/, _a.sent()];
157
- }
158
- });
159
- });
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);
160
51
  },
161
- depositWrapped: function (amounts, slippage) {
162
- return __awaiter(this, void 0, void 0, function () {
163
- var _amounts;
164
- return __generator(this, function (_a) {
165
- switch (_a.label) {
166
- case 0: return [4 /*yield*/, _depositWrappedCheck.call(this, amounts)];
167
- case 1:
168
- _amounts = _a.sent();
169
- return [4 /*yield*/, this._depositWrapped(_amounts, slippage)];
170
- case 2:
171
- // @ts-ignore
172
- return [2 /*return*/, _a.sent()];
173
- }
174
- });
175
- });
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);
176
57
  },
177
58
  };
178
59
  // @ts-ignore
179
- exports.depositWrapped3argsMixin = {
60
+ export const depositWrapped3argsMixin = {
180
61
  // @ts-ignore
181
- _depositWrapped: function (_amounts, slippage, estimateGas) {
182
- if (estimateGas === void 0) { estimateGas = false; }
183
- return __awaiter(this, void 0, void 0, function () {
184
- var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
185
- return __generator(this, function (_a) {
186
- switch (_a.label) {
187
- case 0:
188
- if (!!estimateGas) return [3 /*break*/, 2];
189
- return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.wrappedCoinAddresses, _amounts, this.address)];
190
- case 1:
191
- _a.sent();
192
- _a.label = 2;
193
- case 2: return [4 /*yield*/, _depositWrappedMinAmount.call(this, _amounts, slippage)];
194
- case 3:
195
- _minMintAmount = _a.sent();
196
- ethIndex = (0, utils_1.getEthIndex)(this.wrappedCoinAddresses);
197
- value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
198
- contract = curve_1.curve.contracts[this.address].contract;
199
- return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
200
- case 4:
201
- gas = _a.sent();
202
- if (estimateGas)
203
- return [2 /*return*/, gas.toNumber()];
204
- gasLimit = gas.mul(130).div(100);
205
- return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, false, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
206
- case 5: return [2 /*return*/, (_a.sent()).hash];
207
- }
208
- });
209
- });
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;
210
75
  },
211
- depositWrappedEstimateGas: function (amounts) {
212
- return __awaiter(this, void 0, void 0, function () {
213
- var _amounts;
214
- return __generator(this, function (_a) {
215
- switch (_a.label) {
216
- case 0: return [4 /*yield*/, _depositWrappedCheck.call(this, amounts, true)];
217
- case 1:
218
- _amounts = _a.sent();
219
- return [4 /*yield*/, this._depositWrapped(_amounts, 0.1, true)];
220
- case 2:
221
- // @ts-ignore
222
- return [2 /*return*/, _a.sent()];
223
- }
224
- });
225
- });
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);
226
81
  },
227
- depositWrapped: function (amounts, slippage) {
228
- return __awaiter(this, void 0, void 0, function () {
229
- var _amounts;
230
- return __generator(this, function (_a) {
231
- switch (_a.label) {
232
- case 0: return [4 /*yield*/, _depositWrappedCheck.call(this, amounts)];
233
- case 1:
234
- _amounts = _a.sent();
235
- return [4 /*yield*/, this._depositWrapped(_amounts, slippage)];
236
- case 2:
237
- // @ts-ignore
238
- return [2 /*return*/, _a.sent()];
239
- }
240
- });
241
- });
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);
242
87
  },
243
88
  };
@@ -1,4 +1,3 @@
1
- import { PoolTemplate } from "../PoolTemplate";
2
- export declare const poolBalancesAtricrypto3Mixin: PoolTemplate;
1
+ import { PoolTemplate } from "../PoolTemplate.js";
3
2
  export declare const poolBalancesMetaMixin: PoolTemplate;
4
3
  export declare const poolBalancesLendingMixin: PoolTemplate;
@@ -1,137 +1,31 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.poolBalancesLendingMixin = exports.poolBalancesMetaMixin = exports.poolBalancesAtricrypto3Mixin = void 0;
49
- var ethers_1 = require("ethers");
50
- var curve_1 = require("../../curve");
51
- var common_1 = require("./common");
52
- var PoolTemplate_1 = require("../PoolTemplate");
53
- // @ts-ignore
54
- exports.poolBalancesAtricrypto3Mixin = {
55
- statsUnderlyingBalances: function () {
56
- return __awaiter(this, void 0, void 0, function () {
57
- var swapContract, contractCalls, _poolWrappedBalances, _poolMetaCoinBalance, _poolNonMetaBalances, basePool, _basePoolExpectedAmounts, _poolUnderlyingBalances;
58
- var _this = this;
59
- return __generator(this, function (_a) {
60
- switch (_a.label) {
61
- case 0:
62
- swapContract = curve_1.curve.contracts[this.address].multicallContract;
63
- contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
64
- return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
65
- case 1:
66
- _poolWrappedBalances = _a.sent();
67
- _poolMetaCoinBalance = _poolWrappedBalances[0], _poolNonMetaBalances = _poolWrappedBalances.slice(1);
68
- basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
69
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _poolMetaCoinBalance)];
70
- case 2:
71
- _basePoolExpectedAmounts = _a.sent();
72
- _poolUnderlyingBalances = __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolNonMetaBalances, true);
73
- return [2 /*return*/, _poolUnderlyingBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.underlyingDecimals[i]); })];
74
- }
75
- });
76
- });
77
- },
78
- };
1
+ import { curve } from "../../curve.js";
2
+ import { PoolTemplate } from "../PoolTemplate.js";
3
+ import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
79
4
  // @ts-ignore
80
- exports.poolBalancesMetaMixin = {
81
- statsUnderlyingBalances: function () {
82
- return __awaiter(this, void 0, void 0, function () {
83
- var swapContract, contractCalls, _poolWrappedBalances, _poolMetaCoinBalance, _poolNonMetaBalance, basePool, _basePoolExpectedAmounts, _a, _poolUnderlyingBalances;
84
- var _this = this;
85
- return __generator(this, function (_c) {
86
- switch (_c.label) {
87
- case 0:
88
- swapContract = curve_1.curve.contracts[this.address].multicallContract;
89
- contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
90
- return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
91
- case 1:
92
- _poolWrappedBalances = _c.sent();
93
- _poolWrappedBalances.unshift(_poolWrappedBalances.pop());
94
- _poolMetaCoinBalance = _poolWrappedBalances[0], _poolNonMetaBalance = _poolWrappedBalances.slice(1);
95
- basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
96
- if (!(this.basePool === "atricrypto3")) return [3 /*break*/, 3];
97
- return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(basePool, _poolMetaCoinBalance)];
98
- case 2:
99
- _a = _c.sent();
100
- return [3 /*break*/, 5];
101
- case 3: return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _poolMetaCoinBalance)];
102
- case 4:
103
- _a = _c.sent();
104
- _c.label = 5;
105
- case 5:
106
- _basePoolExpectedAmounts = _a;
107
- _poolUnderlyingBalances = __spreadArray(__spreadArray([], _poolNonMetaBalance, true), _basePoolExpectedAmounts, true);
108
- return [2 /*return*/, _poolUnderlyingBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.underlyingDecimals[i]); })];
109
- }
110
- });
111
- });
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]));
112
18
  },
113
19
  };
114
20
  // @ts-ignore
115
- exports.poolBalancesLendingMixin = {
116
- statsUnderlyingBalances: function () {
117
- return __awaiter(this, void 0, void 0, function () {
118
- var swapContract, contractCalls, _poolWrappedBalances, _rates, _poolUnderlyingBalances;
119
- var _this = this;
120
- return __generator(this, function (_a) {
121
- switch (_a.label) {
122
- case 0:
123
- swapContract = curve_1.curve.contracts[this.address].multicallContract;
124
- contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
125
- return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
126
- case 1:
127
- _poolWrappedBalances = _a.sent();
128
- return [4 /*yield*/, this._getRates()];
129
- case 2:
130
- _rates = _a.sent();
131
- _poolUnderlyingBalances = _poolWrappedBalances.map(function (_b, i) { return _b.mul(_rates[i]).div(ethers_1.ethers.BigNumber.from(10).pow(18)); });
132
- return [2 /*return*/, _poolUnderlyingBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.underlyingDecimals[i]); })];
133
- }
134
- });
135
- });
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]));
136
30
  },
137
31
  };
@@ -1,4 +1,4 @@
1
- import { PoolTemplate } from "../PoolTemplate";
1
+ import { PoolTemplate } from "../PoolTemplate.js";
2
2
  export declare const swapTricrypto2Mixin: PoolTemplate;
3
3
  export declare const swapMetaFactoryMixin: PoolTemplate;
4
4
  export declare const swapCryptoMetaFactoryMixin: PoolTemplate;