@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,297 +1,111 @@
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 };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.swapWrappedExpectedAndApproveMixin = exports.swapWrappedMixin = exports.swapWrappedTricrypto2Mixin = void 0;
51
- var utils_1 = require("../../utils");
52
- var curve_1 = require("../../curve");
53
- var ethers_1 = require("ethers");
1
+ import { curve } from "../../curve.js";
2
+ import { _ensureAllowance, _getCoinDecimals, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, } from "../../utils.js";
54
3
  // @ts-ignore
55
- function _swapWrappedCheck(inputCoin, outputCoin, amount, estimateGas) {
56
- if (estimateGas === void 0) { estimateGas = false; }
57
- return __awaiter(this, void 0, void 0, function () {
58
- var i, j, inputCoinBalance, _a, _b, _c, _amount;
59
- return __generator(this, function (_d) {
60
- switch (_d.label) {
61
- case 0:
62
- i = this._getCoinIdx(inputCoin, false);
63
- j = this._getCoinIdx(outputCoin, false);
64
- _b = (_a = Object).values;
65
- return [4 /*yield*/, this.wallet.wrappedCoinBalances()];
66
- case 1:
67
- inputCoinBalance = _b.apply(_a, [_d.sent()])[i];
68
- if (Number(inputCoinBalance) < Number(amount)) {
69
- throw Error("Not enough ".concat(this.wrappedCoins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
70
- }
71
- _c = estimateGas;
72
- if (!_c) return [3 /*break*/, 3];
73
- return [4 /*yield*/, (0, utils_1.hasAllowance)([this.wrappedCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.address)];
74
- case 2:
75
- _c = !(_d.sent());
76
- _d.label = 3;
77
- case 3:
78
- if (_c) {
79
- throw Error("Token allowance is needed to estimate gas");
80
- }
81
- if (!!estimateGas) return [3 /*break*/, 5];
82
- return [4 /*yield*/, curve_1.curve.updateFeeData()];
83
- case 4:
84
- _d.sent();
85
- _d.label = 5;
86
- case 5:
87
- _amount = (0, utils_1.parseUnits)(amount, this.wrappedDecimals[i]);
88
- return [2 /*return*/, [i, j, _amount]];
89
- }
90
- });
91
- });
4
+ async function _swapWrappedCheck(inputCoin, outputCoin, amount, estimateGas = false) {
5
+ // @ts-ignore
6
+ const i = this._getCoinIdx(inputCoin, false);
7
+ // @ts-ignore
8
+ const j = this._getCoinIdx(outputCoin, false);
9
+ const inputCoinBalance = Object.values(await this.wallet.wrappedCoinBalances())[i];
10
+ if (Number(inputCoinBalance) < Number(amount)) {
11
+ throw Error(`Not enough ${this.wrappedCoins[i]}. Actual: ${inputCoinBalance}, required: ${amount}`);
12
+ }
13
+ if (estimateGas && !(await hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address))) {
14
+ throw Error("Token allowance is needed to estimate gas");
15
+ }
16
+ if (!estimateGas)
17
+ await curve.updateFeeData();
18
+ const _amount = parseUnits(amount, this.wrappedDecimals[i]);
19
+ return [i, j, _amount];
92
20
  }
93
- function _swapWrappedMinAmount(i, j, _amount, slippage) {
94
- if (slippage === void 0) { slippage = 0.5; }
95
- return __awaiter(this, void 0, void 0, function () {
96
- var _expected, outputCoinDecimals, minAmountBN;
97
- return __generator(this, function (_a) {
98
- switch (_a.label) {
99
- case 0: return [4 /*yield*/, this._swapWrappedExpected(i, j, _amount)];
100
- case 1:
101
- _expected = _a.sent();
102
- outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.wrappedCoinAddresses[j])[0];
103
- minAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(100 - slippage).div(100);
104
- return [2 /*return*/, (0, utils_1.fromBN)(minAmountBN, outputCoinDecimals)];
105
- }
106
- });
107
- });
21
+ async function _swapWrappedMinAmount(i, j, _amount, slippage = 0.5) {
22
+ // @ts-ignore
23
+ const _expected = await this._swapWrappedExpected(i, j, _amount);
24
+ const [outputCoinDecimals] = _getCoinDecimals(this.wrappedCoinAddresses[j]);
25
+ const minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
26
+ return fromBN(minAmountBN, outputCoinDecimals);
108
27
  }
109
28
  // @ts-ignore
110
- exports.swapWrappedTricrypto2Mixin = {
29
+ export const swapWrappedTricrypto2Mixin = {
111
30
  // @ts-ignore
112
- _swapWrapped: function (i, j, _amount, slippage, estimateGas) {
113
- if (estimateGas === void 0) { estimateGas = false; }
114
- return __awaiter(this, void 0, void 0, function () {
115
- var _minRecvAmount, contract, value, gas, gasLimit;
116
- return __generator(this, function (_a) {
117
- switch (_a.label) {
118
- case 0:
119
- if (!!estimateGas) return [3 /*break*/, 2];
120
- return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.wrappedCoinAddresses[i]], [_amount], this.address)];
121
- case 1:
122
- _a.sent();
123
- _a.label = 2;
124
- case 2: return [4 /*yield*/, _swapWrappedMinAmount.call(this, i, j, _amount, slippage)];
125
- case 3:
126
- _minRecvAmount = _a.sent();
127
- contract = curve_1.curve.contracts[this.address].contract;
128
- value = (0, utils_1.isEth)(this.wrappedCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
129
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
130
- case 4:
131
- gas = _a.sent();
132
- if (estimateGas)
133
- return [2 /*return*/, gas.toNumber()];
134
- gasLimit = gas.mul(130).div(100);
135
- return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
136
- case 5: return [2 /*return*/, (_a.sent()).hash];
137
- }
138
- });
139
- });
31
+ async _swapWrapped(i, j, _amount, slippage, estimateGas = false) {
32
+ if (!estimateGas)
33
+ await _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
34
+ const _minRecvAmount = await _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
35
+ const contract = curve.contracts[this.address].contract;
36
+ const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : 0n;
37
+ const gas = await contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, false, { ...curve.constantOptions, value });
38
+ if (estimateGas)
39
+ return Number(gas);
40
+ const gasLimit = mulBy1_3(gas);
41
+ return (await contract.exchange(i, j, _amount, _minRecvAmount, false, { ...curve.options, value, gasLimit })).hash;
140
42
  },
141
- swapWrappedEstimateGas: function (inputCoin, outputCoin, amount) {
142
- return __awaiter(this, void 0, void 0, function () {
143
- var _a, i, j, _amount;
144
- return __generator(this, function (_b) {
145
- switch (_b.label) {
146
- case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true)];
147
- case 1:
148
- _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
149
- return [4 /*yield*/, this._swapWrapped(i, j, _amount, 0.1, true)];
150
- case 2:
151
- // @ts-ignore
152
- return [2 /*return*/, _b.sent()];
153
- }
154
- });
155
- });
43
+ async swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
44
+ // @ts-ignore
45
+ const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
46
+ // @ts-ignore
47
+ return await this._swapWrapped(i, j, _amount, 0.1, true);
156
48
  },
157
- swapWrapped: function (inputCoin, outputCoin, amount, slippage) {
158
- return __awaiter(this, void 0, void 0, function () {
159
- var _a, i, j, _amount;
160
- return __generator(this, function (_b) {
161
- switch (_b.label) {
162
- case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount)];
163
- case 1:
164
- _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
165
- return [4 /*yield*/, this._swapWrapped(i, j, _amount, slippage)];
166
- case 2:
167
- // @ts-ignore
168
- return [2 /*return*/, _b.sent()];
169
- }
170
- });
171
- });
49
+ async swapWrapped(inputCoin, outputCoin, amount, slippage) {
50
+ // @ts-ignore
51
+ const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
52
+ // @ts-ignore
53
+ return await this._swapWrapped(i, j, _amount, slippage);
172
54
  },
