@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,42 +7,6 @@ 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
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
- if (ar || !(i in from)) {
51
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
- ar[i] = from[i];
53
- }
54
- }
55
- return to.concat(ar || Array.prototype.slice.call(from));
56
- };
57
10
  import { ethers, Contract, Typed } from "ethers";
58
11
  import { curve } from "../curve.js";
59
12
  import { getPool } from "../pools/index.js";
@@ -62,904 +15,586 @@ import CurveLpTokenV5ABI from "../constants/abis/curve_lp_token_v5.json" assert
62
15
  import Plain2ETHOracleABIABI from "../constants/abis/factory-v2/Plain2ETHOracle.json" assert { type: 'json' };
63
16
  import { tricryptoDeployImplementations } from "../constants/tricryptoDeployImplementations.js";
64
17
  // ------- STABLE PLAIN POOLS -------
65
- var _deployStablePlainPool = function (name, symbol, coins, A, fee, // %
18
+ const _deployStablePlainPool = (name, symbol, coins, A, fee, // %
66
19
  assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
67
20
  implementationIdx, emaTime, // seconds
68
- oracleAddress, methodName, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
69
- var _A, _fee, _coins, useProxy, setOracle, contractAddress, contract, args, methodId, methodToCall, gas, gasLimit;
70
- var _a;
71
- return __generator(this, function (_b) {
72
- switch (_b.label) {
73
- case 0:
74
- if (name.length > 32)
75
- throw Error("Max name length = 32");
76
- if (symbol.length > 10)
77
- throw Error("Max symbol length = 10");
78
- if (![2, 3, 4].includes(coins.length))
79
- throw Error("Invalid number of coins. Must be 2, 3 or 4");
80
- if (BN(fee).lt(0.04))
81
- throw Error("fee must be >= 0.04%. Passed fee = ".concat(fee));
82
- if (BN(fee).gt(1))
83
- throw Error("fee must be <= 1%. Passed fee = ".concat(fee));
84
- if (![0, 1, 2, 3].includes(assetType))
85
- throw Error("Invalid assetType. Must be one of: 0 = USD, 1 = ETH, 2 = BTC, 3 = Other");
86
- if (curve.chainId !== 1 || coins.length > 2) {
87
- if (![0, 1, 2, 3].includes(implementationIdx))
88
- throw Error("Invalid implementationIdx. Must be one 0, 1, 2 or 3");
89
- }
90
- else {
91
- if (![0, 1, 2, 3, 4, 5].includes(implementationIdx))
92
- throw Error("Invalid implementationIdx. Must be one 0, 1, 2, 3, 4 or 5");
93
- }
94
- if (emaTime <= 0)
95
- throw Error("emaTime must be > 0. Passed emaTime = ".concat(emaTime));
96
- _A = parseUnits(A, 0);
97
- _fee = parseUnits(fee, 8);
98
- _coins = coins.concat(Array(4 - coins.length).fill(curve.constants.ZERO_ADDRESS));
99
- useProxy = (curve.chainId === 1 && coins.length === 2 && implementationIdx === 4 && emaTime !== 600) ||
100
- (curve.chainId === 1 && coins.length === 2 && implementationIdx === 5 && emaTime !== 600) ||
101
- ((curve.chainId === 42161 || curve.chainId == 10) && coins.length === 2 && implementationIdx === 0 && emaTime !== 600);
102
- setOracle = ((curve.chainId === 42161 || curve.chainId == 10) && coins.length === 2 && implementationIdx === 2);
103
- contractAddress = (useProxy || setOracle) ? curve.constants.ALIASES.factory_admin : curve.constants.ALIASES.factory;
104
- contract = curve.contracts[contractAddress].contract;
105
- args = [name, symbol, _coins, _A, _fee, assetType, implementationIdx];
106
- if (useProxy || setOracle)
107
- args.push(parseUnits(Math.floor(emaTime / Math.log(2)), 0));
108
- if (setOracle) {
109
- methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
110
- args.push(methodId, oracleAddress);
111
- }
112
- methodToCall = setOracle ? "deploy_plain_pool_and_set_oracle" : "deploy_plain_pool";
113
- return [4 /*yield*/, (_a = contract[methodToCall]).estimateGas.apply(_a, __spreadArray(__spreadArray([], args, false), [curve.constantOptions], false))];
114
- case 1:
115
- gas = _b.sent();
116
- if (estimateGas)
117
- return [2 /*return*/, smartNumber(gas)];
118
- gasLimit = mulBy1_3(DIGas(gas));
119
- return [4 /*yield*/, curve.updateFeeData()];
120
- case 2:
121
- _b.sent();
122
- return [4 /*yield*/, contract[methodToCall].apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve.options), { gasLimit: gasLimit })], false))];
123
- case 3: return [2 /*return*/, _b.sent()];
124
- }
125
- });
126
- }); };
127
- export var deployStablePlainPoolEstimateGas = function (name, symbol, coins, A, fee, // %
21
+ oracleAddress, methodName, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
22
+ if (name.length > 32)
23
+ throw Error("Max name length = 32");
24
+ if (symbol.length > 10)
25
+ throw Error("Max symbol length = 10");
26
+ if (![2, 3, 4].includes(coins.length))
27
+ throw Error("Invalid number of coins. Must be 2, 3 or 4");
28
+ if (BN(fee).lt(0.04))
29
+ throw Error(`fee must be >= 0.04%. Passed fee = ${fee}`);
30
+ if (BN(fee).gt(1))
31
+ throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
32
+ if (![0, 1, 2, 3].includes(assetType))
33
+ throw Error("Invalid assetType. Must be one of: 0 = USD, 1 = ETH, 2 = BTC, 3 = Other");
34
+ if (curve.chainId !== 1 || coins.length > 2) {
35
+ if (![0, 1, 2, 3].includes(implementationIdx))
36
+ throw Error("Invalid implementationIdx. Must be one 0, 1, 2 or 3");
37
+ }
38
+ else {
39
+ if (![0, 1, 2, 3, 4, 5].includes(implementationIdx))
40
+ throw Error("Invalid implementationIdx. Must be one 0, 1, 2, 3, 4 or 5");
41
+ }
42
+ if (emaTime <= 0)
43
+ throw Error(`emaTime must be > 0. Passed emaTime = ${emaTime}`);
44
+ const _A = parseUnits(A, 0);
45
+ const _fee = parseUnits(fee, 8);
46
+ const _coins = coins.concat(Array(4 - coins.length).fill(curve.constants.ZERO_ADDRESS));
47
+ const useProxy = (curve.chainId === 1 && coins.length === 2 && implementationIdx === 4 && emaTime !== 600) ||
48
+ (curve.chainId === 1 && coins.length === 2 && implementationIdx === 5 && emaTime !== 600) ||
49
+ ((curve.chainId === 42161 || curve.chainId == 10) && coins.length === 2 && implementationIdx === 0 && emaTime !== 600);
50
+ const setOracle = ((curve.chainId === 42161 || curve.chainId == 10) && coins.length === 2 && implementationIdx === 2);
51
+ const contractAddress = (useProxy || setOracle) ? curve.constants.ALIASES.factory_admin : curve.constants.ALIASES.factory;
52
+ const contract = curve.contracts[contractAddress].contract;
53
+ const args = [name, symbol, _coins, _A, _fee, assetType, implementationIdx];
54
+ if (useProxy || setOracle)
55
+ args.push(parseUnits(Math.floor(emaTime / Math.log(2)), 0));
56
+ if (setOracle) {
57
+ const methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
58
+ args.push(methodId, oracleAddress);
59
+ }
60
+ const methodToCall = setOracle ? "deploy_plain_pool_and_set_oracle" : "deploy_plain_pool";
61
+ const gas = yield contract[methodToCall].estimateGas(...args, curve.constantOptions);
62
+ if (estimateGas)
63
+ return smartNumber(gas);
64
+ const gasLimit = mulBy1_3(DIGas(gas));
65
+ yield curve.updateFeeData();
66
+ return yield contract[methodToCall](...args, Object.assign(Object.assign({}, curve.options), { gasLimit }));
67
+ });
68
+ export const deployStablePlainPoolEstimateGas = (name, symbol, coins, A, fee, // %
128
69
  assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
129
- implementationIdx, emaTime, // seconds
130
- oracleAddress, methodName) {
131
- if (emaTime === void 0) { emaTime = 600; }
132
- if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
133
- if (methodName === void 0) { methodName = "0x00000000"; }
134
- return __awaiter(void 0, void 0, void 0, function () {
135
- return __generator(this, function (_a) {
136
- switch (_a.label) {
137
- case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, true)];
138
- case 1: return [2 /*return*/, _a.sent()];
139
- }
140
- });
141
- });
142
- };
143
- export var deployStablePlainPool = function (name, symbol, coins, A, fee, // %
70
+ implementationIdx, emaTime = 600, // seconds
71
+ oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") => __awaiter(void 0, void 0, void 0, function* () {
72
+ return yield _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, true);
73
+ });
74
+ export const deployStablePlainPool = (name, symbol, coins, A, fee, // %
144
75
  assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
145
- implementationIdx, emaTime, // seconds
146
- oracleAddress, methodName) {
147
- if (emaTime === void 0) { emaTime = 600; }
148
- if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
149
- if (methodName === void 0) { methodName = "0x00000000"; }
150
- return __awaiter(void 0, void 0, void 0, function () {
151
- return __generator(this, function (_a) {
152
- switch (_a.label) {
153
- case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, false)];
154
- case 1: return [2 /*return*/, _a.sent()];
155
- }
156
- });
157
- });
158
- };
159
- var _deployStableNgPlainPool = function (name, symbol, coins, A, fee, // %
76
+ implementationIdx, emaTime = 600, // seconds
77
+ oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") => __awaiter(void 0, void 0, void 0, function* () {
78
+ return yield _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, false);
79
+ });
80
+ const _deployStableNgPlainPool = (name, symbol, coins, A, fee, // %
160
81
  offpegFeeMultiplier, assetTypes, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
161
- implementationIdx, emaTime, // seconds
162
- oracleAddresses, methodNames, estimateGas) {
163
- if (emaTime === void 0) { emaTime = 600; }
164
- return __awaiter(void 0, void 0, void 0, function () {
165
- var _oracleAddresses, _methodNames, _A, _fee, _offpegFeeMultiplier, _coins, contractAddress, contract, methodIds, args, gas, gasLimit;
166
- var _a;
167
- return __generator(this, function (_b) {
168
- switch (_b.label) {
169
- case 0:
170
- if (name.length > 32)
171
- throw Error("Max name length = 32");
172
- if (symbol.length > 10)
173
- throw Error("Max symbol length = 10");
174
- if (coins.length < 1)
175
- throw Error("Invalid number of coins. Must be more than 1");
176
- if (coins.length > 9)
177
- throw Error("Invalid number of coins. Must be less than 9");
178
- if (BN(fee).gt(1))
179
- throw Error("fee must be <= 1%. Passed fee = ".concat(fee));
180
- if (oracleAddresses.length === 0) {
181
- _oracleAddresses = new Array(coins.length).fill(curve.constants.ZERO_ADDRESS);
182
- }
183
- else {
184
- _oracleAddresses = oracleAddresses;
185
- }
186
- if (methodNames.length === 0) {
187
- _methodNames = new Array(coins.length).fill("0x00000000");
188
- }
189
- else {
190
- _methodNames = methodNames;
191
- }
192
- if (coins.length !== assetTypes.length)
193
- throw Error("Invalid length of assetTypes. Must be same coins length");
194
- if (coins.length !== _oracleAddresses.length)
195
- throw Error("Invalid length of oracleAddresses. Must be same coins length");
196
- if (coins.length !== _methodNames.length)
197
- throw Error("Invalid length of methodNames. Must be same coins length");
198
- assetTypes.forEach(function (item, index) {
199
- if (![0, 1, 2, 3].includes(item))
200
- throw Error("Invalid assetType. Must be one of: 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626 for assetTypes[".concat(index, "]"));
201
- });
202
- if (![0].includes(implementationIdx))
203
- throw Error("Invalid implementationIdx. Must be 0");
204
- if (emaTime <= 0)
205
- throw Error("emaTime must be > 0. Passed emaTime = ".concat(emaTime));
206
- _A = parseUnits(A, 0);
207
- _fee = parseUnits(fee, 8);
208
- _offpegFeeMultiplier = parseUnits(offpegFeeMultiplier, 10);
209
- _coins = coins;
210
- contractAddress = curve.constants.ALIASES.stable_ng_factory;
211
- contract = curve.contracts[contractAddress].contract;
212
- methodIds = [];
213
- _methodNames.forEach(function (item) {
214
- if (item === '0x00000000' || item === '') {
215
- methodIds.push('0x00000000');
216
- }
217
- else {
218
- methodIds.push(ethers.id(item).substring(0, 10));
219
- }
220
- });
221
- args = [name, symbol, _coins, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetTypes, methodIds, _oracleAddresses];
222
- return [4 /*yield*/, (_a = contract.deploy_plain_pool).estimateGas.apply(_a, __spreadArray(__spreadArray([], args, false), [curve.constantOptions], false))];
223
- case 1:
224
- gas = _b.sent();
225
- if (estimateGas)
226
- return [2 /*return*/, smartNumber(gas)];
227
- gasLimit = mulBy1_3(DIGas(gas));
228
- return [4 /*yield*/, curve.updateFeeData()];
229
- case 2:
230
- _b.sent();
231
- return [4 /*yield*/, contract.deploy_plain_pool.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve.options), { gasLimit: gasLimit })], false))];
232
- case 3: return [2 /*return*/, _b.sent()];
233
- }
234
- });
82
+ implementationIdx, emaTime = 600, // seconds
83
+ oracleAddresses, methodNames, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
84
+ if (name.length > 32)
85
+ throw Error("Max name length = 32");
86
+ if (symbol.length > 10)
87
+ throw Error("Max symbol length = 10");
88
+ if (coins.length < 1)
89
+ throw Error("Invalid number of coins. Must be more than 1");
90
+ if (coins.length > 9)
91
+ throw Error("Invalid number of coins. Must be less than 9");
92
+ if (BN(fee).gt(1))
93
+ throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
94
+ let _oracleAddresses;
95
+ if (oracleAddresses.length === 0) {
96
+ _oracleAddresses = new Array(coins.length).fill(curve.constants.ZERO_ADDRESS);
97
+ }
98
+ else {
99
+ _oracleAddresses = oracleAddresses;
100
+ }
101
+ let _methodNames;
102
+ if (methodNames.length === 0) {
103
+ _methodNames = new Array(coins.length).fill("0x00000000");
104
+ }
105
+ else {
106
+ _methodNames = methodNames;
107
+ }
108
+ if (coins.length !== assetTypes.length)
109
+ throw Error("Invalid length of assetTypes. Must be same coins length");
110
+ if (coins.length !== _oracleAddresses.length)
111
+ throw Error("Invalid length of oracleAddresses. Must be same coins length");
112
+ if (coins.length !== _methodNames.length)
113
+ throw Error("Invalid length of methodNames. Must be same coins length");
114
+ assetTypes.forEach((item, index) => {
115
+ if (![0, 1, 2, 3].includes(item))
116
+ throw Error(`Invalid assetType. Must be one of: 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626 for assetTypes[${index}]`);
117
+ });
118
+ if (![0].includes(implementationIdx))
119
+ throw Error("Invalid implementationIdx. Must be 0");
120
+ if (emaTime <= 0)
121
+ throw Error(`emaTime must be > 0. Passed emaTime = ${emaTime}`);
122
+ const _A = parseUnits(A, 0);
123
+ const _fee = parseUnits(fee, 8);
124
+ const _offpegFeeMultiplier = parseUnits(offpegFeeMultiplier, 10);
125
+ const _coins = coins;
126
+ const contractAddress = curve.constants.ALIASES.stable_ng_factory;
127
+ const contract = curve.contracts[contractAddress].contract;
128
+ const methodIds = [];
129
+ _methodNames.forEach((item) => {
130
+ if (item === '0x00000000' || item === '') {
131
+ methodIds.push('0x00000000');
132
+ }
133
+ else {
134
+ methodIds.push(ethers.id(item).substring(0, 10));
135
+ }
235
136
  });
