@curvefi/api 2.30.1 → 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 (100) hide show
  1. package/lib/boosting.js +137 -402
  2. package/lib/constants/abis/avaxcrypto/swap.json +1195 -0
  3. package/lib/constants/abis/avaxcrypto/zap.json +250 -0
  4. package/lib/constants/aliases.d.ts +11 -11
  5. package/lib/constants/aliases.js +12 -15
  6. package/lib/constants/coins/arbitrum.js +6 -9
  7. package/lib/constants/coins/aurora.js +6 -9
  8. package/lib/constants/coins/avalanche.js +12 -10
  9. package/lib/constants/coins/celo.js +6 -9
  10. package/lib/constants/coins/ethereum.js +10 -13
  11. package/lib/constants/coins/fantom.js +8 -11
  12. package/lib/constants/coins/kava.js +6 -9
  13. package/lib/constants/coins/moonbeam.js +6 -9
  14. package/lib/constants/coins/optimism.js +6 -9
  15. package/lib/constants/coins/polygon.js +7 -10
  16. package/lib/constants/coins/xdai.js +6 -9
  17. package/lib/constants/pools/arbitrum.d.ts +2 -4
  18. package/lib/constants/pools/arbitrum.js +22 -28
  19. package/lib/constants/pools/aurora.d.ts +2 -4
  20. package/lib/constants/pools/aurora.js +6 -12
  21. package/lib/constants/pools/avalanche.d.ts +2 -4
  22. package/lib/constants/pools/avalanche.js +51 -22
  23. package/lib/constants/pools/celo.d.ts +2 -4
  24. package/lib/constants/pools/celo.js +2 -5
  25. package/lib/constants/pools/ethereum.js +247 -253
  26. package/lib/constants/pools/fantom.d.ts +2 -4
  27. package/lib/constants/pools/fantom.js +28 -34
  28. package/lib/constants/pools/index.d.ts +11 -11
  29. package/lib/constants/pools/index.js +12 -25
  30. package/lib/constants/pools/kava.d.ts +2 -4
  31. package/lib/constants/pools/kava.js +2 -5
  32. package/lib/constants/pools/moonbeam.d.ts +2 -4
  33. package/lib/constants/pools/moonbeam.js +6 -12
  34. package/lib/constants/pools/optimism.d.ts +2 -4
  35. package/lib/constants/pools/optimism.js +9 -15
  36. package/lib/constants/pools/polygon.d.ts +2 -4
  37. package/lib/constants/pools/polygon.js +23 -28
  38. package/lib/constants/pools/xdai.d.ts +2 -4
  39. package/lib/constants/pools/xdai.js +25 -30
  40. package/lib/constants/utils.js +20 -29
  41. package/lib/curve.d.ts +9 -7
  42. package/lib/curve.js +397 -615
  43. package/lib/external-api.d.ts +1 -1
  44. package/lib/external-api.js +47 -140
  45. package/lib/factory/common.js +6 -10
  46. package/lib/factory/constants-crypto.js +48 -54
  47. package/lib/factory/constants.js +274 -280
  48. package/lib/factory/deploy.d.ts +8 -8
  49. package/lib/factory/deploy.js +177 -347
  50. package/lib/factory/factory-api.js +195 -278
  51. package/lib/factory/factory-crypto.js +170 -323
  52. package/lib/factory/factory.js +195 -350
  53. package/lib/index.d.ts +24 -25
  54. package/lib/index.js +87 -143
  55. package/lib/interfaces.d.ts +6 -5
  56. package/lib/interfaces.js +1 -2
  57. package/lib/pools/PoolTemplate.d.ts +1 -0
  58. package/lib/pools/PoolTemplate.js +1516 -2928
  59. package/lib/pools/index.d.ts +2 -2
  60. package/lib/pools/index.js +3 -7
  61. package/lib/pools/mixins/common.d.ts +3 -4
  62. package/lib/pools/mixins/common.js +23 -102
  63. package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +1 -1
  64. package/lib/pools/mixins/depositBalancedAmountsMixins.js +50 -139
  65. package/lib/pools/mixins/depositMixins.d.ts +1 -1
  66. package/lib/pools/mixins/depositMixins.js +145 -405
  67. package/lib/pools/mixins/depositWrappedMixins.d.ts +1 -1
  68. package/lib/pools/mixins/depositWrappedMixins.js +72 -227
  69. package/lib/pools/mixins/poolBalancesMixin.d.ts +1 -2
  70. package/lib/pools/mixins/poolBalancesMixin.js +25 -131
  71. package/lib/pools/mixins/swapMixins.d.ts +1 -1
  72. package/lib/pools/mixins/swapMixins.js +127 -353
  73. package/lib/pools/mixins/swapWrappedMixins.d.ts +1 -1
  74. package/lib/pools/mixins/swapWrappedMixins.js +90 -276
  75. package/lib/pools/mixins/withdrawExpectedMixins.d.ts +1 -2
  76. package/lib/pools/mixins/withdrawExpectedMixins.js +26 -154
  77. package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +1 -1
  78. package/lib/pools/mixins/withdrawImbalanceMixins.js +99 -321
  79. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +1 -1
  80. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +53 -192
  81. package/lib/pools/mixins/withdrawMixins.d.ts +1 -1
  82. package/lib/pools/mixins/withdrawMixins.js +124 -378
  83. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +1 -1
  84. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +17 -92
  85. package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +1 -1
  86. package/lib/pools/mixins/withdrawOneCoinMixins.js +125 -378
  87. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +1 -1
  88. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +9 -66
  89. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +1 -1
  90. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +55 -190
  91. package/lib/pools/mixins/withdrawWrappedMixins.d.ts +1 -1
  92. package/lib/pools/mixins/withdrawWrappedMixins.js +52 -191
  93. package/lib/pools/poolConstructor.d.ts +1 -1
  94. package/lib/pools/poolConstructor.js +79 -109
  95. package/lib/pools/utils.js +298 -500
  96. package/lib/router.d.ts +2 -2
  97. package/lib/router.js +406 -650
  98. package/lib/utils.d.ts +9 -9
  99. package/lib/utils.js +377 -731
  100. 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,6 +1,5 @@
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;
5
- export declare const withdrawExpectedAtricrypto3Mixin: PoolTemplate;
6
5
  export declare const withdrawWrappedExpectedMixin: PoolTemplate;
