@curvefi/api 2.32.0 → 2.33.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 (59) hide show
  1. package/lib/boosting.js +385 -135
  2. package/lib/constants/aliases.js +22 -11
  3. package/lib/constants/coins/arbitrum.js +5 -5
  4. package/lib/constants/coins/aurora.js +5 -5
  5. package/lib/constants/coins/avalanche.js +6 -6
  6. package/lib/constants/coins/celo.js +5 -5
  7. package/lib/constants/coins/ethereum.js +10 -9
  8. package/lib/constants/coins/fantom.js +7 -7
  9. package/lib/constants/coins/kava.js +5 -5
  10. package/lib/constants/coins/moonbeam.js +5 -5
  11. package/lib/constants/coins/optimism.js +5 -5
  12. package/lib/constants/coins/polygon.js +6 -6
  13. package/lib/constants/coins/xdai.js +5 -5
  14. package/lib/constants/pools/arbitrum.js +1 -1
  15. package/lib/constants/pools/aurora.js +1 -1
  16. package/lib/constants/pools/avalanche.js +1 -1
  17. package/lib/constants/pools/celo.js +1 -1
  18. package/lib/constants/pools/ethereum.js +1 -1
  19. package/lib/constants/pools/fantom.js +1 -1
  20. package/lib/constants/pools/kava.js +1 -1
  21. package/lib/constants/pools/moonbeam.js +1 -1
  22. package/lib/constants/pools/optimism.js +1 -1
  23. package/lib/constants/pools/polygon.js +1 -1
  24. package/lib/constants/pools/xdai.js +1 -1
  25. package/lib/constants/utils.js +19 -18
  26. package/lib/curve.js +506 -282
  27. package/lib/external-api.js +132 -45
  28. package/lib/factory/common.js +3 -3
  29. package/lib/factory/constants-crypto.js +21 -21
  30. package/lib/factory/constants.js +32 -31
  31. package/lib/factory/deploy.js +336 -176
  32. package/lib/factory/factory-api.js +256 -180
  33. package/lib/factory/factory-crypto.js +309 -163
  34. package/lib/factory/factory.d.ts +1 -1
  35. package/lib/factory/factory.js +336 -186
  36. package/lib/index.js +98 -44
  37. package/lib/interfaces.d.ts +5 -0
  38. package/lib/pools/PoolTemplate.js +2879 -1468
  39. package/lib/pools/mixins/common.js +106 -22
  40. package/lib/pools/mixins/depositBalancedAmountsMixins.js +131 -48
  41. package/lib/pools/mixins/depositMixins.js +413 -144
  42. package/lib/pools/mixins/depositWrappedMixins.js +223 -72
  43. package/lib/pools/mixins/poolBalancesMixin.js +98 -22
  44. package/lib/pools/mixins/swapMixins.js +347 -125
  45. package/lib/pools/mixins/swapWrappedMixins.js +270 -88
  46. package/lib/pools/mixins/withdrawExpectedMixins.js +104 -23
  47. package/lib/pools/mixins/withdrawImbalanceMixins.js +316 -97
  48. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +187 -51
  49. package/lib/pools/mixins/withdrawMixins.js +385 -122
  50. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +88 -16
  51. package/lib/pools/mixins/withdrawOneCoinMixins.js +386 -123
  52. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +62 -8
  53. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +185 -53
  54. package/lib/pools/mixins/withdrawWrappedMixins.js +185 -50
  55. package/lib/pools/poolConstructor.js +25 -5
  56. package/lib/pools/utils.js +488 -299
  57. package/lib/router.js +675 -212
  58. package/lib/utils.js +675 -354
  59. package/package.json +1 -2
@@ -1,154 +1,376 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
1
48
  import { curve } from "../../curve.js";