236
- };
237
- export var deployStableNgPlainPoolEstimateGas = function (name, symbol, coins, A, fee, // %
137
+ const args = [name, symbol, _coins, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetTypes, methodIds, _oracleAddresses];
138
+ const gas = yield contract.deploy_plain_pool.estimateGas(...args, curve.constantOptions);
139
+ if (estimateGas)
140
+ return smartNumber(gas);
141
+ const gasLimit = mulBy1_3(DIGas(gas));
142
+ yield curve.updateFeeData();
143
+ return yield contract.deploy_plain_pool(...args, Object.assign(Object.assign({}, curve.options), { gasLimit }));
144
+ });
145
+ export const deployStableNgPlainPoolEstimateGas = (name, symbol, coins, A, fee, // %
238
146
  offpegFeeMultiplier, assetTypes, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
239
147
  implementationIdx, emaTime, // seconds
240
- oracleAddresses, methodNames) { return __awaiter(void 0, void 0, void 0, function () {
241
- return __generator(this, function (_a) {
242
- switch (_a.label) {
243
- case 0: return [4 /*yield*/, _deployStableNgPlainPool(name, symbol, coins, A, fee, offpegFeeMultiplier, assetTypes, implementationIdx, emaTime, oracleAddresses, methodNames, true)];
244
- case 1: return [2 /*return*/, _a.sent()];
245
- }
246
- });
247
- }); };
248
- export var deployStableNgPlainPool = function (name, symbol, coins, A, fee, // %
148
+ oracleAddresses, methodNames) => __awaiter(void 0, void 0, void 0, function* () {
149
+ return yield _deployStableNgPlainPool(name, symbol, coins, A, fee, offpegFeeMultiplier, assetTypes, implementationIdx, emaTime, oracleAddresses, methodNames, true);
150
+ });
151
+ export const deployStableNgPlainPool = (name, symbol, coins, A, fee, // %
249
152
  offpegFeeMultiplier, assetTypes, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
250
153
  implementationIdx, emaTime, // seconds
251
- oracleAddresses, methodNames) { return __awaiter(void 0, void 0, void 0, function () {
252
- return __generator(this, function (_a) {
253
- switch (_a.label) {
254
- case 0: return [4 /*yield*/, _deployStableNgPlainPool(name, symbol, coins, A, fee, offpegFeeMultiplier, assetTypes, implementationIdx, emaTime, oracleAddresses, methodNames, false)];
255
- case 1: return [2 /*return*/, _a.sent()];
256
- }
257
- });
258
- }); };
259
- export var getDeployedStablePlainPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
260
- var txInfo;
261
- return __generator(this, function (_a) {
262
- switch (_a.label) {
263
- case 0: return [4 /*yield*/, tx.wait()];
264
- case 1:
265
- txInfo = _a.sent();
266
- if (!txInfo)
267
- throw Error("Can't get tx info");
268
- return [2 /*return*/, txInfo.logs[0].address.toLowerCase()];
269
- }
270
- });
271
- }); };
272
- export var _setOracle = function (poolAddress, oracleAddress, methodName, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
273
- var poolContract, methodId, _gas, gasLimit;
274
- return __generator(this, function (_a) {
275
- switch (_a.label) {
276
- case 0:
277
- curve.setContract(poolAddress, Plain2ETHOracleABIABI);
278
- poolContract = curve.contracts[poolAddress].contract;
279
- methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
280
- return [4 /*yield*/, poolContract.set_oracle.estimateGas(methodId, oracleAddress, curve.constantOptions)];
281
- case 1:
282
- _gas = _a.sent();
283
- if (estimateGas)
284
- return [2 /*return*/, Number(_gas)];
285
- gasLimit = mulBy1_3(_gas);
286
- return [4 /*yield*/, curve.updateFeeData()];
287
- case 2:
288
- _a.sent();
289
- return [4 /*yield*/, poolContract.set_oracle(methodId, oracleAddress, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
290
- case 3: return [2 /*return*/, _a.sent()];
291
- }
292
- });
293
- }); };
294
- export var setOracleEstimateGas = function (poolAddress, oracleAddress, methodName) {
295
- if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
296
- if (methodName === void 0) { methodName = "0x00000000"; }
297
- return __awaiter(void 0, void 0, void 0, function () {
298
- return __generator(this, function (_a) {
299
- switch (_a.label) {
300
- case 0: return [4 /*yield*/, _setOracle(poolAddress, oracleAddress, methodName, true)];
301
- case 1: return [2 /*return*/, _a.sent()];
302
- }
303
- });
304
- });
305
- };
306
- export var setOracle = function (poolAddress, oracleAddress, methodName) {
307
- if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
308
- if (methodName === void 0) { methodName = "0x00000000"; }
309
- return __awaiter(void 0, void 0, void 0, function () {
310
- return __generator(this, function (_a) {
311
- switch (_a.label) {
312
- case 0: return [4 /*yield*/, _setOracle(poolAddress, oracleAddress, methodName, false)];
313
- case 1: return [2 /*return*/, _a.sent()];
314
- }
315
- });
316
- });
317
- };
154
+ oracleAddresses, methodNames) => __awaiter(void 0, void 0, void 0, function* () {
155
+ return yield _deployStableNgPlainPool(name, symbol, coins, A, fee, offpegFeeMultiplier, assetTypes, implementationIdx, emaTime, oracleAddresses, methodNames, false);
156
+ });
157
+ export const getDeployedStablePlainPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
158
+ const txInfo = yield tx.wait();
159
+ if (!txInfo)
160
+ throw Error("Can't get tx info");
161
+ return txInfo.logs[0].address.toLowerCase();
162
+ });
163
+ export const _setOracle = (poolAddress, oracleAddress, methodName, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
164
+ curve.setContract(poolAddress, Plain2ETHOracleABIABI);
165
+ const poolContract = curve.contracts[poolAddress].contract;
166
+ const methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
167
+ const _gas = yield poolContract.set_oracle.estimateGas(methodId, oracleAddress, curve.constantOptions);
168
+ if (estimateGas)
169
+ return Number(_gas);
170
+ const gasLimit = mulBy1_3(_gas);
171
+ yield curve.updateFeeData();
172
+ return yield poolContract.set_oracle(methodId, oracleAddress, Object.assign(Object.assign({}, curve.options), { gasLimit }));
173
+ });
174
+ export const setOracleEstimateGas = (poolAddress, oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") => __awaiter(void 0, void 0, void 0, function* () {
175
+ return yield _setOracle(poolAddress, oracleAddress, methodName, true);
176
+ });
177
+ export const setOracle = (poolAddress, oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") => __awaiter(void 0, void 0, void 0, function* () {
178
+ return yield _setOracle(poolAddress, oracleAddress, methodName, false);
179
+ });
318
180
  // ------- STABLE META POOLS -------
