@curvefi/api 2.16.2 → 2.17.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.
@@ -0,0 +1,358 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.getDeployedGaugeAddress = exports.deployGauge = exports.deployGaugeEstimateGas = exports.getDeployedCryptoPoolAddress = exports.deployCryptoPool = exports.deployCryptoPoolEstimateGas = exports.getDeployedStableMetaPoolAddress = exports.deployStableMetaPool = exports.deployStableMetaPoolEstimateGas = exports.getDeployedStablePlainPoolAddress = exports.deployStablePlainPool = exports.deployStablePlainPoolEstimateGas = void 0;
54
+ var ethers_1 = require("ethers");
55
+ var curve_1 = require("../curve");
56
+ var utils_1 = require("../utils");
57
+ var curve_lp_token_v5_json_1 = __importDefault(require("../constants/abis/curve_lp_token_v5.json"));
58
+ // ------- STABLE PLAIN POOLS -------
59
+ var _deployStablePlainPool = function (name, symbol, coins, A, fee, // %
60
+ assetType, implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
61
+ var _A, _fee, _coins, contract, gas, gasLimit;
62
+ return __generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0:
65
+ if (name.length > 32)
66
+ throw Error("Max name length = 32");
67
+ if (symbol.length > 10)
68
+ throw Error("Max symbol length = 10");
69
+ if (![2, 3, 4].includes(coins.length))
70
+ throw Error("Invalid number of coins. Must be 2, 3 or 4");
71
+ if (fee < 0.04)
72
+ throw Error("Fee must be >= 0.04%");
73
+ if (fee > 1)
74
+ throw Error("Fee must be <= 1%");
75
+ if (![0, 1, 2, 3].includes(assetType))
76
+ throw Error("Invalid assetType. Must be one of: 0 = USD, 1 = ETH, 2 = BTC, 3 = Other");
77
+ if (![0, 1, 2, 3].includes(implementationIdx))
78
+ throw Error("Invalid implementationIdx. Must be one 0, 1, 2 or 3");
79
+ _A = (0, utils_1.parseUnits)(A, 0);
80
+ _fee = (0, utils_1.parseUnits)(fee, 8);
81
+ _coins = coins.concat(Array(4 - coins.length).fill(ethers_1.ethers.constants.AddressZero));
82
+ contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.factory].contract;
83
+ return [4 /*yield*/, contract.estimateGas.deploy_plain_pool(name, symbol, _coins, _A, _fee, assetType, implementationIdx, curve_1.curve.constantOptions)];
84
+ case 1:
85
+ gas = _a.sent();
86
+ if (estimateGas)
87
+ return [2 /*return*/, gas.toNumber()];
88
+ gasLimit = gas.mul(130).div(100);
89
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
90
+ case 2:
91
+ _a.sent();
92
+ return [4 /*yield*/, contract.deploy_plain_pool(name, symbol, _coins, _A, _fee, assetType, implementationIdx, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
93
+ case 3: return [2 /*return*/, _a.sent()];
94
+ }
95
+ });
96
+ }); };
97
+ var deployStablePlainPoolEstimateGas = function (name, symbol, coins, A, fee, // %
98
+ assetType, implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, true)];
102
+ case 1: return [2 /*return*/, _a.sent()];
103
+ }
104
+ });
105
+ }); };
106
+ exports.deployStablePlainPoolEstimateGas = deployStablePlainPoolEstimateGas;
107
+ var deployStablePlainPool = function (name, symbol, coins, A, fee, // %
108
+ assetType, implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
109
+ return __generator(this, function (_a) {
110
+ switch (_a.label) {
111
+ case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, false)];
112
+ case 1: return [2 /*return*/, _a.sent()];
113
+ }
114
+ });
115
+ }); };
116
+ exports.deployStablePlainPool = deployStablePlainPool;
117
+ var getDeployedStablePlainPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
118
+ var txInfo;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0: return [4 /*yield*/, tx.wait()];
122
+ case 1:
123
+ txInfo = _a.sent();
124
+ return [2 /*return*/, txInfo.logs[0].address.toLowerCase()];
125
+ }
126
+ });
127
+ }); };
128
+ exports.getDeployedStablePlainPoolAddress = getDeployedStablePlainPoolAddress;
129
+ // ------- STABLE META POOLS -------
130
+ var _deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
131
+ implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
132
+ var _A, _fee, contract, gas, gasLimit;
133
+ return __generator(this, function (_a) {
134
+ switch (_a.label) {
135
+ case 0:
136
+ if (name.length > 32)
137
+ throw Error("Max name length = 32");
138
+ if (symbol.length > 10)
139
+ throw Error("Max symbol length = 10");
140
+ if (fee < 0.04)
141
+ throw Error("Fee must be >= 0.04%");
142
+ if (fee > 1)
143
+ throw Error("Fee must be <= 1%");
144
+ if (![0, 1].includes(implementationIdx))
145
+ throw Error("Invalid implementationIdx. Must be one 0 or 1");
146
+ _A = (0, utils_1.parseUnits)(A, 0);
147
+ _fee = (0, utils_1.parseUnits)(fee, 8);
148
+ contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.factory].contract;
149
+ return [4 /*yield*/, contract.estimateGas.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, curve_1.curve.constantOptions)];
150
+ case 1:
151
+ gas = _a.sent();
152
+ if (estimateGas)
153
+ return [2 /*return*/, gas.toNumber()];
154
+ gasLimit = gas.mul(130).div(100);
155
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
156
+ case 2:
157
+ _a.sent();
158
+ return [4 /*yield*/, contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
159
+ case 3: return [2 /*return*/, _a.sent()];
160
+ }
161
+ });
162
+ }); };
163
+ var deployStableMetaPoolEstimateGas = function (basePool, name, symbol, coin, A, fee, // %
164
+ implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, true)];
168
+ case 1: return [2 /*return*/, _a.sent()];
169
+ }
170
+ });
171
+ }); };
172
+ exports.deployStableMetaPoolEstimateGas = deployStableMetaPoolEstimateGas;
173
+ var deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
174
+ implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
175
+ return __generator(this, function (_a) {
176
+ switch (_a.label) {
177
+ case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, false)];
178
+ case 1: return [2 /*return*/, _a.sent()];
179
+ }
180
+ });
181
+ }); };
182
+ exports.deployStableMetaPool = deployStableMetaPool;
183
+ var getDeployedStableMetaPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
184
+ var txInfo;
185
+ return __generator(this, function (_a) {
186
+ switch (_a.label) {
187
+ case 0: return [4 /*yield*/, tx.wait()];
188
+ case 1:
189
+ txInfo = _a.sent();
190
+ return [2 /*return*/, txInfo.logs[txInfo.logs.length - 3].address.toLowerCase()];
191
+ }
192
+ });
193
+ }); };
194
+ exports.getDeployedStableMetaPoolAddress = getDeployedStableMetaPoolAddress;
195
+ // ------- CRYPTO POOLS -------
196
+ var _deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
197
+ outFee, // %
198
+ allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
199
+ initialPrice, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
200
+ var _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, _initialPrice, contract, gas, gasLimit;
201
+ return __generator(this, function (_a) {
202
+ switch (_a.label) {
203
+ case 0:
204
+ if (name.length > 32)
205
+ throw Error("Max name length = 32");
206
+ if (symbol.length > 10)
207
+ throw Error("Max symbol length = 10");
208
+ if (coins.length !== 2)
209
+ throw Error("Invalid number of coins. Must be 2");
210
+ if (coins[1] === coins[2])
211
+ throw Error("Coins must be different");
212
+ if (A < 4000)
213
+ throw Error("A must be >= 4000");
214
+ if (A > 4 * (Math.pow(10, 9)))
215
+ throw Error("A must be <= 4 * 10 ** 9");
216
+ if (gamma < 1e-8)
217
+ throw Error("gamma must be >= 1e-8");
218
+ if (gamma > 0.02)
219
+ throw Error("gamma must be <= 0.02");
220
+ if (midFee < 0.005)
221
+ throw Error("midFee must be >= 0.005");
222
+ if (midFee > 100)
223
+ throw Error("midFee must be <= 100");
224
+ if (outFee < midFee)
225
+ throw Error("outFee must be >= midFee");
226
+ if (outFee > 100)
227
+ throw Error("outFee must be <= 100");
228
+ if (allowedExtraProfit < 0)
229
+ throw Error("allowedExtraProfit must be >= 0");
230
+ if (allowedExtraProfit > 0.01)
231
+ throw Error("allowedExtraProfit must be <= 0.01");
232
+ if (feeGamma < 0)
233
+ throw Error("feeGamma must be >= 0");
234
+ if (feeGamma > 1)
235
+ throw Error("feeGamma must be <= 1");
236
+ if (adjustmentStep < 0)
237
+ throw Error("adjustmentStep must be >= 0");
238
+ if (adjustmentStep > 1)
239
+ throw Error("adjustmentStep must be <= 1");
240
+ if (maHalfTime < 0)
241
+ throw Error("daoFee must be >= 0");
242
+ if (maHalfTime > 604800)
243
+ throw Error("daoFee must be <= 604800");
244
+ if (initialPrice < 1e-12)
245
+ throw Error("initialPrice must be >= 1e-12");
246
+ if (initialPrice > 1e12)
247
+ throw Error("initialPrice must be <= 1e12");
248
+ _gamma = (0, utils_1.parseUnits)(gamma);
249
+ _midFee = (0, utils_1.parseUnits)(midFee, 8);
250
+ _outFee = (0, utils_1.parseUnits)(outFee, 8);
251
+ _allowedExtraProfit = (0, utils_1.parseUnits)(allowedExtraProfit);
252
+ _feeGamma = (0, utils_1.parseUnits)(feeGamma);
253
+ _adjustmentStep = (0, utils_1.parseUnits)(adjustmentStep);
254
+ _initialPrice = (0, utils_1.parseUnits)(initialPrice);
255
+ contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.crypto_factory].contract;
256
+ return [4 /*yield*/, contract.estimateGas.deploy_pool(name, symbol, coins, A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, maHalfTime, _initialPrice, curve_1.curve.constantOptions)];
257
+ case 1:
258
+ gas = _a.sent();
259
+ if (estimateGas)
260
+ return [2 /*return*/, gas.toNumber()];
261
+ gasLimit = gas.mul(130).div(100);
262
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
263
+ case 2:
264
+ _a.sent();
265
+ return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
266
+ maHalfTime, _initialPrice, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
267
+ case 3: return [2 /*return*/, _a.sent()];
268
+ }
269
+ });
270
+ }); };
271
+ var deployCryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
272
+ outFee, // %
273
+ allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
274
+ initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
275
+ return __generator(this, function (_a) {
276
+ switch (_a.label) {
277
+ case 0: return [4 /*yield*/, _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true)];
278
+ case 1: return [2 /*return*/, _a.sent()];
279
+ }
280
+ });
281
+ }); };
282
+ exports.deployCryptoPoolEstimateGas = deployCryptoPoolEstimateGas;
283
+ var deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
284
+ outFee, // %
285
+ allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
286
+ initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
287
+ return __generator(this, function (_a) {
288
+ switch (_a.label) {
289
+ case 0: return [4 /*yield*/, _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false)];
290
+ case 1: return [2 /*return*/, _a.sent()];
291
+ }
292
+ });
293
+ }); };
294
+ exports.deployCryptoPool = deployCryptoPool;
295
+ var getDeployedCryptoPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
296
+ var txInfo, lpTokenAddress, contract;
297
+ return __generator(this, function (_a) {
298
+ switch (_a.label) {
299
+ case 0: return [4 /*yield*/, tx.wait()];
300
+ case 1:
301
+ txInfo = _a.sent();
302
+ lpTokenAddress = txInfo.logs[0].address;
303
+ contract = new ethers_1.Contract(lpTokenAddress, curve_lp_token_v5_json_1.default, curve_1.curve.provider);
304
+ return [4 /*yield*/, contract.minter(curve_1.curve.constantOptions)];
305
+ case 2: return [2 /*return*/, (_a.sent()).toLowerCase()];
306
+ }
307
+ });
308
+ }); };
309
+ exports.getDeployedCryptoPoolAddress = getDeployedCryptoPoolAddress;
310
+ // ------- GAUGE -------
311
+ var _deployGauge = function (pool, isCrypto, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
312
+ var contractAddress, contract, gas, gasLimit;
313
+ return __generator(this, function (_a) {
314
+ switch (_a.label) {
315
+ case 0:
316
+ contractAddress = isCrypto ? curve_1.curve.constants.ALIASES.crypto_factory : curve_1.curve.constants.ALIASES.factory;
317
+ contract = curve_1.curve.contracts[contractAddress].contract;
318
+ return [4 /*yield*/, contract.estimateGas.deploy_gauge(pool, curve_1.curve.constantOptions)];
319
+ case 1:
320
+ gas = _a.sent();
321
+ if (estimateGas)
322
+ return [2 /*return*/, gas.toNumber()];
323
+ gasLimit = gas.mul(130).div(100);
324
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
325
+ case 2:
326
+ _a.sent();
327
+ return [4 /*yield*/, contract.deploy_gauge(pool, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
328
+ case 3: return [2 /*return*/, _a.sent()];
329
+ }
330
+ });
331
+ }); };
332
+ var deployGaugeEstimateGas = function (pool, isCrypto) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
333
+ switch (_a.label) {
334
+ case 0: return [4 /*yield*/, _deployGauge(pool, isCrypto, true)];
335
+ case 1: return [2 /*return*/, _a.sent()];
336
+ }
337
+ }); }); };
338
+ exports.deployGaugeEstimateGas = deployGaugeEstimateGas;
339
+ var deployGauge = function (pool, isCrypto) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
340
+ switch (_a.label) {
341
+ case 0: return [4 /*yield*/, _deployGauge(pool, isCrypto, false)];
342
+ case 1: return [2 /*return*/, _a.sent()];
343
+ }
344
+ }); }); };
345
+ exports.deployGauge = deployGauge;
346
+ var getDeployedGaugeAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
347
+ var txInfo;
348
+ return __generator(this, function (_a) {
349
+ switch (_a.label) {
350
+ case 0: return [4 /*yield*/, tx.wait()];
351
+ case 1:
352
+ txInfo = _a.sent();
353
+ // @ts-ignore
354
+ return [2 /*return*/, txInfo.events[0].args[txInfo.events[0].args.length - 1].toLowerCase()];
355
+ }
356
+ });
357
+ }); };
358
+ exports.getDeployedGaugeAddress = getDeployedGaugeAddress;
@@ -65,7 +65,6 @@ var ethers_1 = require("ethers");
65
65
  var ethcall_1 = require("ethcall");