2
49
  import { _ensureAllowance, _getCoinDecimals, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
3
50
  // @ts-ignore
4
- async function _swapCheck(inputCoin, outputCoin, amount, estimateGas = false) {
5
- // @ts-ignore
6
- const contractAddress = this._swapContractAddress();
7
- // @ts-ignore
8
- const i = this._getCoinIdx(inputCoin);
9
- // @ts-ignore
10
- const j = this._getCoinIdx(outputCoin);
11
- const inputCoinBalance = Object.values(await this.wallet.underlyingCoinBalances())[i];
12
- if (Number(inputCoinBalance) < Number(amount)) {
13
- throw Error(`Not enough ${this.underlyingCoins[i]}. Actual: ${inputCoinBalance}, required: ${amount}`);
14
- }
15
- if (estimateGas && !(await hasAllowance([this.underlyingCoinAddresses[i]], [amount], curve.signerAddress, contractAddress))) {
16
- throw Error("Token allowance is needed to estimate gas");
17
- }
18
- if (!estimateGas)
19
- await curve.updateFeeData();
20
- const _amount = parseUnits(amount, this.underlyingDecimals[i]);
21
- return [i, j, _amount];
51
+ function _swapCheck(inputCoin, outputCoin, amount, estimateGas) {
52
+ if (estimateGas === void 0) { estimateGas = false; }
53
+ return __awaiter(this, void 0, void 0, function () {
54
+ var contractAddress, i, j, inputCoinBalance, _a, _b, _c, _amount;
55
+ return __generator(this, function (_d) {
56
+ switch (_d.label) {
57
+ case 0:
58
+ contractAddress = this._swapContractAddress();
59
+ i = this._getCoinIdx(inputCoin);
60
+ j = this._getCoinIdx(outputCoin);
61
+ _b = (_a = Object).values;
62
+ return [4 /*yield*/, this.wallet.underlyingCoinBalances()];
63
+ case 1:
64
+ inputCoinBalance = _b.apply(_a, [_d.sent()])[i];
65
+ if (Number(inputCoinBalance) < Number(amount)) {
66
+ throw Error("Not enough ".concat(this.underlyingCoins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
67
+ }
68
+ _c = estimateGas;
69
+ if (!_c) return [3 /*break*/, 3];
70
+ return [4 /*yield*/, hasAllowance([this.underlyingCoinAddresses[i]], [amount], curve.signerAddress, contractAddress)];
71
+ case 2:
72
+ _c = !(_d.sent());
73
+ _d.label = 3;
74
+ case 3:
75
+ if (_c) {
76
+ throw Error("Token allowance is needed to estimate gas");
77
+ }
78
+ if (!!estimateGas) return [3 /*break*/, 5];
79
+ return [4 /*yield*/, curve.updateFeeData()];
80
+ case 4:
81
+ _d.sent();
82
+ _d.label = 5;
83
+ case 5:
84
+ _amount = parseUnits(amount, this.underlyingDecimals[i]);
85
+ return [2 /*return*/, [i, j, _amount]];
86
+ }
87
+ });
88
+ });
22
89
  }
23
- async function _swapMinAmount(i, j, _amount, slippage = 0.5) {
24
- // @ts-ignore
25
- const _expected = await this._swapExpected(i, j, _amount);
26
- const [outputCoinDecimals] = _getCoinDecimals(this.underlyingCoinAddresses[j]);
27
- const minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
28
- return fromBN(minAmountBN, outputCoinDecimals);
90
+ function _swapMinAmount(i, j, _amount, slippage) {
91
+ if (slippage === void 0) { slippage = 0.5; }
92
+ return __awaiter(this, void 0, void 0, function () {
93
+ var _expected, outputCoinDecimals, minAmountBN;
94
+ return __generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0: return [4 /*yield*/, this._swapExpected(i, j, _amount)];
97
+ case 1:
98
+ _expected = _a.sent();
99
+ outputCoinDecimals = _getCoinDecimals(this.underlyingCoinAddresses[j])[0];
100
+ minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
101
+ return [2 /*return*/, fromBN(minAmountBN, outputCoinDecimals)];
102
+ }
103
+ });
104
+ });
29
105
  }
30
106
  // @ts-ignore
31
- export const swapTricrypto2Mixin = {
107
+ export var swapTricrypto2Mixin = {
32
108
  // @ts-ignore
33
- async _swap(i, j, _amount, slippage, estimateGas = false) {
34
- // @ts-ignore
35
- const contractAddress = this._swapContractAddress();
36
- if (!estimateGas)
37
- await _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
38
- const _minRecvAmount = await _swapMinAmount.call(this, i, j, _amount, slippage);
39
- const contract = curve.contracts[contractAddress].contract;
40
- const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
41
- const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : 0n;
42
- const gas = await contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, true, { ...curve.constantOptions, value });
43
- if (estimateGas)
44
- return Number(gas);
45
- const gasLimit = mulBy1_3(gas);
46
- return (await contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, { ...curve.options, value, gasLimit })).hash;
109
+ _swap: function (i, j, _amount, slippage, estimateGas) {
110
+ if (estimateGas === void 0) { estimateGas = false; }
111
+ return __awaiter(this, void 0, void 0, function () {
112
+ var contractAddress, _minRecvAmount, contract, exchangeMethod, value, gas, gasLimit;
113
+ return __generator(this, function (_a) {
114
+ switch (_a.label) {
115
+ case 0:
116
+ contractAddress = this._swapContractAddress();
117
+ if (!!estimateGas) return [3 /*break*/, 2];
118
+ return [4 /*yield*/, _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress)];
119
+ case 1:
120
+ _a.sent();
121
+ _a.label = 2;
122
+ case 2: return [4 /*yield*/, _swapMinAmount.call(this, i, j, _amount, slippage)];
123
+ case 3:
124
+ _minRecvAmount = _a.sent();
125
+ contract = curve.contracts[contractAddress].contract;
126
+ exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
127
+ value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
128
+ return [4 /*yield*/, contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve.constantOptions), { value: value }))];
129
+ case 4:
130
+ gas = _a.sent();
131
+ if (estimateGas)
132
+ return [2 /*return*/, Number(gas)];
133
+ gasLimit = mulBy1_3(gas);
134
+ return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
135
+ case 5: return [2 /*return*/, (_a.sent()).hash];
136
+ }
137
+ });
138
+ });
47
139
  },
