@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,439 +1,179 @@
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];
1
+ import { curve } from "../../curve.js";
2
+ import { _ensureAllowance, fromBN, getEthIndex, hasAllowance, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
3
+ // @ts-ignore
4
+ async function _depositCheck(amounts, estimateGas = false) {
5
+ if (amounts.length !== this.underlyingCoinAddresses.length) {
6
+ throw Error(`${this.name} pool has ${this.underlyingCoinAddresses.length} coins (amounts provided for ${amounts.length})`);
7
+ }
8
+ const balances = Object.values(await this.wallet.underlyingCoinBalances());
9
+ for (let i = 0; i < balances.length; i++) {
10
+ if (Number(balances[i]) < Number(amounts[i])) {
11
+ throw Error(`Not enough ${this.underlyingCoins[i]}. Actual: ${balances[i]}, required: ${amounts[i]}`);
8
12
  }
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
13
  }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.depositPlainMixin = exports.depositLendingOrCryptoMixin = exports.depositZapMixin = exports.depositCryptoMetaFactoryMixin = exports.depositMetaFactoryMixin = void 0;
51
- var utils_1 = require("../../utils");
52
- var curve_1 = require("../../curve");
53
- var ethers_1 = require("ethers");
54
- // @ts-ignore
55
- function _depositCheck(amounts, estimateGas) {
56
- if (estimateGas === void 0) { estimateGas = false; }
57
- return __awaiter(this, void 0, void 0, function () {
58
- var balances, _a, _b, i, _c;
59
- var _this = this;
60
- return __generator(this, function (_d) {
61
- switch (_d.label) {
62
- case 0:
63
- if (amounts.length !== this.underlyingCoinAddresses.length) {
64
- throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
65
- }
66
- _b = (_a = Object).values;
67
- return [4 /*yield*/, this.wallet.underlyingCoinBalances()];
68
- case 1:
69
- balances = _b.apply(_a, [_d.sent()]);
70
- for (i = 0; i < balances.length; i++) {
71
- if (Number(balances[i]) < Number(amounts[i])) {
72
- throw Error("Not enough ".concat(this.underlyingCoins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
73
- }
74
- }
75
- _c = estimateGas;
76
- if (!_c) return [3 /*break*/, 3];
77
- return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.address)];
78
- case 2:
79
- _c = !(_d.sent());
80
- _d.label = 3;
81
- case 3:
82
- if (_c) {
83
- throw Error("Token allowance is needed to estimate gas");
84
- }
85
- if (!!estimateGas) return [3 /*break*/, 5];
86
- return [4 /*yield*/, curve_1.curve.updateFeeData()];
87
- case 4:
88
- _d.sent();
89
- _d.label = 5;
90
- case 5: return [2 /*return*/, amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); })];
91
- }
92
- });
93
- });
14
+ if (estimateGas && !(await hasAllowance(this.underlyingCoinAddresses, amounts, curve.signerAddress, this.zap || this.address))) {
15
+ throw Error("Token allowance is needed to estimate gas");
16
+ }
17
+ if (!estimateGas)
18
+ await curve.updateFeeData();
19
+ return amounts.map((amount, i) => parseUnits(amount, this.underlyingDecimals[i]));
94
20
  }