@@ -1,166 +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
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.withdrawWrappedExpectedMixin = exports.withdrawExpectedAtricrypto3Mixin = exports.withdrawExpectedMetaMixin = exports.withdrawExpectedLendingOrCryptoMixin = exports.withdrawExpectedMixin = void 0;
49
- var ethers_1 = require("ethers");
50
- var common_1 = require("./common");
51
- var PoolTemplate_1 = require("../PoolTemplate");
52
- var utils_1 = require("../../utils");
53
- // @ts-ignore
54
- exports.withdrawExpectedMixin = {
55
- withdrawExpected: function (lpTokenAmount) {
56
- return __awaiter(this, void 0, void 0, function () {
57
- var _lpTokenAmount, _expected;
58
- var _this = this;
59
- return __generator(this, function (_a) {
60
- switch (_a.label) {
61
- case 0:
62
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
63
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
64
- case 1:
65
- _expected = _a.sent();
66
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
67
- }
68
- });
69
- });
70
- },
71
- };
1
+ import { curve } from "../../curve.js";
2
+ import { parseUnits } from "../../utils.js";
3
+ import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
72
4
  // @ts-ignore
73
- exports.withdrawExpectedLendingOrCryptoMixin = {
74
- withdrawExpected: function (lpTokenAmount) {
75
- return __awaiter(this, void 0, void 0, function () {
76
- var _lpTokenAmount, _expectedAmounts, _rates, _expected;
77
- var _this = this;
78
- return __generator(this, function (_a) {
79
- switch (_a.label) {
80
- case 0:
81
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
82
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
83
- case 1:
84
- _expectedAmounts = _a.sent();
85
- return [4 /*yield*/, this._getRates()];
86
- case 2:
87
- _rates = _a.sent();
88
- _expected = _expectedAmounts.map(function (_amount, i) { return _amount.mul(_rates[i]).div(ethers_1.ethers.BigNumber.from(10).pow(18)); });
89
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
90
- }
91
- });
92
- });
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]));
93
10
  },
94
11
  };
95
12
  // @ts-ignore
96
- exports.withdrawExpectedMetaMixin = {
97
- withdrawExpected: function (lpTokenAmount) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- var _lpTokenAmount, _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts, _a, _expected;
100
- var _this = this;
101
- return __generator(this, function (_b) {
102
- switch (_b.label) {
103
- case 0:
104
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
105
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
106
- case 1:
107
- _expectedWrappedAmounts = _b.sent();
108
- _expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
109
- _expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
110
- basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
111
- if (!(this.basePool === "atricrypto3")) return [3 /*break*/, 3];
112
- return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
113
- case 2:
114
- _a = _b.sent();
115
- return [3 /*break*/, 5];
116
- case 3: return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
117
- case 4:
118
- _a = _b.sent();
119
- _b.label = 5;
120
- case 5:
121
- _basePoolExpectedAmounts = _a;
122
- _expected = __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true);
123
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
124
- }
125
- });
126
- });
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]));
127
21
  },
128
22
  };
129
23
  // @ts-ignore
130
- exports.withdrawExpectedAtricrypto3Mixin = {
131
- withdrawExpected: function (lpTokenAmount) {
132
- return __awaiter(this, void 0, void 0, function () {
133
- var _lpTokenAmount, _expected;
134
- var _this = this;
135
- return __generator(this, function (_a) {
136
- switch (_a.label) {
137
- case 0:
138
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
139
- return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(this, _lpTokenAmount)];
140
- case 1:
141
- _expected = _a.sent();
142
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
143
- }
144
- });
145
- });
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]));
146
29
  },
147
30
  };
148
31
  // @ts-ignore
149
- exports.withdrawWrappedExpectedMixin = {
150
- withdrawWrappedExpected: function (lpTokenAmount) {
151
- return __awaiter(this, void 0, void 0, function () {
152
- var _lpTokenAmount, _expected;
153
- var _this = this;
154
- return __generator(this, function (_a) {
155
- switch (_a.label) {
156
- case 0:
157
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
158
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
159
- case 1:
160
- _expected = _a.sent();
161
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.wrappedDecimals[i]); })];
162
- }
163
- });
164
- });
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]));
165
37
  },
166
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;