48
- async swapEstimateGas(inputCoin, outputCoin, amount) {
49
- // @ts-ignore
50
- const [i, j, _amount] = await _swapCheck.call(this, inputCoin, outputCoin, amount, true);
51
- // @ts-ignore
52
- return await this._swap(i, j, _amount, 0.1, true);
140
+ swapEstimateGas: function (inputCoin, outputCoin, amount) {
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ var _a, i, j, _amount;
143
+ return __generator(this, function (_b) {
144
+ switch (_b.label) {
145
+ case 0: return [4 /*yield*/, _swapCheck.call(this, inputCoin, outputCoin, amount, true)];
146
+ case 1:
147
+ _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
148
+ return [4 /*yield*/, this._swap(i, j, _amount, 0.1, true)];
149
+ case 2:
150
+ // @ts-ignore
151
+ return [2 /*return*/, _b.sent()];
152
+ }
153
+ });
154
+ });
53
155
  },
54
- async swap(inputCoin, outputCoin, amount, slippage) {
55
- // @ts-ignore
56
- const [i, j, _amount] = await _swapCheck.call(this, inputCoin, outputCoin, amount);
57
- // @ts-ignore
58
- return await this._swap(i, j, _amount, slippage);
156
+ swap: function (inputCoin, outputCoin, amount, slippage) {
157
+ return __awaiter(this, void 0, void 0, function () {
158
+ var _a, i, j, _amount;
159
+ return __generator(this, function (_b) {
160
+ switch (_b.label) {
161
+ case 0: return [4 /*yield*/, _swapCheck.call(this, inputCoin, outputCoin, amount)];
162
+ case 1:
163
+ _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
164
+ return [4 /*yield*/, this._swap(i, j, _amount, slippage)];
165
+ case 2:
166
+ // @ts-ignore
167
+ return [2 /*return*/, _b.sent()];
168
+ }
169
+ });
170
+ });
59
171
  },
60
172
  };
61
173
  // @ts-ignore
