@curvefi/api 2.63.0 → 2.63.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 (83) hide show
  1. package/lib/boosting.js +247 -645
  2. package/lib/constants/L2Networks.js +1 -1
  3. package/lib/constants/aliases.js +19 -19
  4. package/lib/constants/coins/arbitrum.js +5 -5
  5. package/lib/constants/coins/aurora.js +5 -5
  6. package/lib/constants/coins/avalanche.js +6 -6
  7. package/lib/constants/coins/base.js +5 -5
  8. package/lib/constants/coins/bsc.js +5 -5
  9. package/lib/constants/coins/celo.js +5 -5
  10. package/lib/constants/coins/ethereum.js +9 -9
  11. package/lib/constants/coins/fantom.js +7 -7
  12. package/lib/constants/coins/fraxtal.js +5 -5
  13. package/lib/constants/coins/kava.js +5 -5
  14. package/lib/constants/coins/mantle.js +5 -5
  15. package/lib/constants/coins/moonbeam.js +5 -5
  16. package/lib/constants/coins/optimism.js +5 -5
  17. package/lib/constants/coins/polygon.js +6 -6
  18. package/lib/constants/coins/xdai.js +5 -5
  19. package/lib/constants/coins/xlayer.js +5 -5
  20. package/lib/constants/coins/zksync.js +5 -5
  21. package/lib/constants/pools/arbitrum.js +1 -1
  22. package/lib/constants/pools/aurora.js +1 -1
  23. package/lib/constants/pools/avalanche.js +1 -1
  24. package/lib/constants/pools/base.js +1 -1
  25. package/lib/constants/pools/bsc.js +1 -1
  26. package/lib/constants/pools/celo.js +1 -1
  27. package/lib/constants/pools/ethereum.js +2 -2
  28. package/lib/constants/pools/fantom.js +1 -1
  29. package/lib/constants/pools/fraxtal.js +1 -1
  30. package/lib/constants/pools/kava.js +1 -1
  31. package/lib/constants/pools/mantle.js +1 -1
  32. package/lib/constants/pools/moonbeam.js +1 -1
  33. package/lib/constants/pools/optimism.js +1 -1
  34. package/lib/constants/pools/polygon.js +1 -1
  35. package/lib/constants/pools/xdai.js +1 -1
  36. package/lib/constants/pools/xlayer.js +1 -1
  37. package/lib/constants/pools/zksync.js +1 -1
  38. package/lib/constants/tricryptoDeployImplementations.js +1 -1
  39. package/lib/constants/utils.js +18 -19
  40. package/lib/constants/volumeNetworks.js +1 -1
  41. package/lib/curve.d.ts +3 -1
  42. package/lib/curve.js +534 -909
  43. package/lib/dao.js +351 -705
  44. package/lib/external-api.js +127 -256
  45. package/lib/factory/common.js +4 -4
  46. package/lib/factory/constants-crypto.js +33 -33
  47. package/lib/factory/constants.js +34 -34
  48. package/lib/factory/deploy.js +542 -907
  49. package/lib/factory/factory-api.js +205 -269
  50. package/lib/factory/factory-crypto.js +202 -342
  51. package/lib/factory/factory-tricrypto.js +164 -286
  52. package/lib/factory/factory-twocrypto.js +151 -269
  53. package/lib/factory/factory.js +245 -385
  54. package/lib/index.js +109 -198
  55. package/lib/interfaces.d.ts +1 -6
  56. package/lib/pools/PoolTemplate.js +1773 -3025
  57. package/lib/pools/gaugePool.js +112 -251
  58. package/lib/pools/mixins/common.js +22 -93
  59. package/lib/pools/mixins/depositBalancedAmountsMixins.js +52 -118
  60. package/lib/pools/mixins/depositMixins.js +160 -386
  61. package/lib/pools/mixins/depositWrappedMixins.js +79 -205
  62. package/lib/pools/mixins/poolBalancesMixin.js +24 -87
  63. package/lib/pools/mixins/swapMixins.js +139 -324
  64. package/lib/pools/mixins/swapWrappedMixins.js +111 -265
  65. package/lib/pools/mixins/withdrawExpectedMixins.js +27 -91
  66. package/lib/pools/mixins/withdrawImbalanceMixins.js +111 -293
  67. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +58 -169
  68. package/lib/pools/mixins/withdrawMixins.js +139 -359
  69. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +20 -75
  70. package/lib/pools/mixins/withdrawOneCoinMixins.js +140 -360
  71. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +10 -51
  72. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +60 -167
  73. package/lib/pools/mixins/withdrawWrappedMixins.js +57 -167
  74. package/lib/pools/poolConstructor.js +5 -25
  75. package/lib/pools/utils.js +301 -469
  76. package/lib/route-finder.worker.d.ts +9 -0
  77. package/lib/route-finder.worker.js +112 -0
  78. package/lib/route-graph.worker.d.ts +11 -0
  79. package/lib/route-graph.worker.js +334 -0
  80. package/lib/router.js +323 -912
  81. package/lib/utils.d.ts +5 -4
  82. package/lib/utils.js +539 -918
  83. package/package.json +1 -1