319
- var _deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
320
- implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
321
- var _A, _fee, contract, gas, gasLimit;
322
- return __generator(this, function (_a) {
323
- switch (_a.label) {
324
- case 0:
325
- if (name.length > 32)
326
- throw Error("Max name length = 32");
327
- if (symbol.length > 10)
328
- throw Error("Max symbol length = 10");
329
- if (BN(fee).lt(0.04))
330
- throw Error("fee must be >= 0.04%. Passed fee = ".concat(fee));
331
- if (BN(fee).gt(1))
332
- throw Error("fee must be <= 1%. Passed fee = ".concat(fee));
333
- if (![0, 1].includes(implementationIdx))
334
- throw Error("Invalid implementationIdx. Must be one 0 or 1");
335
- _A = parseUnits(A, 0);
336
- _fee = parseUnits(fee, 8);
337
- contract = curve.contracts[curve.constants.ALIASES.factory].contract;
338
- return [4 /*yield*/, contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, implementationIdx, curve.constantOptions)];
339
- case 1:
340
- gas = _a.sent();
341
- if (estimateGas)
342
- return [2 /*return*/, smartNumber(gas)];
343
- gasLimit = mulBy1_3(DIGas(gas));
344
- return [4 /*yield*/, curve.updateFeeData()];
345
- case 2:
346
- _a.sent();
347
- return [4 /*yield*/, contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
348
- case 3: return [2 /*return*/, _a.sent()];
349
- }
350
- });
351
- }); };
352
- export var deployStableMetaPoolEstimateGas = function (basePool, name, symbol, coin, A, fee, // %
353
- implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
354
- return __generator(this, function (_a) {
355
- switch (_a.label) {
356
- case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, true)];
357
- case 1: return [2 /*return*/, _a.sent()];
358
- }
359
- });
360
- }); };
361
- export var deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
362
- implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
363
- return __generator(this, function (_a) {
364
- switch (_a.label) {
365
- case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, false)];
366
- case 1: return [2 /*return*/, _a.sent()];
367
- }
368
- });
369
- }); };
370
- var _deployStableNgMetaPool = function (basePool, name, symbol, coin, A, fee, // %
181
+ const _deployStableMetaPool = (basePool, name, symbol, coin, A, fee, // %
182
+ implementationIdx, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
183
+ if (name.length > 32)
184
+ throw Error("Max name length = 32");
185
+ if (symbol.length > 10)
186
+ throw Error("Max symbol length = 10");
187
+ if (BN(fee).lt(0.04))
188
+ throw Error(`fee must be >= 0.04%. Passed fee = ${fee}`);
189
+ if (BN(fee).gt(1))
190
+ throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
191
+ if (![0, 1].includes(implementationIdx))
192
+ throw Error("Invalid implementationIdx. Must be one 0 or 1");
193
+ const _A = parseUnits(A, 0);
194
+ const _fee = parseUnits(fee, 8);
195
+ const contract = curve.contracts[curve.constants.ALIASES.factory].contract;
196
+ const gas = yield contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, implementationIdx, curve.constantOptions);
197
+ if (estimateGas)
198
+ return smartNumber(gas);
199
+ const gasLimit = mulBy1_3(DIGas(gas));
200
+ yield curve.updateFeeData();
201
+ return yield contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, Object.assign(Object.assign({}, curve.options), { gasLimit }));
202
+ });
203
+ export const deployStableMetaPoolEstimateGas = (basePool, name, symbol, coin, A, fee, // %
204
+ implementationIdx) => __awaiter(void 0, void 0, void 0, function* () {
205
+ return yield _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, true);
206
+ });
207
+ export const deployStableMetaPool = (basePool, name, symbol, coin, A, fee, // %
208
+ implementationIdx) => __awaiter(void 0, void 0, void 0, function* () {
209
+ return yield _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, false);
210
+ });
211
+ const _deployStableNgMetaPool = (basePool, name, symbol, coin, A, fee, // %
371
212
  offpegFeeMultiplier, assetType, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
372
- emaTime, // seconds
373
- implementationIdx, methodName, oracleAddress, estimateGas) {
374
- if (emaTime === void 0) { emaTime = 600; }
375
- if (implementationIdx === void 0) { implementationIdx = 0; }
376
- if (methodName === void 0) { methodName = "0x00000000"; }
377
- if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
378
- return __awaiter(void 0, void 0, void 0, function () {
379
- var _A, _fee, _offpegFeeMultiplier, methodId, contract, gas, gasLimit;
380
- return __generator(this, function (_a) {
381
- switch (_a.label) {
382
- case 0:
383
- if (name.length > 32)
384
- throw Error("Max name length = 32");
385
- if (symbol.length > 10)
386
- throw Error("Max symbol length = 10");
387
- if (BN(fee).gt(1))
388
- throw Error("fee must be <= 1%. Passed fee = ".concat(fee));
389
- if (![0, 1].includes(implementationIdx))
390
- throw Error("Invalid implementationIdx. Must be one 0 or 1");
391
- _A = parseUnits(A, 0);
392
- _fee = parseUnits(fee, 8);
393
- _offpegFeeMultiplier = parseUnits(offpegFeeMultiplier, 10);
394
- methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
395
- contract = curve.contracts[curve.constants.ALIASES.stable_ng_factory].contract;
396
- return [4 /*yield*/, contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetType, methodId, oracleAddress, curve.constantOptions)];
397
- case 1:
398
- gas = _a.sent();
399
- if (estimateGas)
400
- return [2 /*return*/, smartNumber(gas)];
401
- gasLimit = mulBy1_3(DIGas(gas));
402
- return [4 /*yield*/, curve.updateFeeData()];
403
- case 2:
404
- _a.sent();
405
- return [4 /*yield*/, contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetType, methodId, oracleAddress, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
406
- case 3: return [2 /*return*/, _a.sent()];
407
- }
408
- });
409
- });
410
- };
411
- export var deployStableNgMetaPoolEstimateGas = function (basePool, name, symbol, coin, A, fee, // %
213
+ emaTime = 600, // seconds
214
+ implementationIdx = 0, methodName = "0x00000000", oracleAddress = curve.constants.ZERO_ADDRESS, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
215
+ if (name.length > 32)
216
+ throw Error("Max name length = 32");
217
+ if (symbol.length > 10)
218
+ throw Error("Max symbol length = 10");
219
+ if (BN(fee).gt(1))
220
+ throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
221
+ if (![0, 1].includes(implementationIdx))
222
+ throw Error("Invalid implementationIdx. Must be one 0 or 1");
223
+ const _A = parseUnits(A, 0);
224
+ const _fee = parseUnits(fee, 8);
225
+ const _offpegFeeMultiplier = parseUnits(offpegFeeMultiplier, 10);
226
+ const methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
227
+ const contract = curve.contracts[curve.constants.ALIASES.stable_ng_factory].contract;
228
+ const gas = yield contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetType, methodId, oracleAddress, curve.constantOptions);
229
+ if (estimateGas)
230
+ return smartNumber(gas);
231
+ const gasLimit = mulBy1_3(DIGas(gas));
232
+ yield curve.updateFeeData();
233
+ return yield contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetType, methodId, oracleAddress, Object.assign(Object.assign({}, curve.options), { gasLimit }));
234
+ });
235
+ export const deployStableNgMetaPoolEstimateGas = (basePool, name, symbol, coin, A, fee, // %
412
236
  offpegFeeMultiplier, assetType, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
413
237
  emaTime, // seconds
414
- implementationIdx, methodName, oracleAddress) { return __awaiter(void 0, void 0, void 0, function () {
415
- return __generator(this, function (_a) {
416
- switch (_a.label) {
417
- case 0: return [4 /*yield*/, _deployStableNgMetaPool(basePool, name, symbol, coin, A, fee, offpegFeeMultiplier, assetType, emaTime, implementationIdx, methodName, oracleAddress, true)];
418
- case 1: return [2 /*return*/, _a.sent()];
419
- }
420
- });
421
- }); };
422
- export var deployStableNgMetaPool = function (basePool, name, symbol, coin, A, fee, // %
238
+ implementationIdx, methodName, oracleAddress) => __awaiter(void 0, void 0, void 0, function* () {
239
+ return yield _deployStableNgMetaPool(basePool, name, symbol, coin, A, fee, offpegFeeMultiplier, assetType, emaTime, implementationIdx, methodName, oracleAddress, true);
240
+ });
241
+ export const deployStableNgMetaPool = (basePool, name, symbol, coin, A, fee, // %
423
242
  offpegFeeMultiplier, emaTime, // seconds
424
243
  implementationIdx, assetType, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
425
- methodName, oracleAddress) { return __awaiter(void 0, void 0, void 0, function () {
426
- return __generator(this, function (_a) {
427
- switch (_a.label) {
428
- case 0: return [4 /*yield*/, _deployStableNgMetaPool(basePool, name, symbol, coin, A, fee, offpegFeeMultiplier, assetType, emaTime, implementationIdx, methodName, oracleAddress, false)];
429
- case 1: return [2 /*return*/, _a.sent()];
430
- }
431
- });
432
- }); };
433
- export var getDeployedStableMetaPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
434
- var txInfo, i, basePoolId, basePool;
435
- return __generator(this, function (_a) {
436
- switch (_a.label) {
437
- case 0: return [4 /*yield*/, tx.wait()];
438
- case 1:
439
- txInfo = _a.sent();
440
- if (!txInfo)
441
- throw Error("Can't get tx info");
442
- for (i = txInfo.logs.length - 1; i > -1; i--) {
443
- if ("args" in txInfo.logs[i]) {
444
- basePoolId = getPoolIdBySwapAddress(txInfo.logs[i].args[1]);
445
- basePool = getPool(basePoolId);
446
- return [2 /*return*/, txInfo.logs[basePool.underlyingCoins.length].address.toLowerCase()];
447
- }
448
- }
449
- throw Error("Can't get deployed metapool address");
244
+ methodName, oracleAddress) => __awaiter(void 0, void 0, void 0, function* () {
245
+ return yield _deployStableNgMetaPool(basePool, name, symbol, coin, A, fee, offpegFeeMultiplier, assetType, emaTime, implementationIdx, methodName, oracleAddress, false);
246
+ });
247
+ export const getDeployedStableMetaPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
248
+ const txInfo = yield tx.wait();
249
+ if (!txInfo)
250
+ throw Error("Can't get tx info");
251
+ for (let i = txInfo.logs.length - 1; i > -1; i--) {
252
+ if ("args" in txInfo.logs[i]) {
253
+ const basePoolId = getPoolIdBySwapAddress(txInfo.logs[i].args[1]);
254
+ const basePool = getPool(basePoolId);
255
+ return txInfo.logs[basePool.underlyingCoins.length].address.toLowerCase();
450
256
  }
451
- });
452
- }); };
257
+ }
258
+ throw Error("Can't get deployed metapool address");
259
+ });
453
260
  // ------- CRYPTO POOLS -------
