@curvefi/api 2.62.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.
- package/lib/boosting.js +247 -645
- package/lib/constants/L2Networks.js +1 -1
- package/lib/constants/aliases.js +31 -31
- 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/base.js +5 -5
- package/lib/constants/coins/bsc.js +5 -5
- package/lib/constants/coins/celo.js +5 -5
- package/lib/constants/coins/ethereum.js +9 -9
- package/lib/constants/coins/fantom.js +7 -7
- package/lib/constants/coins/fraxtal.js +5 -5
- package/lib/constants/coins/kava.js +5 -5
- package/lib/constants/coins/mantle.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/coins/xlayer.js +5 -5
- package/lib/constants/coins/zksync.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/base.js +1 -1
- package/lib/constants/pools/bsc.js +1 -1
- package/lib/constants/pools/celo.js +1 -1
- package/lib/constants/pools/ethereum.js +2 -2
- package/lib/constants/pools/fantom.js +1 -1
- package/lib/constants/pools/fraxtal.js +1 -1
- package/lib/constants/pools/kava.js +1 -1
- package/lib/constants/pools/mantle.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/pools/xlayer.js +1 -1
- package/lib/constants/pools/zksync.js +1 -1
- package/lib/constants/tricryptoDeployImplementations.js +3 -3
- package/lib/constants/utils.js +18 -19
- package/lib/constants/volumeNetworks.js +1 -1
- package/lib/curve.d.ts +3 -1
- package/lib/curve.js +534 -909
- package/lib/dao.js +351 -705
- package/lib/external-api.js +127 -256
- package/lib/factory/common.js +4 -4
- package/lib/factory/constants-crypto.js +33 -33
- package/lib/factory/constants.js +36 -46
- package/lib/factory/deploy.js +542 -907
- package/lib/factory/factory-api.js +205 -269
- package/lib/factory/factory-crypto.js +202 -342
- package/lib/factory/factory-tricrypto.js +164 -286
- package/lib/factory/factory-twocrypto.js +151 -269
- package/lib/factory/factory.js +245 -385
- package/lib/index.js +109 -198
- package/lib/interfaces.d.ts +1 -6
- package/lib/pools/PoolTemplate.js +1773 -3025
- package/lib/pools/gaugePool.js +112 -251
- package/lib/pools/mixins/common.js +22 -93
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +52 -118
- package/lib/pools/mixins/depositMixins.js +160 -386
- package/lib/pools/mixins/depositWrappedMixins.js +79 -205
- package/lib/pools/mixins/poolBalancesMixin.js +24 -87
- package/lib/pools/mixins/swapMixins.js +139 -324
- package/lib/pools/mixins/swapWrappedMixins.js +111 -265
- package/lib/pools/mixins/withdrawExpectedMixins.js +27 -91
- package/lib/pools/mixins/withdrawImbalanceMixins.js +111 -293
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +58 -169
- package/lib/pools/mixins/withdrawMixins.js +139 -359
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +20 -75
- package/lib/pools/mixins/withdrawOneCoinMixins.js +140 -360
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +10 -51
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +60 -167
- package/lib/pools/mixins/withdrawWrappedMixins.js +57 -167
- package/lib/pools/poolConstructor.js +5 -25
- package/lib/pools/utils.js +301 -469
- package/lib/route-finder.worker.d.ts +9 -0
- package/lib/route-finder.worker.js +112 -0
- package/lib/route-graph.worker.d.ts +11 -0
- package/lib/route-graph.worker.js +334 -0
- package/lib/router.js +323 -912
- package/lib/utils.d.ts +5 -4
- package/lib/utils.js +539 -906
- 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,296 +7,153 @@ 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, _getCoinDecimals, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
|
|
50
12
|
// @ts-ignore
|
|
51
|
-
function _swapWrappedCheck(inputCoin, outputCoin, amount, estimateGas) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (!_c) return [3 /*break*/, 3];
|
|
69
|
-
return [4 /*yield*/, hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address)];
|
|
70
|
-
case 2:
|
|
71
|
-
_c = !(_d.sent());
|
|
72
|
-
_d.label = 3;
|
|
73
|
-
case 3:
|
|
74
|
-
if (_c) {
|
|
75
|
-
throw Error("Token allowance is needed to estimate gas");
|
|
76
|
-
}
|
|
77
|
-
if (!!estimateGas) return [3 /*break*/, 5];
|
|
78
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
79
|
-
case 4:
|
|
80
|
-
_d.sent();
|
|
81
|
-
_d.label = 5;
|
|
82
|
-
case 5:
|
|
83
|
-
_amount = parseUnits(amount, this.wrappedDecimals[i]);
|
|
84
|
-
return [2 /*return*/, [i, j, _amount]];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
13
|
+
function _swapWrappedCheck(inputCoin, outputCoin, amount, estimateGas = false) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const j = this._getCoinIdx(outputCoin, false);
|
|
19
|
+
const inputCoinBalance = Object.values(yield this.wallet.wrappedCoinBalances())[i];
|
|
20
|
+
if (Number(inputCoinBalance) < Number(amount)) {
|
|
21
|
+
throw Error(`Not enough ${this.wrappedCoins[i]}. Actual: ${inputCoinBalance}, required: ${amount}`);
|
|
22
|
+
}
|
|
23
|
+
if (estimateGas && !(yield hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address))) {
|
|
24
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
25
|
+
}
|
|
26
|
+
if (!estimateGas)
|
|
27
|
+
yield curve.updateFeeData();
|
|
28
|
+
const _amount = parseUnits(amount, this.wrappedDecimals[i]);
|
|
29
|
+
return [i, j, _amount];
|
|
87
30
|
});
|
|
88
31
|
}
|
|
89
|
-
function _swapWrappedMinAmount(i, j, _amount, slippage) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
case 1:
|
|
97
|
-
_expected = _a.sent();
|
|
98
|
-
outputCoinDecimals = _getCoinDecimals(this.wrappedCoinAddresses[j])[0];
|
|
99
|
-
minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
|
|
100
|
-
return [2 /*return*/, fromBN(minAmountBN, outputCoinDecimals)];
|
|
101
|
-
}
|
|
102
|
-
});
|
|
32
|
+
function _swapWrappedMinAmount(i, j, _amount, slippage = 0.5) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
const _expected = yield this._swapWrappedExpected(i, j, _amount);
|
|
36
|
+
const [outputCoinDecimals] = _getCoinDecimals(this.wrappedCoinAddresses[j]);
|
|
37
|
+
const minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
|
|
38
|
+
return fromBN(minAmountBN, outputCoinDecimals);
|
|
103
39
|
});
|
|
104
40
|
}
|
|
105
41
|
// @ts-ignore
|
|
106
|
-
export
|
|
42
|
+
export const swapWrappedTricrypto2Mixin = {
|
|
107
43
|
// @ts-ignore
|
|
108
|
-
_swapWrapped
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
case 2: return [4 /*yield*/, _swapWrappedMinAmount.call(this, i, j, _amount, slippage)];
|
|
121
|
-
case 3:
|
|
122
|
-
_minRecvAmount = _a.sent();
|
|
123
|
-
contract = curve.contracts[this.address].contract;
|
|
124
|
-
value = isEth(this.wrappedCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
125
|
-
return [4 /*yield*/, contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
126
|
-
case 4:
|
|
127
|
-
gas = _a.sent();
|
|
128
|
-
if (estimateGas)
|
|
129
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
130
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
131
|
-
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
|
|
132
|
-
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
44
|
+
_swapWrapped(i, j, _amount, slippage, estimateGas = false) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
if (!estimateGas)
|
|
47
|
+
yield _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
|
|
48
|
+
const _minRecvAmount = yield _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
|
|
49
|
+
const contract = curve.contracts[this.address].contract;
|
|
50
|
+
const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
51
|
+
const gas = yield contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, false, Object.assign(Object.assign({}, curve.constantOptions), { value }));
|
|
52
|
+
if (estimateGas)
|
|
53
|
+
return smartNumber(gas);
|
|
54
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
55
|
+
return (yield contract.exchange(i, j, _amount, _minRecvAmount, false, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
|
|
135
56
|
});
|
|
136
57
|
},
|
|
137
|
-
swapWrappedEstimateGas
|
|
138
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
case 1:
|
|
144
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
145
|
-
return [4 /*yield*/, this._swapWrapped(i, j, _amount, 0.1, true)];
|
|
146
|
-
case 2:
|
|
147
|
-
// @ts-ignore
|
|
148
|
-
return [2 /*return*/, _b.sent()];
|
|
149
|
-
}
|
|
150
|
-
});
|
|
58
|
+
swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
return yield this._swapWrapped(i, j, _amount, 0.1, true);
|
|
151
64
|
});
|
|
152
65
|
},
|
|
153
|
-
swapWrapped
|
|
154
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
case 1:
|
|
160
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
161
|
-
return [4 /*yield*/, this._swapWrapped(i, j, _amount, slippage)];
|
|
162
|
-
case 2:
|
|
163
|
-
// @ts-ignore
|
|
164
|
-
return [2 /*return*/, _b.sent()];
|
|
165
|
-
}
|
|
166
|
-
});
|
|
66
|
+
swapWrapped(inputCoin, outputCoin, amount, slippage) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
return yield this._swapWrapped(i, j, _amount, slippage);
|
|
167
72
|
});
|
|
168
73
|
},
|
|
169
74
|
};
|
|
170
75
|
// @ts-ignore
|
|
171
|
-
export
|
|
76
|
+
export const swapWrappedMixin = {
|
|
172
77
|
// @ts-ignore
|
|
173
|
-
_swapWrapped
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
case 2: return [4 /*yield*/, _swapWrappedMinAmount.call(this, i, j, _amount, slippage)];
|
|
186
|
-
case 3:
|
|
187
|
-
_minRecvAmount = _a.sent();
|
|
188
|
-
contract = curve.contracts[this.address].contract;
|
|
189
|
-
value = isEth(this.wrappedCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
190
|
-
return [4 /*yield*/, contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
191
|
-
case 4:
|
|
192
|
-
gas = _a.sent();
|
|
193
|
-
if (estimateGas)
|
|
194
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
195
|
-
gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
|
|
196
|
-
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
|
|
197
|
-
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
78
|
+
_swapWrapped(i, j, _amount, slippage, estimateGas = false) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
if (!estimateGas)
|
|
81
|
+
yield _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
|
|
82
|
+
const _minRecvAmount = yield _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
|
|
83
|
+
const contract = curve.contracts[this.address].contract;
|
|
84
|
+
const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
85
|
+
const gas = yield contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.constantOptions), { value }));
|
|
86
|
+
if (estimateGas)
|
|
87
|
+
return smartNumber(gas);
|
|
88
|
+
const gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
|
|
89
|
+
return (yield contract.exchange(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
|
|
200
90
|
});
|
|
201
91
|
},
|
|
202
|
-
swapWrappedEstimateGas
|
|
203
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
case 1:
|
|
209
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
210
|
-
return [4 /*yield*/, this._swapWrapped(i, j, _amount, 0.1, true)];
|
|
211
|
-
case 2:
|
|
212
|
-
// @ts-ignore
|
|
213
|
-
return [2 /*return*/, _b.sent()];
|
|
214
|
-
}
|
|
215
|
-
});
|
|
92
|
+
swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
return yield this._swapWrapped(i, j, _amount, 0.1, true);
|
|
216
98
|
});
|
|
217
99
|
},
|
|
218
|
-
swapWrapped
|
|
219
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
case 1:
|
|
225
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
226
|
-
return [4 /*yield*/, this._swapWrapped(i, j, _amount, slippage)];
|
|
227
|
-
case 2:
|
|
228
|
-
// @ts-ignore
|
|
229
|
-
return [2 /*return*/, _b.sent()];
|
|
230
|
-
}
|
|
231
|
-
});
|
|
100
|
+
swapWrapped(inputCoin, outputCoin, amount, slippage) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
|
|
104
|
+
// @ts-ignore
|
|
105
|
+
return yield this._swapWrapped(i, j, _amount, slippage);
|
|
232
106
|
});
|
|
233
107
|
},
|
|
234
108
|
};
|
|
235
109
|
// @ts-ignore
|
|
236
|
-
export
|
|
237
|
-
swapWrappedExpected
|
|
238
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
case 1:
|
|
248
|
-
_expected = _a.sent();
|
|
249
|
-
return [2 /*return*/, curve.formatUnits(_expected, this.wrappedDecimals[j])];
|
|
250
|
-
}
|
|
251
|
-
});
|
|
110
|
+
export const swapWrappedExpectedAndApproveMixin = {
|
|
111
|
+
swapWrappedExpected(inputCoin, outputCoin, amount) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
const j = this._getCoinIdx(outputCoin, false);
|
|
117
|
+
const _amount = parseUnits(amount, this.wrappedDecimals[i]);
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
const _expected = yield this._swapWrappedExpected(i, j, _amount);
|
|
120
|
+
return curve.formatUnits(_expected, this.wrappedDecimals[j]);
|
|
252
121
|
});
|
|
253
122
|
},
|
|
254
|
-
swapWrappedIsApproved
|
|
255
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
case 0:
|
|
260
|
-
i = this._getCoinIdx(inputCoin, false);
|
|
261
|
-
return [4 /*yield*/, hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address)];
|
|
262
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
263
|
-
}
|
|
264
|
-
});
|
|
123
|
+
swapWrappedIsApproved(inputCoin, amount) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
127
|
+
return yield hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address);
|
|
265
128
|
});
|
|
266
129
|
},
|
|
267
|
-
swapWrappedApproveEstimateGas
|
|
268
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
case 0:
|
|
273
|
-
i = this._getCoinIdx(inputCoin, false);
|
|
274
|
-
return [4 /*yield*/, ensureAllowanceEstimateGas([this.wrappedCoinAddresses[i]], [amount], this.address)];
|
|
275
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
276
|
-
}
|
|
277
|
-
});
|
|
130
|
+
swapWrappedApproveEstimateGas(inputCoin, amount) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
134
|
+
return yield ensureAllowanceEstimateGas([this.wrappedCoinAddresses[i]], [amount], this.address);
|
|
278
135
|
});
|
|
279
136
|
},
|
|
280
|
-
swapWrappedApprove
|
|
281
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
case 0:
|
|
286
|
-
i = this._getCoinIdx(inputCoin, false);
|
|
287
|
-
return [4 /*yield*/, ensureAllowance([this.wrappedCoinAddresses[i]], [amount], this.address)];
|
|
288
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
289
|
-
}
|
|
290
|
-
});
|
|
137
|
+
swapWrappedApprove(inputCoin, amount) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
141
|
+
return yield ensureAllowance([this.wrappedCoinAddresses[i]], [amount], this.address);
|
|
291
142
|
});
|
|
292
143
|
},
|
|
293
144
|
};
|
|
294
145
|
// @ts-ignore
|
|
295
|
-
export
|
|
296
|
-
swapWrappedRequired
|
|
297
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
case 1:
|
|
307
|
-
_required = _a.sent();
|
|
308
|
-
return [2 /*return*/, curve.formatUnits(_required, this.wrappedDecimals[i])];
|
|
309
|
-
}
|
|
310
|
-
});
|
|
146
|
+
export const swapWrappedRequiredMixin = {
|
|
147
|
+
swapWrappedRequired(inputCoin, outputCoin, amount) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
151
|
+
// @ts-ignore
|
|
152
|
+
const j = this._getCoinIdx(outputCoin, false);
|
|
153
|
+
const _amount = parseUnits(amount, this.wrappedDecimals[j]);
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
const _required = yield this._swapRequired(i, j, _amount, false);
|
|
156
|
+
return curve.formatUnits(_required, this.wrappedDecimals[i]);
|
|
311
157
|
});
|
|
312
158
|
},
|
|
313
159
|
};
|
|
@@ -7,113 +7,49 @@ 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
10
|
import { curve } from "../../curve.js";
|
|
38
11
|
import { parseUnits } from "../../utils.js";
|
|
39
12
|
import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
|
|
40
13
|
// @ts-ignore
|
|
41
|
-
export
|
|
42
|
-
withdrawExpected
|
|
43
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return
|
|
47
|
-
switch (_a.label) {
|
|
48
|
-
case 0:
|
|
49
|
-
_lpTokenAmount = parseUnits(lpTokenAmount);
|
|
50
|
-
return [4 /*yield*/, _calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
51
|
-
case 1:
|
|
52
|
-
_expected = _a.sent();
|
|
53
|
-
return [2 /*return*/, _expected.map(function (amount, i) { return curve.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
54
|
-
}
|
|
55
|
-
});
|
|
14
|
+
export const withdrawExpectedMixin = {
|
|
15
|
+
withdrawExpected(lpTokenAmount) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
18
|
+
const _expected = yield _calcExpectedAmounts.call(this, _lpTokenAmount);
|
|
19
|
+
return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
|
|
56
20
|
});
|
|
57
21
|
},
|
|
58
22
|
};
|
|
59
23
|
// @ts-ignore
|
|
60
|
-
export
|
|
61
|
-
withdrawExpected
|
|
62
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return [4 /*yield*/, _calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
70
|
-
case 1:
|
|
71
|
-
_expectedAmounts = _a.sent();
|
|
72
|
-
return [4 /*yield*/, this._getRates()];
|
|
73
|
-
case 2:
|
|
74
|
-
_rates = _a.sent();
|
|
75
|
-
_expected = _expectedAmounts.map(function (_amount, i) { return _amount * _rates[i] / curve.parseUnits(String(Math.pow(10, 18)), 0); });
|
|
76
|
-
return [2 /*return*/, _expected.map(function (amount, i) { return curve.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
24
|
+
export const withdrawExpectedLendingOrCryptoMixin = {
|
|
25
|
+
withdrawExpected(lpTokenAmount) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
28
|
+
const _expectedAmounts = yield _calcExpectedAmounts.call(this, _lpTokenAmount);
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
const _rates = yield this._getRates();
|
|
31
|
+
const _expected = _expectedAmounts.map((_amount, i) => _amount * _rates[i] / curve.parseUnits(String(Math.pow(10, 18)), 0));
|
|
32
|
+
return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
|
|
79
33
|
});
|
|
80
34
|
},
|
|
81
35
|
};
|
|
82
36
|
// @ts-ignore
|
|
83
|
-
export
|
|
84
|
-
withdrawExpected
|
|
85
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return
|
|
89
|
-
switch (_a.label) {
|
|
90
|
-
case 0:
|
|
91
|
-
_lpTokenAmount = parseUnits(lpTokenAmount);
|
|
92
|
-
return [4 /*yield*/, _calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount)];
|
|
93
|
-
case 1:
|
|
94
|
-
_expected = _a.sent();
|
|
95
|
-
return [2 /*return*/, _expected.map(function (amount, i) { return curve.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
37
|
+
export const withdrawExpectedMetaMixin = {
|
|
38
|
+
withdrawExpected(lpTokenAmount) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
41
|
+
const _expected = yield _calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount);
|
|
42
|
+
return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
|
|
98
43
|
});
|
|
99
44
|
},
|
|
100
45
|
};
|
|
101
46
|
// @ts-ignore
|
|
102
|
-
export
|
|
103
|
-
withdrawWrappedExpected
|
|
104
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return
|
|
108
|
-
switch (_a.label) {
|
|
109
|
-
case 0:
|
|
110
|
-
_lpTokenAmount = parseUnits(lpTokenAmount);
|
|
111
|
-
return [4 /*yield*/, _calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
112
|
-
case 1:
|
|
113
|
-
_expected = _a.sent();
|
|
114
|
-
return [2 /*return*/, _expected.map(function (amount, i) { return curve.formatUnits(amount, _this.wrappedDecimals[i]); })];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
47
|
+
export const withdrawWrappedExpectedMixin = {
|
|
48
|
+
withdrawWrappedExpected(lpTokenAmount) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
51
|
+
const _expected = yield _calcExpectedAmounts.call(this, _lpTokenAmount);
|
|
52
|
+
return _expected.map((amount, i) => curve.formatUnits(amount, this.wrappedDecimals[i]));
|
|
117
53
|
});
|
|
118
54
|
},
|
|
119
55
|
};
|