@@ -1,14 +1,3 @@
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
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18,359 +7,185 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
19
8
  });
20
9
  };
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
- };
48
10
  import { curve } from "../../curve.js";
49
11
  import { _ensureAllowance, _getCoinDecimals, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
50
12
  // @ts-ignore
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
- });
13
+ function _swapCheck(inputCoin, outputCoin, amount, estimateGas = false) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ // @ts-ignore
16
+ const contractAddress = this._swapContractAddress();
17
+ // @ts-ignore
18
+ const i = this._getCoinIdx(inputCoin);
19
+ // @ts-ignore
20
+ const j = this._getCoinIdx(outputCoin);
21
+ const inputCoinBalance = Object.values(yield this.wallet.underlyingCoinBalances())[i];
22
+ if (Number(inputCoinBalance) < Number(amount)) {
23
+ throw Error(`Not enough ${this.underlyingCoins[i]}. Actual: ${inputCoinBalance}, required: ${amount}`);
24
+ }
25
+ if (estimateGas && !(yield hasAllowance([this.underlyingCoinAddresses[i]], [amount], curve.signerAddress, contractAddress))) {
26
+ throw Error("Token allowance is needed to estimate gas");
27
+ }
28
+ if (!estimateGas)
29
+ yield curve.updateFeeData();
30
+ const _amount = parseUnits(amount, this.underlyingDecimals[i]);
31
+ return [i, j, _amount];
88
32
  });
89
33
  }
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
- });
34
+ function _swapMinAmount(i, j, _amount, slippage = 0.5) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ // @ts-ignore
37
+ const _expected = yield this._swapExpected(i, j, _amount);
38
+ const [outputCoinDecimals] = _getCoinDecimals(this.underlyingCoinAddresses[j]);
39
+ const minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
40
+ return fromBN(minAmountBN, outputCoinDecimals);
104
41
  });
105
42
  }
106
43
  // @ts-ignore
107
- export var swapTricrypto2Mixin = {
44
+ export const swapTricrypto2Mixin = {
108
45
  // @ts-ignore
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*/, smartNumber(gas)];
133
- gasLimit = mulBy1_3(DIGas(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
- });
46
+ _swap(i, j, _amount, slippage, estimateGas = false) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ // @ts-ignore
49
+ const contractAddress = this._swapContractAddress();
50
+ if (!estimateGas)
51
+ yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
52
+ const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
53
+ const contract = curve.contracts[contractAddress].contract;
54
+ const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
55
+ const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
56
+ const gas = yield contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, curve.constantOptions), { value }));
57
+ if (estimateGas)
58
+ return smartNumber(gas);
59
+ const gasLimit = mulBy1_3(DIGas(gas));
60
+ return (yield contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
138
61
  });
139
62
  },
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
- });
63
+ swapEstimateGas(inputCoin, outputCoin, amount) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ // @ts-ignore
66
+ const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
67
+ // @ts-ignore
68
+ return yield this._swap(i, j, _amount, 0.1, true);
154
69
  });
155
70
  },
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
- });
71
+ swap(inputCoin, outputCoin, amount, slippage) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ // @ts-ignore
74
+ const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
75
+ // @ts-ignore
76
+ return yield this._swap(i, j, _amount, slippage);
170
77
  });
171
78
  },