62
- export const swapMetaFactoryMixin = {
174
+ export var swapMetaFactoryMixin = {
63
175
  // @ts-ignore
64
- async _swap(i, j, _amount, slippage, estimateGas = false) {
65
- // @ts-ignore
66
- const contractAddress = this._swapContractAddress();
67
- if (!estimateGas)
68
- await _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
69
- const _minRecvAmount = await _swapMinAmount.call(this, i, j, _amount, slippage);
70
- const contract = curve.contracts[contractAddress].contract;
71
- const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
72
- const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : 0n;
73
- const gas = await contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, { ...curve.constantOptions, value });
74
- if (estimateGas)
75
- return Number(gas);
76
- const gasLimit = gas * 140n / 100n;
77
- return (await contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, { ...curve.options, value, gasLimit })).hash;
176
+ _swap: function (i, j, _amount, slippage, estimateGas) {
177
+ if (estimateGas === void 0) { estimateGas = false; }
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ var contractAddress, _minRecvAmount, contract, exchangeMethod, value, gas, gasLimit;
180
+ return __generator(this, function (_a) {
181
+ switch (_a.label) {
182
+ case 0:
183
+ contractAddress = this._swapContractAddress();
184
+ if (!!estimateGas) return [3 /*break*/, 2];
185
+ return [4 /*yield*/, _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress)];
186
+ case 1:
187
+ _a.sent();
188
+ _a.label = 2;
189
+ case 2: return [4 /*yield*/, _swapMinAmount.call(this, i, j, _amount, slippage)];
190
+ case 3:
191
+ _minRecvAmount = _a.sent();
192
+ contract = curve.contracts[contractAddress].contract;
193
+ exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
194
+ value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
195
+ return [4 /*yield*/, contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.constantOptions), { value: value }))];
196
+ case 4:
197
+ gas = _a.sent();
198
+ if (estimateGas)
199
+ return [2 /*return*/, Number(gas)];
200
+ gasLimit = gas * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
201
+ return [4 /*yield*/, contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
202
+ case 5: return [2 /*return*/, (_a.sent()).hash];
203
+ }
204
+ });
205
+ });
78
206
  },
79
- async swapEstimateGas(inputCoin, outputCoin, amount) {
80
- // @ts-ignore
81
- const [i, j, _amount] = await _swapCheck.call(this, inputCoin, outputCoin, amount, true);
82
- // @ts-ignore
83
- return await this._swap(i, j, _amount, 0.1, true);
207
+ swapEstimateGas: function (inputCoin, outputCoin, amount) {
208
+ return __awaiter(this, void 0, void 0, function () {
209
+ var _a, i, j, _amount;
210
+ return __generator(this, function (_b) {
211
+ switch (_b.label) {
212
+ case 0: return [4 /*yield*/, _swapCheck.call(this, inputCoin, outputCoin, amount, true)];
213
+ case 1:
214
+ _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
215
+ return [4 /*yield*/, this._swap(i, j, _amount, 0.1, true)];
216
+ case 2:
217
+ // @ts-ignore
218
+ return [2 /*return*/, _b.sent()];
219
+ }
220
+ });
221
+ });
84
222
  },
85
- async swap(inputCoin, outputCoin, amount, slippage) {
86
- // @ts-ignore
87
- const [i, j, _amount] = await _swapCheck.call(this, inputCoin, outputCoin, amount);
88
- // @ts-ignore
89
- return await this._swap(i, j, _amount, slippage);
223
+ swap: function (inputCoin, outputCoin, amount, slippage) {
224
+ return __awaiter(this, void 0, void 0, function () {
225
+ var _a, i, j, _amount;
226
+ return __generator(this, function (_b) {
227
+ switch (_b.label) {
228
+ case 0: return [4 /*yield*/, _swapCheck.call(this, inputCoin, outputCoin, amount)];
229
+ case 1:
230
+ _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
231
+ return [4 /*yield*/, this._swap(i, j, _amount, slippage)];
232
+ case 2:
233
+ // @ts-ignore
234
+ return [2 /*return*/, _b.sent()];
235
+ }
236
+ });
237
+ });
90
238
  },
91
239
  };
92
240
  // @ts-ignore
93
- export const swapCryptoMetaFactoryMixin = {
241
+ export var swapCryptoMetaFactoryMixin = {
94
242
  // @ts-ignore
95
- async _swap(i, j, _amount, slippage, estimateGas = false) {
96
- // @ts-ignore
97
- const contractAddress = this._swapContractAddress();
98
- if (!estimateGas)
99
- await _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
100
- const _minRecvAmount = await _swapMinAmount.call(this, i, j, _amount, slippage);
101
- const contract = curve.contracts[contractAddress].contract;
102
- const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
103
- const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : 0n;
104
- const gas = await contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, true, { ...curve.constantOptions, value });
105
- if (estimateGas)
106
- return Number(gas);
107
- const gasLimit = gas * 140n / 100n;
108
- return (await contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, true, { ...curve.options, value, gasLimit })).hash;
243
+ _swap: function (i, j, _amount, slippage, estimateGas) {
244
+ if (estimateGas === void 0) { estimateGas = false; }
245
+ return __awaiter(this, void 0, void 0, function () {
246
+ var contractAddress, _minRecvAmount, contract, exchangeMethod, value, gas, gasLimit;
247
+ return __generator(this, function (_a) {
248
+ switch (_a.label) {
249
+ case 0:
250
+ contractAddress = this._swapContractAddress();
251
+ if (!!estimateGas) return [3 /*break*/, 2];
252
+ return [4 /*yield*/, _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress)];
253
+ case 1:
254
+ _a.sent();
255
+ _a.label = 2;
256
+ case 2: return [4 /*yield*/, _swapMinAmount.call(this, i, j, _amount, slippage)];
257
+ case 3:
258
+ _minRecvAmount = _a.sent();
259
+ contract = curve.contracts[contractAddress].contract;
260
+ exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
261
+ value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
262
+ return [4 /*yield*/, contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve.constantOptions), { value: value }))];
263
+ case 4:
264
+ gas = _a.sent();
265
+ if (estimateGas)
266
+ return [2 /*return*/, Number(gas)];
267
+ gasLimit = gas * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
268
+ return [4 /*yield*/, contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
269
+ case 5: return [2 /*return*/, (_a.sent()).hash];
270
+ }
271
+ });
272
+ });
109
273
  },
