@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.
Files changed (97) hide show
  1. package/lib/boosting.js +137 -402
  2. package/lib/constants/aliases.d.ts +11 -11
  3. package/lib/constants/aliases.js +12 -15
  4. package/lib/constants/coins/arbitrum.js +6 -9
  5. package/lib/constants/coins/aurora.js +6 -9
  6. package/lib/constants/coins/avalanche.js +7 -10
  7. package/lib/constants/coins/celo.js +6 -9
  8. package/lib/constants/coins/ethereum.js +10 -13
  9. package/lib/constants/coins/fantom.js +8 -11
  10. package/lib/constants/coins/kava.js +6 -9
  11. package/lib/constants/coins/moonbeam.js +6 -9
  12. package/lib/constants/coins/optimism.js +6 -9
  13. package/lib/constants/coins/polygon.js +7 -10
  14. package/lib/constants/coins/xdai.js +6 -9
  15. package/lib/constants/pools/arbitrum.d.ts +2 -4
  16. package/lib/constants/pools/arbitrum.js +22 -28
  17. package/lib/constants/pools/aurora.d.ts +2 -4
  18. package/lib/constants/pools/aurora.js +6 -12
  19. package/lib/constants/pools/avalanche.d.ts +2 -4
  20. package/lib/constants/pools/avalanche.js +21 -27
  21. package/lib/constants/pools/celo.d.ts +2 -4
  22. package/lib/constants/pools/celo.js +2 -5
  23. package/lib/constants/pools/ethereum.js +247 -253
  24. package/lib/constants/pools/fantom.d.ts +2 -4
  25. package/lib/constants/pools/fantom.js +28 -34
  26. package/lib/constants/pools/index.d.ts +11 -11
  27. package/lib/constants/pools/index.js +12 -25
  28. package/lib/constants/pools/kava.d.ts +2 -4
  29. package/lib/constants/pools/kava.js +2 -5
  30. package/lib/constants/pools/moonbeam.d.ts +2 -4
  31. package/lib/constants/pools/moonbeam.js +6 -12
  32. package/lib/constants/pools/optimism.d.ts +2 -4
  33. package/lib/constants/pools/optimism.js +9 -15
  34. package/lib/constants/pools/polygon.d.ts +2 -4
  35. package/lib/constants/pools/polygon.js +22 -28
  36. package/lib/constants/pools/xdai.d.ts +2 -4
  37. package/lib/constants/pools/xdai.js +24 -30
  38. package/lib/constants/utils.js +20 -29
  39. package/lib/curve.d.ts +9 -7
  40. package/lib/curve.js +397 -615
  41. package/lib/external-api.d.ts +1 -1
  42. package/lib/external-api.js +47 -140
  43. package/lib/factory/common.js +6 -10
  44. package/lib/factory/constants-crypto.js +48 -54
  45. package/lib/factory/constants.js +274 -280
  46. package/lib/factory/deploy.d.ts +8 -8
  47. package/lib/factory/deploy.js +177 -347
  48. package/lib/factory/factory-api.js +195 -278
  49. package/lib/factory/factory-crypto.js +170 -323
  50. package/lib/factory/factory.js +195 -350
  51. package/lib/index.d.ts +24 -25
  52. package/lib/index.js +87 -143
  53. package/lib/interfaces.d.ts +5 -5
  54. package/lib/interfaces.js +1 -2
  55. package/lib/pools/PoolTemplate.js +1516 -2929
  56. package/lib/pools/index.d.ts +2 -2
  57. package/lib/pools/index.js +3 -7
  58. package/lib/pools/mixins/common.d.ts +3 -4
  59. package/lib/pools/mixins/common.js +23 -112
  60. package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +1 -1
  61. package/lib/pools/mixins/depositBalancedAmountsMixins.js +50 -139
  62. package/lib/pools/mixins/depositMixins.d.ts +1 -1
  63. package/lib/pools/mixins/depositMixins.js +144 -417
  64. package/lib/pools/mixins/depositWrappedMixins.d.ts +1 -1
  65. package/lib/pools/mixins/depositWrappedMixins.js +72 -227
  66. package/lib/pools/mixins/poolBalancesMixin.d.ts +1 -1
  67. package/lib/pools/mixins/poolBalancesMixin.js +25 -105
  68. package/lib/pools/mixins/swapMixins.d.ts +1 -1
  69. package/lib/pools/mixins/swapMixins.js +127 -353
  70. package/lib/pools/mixins/swapWrappedMixins.d.ts +1 -1
  71. package/lib/pools/mixins/swapWrappedMixins.js +90 -276
  72. package/lib/pools/mixins/withdrawExpectedMixins.d.ts +1 -1
  73. package/lib/pools/mixins/withdrawExpectedMixins.js +26 -110
  74. package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +1 -1
  75. package/lib/pools/mixins/withdrawImbalanceMixins.js +99 -321
  76. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +1 -1
  77. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +53 -192
  78. package/lib/pools/mixins/withdrawMixins.d.ts +1 -1
  79. package/lib/pools/mixins/withdrawMixins.js +123 -390
  80. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +1 -1
  81. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +17 -92
  82. package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +1 -1
  83. package/lib/pools/mixins/withdrawOneCoinMixins.js +124 -390
  84. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +1 -1
  85. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +9 -66
  86. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +1 -1
  87. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +55 -190
  88. package/lib/pools/mixins/withdrawWrappedMixins.d.ts +1 -1
  89. package/lib/pools/mixins/withdrawWrappedMixins.js +52 -191
  90. package/lib/pools/poolConstructor.d.ts +1 -1
  91. package/lib/pools/poolConstructor.js +77 -101
  92. package/lib/pools/utils.js +298 -500
  93. package/lib/router.d.ts +2 -2
  94. package/lib/router.js +390 -653
  95. package/lib/utils.d.ts +9 -9
  96. package/lib/utils.js +377 -731
  97. package/package.json +8 -8