172
79
  };
173
80
  // @ts-ignore
174
- export var swapMetaFactoryMixin = {
81
+ export const swapMetaFactoryMixin = {
175
82
  // @ts-ignore
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*/, smartNumber(gas)];
200
- gasLimit = DIGas(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
- });
83
+ _swap(i, j, _amount, slippage, estimateGas = false) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ // @ts-ignore
86
+ const contractAddress = this._swapContractAddress();
87
+ if (!estimateGas)
88
+ yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
89
+ const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
90
+ const contract = curve.contracts[contractAddress].contract;
91
+ const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
92
+ const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
93
+ const gas = yield contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.constantOptions), { value }));
94
+ if (estimateGas)
95
+ return smartNumber(gas);
96
+ const gasLimit = DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
97
+ return (yield contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
205
98
  });
206
99
  },
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
- });
100
+ swapEstimateGas(inputCoin, outputCoin, amount) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ // @ts-ignore
103
+ const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
104
+ // @ts-ignore
105
+ return yield this._swap(i, j, _amount, 0.1, true);
221
106
  });
222
107
  },
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
- });
108
+ swap(inputCoin, outputCoin, amount, slippage) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ // @ts-ignore
111
+ const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
112
+ // @ts-ignore
113
+ return yield this._swap(i, j, _amount, slippage);
237
114
  });
238
115
  },
239
116
  };
240
117
  // @ts-ignore
241
- export var swapCryptoMetaFactoryMixin = {
118
+ export const swapCryptoMetaFactoryMixin = {
242
119
  // @ts-ignore
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*/, smartNumber(gas)];
267
- gasLimit = DIGas(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
- });
120
+ _swap(i, j, _amount, slippage, estimateGas = false) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ // @ts-ignore
123
+ const contractAddress = this._swapContractAddress();
124
+ if (!estimateGas)
125
+ yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
126
+ const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
127
+ const contract = curve.contracts[contractAddress].contract;
128
+ const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
129
+ const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
130
+ const gas = yield contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, curve.constantOptions), { value }));
131
+ if (estimateGas)
132
+ return smartNumber(gas);
133
+ const gasLimit = DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
134
+ return (yield contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
272
135
  });
273
136
  },
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
- });
137
+ swapEstimateGas(inputCoin, outputCoin, amount) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ // @ts-ignore
140
+ const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
141
+ // @ts-ignore
142
+ return yield this._swap(i, j, _amount, 0.1, true);
288
143
  });
289
144
  },
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
- });
145
+ swap(inputCoin, outputCoin, amount, slippage) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ // @ts-ignore
148
+ const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
149
+ // @ts-ignore
150
+ return yield this._swap(i, j, _amount, slippage);
304
151
  });
305
152
  },
306
153
  };
307
154
  // @ts-ignore
308
- export var swapMixin = {
155
+ export const swapMixin = {
309
156
  // @ts-ignore
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*/, smartNumber(gas)];
334
- return [4 /*yield*/, curve.updateFeeData()];
335
- case 5:
336
- _a.sent();
337
- gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(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
- });
157
+ _swap(i, j, _amount, slippage, estimateGas = false) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ // @ts-ignore
160
+ const contractAddress = this._swapContractAddress();
161
+ if (!estimateGas)
162
+ yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
163
+ const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
164
+ const contract = curve.contracts[contractAddress].contract;
165
+ const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
166
+ const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
167
+ const gas = yield contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.constantOptions), { value }));
168
+ if (estimateGas)
169
+ return smartNumber(gas);
170
+ yield curve.updateFeeData();
171
+ const gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
172
+ return (yield contract[exchangeMethod](i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
342
173
  });
343
174
  },
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
- });
175
+ swapEstimateGas(inputCoin, outputCoin, amount) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ // @ts-ignore
178
+ const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
179
+ // @ts-ignore
180
+ return yield this._swap(i, j, _amount, 0.1, true);
358
181
  });
359
182
  },
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
- });
183
+ swap(inputCoin, outputCoin, amount, slippage) {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ // @ts-ignore
186
+ const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
187
+ // @ts-ignore
188
+ return yield this._swap(i, j, _amount, slippage);
374
189
  });
375
190
  },
376
191
  };