110
- async swapEstimateGas(inputCoin, outputCoin, amount) {
111
- // @ts-ignore
112
- const [i, j, _amount] = await _swapCheck.call(this, inputCoin, outputCoin, amount, true);
113
- // @ts-ignore
114
- return await this._swap(i, j, _amount, 0.1, true);
274
+ swapEstimateGas: function (inputCoin, outputCoin, amount) {
275
+ return __awaiter(this, void 0, void 0, function () {
276
+ var _a, i, j, _amount;
277
+ return __generator(this, function (_b) {
278
+ switch (_b.label) {
279
+ case 0: return [4 /*yield*/, _swapCheck.call(this, inputCoin, outputCoin, amount, true)];
280
+ case 1:
281
+ _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
282
+ return [4 /*yield*/, this._swap(i, j, _amount, 0.1, true)];
283
+ case 2:
284
+ // @ts-ignore
285
+ return [2 /*return*/, _b.sent()];
286
+ }
287
+ });
288
+ });
115
289
  },
116
- async swap(inputCoin, outputCoin, amount, slippage) {
117
- // @ts-ignore
118
- const [i, j, _amount] = await _swapCheck.call(this, inputCoin, outputCoin, amount);
119
- // @ts-ignore
120
- return await this._swap(i, j, _amount, slippage);
290
+ swap: function (inputCoin, outputCoin, amount, slippage) {
291
+ return __awaiter(this, void 0, void 0, function () {
292
+ var _a, i, j, _amount;
293
+ return __generator(this, function (_b) {
294
+ switch (_b.label) {
295
+ case 0: return [4 /*yield*/, _swapCheck.call(this, inputCoin, outputCoin, amount)];
296
+ case 1:
297
+ _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
298
+ return [4 /*yield*/, this._swap(i, j, _amount, slippage)];
299
+ case 2:
300
+ // @ts-ignore
301
+ return [2 /*return*/, _b.sent()];
302
+ }
303
+ });
304
+ });
121
305
  },
122
306
  };
123
307
  // @ts-ignore
124
- export const swapMixin = {
308
+ export var swapMixin = {
125
309
  // @ts-ignore
126
- async _swap(i, j, _amount, slippage, estimateGas = false) {
127
- // @ts-ignore
128
- const contractAddress = this._swapContractAddress();
129
- if (!estimateGas)
130
- await _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
131
- const _minRecvAmount = await _swapMinAmount.call(this, i, j, _amount, slippage);
132
- const contract = curve.contracts[contractAddress].contract;
133
- const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
134
- const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : 0n;
135
- const gas = await contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, { ...curve.constantOptions, value });
136
- if (estimateGas)
137
- return Number(gas);
138
- await curve.updateFeeData();
139
- const gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * 160n / 100n : mulBy1_3(gas);
140
- return (await contract[exchangeMethod](i, j, _amount, _minRecvAmount, { ...curve.options, value, gasLimit })).hash;
310
+ _swap: function (i, j, _amount, slippage, estimateGas) {
311
+ if (estimateGas === void 0) { estimateGas = false; }
312
+ return __awaiter(this, void 0, void 0, function () {
313
+ var contractAddress, _minRecvAmount, contract, exchangeMethod, value, gas, gasLimit;
314
+ return __generator(this, function (_a) {
315
+ switch (_a.label) {
316
+ case 0:
317
+ contractAddress = this._swapContractAddress();
318
+ if (!!estimateGas) return [3 /*break*/, 2];
319
+ return [4 /*yield*/, _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress)];
320
+ case 1:
321
+ _a.sent();
322
+ _a.label = 2;
323
+ case 2: return [4 /*yield*/, _swapMinAmount.call(this, i, j, _amount, slippage)];
324
+ case 3:
325
+ _minRecvAmount = _a.sent();
326
+ contract = curve.contracts[contractAddress].contract;
327
+ exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
328
+ value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
329
+ return [4 /*yield*/, contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.constantOptions), { value: value }))];
330
+ case 4:
331
+ gas = _a.sent();
332
+ if (estimateGas)
333
+ return [2 /*return*/, Number(gas)];
334
+ return [4 /*yield*/, curve.updateFeeData()];
335
+ case 5:
336
+ _a.sent();
337
+ gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(gas);
338
+ return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
339
+ case 6: return [2 /*return*/, (_a.sent()).hash];
340
+ }
341
+ });
342
+ });
141
343
  },