@@ -1,424 +1,158 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
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 };
1
+ import { curve } from "../../curve.js";
2
+ import { _ensureAllowance, fromBN, hasAllowance, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
3
+ // @ts-ignore
4
+ async function _withdrawOneCoinCheck(lpTokenAmount, coin, estimateGas = false) {
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}`);
47
8
  }
48
- };
49
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
- if (ar || !(i in from)) {
52
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
- ar[i] = from[i];
54
- }
9
+ if (estimateGas && this.zap && !(await hasAllowance([this.lpToken], [lpTokenAmount], curve.signerAddress, this.zap))) {
10
+ throw Error("Token allowance is needed to estimate gas");
55
11
  }
56
- return to.concat(ar || Array.prototype.slice.call(from));
57
- };
58
- Object.defineProperty(exports, "__esModule", { value: true });
59
- exports.withdrawOneCoinPlainMixin = exports.withdrawOneCoinLendingOrCryptoMixin = exports.withdrawOneCoinZapMixin = exports.withdrawOneCoinCryptoMetaFactoryMixin = exports.withdrawOneCoinMetaFactoryMixin = void 0;
60
- var curve_1 = require("../../curve");
61
- var utils_1 = require("../../utils");
62
- // @ts-ignore
63
- function _withdrawOneCoinCheck(lpTokenAmount, coin, estimateGas) {
64
- if (estimateGas === void 0) { estimateGas = false; }
65
- return __awaiter(this, void 0, void 0, function () {
66
- var lpTokenBalance, _a, i, _lpTokenAmount;
67
- return __generator(this, function (_b) {
68
- switch (_b.label) {
69
- case 0: return [4 /*yield*/, this.wallet.lpTokenBalances()];
70
- case 1:
71
- lpTokenBalance = (_b.sent())['lpToken'];
72
- if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
73
- throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
74
- }
75
- _a = estimateGas && this.zap;
76
- if (!_a) return [3 /*break*/, 3];
77
- return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
78
- case 2:
79
- _a = !(_b.sent());
80
- _b.label = 3;
81
- case 3:
82
- if (_a) {
83
- throw Error("Token allowance is needed to estimate gas");
84
- }
85
- if (!!estimateGas) return [3 /*break*/, 5];
86
- return [4 /*yield*/, curve_1.curve.updateFeeData()];
87
- case 4:
88
- _b.sent();
89
- _b.label = 5;
90
- case 5:
91
- i = this._getCoinIdx(coin);
92
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
93
- return [2 /*return*/, [_lpTokenAmount, i]];
94
- }
95
- });
96
- });
12
+ if (!estimateGas)
13
+ await curve.updateFeeData();
14
+ // @ts-ignore
15
+ const i = this._getCoinIdx(coin);
16
+ const _lpTokenAmount = parseUnits(lpTokenAmount);
17
+ return [_lpTokenAmount, i];
97
18
  }
98
- function _withdrawOneCoinMinAmount(_lpTokenAmount, i, slippage) {
99
- if (slippage === void 0) { slippage = 0.5; }
100
- return __awaiter(this, void 0, void 0, function () {
101
- var _expectedLpTokenAmount, minAmountBN;
102
- return __generator(this, function (_a) {
103
- switch (_a.label) {
104
- case 0: return [4 /*yield*/, this._withdrawOneCoinExpected(_lpTokenAmount, i)];
105
- case 1:
106
- _expectedLpTokenAmount = _a.sent();
107
- minAmountBN = (0, utils_1.toBN)(_expectedLpTokenAmount).times(100 - slippage).div(100);
108
- return [2 /*return*/, (0, utils_1.fromBN)(minAmountBN)];
109
- }
110
- });
111
- });
19
+ async function _withdrawOneCoinMinAmount(_lpTokenAmount, i, slippage = 0.5) {
20
+ // @ts-ignore
21
+ const _expectedLpTokenAmount = await this._withdrawOneCoinExpected(_lpTokenAmount, i);
22
+ const minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
23
+ return fromBN(minAmountBN);
112
24
  }
113
25
  // @ts-ignore
114
- exports.withdrawOneCoinMetaFactoryMixin = {
26
+ export const withdrawOneCoinMetaFactoryMixin = {
115
27
  // @ts-ignore
116
- _withdrawOneCoin: function (_lpTokenAmount, i, slippage, estimateGas) {
117
- if (estimateGas === void 0) { estimateGas = false; }
118
- return __awaiter(this, void 0, void 0, function () {
119
- var _minAmount, contract, gas, gasLimit;
120
- return __generator(this, function (_a) {
121
- switch (_a.label) {
122
- case 0:
123
- if (!!estimateGas) return [3 /*break*/, 2];
124
- return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
125
- case 1:
126
- _a.sent();
127
- _a.label = 2;
128
- case 2: return [4 /*yield*/, _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage)];
129
- case 3:
130
- _minAmount = _a.sent();
131
- contract = curve_1.curve.contracts[this.zap].contract;
132
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.address, _lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
133
- case 4:
134
- gas = _a.sent();
135
- if (estimateGas)
136
- return [2 /*return*/, gas.toNumber()];
137
- gasLimit = gas.mul(130).div(100);
138
- return [4 /*yield*/, contract.remove_liquidity_one_coin(this.address, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
139
- case 5: return [2 /*return*/, (_a.sent()).hash];
140
- }
141
- });
142
- });
28
+ async _withdrawOneCoin(_lpTokenAmount, i, slippage, estimateGas = false) {
29
+ if (!estimateGas)
30
+ await _ensureAllowance([this.lpToken], [_lpTokenAmount], this.zap);
31
+ const _minAmount = await _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage);
32
+ const contract = curve.contracts[this.zap].contract;
33
+ const gas = await contract.remove_liquidity_one_coin.estimateGas(this.address, _lpTokenAmount, i, _minAmount, curve.constantOptions);
34
+ if (estimateGas)
35
+ return Number(gas);
36
+ const gasLimit = mulBy1_3(gas);
37
+ return (await contract.remove_liquidity_one_coin(this.address, _lpTokenAmount, i, _minAmount, { ...curve.options, gasLimit })).hash;
143
38
  },
144
- withdrawOneCoinEstimateGas: function (lpTokenAmount, coin) {
145
- return __awaiter(this, void 0, void 0, function () {
146
- var _a, _lpTokenAmount, i;
147
- return __generator(this, function (_b) {
148
- switch (_b.label) {
149
- case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true)];
150
- case 1:
151
- _a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
152
- return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true)];
153
- case 2:
154
- // @ts-ignore
155
- return [2 /*return*/, _b.sent()];
156
- }
157
- });
158
- });
39
+ async withdrawOneCoinEstimateGas(lpTokenAmount, coin) {
40
+ // @ts-ignore
41
+ const [_lpTokenAmount, i] = await _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true);
42
+ // @ts-ignore
43
+ return await this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true);
159
44
  },
160
- withdrawOneCoin: function (lpTokenAmount, coin, slippage) {
161
- return __awaiter(this, void 0, void 0, function () {
162
- var _a, _lpTokenAmount, i;
163
- return __generator(this, function (_b) {
164
- switch (_b.label) {
165
- case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin)];
166
- case 1:
167
- _a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
168
- return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, slippage)];
169
- case 2:
170
- // @ts-ignore
171
- return [2 /*return*/, _b.sent()];
172
- }
173
- });
174
- });
45
+ async withdrawOneCoin(lpTokenAmount, coin, slippage) {
46
+ // @ts-ignore
47
+ const [_lpTokenAmount, i] = await _withdrawOneCoinCheck.call(this, lpTokenAmount, coin);
48
+ // @ts-ignore
49
+ return await this._withdrawOneCoin(_lpTokenAmount, i, slippage);
175
50
  },
176
51
  };
177
52
  // @ts-ignore
178
- exports.withdrawOneCoinCryptoMetaFactoryMixin = {
53
+ export const withdrawOneCoinCryptoMetaFactoryMixin = {
179
54
  // @ts-ignore
180
- _withdrawOneCoin: function (_lpTokenAmount, i, slippage, estimateGas) {
181
- if (estimateGas === void 0) { estimateGas = false; }
182
- return __awaiter(this, void 0, void 0, function () {
183
- var _minAmount, contract, gas, gasLimit;
184
- return __generator(this, function (_a) {
185
- switch (_a.label) {
186
- case 0:
187
- if (!!estimateGas) return [3 /*break*/, 2];
188
- return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
189
- case 1:
190
- _a.sent();
191
- _a.label = 2;
192
- case 2: return [4 /*yield*/, _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage)];
193
- case 3:
194
- _minAmount = _a.sent();
195
- contract = curve_1.curve.contracts[this.zap].contract;
196
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.address, _lpTokenAmount, i, _minAmount, true, curve_1.curve.constantOptions)];
197
- case 4:
198
- gas = _a.sent();
199
- if (estimateGas)
200
- return [2 /*return*/, gas.toNumber()];
201
- gasLimit = gas.mul(130).div(100);
202
- return [4 /*yield*/, contract.remove_liquidity_one_coin(this.address, _lpTokenAmount, i, _minAmount, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
203
- case 5: return [2 /*return*/, (_a.sent()).hash];
204
- }
205
- });
206
- });
55
+ async _withdrawOneCoin(_lpTokenAmount, i, slippage, estimateGas = false) {
56
+ if (!estimateGas)
57
+ await _ensureAllowance([this.lpToken], [_lpTokenAmount], this.zap);
58
+ const _minAmount = await _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage);
59
+ const contract = curve.contracts[this.zap].contract;
60
+ const gas = await contract.remove_liquidity_one_coin.estimateGas(this.address, _lpTokenAmount, i, _minAmount, true, curve.constantOptions);
61
+ if (estimateGas)
62
+ return Number(gas);
63
+ const gasLimit = mulBy1_3(gas);
64
+ return (await contract.remove_liquidity_one_coin(this.address, _lpTokenAmount, i, _minAmount, true, { ...curve.options, gasLimit })).hash;
207
65
  },
208
- withdrawOneCoinEstimateGas: function (lpTokenAmount, coin) {
209
- return __awaiter(this, void 0, void 0, function () {
210
- var _a, _lpTokenAmount, i;
211
- return __generator(this, function (_b) {
212
- switch (_b.label) {
213
- case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true)];
214
- case 1:
215
- _a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
216
- return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true)];
217
- case 2:
218
- // @ts-ignore
219
- return [2 /*return*/, _b.sent()];
220
- }
221
- });
222
- });
66
+ async withdrawOneCoinEstimateGas(lpTokenAmount, coin) {
67
+ // @ts-ignore
68
+ const [_lpTokenAmount, i] = await _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true);
69
+ // @ts-ignore
70
+ return await this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true);
223
71
  },
224
- withdrawOneCoin: function (lpTokenAmount, coin, slippage) {
225
- return __awaiter(this, void 0, void 0, function () {
226
- var _a, _lpTokenAmount, i;
227
- return __generator(this, function (_b) {
228
- switch (_b.label) {
229
- case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin)];
230
- case 1:
231
- _a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
232
- return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, slippage)];
233
- case 2:
234
- // @ts-ignore
235
- return [2 /*return*/, _b.sent()];
236
- }
237
- });
238
- });
72
+ async withdrawOneCoin(lpTokenAmount, coin, slippage) {
73
+ // @ts-ignore
74
+ const [_lpTokenAmount, i] = await _withdrawOneCoinCheck.call(this, lpTokenAmount, coin);
75
+ // @ts-ignore
76
+ return await this._withdrawOneCoin(_lpTokenAmount, i, slippage);
239
77
  },
240
78
  };
241
79
  // @ts-ignore
242
- exports.withdrawOneCoinZapMixin = {
80
+ export const withdrawOneCoinZapMixin = {
243
81
  // @ts-ignore
244
- _withdrawOneCoin: function (_lpTokenAmount, i, slippage, estimateGas) {
245
- if (estimateGas === void 0) { estimateGas = false; }
246
- return __awaiter(this, void 0, void 0, function () {
247
- var _minAmount, contract, args, gas, gasLimit;
248
- var _a;
249
- return __generator(this, function (_b) {
250
- switch (_b.label) {
251
- case 0:
252
- if (!!estimateGas) return [3 /*break*/, 2];
253
- return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
254
- case 1:
255
- _b.sent();
256
- _b.label = 2;
257
- case 2: return [4 /*yield*/, _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage)];
258
- case 3:
259
- _minAmount = _b.sent();
260
- contract = curve_1.curve.contracts[this.zap].contract;
261
- args = [_lpTokenAmount, i, _minAmount];
262
- if ("remove_liquidity_one_coin(uint256,uint256,uint256,bool)" in contract)
263
- args.push(true);
264
- return [4 /*yield*/, (_a = contract.estimateGas).remove_liquidity_one_coin.apply(_a, __spreadArray(__spreadArray([], args, false), [curve_1.curve.constantOptions], false))];
265
- case 4:
266
- gas = _b.sent();
267
- if (estimateGas)
268
- return [2 /*return*/, gas.toNumber()];
269
- gasLimit = gas.mul(130).div(100);
270
- return [4 /*yield*/, contract.remove_liquidity_one_coin.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit })], false))];
271
- case 5: return [2 /*return*/, (_b.sent()).hash];
272
- }
273
- });
274
- });
82
+ async _withdrawOneCoin(_lpTokenAmount, i, slippage, estimateGas = false) {
83
+ if (!estimateGas)
84
+ await _ensureAllowance([this.lpToken], [_lpTokenAmount], this.zap);
85
+ const _minAmount = await _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage);
86
+ const contract = curve.contracts[this.zap].contract;
87
+ const args = [_lpTokenAmount, i, _minAmount];
88
+ if (`remove_liquidity_one_coin(uint256,uint256,uint256,bool)` in contract)
89
+ args.push(true);
90
+ const gas = await contract.remove_liquidity_one_coin.estimateGas(...args, curve.constantOptions);
91
+ if (estimateGas)
92
+ return Number(gas);
93
+ const gasLimit = mulBy1_3(gas);
94
+ return (await contract.remove_liquidity_one_coin(...args, { ...curve.options, gasLimit })).hash;
275
95
  },
276
- withdrawOneCoinEstimateGas: function (lpTokenAmount, coin) {
277
- return __awaiter(this, void 0, void 0, function () {
278
- var _a, _lpTokenAmount, i;
279
- return __generator(this, function (_b) {
280
- switch (_b.label) {
281
- case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true)];
282
- case 1:
283
- _a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
284
- return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true)];
285
- case 2:
286
- // @ts-ignore
287
- return [2 /*return*/, _b.sent()];
288
- }
289
- });
290
- });
96
+ async withdrawOneCoinEstimateGas(lpTokenAmount, coin) {
97
+ // @ts-ignore
98
+ const [_lpTokenAmount, i] = await _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true);
99
+ // @ts-ignore
100
+ return await this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true);
291
101
  },
292
- withdrawOneCoin: function (lpTokenAmount, coin, slippage) {
293
- return __awaiter(this, void 0, void 0, function () {
294
- var _a, _lpTokenAmount, i;
295
- return __generator(this, function (_b) {
296
- switch (_b.label) {
297
- case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin)];
298
- case 1:
299
- _a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
300
- return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, slippage)];
301
- case 2:
302
- // @ts-ignore
303
- return [2 /*return*/, _b.sent()];
304
- }
305
- });
306
- });
102
+ async withdrawOneCoin(lpTokenAmount, coin, slippage) {
103
+ // @ts-ignore
104
+ const [_lpTokenAmount, i] = await _withdrawOneCoinCheck.call(this, lpTokenAmount, coin);
105
+ // @ts-ignore
106
+ return await this._withdrawOneCoin(_lpTokenAmount, i, slippage);
307
107
  },
308
108
  };
309
109
  // @ts-ignore
310
- exports.withdrawOneCoinLendingOrCryptoMixin = {
110
+ export const withdrawOneCoinLendingOrCryptoMixin = {
311
111
  // @ts-ignore
312
- _withdrawOneCoin: function (_lpTokenAmount, i, slippage, estimateGas) {
313
- if (estimateGas === void 0) { estimateGas = false; }
314
- return __awaiter(this, void 0, void 0, function () {
315
- var _minAmount, contract, gas, gasLimit;
316
- return __generator(this, function (_a) {
317
- switch (_a.label) {
318
- case 0: return [4 /*yield*/, _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage)];
319
- case 1:
320
- _minAmount = _a.sent();
321
- contract = curve_1.curve.contracts[this.address].contract;
322
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, true, curve_1.curve.constantOptions)];
323
- case 2:
324
- gas = _a.sent();
325
- if (estimateGas)
326
- return [2 /*return*/, gas.toNumber()];
327
- gasLimit = curve_1.curve.chainId === 137 && this.id === 'ren' ? gas.mul(160).div(100) : gas.mul(130).div(100);
328
- return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
329
- case 3: return [2 /*return*/, (_a.sent()).hash];
330
- }
331
- });
332
- });
112
+ async _withdrawOneCoin(_lpTokenAmount, i, slippage, estimateGas = false) {
113
+ const _minAmount = await _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage);
114
+ const contract = curve.contracts[this.address].contract;
115
+ const gas = await contract.remove_liquidity_one_coin.estimateGas(_lpTokenAmount, i, _minAmount, true, curve.constantOptions);
116
+ if (estimateGas)
117
+ return Number(gas);
118
+ const gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * 160n / 100n : mulBy1_3(gas);
119
+ return (await contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, true, { ...curve.options, gasLimit })).hash;
333
120
  },
334
- withdrawOneCoinEstimateGas: function (lpTokenAmount, coin) {
335
- return __awaiter(this, void 0, void 0, function () {
336
- var _a, _lpTokenAmount, i;
337
- return __generator(this, function (_b) {
338
- switch (_b.label) {
339
- case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true)];
340
- case 1:
341
- _a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
342
- return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true)];
343
- case 2:
344
- // @ts-ignore
345
- return [2 /*return*/, _b.sent()];
346
- }
347
- });
348
- });
121
+ async withdrawOneCoinEstimateGas(lpTokenAmount, coin) {
122
+ // @ts-ignore
123
+ const [_lpTokenAmount, i] = await _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true);
124
+ // @ts-ignore
125
+ return await this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true);
349
126
  },
350
- withdrawOneCoin: function (lpTokenAmount, coin, slippage) {
351
- return __awaiter(this, void 0, void 0, function () {
352
- var _a, _lpTokenAmount, i;
353
- return __generator(this, function (_b) {
354
- switch (_b.label) {
355
- case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin)];
356
- case 1:
357
- _a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
358
- return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, slippage)];
359
- case 2:
360
- // @ts-ignore
361
- return [2 /*return*/, _b.sent()];
362
- }
363
- });
364
- });
127
+ async withdrawOneCoin(lpTokenAmount, coin, slippage) {
128
+ // @ts-ignore
129
+ const [_lpTokenAmount, i] = await _withdrawOneCoinCheck.call(this, lpTokenAmount, coin);
130
+ // @ts-ignore
131
+ return await this._withdrawOneCoin(_lpTokenAmount, i, slippage);
365
132
  },
366
133
  };
367
134
  // @ts-ignore
368
- exports.withdrawOneCoinPlainMixin = {
135
+ export const withdrawOneCoinPlainMixin = {
369
136
  // @ts-ignore
370
- _withdrawOneCoin: function (_lpTokenAmount, i, slippage, estimateGas) {
371
- if (estimateGas === void 0) { estimateGas = false; }
372
- return __awaiter(this, void 0, void 0, function () {
373
- var _minAmount, contract, gas, gasLimit;
374
- return __generator(this, function (_a) {
375
- switch (_a.label) {
376
- case 0: return [4 /*yield*/, _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage)];
377
- case 1:
378
- _minAmount = _a.sent();
379
- contract = curve_1.curve.contracts[this.address].contract;
380
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
381
- case 2:
382
- gas = _a.sent();
383
- if (estimateGas)
384
- return [2 /*return*/, gas.toNumber()];
385
- gasLimit = gas.mul(130).div(100);
386
- return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
387
- case 3: return [2 /*return*/, (_a.sent()).hash];
388
- }
389
- });
390
- });
137
+ async _withdrawOneCoin(_lpTokenAmount, i, slippage, estimateGas = false) {
138
+ const _minAmount = await _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage);
139
+ const contract = curve.contracts[this.address].contract;
140
+ const gas = await contract.remove_liquidity_one_coin.estimateGas(_lpTokenAmount, i, _minAmount, curve.constantOptions);
141
+ if (estimateGas)
142
+ return Number(gas);
143
+ const gasLimit = mulBy1_3(gas);
144
+ return (await contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, { ...curve.options, gasLimit })).hash;
391
145
  },
392
- withdrawOneCoinEstimateGas: function (lpTokenAmount, coin) {
393
- return __awaiter(this, void 0, void 0, function () {
394
- var _a, _lpTokenAmount, i;
395
- return __generator(this, function (_b) {
396
- switch (_b.label) {
397
- case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true)];
398
- case 1:
399
- _a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
400
- return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true)];
401
- case 2:
402
- // @ts-ignore
403
- return [2 /*return*/, _b.sent()];
404
- }
405
- });
406
- });
146
+ async withdrawOneCoinEstimateGas(lpTokenAmount, coin) {
147
+ // @ts-ignore
148
+ const [_lpTokenAmount, i] = await _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true);
149
+ // @ts-ignore
150
+ return await this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true);
407
151
  },
408
- withdrawOneCoin: function (lpTokenAmount, coin, slippage) {
409
- return __awaiter(this, void 0, void 0, function () {
410
- var _a, _lpTokenAmount, i;
411
- return __generator(this, function (_b) {
412
- switch (_b.label) {
413
- case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin)];
414
- case 1:
415
- _a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
416
- return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, slippage)];
417
- case 2:
418
- // @ts-ignore
419
- return [2 /*return*/, _b.sent()];
420
- }
421
- });
422
- });
152
+ async withdrawOneCoin(lpTokenAmount, coin, slippage) {
153
+ // @ts-ignore
154
+ const [_lpTokenAmount, i] = await _withdrawOneCoinCheck.call(this, lpTokenAmount, coin);
155
+ // @ts-ignore
156
+ return await this._withdrawOneCoin(_lpTokenAmount, i, slippage);
423
157
  },
424
158
  };
@@ -1,3 +1,3 @@
1
- import { PoolTemplate } from "../PoolTemplate";
1
+ import { PoolTemplate } from "../PoolTemplate.js";
2
2
  export declare const withdrawOneCoinWrappedExpected2argsMixin: PoolTemplate;
3
3
  export declare const withdrawOneCoinWrappedExpected3argsMixin: PoolTemplate;
@@ -1,72 +1,15 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.withdrawOneCoinWrappedExpected3argsMixin = exports.withdrawOneCoinWrappedExpected2argsMixin = void 0;
40
- var curve_1 = require("../../curve");
1
+ import { curve } from "../../curve.js";
41
2
  // @ts-ignore
42
- exports.withdrawOneCoinWrappedExpected2argsMixin = {
43
- _withdrawOneCoinWrappedExpected: function (_lpTokenAmount, i) {
44
- return __awaiter(this, void 0, void 0, function () {
45
- var contract;
46
- return __generator(this, function (_a) {
47
- switch (_a.label) {
48
- case 0:
49
- contract = curve_1.curve.contracts[this.address].contract;
50
- return [4 /*yield*/, contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.constantOptions)];
51
- case 1: return [2 /*return*/, _a.sent()];
52
- }
53
- });
54
- });
3
+ export const withdrawOneCoinWrappedExpected2argsMixin = {
4
+ async _withdrawOneCoinWrappedExpected(_lpTokenAmount, i) {
5
+ const contract = curve.contracts[this.address].contract;
6
+ return await contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve.constantOptions);
55
7
  },
56
8
  };
57
9
  // @ts-ignore
58
- exports.withdrawOneCoinWrappedExpected3argsMixin = {
59
- _withdrawOneCoinWrappedExpected: function (_lpTokenAmount, i) {
60
- return __awaiter(this, void 0, void 0, function () {
61
- var contract;
62
- return __generator(this, function (_a) {
63
- switch (_a.label) {
64
- case 0:
65
- contract = curve_1.curve.contracts[this.address].contract;
66
- return [4 /*yield*/, contract.calc_withdraw_one_coin(_lpTokenAmount, i, false, curve_1.curve.constantOptions)];
67
- case 1: return [2 /*return*/, _a.sent()];
68
- }
69
- });
70
- });
10
+ export const withdrawOneCoinWrappedExpected3argsMixin = {
11
+ async _withdrawOneCoinWrappedExpected(_lpTokenAmount, i) {
12
+ const contract = curve.contracts[this.address].contract;
13
+ return await contract.calc_withdraw_one_coin(_lpTokenAmount, i, false, curve.constantOptions);
71
14
  },
72
15
  };