95
- function _depositMinAmount(_amounts, slippage) {
96
- if (slippage === void 0) { slippage = 0.5; }
97
- return __awaiter(this, void 0, void 0, function () {
98
- var _expectedLpTokenAmount, minAmountBN;
99
- return __generator(this, function (_a) {
100
- switch (_a.label) {
101
- case 0: return [4 /*yield*/, this._calcLpTokenAmount(_amounts)];
102
- case 1:
103
- _expectedLpTokenAmount = _a.sent();
104
- minAmountBN = (0, utils_1.toBN)(_expectedLpTokenAmount).times(100 - slippage).div(100);
105
- return [2 /*return*/, (0, utils_1.fromBN)(minAmountBN)];
106
- }
107
- });
108
- });
21
+ async function _depositMinAmount(_amounts, slippage = 0.5) {
22
+ // @ts-ignore
23
+ const _expectedLpTokenAmount = await this._calcLpTokenAmount(_amounts);
24
+ const minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
25
+ return fromBN(minAmountBN);
109
26
  }
110
27
  // @ts-ignore
111
- exports.depositMetaFactoryMixin = {
28
+ export const depositMetaFactoryMixin = {
112
29
  // @ts-ignore
113
- _deposit: function (_amounts, slippage, estimateGas) {
114
- if (estimateGas === void 0) { estimateGas = false; }
115
- return __awaiter(this, void 0, void 0, function () {
116
- var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
117
- return __generator(this, function (_a) {
118
- switch (_a.label) {
119
- case 0:
120
- if (!!estimateGas) return [3 /*break*/, 2];
121
- return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.underlyingCoinAddresses, _amounts, this.zap)];
122
- case 1:
123
- _a.sent();
124
- _a.label = 2;
125
- case 2: return [4 /*yield*/, _depositMinAmount.call(this, _amounts, slippage)];
126
- case 3:
127
- _minMintAmount = _a.sent();
128
- ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
129
- value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
130
- contract = curve_1.curve.contracts[this.zap].contract;
131
- return [4 /*yield*/, contract.estimateGas.add_liquidity(this.address, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
132
- case 4:
133
- gas = _a.sent();
134
- if (estimateGas)
135
- return [2 /*return*/, gas.toNumber()];
136
- gasLimit = gas.mul(130).div(100);
137
- return [4 /*yield*/, contract.add_liquidity(this.address, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
138
- case 5: return [2 /*return*/, (_a.sent()).hash];
139
- }
140
- });
141
- });
30
+ async _deposit(_amounts, slippage, estimateGas = false) {
31
+ if (!estimateGas)
32
+ await _ensureAllowance(this.underlyingCoinAddresses, _amounts, this.zap);
33
+ // @ts-ignore
34
+ const _minMintAmount = await _depositMinAmount.call(this, _amounts, slippage);
35
+ const ethIndex = getEthIndex(this.underlyingCoinAddresses);
36
+ const value = _amounts[ethIndex] || 0n;
37
+ const contract = curve.contracts[this.zap].contract;
38
+ const gas = await contract.add_liquidity.estimateGas(this.address, _amounts, _minMintAmount, { ...curve.constantOptions, value });
39
+ if (estimateGas)
40
+ return Number(gas);
41
+ const gasLimit = mulBy1_3(gas);
42
+ return (await contract.add_liquidity(this.address, _amounts, _minMintAmount, { ...curve.options, gasLimit, value })).hash;
142
43
  },
143
- depositEstimateGas: function (amounts) {
144
- return __awaiter(this, void 0, void 0, function () {
145
- var _amounts;
146
- return __generator(this, function (_a) {
147
- switch (_a.label) {
148
- case 0: return [4 /*yield*/, _depositCheck.call(this, amounts, true)];
149
- case 1:
150
- _amounts = _a.sent();
151
- return [4 /*yield*/, this._deposit(_amounts, 0.1, true)];
152
- case 2:
153
- // @ts-ignore
154
- return [2 /*return*/, _a.sent()];
155
- }
156
- });
157
- });
44
+ async depositEstimateGas(amounts) {
45
+ // @ts-ignore
46
+ const _amounts = await _depositCheck.call(this, amounts, true);
47
+ // @ts-ignore
48
+ return await this._deposit(_amounts, 0.1, true);
158
49
  },
159
- deposit: function (amounts, slippage) {
160
- return __awaiter(this, void 0, void 0, function () {
161
- var _amounts;
162
- return __generator(this, function (_a) {
163
- switch (_a.label) {
164
- case 0: return [4 /*yield*/, _depositCheck.call(this, amounts)];
165
- case 1:
166
- _amounts = _a.sent();
167
- return [4 /*yield*/, this._deposit(_amounts, slippage)];
168
- case 2:
169
- // @ts-ignore
170
- return [2 /*return*/, _a.sent()];
171
- }
172
- });
173
- });
50
+ async deposit(amounts, slippage) {
51
+ // @ts-ignore
52
+ const _amounts = await _depositCheck.call(this, amounts);
53
+ // @ts-ignore
54
+ return await this._deposit(_amounts, slippage);
174
55
  },
175
56
  };
176
57
  // @ts-ignore
177
- exports.depositCryptoMetaFactoryMixin = {
58
+ export const depositCryptoMetaFactoryMixin = {
178
59
  // @ts-ignore
179
- _deposit: function (_amounts, slippage, estimateGas) {
180
- if (estimateGas === void 0) { estimateGas = false; }
181
- return __awaiter(this, void 0, void 0, function () {
182
- var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
183
- return __generator(this, function (_a) {
184
- switch (_a.label) {
185
- case 0:
186
- if (!!estimateGas) return [3 /*break*/, 2];
187
- return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.underlyingCoinAddresses, _amounts, this.zap)];
188
- case 1:
189
- _a.sent();
190
- _a.label = 2;
191
- case 2: return [4 /*yield*/, _depositMinAmount.call(this, _amounts, slippage)];
192
- case 3:
193
- _minMintAmount = _a.sent();
194
- ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
195
- value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
196
- contract = curve_1.curve.contracts[this.zap].contract;
197
- return [4 /*yield*/, contract.estimateGas.add_liquidity(this.address, _amounts, _minMintAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
198
- case 4:
199
- gas = _a.sent();
200
- if (estimateGas)
201
- return [2 /*return*/, gas.toNumber()];
202
- gasLimit = gas.mul(130).div(100);
203
- return [4 /*yield*/, contract.add_liquidity(this.address, _amounts, _minMintAmount, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
204
- case 5: return [2 /*return*/, (_a.sent()).hash];
205
- }
206
- });
207
- });
60
+ async _deposit(_amounts, slippage, estimateGas = false) {
61
+ if (!estimateGas)
62
+ await _ensureAllowance(this.underlyingCoinAddresses, _amounts, this.zap);
63
+ // @ts-ignore
64
+ const _minMintAmount = await _depositMinAmount.call(this, _amounts, slippage);
65
+ const ethIndex = getEthIndex(this.underlyingCoinAddresses);
66
+ const value = _amounts[ethIndex] || 0n;
67
+ const contract = curve.contracts[this.zap].contract;
68
+ const gas = await contract.add_liquidity.estimateGas(this.address, _amounts, _minMintAmount, true, { ...curve.constantOptions, value });
69
+ if (estimateGas)
70
+ return Number(gas);
71
+ const gasLimit = mulBy1_3(gas);
72
+ return (await contract.add_liquidity(this.address, _amounts, _minMintAmount, true, { ...curve.options, gasLimit, value })).hash;
208
73
  },
209
- depositEstimateGas: function (amounts) {
210
- return __awaiter(this, void 0, void 0, function () {
211
- var _amounts;
212
- return __generator(this, function (_a) {
213
- switch (_a.label) {
214
- case 0: return [4 /*yield*/, _depositCheck.call(this, amounts, true)];
215
- case 1:
216
- _amounts = _a.sent();
217
- return [4 /*yield*/, this._deposit(_amounts, 0.1, true)];
218
- case 2:
219
- // @ts-ignore
220
- return [2 /*return*/, _a.sent()];
221
- }
222
- });
223
- });
74
+ async depositEstimateGas(amounts) {
75
+ // @ts-ignore
76
+ const _amounts = await _depositCheck.call(this, amounts, true);
77
+ // @ts-ignore
78
+ return await this._deposit(_amounts, 0.1, true);
224
79
  },
225
- deposit: function (amounts, slippage) {
226
- return __awaiter(this, void 0, void 0, function () {
227
- var _amounts;
228
- return __generator(this, function (_a) {
229
- switch (_a.label) {
230
- case 0: return [4 /*yield*/, _depositCheck.call(this, amounts)];
231
- case 1:
232
- _amounts = _a.sent();
233
- return [4 /*yield*/, this._deposit(_amounts, slippage)];
234
- case 2:
235
- // @ts-ignore
236
- return [2 /*return*/, _a.sent()];
237
- }
238
- });
239
- });
80
+ async deposit(amounts, slippage) {
81
+ // @ts-ignore
82
+ const _amounts = await _depositCheck.call(this, amounts);
83
+ // @ts-ignore
84
+ return await this._deposit(_amounts, slippage);
240
85
  },
241
86
  };
242
87
  // @ts-ignore
243
- exports.depositZapMixin = {
88
+ export const depositZapMixin = {
244
89
  // @ts-ignore
245
- _deposit: function (_amounts, slippage, estimateGas) {
246
- if (estimateGas === void 0) { estimateGas = false; }
247
- return __awaiter(this, void 0, void 0, function () {
248
- var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
249
- return __generator(this, function (_a) {
250
- switch (_a.label) {
251
- case 0:
252
- if (!!estimateGas) return [3 /*break*/, 2];
253
- return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.underlyingCoinAddresses, _amounts, this.zap)];
254
- case 1:
255
- _a.sent();
256
- _a.label = 2;
257
- case 2: return [4 /*yield*/, _depositMinAmount.call(this, _amounts, slippage)];
258
- case 3:
259
- _minMintAmount = _a.sent();
260
- ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
261
- value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
262
- contract = curve_1.curve.contracts[this.zap].contract;
263
- return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
264
- case 4:
265
- gas = _a.sent();
266
- if (estimateGas)
267
- return [2 /*return*/, gas.toNumber()];
268
- gasLimit = gas.mul(130).div(100);
269
- return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
270
- case 5: return [2 /*return*/, (_a.sent()).hash];
271
- }
272
- });
273
- });
90
+ async _deposit(_amounts, slippage, estimateGas = false) {
91
+ if (!estimateGas)
92
+ await _ensureAllowance(this.underlyingCoinAddresses, _amounts, this.zap);
93
+ // @ts-ignore
94
+ const _minMintAmount = await _depositMinAmount.call(this, _amounts, slippage);
95
+ const ethIndex = getEthIndex(this.underlyingCoinAddresses);
96
+ const value = _amounts[ethIndex] || 0n;
97
+ const contract = curve.contracts[this.zap].contract;
98
+ const args = [_amounts, _minMintAmount];
99
+ if (`add_liquidity(uint256[${this.underlyingCoinAddresses.length}],uint256,bool)` in contract)
100
+ args.push(true);
101
+ const gas = await contract.add_liquidity.estimateGas(...args, { ...curve.constantOptions, value });
102
+ if (estimateGas)
103
+ return Number(gas);
104
+ const gasLimit = mulBy1_3(gas);
105
+ return (await contract.add_liquidity(...args, { ...curve.options, gasLimit, value })).hash;
274
106
  },
275
- depositEstimateGas: function (amounts) {
276
- return __awaiter(this, void 0, void 0, function () {
277
- var _amounts;
278
- return __generator(this, function (_a) {
279
- switch (_a.label) {
280
- case 0: return [4 /*yield*/, _depositCheck.call(this, amounts, true)];
281
- case 1:
282
- _amounts = _a.sent();
283
- return [4 /*yield*/, this._deposit(_amounts, 0.1, true)];
284
- case 2:
285
- // @ts-ignore
286
- return [2 /*return*/, _a.sent()];
287
- }
288
- });
289
- });
107
+ async depositEstimateGas(amounts) {
108
+ // @ts-ignore
109
+ const _amounts = await _depositCheck.call(this, amounts, true);
110
+ // @ts-ignore
111
+ return await this._deposit(_amounts, 0.1, true);
290
112
  },
291
- deposit: function (amounts, slippage) {
292
- return __awaiter(this, void 0, void 0, function () {
293
- var _amounts;
294
- return __generator(this, function (_a) {
295
- switch (_a.label) {
296
- case 0: return [4 /*yield*/, _depositCheck.call(this, amounts)];
297
- case 1:
298
- _amounts = _a.sent();
299
- return [4 /*yield*/, this._deposit(_amounts, slippage)];
300
- case 2:
301
- // @ts-ignore
302
- return [2 /*return*/, _a.sent()];
303
- }
304
- });
305
- });
113
+ async deposit(amounts, slippage) {
114
+ // @ts-ignore
115
+ const _amounts = await _depositCheck.call(this, amounts);
116
+ // @ts-ignore
117
+ return await this._deposit(_amounts, slippage);
306
118
  },
307
119
  };
308
120
  // @ts-ignore
309
- exports.depositLendingOrCryptoMixin = {
121
+ export const depositLendingOrCryptoMixin = {
310
122
  // @ts-ignore
311
- _deposit: function (_amounts, slippage, estimateGas) {
312
- if (estimateGas === void 0) { estimateGas = false; }
313
- return __awaiter(this, void 0, void 0, function () {
314
- var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
315
- return __generator(this, function (_a) {
316
- switch (_a.label) {
317
- case 0:
318
- if (!!estimateGas) return [3 /*break*/, 2];
319
- return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.underlyingCoinAddresses, _amounts, this.address)];
320
- case 1:
321
- _a.sent();
322
- _a.label = 2;
323
- case 2: return [4 /*yield*/, _depositMinAmount.call(this, _amounts, slippage)];
324
- case 3:
325
- _minMintAmount = _a.sent();
326
- ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
327
- value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
328
- contract = curve_1.curve.contracts[this.address].contract;
329
- return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
330
- case 4:
331
- gas = _a.sent();
332
- if (estimateGas)
333
- return [2 /*return*/, gas.toNumber()];
334
- gasLimit = gas.mul(130).div(100);
335
- return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
336
- case 5: return [2 /*return*/, (_a.sent()).hash];
337
- }
338
- });
339
- });
123
+ async _deposit(_amounts, slippage, estimateGas = false) {
124
+ if (!estimateGas)
125
+ await _ensureAllowance(this.underlyingCoinAddresses, _amounts, this.address);
126
+ // @ts-ignore
127
+ const _minMintAmount = await _depositMinAmount.call(this, _amounts, slippage);
128
+ const ethIndex = getEthIndex(this.underlyingCoinAddresses);
129
+ const value = _amounts[ethIndex] || 0n;
130
+ const contract = curve.contracts[this.address].contract;
131
+ const gas = await contract.add_liquidity.estimateGas(_amounts, _minMintAmount, true, { ...curve.constantOptions, value });
132
+ if (estimateGas)
133
+ return Number(gas);
134
+ const gasLimit = mulBy1_3(gas);
135
+ return (await contract.add_liquidity(_amounts, _minMintAmount, true, { ...curve.options, gasLimit, value })).hash;
340
136
  },
341
- depositEstimateGas: function (amounts) {
342
- return __awaiter(this, void 0, void 0, function () {
343
- var _amounts;
344
- return __generator(this, function (_a) {
345
- switch (_a.label) {
346
- case 0: return [4 /*yield*/, _depositCheck.call(this, amounts, true)];
347
- case 1:
348
- _amounts = _a.sent();
349
- return [4 /*yield*/, this._deposit(_amounts, 0.1, true)];
350
- case 2:
351
- // @ts-ignore
352
- return [2 /*return*/, _a.sent()];
353
- }
354
- });
355
- });
137
+ async depositEstimateGas(amounts) {
138
+ // @ts-ignore
139
+ const _amounts = await _depositCheck.call(this, amounts, true);
140
+ // @ts-ignore
141
+ return await this._deposit(_amounts, 0.1, true);
356
142
  },
357
- deposit: function (amounts, slippage) {
358
- return __awaiter(this, void 0, void 0, function () {
359
- var _amounts;
360
- return __generator(this, function (_a) {
361
- switch (_a.label) {
362
- case 0: return [4 /*yield*/, _depositCheck.call(this, amounts)];
363
- case 1:
364
- _amounts = _a.sent();
365
- return [4 /*yield*/, this._deposit(_amounts, slippage)];
366
- case 2:
367
- // @ts-ignore
368
- return [2 /*return*/, _a.sent()];
369
- }
370
- });
371
- });
143
+ async deposit(amounts, slippage) {
144
+ // @ts-ignore
145
+ const _amounts = await _depositCheck.call(this, amounts);
146
+ // @ts-ignore
147
+ return await this._deposit(_amounts, slippage);
372
148
  },
373
149
  };
374
150
  // @ts-ignore
375
- exports.depositPlainMixin = {
151
+ export const depositPlainMixin = {
376
152
  // @ts-ignore
377
- _deposit: function (_amounts, slippage, estimateGas) {
378
- if (estimateGas === void 0) { estimateGas = false; }
379
- return __awaiter(this, void 0, void 0, function () {
380
- var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
381
- return __generator(this, function (_a) {
382
- switch (_a.label) {
383
- case 0:
384
- if (!!estimateGas) return [3 /*break*/, 2];
385
- return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.wrappedCoinAddresses, _amounts, this.address)];
386
- case 1:
387
- _a.sent();
388
- _a.label = 2;
389
- case 2: return [4 /*yield*/, _depositMinAmount.call(this, _amounts, slippage)];
390
- case 3:
391
- _minMintAmount = _a.sent();
392
- ethIndex = (0, utils_1.getEthIndex)(this.wrappedCoinAddresses);
393
- value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
394
- contract = curve_1.curve.contracts[this.address].contract;
395
- return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
396
- case 4:
397
- gas = _a.sent();
398
- if (estimateGas)
399
- return [2 /*return*/, gas.toNumber()];
400
- gasLimit = gas.mul(130).div(100);
401
- return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
402
- case 5: return [2 /*return*/, (_a.sent()).hash];
403
- }
404
- });
405
- });
153
+ async _deposit(_amounts, slippage, estimateGas = false) {
154
+ if (!estimateGas)
155
+ await _ensureAllowance(this.wrappedCoinAddresses, _amounts, this.address);
156
+ // @ts-ignore
157
+ const _minMintAmount = await _depositMinAmount.call(this, _amounts, slippage);
158
+ const ethIndex = getEthIndex(this.wrappedCoinAddresses);
159
+ const value = _amounts[ethIndex] || 0n;
160
+ const contract = curve.contracts[this.address].contract;
161
+ const gas = await contract.add_liquidity.estimateGas(_amounts, _minMintAmount, { ...curve.constantOptions, value });
162
+ if (estimateGas)
163
+ return Number(gas);
164
+ const gasLimit = mulBy1_3(gas);
165
+ return (await contract.add_liquidity(_amounts, _minMintAmount, { ...curve.options, gasLimit, value })).hash;
406
166
  },
407
- depositEstimateGas: function (amounts) {
408
- return __awaiter(this, void 0, void 0, function () {
409
- var _amounts;
410
- return __generator(this, function (_a) {
411
- switch (_a.label) {
412
- case 0: return [4 /*yield*/, _depositCheck.call(this, amounts, true)];
413
- case 1:
414
- _amounts = _a.sent();
415
- return [4 /*yield*/, this._deposit(_amounts, 0.1, true)];
416
- case 2:
417
- // @ts-ignore
418
- return [2 /*return*/, _a.sent()];
419
- }
420
- });
421
- });
167
+ async depositEstimateGas(amounts) {
168
+ // @ts-ignore
169
+ const _amounts = await _depositCheck.call(this, amounts, true);
170
+ // @ts-ignore
171
+ return await this._deposit(_amounts, 0.1, true);
422
172
  },
423
- deposit: function (amounts, slippage) {
424
- return __awaiter(this, void 0, void 0, function () {
425
- var _amounts;
426
- return __generator(this, function (_a) {
427
- switch (_a.label) {
428
- case 0: return [4 /*yield*/, _depositCheck.call(this, amounts)];
429
- case 1:
430
- _amounts = _a.sent();
431
- return [4 /*yield*/, this._deposit(_amounts, slippage)];
432
- case 2:
433
- // @ts-ignore
434
- return [2 /*return*/, _a.sent()];
435
- }
436
- });
437
- });
173
+ async deposit(amounts, slippage) {
174
+ // @ts-ignore
175
+ const _amounts = await _depositCheck.call(this, amounts);
176
+ // @ts-ignore
177
+ return await this._deposit(_amounts, slippage);
438
178
  },
439
179
  };
@@ -1,3 +1,3 @@
1
- import { PoolTemplate } from "../PoolTemplate";
1
+ import { PoolTemplate } from "../PoolTemplate.js";
2
2
  export declare const depositWrapped2argsMixin: PoolTemplate;
3
3
  export declare const depositWrapped3argsMixin: PoolTemplate;