173
55
  };
174
56
  // @ts-ignore
175
- exports.swapWrappedMixin = {
57
+ export const swapWrappedMixin = {
176
58
  // @ts-ignore
177
- _swapWrapped: function (i, j, _amount, slippage, estimateGas) {
178
- if (estimateGas === void 0) { estimateGas = false; }
179
- return __awaiter(this, void 0, void 0, function () {
180
- var _minRecvAmount, contract, value, gas, gasLimit;
181
- return __generator(this, function (_a) {
182
- switch (_a.label) {
183
- case 0:
184
- if (!!estimateGas) return [3 /*break*/, 2];
185
- return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.wrappedCoinAddresses[i]], [_amount], this.address)];
186
- case 1:
187
- _a.sent();
188
- _a.label = 2;
189
- case 2: return [4 /*yield*/, _swapWrappedMinAmount.call(this, i, j, _amount, slippage)];
190
- case 3:
191
- _minRecvAmount = _a.sent();
192
- contract = curve_1.curve.contracts[this.address].contract;
193
- value = (0, utils_1.isEth)(this.wrappedCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
194
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
195
- case 4:
196
- gas = _a.sent();
197
- if (estimateGas)
198
- return [2 /*return*/, gas.toNumber()];
199
- gasLimit = curve_1.curve.chainId === 137 && this.id === 'ren' ? gas.mul(140).div(100) : gas.mul(130).div(100);
200
- return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
201
- case 5: return [2 /*return*/, (_a.sent()).hash];
202
- }
203
- });
204
- });
59
+ async _swapWrapped(i, j, _amount, slippage, estimateGas = false) {
60
+ if (!estimateGas)
61
+ await _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
62
+ const _minRecvAmount = await _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
63
+ const contract = curve.contracts[this.address].contract;
64
+ const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : 0n;
65
+ const gas = await contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, { ...curve.constantOptions, value });
66
+ if (estimateGas)
67
+ return Number(gas);
68
+ const gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * 140n / 100n : mulBy1_3(gas);
69
+ return (await contract.exchange(i, j, _amount, _minRecvAmount, { ...curve.options, value, gasLimit })).hash;
205
70
  },
