@curvefi/api 2.63.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 +19 -19
- 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 +1 -1
- 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 +34 -34
- 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 -918
- package/package.json +1 -1
|
@@ -7,63 +7,22 @@ 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
|
// @ts-ignore
|
|
39
|
-
export
|
|
40
|
-
_withdrawOneCoinWrappedExpected
|
|
41
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
-
|
|
43
|
-
return
|
|
44
|
-
switch (_a.label) {
|
|
45
|
-
case 0:
|
|
46
|
-
contract = curve.contracts[this.address].contract;
|
|
47
|
-
return [4 /*yield*/, contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve.constantOptions)];
|
|
48
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
49
|
-
}
|
|
50
|
-
});
|
|
12
|
+
export const withdrawOneCoinWrappedExpected2argsMixin = {
|
|
13
|
+
_withdrawOneCoinWrappedExpected(_lpTokenAmount, i) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const contract = curve.contracts[this.address].contract;
|
|
16
|
+
return yield contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve.constantOptions);
|
|
51
17
|
});
|
|
52
18
|
},
|
|
53
19
|
};
|
|
54
20
|
// @ts-ignore
|
|
55
|
-
export
|
|
56
|
-
_withdrawOneCoinWrappedExpected
|
|
57
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
switch (_a.label) {
|
|
61
|
-
case 0:
|
|
62
|
-
contract = curve.contracts[this.address].contract;
|
|
63
|
-
return [4 /*yield*/, contract.calc_withdraw_one_coin(_lpTokenAmount, i, false, curve.constantOptions)];
|
|
64
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
21
|
+
export const withdrawOneCoinWrappedExpected3argsMixin = {
|
|
22
|
+
_withdrawOneCoinWrappedExpected(_lpTokenAmount, i) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const contract = curve.contracts[this.address].contract;
|
|
25
|
+
return yield contract.calc_withdraw_one_coin(_lpTokenAmount, i, false, curve.constantOptions);
|
|
67
26
|
});
|
|
68
27
|
},
|
|
69
28
|
};
|
|
@@ -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,185 +7,89 @@ 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 { fromBN, toBN, parseUnits, mulBy1_3, smartNumber, DIGas } from '../../utils.js';
|
|
50
12
|
// @ts-ignore
|
|
51
13
|
function _withdrawOneCoinWrappedCheck(lpTokenAmount, coin) {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
});
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const lpTokenBalance = (yield this.wallet.lpTokenBalances())['lpToken'];
|
|
16
|
+
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
17
|
+
throw Error(`Not enough LP tokens. Actual: ${lpTokenBalance}, required: ${lpTokenAmount}`);
|
|
18
|
+
}
|
|
19
|
+
yield curve.updateFeeData();
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
const i = this._getCoinIdx(coin, false);
|
|
22
|
+
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
23
|
+
return [_lpTokenAmount, i];
|
|
70
24
|
});
|
|
71
25
|
}
|
|
72
|
-
function _withdrawOneCoinWrappedMinAmount(_lpTokenAmount, i, slippage) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
});
|
|
26
|
+
function _withdrawOneCoinWrappedMinAmount(_lpTokenAmount, i, slippage = 0.5) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
const _expectedLpTokenAmount = yield this._withdrawOneCoinWrappedExpected(_lpTokenAmount, i);
|
|
30
|
+
const minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
|
|
31
|
+
return fromBN(minAmountBN);
|
|
85
32
|
});
|
|
86
33
|
}
|
|
87
34
|
// @ts-ignore
|
|
88
|
-
export
|
|
35
|
+
export const withdrawOneCoinWrappedLendingOrCryptoMixin = {
|
|
89
36
|
// @ts-ignore
|
|
90
|
-
_withdrawOneCoinWrapped
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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*/, smartNumber(gas)];
|
|
105
|
-
gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(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
|
-
});
|
|
37
|
+
_withdrawOneCoinWrapped(_lpTokenAmount, i, slippage, estimateGas = false) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const _minAmount = yield _withdrawOneCoinWrappedMinAmount.call(this, _lpTokenAmount, i, slippage);
|
|
40
|
+
const contract = curve.contracts[this.address].contract;
|
|
41
|
+
const gas = yield contract.remove_liquidity_one_coin.estimateGas(_lpTokenAmount, i, _minAmount, false, curve.constantOptions);
|
|
42
|
+
if (estimateGas)
|
|
43
|
+
return smartNumber(gas);
|
|
44
|
+
const gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
|
|
45
|
+
return (yield contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, false, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
110
46
|
});
|
|
111
47
|
},
|
|
112
|
-
withdrawOneCoinWrappedEstimateGas
|
|
113
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
});
|
|
48
|
+
withdrawOneCoinWrappedEstimateGas(lpTokenAmount, coin) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
const [_lpTokenAmount, i] = yield _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin);
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
return yield this._withdrawOneCoinWrapped(_lpTokenAmount, i, 0.1, true);
|
|
126
54
|
});
|
|
127
55
|
},
|
|
128
|
-
withdrawOneCoinWrapped
|
|
129
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
});
|
|
56
|
+
withdrawOneCoinWrapped(lpTokenAmount, coin, slippage) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
const [_lpTokenAmount, i] = yield _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin);
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
return yield this._withdrawOneCoinWrapped(_lpTokenAmount, i, slippage);
|
|
142
62
|
});
|
|
143
63
|
},
|
|
144
64
|
};
|
|
145
65
|
// @ts-ignore
|
|
146
|
-
export
|
|
66
|
+
export const withdrawOneCoinWrappedMixin = {
|
|
147
67
|
// @ts-ignore
|
|
148
|
-
_withdrawOneCoinWrapped
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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*/, smartNumber(gas)];
|
|
163
|
-
gasLimit = mulBy1_3(DIGas(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
|
-
});
|
|
68
|
+
_withdrawOneCoinWrapped(_lpTokenAmount, i, slippage, estimateGas = false) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const _minAmount = yield _withdrawOneCoinWrappedMinAmount.call(this, _lpTokenAmount, i, slippage);
|
|
71
|
+
const contract = curve.contracts[this.address].contract;
|
|
72
|
+
const gas = yield contract.remove_liquidity_one_coin.estimateGas(_lpTokenAmount, i, _minAmount, curve.constantOptions);
|
|
73
|
+
if (estimateGas)
|
|
74
|
+
return smartNumber(gas);
|
|
75
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
76
|
+
return (yield contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
168
77
|
});
|
|
169
78
|
},
|
|
170
|
-
withdrawOneCoinWrappedEstimateGas
|
|
171
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
});
|
|
79
|
+
withdrawOneCoinWrappedEstimateGas(lpTokenAmount, coin) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
const [_lpTokenAmount, i] = yield _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin);
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
return yield this._withdrawOneCoinWrapped(_lpTokenAmount, i, 0.1, true);
|
|
184
85
|
});
|
|
185
86
|
},
|
|
186
|
-
withdrawOneCoinWrapped
|
|
187
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
});
|
|
87
|
+
withdrawOneCoinWrapped(lpTokenAmount, coin, slippage) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
const [_lpTokenAmount, i] = yield _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin);
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
return yield this._withdrawOneCoinWrapped(_lpTokenAmount, i, slippage);
|
|
200
93
|
});
|
|
201
94
|
},
|
|
202
95
|
};
|
|
@@ -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,185 +7,86 @@ 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 { fromBN, toBN, parseUnits, mulBy1_3, smartNumber, DIGas } from '../../utils.js';
|
|
50
12
|
// @ts-ignore
|
|
51
13
|
function _withdrawWrappedCheck(lpTokenAmount) {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
});
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const lpTokenBalance = (yield this.wallet.lpTokenBalances())['lpToken'];
|
|
16
|
+
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
17
|
+
throw Error(`Not enough LP tokens. Actual: ${lpTokenBalance}, required: ${lpTokenAmount}`);
|
|
18
|
+
}
|
|
19
|
+
yield curve.updateFeeData();
|
|
20
|
+
return parseUnits(lpTokenAmount);
|
|
68
21
|
});
|
|
69
22
|
}
|
|
70
|
-
function _withdrawWrappedMinAmounts(_lpTokenAmount, slippage) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return
|
|
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
|
-
});
|
|
23
|
+
function _withdrawWrappedMinAmounts(_lpTokenAmount, slippage = 0.5) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const expectedAmounts = yield this.withdrawWrappedExpected(curve.formatUnits(_lpTokenAmount));
|
|
26
|
+
const _expectedAmounts = expectedAmounts.map((a, i) => curve.parseUnits(a, this.wrappedDecimals[i]));
|
|
27
|
+
const minRecvAmountsBN = _expectedAmounts.map((_a, i) => toBN(_a, this.wrappedDecimals[i]).times(100 - slippage).div(100));
|
|
28
|
+
return minRecvAmountsBN.map((a, i) => fromBN(a, this.wrappedDecimals[i]));
|
|
85
29
|
});
|
|
86
30
|
}
|
|
87
31
|
// @ts-ignore
|
|
88
|
-
export
|
|
32
|
+
export const withdrawWrapped2argsMixin = {
|
|
89
33
|
// @ts-ignore
|
|
90
|
-
_withdrawWrapped
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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*/, smartNumber(gas)];
|
|
105
|
-
gasLimit = mulBy1_3(DIGas(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
|
-
});
|
|
34
|
+
_withdrawWrapped(_lpTokenAmount, slippage, estimateGas = false) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const _minAmounts = yield _withdrawWrappedMinAmounts.call(this, _lpTokenAmount, slippage);
|
|
37
|
+
const contract = curve.contracts[this.address].contract;
|
|
38
|
+
const gas = yield contract.remove_liquidity.estimateGas(_lpTokenAmount, _minAmounts, curve.constantOptions);
|
|
39
|
+
if (estimateGas)
|
|
40
|
+
return smartNumber(gas);
|
|
41
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
42
|
+
return (yield contract.remove_liquidity(_lpTokenAmount, _minAmounts, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
110
43
|
});
|
|
111
44
|
},
|
|
112
|
-
withdrawWrappedEstimateGas
|
|
113
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
});
|
|
45
|
+
withdrawWrappedEstimateGas(lpTokenAmount) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
const _lpTokenAmount = yield _withdrawWrappedCheck.call(this, lpTokenAmount);
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
return yield this._withdrawWrapped(_lpTokenAmount, 0.1, true);
|
|
126
51
|
});
|
|
127
52
|
},
|
|
128
|
-
withdrawWrapped
|
|
129
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
});
|
|
53
|
+
withdrawWrapped(lpTokenAmount, slippage) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
const _lpTokenAmount = yield _withdrawWrappedCheck.call(this, lpTokenAmount);
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
return yield this._withdrawWrapped(_lpTokenAmount, slippage);
|
|
142
59
|
});
|
|
143
60
|
},
|
|
144
61
|
};
|
|
145
62
|
// @ts-ignore
|
|
146
|
-
export
|
|
63
|
+
export const withdrawWrapped3argsMixin = {
|
|
147
64
|
// @ts-ignore
|
|
148
|
-
_withdrawWrapped
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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*/, smartNumber(gas)];
|
|
163
|
-
gasLimit = mulBy1_3(DIGas(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
|
-
});
|
|
65
|
+
_withdrawWrapped(_lpTokenAmount, slippage, estimateGas = false) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const _minAmounts = yield _withdrawWrappedMinAmounts.call(this, _lpTokenAmount, slippage);
|
|
68
|
+
const contract = curve.contracts[this.address].contract;
|
|
69
|
+
const gas = yield contract.remove_liquidity.estimateGas(_lpTokenAmount, _minAmounts, false, curve.constantOptions);
|
|
70
|
+
if (estimateGas)
|
|
71
|
+
return smartNumber(gas);
|
|
72
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
73
|
+
return (yield contract.remove_liquidity(_lpTokenAmount, _minAmounts, false, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
168
74
|
});
|
|
169
75
|
},
|
|
170
|
-
withdrawWrappedEstimateGas
|
|
171
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
});
|
|
76
|
+
withdrawWrappedEstimateGas(lpTokenAmount) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
const _lpTokenAmount = yield _withdrawWrappedCheck.call(this, lpTokenAmount);
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
return yield this._withdrawWrapped(_lpTokenAmount, 0.1, true);
|
|
184
82
|
});
|
|
185
83
|
},
|
|
186
|
-
withdrawWrapped
|
|
187
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
});
|
|
84
|
+
withdrawWrapped(lpTokenAmount, slippage) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
const _lpTokenAmount = yield _withdrawWrappedCheck.call(this, lpTokenAmount);
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
return yield this._withdrawWrapped(_lpTokenAmount, slippage);
|
|
200
90
|
});
|
|
201
91
|
},
|
|
202
92
|
};
|