142
- async swapEstimateGas(inputCoin, outputCoin, amount) {
143
- // @ts-ignore
144
- const [i, j, _amount] = await _swapCheck.call(this, inputCoin, outputCoin, amount, true);
145
- // @ts-ignore
146
- return await this._swap(i, j, _amount, 0.1, true);
344
+ swapEstimateGas: function (inputCoin, outputCoin, amount) {
345
+ return __awaiter(this, void 0, void 0, function () {
346
+ var _a, i, j, _amount;
347
+ return __generator(this, function (_b) {
348
+ switch (_b.label) {
349
+ case 0: return [4 /*yield*/, _swapCheck.call(this, inputCoin, outputCoin, amount, true)];
350
+ case 1:
351
+ _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
352
+ return [4 /*yield*/, this._swap(i, j, _amount, 0.1, true)];
353
+ case 2:
354
+ // @ts-ignore
355
+ return [2 /*return*/, _b.sent()];
356
+ }
357
+ });
358
+ });
147
359
  },
148
- async swap(inputCoin, outputCoin, amount, slippage) {
149
- // @ts-ignore
150
- const [i, j, _amount] = await _swapCheck.call(this, inputCoin, outputCoin, amount);
151
- // @ts-ignore
152
- return await this._swap(i, j, _amount, slippage);
360
+ swap: function (inputCoin, outputCoin, amount, slippage) {
361
+ return __awaiter(this, void 0, void 0, function () {
362
+ var _a, i, j, _amount;
363
+ return __generator(this, function (_b) {
364
+ switch (_b.label) {
365
+ case 0: return [4 /*yield*/, _swapCheck.call(this, inputCoin, outputCoin, amount)];
366
+ case 1:
367
+ _a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
368
+ return [4 /*yield*/, this._swap(i, j, _amount, slippage)];
369
+ case 2:
370
+ // @ts-ignore
371
+ return [2 /*return*/, _b.sent()];
372
+ }
373
+ });
374
+ });
153
375
  },
154
376
  };