206
- swapWrappedEstimateGas: function (inputCoin, outputCoin, amount) {
207
- return __awaiter(this, void 0, void 0, function () {
208
- var _a, i, j, _amount;
209
- return __generator(this, function (_b) {
210
- switch (_b.label) {
211
- case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true)];
212
- case 1:
213
- _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
214
- return [4 /*yield*/, this._swapWrapped(i, j, _amount, 0.1, true)];
215
- case 2:
216
- // @ts-ignore
217
- return [2 /*return*/, _b.sent()];
218
- }
219
- });
220
- });
71
+ async swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
72
+ // @ts-ignore
73
+ const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
74
+ // @ts-ignore
75
+ return await this._swapWrapped(i, j, _amount, 0.1, true);
221
76
  },
222
- swapWrapped: function (inputCoin, outputCoin, amount, slippage) {
223
- return __awaiter(this, void 0, void 0, function () {
224
- var _a, i, j, _amount;
225
- return __generator(this, function (_b) {
226
- switch (_b.label) {
227
- case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount)];
228
- case 1:
229
- _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
230
- return [4 /*yield*/, this._swapWrapped(i, j, _amount, slippage)];
231
- case 2:
232
- // @ts-ignore
233
- return [2 /*return*/, _b.sent()];
234
- }
235
- });
236
- });
77
+ async swapWrapped(inputCoin, outputCoin, amount, slippage) {
78
+ // @ts-ignore
79
+ const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
80
+ // @ts-ignore
81
+ return await this._swapWrapped(i, j, _amount, slippage);
237
82
  },
238
83
  };
239
84
  // @ts-ignore