454
- var _deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
261
+ const _deployCryptoPool = (name, symbol, coins, A, gamma, midFee, // %
455
262
  outFee, // %
456
263
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
457
- initialPrice, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
458
- var _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, _maHalfTime, _initialPrice, contract, gas, gasLimit;
459
- return __generator(this, function (_a) {
460
- switch (_a.label) {
461
- case 0:
462
- if (name.length > 32)
463
- throw Error("Max name length = 32");
464
- if (symbol.length > 10)
465
- throw Error("Max symbol length = 10");
466
- if (coins.length !== 2)
467
- throw Error("Invalid number of coins. Must be 2");
468
- if (coins[0] === coins[1])
469
- throw Error("Coins must be different");
470
- if (BN(A).lt(4000))
471
- throw Error("A must be >= 4000. Passed A = ".concat(A));
472
- if (BN(A).gt(4 * (Math.pow(10, 9))))
473
- throw Error("A must be <= 4 * 10 ** 9. Passed A = ".concat(A));
474
- if (BN(gamma).lt(1e-8))
475
- throw Error("gamma must be >= 1e-8. Passed gamma = ".concat(gamma));
476
- if (BN(gamma).gt(0.02))
477
- throw Error("gamma must be <= 0.02. Passed gamma = ".concat(gamma));
478
- if (BN(midFee).lt(0.005))
479
- throw Error("midFee must be >= 0.005. Passed midFee = ".concat(midFee));
480
- if (BN(midFee).gt(100))
481
- throw Error("midFee must be <= 100. Passed midFee = ".concat(midFee));
482
- if (BN(outFee).lt(BN(midFee)))
483
- throw Error("outFee must be >= midFee. Passed outFee = ".concat(outFee, " < midFee = ").concat(midFee));
484
- if (BN(outFee).gt(100))
485
- throw Error("outFee must be <= 100. Passed outFee = ".concat(outFee));
486
- if (BN(allowedExtraProfit).lt(0))
487
- throw Error("allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
488
- if (BN(allowedExtraProfit).gt(0.01))
489
- throw Error("allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
490
- if (BN(feeGamma).lt(0))
491
- throw Error("feeGamma must be >= 0. Passed feeGamma = ".concat(feeGamma));
492
- if (BN(feeGamma).gt(1))
493
- throw Error("feeGamma must be <= 1. Passed feeGamma = ".concat(feeGamma));
494
- if (BN(adjustmentStep).lt(0))
495
- throw Error("adjustmentStep must be >= 0. Passed adjustmentStep=".concat(adjustmentStep));
496
- if (BN(adjustmentStep).gt(1))
497
- throw Error("adjustmentStep must be <= 1. Passed adjustmentStep=".concat(adjustmentStep));
498
- if (BN(maHalfTime).lt(0))
499
- throw Error("maHalfTime must be >= 0. Passed maHalfTime=".concat(maHalfTime));
500
- if (BN(maHalfTime).gt(604800))
501
- throw Error("maHalfTime must be <= 604800. Passed maHalfTime=".concat(maHalfTime));
502
- if (BN(initialPrice).lt(1e-12))
503
- throw Error("initialPrice must be >= 1e-12. Passed initialPrice=".concat(initialPrice));
504
- if (BN(initialPrice).gt(1e12))
505
- throw Error("initialPrice must be <= 1e12. Passed initialPrice=".concat(initialPrice));
506
- _A = parseUnits(A, 0);
507
- _gamma = parseUnits(gamma);
508
- _midFee = parseUnits(midFee, 8);
509
- _outFee = parseUnits(outFee, 8);
510
- _allowedExtraProfit = parseUnits(allowedExtraProfit);
511
- _feeGamma = parseUnits(feeGamma);
512
- _adjustmentStep = parseUnits(adjustmentStep);
513
- _maHalfTime = parseUnits(maHalfTime, 0);
514
- _initialPrice = parseUnits(initialPrice);
515
- contract = curve.contracts[curve.constants.ALIASES.crypto_factory].contract;
516
- return [4 /*yield*/, contract.deploy_pool.estimateGas(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, _maHalfTime, _initialPrice, curve.constantOptions)];
517
- case 1:
518
- gas = _a.sent();
519
- if (estimateGas)
520
- return [2 /*return*/, smartNumber(gas)];
521
- gasLimit = mulBy1_3(DIGas(gas));
522
- return [4 /*yield*/, curve.updateFeeData()];
523
- case 2:
524
- _a.sent();
525
- return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
526
- _maHalfTime, _initialPrice, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
527
- case 3: return [2 /*return*/, _a.sent()];
528
- }
529
- });
530
- }); };
531
- export var deployCryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
264
+ initialPrice, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
265
+ if (name.length > 32)
266
+ throw Error("Max name length = 32");
267
+ if (symbol.length > 10)
268
+ throw Error("Max symbol length = 10");
269
+ if (coins.length !== 2)
270
+ throw Error("Invalid number of coins. Must be 2");
271
+ if (coins[0] === coins[1])
272
+ throw Error("Coins must be different");
273
+ if (BN(A).lt(4000))
274
+ throw Error(`A must be >= 4000. Passed A = ${A}`);
275
+ if (BN(A).gt(4 * (Math.pow(10, 9))))
276
+ throw Error(`A must be <= 4 * 10 ** 9. Passed A = ${A}`);
277
+ if (BN(gamma).lt(1e-8))
278
+ throw Error(`gamma must be >= 1e-8. Passed gamma = ${gamma}`);
279
+ if (BN(gamma).gt(0.02))
280
+ throw Error(`gamma must be <= 0.02. Passed gamma = ${gamma}`);
281
+ if (BN(midFee).lt(0.005))
282
+ throw Error(`midFee must be >= 0.005. Passed midFee = ${midFee}`);
283
+ if (BN(midFee).gt(100))
284
+ throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
285
+ if (BN(outFee).lt(BN(midFee)))
286
+ throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
287
+ if (BN(outFee).gt(100))
288
+ throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
289
+ if (BN(allowedExtraProfit).lt(0))
290
+ throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
291
+ if (BN(allowedExtraProfit).gt(0.01))
292
+ throw Error(`allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ${allowedExtraProfit}`);
293
+ if (BN(feeGamma).lt(0))
294
+ throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
295
+ if (BN(feeGamma).gt(1))
296
+ throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
297
+ if (BN(adjustmentStep).lt(0))
298
+ throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
299
+ if (BN(adjustmentStep).gt(1))
300
+ throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
301
+ if (BN(maHalfTime).lt(0))
302
+ throw Error(`maHalfTime must be >= 0. Passed maHalfTime=${maHalfTime}`);
303
+ if (BN(maHalfTime).gt(604800))
304
+ throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${maHalfTime}`);
305
+ if (BN(initialPrice).lt(1e-12))
306
+ throw Error(`initialPrice must be >= 1e-12. Passed initialPrice=${initialPrice}`);
307
+ if (BN(initialPrice).gt(1e12))
308
+ throw Error(`initialPrice must be <= 1e12. Passed initialPrice=${initialPrice}`);
309
+ const _A = parseUnits(A, 0);
310
+ const _gamma = parseUnits(gamma);
311
+ const _midFee = parseUnits(midFee, 8);
312
+ const _outFee = parseUnits(outFee, 8);
313
+ const _allowedExtraProfit = parseUnits(allowedExtraProfit);
314
+ const _feeGamma = parseUnits(feeGamma);
315
+ const _adjustmentStep = parseUnits(adjustmentStep);
316
+ const _maHalfTime = parseUnits(maHalfTime, 0);
317
+ const _initialPrice = parseUnits(initialPrice);
318
+ const contract = curve.contracts[curve.constants.ALIASES.crypto_factory].contract;
319
+ const gas = yield contract.deploy_pool.estimateGas(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, _maHalfTime, _initialPrice, curve.constantOptions);
320
+ if (estimateGas)
321
+ return smartNumber(gas);
322
+ const gasLimit = mulBy1_3(DIGas(gas));
323
+ yield curve.updateFeeData();
324
+ return yield contract.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
325
+ _maHalfTime, _initialPrice, Object.assign(Object.assign({}, curve.options), { gasLimit }));
326
+ });
327
+ export const deployCryptoPoolEstimateGas = (name, symbol, coins, A, gamma, midFee, // %
532
328
  outFee, // %
533
329
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
534
- initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
535
- return __generator(this, function (_a) {
536
- switch (_a.label) {
537
- case 0: return [4 /*yield*/, _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true)];
538
- case 1: return [2 /*return*/, _a.sent()];
539
- }
540
- });
541
- }); };
542
- export var deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
330
+ initialPrice) => __awaiter(void 0, void 0, void 0, function* () {
331
+ return yield _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true);
332
+ });
333
+ export const deployCryptoPool = (name, symbol, coins, A, gamma, midFee, // %
543
334
  outFee, // %
544
335
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
545
- initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
546
- return __generator(this, function (_a) {
547
- switch (_a.label) {
548
- case 0: return [4 /*yield*/, _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false)];
549
- case 1: return [2 /*return*/, _a.sent()];
550
- }
551
- });
552
- }); };
553
- export var getDeployedCryptoPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
554
- var txInfo, lpTokenAddress, contract;
555
- return __generator(this, function (_a) {
556
- switch (_a.label) {
557
- case 0: return [4 /*yield*/, tx.wait()];
558
- case 1:
559
- txInfo = _a.sent();
560
- if (!txInfo)
561
- throw Error("Can't get tx info");
562
- lpTokenAddress = txInfo.logs[0].address;
563
- contract = new Contract(lpTokenAddress, CurveLpTokenV5ABI, curve.provider);
564
- return [4 /*yield*/, contract.minter(curve.constantOptions)];
565
- case 2: return [2 /*return*/, (_a.sent()).toLowerCase()];
566
- }
567
- });
568
- }); };
336
+ initialPrice) => __awaiter(void 0, void 0, void 0, function* () {
337
+ return yield _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false);
338
+ });
339
+ export const getDeployedCryptoPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
340
+ const txInfo = yield tx.wait();
341
+ if (!txInfo)
342
+ throw Error("Can't get tx info");
343
+ const lpTokenAddress = txInfo.logs[0].address;
344
+ const contract = new Contract(lpTokenAddress, CurveLpTokenV5ABI, curve.provider);
345
+ return (yield contract.minter(curve.constantOptions)).toLowerCase();
346
+ });
569
347
  // ------- TWOCRYPTO POOLS -------
570
- var _deployTwocryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
348
+ const _deployTwocryptoPool = (name, symbol, coins, A, gamma, midFee, // %
571
349
  outFee, // %
572
350
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
573
- initialPrice, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
574
- var MIN_GAMMA, MAX_GAMMA, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, _maHalfTime, _initialPrice, contract, gas, gasLimit;
575
- return __generator(this, function (_a) {
576
- switch (_a.label) {
577
- case 0:
578
- if (name.length > 32)
579
- throw Error("Max name length = 32");
580
- if (symbol.length > 10)
581
- throw Error("Max symbol length = 10");
582
- if (coins.length !== 2)
583
- throw Error("Invalid number of coins. Must be 2");
584
- if (coins[0] === coins[1])
585
- throw Error("Coins must be different");
586
- if (BN(A).lt(4000))
587
- throw Error("A must be >= 4000. Passed A = ".concat(A));
588
- if (BN(A).gt(4 * (Math.pow(10, 9))))
589
- throw Error("A must be <= 4 * 10 ** 9. Passed A = ".concat(A));
590
- MIN_GAMMA = BN((Math.pow(10, 10)) / (Math.pow(10, 18)));
591
- MAX_GAMMA = BN(199 * (Math.pow(10, 15)) / (Math.pow(10, 18)));
592
- if (BN(gamma).lt(MIN_GAMMA))
593
- throw Error("gamma must be >= ".concat(MIN_GAMMA, ". Passed gamma = ").concat(gamma));
594
- if (BN(gamma).gt(MAX_GAMMA))
595
- throw Error("gamma must be <= ".concat(MAX_GAMMA, ". Passed gamma = ").concat(gamma));
596
- if (BN(midFee).lt(0.005))
597
- throw Error("midFee must be >= 0.005. Passed midFee = ".concat(midFee));
598
- if (BN(midFee).gt(100))
599
- throw Error("midFee must be <= 100. Passed midFee = ".concat(midFee));
600
- if (BN(outFee).lt(BN(midFee)))
601
- throw Error("outFee must be >= midFee. Passed outFee = ".concat(outFee, " < midFee = ").concat(midFee));
602
- if (BN(outFee).gt(100))
603
- throw Error("outFee must be <= 100. Passed outFee = ".concat(outFee));
604
- if (BN(allowedExtraProfit).lt(0))
605
- throw Error("allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
606
- if (BN(allowedExtraProfit).gt(0.01))
607
- throw Error("allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
608
- if (BN(feeGamma).lt(0))
609
- throw Error("feeGamma must be >= 0. Passed feeGamma = ".concat(feeGamma));
610
- if (BN(feeGamma).gt(1))
611
- throw Error("feeGamma must be <= 1. Passed feeGamma = ".concat(feeGamma));
612
- if (BN(adjustmentStep).lt(0))
613
- throw Error("adjustmentStep must be >= 0. Passed adjustmentStep=".concat(adjustmentStep));
614
- if (BN(adjustmentStep).gt(1))
615
- throw Error("adjustmentStep must be <= 1. Passed adjustmentStep=".concat(adjustmentStep));
616
- if (BN(maHalfTime).lt(0))
617
- throw Error("maHalfTime must be >= 0. Passed maHalfTime=".concat(maHalfTime));
618
- if (BN(maHalfTime).gt(604800))
619
- throw Error("maHalfTime must be <= 604800. Passed maHalfTime=".concat(maHalfTime));
620
- if (BN(initialPrice).lt(1e-12))
621
- throw Error("initialPrice must be >= 1e-12. Passed initialPrice=".concat(initialPrice));
622
- if (BN(initialPrice).gt(1e12))
623
- throw Error("initialPrice must be <= 1e12. Passed initialPrice=".concat(initialPrice));
624
- _A = parseUnits(A, 0);
625
- _gamma = parseUnits(gamma);
626
- _midFee = parseUnits(midFee, 8);
627
- _outFee = parseUnits(outFee, 8);
628
- _allowedExtraProfit = parseUnits(allowedExtraProfit);
629
- _feeGamma = parseUnits(feeGamma);
630
- _adjustmentStep = parseUnits(adjustmentStep);
631
- _maHalfTime = parseUnits(maHalfTime, 0);
632
- _initialPrice = parseUnits(initialPrice);
633
- contract = curve.contracts[curve.constants.ALIASES.twocrypto_factory].contract;
634
- return [4 /*yield*/, contract.deploy_pool.estimateGas(name, symbol, coins, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _maHalfTime, _initialPrice, curve.constantOptions)];
635
- case 1:
636
- gas = _a.sent();
637
- if (estimateGas)
638
- return [2 /*return*/, smartNumber(gas)];
639
- gasLimit = mulBy1_3(DIGas(gas));
640
- return [4 /*yield*/, curve.updateFeeData()];
641
- case 2:
642
- _a.sent();
643
- return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _maHalfTime, _initialPrice, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
644
- case 3: return [2 /*return*/, _a.sent()];
645
- }
646
- });
647
- }); };
648
- export var deployTwocryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
351
+ initialPrice, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
352
+ if (name.length > 32)
353
+ throw Error("Max name length = 32");
354
+ if (symbol.length > 10)
355
+ throw Error("Max symbol length = 10");
356
+ if (coins.length !== 2)
357
+ throw Error("Invalid number of coins. Must be 2");
358
+ if (coins[0] === coins[1])
359
+ throw Error("Coins must be different");
360
+ if (BN(A).lt(4000))
361
+ throw Error(`A must be >= 4000. Passed A = ${A}`);
362
+ if (BN(A).gt(4 * (Math.pow(10, 9))))
363
+ throw Error(`A must be <= 4 * 10 ** 9. Passed A = ${A}`);
364
+ const MIN_GAMMA = BN((Math.pow(10, 10)) / (Math.pow(10, 18)));
365
+ const MAX_GAMMA = BN(199 * (Math.pow(10, 15)) / (Math.pow(10, 18)));
366
+ if (BN(gamma).lt(MIN_GAMMA))
367
+ throw Error(`gamma must be >= ${MIN_GAMMA}. Passed gamma = ${gamma}`);
368
+ if (BN(gamma).gt(MAX_GAMMA))
369
+ throw Error(`gamma must be <= ${MAX_GAMMA}. Passed gamma = ${gamma}`);
370
+ if (BN(midFee).lt(0.005))
371
+ throw Error(`midFee must be >= 0.005. Passed midFee = ${midFee}`);
372
+ if (BN(midFee).gt(100))
373
+ throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
374
+ if (BN(outFee).lt(BN(midFee)))
375
+ throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
376
+ if (BN(outFee).gt(100))
377
+ throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
378
+ if (BN(allowedExtraProfit).lt(0))
379
+ throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
380
+ if (BN(allowedExtraProfit).gt(0.01))
381
+ throw Error(`allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ${allowedExtraProfit}`);
382
+ if (BN(feeGamma).lt(0))
383
+ throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
384
+ if (BN(feeGamma).gt(1))
385
+ throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
386
+ if (BN(adjustmentStep).lt(0))
387
+ throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
388
+ if (BN(adjustmentStep).gt(1))
389
+ throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
390
+ if (BN(maHalfTime).lt(0))
391
+ throw Error(`maHalfTime must be >= 0. Passed maHalfTime=${maHalfTime}`);
392
+ if (BN(maHalfTime).gt(604800))
393
+ throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${maHalfTime}`);
394
+ if (BN(initialPrice).lt(1e-12))
395
+ throw Error(`initialPrice must be >= 1e-12. Passed initialPrice=${initialPrice}`);
396
+ if (BN(initialPrice).gt(1e12))
397
+ throw Error(`initialPrice must be <= 1e12. Passed initialPrice=${initialPrice}`);
398
+ const _A = parseUnits(A, 0);
399
+ const _gamma = parseUnits(gamma);
400
+ const _midFee = parseUnits(midFee, 8);
401
+ const _outFee = parseUnits(outFee, 8);
402
+ const _allowedExtraProfit = parseUnits(allowedExtraProfit);
403
+ const _feeGamma = parseUnits(feeGamma);
404
+ const _adjustmentStep = parseUnits(adjustmentStep);
405
+ const _maHalfTime = parseUnits(maHalfTime, 0);
406
+ const _initialPrice = parseUnits(initialPrice);
407
+ const contract = curve.contracts[curve.constants.ALIASES.twocrypto_factory].contract;
408
+ const gas = yield contract.deploy_pool.estimateGas(name, symbol, coins, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _maHalfTime, _initialPrice, curve.constantOptions);
409
+ if (estimateGas)
410
+ return smartNumber(gas);
411
+ const gasLimit = mulBy1_3(DIGas(gas));
412
+ yield curve.updateFeeData();
413
+ return yield contract.deploy_pool(name, symbol, coins, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _maHalfTime, _initialPrice, Object.assign(Object.assign({}, curve.options), { gasLimit }));
414
+ });
415
+ export const deployTwocryptoPoolEstimateGas = (name, symbol, coins, A, gamma, midFee, // %
649
416
  outFee, // %
650
417
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
651
- initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
652
- return __generator(this, function (_a) {
653
- switch (_a.label) {
654
- case 0: return [4 /*yield*/, _deployTwocryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true)];
655
- case 1: return [2 /*return*/, _a.sent()];
656
- }
657
- });
658
- }); };
659
- export var deployTwocryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
418
+ initialPrice) => __awaiter(void 0, void 0, void 0, function* () {
419
+ return yield _deployTwocryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true);
420
+ });
421
+ export const deployTwocryptoPool = (name, symbol, coins, A, gamma, midFee, // %
660
422
  outFee, // %
661
423
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
662
- initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
663
- return __generator(this, function (_a) {
664
- switch (_a.label) {
665
- case 0: return [4 /*yield*/, _deployTwocryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false)];
666
- case 1: return [2 /*return*/, _a.sent()];
667
- }
668
- });
669
- }); };
670
- export var getDeployedTwocryptoPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
671
- var txInfo, i;
672
- return __generator(this, function (_a) {
673
- switch (_a.label) {
674
- case 0: return [4 /*yield*/, tx.wait()];
675
- case 1:
676
- txInfo = _a.sent();
677
- if (!txInfo)
678
- throw Error("Can't get tx info");
679
- for (i = txInfo.logs.length - 1; i > -1; i--) {
680
- if ("args" in txInfo.logs[i]) {
681
- // @ts-ignore
682
- return [2 /*return*/, txInfo.logs[i].args[0]];
683
- }
684
- }
685
- throw Error("Can't get deployed tricrypto pool address");
424
+ initialPrice) => __awaiter(void 0, void 0, void 0, function* () {
425
+ return yield _deployTwocryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false);
426
+ });
427
+ export const getDeployedTwocryptoPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
428
+ const txInfo = yield tx.wait();
429
+ if (!txInfo)
430
+ throw Error("Can't get tx info");
431
+ for (let i = txInfo.logs.length - 1; i > -1; i--) {
432
+ if ("args" in txInfo.logs[i]) {
433
+ // @ts-ignore
434
+ return txInfo.logs[i].args[0];
686
435
  }
687
- });
688
- }); };
436
+ }
437
+ throw Error("Can't get deployed tricrypto pool address");
438
+ });
689
439
  // ------- TRICRYPTO POOLS -------