66
66
  var gauge_factory_json_1 = __importDefault(require("../constants/abis/gauge_factory.json"));
67
67
  var gauge_child_json_1 = __importDefault(require("../constants/abis/gauge_child.json"));
68
- var gauge_rewards_only_json_1 = __importDefault(require("../constants/abis/gauge_rewards_only.json"));
69
68
  var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
70
69
  var factory_crypto_pool_2_json_1 = __importDefault(require("../constants/abis/factory-crypto/factory-crypto-pool-2.json"));
71
70
  var constants_1 = require("./constants");
@@ -109,8 +108,8 @@ function setFactoryGaugeContracts(rawPoolList) {
109
108
  if (pool.gaugeAddress) {
110
109
  var addr = pool.gaugeAddress.toLowerCase();
111
110
  _this.contracts[addr] = {
112
- contract: new ethers_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : _this.chainId === 2222 ? gauge_rewards_only_json_1.default : gauge_child_json_1.default, _this.signer || _this.provider),
113
- multicallContract: new ethcall_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : _this.chainId === 2222 ? gauge_rewards_only_json_1.default : gauge_child_json_1.default),
111
+ contract: new ethers_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default, _this.signer || _this.provider),
112
+ multicallContract: new ethcall_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default),
114
113
  };
115
114
  }
