@curvefi/api 2.32.0 → 2.33.0

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,190 +1,350 @@
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 { Contract } from "ethers";
2
49
  import { curve } from "../curve.js";
3
50
  import { parseUnits, BN, mulBy1_3 } from "../utils.js";
4
51
  import CurveLpTokenV5ABI from "../constants/abis/curve_lp_token_v5.json" assert { type: 'json' };
5
52
  // ------- STABLE PLAIN POOLS -------
6
- const _deployStablePlainPool = async (name, symbol, coins, A, fee, // %
7
- assetType, implementationIdx, estimateGas) => {
8
- if (name.length > 32)
9
- throw Error("Max name length = 32");
10
- if (symbol.length > 10)
11
- throw Error("Max symbol length = 10");
12
- if (![2, 3, 4].includes(coins.length))
13
- throw Error("Invalid number of coins. Must be 2, 3 or 4");
14
- if (BN(fee).lt(0.04))
15
- throw Error(`fee must be >= 0.04%. Passed fee = ${fee}`);
16
- if (BN(fee).gt(1))
17
- throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
18
- if (![0, 1, 2, 3].includes(assetType))
19
- throw Error("Invalid assetType. Must be one of: 0 = USD, 1 = ETH, 2 = BTC, 3 = Other");
20
- if (![0, 1, 2, 3].includes(implementationIdx))
21
- throw Error("Invalid implementationIdx. Must be one 0, 1, 2 or 3");
22
- const _A = parseUnits(A, 0);
23
- const _fee = parseUnits(fee, 8);
24
- const _coins = coins.concat(Array(4 - coins.length).fill(curve.constants.ZERO_ADDRESS));
25
- const contract = curve.contracts[curve.constants.ALIASES.factory].contract;
26
- const gas = await contract.deploy_plain_pool.estimateGas(name, symbol, _coins, _A, _fee, assetType, implementationIdx, curve.constantOptions);
27
- if (estimateGas)
28
- return Number(gas);
29
- const gasLimit = mulBy1_3(gas);
30
- await curve.updateFeeData();
31
- return await contract.deploy_plain_pool(name, symbol, _coins, _A, _fee, assetType, implementationIdx, { ...curve.options, gasLimit });
32
- };
33
- export const deployStablePlainPoolEstimateGas = async (name, symbol, coins, A, fee, // %
34
- assetType, implementationIdx) => {
35
- return await _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, true);
36
- };
37
- export const deployStablePlainPool = async (name, symbol, coins, A, fee, // %
38
- assetType, implementationIdx) => {
39
- return await _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, false);
40
- };
41
- export const getDeployedStablePlainPoolAddress = async (tx) => {
42
- const txInfo = await tx.wait();
43
- if (!txInfo)
44
- throw Error("Can't get tx info");
45
- return txInfo.logs[0].address.toLowerCase();
46
- };
53
+ var _deployStablePlainPool = function (name, symbol, coins, A, fee, // %
54
+ assetType, implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
55
+ var _A, _fee, _coins, contract, gas, gasLimit;
56
+ return __generator(this, function (_a) {
57
+ switch (_a.label) {
58
+ case 0:
59
+ if (name.length > 32)
60
+ throw Error("Max name length = 32");
61
+ if (symbol.length > 10)
62
+ throw Error("Max symbol length = 10");
63
+ if (![2, 3, 4].includes(coins.length))
64
+ throw Error("Invalid number of coins. Must be 2, 3 or 4");
65
+ if (BN(fee).lt(0.04))
66
+ throw Error("fee must be >= 0.04%. Passed fee = ".concat(fee));
67
+ if (BN(fee).gt(1))
68
+ throw Error("fee must be <= 1%. Passed fee = ".concat(fee));
69
+ if (![0, 1, 2, 3].includes(assetType))
70
+ throw Error("Invalid assetType. Must be one of: 0 = USD, 1 = ETH, 2 = BTC, 3 = Other");
71
+ if (![0, 1, 2, 3].includes(implementationIdx))
72
+ throw Error("Invalid implementationIdx. Must be one 0, 1, 2 or 3");
73
+ _A = parseUnits(A, 0);
74
+ _fee = parseUnits(fee, 8);
75
+ _coins = coins.concat(Array(4 - coins.length).fill(curve.constants.ZERO_ADDRESS));
76
+ contract = curve.contracts[curve.constants.ALIASES.factory].contract;
77
+ return [4 /*yield*/, contract.deploy_plain_pool.estimateGas(name, symbol, _coins, _A, _fee, assetType, implementationIdx, curve.constantOptions)];
78
+ case 1:
79
+ gas = _a.sent();
80
+ if (estimateGas)
81
+ return [2 /*return*/, Number(gas)];
82
+ gasLimit = mulBy1_3(gas);
83
+ return [4 /*yield*/, curve.updateFeeData()];
84
+ case 2:
85
+ _a.sent();
86
+ return [4 /*yield*/, contract.deploy_plain_pool(name, symbol, _coins, _A, _fee, assetType, implementationIdx, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
87
+ case 3: return [2 /*return*/, _a.sent()];
88
+ }
89
+ });
90
+ }); };
91
+ export var deployStablePlainPoolEstimateGas = function (name, symbol, coins, A, fee, // %
92
+ assetType, implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
93
+ return __generator(this, function (_a) {
94
+ switch (_a.label) {
95
+ case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, true)];
96
+ case 1: return [2 /*return*/, _a.sent()];
97
+ }
98
+ });
99
+ }); };
100
+ export var deployStablePlainPool = function (name, symbol, coins, A, fee, // %
101
+ assetType, implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
102
+ return __generator(this, function (_a) {
103
+ switch (_a.label) {
104
+ case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, false)];
105
+ case 1: return [2 /*return*/, _a.sent()];
106
+ }
107
+ });
108
+ }); };
109
+ export var getDeployedStablePlainPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
110
+ var txInfo;
111
+ return __generator(this, function (_a) {
112
+ switch (_a.label) {
113
+ case 0: return [4 /*yield*/, tx.wait()];
114
+ case 1:
115
+ txInfo = _a.sent();
116
+ if (!txInfo)
117
+ throw Error("Can't get tx info");
118
+ return [2 /*return*/, txInfo.logs[0].address.toLowerCase()];
119
+ }
120
+ });
121
+ }); };
47
122
  // ------- STABLE META POOLS -------