240
- exports.swapWrappedExpectedAndApproveMixin = {
241
- swapWrappedExpected: function (inputCoin, outputCoin, amount) {
242
- return __awaiter(this, void 0, void 0, function () {
243
- var i, j, _amount, _expected;
244
- return __generator(this, function (_a) {
245
- switch (_a.label) {
246
- case 0:
247
- i = this._getCoinIdx(inputCoin, false);
248
- j = this._getCoinIdx(outputCoin, false);
249
- _amount = (0, utils_1.parseUnits)(amount, this.wrappedDecimals[i]);
250
- return [4 /*yield*/, this._swapWrappedExpected(i, j, _amount)];
251
- case 1:
252
- _expected = _a.sent();
253
- return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.wrappedDecimals[j])];
254
- }
255
- });
256
- });
85
+ export const swapWrappedExpectedAndApproveMixin = {
86
+ async swapWrappedExpected(inputCoin, outputCoin, amount) {
87
+ // @ts-ignore
88
+ const i = this._getCoinIdx(inputCoin, false);
89
+ // @ts-ignore
90
+ const j = this._getCoinIdx(outputCoin, false);
91
+ const _amount = parseUnits(amount, this.wrappedDecimals[i]);
92
+ // @ts-ignore
93
+ const _expected = await this._swapWrappedExpected(i, j, _amount);
94
+ return curve.formatUnits(_expected, this.wrappedDecimals[j]);
257
95
  },
258
- swapWrappedIsApproved: function (inputCoin, amount) {
259
- return __awaiter(this, void 0, void 0, function () {
260
- var i;
261
- return __generator(this, function (_a) {
262
- switch (_a.label) {
263
- case 0:
264
- i = this._getCoinIdx(inputCoin, false);
265
- return [4 /*yield*/, (0, utils_1.hasAllowance)([this.wrappedCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.address)];
266
- case 1: return [2 /*return*/, _a.sent()];
267
- }
268
- });
269
- });
96
+ async swapWrappedIsApproved(inputCoin, amount) {
97
+ // @ts-ignore
98
+ const i = this._getCoinIdx(inputCoin, false);
99
+ return await hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address);
270
100
  },
271
- swapWrappedApproveEstimateGas: function (inputCoin, amount) {
272
- return __awaiter(this, void 0, void 0, function () {
273
- var i;
274
- return __generator(this, function (_a) {
275
- switch (_a.label) {
276
- case 0:
277
- i = this._getCoinIdx(inputCoin, false);
278
- return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.wrappedCoinAddresses[i]], [amount], this.address)];
279
- case 1: return [2 /*return*/, _a.sent()];
280
- }
281
- });
282
- });
101
+ async swapWrappedApproveEstimateGas(inputCoin, amount) {
102
+ // @ts-ignore
103
+ const i = this._getCoinIdx(inputCoin, false);
104
+ return await ensureAllowanceEstimateGas([this.wrappedCoinAddresses[i]], [amount], this.address);
283
105
  },
284
- swapWrappedApprove: function (inputCoin, amount) {
285
- return __awaiter(this, void 0, void 0, function () {
286
- var i;
287
- return __generator(this, function (_a) {
288
- switch (_a.label) {
289
- case 0:
290
- i = this._getCoinIdx(inputCoin, false);
291
- return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.wrappedCoinAddresses[i]], [amount], this.address)];
292
- case 1: return [2 /*return*/, _a.sent()];
293
- }
294
- });
295
- });
106
+ async swapWrappedApprove(inputCoin, amount) {
107
+ // @ts-ignore
108
+ const i = this._getCoinIdx(inputCoin, false);
109
+ return await ensureAllowance([this.wrappedCoinAddresses[i]], [amount], this.address);
296
110
  },
297
111
  };
@@ -1,4 +1,4 @@
1
- import { PoolTemplate } from "../PoolTemplate";
1
+ import { PoolTemplate } from "../PoolTemplate.js";
2
2
  export declare const withdrawExpectedMixin: PoolTemplate;
3
3
  export declare const withdrawExpectedLendingOrCryptoMixin: PoolTemplate;
4
4
  export declare const withdrawExpectedMetaMixin: PoolTemplate;
@@ -1,122 +1,38 @@
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.withdrawWrappedExpectedMixin = exports.withdrawExpectedMetaMixin = exports.withdrawExpectedLendingOrCryptoMixin = exports.withdrawExpectedMixin = void 0;
40
- var ethers_1 = require("ethers");
41
- var common_1 = require("./common");
42
- var utils_1 = require("../../utils");
1
+ import { curve } from "../../curve.js";
2
+ import { parseUnits } from "../../utils.js";
3
+ import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
43
4
  // @ts-ignore
