@curvefi/api 2.31.0 → 2.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/boosting.js +137 -402
- package/lib/constants/aliases.d.ts +11 -11
- package/lib/constants/aliases.js +12 -15
- package/lib/constants/coins/arbitrum.js +6 -9
- package/lib/constants/coins/aurora.js +6 -9
- package/lib/constants/coins/avalanche.js +7 -10
- package/lib/constants/coins/celo.js +6 -9
- package/lib/constants/coins/ethereum.js +10 -13
- package/lib/constants/coins/fantom.js +8 -11
- package/lib/constants/coins/kava.js +6 -9
- package/lib/constants/coins/moonbeam.js +6 -9
- package/lib/constants/coins/optimism.js +6 -9
- package/lib/constants/coins/polygon.js +7 -10
- package/lib/constants/coins/xdai.js +6 -9
- package/lib/constants/pools/arbitrum.d.ts +2 -4
- package/lib/constants/pools/arbitrum.js +22 -28
- package/lib/constants/pools/aurora.d.ts +2 -4
- package/lib/constants/pools/aurora.js +6 -12
- package/lib/constants/pools/avalanche.d.ts +2 -4
- package/lib/constants/pools/avalanche.js +21 -27
- package/lib/constants/pools/celo.d.ts +2 -4
- package/lib/constants/pools/celo.js +2 -5
- package/lib/constants/pools/ethereum.js +247 -253
- package/lib/constants/pools/fantom.d.ts +2 -4
- package/lib/constants/pools/fantom.js +28 -34
- package/lib/constants/pools/index.d.ts +11 -11
- package/lib/constants/pools/index.js +12 -25
- package/lib/constants/pools/kava.d.ts +2 -4
- package/lib/constants/pools/kava.js +2 -5
- package/lib/constants/pools/moonbeam.d.ts +2 -4
- package/lib/constants/pools/moonbeam.js +6 -12
- package/lib/constants/pools/optimism.d.ts +2 -4
- package/lib/constants/pools/optimism.js +9 -15
- package/lib/constants/pools/polygon.d.ts +2 -4
- package/lib/constants/pools/polygon.js +22 -28
- package/lib/constants/pools/xdai.d.ts +2 -4
- package/lib/constants/pools/xdai.js +24 -30
- package/lib/constants/utils.js +20 -29
- package/lib/curve.d.ts +9 -7
- package/lib/curve.js +397 -615
- package/lib/external-api.d.ts +1 -1
- package/lib/external-api.js +47 -140
- package/lib/factory/common.js +6 -10
- package/lib/factory/constants-crypto.js +48 -54
- package/lib/factory/constants.js +274 -280
- package/lib/factory/deploy.d.ts +8 -8
- package/lib/factory/deploy.js +177 -347
- package/lib/factory/factory-api.js +195 -278
- package/lib/factory/factory-crypto.js +170 -323
- package/lib/factory/factory.js +195 -350
- package/lib/index.d.ts +24 -25
- package/lib/index.js +87 -143
- package/lib/interfaces.d.ts +5 -5
- package/lib/interfaces.js +1 -2
- package/lib/pools/PoolTemplate.js +1516 -2929
- package/lib/pools/index.d.ts +2 -2
- package/lib/pools/index.js +3 -7
- package/lib/pools/mixins/common.d.ts +3 -4
- package/lib/pools/mixins/common.js +23 -112
- package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +1 -1
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +50 -139
- package/lib/pools/mixins/depositMixins.d.ts +1 -1
- package/lib/pools/mixins/depositMixins.js +144 -417
- package/lib/pools/mixins/depositWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/depositWrappedMixins.js +72 -227
- package/lib/pools/mixins/poolBalancesMixin.d.ts +1 -1
- package/lib/pools/mixins/poolBalancesMixin.js +25 -105
- package/lib/pools/mixins/swapMixins.d.ts +1 -1
- package/lib/pools/mixins/swapMixins.js +127 -353
- package/lib/pools/mixins/swapWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/swapWrappedMixins.js +90 -276
- package/lib/pools/mixins/withdrawExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawExpectedMixins.js +26 -110
- package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawImbalanceMixins.js +99 -321
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +53 -192
- package/lib/pools/mixins/withdrawMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawMixins.js +123 -390
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +17 -92
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinMixins.js +124 -390
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +9 -66
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +55 -190
- package/lib/pools/mixins/withdrawWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawWrappedMixins.js +52 -191
- package/lib/pools/poolConstructor.d.ts +1 -1
- package/lib/pools/poolConstructor.js +77 -101
- package/lib/pools/utils.js +298 -500
- package/lib/router.d.ts +2 -2
- package/lib/router.js +390 -653
- package/lib/utils.d.ts +9 -9
- package/lib/utils.js +377 -731
- package/package.json +8 -8
|
@@ -1,205 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.withdrawOneCoinWrappedMixin = exports.withdrawOneCoinWrappedLendingOrCryptoMixin = void 0;
|
|
51
|
-
var curve_1 = require("../../curve");
|
|
52
|
-
var utils_1 = require("../../utils");
|
|
1
|
+
import { curve } from "../../curve.js";
|
|
2
|
+
import { fromBN, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
|
|
53
3
|
// @ts-ignore
|
|
54
|
-
function _withdrawOneCoinWrappedCheck(lpTokenAmount, coin) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
66
|
-
case 2:
|
|
67
|
-
_a.sent();
|
|
68
|
-
i = this._getCoinIdx(coin, false);
|
|
69
|
-
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
70
|
-
return [2 /*return*/, [_lpTokenAmount, i]];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
4
|
+
async function _withdrawOneCoinWrappedCheck(lpTokenAmount, coin) {
|
|
5
|
+
const lpTokenBalance = (await this.wallet.lpTokenBalances())['lpToken'];
|
|
6
|
+
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
7
|
+
throw Error(`Not enough LP tokens. Actual: ${lpTokenBalance}, required: ${lpTokenAmount}`);
|
|
8
|
+
}
|
|
9
|
+
await curve.updateFeeData();
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
const i = this._getCoinIdx(coin, false);
|
|
12
|
+
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
13
|
+
return [_lpTokenAmount, i];
|
|
74
14
|
}
|
|
75
|
-
function _withdrawOneCoinWrappedMinAmount(_lpTokenAmount, i, slippage) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
switch (_a.label) {
|
|
81
|
-
case 0: return [4 /*yield*/, this._withdrawOneCoinWrappedExpected(_lpTokenAmount, i)];
|
|
82
|
-
case 1:
|
|
83
|
-
_expectedLpTokenAmount = _a.sent();
|
|
84
|
-
minAmountBN = (0, utils_1.toBN)(_expectedLpTokenAmount).times(100 - slippage).div(100);
|
|
85
|
-
return [2 /*return*/, (0, utils_1.fromBN)(minAmountBN)];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
});
|
|
15
|
+
async function _withdrawOneCoinWrappedMinAmount(_lpTokenAmount, i, slippage = 0.5) {
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
const _expectedLpTokenAmount = await this._withdrawOneCoinWrappedExpected(_lpTokenAmount, i);
|
|
18
|
+
const minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
|
|
19
|
+
return fromBN(minAmountBN);
|
|
89
20
|
}
|
|
90
21
|
// @ts-ignore
|
|
91
|
-
|
|
22
|
+
export const withdrawOneCoinWrappedLendingOrCryptoMixin = {
|
|
92
23
|
// @ts-ignore
|
|
93
|
-
_withdrawOneCoinWrapped
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
_minAmount = _a.sent();
|
|
102
|
-
contract = curve_1.curve.contracts[this.address].contract;
|
|
103
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, false, curve_1.curve.constantOptions)];
|
|
104
|
-
case 2:
|
|
105
|
-
gas = _a.sent();
|
|
106
|
-
if (estimateGas)
|
|
107
|
-
return [2 /*return*/, gas.toNumber()];
|
|
108
|
-
gasLimit = curve_1.curve.chainId === 137 && this.id === 'ren' ? gas.mul(160).div(100) : gas.mul(130).div(100);
|
|
109
|
-
return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, false, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
110
|
-
case 3: return [2 /*return*/, (_a.sent()).hash];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
24
|
+
async _withdrawOneCoinWrapped(_lpTokenAmount, i, slippage, estimateGas = false) {
|
|
25
|
+
const _minAmount = await _withdrawOneCoinWrappedMinAmount.call(this, _lpTokenAmount, i, slippage);
|
|
26
|
+
const contract = curve.contracts[this.address].contract;
|
|
27
|
+
const gas = await contract.remove_liquidity_one_coin.estimateGas(_lpTokenAmount, i, _minAmount, false, curve.constantOptions);
|
|
28
|
+
if (estimateGas)
|
|
29
|
+
return Number(gas);
|
|
30
|
+
const gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * 160n / 100n : mulBy1_3(gas);
|
|
31
|
+
return (await contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, false, { ...curve.options, gasLimit })).hash;
|
|
114
32
|
},
|
|
115
|
-
withdrawOneCoinWrappedEstimateGas
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
case 0: return [4 /*yield*/, _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin)];
|
|
121
|
-
case 1:
|
|
122
|
-
_a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
|
|
123
|
-
return [4 /*yield*/, this._withdrawOneCoinWrapped(_lpTokenAmount, i, 0.1, true)];
|
|
124
|
-
case 2:
|
|
125
|
-
// @ts-ignore
|
|
126
|
-
return [2 /*return*/, _b.sent()];
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
33
|
+
async withdrawOneCoinWrappedEstimateGas(lpTokenAmount, coin) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
const [_lpTokenAmount, i] = await _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin);
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
return await this._withdrawOneCoinWrapped(_lpTokenAmount, i, 0.1, true);
|
|
130
38
|
},
|
|
131
|
-
withdrawOneCoinWrapped
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
case 0: return [4 /*yield*/, _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin)];
|
|
137
|
-
case 1:
|
|
138
|
-
_a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
|
|
139
|
-
return [4 /*yield*/, this._withdrawOneCoinWrapped(_lpTokenAmount, i, slippage)];
|
|
140
|
-
case 2:
|
|
141
|
-
// @ts-ignore
|
|
142
|
-
return [2 /*return*/, _b.sent()];
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
39
|
+
async withdrawOneCoinWrapped(lpTokenAmount, coin, slippage) {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
const [_lpTokenAmount, i] = await _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin);
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
return await this._withdrawOneCoinWrapped(_lpTokenAmount, i, slippage);
|
|
146
44
|
},
|
|
147
45
|
};
|
|
148
46
|
// @ts-ignore
|
|
149
|
-
|
|
47
|
+
export const withdrawOneCoinWrappedMixin = {
|
|
150
48
|
// @ts-ignore
|
|
151
|
-
_withdrawOneCoinWrapped
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
_minAmount = _a.sent();
|
|
160
|
-
contract = curve_1.curve.contracts[this.address].contract;
|
|
161
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
|
|
162
|
-
case 2:
|
|
163
|
-
gas = _a.sent();
|
|
164
|
-
if (estimateGas)
|
|
165
|
-
return [2 /*return*/, gas.toNumber()];
|
|
166
|
-
gasLimit = gas.mul(130).div(100);
|
|
167
|
-
return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
168
|
-
case 3: return [2 /*return*/, (_a.sent()).hash];
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
});
|
|
49
|
+
async _withdrawOneCoinWrapped(_lpTokenAmount, i, slippage, estimateGas = false) {
|
|
50
|
+
const _minAmount = await _withdrawOneCoinWrappedMinAmount.call(this, _lpTokenAmount, i, slippage);
|
|
51
|
+
const contract = curve.contracts[this.address].contract;
|
|
52
|
+
const gas = await contract.remove_liquidity_one_coin.estimateGas(_lpTokenAmount, i, _minAmount, curve.constantOptions);
|
|
53
|
+
if (estimateGas)
|
|
54
|
+
return Number(gas);
|
|
55
|
+
const gasLimit = mulBy1_3(gas);
|
|
56
|
+
return (await contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, { ...curve.options, gasLimit })).hash;
|
|
172
57
|
},
|
|
173
|
-
withdrawOneCoinWrappedEstimateGas
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
case 0: return [4 /*yield*/, _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin)];
|
|
179
|
-
case 1:
|
|
180
|
-
_a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
|
|
181
|
-
return [4 /*yield*/, this._withdrawOneCoinWrapped(_lpTokenAmount, i, 0.1, true)];
|
|
182
|
-
case 2:
|
|
183
|
-
// @ts-ignore
|
|
184
|
-
return [2 /*return*/, _b.sent()];
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
});
|
|
58
|
+
async withdrawOneCoinWrappedEstimateGas(lpTokenAmount, coin) {
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
const [_lpTokenAmount, i] = await _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin);
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
return await this._withdrawOneCoinWrapped(_lpTokenAmount, i, 0.1, true);
|
|
188
63
|
},
|
|
189
|
-
withdrawOneCoinWrapped
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
case 0: return [4 /*yield*/, _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin)];
|
|
195
|
-
case 1:
|
|
196
|
-
_a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
|
|
197
|
-
return [4 /*yield*/, this._withdrawOneCoinWrapped(_lpTokenAmount, i, slippage)];
|
|
198
|
-
case 2:
|
|
199
|
-
// @ts-ignore
|
|
200
|
-
return [2 /*return*/, _b.sent()];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
64
|
+
async withdrawOneCoinWrapped(lpTokenAmount, coin, slippage) {
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
const [_lpTokenAmount, i] = await _withdrawOneCoinWrappedCheck.call(this, lpTokenAmount, coin);
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
return await this._withdrawOneCoinWrapped(_lpTokenAmount, i, slippage);
|
|
204
69
|
},
|
|
205
70
|
};
|
|
@@ -1,206 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.withdrawWrapped3argsMixin = exports.withdrawWrapped2argsMixin = void 0;
|
|
51
|
-
var ethers_1 = require("ethers");
|
|
52
|
-
var curve_1 = require("../../curve");
|
|
53
|
-
var utils_1 = require("../../utils");
|
|
1
|
+
import { curve } from "../../curve.js";
|
|
2
|
+
import { fromBN, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
|
|
54
3
|
// @ts-ignore
|
|
55
|
-
function _withdrawWrappedCheck(lpTokenAmount) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
lpTokenBalance = (_b.sent())['lpToken'];
|
|
63
|
-
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
64
|
-
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
65
|
-
}
|
|
66
|
-
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
67
|
-
case 2:
|
|
68
|
-
_b.sent();
|
|
69
|
-
return [2 /*return*/, (0, utils_1.parseUnits)(lpTokenAmount)];
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
4
|
+
async function _withdrawWrappedCheck(lpTokenAmount) {
|
|
5
|
+
const lpTokenBalance = (await this.wallet.lpTokenBalances())['lpToken'];
|
|
6
|
+
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
7
|
+
throw Error(`Not enough LP tokens. Actual: ${lpTokenBalance}, required: ${lpTokenAmount}`);
|
|
8
|
+
}
|
|
9
|
+
await curve.updateFeeData();
|
|
10
|
+
return parseUnits(lpTokenAmount);
|
|
73
11
|
}
|
|
74
|
-
function _withdrawWrappedMinAmounts(_lpTokenAmount, slippage) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return __generator(this, function (_b) {
|
|
80
|
-
switch (_b.label) {
|
|
81
|
-
case 0: return [4 /*yield*/, this.withdrawWrappedExpected(ethers_1.ethers.utils.formatUnits(_lpTokenAmount))];
|
|
82
|
-
case 1:
|
|
83
|
-
expectedAmounts = _b.sent();
|
|
84
|
-
_expectedAmounts = expectedAmounts.map(function (a, i) { return ethers_1.ethers.utils.parseUnits(a, _this.wrappedDecimals[i]); });
|
|
85
|
-
minRecvAmountsBN = _expectedAmounts.map(function (_a, i) { return (0, utils_1.toBN)(_a, _this.wrappedDecimals[i]).times(100 - slippage).div(100); });
|
|
86
|
-
return [2 /*return*/, minRecvAmountsBN.map(function (a, i) { return (0, utils_1.fromBN)(a, _this.wrappedDecimals[i]); })];
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
});
|
|
12
|
+
async function _withdrawWrappedMinAmounts(_lpTokenAmount, slippage = 0.5) {
|
|
13
|
+
const expectedAmounts = await this.withdrawWrappedExpected(curve.formatUnits(_lpTokenAmount));
|
|
14
|
+
const _expectedAmounts = expectedAmounts.map((a, i) => curve.parseUnits(a, this.wrappedDecimals[i]));
|
|
15
|
+
const minRecvAmountsBN = _expectedAmounts.map((_a, i) => toBN(_a, this.wrappedDecimals[i]).times(100 - slippage).div(100));
|
|
16
|
+
return minRecvAmountsBN.map((a, i) => fromBN(a, this.wrappedDecimals[i]));
|
|
90
17
|
}
|
|
91
18
|
// @ts-ignore
|
|
92
|
-
|
|
19
|
+
export const withdrawWrapped2argsMixin = {
|
|
93
20
|
// @ts-ignore
|
|
94
|
-
_withdrawWrapped
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
_minAmounts = _b.sent();
|
|
103
|
-
contract = curve_1.curve.contracts[this.address].contract;
|
|
104
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
|
|
105
|
-
case 2:
|
|
106
|
-
gas = _b.sent();
|
|
107
|
-
if (estimateGas)
|
|
108
|
-
return [2 /*return*/, gas.toNumber()];
|
|
109
|
-
gasLimit = gas.mul(130).div(100);
|
|
110
|
-
return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
111
|
-
case 3: return [2 /*return*/, (_b.sent()).hash];
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
21
|
+
async _withdrawWrapped(_lpTokenAmount, slippage, estimateGas = false) {
|
|
22
|
+
const _minAmounts = await _withdrawWrappedMinAmounts.call(this, _lpTokenAmount, slippage);
|
|
23
|
+
const contract = curve.contracts[this.address].contract;
|
|
24
|
+
const gas = await contract.remove_liquidity.estimateGas(_lpTokenAmount, _minAmounts, curve.constantOptions);
|
|
25
|
+
if (estimateGas)
|
|
26
|
+
return Number(gas);
|
|
27
|
+
const gasLimit = mulBy1_3(gas);
|
|
28
|
+
return (await contract.remove_liquidity(_lpTokenAmount, _minAmounts, { ...curve.options, gasLimit })).hash;
|
|
115
29
|
},
|
|
116
|
-
withdrawWrappedEstimateGas
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
122
|
-
case 1:
|
|
123
|
-
_lpTokenAmount = _b.sent();
|
|
124
|
-
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, 0.1, true)];
|
|
125
|
-
case 2:
|
|
126
|
-
// @ts-ignore
|
|
127
|
-
return [2 /*return*/, _b.sent()];
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
});
|
|
30
|
+
async withdrawWrappedEstimateGas(lpTokenAmount) {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
const _lpTokenAmount = await _withdrawWrappedCheck.call(this, lpTokenAmount);
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
return await this._withdrawWrapped(_lpTokenAmount, 0.1, true);
|
|
131
35
|
},
|
|
132
|
-
withdrawWrapped
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
138
|
-
case 1:
|
|
139
|
-
_lpTokenAmount = _b.sent();
|
|
140
|
-
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, slippage)];
|
|
141
|
-
case 2:
|
|
142
|
-
// @ts-ignore
|
|
143
|
-
return [2 /*return*/, _b.sent()];
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
});
|
|
36
|
+
async withdrawWrapped(lpTokenAmount, slippage) {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
const _lpTokenAmount = await _withdrawWrappedCheck.call(this, lpTokenAmount);
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
return await this._withdrawWrapped(_lpTokenAmount, slippage);
|
|
147
41
|
},
|
|
148
42
|
};
|
|
149
43
|
// @ts-ignore
|
|
150
|
-
|
|
44
|
+
export const withdrawWrapped3argsMixin = {
|
|
151
45
|
// @ts-ignore
|
|
152
|
-
_withdrawWrapped
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
_minAmounts = _b.sent();
|
|
161
|
-
contract = curve_1.curve.contracts[this.address].contract;
|
|
162
|
-
return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, false, curve_1.curve.constantOptions)];
|
|
163
|
-
case 2:
|
|
164
|
-
gas = _b.sent();
|
|
165
|
-
if (estimateGas)
|
|
166
|
-
return [2 /*return*/, gas.toNumber()];
|
|
167
|
-
gasLimit = gas.mul(130).div(100);
|
|
168
|
-
return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, false, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
169
|
-
case 3: return [2 /*return*/, (_b.sent()).hash];
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
});
|
|
46
|
+
async _withdrawWrapped(_lpTokenAmount, slippage, estimateGas = false) {
|
|
47
|
+
const _minAmounts = await _withdrawWrappedMinAmounts.call(this, _lpTokenAmount, slippage);
|
|
48
|
+
const contract = curve.contracts[this.address].contract;
|
|
49
|
+
const gas = await contract.remove_liquidity.estimateGas(_lpTokenAmount, _minAmounts, false, curve.constantOptions);
|
|
50
|
+
if (estimateGas)
|
|
51
|
+
return Number(gas);
|
|
52
|
+
const gasLimit = mulBy1_3(gas);
|
|
53
|
+
return (await contract.remove_liquidity(_lpTokenAmount, _minAmounts, false, { ...curve.options, gasLimit })).hash;
|
|
173
54
|
},
|
|
174
|
-
withdrawWrappedEstimateGas
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
180
|
-
case 1:
|
|
181
|
-
_lpTokenAmount = _b.sent();
|
|
182
|
-
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, 0.1, true)];
|
|
183
|
-
case 2:
|
|
184
|
-
// @ts-ignore
|
|
185
|
-
return [2 /*return*/, _b.sent()];
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
});
|
|
55
|
+
async withdrawWrappedEstimateGas(lpTokenAmount) {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
const _lpTokenAmount = await _withdrawWrappedCheck.call(this, lpTokenAmount);
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
return await this._withdrawWrapped(_lpTokenAmount, 0.1, true);
|
|
189
60
|
},
|
|
190
|
-
withdrawWrapped
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
196
|
-
case 1:
|
|
197
|
-
_lpTokenAmount = _b.sent();
|
|
198
|
-
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, slippage)];
|
|
199
|
-
case 2:
|
|
200
|
-
// @ts-ignore
|
|
201
|
-
return [2 /*return*/, _b.sent()];
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
});
|
|
61
|
+
async withdrawWrapped(lpTokenAmount, slippage) {
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
const _lpTokenAmount = await _withdrawWrappedCheck.call(this, lpTokenAmount);
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
return await this._withdrawWrapped(_lpTokenAmount, slippage);
|
|
205
66
|
},
|
|
206
67
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PoolTemplate } from "./PoolTemplate";
|
|
1
|
+
import { PoolTemplate } from "./PoolTemplate.js";
|
|
2
2
|
export declare const getPool: (poolId: string) => PoolTemplate;
|