48
- const _deployStableMetaPool = async (basePool, name, symbol, coin, A, fee, // %
49
- implementationIdx, estimateGas) => {
50
- if (name.length > 32)
51
- throw Error("Max name length = 32");
52
- if (symbol.length > 10)
53
- throw Error("Max symbol length = 10");
54
- if (BN(fee).lt(0.04))
55
- throw Error(`fee must be >= 0.04%. Passed fee = ${fee}`);
56
- if (BN(fee).gt(1))
57
- throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
58
- if (![0, 1].includes(implementationIdx))
59
- throw Error("Invalid implementationIdx. Must be one 0 or 1");
60
- const _A = parseUnits(A, 0);
61
- const _fee = parseUnits(fee, 8);
62
- const contract = curve.contracts[curve.constants.ALIASES.factory].contract;
63
- const gas = await contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, implementationIdx, curve.constantOptions);
64
- if (estimateGas)
65
- return Number(gas);
66
- const gasLimit = mulBy1_3(gas);
67
- await curve.updateFeeData();
68
- return await contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, { ...curve.options, gasLimit });
69
- };
70
- export const deployStableMetaPoolEstimateGas = async (basePool, name, symbol, coin, A, fee, // %
71
- implementationIdx) => {
72
- return await _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, true);
73
- };
74
- export const deployStableMetaPool = async (basePool, name, symbol, coin, A, fee, // %
75
- implementationIdx) => {
76
- return await _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, false);
77
- };
78
- export const getDeployedStableMetaPoolAddress = async (tx) => {
79
- const txInfo = await tx.wait();
80
- if (!txInfo)
81
- throw Error("Can't get tx info");
82
- return txInfo.logs[3].address.toLowerCase();
83
- };
123
+ var _deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
124
+ implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
125
+ var _A, _fee, contract, gas, gasLimit;
126
+ return __generator(this, function (_a) {
127
+ switch (_a.label) {
128
+ case 0:
129
+ if (name.length > 32)
130
+ throw Error("Max name length = 32");
131
+ if (symbol.length > 10)
132
+ throw Error("Max symbol length = 10");
133
+ if (BN(fee).lt(0.04))
134
+ throw Error("fee must be >= 0.04%. Passed fee = ".concat(fee));
135
+ if (BN(fee).gt(1))
136
+ throw Error("fee must be <= 1%. Passed fee = ".concat(fee));
137
+ if (![0, 1].includes(implementationIdx))
138
+ throw Error("Invalid implementationIdx. Must be one 0 or 1");
139
+ _A = parseUnits(A, 0);
140
+ _fee = parseUnits(fee, 8);
141
+ contract = curve.contracts[curve.constants.ALIASES.factory].contract;
142
+ return [4 /*yield*/, contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, implementationIdx, curve.constantOptions)];
143
+ case 1:
144
+ gas = _a.sent();
145
+ if (estimateGas)
146
+ return [2 /*return*/, Number(gas)];
147
+ gasLimit = mulBy1_3(gas);
148
+ return [4 /*yield*/, curve.updateFeeData()];
149
+ case 2:
150
+ _a.sent();
151
+ return [4 /*yield*/, contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
152
+ case 3: return [2 /*return*/, _a.sent()];
153
+ }
154
+ });
155
+ }); };
156
+ export var deployStableMetaPoolEstimateGas = function (basePool, name, symbol, coin, A, fee, // %
157
+ implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
158
+ return __generator(this, function (_a) {
159
+ switch (_a.label) {
160
+ case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, true)];
161
+ case 1: return [2 /*return*/, _a.sent()];
162
+ }
163
+ });
164
+ }); };
165
+ export var deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
166
+ implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
167
+ return __generator(this, function (_a) {
168
+ switch (_a.label) {
169
+ case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, false)];
170
+ case 1: return [2 /*return*/, _a.sent()];
171
+ }
172
+ });
173
+ }); };
174
+ export var getDeployedStableMetaPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
175
+ var txInfo;
176
+ return __generator(this, function (_a) {
177
+ switch (_a.label) {
178
+ case 0: return [4 /*yield*/, tx.wait()];
179
+ case 1:
180
+ txInfo = _a.sent();
181
+ if (!txInfo)
182
+ throw Error("Can't get tx info");
183
+ return [2 /*return*/, txInfo.logs[3].address.toLowerCase()];
184
+ }
185
+ });
186
+ }); };
84
187
  // ------- CRYPTO POOLS -------