690
- var _deployTricryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
440
+ const _deployTricryptoPool = (name, symbol, coins, A, gamma, midFee, // %
691
441
  outFee, // %
692
442
  allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
693
- initialPrices, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
694
- var _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, _emaTime, _initialPrices, contract, gas, gasLimit;
695
- return __generator(this, function (_a) {
696
- switch (_a.label) {
697
- case 0:
698
- if (name.length > 64)
699
- throw Error("Max name length = 64");
700
- if (symbol.length > 32)
701
- throw Error("Max symbol length = 32");
702
- if (coins.length !== 3)
703
- throw Error("Invalid number of coins. Must be 3");
704
- if (coins[0] === coins[1] || coins[1] === coins[2] || coins[0] === coins[2])
705
- throw Error("Coins must be different");
706
- if (BN(A).lt(2700))
707
- throw Error("A must be >= 2700. Passed A = ".concat(A));
708
- if (BN(A).gt(27 * (Math.pow(10, 7))))
709
- throw Error("A must be <= 27 * 10 ** 7. Passed A = ".concat(A));
710
- if (BN(gamma).lt(1e-8))
711
- throw Error("gamma must be >= 1e-8. Passed gamma = ".concat(gamma));
712
- if (BN(gamma).gt(0.05))
713
- throw Error("gamma must be <= 0.05. Passed gamma = ".concat(gamma));
714
- if (BN(midFee).lt(0))
715
- throw Error("midFee must be >= 0. Passed midFee = ".concat(midFee));
716
- if (BN(midFee).gt(100))
717
- throw Error("midFee must be <= 100. Passed midFee = ".concat(midFee));
718
- if (BN(outFee).lt(BN(midFee)))
719
- throw Error("outFee must be >= midFee. Passed outFee = ".concat(outFee, " < midFee = ").concat(midFee));
720
- if (BN(outFee).gt(100))
721
- throw Error("outFee must be <= 100. Passed outFee = ".concat(outFee));
722
- if (BN(allowedExtraProfit).lt(0))
723
- throw Error("allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
724
- if (BN(allowedExtraProfit).gt(1))
725
- throw Error("allowedExtraProfit must be <= 1. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
726
- if (BN(feeGamma).lt(0))
727
- throw Error("feeGamma must be >= 0. Passed feeGamma = ".concat(feeGamma));
728
- if (BN(feeGamma).gt(1))
729
- throw Error("feeGamma must be <= 1. Passed feeGamma = ".concat(feeGamma));
730
- if (BN(adjustmentStep).lt(0))
731
- throw Error("adjustmentStep must be >= 0. Passed adjustmentStep=".concat(adjustmentStep));
732
- if (BN(adjustmentStep).gt(1))
733
- throw Error("adjustmentStep must be <= 1. Passed adjustmentStep=".concat(adjustmentStep));
734
- if (BN(emaTime).lt(60))
735
- throw Error("maHalfTime must be >= 60. Passed maHalfTime=".concat(emaTime));
736
- if (BN(emaTime).gt(604800))
737
- throw Error("maHalfTime must be <= 604800. Passed maHalfTime=".concat(emaTime));
738
- if (initialPrices.length !== 2)
739
- throw Error("Invalid number of initial prices. Must be 2");
740
- if (BN(initialPrices[0]).lt(1e-12))
741
- throw Error("initialPrices[0] must be >= 1e-12. Passed initialPrices[0]=".concat(initialPrices[0]));
742
- if (BN(initialPrices[0]).gt(1e12))
743
- throw Error("initialPrices[0] must be <= 1e12. Passed initialPrices[0]=".concat(initialPrices[0]));
744
- if (BN(initialPrices[1]).lt(1e-12))
745
- throw Error("initialPrices[1] must be >= 1e-12. Passed initialPrices[1]=".concat(initialPrices[1]));
746
- if (BN(initialPrices[1]).gt(1e12))
747
- throw Error("initialPrices[1] must be <= 1e12. Passed initialPrices[1]=".concat(initialPrices[1]));
748
- _A = parseUnits(A, 0);
749
- _gamma = parseUnits(gamma);
750
- _midFee = parseUnits(midFee, 8);
751
- _outFee = parseUnits(outFee, 8);
752
- _allowedExtraProfit = parseUnits(allowedExtraProfit);
753
- _feeGamma = parseUnits(feeGamma);
754
- _adjustmentStep = parseUnits(adjustmentStep);
755
- _emaTime = parseUnits(Math.floor(emaTime / Math.log(2)), 0);
756
- _initialPrices = [parseUnits(initialPrices[0]), parseUnits(initialPrices[1])];
757
- contract = curve.contracts[curve.constants.ALIASES.tricrypto_factory].contract;
758
- return [4 /*yield*/, contract.deploy_pool.estimateGas(name, symbol, coins, curve.constants.ZERO_ADDRESS, tricryptoDeployImplementations[curve.chainId].implementationIdx, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, curve.constantOptions)];
759
- case 1:
760
- gas = _a.sent();
761
- if (estimateGas)
762
- return [2 /*return*/, smartNumber(gas)];
763
- gasLimit = mulBy1_3(DIGas(gas));
764
- return [4 /*yield*/, curve.updateFeeData()];
765
- case 2:
766
- _a.sent();
767
- return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, curve.constants.NATIVE_TOKEN.wrappedAddress, tricryptoDeployImplementations[curve.chainId].implementationIdx, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
768
- case 3: return [2 /*return*/, _a.sent()];
769
- }
770
- });
771
- }); };
772
- export var deployTricryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
443
+ initialPrices, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
444
+ if (name.length > 64)
445
+ throw Error("Max name length = 64");
446
+ if (symbol.length > 32)
447
+ throw Error("Max symbol length = 32");
448
+ if (coins.length !== 3)
449
+ throw Error("Invalid number of coins. Must be 3");
450
+ if (coins[0] === coins[1] || coins[1] === coins[2] || coins[0] === coins[2])
451
+ throw Error("Coins must be different");
452
+ if (BN(A).lt(2700))
453
+ throw Error(`A must be >= 2700. Passed A = ${A}`);
454
+ if (BN(A).gt(27 * (Math.pow(10, 7))))
455
+ throw Error(`A must be <= 27 * 10 ** 7. Passed A = ${A}`);
456
+ if (BN(gamma).lt(1e-8))
457
+ throw Error(`gamma must be >= 1e-8. Passed gamma = ${gamma}`);
458
+ if (BN(gamma).gt(0.05))
459
+ throw Error(`gamma must be <= 0.05. Passed gamma = ${gamma}`);
460
+ if (BN(midFee).lt(0))
461
+ throw Error(`midFee must be >= 0. Passed midFee = ${midFee}`);
462
+ if (BN(midFee).gt(100))
463
+ throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
464
+ if (BN(outFee).lt(BN(midFee)))
465
+ throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
466
+ if (BN(outFee).gt(100))
467
+ throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
468
+ if (BN(allowedExtraProfit).lt(0))
469
+ throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
470
+ if (BN(allowedExtraProfit).gt(1))
471
+ throw Error(`allowedExtraProfit must be <= 1. Passed allowedExtraProfit = ${allowedExtraProfit}`);
472
+ if (BN(feeGamma).lt(0))
473
+ throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
474
+ if (BN(feeGamma).gt(1))
475
+ throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
476
+ if (BN(adjustmentStep).lt(0))
477
+ throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
478
+ if (BN(adjustmentStep).gt(1))
479
+ throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
480
+ if (BN(emaTime).lt(60))
481
+ throw Error(`maHalfTime must be >= 60. Passed maHalfTime=${emaTime}`);
482
+ if (BN(emaTime).gt(604800))
483
+ throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${emaTime}`);
484
+ if (initialPrices.length !== 2)
485
+ throw Error("Invalid number of initial prices. Must be 2");
486
+ if (BN(initialPrices[0]).lt(1e-12))
487
+ throw Error(`initialPrices[0] must be >= 1e-12. Passed initialPrices[0]=${initialPrices[0]}`);
488
+ if (BN(initialPrices[0]).gt(1e12))
489
+ throw Error(`initialPrices[0] must be <= 1e12. Passed initialPrices[0]=${initialPrices[0]}`);
490
+ if (BN(initialPrices[1]).lt(1e-12))
491
+ throw Error(`initialPrices[1] must be >= 1e-12. Passed initialPrices[1]=${initialPrices[1]}`);
492
+ if (BN(initialPrices[1]).gt(1e12))
493
+ throw Error(`initialPrices[1] must be <= 1e12. Passed initialPrices[1]=${initialPrices[1]}`);
494
+ const _A = parseUnits(A, 0);
495
+ const _gamma = parseUnits(gamma);
496
+ const _midFee = parseUnits(midFee, 8);
497
+ const _outFee = parseUnits(outFee, 8);
498
+ const _allowedExtraProfit = parseUnits(allowedExtraProfit);
499
+ const _feeGamma = parseUnits(feeGamma);
500
+ const _adjustmentStep = parseUnits(adjustmentStep);
501
+ const _emaTime = parseUnits(Math.floor(emaTime / Math.log(2)), 0);
502
+ const _initialPrices = [parseUnits(initialPrices[0]), parseUnits(initialPrices[1])];
503
+ const contract = curve.contracts[curve.constants.ALIASES.tricrypto_factory].contract;
504
+ const gas = yield contract.deploy_pool.estimateGas(name, symbol, coins, curve.constants.ZERO_ADDRESS, tricryptoDeployImplementations[curve.chainId].implementationIdx, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, curve.constantOptions);
505
+ if (estimateGas)
506
+ return smartNumber(gas);
507
+ const gasLimit = mulBy1_3(DIGas(gas));
508
+ yield curve.updateFeeData();
509
+ return yield contract.deploy_pool(name, symbol, coins, curve.constants.NATIVE_TOKEN.wrappedAddress, tricryptoDeployImplementations[curve.chainId].implementationIdx, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, Object.assign(Object.assign({}, curve.options), { gasLimit }));
510
+ });
511
+ export const deployTricryptoPoolEstimateGas = (name, symbol, coins, A, gamma, midFee, // %
773
512
  outFee, // %
774
513
  allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
775
- initialPrices) { return __awaiter(void 0, void 0, void 0, function () {
776
- return __generator(this, function (_a) {
777
- switch (_a.label) {
778
- case 0: return [4 /*yield*/, _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, true)];
779
- case 1: return [2 /*return*/, _a.sent()];
780
- }
781
- });
782
- }); };
783
- export var deployTricryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
514
+ initialPrices) => __awaiter(void 0, void 0, void 0, function* () {
515
+ return yield _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, true);
516
+ });
517
+ export const deployTricryptoPool = (name, symbol, coins, A, gamma, midFee, // %
784
518
  outFee, // %
785
519
  allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
786
- initialPrices) { return __awaiter(void 0, void 0, void 0, function () {
787
- return __generator(this, function (_a) {
788
- switch (_a.label) {
789
- case 0: return [4 /*yield*/, _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, false)];
790
- case 1: return [2 /*return*/, _a.sent()];
791
- }
792
- });
793
- }); };
794
- export var getDeployedTricryptoPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
795
- var txInfo, i;
796
- return __generator(this, function (_a) {
797
- switch (_a.label) {
798
- case 0: return [4 /*yield*/, tx.wait()];
799
- case 1:
800
- txInfo = _a.sent();
801
- if (!txInfo)
802
- throw Error("Can't get tx info");
803
- for (i = txInfo.logs.length - 1; i > -1; i--) {
804
- if ("args" in txInfo.logs[i]) {
805
- // @ts-ignore
806
- return [2 /*return*/, txInfo.logs[i].args[0]];
807
- }
808
- }
809
- throw Error("Can't get deployed tricrypto pool address");
810
- }
811
- });
812
- }); };
813
- // ------- GAUGE -------
814
- var _deployGauge = function (pool, factory, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
815
- var contract, gas, gasLimit;
816
- return __generator(this, function (_a) {
817
- switch (_a.label) {
818
- case 0:
819
- if (curve.chainId !== 1)
820
- throw Error("There is no deployGauge method on sidechain network");
821
- contract = curve.contracts[factory].contract;
822
- return [4 /*yield*/, contract.deploy_gauge.estimateGas(pool, curve.constantOptions)];
823
- case 1:
824
- gas = _a.sent();
825
- if (estimateGas)
826
- return [2 /*return*/, smartNumber(gas)];
827
- gasLimit = mulBy1_3(DIGas(gas));
828
- return [4 /*yield*/, curve.updateFeeData()];
829
- case 2:
830
- _a.sent();
831
- return [4 /*yield*/, contract.deploy_gauge(pool, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
832
- case 3: return [2 /*return*/, _a.sent()];
520
+ initialPrices) => __awaiter(void 0, void 0, void 0, function* () {
521
+ return yield _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, false);
522
+ });
523
+ export const getDeployedTricryptoPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
524
+ const txInfo = yield tx.wait();
525
+ if (!txInfo)
526
+ throw Error("Can't get tx info");
527
+ for (let i = txInfo.logs.length - 1; i > -1; i--) {
528
+ if ("args" in txInfo.logs[i]) {
529
+ // @ts-ignore
530
+ return txInfo.logs[i].args[0];
833
531
  }
834
- });
835
- }); };
836
- var _deployGaugeSidechain = function (pool, salt, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
837
- var contract, _salt, gas, gasLimit;
838
- return __generator(this, function (_a) {
839
- switch (_a.label) {
840
- case 0:
841
- if (curve.chainId === 1)
842
- throw Error("There is no deployGaugeSidechain method on ethereum network");
843
- contract = curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
844
- _salt = ethers.encodeBytes32String(salt);
845
- return [4 /*yield*/, contract.deploy_gauge.estimateGas(pool, Typed.bytes32(_salt), curve.signerAddress, curve.constantOptions)];
846
- case 1:
847
- gas = _a.sent();
848
- if (estimateGas)
849
- return [2 /*return*/, smartNumber(gas)];
850
- gasLimit = mulBy1_3(DIGas(gas));
851
- return [4 /*yield*/, curve.updateFeeData()];
852
- case 2:
853
- _a.sent();
854
- return [4 /*yield*/, contract.deploy_gauge(pool, Typed.bytes32(_salt), curve.signerAddress, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
855
- case 3: return [2 /*return*/, _a.sent()];
856
- }
857
- });
858
- }); };
859
- var _deployGaugeMirror = function (chainId, salt, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
860
- var contract, _salt, gas, gasLimit;
861
- return __generator(this, function (_a) {
862
- switch (_a.label) {
863
- case 0:
864
- if (curve.chainId !== 1)
865
- throw Error("There is no deployGaugeMirror method on sidechain network");
866
- contract = chainId === 252 ? curve.contracts[curve.constants.ALIASES.gauge_factory_fraxtal].contract : curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
867
- _salt = ethers.encodeBytes32String(salt);
868
- return [4 /*yield*/, contract.deploy_gauge.estimateGas(chainId, Typed.bytes32(_salt), curve.constantOptions)];
869
- case 1:
870
- gas = _a.sent();
871
- if (estimateGas)
872
- return [2 /*return*/, smartNumber(gas)];
873
- gasLimit = mulBy1_3(DIGas(gas));
874
- return [4 /*yield*/, curve.updateFeeData()];
875
- case 2:
876
- _a.sent();
877
- return [4 /*yield*/, contract.deploy_gauge(chainId, Typed.bytes32(_salt), __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
878
- case 3: return [2 /*return*/, _a.sent()];
879
- }
880
- });
881
- }); };
882
- export var deployGaugeEstimateGas = function (pool, factory) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
883
- switch (_a.label) {
884
- case 0: return [4 /*yield*/, _deployGauge(pool, factory, true)];
885
- case 1: return [2 /*return*/, _a.sent()];
886
- }
887
- }); }); };
888
- export var deployGauge = function (pool, factory) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
889
- switch (_a.label) {
890
- case 0: return [4 /*yield*/, _deployGauge(pool, factory, false)];
891
- case 1: return [2 /*return*/, _a.sent()];
892
532
  }
893
- }); }); };
894
- export var deployGaugeSidechainEstimateGas = function (pool, salt) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
895
- switch (_a.label) {
896
- case 0: return [4 /*yield*/, _deployGaugeSidechain(pool, salt, true)];
897
- case 1: return [2 /*return*/, _a.sent()];
898
- }
899
- }); }); };
900
- export var deployGaugeSidechain = function (pool, salt) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
901
- switch (_a.label) {
902
- case 0: return [4 /*yield*/, _deployGaugeSidechain(pool, salt, false)];
903
- case 1: return [2 /*return*/, _a.sent()];
904
- }
905
- }); }); };
906
- export var deployGaugeMirrorEstimateGas = function (chainId, salt) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
907
- switch (_a.label) {
908
- case 0: return [4 /*yield*/, _deployGaugeMirror(chainId, salt, true)];
909
- case 1: return [2 /*return*/, _a.sent()];
910
- }
911
- }); }); };
912
- export var deployGaugeMirror = function (chainId, salt) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
913
- switch (_a.label) {
914
- case 0: return [4 /*yield*/, _deployGaugeMirror(chainId, salt, false)];
915
- case 1: return [2 /*return*/, _a.sent()];
916
- }
917
- }); }); };
918
- export var getDeployedGaugeAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
919
- var txInfo;
920
- return __generator(this, function (_a) {
921
- switch (_a.label) {
922
- case 0: return [4 /*yield*/, tx.wait()];
923
- case 1:
924
- txInfo = _a.sent();
925
- if (!txInfo)
926
- throw Error("Can't get tx info");
927
- // @ts-ignore
928
- return [2 /*return*/, txInfo.logs[0].args[txInfo.logs[0].args.length - 1].toLowerCase()];
929
- }
930
- });
931
- }); };
932
- export var getDeployedGaugeMirrorAddressByTx = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
933
- var txInfo;
934
- return __generator(this, function (_a) {
935
- switch (_a.label) {
936
- case 0:
937
- if (curve.chainId !== 1)
938
- throw Error("There is no getDeployedGaugeMirrorAddressByTx method on sidechain network");
939
- return [4 /*yield*/, tx.wait()];
940
- case 1:
941
- txInfo = _a.sent();
942
- if (!txInfo)
943
- throw Error("Can't get tx info");
944
- // @ts-ignore
945
- return [2 /*return*/, txInfo.logs[1].args[txInfo.logs[1].args.length - 1].toLowerCase()];
946
- }
947
- });
948
- }); };
949
- export var getDeployedGaugeMirrorAddress = function (chainId) { return __awaiter(void 0, void 0, void 0, function () {
950
- var contract, gaugeCount, currentIndex;
951
- return __generator(this, function (_a) {
952
- switch (_a.label) {
953
- case 0:
954
- if (curve.chainId !== 1)
955
- throw Error("There is no getDeployedGaugeMirrorAddress method on sidechain network");
956
- contract = curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
957
- return [4 /*yield*/, contract.get_gauge_count(chainId)];
958
- case 1:
959
- gaugeCount = _a.sent();
960
- currentIndex = Number(gaugeCount) - 1;
961
- return [4 /*yield*/, contract.get_gauge(chainId, currentIndex)];
962
- case 2: return [2 /*return*/, _a.sent()];
963
- }
964
- });
965
- }); };
533
+ throw Error("Can't get deployed tricrypto pool address");
534
+ });
535
+ // ------- GAUGE -------
536
+ const _deployGauge = (pool, factory, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
537
+ if (curve.chainId !== 1)
538
+ throw Error("There is no deployGauge method on sidechain network");
539
+ const contract = curve.contracts[factory].contract;
540
+ const gas = yield contract.deploy_gauge.estimateGas(pool, curve.constantOptions);
541
+ if (estimateGas)
542
+ return smartNumber(gas);
543
+ const gasLimit = mulBy1_3(DIGas(gas));
544
+ yield curve.updateFeeData();
545
+ return yield contract.deploy_gauge(pool, Object.assign(Object.assign({}, curve.options), { gasLimit }));
546
+ });
547
+ const _deployGaugeSidechain = (pool, salt, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
548
+ if (curve.chainId === 1)
549
+ throw Error("There is no deployGaugeSidechain method on ethereum network");
550
+ const contract = curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
551
+ const _salt = ethers.encodeBytes32String(salt);
552
+ const gas = yield contract.deploy_gauge.estimateGas(pool, Typed.bytes32(_salt), curve.signerAddress, curve.constantOptions);
553
+ if (estimateGas)
554
+ return smartNumber(gas);
555
+ const gasLimit = mulBy1_3(DIGas(gas));
556
+ yield curve.updateFeeData();
557
+ return yield contract.deploy_gauge(pool, Typed.bytes32(_salt), curve.signerAddress, Object.assign(Object.assign({}, curve.options), { gasLimit }));
558
+ });
559
+ const _deployGaugeMirror = (chainId, salt, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
560
+ if (curve.chainId !== 1)
561
+ throw Error("There is no deployGaugeMirror method on sidechain network");
562
+ const contract = chainId === 252 ? curve.contracts[curve.constants.ALIASES.gauge_factory_fraxtal].contract : curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
563
+ const _salt = ethers.encodeBytes32String(salt);
564
+ const gas = yield contract.deploy_gauge.estimateGas(chainId, Typed.bytes32(_salt), curve.constantOptions);
565
+ if (estimateGas)
566
+ return smartNumber(gas);
567
+ const gasLimit = mulBy1_3(DIGas(gas));
568
+ yield curve.updateFeeData();
569
+ return yield contract.deploy_gauge(chainId, Typed.bytes32(_salt), Object.assign(Object.assign({}, curve.options), { gasLimit }));
570
+ });
571
+ export const deployGaugeEstimateGas = (pool, factory) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGauge(pool, factory, true); });
572
+ export const deployGauge = (pool, factory) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGauge(pool, factory, false); });
573
+ export const deployGaugeSidechainEstimateGas = (pool, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeSidechain(pool, salt, true); });
574
+ export const deployGaugeSidechain = (pool, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeSidechain(pool, salt, false); });
575
+ export const deployGaugeMirrorEstimateGas = (chainId, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeMirror(chainId, salt, true); });
576
+ export const deployGaugeMirror = (chainId, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeMirror(chainId, salt, false); });
577
+ export const getDeployedGaugeAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
578
+ const txInfo = yield tx.wait();
579
+ if (!txInfo)
580
+ throw Error("Can't get tx info");
581
+ // @ts-ignore
582
+ return txInfo.logs[0].args[txInfo.logs[0].args.length - 1].toLowerCase();
583
+ });
584
+ export const getDeployedGaugeMirrorAddressByTx = (tx) => __awaiter(void 0, void 0, void 0, function* () {
585
+ if (curve.chainId !== 1)
586
+ throw Error("There is no getDeployedGaugeMirrorAddressByTx method on sidechain network");
587
+ const txInfo = yield tx.wait();
588
+ if (!txInfo)
589
+ throw Error("Can't get tx info");
590
+ // @ts-ignore
591
+ return txInfo.logs[1].args[txInfo.logs[1].args.length - 1].toLowerCase();
592
+ });
593
+ export const getDeployedGaugeMirrorAddress = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
594
+ if (curve.chainId !== 1)
595
+ throw Error("There is no getDeployedGaugeMirrorAddress method on sidechain network");
596
+ const contract = curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
597
+ const gaugeCount = yield contract.get_gauge_count(chainId);
598
+ const currentIndex = Number(gaugeCount) - 1;
599
+ return yield contract.get_gauge(chainId, currentIndex);
600
+ });