@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,70 +1,202 @@
|
|
|
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
|
+
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 };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
1
48
|
import { curve } from "../../curve.js";
|
|
2
49
|
import { fromBN, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
|
|
3
50
|
// @ts-ignore
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
51
|
+
function _withdrawOneCoinWrappedCheck(lpTokenAmount, coin) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
var lpTokenBalance, i, _lpTokenAmount;
|
|
54
|
+
return __generator(this, function (_a) {
|
|
55
|
+
switch (_a.label) {
|
|
56
|
+
case 0: return [4 /*yield*/, this.wallet.lpTokenBalances()];
|
|
57
|
+
case 1:
|
|
58
|
+
lpTokenBalance = (_a.sent())['lpToken'];
|
|
59
|
+
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
60
|
+
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
61
|
+
}
|
|
62
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
63
|
+
case 2:
|
|
64
|
+
_a.sent();
|
|
65
|
+
i = this._getCoinIdx(coin, false);
|
|
66
|
+
_lpTokenAmount = parseUnits(lpTokenAmount);
|
|
67
|
+
return [2 /*return*/, [_lpTokenAmount, i]];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
14
71
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
72
|
+
function _withdrawOneCoinWrappedMinAmount(_lpTokenAmount, i, slippage) {
|
|
73
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var _expectedLpTokenAmount, minAmountBN;
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
|
+
case 0: return [4 /*yield*/, this._withdrawOneCoinWrappedExpected(_lpTokenAmount, i)];
|
|
79
|
+
case 1:
|
|
80
|
+
_expectedLpTokenAmount = _a.sent();
|
|
81
|
+
minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
|
|
82
|
+
return [2 /*return*/, fromBN(minAmountBN)];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
20
86
|
}
|
|
21
87
|
// @ts-ignore
|
|
22
|
-
export
|
|
88
|
+
export var withdrawOneCoinWrappedLendingOrCryptoMixin = {
|
|
23
89
|
// @ts-ignore
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
90
|
+
_withdrawOneCoinWrapped: function (_lpTokenAmount, i, slippage, estimateGas) {
|
|
91
|
+
if (estimateGas === void 0) { estimateGas = false; }
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var _minAmount, contract, gas, gasLimit;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0: return [4 /*yield*/, _withdrawOneCoinWrappedMinAmount.call(this, _lpTokenAmount, i, slippage)];
|
|
97
|
+
case 1:
|
|
98
|
+
_minAmount = _a.sent();
|
|
99
|
+
contract = curve.contracts[this.address].contract;
|
|
100
|
+
return [4 /*yield*/, contract.remove_liquidity_one_coin.estimateGas(_lpTokenAmount, i, _minAmount, false, curve.constantOptions)];
|
|
101
|
+
case 2:
|
|
102
|
+
gas = _a.sent();
|
|
103
|
+
if (estimateGas)
|
|
104
|
+
return [2 /*return*/, Number(gas)];
|
|
105
|
+
gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(gas);
|
|
106
|
+
return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, false, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
107
|
+
case 3: return [2 /*return*/, (_a.sent()).hash];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
32
111
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
112
|
+
withdrawOneCoinWrappedEstimateGas: function (lpTokenAmount, coin) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
114
|
+
var _a, _lpTokenAmount, i;
|
|
115
|
+
return __generator(this, function (_b) {
|
|
116
|
+
switch (_b.label) {
|
|
117
|
+
case 0: return [4 /*yield*/, _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin)];
|
|
118
|
+
case 1:
|
|
119
|
+
_a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
|
|
120
|
+
return [4 /*yield*/, this._withdrawOneCoinWrapped(_lpTokenAmount, i, 0.1, true)];
|
|
121
|
+
case 2:
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
return [2 /*return*/, _b.sent()];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
38
127
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
128
|
+
withdrawOneCoinWrapped: function (lpTokenAmount, coin, slippage) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
+
var _a, _lpTokenAmount, i;
|
|
131
|
+
return __generator(this, function (_b) {
|
|
132
|
+
switch (_b.label) {
|
|
133
|
+
case 0: return [4 /*yield*/, _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin)];
|
|
134
|
+
case 1:
|
|
135
|
+
_a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
|
|
136
|
+
return [4 /*yield*/, this._withdrawOneCoinWrapped(_lpTokenAmount, i, slippage)];
|
|
137
|
+
case 2:
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
return [2 /*return*/, _b.sent()];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
44
143
|
},
|
|
45
144
|
};
|
|
46
145
|
// @ts-ignore
|
|
47
|
-
export
|
|
146
|
+
export var withdrawOneCoinWrappedMixin = {
|
|
48
147
|
// @ts-ignore
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
148
|
+
_withdrawOneCoinWrapped: function (_lpTokenAmount, i, slippage, estimateGas) {
|
|
149
|
+
if (estimateGas === void 0) { estimateGas = false; }
|
|
150
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
+
var _minAmount, contract, gas, gasLimit;
|
|
152
|
+
return __generator(this, function (_a) {
|
|
153
|
+
switch (_a.label) {
|
|
154
|
+
case 0: return [4 /*yield*/, _withdrawOneCoinWrappedMinAmount.call(this, _lpTokenAmount, i, slippage)];
|
|
155
|
+
case 1:
|
|
156
|
+
_minAmount = _a.sent();
|
|
157
|
+
contract = curve.contracts[this.address].contract;
|
|
158
|
+
return [4 /*yield*/, contract.remove_liquidity_one_coin.estimateGas(_lpTokenAmount, i, _minAmount, curve.constantOptions)];
|
|
159
|
+
case 2:
|
|
160
|
+
gas = _a.sent();
|
|
161
|
+
if (estimateGas)
|
|
162
|
+
return [2 /*return*/, Number(gas)];
|
|
163
|
+
gasLimit = mulBy1_3(gas);
|
|
164
|
+
return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
165
|
+
case 3: return [2 /*return*/, (_a.sent()).hash];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
57
169
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
170
|
+
withdrawOneCoinWrappedEstimateGas: function (lpTokenAmount, coin) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
+
var _a, _lpTokenAmount, i;
|
|
173
|
+
return __generator(this, function (_b) {
|
|
174
|
+
switch (_b.label) {
|
|
175
|
+
case 0: return [4 /*yield*/, _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin)];
|
|
176
|
+
case 1:
|
|
177
|
+
_a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
|
|
178
|
+
return [4 /*yield*/, this._withdrawOneCoinWrapped(_lpTokenAmount, i, 0.1, true)];
|
|
179
|
+
case 2:
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
return [2 /*return*/, _b.sent()];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
63
185
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
186
|
+
withdrawOneCoinWrapped: function (lpTokenAmount, coin, slippage) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
188
|
+
var _a, _lpTokenAmount, i;
|
|
189
|
+
return __generator(this, function (_b) {
|
|
190
|
+
switch (_b.label) {
|
|
191
|
+
case 0: return [4 /*yield*/, _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin)];
|
|
192
|
+
case 1:
|
|
193
|
+
_a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
|
|
194
|
+
return [4 /*yield*/, this._withdrawOneCoinWrapped(_lpTokenAmount, i, slippage)];
|
|
195
|
+
case 2:
|
|
196
|
+
// @ts-ignore
|
|
197
|
+
return [2 /*return*/, _b.sent()];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
69
201
|
},
|
|
70
202
|
};
|
|
@@ -1,67 +1,202 @@
|
|
|
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
|
+
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 };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
1
48
|
import { curve } from "../../curve.js";
|
|
2
49
|
import { fromBN, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
|
|
3
50
|
// @ts-ignore
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
51
|
+
function _withdrawWrappedCheck(lpTokenAmount) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
var lpTokenBalance;
|
|
54
|
+
return __generator(this, function (_b) {
|
|
55
|
+
switch (_b.label) {
|
|
56
|
+
case 0: return [4 /*yield*/, this.wallet.lpTokenBalances()];
|
|
57
|
+
case 1:
|
|
58
|
+
lpTokenBalance = (_b.sent())['lpToken'];
|
|
59
|
+
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
60
|
+
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
61
|
+
}
|
|
62
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
63
|
+
case 2:
|
|
64
|
+
_b.sent();
|
|
65
|
+
return [2 /*return*/, parseUnits(lpTokenAmount)];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
11
69
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
70
|
+
function _withdrawWrappedMinAmounts(_lpTokenAmount, slippage) {
|
|
71
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
var expectedAmounts, _expectedAmounts, minRecvAmountsBN;
|
|
74
|
+
var _this = this;
|
|
75
|
+
return __generator(this, function (_b) {
|
|
76
|
+
switch (_b.label) {
|
|
77
|
+
case 0: return [4 /*yield*/, this.withdrawWrappedExpected(curve.formatUnits(_lpTokenAmount))];
|
|
78
|
+
case 1:
|
|
79
|
+
expectedAmounts = _b.sent();
|
|
80
|
+
_expectedAmounts = expectedAmounts.map(function (a, i) { return curve.parseUnits(a, _this.wrappedDecimals[i]); });
|
|
81
|
+
minRecvAmountsBN = _expectedAmounts.map(function (_a, i) { return toBN(_a, _this.wrappedDecimals[i]).times(100 - slippage).div(100); });
|
|
82
|
+
return [2 /*return*/, minRecvAmountsBN.map(function (a, i) { return fromBN(a, _this.wrappedDecimals[i]); })];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
17
86
|
}
|
|
18
87
|
// @ts-ignore
|
|
19
|
-
export
|
|
88
|
+
export var withdrawWrapped2argsMixin = {
|
|
20
89
|
// @ts-ignore
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
90
|
+
_withdrawWrapped: function (_lpTokenAmount, slippage, estimateGas) {
|
|
91
|
+
if (estimateGas === void 0) { estimateGas = false; }
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var _minAmounts, contract, gas, gasLimit;
|
|
94
|
+
return __generator(this, function (_b) {
|
|
95
|
+
switch (_b.label) {
|
|
96
|
+
case 0: return [4 /*yield*/, _withdrawWrappedMinAmounts.call(this, _lpTokenAmount, slippage)];
|
|
97
|
+
case 1:
|
|
98
|
+
_minAmounts = _b.sent();
|
|
99
|
+
contract = curve.contracts[this.address].contract;
|
|
100
|
+
return [4 /*yield*/, contract.remove_liquidity.estimateGas(_lpTokenAmount, _minAmounts, curve.constantOptions)];
|
|
101
|
+
case 2:
|
|
102
|
+
gas = _b.sent();
|
|
103
|
+
if (estimateGas)
|
|
104
|
+
return [2 /*return*/, Number(gas)];
|
|
105
|
+
gasLimit = mulBy1_3(gas);
|
|
106
|
+
return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
107
|
+
case 3: return [2 /*return*/, (_b.sent()).hash];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
29
111
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
112
|
+
withdrawWrappedEstimateGas: function (lpTokenAmount) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
114
|
+
var _lpTokenAmount;
|
|
115
|
+
return __generator(this, function (_b) {
|
|
116
|
+
switch (_b.label) {
|
|
117
|
+
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
118
|
+
case 1:
|
|
119
|
+
_lpTokenAmount = _b.sent();
|
|
120
|
+
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, 0.1, true)];
|
|
121
|
+
case 2:
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
return [2 /*return*/, _b.sent()];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
35
127
|
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
128
|
+
withdrawWrapped: function (lpTokenAmount, slippage) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
+
var _lpTokenAmount;
|
|
131
|
+
return __generator(this, function (_b) {
|
|
132
|
+
switch (_b.label) {
|
|
133
|
+
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
134
|
+
case 1:
|
|
135
|
+
_lpTokenAmount = _b.sent();
|
|
136
|
+
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, slippage)];
|
|
137
|
+
case 2:
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
return [2 /*return*/, _b.sent()];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
41
143
|
},
|
|
42
144
|
};
|
|
43
145
|
// @ts-ignore
|
|
44
|
-
export
|
|
146
|
+
export var withdrawWrapped3argsMixin = {
|
|
45
147
|
// @ts-ignore
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
148
|
+
_withdrawWrapped: function (_lpTokenAmount, slippage, estimateGas) {
|
|
149
|
+
if (estimateGas === void 0) { estimateGas = false; }
|
|
150
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
+
var _minAmounts, contract, gas, gasLimit;
|
|
152
|
+
return __generator(this, function (_b) {
|
|
153
|
+
switch (_b.label) {
|
|
154
|
+
case 0: return [4 /*yield*/, _withdrawWrappedMinAmounts.call(this, _lpTokenAmount, slippage)];
|
|
155
|
+
case 1:
|
|
156
|
+
_minAmounts = _b.sent();
|
|
157
|
+
contract = curve.contracts[this.address].contract;
|
|
158
|
+
return [4 /*yield*/, contract.remove_liquidity.estimateGas(_lpTokenAmount, _minAmounts, false, curve.constantOptions)];
|
|
159
|
+
case 2:
|
|
160
|
+
gas = _b.sent();
|
|
161
|
+
if (estimateGas)
|
|
162
|
+
return [2 /*return*/, Number(gas)];
|
|
163
|
+
gasLimit = mulBy1_3(gas);
|
|
164
|
+
return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, false, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
165
|
+
case 3: return [2 /*return*/, (_b.sent()).hash];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
54
169
|
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
170
|
+
withdrawWrappedEstimateGas: function (lpTokenAmount) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
+
var _lpTokenAmount;
|
|
173
|
+
return __generator(this, function (_b) {
|
|
174
|
+
switch (_b.label) {
|
|
175
|
+
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
176
|
+
case 1:
|
|
177
|
+
_lpTokenAmount = _b.sent();
|
|
178
|
+
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, 0.1, true)];
|
|
179
|
+
case 2:
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
return [2 /*return*/, _b.sent()];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
60
185
|
},
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
186
|
+
withdrawWrapped: function (lpTokenAmount, slippage) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
188
|
+
var _lpTokenAmount;
|
|
189
|
+
return __generator(this, function (_b) {
|
|
190
|
+
switch (_b.label) {
|
|
191
|
+
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
192
|
+
case 1:
|
|
193
|
+
_lpTokenAmount = _b.sent();
|
|
194
|
+
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, slippage)];
|
|
195
|
+
case 2:
|
|
196
|
+
// @ts-ignore
|
|
197
|
+
return [2 /*return*/, _b.sent()];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
66
201
|
},
|
|
67
202
|
};
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
1
16
|
import { curve } from "../curve.js";
|
|
2
17
|
import { PoolTemplate } from "./PoolTemplate.js";
|
|
3
18
|
import { poolBalancesMetaMixin, poolBalancesLendingMixin } from "./mixins/poolBalancesMixin.js";
|
|
@@ -15,15 +30,20 @@ import { withdrawOneCoinWrappedExpected2argsMixin, withdrawOneCoinWrappedExpecte
|
|
|
15
30
|
import { withdrawOneCoinWrappedLendingOrCryptoMixin, withdrawOneCoinWrappedMixin } from "./mixins/withdrawOneCoinWrappedMixins.js";
|
|
16
31
|
import { swapTricrypto2Mixin, swapMetaFactoryMixin, swapCryptoMetaFactoryMixin, swapMixin } from "./mixins/swapMixins.js";
|
|
17
32
|
import { swapWrappedExpectedAndApproveMixin, swapWrappedTricrypto2Mixin, swapWrappedMixin } from "./mixins/swapWrappedMixins.js";
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
export var getPool = function (poolId) {
|
|
34
|
+
var poolDummy = new PoolTemplate(poolId);
|
|
35
|
+
var Pool = /** @class */ (function (_super) {
|
|
36
|
+
__extends(Pool, _super);
|
|
37
|
+
function Pool() {
|
|
38
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
39
|
+
}
|
|
40
|
+
return Pool;
|
|
41
|
+
}(PoolTemplate));
|
|
22
42
|
// statsBalances
|
|
23
43
|
if (poolDummy.isMeta) {
|
|
24
44
|
Object.assign(Pool.prototype, poolBalancesMetaMixin);
|
|
25
45
|
}
|
|
26
|
-
else if (poolDummy.useLending.reduce((x, y)
|
|
46
|
+
else if (poolDummy.useLending.reduce(function (x, y) { return x || y; })) {
|
|
27
47
|
Object.assign(Pool.prototype, poolBalancesLendingMixin);
|
|
28
48
|
}
|
|
29
49
|
// depositBalancedAmounts
|