116
115
  });
@@ -130,22 +129,6 @@ function setFactoryCoinsContracts(rawPoolList) {
130
129
  }
131
130
  }
132
131
  }
133
- function setFactoryRewardCoinsContracts(rawPoolList) {
134
- var _a;
135
- for (var _i = 0, rawPoolList_2 = rawPoolList; _i < rawPoolList_2.length; _i++) {
136
- var pool = rawPoolList_2[_i];
137
- for (var _b = 0, _c = (_a = pool.gaugeRewards) !== null && _a !== void 0 ? _a : []; _b < _c.length; _b++) {
138
- var rewardCoin = _c[_b];
139
- var addr = rewardCoin.tokenAddress.toLowerCase();
140
- if (addr in this.contracts)
141
- continue;
142
- this.contracts[addr] = {
143
- contract: new ethers_1.Contract(addr, ERC20_json_1.default, this.signer || this.provider),
144
- multicallContract: new ethcall_1.Contract(addr, ERC20_json_1.default),
145
- };
146
- }
147
- }
148
- }
149
132
  function getFactoryPoolsDataFromApi(isCrypto) {
150
133
  return __awaiter(this, void 0, void 0, function () {
151
134
  var network, factoryType, url, response, rawPoolList, mainAddresses, url_1, response_1, poolGaugeDict, _i, _a, gaugeData, i, FACTORY_POOLS_DATA;
@@ -182,7 +165,6 @@ function getFactoryPoolsDataFromApi(isCrypto) {
182
165
  setCryptoFactoryTokenContracts.call(this, rawPoolList);
183
166
  setFactoryGaugeContracts.call(this, rawPoolList);
184
167
  setFactoryCoinsContracts.call(this, rawPoolList);
185
- setFactoryRewardCoinsContracts.call(this, rawPoolList);
186
168
  common_1.setFactoryZapContracts.call(this, isCrypto);
187
169
  FACTORY_POOLS_DATA = {};
188
170
  rawPoolList.forEach(function (pool) {
@@ -310,7 +292,7 @@ function getFactoryPoolsDataFromApi(isCrypto) {
310
292
  underlying_decimals: coinDecimals,
311
293
  wrapped_decimals: coinDecimals,
312
294
  swap_abi: implementationABIDict[pool.implementationAddress],
313
- gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : _this.chainId === 2222 ? gauge_rewards_only_json_1.default : gauge_child_json_1.default, // TODO remove RewardsOnly for Kava
295
+ gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
314
296
  };
315
297
  }
316
298
  });
@@ -1,2 +1,2 @@
1
1
  import { IDict, IPoolData, ICurve } from "../interfaces";
2
- export declare function getCryptoFactoryPoolData(this: ICurve): Promise<IDict<IPoolData>>;
2
+ export declare function getCryptoFactoryPoolData(this: ICurve, swapAddress?: string): Promise<IDict<IPoolData>>;
@@ -69,6 +69,36 @@ var gauge_child_json_1 = __importDefault(require("../constants/abis/gauge_child.
69
69
  var common_1 = require("./common");
70
70
  var constants_crypto_1 = require("./constants-crypto");
71
71
  var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
72
+ function getRecentlyCreatedCryptoPoolId(swapAddress) {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var factoryContract, poolCount, _a, _b, _c, i, address;
75
+ return __generator(this, function (_e) {
76
+ switch (_e.label) {
77
+ case 0:
78
+ factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
79
+ _a = Number;
80
+ _c = (_b = ethers_1.ethers.utils).formatUnits;
81
+ return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
82
+ case 1:
83
+ poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
84
+ i = 1;
85
+ _e.label = 2;
86
+ case 2:
87
+ if (!(i <= poolCount)) return [3 /*break*/, 5];
88
+ return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
89
+ case 3:
90
+ address = _e.sent();
91
+ if (address.toLowerCase() === swapAddress.toLowerCase())
92
+ return [2 /*return*/, "factory-crypto-".concat(poolCount - i)];
93
+ _e.label = 4;
94
+ case 4:
95
+ i++;
96
+ return [3 /*break*/, 2];
97
+ case 5: throw Error("Unknown pool");
98
+ }
99
+ });
100
+ });
101
+ }
72
102
  function getCryptoFactoryIdsAndSwapAddresses() {
73
103
  return __awaiter(this, void 0, void 0, function () {
74
104
  var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factories, swapAddresses;
@@ -334,40 +364,50 @@ function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDi
334
364
  });
335
365
  });
336
366
  }
337
- function getCryptoFactoryPoolData() {
367
+ function getCryptoFactoryPoolData(swapAddress) {
338
368
  return __awaiter(this, void 0, void 0, function () {
339
- var _a, poolIds, swapAddresses, tokenAddresses, gaugeAddresses, _b, poolSymbols, poolNames, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i, lpTokenBasePoolIdDict, basePoolIdZapDict, basePoolId, allPoolsData, basePoolCoinNames, basePoolCoinAddresses, basePoolDecimals, basePoolZap;
340
- return __generator(this, function (_c) {
341
- switch (_c.label) {
342
- case 0: return [4 /*yield*/, getCryptoFactoryIdsAndSwapAddresses.call(this)];
369
+ var _a, poolIds, swapAddresses, _b, tokenAddresses, gaugeAddresses, _c, poolSymbols, poolNames, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i, lpTokenBasePoolIdDict, basePoolIdZapDict, basePoolId, allPoolsData, basePoolCoinNames, basePoolCoinAddresses, basePoolDecimals, basePoolZap;
370
+ return __generator(this, function (_e) {
371
+ switch (_e.label) {
372
+ case 0:
373
+ if (!swapAddress) return [3 /*break*/, 2];
374
+ return [4 /*yield*/, getRecentlyCreatedCryptoPoolId.call(this, swapAddress)];
343
375
  case 1:
344
- _a = _c.sent(), poolIds = _a[0], swapAddresses = _a[1];
376
+ _b = [[_e.sent()], [swapAddress.toLowerCase()]];
377
+ return [3 /*break*/, 4];
378
+ case 2: return [4 /*yield*/, getCryptoFactoryIdsAndSwapAddresses.call(this)];
379
+ case 3:
380
+ _b = _e.sent();
381
+ _e.label = 4;
382
+ case 4:
383
+ _a = _b, poolIds = _a[0], swapAddresses = _a[1];
384
+ // const [poolIds, swapAddresses] = await getCryptoFactoryIdsAndSwapAddresses.call(this);
345
385
  setCryptoFactorySwapContracts.call(this, swapAddresses);
346
386
  return [4 /*yield*/, getCryptoFactoryTokenAddresses.call(this, swapAddresses)];
347
- case 2:
348
- tokenAddresses = _c.sent();
387
+ case 5:
388
+ tokenAddresses = _e.sent();
349
389
  setCryptoFactoryTokenContracts.call(this, tokenAddresses);
350
390
  return [4 /*yield*/, getCryptoFactoryGaugeAddresses.call(this, swapAddresses)];
351
- case 3:
352
- gaugeAddresses = _c.sent();
391
+ case 6:
392
+ gaugeAddresses = _e.sent();
353
393
  setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
354
394
  return [4 /*yield*/, getCryptoFactorySymbolsAndNames.call(this, tokenAddresses)];
355
- case 4:
356
- _b = _c.sent(), poolSymbols = _b[0], poolNames = _b[1];
395
+ case 7:
396
+ _c = _e.sent(), poolSymbols = _c[0], poolNames = _c[1];
357
397
  return [4 /*yield*/, getCryptoFactoryCoinAddresses.call(this, swapAddresses)];
358
- case 5:
359
- coinAddresses = _c.sent();
398
+ case 8:
399
+ coinAddresses = _e.sent();
360
400
  setCryptoFactoryCoinsContracts.call(this, coinAddresses);
361
401
  return [4 /*yield*/, getCryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses)];
362
- case 6:
363
- underlyingCoinAddresses = _c.sent();
402
+ case 9:
403
+ underlyingCoinAddresses = _e.sent();
364
404
  existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
365
405
  return [4 /*yield*/, getCoinAddressNameDict.call(this, coinAddresses, existingCoinAddressNameDict)];
366
- case 7:
367
- coinAddressNameDict = _c.sent();
406
+ case 10:
407
+ coinAddressNameDict = _e.sent();
368
408
  return [4 /*yield*/, getCoinAddressDecimalsDict.call(this, coinAddresses, this.constants.DECIMALS)];
369
- case 8:
370
- coinAddressDecimalsDict = _c.sent();
409
+ case 11:
410
+ coinAddressDecimalsDict = _e.sent();
371
411
  common_1.setFactoryZapContracts.call(this, true);
372
412
  CRYPTO_FACTORY_POOLS_DATA = {};
373
413
  for (i = 0; i < poolIds.length; i++) {
@@ -1,2 +1,2 @@
1
1
  import { IDict, IPoolData, ICurve } from "../interfaces";
2
- export declare function getFactoryPoolData(this: ICurve): Promise<IDict<IPoolData>>;
2
+ export declare function getFactoryPoolData(this: ICurve, swapAddress?: string): Promise<IDict<IPoolData>>;
@@ -84,6 +84,36 @@ var BLACK_LIST = {
84
84
  42161: [],
85
85
  };
86
86
  var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
87
+ function getRecentlyCreatedPoolId(swapAddress) {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ var factoryContract, poolCount, _a, _b, _c, i, address;
90
+ return __generator(this, function (_e) {
91
+ switch (_e.label) {
92
+ case 0:
93
+ factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
94
+ _a = Number;
95
+ _c = (_b = ethers_1.ethers.utils).formatUnits;
96
+ return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
97
+ case 1:
98
+ poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
99
+ i = 1;
100
+ _e.label = 2;
101
+ case 2:
102
+ if (!(i <= poolCount)) return [3 /*break*/, 5];
103
+ return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
104
+ case 3:
105
+ address = _e.sent();
106
+ if (address.toLowerCase() === swapAddress.toLowerCase())
107
+ return [2 /*return*/, "factory-v2-".concat(poolCount - i)];
108
+ _e.label = 4;
109
+ case 4:
110
+ i++;
111
+ return [3 /*break*/, 2];
112
+ case 5: throw Error("Unknown pool");
113
+ }
114
+ });
115
+ });
116
+ }
87
117
  function getFactoryIdsAndSwapAddresses() {
88
118
  return __awaiter(this, void 0, void 0, function () {
89
119
  var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factories, swapAddresses, blacklist;
@@ -375,44 +405,53 @@ function getFactoryIsMeta(factorySwapAddresses) {
375
405
  });
376
406
  });
377
407
  }
378
- function getFactoryPoolData() {
408
+ function getFactoryPoolData(swapAddress) {
379
409
  return __awaiter(this, void 0, void 0, function () {
380
- var _a, poolIds, swapAddresses, implementations, implementationABIDict, swapABIs, gaugeAddresses, _b, poolSymbols, poolNames, referenceAssets, coinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, isMeta, implementationBasePoolIdDict, basePoolIds, FACTORY_POOLS_DATA, _loop_2, this_1, i;
381
- return __generator(this, function (_c) {
382
- switch (_c.label) {
383
- case 0: return [4 /*yield*/, getFactoryIdsAndSwapAddresses.call(this)];
410
+ var _a, poolIds, swapAddresses, _b, implementations, implementationABIDict, swapABIs, gaugeAddresses, _c, poolSymbols, poolNames, referenceAssets, coinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, isMeta, implementationBasePoolIdDict, basePoolIds, FACTORY_POOLS_DATA, _loop_2, this_1, i;
411
+ return __generator(this, function (_e) {
412
+ switch (_e.label) {
413
+ case 0:
414
+ if (!swapAddress) return [3 /*break*/, 2];
415
+ return [4 /*yield*/, getRecentlyCreatedPoolId.call(this, swapAddress)];
384
416
  case 1:
385
- _a = _c.sent(), poolIds = _a[0], swapAddresses = _a[1];
417
+ _b = [[_e.sent()], [swapAddress.toLowerCase()]];
418
+ return [3 /*break*/, 4];
419
+ case 2: return [4 /*yield*/, getFactoryIdsAndSwapAddresses.call(this)];
420
+ case 3:
421
+ _b = _e.sent();
422
+ _e.label = 4;
423
+ case 4:
424
+ _a = _b, poolIds = _a[0], swapAddresses = _a[1];
386
425
  return [4 /*yield*/, getFactoryImplementations.call(this, swapAddresses)];
387
- case 2:
388
- implementations = _c.sent();
426
+ case 5:
427
+ implementations = _e.sent();
389
428
  implementationABIDict = constants_1.FACTORY_CONSTANTS[this.chainId].implementationABIDict;
390
429
  swapABIs = implementations.map(function (addr) { return implementationABIDict[addr]; });
391
430
  setFactorySwapContracts.call(this, swapAddresses, swapABIs);
392
431
  return [4 /*yield*/, getFactoryGaugeAddresses.call(this, swapAddresses)];
393
- case 3:
394
- gaugeAddresses = _c.sent();
432
+ case 6:
433
+ gaugeAddresses = _e.sent();
395
434
  setFactoryGaugeContracts.call(this, gaugeAddresses);
396
435
  return [4 /*yield*/, getFactorySymbolsAndNames.call(this, swapAddresses)];
397
- case 4:
398
- _b = _c.sent(), poolSymbols = _b[0], poolNames = _b[1];
436
+ case 7:
437
+ _c = _e.sent(), poolSymbols = _c[0], poolNames = _c[1];
399
438
  return [4 /*yield*/, getFactoryReferenceAssets.call(this, swapAddresses)];
400
- case 5:
401
- referenceAssets = _c.sent();
439
+ case 8:
440
+ referenceAssets = _e.sent();
402
441
  return [4 /*yield*/, getFactoryCoinAddresses.call(this, swapAddresses)];
403
- case 6:
404
- coinAddresses = _c.sent();
442
+ case 9:
443
+ coinAddresses = _e.sent();
405
444
  setFactoryCoinsContracts.call(this, coinAddresses);
406
445
  existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
407
446
  return [4 /*yield*/, getCoinAddressNameDict.call(this, coinAddresses, existingCoinAddressNameDict)];
408
- case 7:
409
- coinAddressNameDict = _c.sent();
447
+ case 10:
448
+ coinAddressNameDict = _e.sent();
410
449
  return [4 /*yield*/, getCoinAddressDecimalsDict.call(this, coinAddresses, this.constants.DECIMALS)];
411
- case 8:
412
- coinAddressDecimalsDict = _c.sent();
450
+ case 11:
451
+ coinAddressDecimalsDict = _e.sent();
413
452
  return [4 /*yield*/, getFactoryIsMeta.call(this, swapAddresses)];
414
- case 9:
415
- isMeta = _c.sent();
453
+ case 12:
454
+ isMeta = _e.sent();
416
455
  implementationBasePoolIdDict = constants_1.FACTORY_CONSTANTS[this.chainId].implementationBasePoolIdDict;
417
456
  basePoolIds = implementations.map(function (addr) { return implementationBasePoolIdDict[addr]; });
418
457
  common_1.setFactoryZapContracts.call(this, false);