@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.
- package/lib/boosting.js +385 -135
- package/lib/constants/abis/stable_calc.json +151 -0
- package/lib/constants/abis/wbeth/swap.json +1086 -0
- package/lib/constants/aliases.js +33 -11
- package/lib/constants/coins/arbitrum.js +5 -5
- package/lib/constants/coins/aurora.js +5 -5
- package/lib/constants/coins/avalanche.js +6 -6
- package/lib/constants/coins/celo.js +5 -5
- package/lib/constants/coins/ethereum.js +10 -9
- package/lib/constants/coins/fantom.js +7 -7
- package/lib/constants/coins/kava.js +5 -5
- package/lib/constants/coins/moonbeam.js +5 -5
- package/lib/constants/coins/optimism.js +5 -5
- package/lib/constants/coins/polygon.js +6 -6
- package/lib/constants/coins/xdai.js +5 -5
- package/lib/constants/pools/arbitrum.js +1 -1
- package/lib/constants/pools/aurora.js +1 -1
- package/lib/constants/pools/avalanche.js +1 -1
- package/lib/constants/pools/celo.js +1 -1
- package/lib/constants/pools/ethereum.js +26 -1
- package/lib/constants/pools/fantom.js +1 -1
- package/lib/constants/pools/kava.js +1 -1
- package/lib/constants/pools/moonbeam.js +1 -1
- package/lib/constants/pools/optimism.js +1 -1
- package/lib/constants/pools/polygon.js +1 -1
- package/lib/constants/pools/xdai.js +1 -1
- package/lib/constants/utils.d.ts +1 -1
- package/lib/constants/utils.js +19 -18
- package/lib/curve.js +507 -281
- package/lib/external-api.js +132 -45
- package/lib/factory/common.js +3 -3
- package/lib/factory/constants-crypto.js +21 -21
- package/lib/factory/constants.js +32 -31
- package/lib/factory/deploy.js +336 -176
- package/lib/factory/factory-api.js +256 -180
- package/lib/factory/factory-crypto.js +309 -163
- package/lib/factory/factory.d.ts +1 -1
- package/lib/factory/factory.js +336 -186
- package/lib/index.js +98 -44
- package/lib/interfaces.d.ts +1 -1
- package/lib/pools/PoolTemplate.js +2882 -1511
- package/lib/pools/mixins/common.js +106 -22
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +131 -48
- package/lib/pools/mixins/depositMixins.js +413 -144
- package/lib/pools/mixins/depositWrappedMixins.js +223 -72
- package/lib/pools/mixins/poolBalancesMixin.js +98 -22
- package/lib/pools/mixins/swapMixins.js +347 -125
- package/lib/pools/mixins/swapWrappedMixins.js +270 -88
- package/lib/pools/mixins/withdrawExpectedMixins.js +104 -23
- package/lib/pools/mixins/withdrawImbalanceMixins.js +316 -97
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +187 -51
- package/lib/pools/mixins/withdrawMixins.js +385 -122
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +88 -16
- package/lib/pools/mixins/withdrawOneCoinMixins.js +386 -123
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +62 -8
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +185 -53
- package/lib/pools/mixins/withdrawWrappedMixins.js +185 -50
- package/lib/pools/poolConstructor.js +25 -5
- package/lib/pools/utils.js +488 -298
- package/lib/router.js +636 -378
- package/lib/utils.js +675 -354
- package/package.json +1 -1
|
@@ -1,88 +1,239 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
109
|
+
export var depositWrapped2argsMixin = {
|
|
31
110
|
// @ts-ignore
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
|
175
|
+
export var depositWrapped3argsMixin = {
|
|
61
176
|
// @ts-ignore
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
};
|