44
- exports.withdrawExpectedMixin = {
45
- withdrawExpected: function (lpTokenAmount) {
46
- return __awaiter(this, void 0, void 0, function () {
47
- var _lpTokenAmount, _expected;
48
- var _this = this;
49
- return __generator(this, function (_a) {
50
- switch (_a.label) {
51
- case 0:
52
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
53
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
54
- case 1:
55
- _expected = _a.sent();
56
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
57
- }
58
- });
59
- });
5
+ export const withdrawExpectedMixin = {
6
+ async withdrawExpected(lpTokenAmount) {
7
+ const _lpTokenAmount = parseUnits(lpTokenAmount);
8
+ const _expected = await _calcExpectedAmounts.call(this, _lpTokenAmount);
9
+ return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
60
10
  },
61
11
  };
62
12
  // @ts-ignore
63
- exports.withdrawExpectedLendingOrCryptoMixin = {
64
- withdrawExpected: function (lpTokenAmount) {
65
- return __awaiter(this, void 0, void 0, function () {
66
- var _lpTokenAmount, _expectedAmounts, _rates, _expected;
67
- var _this = this;
68
- return __generator(this, function (_a) {
69
- switch (_a.label) {
70
- case 0:
71
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
72
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
73
- case 1:
74
- _expectedAmounts = _a.sent();
75
- return [4 /*yield*/, this._getRates()];
76
- case 2:
77
- _rates = _a.sent();
78
- _expected = _expectedAmounts.map(function (_amount, i) { return _amount.mul(_rates[i]).div(ethers_1.ethers.BigNumber.from(10).pow(18)); });
79
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
80
- }
81
- });
82
- });
13
+ export const withdrawExpectedLendingOrCryptoMixin = {
14
+ async withdrawExpected(lpTokenAmount) {
15
+ const _lpTokenAmount = parseUnits(lpTokenAmount);
16
+ const _expectedAmounts = await _calcExpectedAmounts.call(this, _lpTokenAmount);
17
+ // @ts-ignore
18
+ const _rates = await this._getRates();
19
+ const _expected = _expectedAmounts.map((_amount, i) => _amount * _rates[i] / (10n ** 18n));
20
+ return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
83
21
  },
84
22
  };
85
23
  // @ts-ignore
86
- exports.withdrawExpectedMetaMixin = {
87
- withdrawExpected: function (lpTokenAmount) {
88
- return __awaiter(this, void 0, void 0, function () {
89
- var _lpTokenAmount, _expected;
90
- var _this = this;
91
- return __generator(this, function (_a) {
92
- switch (_a.label) {
93
- case 0:
94
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
95
- return [4 /*yield*/, common_1._calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount)];
96
- case 1:
97
- _expected = _a.sent();
98
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
99
- }
100
- });
101
- });
24
+ export const withdrawExpectedMetaMixin = {
25
+ async withdrawExpected(lpTokenAmount) {
26
+ const _lpTokenAmount = parseUnits(lpTokenAmount);
27
+ const _expected = await _calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount);
28
+ return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
102
29
  },
103
30
  };
104
31
  // @ts-ignore
105
- exports.withdrawWrappedExpectedMixin = {
106
- withdrawWrappedExpected: function (lpTokenAmount) {
107
- return __awaiter(this, void 0, void 0, function () {
108
- var _lpTokenAmount, _expected;
109
- var _this = this;
110
- return __generator(this, function (_a) {
111
- switch (_a.label) {
112
- case 0:
113
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
114
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
115
- case 1:
116
- _expected = _a.sent();
117
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.wrappedDecimals[i]); })];
118
- }
119
- });
120
- });
32
+ export const withdrawWrappedExpectedMixin = {
33
+ async withdrawWrappedExpected(lpTokenAmount) {
34
+ const _lpTokenAmount = parseUnits(lpTokenAmount);
35
+ const _expected = await _calcExpectedAmounts.call(this, _lpTokenAmount);
36
+ return _expected.map((amount, i) => curve.formatUnits(amount, this.wrappedDecimals[i]));
121
37
  },
122
38
  };
@@ -1,4 +1,4 @@
1
- import { PoolTemplate } from "../PoolTemplate";
1
+ import { PoolTemplate } from "../PoolTemplate.js";
2
2
  export declare const withdrawImbalanceMetaFactoryMixin: PoolTemplate;
3
3
  export declare const withdrawImbalanceZapMixin: PoolTemplate;
4
4
  export declare const withdrawImbalanceLendingMixin: PoolTemplate;