85
- const _deployCryptoPool = async (name, symbol, coins, A, gamma, midFee, // %
188
+ var _deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
86
189
  outFee, // %
87
190
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
88
- initialPrice, estimateGas) => {
89
- if (name.length > 32)
90
- throw Error("Max name length = 32");
91
- if (symbol.length > 10)
92
- throw Error("Max symbol length = 10");
93
- if (coins.length !== 2)
94
- throw Error("Invalid number of coins. Must be 2");
95
- if (coins[1] === coins[2])
96
- throw Error("Coins must be different");
97
- if (BN(A).lt(4000))
98
- throw Error(`A must be >= 4000. Passed A = ${A}`);
99
- if (BN(A).gt(4 * (10 ** 9)))
100
- throw Error(`A must be <= 4 * 10 ** 9. Passed A = ${A}`);
101
- if (BN(gamma).lt(1e-8))
102
- throw Error(`gamma must be >= 1e-8. Passed gamma = ${gamma}`);
103
- if (BN(gamma).gt(0.02))
104
- throw Error(`gamma must be <= 0.02. Passed gamma = ${gamma}`);
105
- if (BN(midFee).lt(0.005))
106
- throw Error(`midFee must be >= 0.005. Passed midFee = ${midFee}`);
107
- if (BN(midFee).gt(100))
108
- throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
109
- if (BN(outFee).lt(BN(midFee)))
110
- throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
111
- if (BN(outFee).gt(100))
112
- throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
113
- if (BN(allowedExtraProfit).lt(0))
114
- throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
115
- if (BN(allowedExtraProfit).gt(0.01))
116
- throw Error(`allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ${allowedExtraProfit}`);
117
- if (BN(feeGamma).lt(0))
118
- throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
119
- if (BN(feeGamma).gt(1))
120
- throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
121
- if (BN(adjustmentStep).lt(0))
122
- throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
123
- if (BN(adjustmentStep).gt(1))
124
- throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
125
- if (BN(maHalfTime).lt(0))
126
- throw Error(`maHalfTime must be >= 0. Passed maHalfTime=${maHalfTime}`);
127
- if (BN(maHalfTime).gt(604800))
128
- throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${maHalfTime}`);
129
- if (BN(initialPrice).lt(1e-12))
130
- throw Error(`initialPrice must be >= 1e-12. Passed initialPrice=${initialPrice}`);
131
- if (BN(initialPrice).gt(1e12))
132
- throw Error(`initialPrice must be <= 1e12. Passed initialPrice=${initialPrice}`);
133
- const _A = parseUnits(A, 0);
134
- const _gamma = parseUnits(gamma);
135
- const _midFee = parseUnits(midFee, 8);
136
- const _outFee = parseUnits(outFee, 8);
137
- const _allowedExtraProfit = parseUnits(allowedExtraProfit);
138
- const _feeGamma = parseUnits(feeGamma);
139
- const _adjustmentStep = parseUnits(adjustmentStep);
140
- const _maHalfTime = parseUnits(maHalfTime, 0);
141
- const _initialPrice = parseUnits(initialPrice);
142
- const contract = curve.contracts[curve.constants.ALIASES.crypto_factory].contract;
143
- const gas = await contract.deploy_pool.estimateGas(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, _maHalfTime, _initialPrice, curve.constantOptions);
144
- if (estimateGas)
145
- return Number(gas);
146
- const gasLimit = mulBy1_3(gas);
147
- await curve.updateFeeData();
148
- return await contract.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
149
- _maHalfTime, _initialPrice, { ...curve.options, gasLimit });
150
- };
151
- export const deployCryptoPoolEstimateGas = async (name, symbol, coins, A, gamma, midFee, // %
191
+ initialPrice, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
192
+ var _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, _maHalfTime, _initialPrice, contract, gas, gasLimit;
193
+ return __generator(this, function (_a) {
194
+ switch (_a.label) {
195
+ case 0:
196
+ if (name.length > 32)
197
+ throw Error("Max name length = 32");
198
+ if (symbol.length > 10)
199
+ throw Error("Max symbol length = 10");
200
+ if (coins.length !== 2)
201
+ throw Error("Invalid number of coins. Must be 2");
202
+ if (coins[1] === coins[2])
203
+ throw Error("Coins must be different");
204
+ if (BN(A).lt(4000))
205
+ throw Error("A must be >= 4000. Passed A = ".concat(A));
206
+ if (BN(A).gt(4 * (Math.pow(10, 9))))
207
+ throw Error("A must be <= 4 * 10 ** 9. Passed A = ".concat(A));
208
+ if (BN(gamma).lt(1e-8))
209
+ throw Error("gamma must be >= 1e-8. Passed gamma = ".concat(gamma));
210
+ if (BN(gamma).gt(0.02))
211
+ throw Error("gamma must be <= 0.02. Passed gamma = ".concat(gamma));
212
+ if (BN(midFee).lt(0.005))
213
+ throw Error("midFee must be >= 0.005. Passed midFee = ".concat(midFee));
214
+ if (BN(midFee).gt(100))
215
+ throw Error("midFee must be <= 100. Passed midFee = ".concat(midFee));
216
+ if (BN(outFee).lt(BN(midFee)))
217
+ throw Error("outFee must be >= midFee. Passed outFee = ".concat(outFee, " < midFee = ").concat(midFee));
218
+ if (BN(outFee).gt(100))
219
+ throw Error("outFee must be <= 100. Passed outFee = ".concat(outFee));
220
+ if (BN(allowedExtraProfit).lt(0))
221
+ throw Error("allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
222
+ if (BN(allowedExtraProfit).gt(0.01))
223
+ throw Error("allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
224
+ if (BN(feeGamma).lt(0))
225
+ throw Error("feeGamma must be >= 0. Passed feeGamma = ".concat(feeGamma));
226
+ if (BN(feeGamma).gt(1))
227
+ throw Error("feeGamma must be <= 1. Passed feeGamma = ".concat(feeGamma));
228
+ if (BN(adjustmentStep).lt(0))
229
+ throw Error("adjustmentStep must be >= 0. Passed adjustmentStep=".concat(adjustmentStep));
230
+ if (BN(adjustmentStep).gt(1))
231
+ throw Error("adjustmentStep must be <= 1. Passed adjustmentStep=".concat(adjustmentStep));
232
+ if (BN(maHalfTime).lt(0))
233
+ throw Error("maHalfTime must be >= 0. Passed maHalfTime=".concat(maHalfTime));
234
+ if (BN(maHalfTime).gt(604800))
235
+ throw Error("maHalfTime must be <= 604800. Passed maHalfTime=".concat(maHalfTime));
236
+ if (BN(initialPrice).lt(1e-12))
237
+ throw Error("initialPrice must be >= 1e-12. Passed initialPrice=".concat(initialPrice));
238
+ if (BN(initialPrice).gt(1e12))
239
+ throw Error("initialPrice must be <= 1e12. Passed initialPrice=".concat(initialPrice));
240
+ _A = parseUnits(A, 0);
241
+ _gamma = parseUnits(gamma);
242
+ _midFee = parseUnits(midFee, 8);
243
+ _outFee = parseUnits(outFee, 8);
244
+ _allowedExtraProfit = parseUnits(allowedExtraProfit);
245
+ _feeGamma = parseUnits(feeGamma);
246
+ _adjustmentStep = parseUnits(adjustmentStep);
247
+ _maHalfTime = parseUnits(maHalfTime, 0);
248
+ _initialPrice = parseUnits(initialPrice);
249
+ contract = curve.contracts[curve.constants.ALIASES.crypto_factory].contract;
250
+ return [4 /*yield*/, contract.deploy_pool.estimateGas(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, _maHalfTime, _initialPrice, curve.constantOptions)];
251
+ case 1:
252
+ gas = _a.sent();
253
+ if (estimateGas)
254
+ return [2 /*return*/, Number(gas)];
255
+ gasLimit = mulBy1_3(gas);
256
+ return [4 /*yield*/, curve.updateFeeData()];
257
+ case 2:
258
+ _a.sent();
259
+ return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
260
+ _maHalfTime, _initialPrice, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
261
+ case 3: return [2 /*return*/, _a.sent()];
262
+ }
263
+ });
264
+ }); };
265
+ export var deployCryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
152
266
  outFee, // %
153
267
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
154
- initialPrice) => {
155
- return await _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true);
156
- };
157
- export const deployCryptoPool = async (name, symbol, coins, A, gamma, midFee, // %
268
+ initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
269
+ return __generator(this, function (_a) {
270
+ switch (_a.label) {
271
+ case 0: return [4 /*yield*/, _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true)];
272
+ case 1: return [2 /*return*/, _a.sent()];
273
+ }
274
+ });
275
+ }); };
276
+ export var deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
158
277
  outFee, // %
159
278
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
160
- initialPrice) => {
161
- return await _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false);
162
- };
163
- export const getDeployedCryptoPoolAddress = async (tx) => {
164
- const txInfo = await tx.wait();
165
- if (!txInfo)
166
- throw Error("Can't get tx info");
167
- const lpTokenAddress = txInfo.logs[0].address;
168
- const contract = new Contract(lpTokenAddress, CurveLpTokenV5ABI, curve.provider);
169
- return (await contract.minter(curve.constantOptions)).toLowerCase();
170
- };
279
+ initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
280
+ return __generator(this, function (_a) {
281
+ switch (_a.label) {
282
+ case 0: return [4 /*yield*/, _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false)];
283
+ case 1: return [2 /*return*/, _a.sent()];
284
+ }
285
+ });
286
+ }); };
287
+ export var getDeployedCryptoPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
288
+ var txInfo, lpTokenAddress, contract;
289
+ return __generator(this, function (_a) {
290
+ switch (_a.label) {
291
+ case 0: return [4 /*yield*/, tx.wait()];
292
+ case 1:
293
+ txInfo = _a.sent();
294
+ if (!txInfo)
295
+ throw Error("Can't get tx info");
296
+ lpTokenAddress = txInfo.logs[0].address;
297
+ contract = new Contract(lpTokenAddress, CurveLpTokenV5ABI, curve.provider);
298
+ return [4 /*yield*/, contract.minter(curve.constantOptions)];
299
+ case 2: return [2 /*return*/, (_a.sent()).toLowerCase()];
300
+ }
301
+ });
302
+ }); };
171
303
  // ------- GAUGE -------
172
- const _deployGauge = async (pool, isCrypto, estimateGas) => {
173
- const contractAddress = isCrypto ? curve.constants.ALIASES.crypto_factory : curve.constants.ALIASES.factory;
174
- const contract = curve.contracts[contractAddress].contract;
175
- const gas = await contract.deploy_gauge.estimateGas(pool, curve.constantOptions);
176
- if (estimateGas)
177
- return Number(gas);
178
- const gasLimit = mulBy1_3(gas);
179
- await curve.updateFeeData();
180
- return await contract.deploy_gauge(pool, { ...curve.options, gasLimit });
181
- };
182
- export const deployGaugeEstimateGas = async (pool, isCrypto) => await _deployGauge(pool, isCrypto, true);
183
- export const deployGauge = async (pool, isCrypto) => await _deployGauge(pool, isCrypto, false);
184
- export const getDeployedGaugeAddress = async (tx) => {
185
- const txInfo = await tx.wait();
186
- if (!txInfo)
187
- throw Error("Can't get tx info");
188
- // @ts-ignore
189
- return txInfo.events[0].args[txInfo.events[0].args.length - 1].toLowerCase();
190
- };
304
+ var _deployGauge = function (pool, isCrypto, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
305
+ var contractAddress, contract, gas, gasLimit;
306
+ return __generator(this, function (_a) {
307
+ switch (_a.label) {
308
+ case 0:
309
+ contractAddress = isCrypto ? curve.constants.ALIASES.crypto_factory : curve.constants.ALIASES.factory;
310
+ contract = curve.contracts[contractAddress].contract;
311
+ return [4 /*yield*/, contract.deploy_gauge.estimateGas(pool, curve.constantOptions)];
312
+ case 1:
313
+ gas = _a.sent();
314
+ if (estimateGas)
315
+ return [2 /*return*/, Number(gas)];
316
+ gasLimit = mulBy1_3(gas);
317
+ return [4 /*yield*/, curve.updateFeeData()];
318
+ case 2:
319
+ _a.sent();
320
+ return [4 /*yield*/, contract.deploy_gauge(pool, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
321
+ case 3: return [2 /*return*/, _a.sent()];
322
+ }
323
+ });
324
+ }); };
325
+ export var deployGaugeEstimateGas = function (pool, isCrypto) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
326
+ switch (_a.label) {
327
+ case 0: return [4 /*yield*/, _deployGauge(pool, isCrypto, true)];
328
+ case 1: return [2 /*return*/, _a.sent()];
329
+ }
330
+ }); }); };
331
+ export var deployGauge = function (pool, isCrypto) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
332
+ switch (_a.label) {
333
+ case 0: return [4 /*yield*/, _deployGauge(pool, isCrypto, false)];
334
+ case 1: return [2 /*return*/, _a.sent()];
335
+ }
336
+ }); }); };
337
+ export var getDeployedGaugeAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
338
+ var txInfo;
339
+ return __generator(this, function (_a) {
340
+ switch (_a.label) {
341
+ case 0: return [4 /*yield*/, tx.wait()];
342
+ case 1:
343
+ txInfo = _a.sent();
344
+ if (!txInfo)
345
+ throw Error("Can't get tx info");
346
+ // @ts-ignore
347
+ return [2 /*return*/, txInfo.events[0].args[txInfo.events[0].args.length - 1].toLowerCase()];
348
+ }
349
+ });
350
+ }); };