@curvefi/api 2.62.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 +31 -31
  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 +3 -3
  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 +36 -46
  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 -906
  83. package/package.json +1 -1
package/lib/curve.js CHANGED
@@ -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,44 +7,8 @@ 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
- import { ethers, AbstractProvider, } from "ethers";
58
- import { Provider as MulticallProvider } from "@curvefi/ethcall";
10
+ import { ethers, Contract, AbstractProvider, } from "ethers";
11
+ import { Provider as MulticallProvider, Contract as MulticallContract } from "@curvefi/ethcall";
59
12
  import { getFactoryPoolData } from "./factory/factory.js";
60
13
  import { getFactoryPoolsDataFromApi } from "./factory/factory-api.js";
61
14
  import { getCryptoFactoryPoolData } from "./factory/factory-crypto.js";
@@ -112,37 +65,36 @@ import { COINS_FRAXTAL, cTokensFraxtal, yTokensFraxtal, ycTokensFraxtal, aTokens
112
65
  import { COINS_XLAYER, cTokensXLayer, yTokensXLayer, ycTokensXLayer, aTokensXLayer } from "./constants/coins/xlayer.js";
113
66
  import { COINS_MANTLE, cTokensMantle, yTokensMantle, ycTokensMantle, aTokensMantle } from "./constants/coins/mantle.js";
114
67
  import { lowerCasePoolDataAddresses, extractDecimals, extractGauges } from "./constants/utils.js";
115
- import { _getAllGauges, _getHiddenPools } from "./external-api.js";
68
+ import { _getHiddenPools } from "./external-api.js";
116
69
  import { L2Networks } from "./constants/L2Networks.js";
117
70
  import { getTwocryptoFactoryPoolData } from "./factory/factory-twocrypto.js";
118
- import { memoizedContract, memoizedMulticallContract } from "./utils.js";
119
- var _killGauges = function (poolsData) { return __awaiter(void 0, void 0, void 0, function () {
120
- var gaugeData, isKilled, gaugeStatuses, poolId;
121
- return __generator(this, function (_a) {
122
- switch (_a.label) {
123
- case 0: return [4 /*yield*/, _getAllGauges()];
124
- case 1:
125
- gaugeData = _a.sent();
126
- isKilled = {};
127
- gaugeStatuses = {};
128
- Object.values(gaugeData).forEach(function (d) {
129
- var _a, _b;
130
- isKilled[d.gauge.toLowerCase()] = (_a = d.is_killed) !== null && _a !== void 0 ? _a : false;
131
- gaugeStatuses[d.gauge.toLowerCase()] = (_b = d.gaugeStatus) !== null && _b !== void 0 ? _b : null;
132
- });
133
- for (poolId in poolsData) {
134
- if (isKilled[poolsData[poolId].gauge_address]) {
135
- poolsData[poolId].is_gauge_killed = true;
136
- }
137
- if (gaugeStatuses[poolsData[poolId].gauge_address]) {
138
- poolsData[poolId].gauge_status = gaugeStatuses[poolsData[poolId].gauge_address];
139
- }
140
- }
141
- return [2 /*return*/];
71
+ export const memoizedContract = () => {
72
+ const cache = {};
73
+ return (address, abi, provider) => {
74
+ if (address in cache) {
75
+ return cache[address];
142
76
  }
143
- });
144
- }); };
145
- export var NATIVE_TOKENS = {
77
+ else {
78
+ const result = new Contract(address, abi, provider);
79
+ cache[address] = result;
80
+ return result;
81
+ }
82
+ };
83
+ };
84
+ export const memoizedMulticallContract = () => {
85
+ const cache = {};
86
+ return (address, abi) => {
87
+ if (address in cache) {
88
+ return cache[address];
89
+ }
90
+ else {
91
+ const result = new MulticallContract(address, abi);
92
+ cache[address] = result;
93
+ return result;
94
+ }
95
+ };
96
+ };
97
+ export const NATIVE_TOKENS = {
146
98
  1: {
147
99
  symbol: 'ETH',
148
100
  wrappedSymbol: 'WETH',
@@ -246,7 +198,7 @@ export var NATIVE_TOKENS = {
246
198
  wrappedAddress: '0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB'.toLowerCase(),
247
199
  },
248
200
  };
249
- export var NETWORK_CONSTANTS = {
201
+ export const NETWORK_CONSTANTS = {
250
202
  1: {
251
203
  NAME: 'ethereum',
252
204
  ALIASES: ALIASES_ETHEREUM,
@@ -419,472 +371,216 @@ export var NETWORK_CONSTANTS = {
419
371
  aTokens: aTokensAurora,
420
372
  },
421
373
  };
422
- var OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools
423
- var Curve = /** @class */ (function () {
424
- function Curve() {
425
- var _this = this;
374
+ const OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools
375
+ class Curve {
376
+ constructor() {
426
377
  this.initContract = memoizedContract();
427
378
  this.initMulticallContract = memoizedMulticallContract();
428
- this.fetchFactoryPools = function (useApi) {
429
- if (useApi === void 0) { useApi = true; }
430
- return __awaiter(_this, void 0, void 0, function () {
431
- var _a, _b, _c, _d, _e, _f, _g;
432
- return __generator(this, function (_h) {
433
- switch (_h.label) {
434
- case 0:
435
- if ([196, 252, 5000, 1313161554].includes(this.chainId))
436
- return [2 /*return*/];
437
- if (!useApi) return [3 /*break*/, 2];
438
- _a = this.constants;
439
- _b = lowerCasePoolDataAddresses;
440
- return [4 /*yield*/, getFactoryPoolsDataFromApi.call(this, "factory")];
441
- case 1:
442
- _a.FACTORY_POOLS_DATA = _b.apply(void 0, [_h.sent()]);
443
- return [3 /*break*/, 4];
444
- case 2:
445
- _c = this.constants;
446
- _d = lowerCasePoolDataAddresses;
447
- return [4 /*yield*/, getFactoryPoolData.call(this)];
448
- case 3:
449
- _c.FACTORY_POOLS_DATA = _d.apply(void 0, [_h.sent()]);
450
- _h.label = 4;
451
- case 4:
452
- _e = this.constants;
453
- return [4 /*yield*/, this._filterHiddenPools(this.constants.FACTORY_POOLS_DATA)];
454
- case 5:
455
- _e.FACTORY_POOLS_DATA = _h.sent();
456
- this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
457
- _f = this.constants.FACTORY_GAUGE_IMPLEMENTATIONS;
458
- _g = "factory";
459
- return [4 /*yield*/, this.contracts[this.constants.ALIASES.factory].contract.gauge_implementation(this.constantOptions)];
460
- case 6:
461
- _f[_g] = _h.sent();
462
- return [2 /*return*/];
463
- }
464
- });
465
- });
466
- };
467
- this.fetchCrvusdFactoryPools = function (useApi) {
468
- if (useApi === void 0) { useApi = true; }
469
- return __awaiter(_this, void 0, void 0, function () {
470
- var _a, _b, _c, _d, _e;
471
- return __generator(this, function (_f) {
472
- switch (_f.label) {
473
- case 0:
474
- if (this.chainId != 1)
475
- return [2 /*return*/];
476
- if (!useApi) return [3 /*break*/, 2];
477
- _a = this.constants;
478
- _b = lowerCasePoolDataAddresses;
479
- return [4 /*yield*/, getFactoryPoolsDataFromApi.call(this, "factory-crvusd")];
480
- case 1:
481
- _a.CRVUSD_FACTORY_POOLS_DATA = _b.apply(void 0, [_f.sent()]);
482
- return [3 /*break*/, 4];
483
- case 2:
484
- _c = this.constants;
485
- _d = lowerCasePoolDataAddresses;
486
- return [4 /*yield*/, getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.crvusd_factory)];
487
- case 3:
488
- _c.CRVUSD_FACTORY_POOLS_DATA = _d.apply(void 0, [_f.sent()]);
489
- _f.label = 4;
490
- case 4:
491
- _e = this.constants;
492
- return [4 /*yield*/, this._filterHiddenPools(this.constants.CRVUSD_FACTORY_POOLS_DATA)];
493
- case 5:
494
- _e.CRVUSD_FACTORY_POOLS_DATA = _f.sent();
495
- this._updateDecimalsAndGauges(this.constants.CRVUSD_FACTORY_POOLS_DATA);
496
- return [2 /*return*/];
497
- }
498
- });
499
- });
500
- };
501
- this.fetchEywaFactoryPools = function (useApi) {
502
- if (useApi === void 0) { useApi = true; }
503
- return __awaiter(_this, void 0, void 0, function () {
504
- var _a, _b, _c, _d, _e;
505
- return __generator(this, function (_f) {
506
- switch (_f.label) {
507
- case 0:
508
- if (this.chainId != 250)
509
- return [2 /*return*/];
510
- if (!useApi) return [3 /*break*/, 2];
511
- _a = this.constants;
512
- _b = lowerCasePoolDataAddresses;
513
- return [4 /*yield*/, getFactoryPoolsDataFromApi.call(this, "factory-eywa")];
514
- case 1:
515
- _a.EYWA_FACTORY_POOLS_DATA = _b.apply(void 0, [_f.sent()]);
516
- return [3 /*break*/, 4];
517
- case 2:
518
- _c = this.constants;
519
- _d = lowerCasePoolDataAddresses;
520
- return [4 /*yield*/, getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.eywa_factory)];
521
- case 3:
522
- _c.EYWA_FACTORY_POOLS_DATA = _d.apply(void 0, [_f.sent()]);
523
- _f.label = 4;
524
- case 4:
525
- _e = this.constants;
526
- return [4 /*yield*/, this._filterHiddenPools(this.constants.EYWA_FACTORY_POOLS_DATA)];
527
- case 5:
528
- _e.EYWA_FACTORY_POOLS_DATA = _f.sent();
529
- this._updateDecimalsAndGauges(this.constants.EYWA_FACTORY_POOLS_DATA);
530
- return [2 /*return*/];
531
- }
532
- });
533
- });
534
- };
535
- this.fetchCryptoFactoryPools = function (useApi) {
536
- if (useApi === void 0) { useApi = true; }
537
- return __awaiter(_this, void 0, void 0, function () {
538
- var _a, _b, _c, _d, _e, _f, _g;
539
- return __generator(this, function (_h) {
540
- switch (_h.label) {
541
- case 0:
542
- if (![1, 56, 137, 250, 5000, 8453].includes(this.chainId))
543
- return [2 /*return*/];
544
- if (!useApi) return [3 /*break*/, 2];
545
- _a = this.constants;
546
- _b = lowerCasePoolDataAddresses;
547
- return [4 /*yield*/, getFactoryPoolsDataFromApi.call(this, "factory-crypto")];
548
- case 1:
549
- _a.CRYPTO_FACTORY_POOLS_DATA = _b.apply(void 0, [_h.sent()]);
550
- return [3 /*break*/, 4];
551
- case 2:
552
- _c = this.constants;
553
- _d = lowerCasePoolDataAddresses;
554
- return [4 /*yield*/, getCryptoFactoryPoolData.call(this)];
555
- case 3:
556
- _c.CRYPTO_FACTORY_POOLS_DATA = _d.apply(void 0, [_h.sent()]);
557
- _h.label = 4;
558
- case 4:
559
- _e = this.constants;
560
- return [4 /*yield*/, this._filterHiddenPools(this.constants.CRYPTO_FACTORY_POOLS_DATA)];
561
- case 5:
562
- _e.CRYPTO_FACTORY_POOLS_DATA = _h.sent();
563
- this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
564
- _f = this.constants.FACTORY_GAUGE_IMPLEMENTATIONS;
565
- _g = "factory-crypto";
566
- return [4 /*yield*/, this.contracts[this.constants.ALIASES.crypto_factory].contract.gauge_implementation(this.constantOptions)];
567
- case 6:
568
- _f[_g] = _h.sent();
569
- return [2 /*return*/];
570
- }
571
- });
572
- });
573
- };
574
- this.fetchTworyptoFactoryPools = function (useApi) {
575
- if (useApi === void 0) { useApi = true; }
576
- return __awaiter(_this, void 0, void 0, function () {
577
- var _a, _b, _c, _d, _e, _f, _g;
578
- return __generator(this, function (_h) {
579
- switch (_h.label) {
580
- case 0:
581
- if ([324, 1284].includes(this.chainId))
582
- return [2 /*return*/];
583
- if (!useApi) return [3 /*break*/, 2];
584
- _a = this.constants;
585
- _b = lowerCasePoolDataAddresses;
586
- return [4 /*yield*/, getFactoryPoolsDataFromApi.call(this, "factory-twocrypto")];
587
- case 1:
588
- _a.TWOCRYPTO_FACTORY_POOLS_DATA = _b.apply(void 0, [_h.sent()]);
589
- return [3 /*break*/, 4];
590
- case 2:
591
- _c = this.constants;
592
- _d = lowerCasePoolDataAddresses;
593
- return [4 /*yield*/, getTwocryptoFactoryPoolData.call(this)];
594
- case 3:
595
- _c.TWOCRYPTO_FACTORY_POOLS_DATA = _d.apply(void 0, [_h.sent()]);
596
- _h.label = 4;
597
- case 4:
598
- _e = this.constants;
599
- return [4 /*yield*/, this._filterHiddenPools(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA)];
600
- case 5:
601
- _e.TWOCRYPTO_FACTORY_POOLS_DATA = _h.sent();
602
- this._updateDecimalsAndGauges(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
603
- _f = this.constants.FACTORY_GAUGE_IMPLEMENTATIONS;
604
- _g = "factory-twocrypto";
605
- return [4 /*yield*/, this.contracts[this.constants.ALIASES.twocrypto_factory].contract.gauge_implementation(this.constantOptions)];
606
- case 6:
607
- _f[_g] = _h.sent();
608
- return [2 /*return*/];
609
- }
610
- });
611
- });
612
- };
613
- this.fetchTricryptoFactoryPools = function (useApi) {
614
- if (useApi === void 0) { useApi = true; }
615
- return __awaiter(_this, void 0, void 0, function () {
616
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
617
- return __generator(this, function (_k) {
618
- switch (_k.label) {
619
- case 0:
620
- if ([324, 1284].includes(this.chainId))
621
- return [2 /*return*/];
622
- if (!useApi) return [3 /*break*/, 2];
623
- _a = this.constants;
624
- _b = lowerCasePoolDataAddresses;
625
- return [4 /*yield*/, getFactoryPoolsDataFromApi.call(this, "factory-tricrypto")];
626
- case 1:
627
- _a.TRICRYPTO_FACTORY_POOLS_DATA = _b.apply(void 0, [_k.sent()]);
628
- return [3 /*break*/, 4];
629
- case 2:
630
- _c = this.constants;
631
- _d = lowerCasePoolDataAddresses;
632
- return [4 /*yield*/, getTricryptoFactoryPoolData.call(this)];
633
- case 3:
634
- _c.TRICRYPTO_FACTORY_POOLS_DATA = _d.apply(void 0, [_k.sent()]);
635
- _k.label = 4;
636
- case 4:
637
- _e = this.constants;
638
- return [4 /*yield*/, this._filterHiddenPools(this.constants.TRICRYPTO_FACTORY_POOLS_DATA)];
639
- case 5:
640
- _e.TRICRYPTO_FACTORY_POOLS_DATA = _k.sent();
641
- this._updateDecimalsAndGauges(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
642
- if (!(this.chainId === 1)) return [3 /*break*/, 7];
643
- _f = this.constants.FACTORY_GAUGE_IMPLEMENTATIONS;
644
- _g = "factory-tricrypto";
645
- return [4 /*yield*/, this.contracts[this.constants.ALIASES.tricrypto_factory].contract.gauge_implementation(this.constantOptions)];
646
- case 6:
647
- _f[_g] =
648
- _k.sent();
649
- return [3 /*break*/, 9];
650
- case 7:
651
- _h = this.constants.FACTORY_GAUGE_IMPLEMENTATIONS;
652
- _j = "factory-tricrypto";
653
- return [4 /*yield*/, this.contracts[this.constants.ALIASES.gauge_factory].contract.get_implementation(this.constantOptions)];
654
- case 8:
655
- _h[_j] =
656
- _k.sent();
657
- _k.label = 9;
658
- case 9: return [2 /*return*/];
659
- }
660
- });
661
- });
662
- };
663
- this.fetchStableNgFactoryPools = function (useApi) {
664
- if (useApi === void 0) { useApi = true; }
665
- return __awaiter(_this, void 0, void 0, function () {
666
- var _a, _b, _c, _d, _e;
667
- return __generator(this, function (_f) {
668
- switch (_f.label) {
669
- case 0:
670
- if (this.chainId === 1313161554)
671
- return [2 /*return*/];
672
- if (!useApi) return [3 /*break*/, 2];
673
- _a = this.constants;
674
- _b = lowerCasePoolDataAddresses;
675
- return [4 /*yield*/, getFactoryPoolsDataFromApi.call(this, "factory-stable-ng")];
676
- case 1:
677
- _a.STABLE_NG_FACTORY_POOLS_DATA = _b.apply(void 0, [_f.sent()]);
678
- return [3 /*break*/, 4];
679
- case 2:
680
- _c = this.constants;
681
- _d = lowerCasePoolDataAddresses;
682
- return [4 /*yield*/, getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.stable_ng_factory)];
683
- case 3:
684
- _c.STABLE_NG_FACTORY_POOLS_DATA = _d.apply(void 0, [_f.sent()]);
685
- _f.label = 4;
686
- case 4:
687
- _e = this.constants;
688
- return [4 /*yield*/, this._filterHiddenPools(this.constants.STABLE_NG_FACTORY_POOLS_DATA)];
689
- case 5:
690
- _e.STABLE_NG_FACTORY_POOLS_DATA = _f.sent();
691
- this._updateDecimalsAndGauges(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
692
- return [2 /*return*/];
693
- }
694
- });
695
- });
696
- };
697
- this.fetchNewFactoryPools = function () { return __awaiter(_this, void 0, void 0, function () {
698
- var currentPoolIds, lastPoolIdx, poolData, _a;
699
- return __generator(this, function (_b) {
700
- switch (_b.label) {
701
- case 0:
702
- if ([196, 252, 1313161554].includes(this.chainId))
703
- return [2 /*return*/, []];
704
- currentPoolIds = Object.keys(this.constants.FACTORY_POOLS_DATA);
705
- lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
706
- _a = lowerCasePoolDataAddresses;
707
- return [4 /*yield*/, getFactoryPoolData.call(this, lastPoolIdx + 1)];
708
- case 1:
709
- poolData = _a.apply(void 0, [_b.sent()]);
710
- this.constants.FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.FACTORY_POOLS_DATA), poolData);
711
- this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
712
- return [2 /*return*/, Object.keys(poolData)];
713
- }
714
- });
715
- }); };
716
- this.fetchNewStableNgFactoryPools = function () { return __awaiter(_this, void 0, void 0, function () {
717
- var currentPoolIds, lastPoolIdx, poolData, _a;
718
- return __generator(this, function (_b) {
719
- switch (_b.label) {
720
- case 0:
721
- currentPoolIds = Object.keys(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
722
- lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[3]);
723
- _a = lowerCasePoolDataAddresses;
724
- return [4 /*yield*/, getFactoryPoolData.call(this, lastPoolIdx + 1, undefined, this.constants.ALIASES.stable_ng_factory)];
725
- case 1:
726
- poolData = _a.apply(void 0, [_b.sent()]);
727
- this.constants.STABLE_NG_FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.STABLE_NG_FACTORY_POOLS_DATA), poolData);
728
- this._updateDecimalsAndGauges(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
729
- return [2 /*return*/, Object.keys(poolData)];
730
- }
731
- });
732
- }); };
733
- this.fetchNewCryptoFactoryPools = function () { return __awaiter(_this, void 0, void 0, function () {
734
- var currentPoolIds, lastPoolIdx, poolData, _a;
735
- return __generator(this, function (_b) {
736
- switch (_b.label) {
737
- case 0:
738
- if (![1, 56, 137, 250, 8453].includes(this.chainId))
739
- return [2 /*return*/, []];
740
- currentPoolIds = Object.keys(this.constants.CRYPTO_FACTORY_POOLS_DATA);
741
- lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
742
- _a = lowerCasePoolDataAddresses;
743
- return [4 /*yield*/, getCryptoFactoryPoolData.call(this, lastPoolIdx + 1)];
744
- case 1:
745
- poolData = _a.apply(void 0, [_b.sent()]);
746
- this.constants.CRYPTO_FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.CRYPTO_FACTORY_POOLS_DATA), poolData);
747
- this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
748
- return [2 /*return*/, Object.keys(poolData)];
749
- }
750
- });
751
- }); };
752
- this.fetchNewTwocryptoFactoryPools = function () { return __awaiter(_this, void 0, void 0, function () {
753
- var currentPoolIds, lastPoolIdx, poolData, _a;
754
- return __generator(this, function (_b) {
755
- switch (_b.label) {
756
- case 0:
757
- if ([324, 1284].includes(this.chainId))
758
- return [2 /*return*/, []];
759
- currentPoolIds = Object.keys(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
760
- lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
761
- _a = lowerCasePoolDataAddresses;
762
- return [4 /*yield*/, getTwocryptoFactoryPoolData.call(this, lastPoolIdx + 1)];
763
- case 1:
764
- poolData = _a.apply(void 0, [_b.sent()]);
765
- this.constants.TWOCRYPTO_FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.TWOCRYPTO_FACTORY_POOLS_DATA), poolData);
766
- this._updateDecimalsAndGauges(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
767
- return [2 /*return*/, Object.keys(poolData)];
768
- }
769
- });
770
- }); };
771
- this.fetchNewTricryptoFactoryPools = function () { return __awaiter(_this, void 0, void 0, function () {
772
- var currentPoolIds, lastPoolIdx, poolData, _a;
773
- return __generator(this, function (_b) {
774
- switch (_b.label) {
775
- case 0:
776
- if ([324, 1284].includes(this.chainId))
777
- return [2 /*return*/, []];
778
- currentPoolIds = Object.keys(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
779
- lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
780
- _a = lowerCasePoolDataAddresses;
781
- return [4 /*yield*/, getTricryptoFactoryPoolData.call(this, lastPoolIdx + 1)];
782
- case 1:
783
- poolData = _a.apply(void 0, [_b.sent()]);
784
- this.constants.TRICRYPTO_FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.TRICRYPTO_FACTORY_POOLS_DATA), poolData);
785
- this._updateDecimalsAndGauges(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
786
- return [2 /*return*/, Object.keys(poolData)];
787
- }
788
- });
789
- }); };
790
- this.fetchRecentlyDeployedFactoryPool = function (poolAddress) { return __awaiter(_this, void 0, void 0, function () {
791
- var poolData, _a;
792
- return __generator(this, function (_b) {
793
- switch (_b.label) {
794
- case 0:
795
- if ([196, 252, 1313161554].includes(this.chainId))
796
- return [2 /*return*/, ''];
797
- _a = lowerCasePoolDataAddresses;
798
- return [4 /*yield*/, getFactoryPoolData.call(this, 0, poolAddress)];
799
- case 1:
800
- poolData = _a.apply(void 0, [_b.sent()]);
801
- this.constants.FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.FACTORY_POOLS_DATA), poolData);
802
- this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
803
- return [2 /*return*/, Object.keys(poolData)[0]]; // id
804
- }
805
- });
806
- }); };
807
- this.fetchRecentlyDeployedStableNgFactoryPool = function (poolAddress) { return __awaiter(_this, void 0, void 0, function () {
808
- var poolData, _a;
809
- return __generator(this, function (_b) {
810
- switch (_b.label) {
811
- case 0:
812
- if (this.chainId === 1313161554)
813
- return [2 /*return*/, ''];
814
- _a = lowerCasePoolDataAddresses;
815
- return [4 /*yield*/, getFactoryPoolData.call(this, 0, poolAddress, this.constants.ALIASES.stable_ng_factory)];
816
- case 1:
817
- poolData = _a.apply(void 0, [_b.sent()]);
818
- this.constants.STABLE_NG_FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.STABLE_NG_FACTORY_POOLS_DATA), poolData);
819
- this._updateDecimalsAndGauges(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
820
- return [2 /*return*/, Object.keys(poolData)[0]]; // id
821
- }
822
- });
823
- }); };
824
- this.fetchRecentlyDeployedCryptoFactoryPool = function (poolAddress) { return __awaiter(_this, void 0, void 0, function () {
825
- var poolData, _a;
826
- return __generator(this, function (_b) {
827
- switch (_b.label) {
828
- case 0:
829
- if (![1, 56, 137, 250, 8453].includes(this.chainId))
830
- return [2 /*return*/, ''];
831
- _a = lowerCasePoolDataAddresses;
832
- return [4 /*yield*/, getCryptoFactoryPoolData.call(this, 0, poolAddress)];
833
- case 1:
834
- poolData = _a.apply(void 0, [_b.sent()]);
835
- this.constants.CRYPTO_FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.CRYPTO_FACTORY_POOLS_DATA), poolData);
836
- this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
837
- return [2 /*return*/, Object.keys(poolData)[0]]; // id
838
- }
839
- });
840
- }); };
841
- this.fetchRecentlyDeployedTwocryptoFactoryPool = function (poolAddress) { return __awaiter(_this, void 0, void 0, function () {
842
- var poolData, _a;
843
- return __generator(this, function (_b) {
844
- switch (_b.label) {
845
- case 0:
846
- if ([324, 1284].includes(this.chainId))
847
- return [2 /*return*/, ''];
848
- _a = lowerCasePoolDataAddresses;
849
- return [4 /*yield*/, getTwocryptoFactoryPoolData.call(this, 0, poolAddress)];
850
- case 1:
851
- poolData = _a.apply(void 0, [_b.sent()]);
852
- this.constants.TWOCRYPTO_FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.TWOCRYPTO_FACTORY_POOLS_DATA), poolData);
853
- this._updateDecimalsAndGauges(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
854
- return [2 /*return*/, Object.keys(poolData)[0]]; // id
855
- }
856
- });
857
- }); };
858
- this.fetchRecentlyDeployedTricryptoFactoryPool = function (poolAddress) { return __awaiter(_this, void 0, void 0, function () {
859
- var poolData, _a;
860
- return __generator(this, function (_b) {
861
- switch (_b.label) {
862
- case 0:
863
- if ([324, 1284].includes(this.chainId))
864
- return [2 /*return*/, ''];
865
- _a = lowerCasePoolDataAddresses;
866
- return [4 /*yield*/, getTricryptoFactoryPoolData.call(this, 0, poolAddress)];
867
- case 1:
868
- poolData = _a.apply(void 0, [_b.sent()]);
869
- this.constants.TRICRYPTO_FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.TRICRYPTO_FACTORY_POOLS_DATA), poolData);
870
- this._updateDecimalsAndGauges(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
871
- return [2 /*return*/, Object.keys(poolData)[0]]; // id
872
- }
873
- });
874
- }); };
875
- this.getMainPoolList = function () { return Object.keys(_this.constants.POOLS_DATA); };
876
- this.getFactoryPoolList = function () { return Object.keys(_this.constants.FACTORY_POOLS_DATA); };
877
- this.getCrvusdFactoryPoolList = function () { return Object.keys(_this.constants.CRVUSD_FACTORY_POOLS_DATA); };
878
- this.getEywaFactoryPoolList = function () { return Object.keys(_this.constants.EYWA_FACTORY_POOLS_DATA); };
879
- this.getCryptoFactoryPoolList = function () { return Object.keys(_this.constants.CRYPTO_FACTORY_POOLS_DATA); };
880
- this.getTworyptoFactoryPoolList = function () { return Object.keys(_this.constants.TWOCRYPTO_FACTORY_POOLS_DATA); };
881
- this.getTricryptoFactoryPoolList = function () { return Object.keys(_this.constants.TRICRYPTO_FACTORY_POOLS_DATA); };
882
- this.getStableNgFactoryPoolList = function () { return Object.keys(_this.constants.STABLE_NG_FACTORY_POOLS_DATA); };
883
- this.getPoolList = function () {
884
- return __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], _this.getMainPoolList(), true), _this.getFactoryPoolList(), true), _this.getCrvusdFactoryPoolList(), true), _this.getEywaFactoryPoolList(), true), _this.getCryptoFactoryPoolList(), true), _this.getTworyptoFactoryPoolList(), true), _this.getTricryptoFactoryPoolList(), true), _this.getStableNgFactoryPoolList(), true);
379
+ this.fetchFactoryPools = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
380
+ if ([196, 252, 324, 5000, 1313161554].includes(this.chainId))
381
+ return;
382
+ if (useApi) {
383
+ this.constants.FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory"));
384
+ }
385
+ else {
386
+ this.constants.FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this));
387
+ }
388
+ this.constants.FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.FACTORY_POOLS_DATA);
389
+ this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
390
+ this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory"] = yield this.contracts[this.constants.ALIASES.factory].contract.gauge_implementation(this.constantOptions);
391
+ });
392
+ this.fetchCrvusdFactoryPools = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
393
+ if (this.chainId != 1)
394
+ return;
395
+ if (useApi) {
396
+ this.constants.CRVUSD_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-crvusd"));
397
+ }
398
+ else {
399
+ this.constants.CRVUSD_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.crvusd_factory));
400
+ }
401
+ this.constants.CRVUSD_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.CRVUSD_FACTORY_POOLS_DATA);
402
+ this._updateDecimalsAndGauges(this.constants.CRVUSD_FACTORY_POOLS_DATA);
403
+ });
404
+ this.fetchEywaFactoryPools = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
405
+ if (this.chainId != 250)
406
+ return;
407
+ if (useApi) {
408
+ this.constants.EYWA_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-eywa"));
409
+ }
410
+ else {
411
+ this.constants.EYWA_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.eywa_factory));
412
+ }
413
+ this.constants.EYWA_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.EYWA_FACTORY_POOLS_DATA);
414
+ this._updateDecimalsAndGauges(this.constants.EYWA_FACTORY_POOLS_DATA);
415
+ });
416
+ this.fetchCryptoFactoryPools = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
417
+ if (![1, 56, 137, 250, 5000, 8453].includes(this.chainId))
418
+ return;
419
+ if (useApi) {
420
+ this.constants.CRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-crypto"));
421
+ }
422
+ else {
423
+ this.constants.CRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getCryptoFactoryPoolData.call(this));
424
+ }
425
+ this.constants.CRYPTO_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.CRYPTO_FACTORY_POOLS_DATA);
426
+ this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
427
+ this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-crypto"] = yield this.contracts[this.constants.ALIASES.crypto_factory].contract.gauge_implementation(this.constantOptions);
428
+ });
429
+ this.fetchTworyptoFactoryPools = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
430
+ if ([1284].includes(this.chainId))
431
+ return;
432
+ if (useApi) {
433
+ this.constants.TWOCRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-twocrypto"));
434
+ }
435
+ else {
436
+ this.constants.TWOCRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getTwocryptoFactoryPoolData.call(this));
437
+ }
438
+ this.constants.TWOCRYPTO_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
439
+ this._updateDecimalsAndGauges(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
440
+ this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-twocrypto"] = yield this.contracts[this.constants.ALIASES.twocrypto_factory].contract.gauge_implementation(this.constantOptions);
441
+ });
442
+ this.fetchTricryptoFactoryPools = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
443
+ if ([1284].includes(this.chainId))
444
+ return;
445
+ if (useApi) {
446
+ this.constants.TRICRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-tricrypto"));
447
+ }
448
+ else {
449
+ this.constants.TRICRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getTricryptoFactoryPoolData.call(this));
450
+ }
451
+ this.constants.TRICRYPTO_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
452
+ this._updateDecimalsAndGauges(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
453
+ if (this.chainId === 1) {
454
+ this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-tricrypto"] =
455
+ yield this.contracts[this.constants.ALIASES.tricrypto_factory].contract.gauge_implementation(this.constantOptions);
456
+ }
457
+ else {
458
+ this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-tricrypto"] =
459
+ yield this.contracts[this.constants.ALIASES.gauge_factory].contract.get_implementation(this.constantOptions);
460
+ }
461
+ });
462
+ this.fetchStableNgFactoryPools = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
463
+ if (this.chainId === 1313161554)
464
+ return;
465
+ if (useApi) {
466
+ this.constants.STABLE_NG_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-stable-ng"));
467
+ }
468
+ else {
469
+ this.constants.STABLE_NG_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.stable_ng_factory));
470
+ }
471
+ this.constants.STABLE_NG_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
472
+ this._updateDecimalsAndGauges(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
473
+ });
474
+ this.fetchNewFactoryPools = () => __awaiter(this, void 0, void 0, function* () {
475
+ if ([196, 252, 1313161554].includes(this.chainId))
476
+ return [];
477
+ const currentPoolIds = Object.keys(this.constants.FACTORY_POOLS_DATA);
478
+ const lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
479
+ const poolData = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this, lastPoolIdx + 1));
480
+ this.constants.FACTORY_POOLS_DATA = Object.assign(Object.assign({}, this.constants.FACTORY_POOLS_DATA), poolData);
481
+ this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
482
+ return Object.keys(poolData);
483
+ });
484
+ this.fetchNewStableNgFactoryPools = () => __awaiter(this, void 0, void 0, function* () {
485
+ const currentPoolIds = Object.keys(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
486
+ const lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[3]);
487
+ const poolData = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this, lastPoolIdx + 1, undefined, this.constants.ALIASES.stable_ng_factory));
488
+ this.constants.STABLE_NG_FACTORY_POOLS_DATA = Object.assign(Object.assign({}, this.constants.STABLE_NG_FACTORY_POOLS_DATA), poolData);
489
+ this._updateDecimalsAndGauges(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
490
+ return Object.keys(poolData);
491
+ });
492
+ this.fetchNewCryptoFactoryPools = () => __awaiter(this, void 0, void 0, function* () {
493
+ if (![1, 56, 137, 250, 8453].includes(this.chainId))
494
+ return [];
495
+ const currentPoolIds = Object.keys(this.constants.CRYPTO_FACTORY_POOLS_DATA);
496
+ const lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
497
+ const poolData = lowerCasePoolDataAddresses(yield getCryptoFactoryPoolData.call(this, lastPoolIdx + 1));
498
+ this.constants.CRYPTO_FACTORY_POOLS_DATA = Object.assign(Object.assign({}, this.constants.CRYPTO_FACTORY_POOLS_DATA), poolData);
499
+ this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
500
+ return Object.keys(poolData);
501
+ });
502
+ this.fetchNewTwocryptoFactoryPools = () => __awaiter(this, void 0, void 0, function* () {
503
+ if ([1284].includes(this.chainId))
504
+ return [];
505
+ const currentPoolIds = Object.keys(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
506
+ const lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
507
+ const poolData = lowerCasePoolDataAddresses(yield getTwocryptoFactoryPoolData.call(this, lastPoolIdx + 1));
508
+ this.constants.TWOCRYPTO_FACTORY_POOLS_DATA = Object.assign(Object.assign({}, this.constants.TWOCRYPTO_FACTORY_POOLS_DATA), poolData);
509
+ this._updateDecimalsAndGauges(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
510
+ return Object.keys(poolData);
511
+ });
512
+ this.fetchNewTricryptoFactoryPools = () => __awaiter(this, void 0, void 0, function* () {
513
+ if ([1284].includes(this.chainId))
514
+ return [];
515
+ const currentPoolIds = Object.keys(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
516
+ const lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
517
+ const poolData = lowerCasePoolDataAddresses(yield getTricryptoFactoryPoolData.call(this, lastPoolIdx + 1));
518
+ this.constants.TRICRYPTO_FACTORY_POOLS_DATA = Object.assign(Object.assign({}, this.constants.TRICRYPTO_FACTORY_POOLS_DATA), poolData);
519
+ this._updateDecimalsAndGauges(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
520
+ return Object.keys(poolData);
521
+ });
522
+ this.fetchRecentlyDeployedFactoryPool = (poolAddress) => __awaiter(this, void 0, void 0, function* () {
523
+ if ([196, 252, 1313161554].includes(this.chainId))
524
+ return '';
525
+ const poolData = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this, 0, poolAddress));
526
+ this.constants.FACTORY_POOLS_DATA = Object.assign(Object.assign({}, this.constants.FACTORY_POOLS_DATA), poolData);
527
+ this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
528
+ return Object.keys(poolData)[0]; // id
529
+ });
530
+ this.fetchRecentlyDeployedStableNgFactoryPool = (poolAddress) => __awaiter(this, void 0, void 0, function* () {
531
+ if (this.chainId === 1313161554)
532
+ return '';
533
+ const poolData = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this, 0, poolAddress, this.constants.ALIASES.stable_ng_factory));
534
+ this.constants.STABLE_NG_FACTORY_POOLS_DATA = Object.assign(Object.assign({}, this.constants.STABLE_NG_FACTORY_POOLS_DATA), poolData);
535
+ this._updateDecimalsAndGauges(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
536
+ return Object.keys(poolData)[0]; // id
537
+ });
538
+ this.fetchRecentlyDeployedCryptoFactoryPool = (poolAddress) => __awaiter(this, void 0, void 0, function* () {
539
+ if (![1, 56, 137, 250, 8453].includes(this.chainId))
540
+ return '';
541
+ const poolData = lowerCasePoolDataAddresses(yield getCryptoFactoryPoolData.call(this, 0, poolAddress));
542
+ this.constants.CRYPTO_FACTORY_POOLS_DATA = Object.assign(Object.assign({}, this.constants.CRYPTO_FACTORY_POOLS_DATA), poolData);
543
+ this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
544
+ return Object.keys(poolData)[0]; // id
545
+ });
546
+ this.fetchRecentlyDeployedTwocryptoFactoryPool = (poolAddress) => __awaiter(this, void 0, void 0, function* () {
547
+ if ([1284].includes(this.chainId))
548
+ return '';
549
+ const poolData = lowerCasePoolDataAddresses(yield getTwocryptoFactoryPoolData.call(this, 0, poolAddress));
550
+ this.constants.TWOCRYPTO_FACTORY_POOLS_DATA = Object.assign(Object.assign({}, this.constants.TWOCRYPTO_FACTORY_POOLS_DATA), poolData);
551
+ this._updateDecimalsAndGauges(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
552
+ return Object.keys(poolData)[0]; // id
553
+ });
554
+ this.fetchRecentlyDeployedTricryptoFactoryPool = (poolAddress) => __awaiter(this, void 0, void 0, function* () {
555
+ if ([1284].includes(this.chainId))
556
+ return '';
557
+ const poolData = lowerCasePoolDataAddresses(yield getTricryptoFactoryPoolData.call(this, 0, poolAddress));
558
+ this.constants.TRICRYPTO_FACTORY_POOLS_DATA = Object.assign(Object.assign({}, this.constants.TRICRYPTO_FACTORY_POOLS_DATA), poolData);
559
+ this._updateDecimalsAndGauges(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
560
+ return Object.keys(poolData)[0]; // id
561
+ });
562
+ this.getMainPoolList = () => Object.keys(this.constants.POOLS_DATA);
563
+ this.getFactoryPoolList = () => Object.keys(this.constants.FACTORY_POOLS_DATA);
564
+ this.getCrvusdFactoryPoolList = () => Object.keys(this.constants.CRVUSD_FACTORY_POOLS_DATA);
565
+ this.getEywaFactoryPoolList = () => Object.keys(this.constants.EYWA_FACTORY_POOLS_DATA);
566
+ this.getCryptoFactoryPoolList = () => Object.keys(this.constants.CRYPTO_FACTORY_POOLS_DATA);
567
+ this.getTworyptoFactoryPoolList = () => Object.keys(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
568
+ this.getTricryptoFactoryPoolList = () => Object.keys(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
569
+ this.getStableNgFactoryPoolList = () => Object.keys(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
570
+ this.getPoolList = () => {
571
+ return [
572
+ ...this.getMainPoolList(),
573
+ ...this.getFactoryPoolList(),
574
+ ...this.getCrvusdFactoryPoolList(),
575
+ ...this.getEywaFactoryPoolList(),
576
+ ...this.getCryptoFactoryPoolList(),
577
+ ...this.getTworyptoFactoryPoolList(),
578
+ ...this.getTricryptoFactoryPoolList(),
579
+ ...this.getStableNgFactoryPoolList(),
580
+ ];
885
581
  };
886
- this.getPoolsData = function () { return (__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, _this.constants.POOLS_DATA), _this.constants.FACTORY_POOLS_DATA), _this.constants.CRVUSD_FACTORY_POOLS_DATA), _this.constants.EYWA_FACTORY_POOLS_DATA), _this.constants.CRYPTO_FACTORY_POOLS_DATA), _this.constants.TWOCRYPTO_FACTORY_POOLS_DATA), _this.constants.TRICRYPTO_FACTORY_POOLS_DATA), _this.constants.STABLE_NG_FACTORY_POOLS_DATA), _this.constants.LLAMMAS_DATA)); };
887
- this.getGaugeImplementation = function (factoryType) { return _this.constants.FACTORY_GAUGE_IMPLEMENTATIONS[factoryType] || _this.constants.ZERO_ADDRESS; };
582
+ this.getPoolsData = () => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, this.constants.POOLS_DATA), this.constants.FACTORY_POOLS_DATA), this.constants.CRVUSD_FACTORY_POOLS_DATA), this.constants.EYWA_FACTORY_POOLS_DATA), this.constants.CRYPTO_FACTORY_POOLS_DATA), this.constants.TWOCRYPTO_FACTORY_POOLS_DATA), this.constants.TRICRYPTO_FACTORY_POOLS_DATA), this.constants.STABLE_NG_FACTORY_POOLS_DATA), this.constants.LLAMMAS_DATA));
583
+ this.getGaugeImplementation = (factoryType) => this.constants.FACTORY_GAUGE_IMPLEMENTATIONS[factoryType] || this.constants.ZERO_ADDRESS;
888
584
  // @ts-ignore
889
585
  this.provider = null;
890
586
  // @ts-ignore
@@ -918,319 +614,267 @@ var Curve = /** @class */ (function () {
918
614
  ZERO_ADDRESS: ethers.ZeroAddress,
919
615
  };
920
616
  }
921
- Curve.prototype.init = function (providerType, providerSettings, options // gasPrice in Gwei
617
+ init(providerType, providerSettings, options = {} // gasPrice in Gwei
922
618
  ) {
923
619
  var _a;
924
- if (options === void 0) { options = {}; }
925
- return __awaiter(this, void 0, void 0, function () {
926
- var jsonRpcApiProviderOptions, _b, e_1, _c, network, poolId, _d, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _e, err_1, _i, _f, pool, _g, _h, coinAddr, _j, _k, coinAddr, _l, _m, coinAddr, _gaugeFactoryABI, factoryContract, _o, curveInstance_1, originalEstimate_1, oldEstimate, newEstimate;
927
- return __generator(this, function (_p) {
928
- switch (_p.label) {
929
- case 0:
930
- // @ts-ignore
931
- this.provider = null;
932
- // @ts-ignore
620
+ return __awaiter(this, void 0, void 0, function* () {
621
+ // @ts-ignore
622
+ this.provider = null;
623
+ // @ts-ignore
624
+ this.signer = null;
625
+ this.signerAddress = '';
626
+ this.chainId = 1;
627
+ // @ts-ignore
628
+ this.multicallProvider = null;
629
+ this.contracts = {};
630
+ this.feeData = {};
631
+ this.constantOptions = { gasLimit: 12000000 };
632
+ this.options = {};
633
+ this.constants = {
634
+ NATIVE_TOKEN: NATIVE_TOKENS[1],
635
+ NETWORK_NAME: 'ethereum',
636
+ ALIASES: {},
637
+ POOLS_DATA: {},
638
+ FACTORY_POOLS_DATA: {},
639
+ CRVUSD_FACTORY_POOLS_DATA: {},
640
+ EYWA_FACTORY_POOLS_DATA: {},
641
+ CRYPTO_FACTORY_POOLS_DATA: {},
642
+ TWOCRYPTO_FACTORY_POOLS_DATA: {},
643
+ TRICRYPTO_FACTORY_POOLS_DATA: {},
644
+ STABLE_NG_FACTORY_POOLS_DATA: {},
645
+ BASE_POOLS: {},
646
+ LLAMMAS_DATA: {},
647
+ COINS: {},
648
+ DECIMALS: {},
649
+ GAUGES: [],
650
+ FACTORY_GAUGE_IMPLEMENTATIONS: {},
651
+ ZERO_ADDRESS: ethers.ZeroAddress,
652
+ };
653
+ this.initContract = memoizedContract();
654
+ this.initMulticallContract = memoizedMulticallContract();
655
+ // JsonRpc provider
656
+ if (providerType.toLowerCase() === 'JsonRpc'.toLowerCase()) {
657
+ providerSettings = providerSettings;
658
+ let jsonRpcApiProviderOptions;
659
+ if (providerSettings.batchMaxCount) {
660
+ jsonRpcApiProviderOptions = {
661
+ batchMaxCount: providerSettings.batchMaxCount,
662
+ };
663
+ }
664
+ if (providerSettings.url) {
665
+ this.provider = new ethers.JsonRpcProvider(providerSettings.url, undefined, jsonRpcApiProviderOptions);
666
+ }
667
+ else {
668
+ this.provider = new ethers.JsonRpcProvider('http://localhost:8545/', undefined, jsonRpcApiProviderOptions);
669
+ }
670
+ if (providerSettings.privateKey) {
671
+ this.signer = new ethers.Wallet(providerSettings.privateKey, this.provider);
672
+ }
673
+ else if (!((_a = providerSettings.url) === null || _a === void 0 ? void 0 : _a.startsWith("https://rpc.gnosischain.com"))) {
674
+ try {
675
+ this.signer = yield this.provider.getSigner();
676
+ }
677
+ catch (e) {
933
678
  this.signer = null;
934
- this.signerAddress = '';
935
- this.chainId = 1;
679
+ }
680
+ }
681
+ // Web3 provider
682
+ }
683
+ else if (providerType.toLowerCase() === 'Web3'.toLowerCase()) {
684
+ providerSettings = providerSettings;
685
+ this.provider = new ethers.BrowserProvider(providerSettings.externalProvider);
686
+ this.signer = yield this.provider.getSigner();
687
+ // Infura provider
688
+ }
689
+ else if (providerType.toLowerCase() === 'Infura'.toLowerCase()) {
690
+ providerSettings = providerSettings;
691
+ this.provider = new ethers.InfuraProvider(providerSettings.network, providerSettings.apiKey);
692
+ this.signer = null;
693
+ // Alchemy provider
694
+ }
695
+ else if (providerType.toLowerCase() === 'Alchemy'.toLowerCase()) {
696
+ providerSettings = providerSettings;
697
+ this.provider = new ethers.AlchemyProvider(providerSettings.network, providerSettings.apiKey);
698
+ this.signer = null;
699
+ }
700
+ else {
701
+ throw Error('Wrong providerType');
702
+ }
703
+ const network = yield this.provider.getNetwork();
704
+ console.log("CURVE-JS IS CONNECTED TO NETWORK:", { name: network.name.toUpperCase(), chainId: Number(network.chainId) });
705
+ this.chainId = Number(network.chainId) === 133 || Number(network.chainId) === 31337 ? 1 : Number(network.chainId);
706
+ this.constants.NATIVE_TOKEN = NATIVE_TOKENS[this.chainId];
707
+ this.constants.NETWORK_NAME = NETWORK_CONSTANTS[this.chainId].NAME;
708
+ this.constants.ALIASES = NETWORK_CONSTANTS[this.chainId].ALIASES;
709
+ this.constants.ALIASES.anycall = "0x37414a8662bc1d25be3ee51fb27c2686e2490a89";
710
+ this.constants.ALIASES.voting_escrow_oracle = "0x12F407340697Ae0b177546E535b91A5be021fBF9";
711
+ this.constants.POOLS_DATA = NETWORK_CONSTANTS[this.chainId].POOLS_DATA;
712
+ if (this.chainId === 1)
713
+ this.constants.LLAMMAS_DATA = NETWORK_CONSTANTS[this.chainId].LLAMMAS_DATA;
714
+ for (const poolId in this.constants.POOLS_DATA)
715
+ this.constants.POOLS_DATA[poolId].in_api = true;
716
+ this.constants.COINS = NETWORK_CONSTANTS[this.chainId].COINS;
717
+ this.constants.DECIMALS = extractDecimals(Object.assign(Object.assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA));
718
+ this.constants.DECIMALS[this.constants.NATIVE_TOKEN.address] = 18;
719
+ this.constants.DECIMALS[this.constants.NATIVE_TOKEN.wrappedAddress] = 18;
720
+ this.constants.GAUGES = extractGauges(this.constants.POOLS_DATA);
721
+ const [cTokens, yTokens, ycTokens, aTokens] = [
722
+ NETWORK_CONSTANTS[this.chainId].cTokens,
723
+ NETWORK_CONSTANTS[this.chainId].yTokens,
724
+ NETWORK_CONSTANTS[this.chainId].ycTokens,
725
+ NETWORK_CONSTANTS[this.chainId].aTokens,
726
+ ];
727
+ const customAbiTokens = [...cTokens, ...yTokens, ...ycTokens, ...aTokens];
728
+ if (this.chainId === 5000) {
729
+ this.constantOptions = {};
730
+ }
731
+ this.multicallProvider = new MulticallProvider(this.chainId, this.provider);
732
+ if (this.signer) {
733
+ try {
734
+ this.signerAddress = yield this.signer.getAddress();
735
+ }
736
+ catch (err) {
737
+ this.signer = null;
738
+ }
739
+ }
740
+ else {
741
+ this.signerAddress = '';
742
+ }
743
+ this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
744
+ yield this.updateFeeData();
745
+ for (const pool of Object.values(Object.assign(Object.assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA))) {
746
+ this.setContract(pool.swap_address, pool.swap_abi);
747
+ if (pool.token_address !== pool.swap_address) {
748
+ this.setContract(pool.token_address, ERC20Abi);
749
+ }
750
+ if (pool.gauge_address !== this.constants.ZERO_ADDRESS) {
751
+ this.setContract(pool.gauge_address, pool.gauge_abi);
752
+ }
753
+ if (pool.deposit_address && !this.contracts[pool.deposit_address]) {
754
+ this.setContract(pool.deposit_address, pool.deposit_abi);
755
+ }
756
+ for (const coinAddr of pool.underlying_coin_addresses) {
757
+ this.setContract(coinAddr, ERC20Abi);
758
+ }
759
+ for (const coinAddr of pool.wrapped_coin_addresses) {
760
+ if (customAbiTokens.includes(coinAddr))
761
+ continue;
762
+ if (coinAddr in this.contracts)
763
+ continue;
764
+ this.setContract(coinAddr, ERC20Abi);
765
+ }
766
+ // TODO add all coins
767
+ for (const coinAddr of pool.wrapped_coin_addresses) {
768
+ if (cTokens.includes(coinAddr)) {
769
+ this.setContract(coinAddr, cERC20Abi);
770
+ }
771
+ if (aTokens.includes(coinAddr)) {
772
+ this.setContract(coinAddr, ERC20Abi);
773
+ }
774
+ if (yTokens.includes(coinAddr) || ycTokens.includes(coinAddr)) {
775
+ this.setContract(coinAddr, yERC20Abi);
776
+ }
777
+ }
778
+ if (pool.reward_contract) {
779
+ this.setContract(pool.reward_contract, streamerABI);
780
+ }
781
+ if (pool.sCurveRewards_address) {
782
+ this.setContract(pool.sCurveRewards_address, pool.sCurveRewards_abi);
783
+ }
784
+ }
785
+ this.setContract(this.constants.NATIVE_TOKEN.wrappedAddress, ERC20Abi);
786
+ this.setContract(this.constants.ALIASES.crv, ERC20Abi);
787
+ this.constants.DECIMALS[this.constants.ALIASES.crv] = 18;
788
+ const _gaugeFactoryABI = this.chainId === 1 ? gaugeFactoryABI : gaugeFactorySidechainABI;
789
+ this.setContract(this.constants.ALIASES.gauge_factory, _gaugeFactoryABI);
790
+ if (this.chainId === 1) {
791
+ this.setContract(this.constants.ALIASES.minter, minterMainnetABI);
792
+ this.setContract(this.constants.ALIASES.gauge_factory_fraxtal, gaugeFactoryForFraxtalABI);
793
+ this.setContract(this.constants.ALIASES.fee_distributor_crvusd, feeDistributorCrvUSDABI);
794
+ }
795
+ this.setContract(this.constants.ALIASES.voting_escrow, votingEscrowABI);
796
+ this.setContract(this.constants.ALIASES.fee_distributor, feeDistributorABI);
797
+ this.setContract(this.constants.ALIASES.gauge_controller, gaugeControllerABI);
798
+ if (this.chainId == 137) {
799
+ this.setContract(this.constants.ALIASES.router, routerPolygonABI);
800
+ }
801
+ else if (OLD_CHAINS.includes(this.chainId)) {
802
+ this.setContract(this.constants.ALIASES.router, routerABI);
803
+ }
804
+ else {
805
+ this.setContract(this.constants.ALIASES.router, routerNgPoolsOnlyABI);
806
+ }
807
+ this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStakeABI);
808
+ this.setContract(this.constants.ALIASES.crypto_calc, cryptoCalcZapABI);
809
+ this.setContract(this.constants.ALIASES.stable_calc, StableCalcZapABI);
810
+ this.setContract(this.constants.ALIASES.factory, factoryABI);
811
+ if (this.chainId !== 1313161554 && this.chainId !== 252 && this.chainId !== 324 && this.chainId !== 196 && this.chainId !== 5000) {
812
+ const factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
813
+ this.constants.ALIASES.factory_admin = (yield factoryContract.admin(this.constantOptions)).toLowerCase();
814
+ this.setContract(this.constants.ALIASES.factory_admin, factoryAdminABI);
815
+ }
816
+ this.setContract(this.constants.ALIASES.crvusd_factory, factoryABI);
817
+ this.setContract(this.constants.ALIASES.eywa_factory, factoryEywaABI);
818
+ this.setContract(this.constants.ALIASES.crypto_factory, cryptoFactoryABI);
819
+ this.setContract(this.constants.ALIASES.twocrypto_factory, twocryptoFactoryABI);
820
+ this.setContract(this.constants.ALIASES.tricrypto_factory, tricryptoFactoryABI);
821
+ this.setContract(this.constants.ALIASES.stable_ng_factory, stableNgFactoryABI);
822
+ this.setContract(this.constants.ALIASES.anycall, anycallABI);
823
+ this.setContract(this.constants.ALIASES.voting_escrow_oracle, this.chainId === 1 ? votingEscrowOracleEthABI : votingEscrowOracleABI);
824
+ if (this.chainId === 1) {
825
+ this.setContract(this.constants.ALIASES.voting_parameter, votingProposalABI);
826
+ this.setContract(this.constants.ALIASES.voting_ownership, votingProposalABI);
827
+ this.setContract(this.constants.ALIASES.circulating_supply, circulatingSupplyABI);
828
+ }
829
+ if (L2Networks.includes(this.chainId)) {
830
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
831
+ const curveInstance = this;
832
+ curveInstance.setContract(curveInstance.constants.ALIASES.gas_oracle, gasOracleABI);
833
+ curveInstance.setContract(curveInstance.constants.ALIASES.gas_oracle_blob, gasOracleBlobABI);
834
+ // @ts-ignore
835
+ if (AbstractProvider.prototype.originalEstimate) {
836
+ // @ts-ignore
837
+ AbstractProvider.prototype.estimateGas = AbstractProvider.prototype.originalEstimate;
838
+ }
839
+ const originalEstimate = AbstractProvider.prototype.estimateGas;
840
+ const oldEstimate = function (arg) {
841
+ return __awaiter(this, void 0, void 0, function* () {
936
842
  // @ts-ignore
937
- this.multicallProvider = null;
938
- this.contracts = {};
939
- this.feeData = {};
940
- this.constantOptions = { gasLimit: 12000000 };
941
- this.options = {};
942
- this.constants = {
943
- NATIVE_TOKEN: NATIVE_TOKENS[1],
944
- NETWORK_NAME: 'ethereum',
945
- ALIASES: {},
946
- POOLS_DATA: {},
947
- FACTORY_POOLS_DATA: {},
948
- CRVUSD_FACTORY_POOLS_DATA: {},
949
- EYWA_FACTORY_POOLS_DATA: {},
950
- CRYPTO_FACTORY_POOLS_DATA: {},
951
- TWOCRYPTO_FACTORY_POOLS_DATA: {},
952
- TRICRYPTO_FACTORY_POOLS_DATA: {},
953
- STABLE_NG_FACTORY_POOLS_DATA: {},
954
- BASE_POOLS: {},
955
- LLAMMAS_DATA: {},
956
- COINS: {},
957
- DECIMALS: {},
958
- GAUGES: [],
959
- FACTORY_GAUGE_IMPLEMENTATIONS: {},
960
- ZERO_ADDRESS: ethers.ZeroAddress,
961
- };
962
- this.initContract = memoizedContract();
963
- this.initMulticallContract = memoizedMulticallContract();
964
- if (!(providerType.toLowerCase() === 'JsonRpc'.toLowerCase())) return [3 /*break*/, 6];
965
- providerSettings = providerSettings;
966
- jsonRpcApiProviderOptions = void 0;
967
- if (providerSettings.batchMaxCount) {
968
- jsonRpcApiProviderOptions = {
969
- batchMaxCount: providerSettings.batchMaxCount,
970
- };
971
- }
972
- if (providerSettings.url) {
973
- this.provider = new ethers.JsonRpcProvider(providerSettings.url, undefined, jsonRpcApiProviderOptions);
974
- }
975
- else {
976
- this.provider = new ethers.JsonRpcProvider('http://localhost:8545/', undefined, jsonRpcApiProviderOptions);
977
- }
978
- if (!providerSettings.privateKey) return [3 /*break*/, 1];
979
- this.signer = new ethers.Wallet(providerSettings.privateKey, this.provider);
980
- return [3 /*break*/, 5];
981
- case 1:
982
- if (!!((_a = providerSettings.url) === null || _a === void 0 ? void 0 : _a.startsWith("https://rpc.gnosischain.com"))) return [3 /*break*/, 5];
983
- _p.label = 2;
984
- case 2:
985
- _p.trys.push([2, 4, , 5]);
986
- _b = this;
987
- return [4 /*yield*/, this.provider.getSigner()];
988
- case 3:
989
- _b.signer = _p.sent();
990
- return [3 /*break*/, 5];
991
- case 4:
992
- e_1 = _p.sent();
993
- this.signer = null;
994
- return [3 /*break*/, 5];
995
- case 5: return [3 /*break*/, 9];
996
- case 6:
997
- if (!(providerType.toLowerCase() === 'Web3'.toLowerCase())) return [3 /*break*/, 8];
998
- providerSettings = providerSettings;
999
- this.provider = new ethers.BrowserProvider(providerSettings.externalProvider);
1000
- _c = this;
1001
- return [4 /*yield*/, this.provider.getSigner()];
1002
- case 7:
1003
- _c.signer = _p.sent();
1004
- return [3 /*break*/, 9];
1005
- case 8:
1006
- if (providerType.toLowerCase() === 'Infura'.toLowerCase()) {
1007
- providerSettings = providerSettings;
1008
- this.provider = new ethers.InfuraProvider(providerSettings.network, providerSettings.apiKey);
1009
- this.signer = null;
1010
- // Alchemy provider
1011
- }
1012
- else if (providerType.toLowerCase() === 'Alchemy'.toLowerCase()) {
1013
- providerSettings = providerSettings;
1014
- this.provider = new ethers.AlchemyProvider(providerSettings.network, providerSettings.apiKey);
1015
- this.signer = null;
1016
- }
1017
- else {
1018
- throw Error('Wrong providerType');
1019
- }
1020
- _p.label = 9;
1021
- case 9: return [4 /*yield*/, this.provider.getNetwork()];
1022
- case 10:
1023
- network = _p.sent();
1024
- console.log("CURVE-JS IS CONNECTED TO NETWORK:", { name: network.name.toUpperCase(), chainId: Number(network.chainId) });
1025
- this.chainId = Number(network.chainId) === 133 || Number(network.chainId) === 31337 ? 1 : Number(network.chainId);
1026
- this.constants.NATIVE_TOKEN = NATIVE_TOKENS[this.chainId];
1027
- this.constants.NETWORK_NAME = NETWORK_CONSTANTS[this.chainId].NAME;
1028
- this.constants.ALIASES = NETWORK_CONSTANTS[this.chainId].ALIASES;
1029
- this.constants.ALIASES.anycall = "0x37414a8662bc1d25be3ee51fb27c2686e2490a89";
1030
- this.constants.ALIASES.voting_escrow_oracle = "0x12F407340697Ae0b177546E535b91A5be021fBF9";
1031
- this.constants.POOLS_DATA = NETWORK_CONSTANTS[this.chainId].POOLS_DATA;
1032
- if (this.chainId === 1)
1033
- this.constants.LLAMMAS_DATA = NETWORK_CONSTANTS[this.chainId].LLAMMAS_DATA;
1034
- for (poolId in this.constants.POOLS_DATA)
1035
- this.constants.POOLS_DATA[poolId].in_api = true;
1036
- this.constants.COINS = NETWORK_CONSTANTS[this.chainId].COINS;
1037
- this.constants.DECIMALS = extractDecimals(__assign(__assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA));
1038
- this.constants.DECIMALS[this.constants.NATIVE_TOKEN.address] = 18;
1039
- this.constants.DECIMALS[this.constants.NATIVE_TOKEN.wrappedAddress] = 18;
1040
- this.constants.GAUGES = extractGauges(this.constants.POOLS_DATA);
1041
- _d = [
1042
- NETWORK_CONSTANTS[this.chainId].cTokens,
1043
- NETWORK_CONSTANTS[this.chainId].yTokens,
1044
- NETWORK_CONSTANTS[this.chainId].ycTokens,
1045
- NETWORK_CONSTANTS[this.chainId].aTokens,
1046
- ], cTokens = _d[0], yTokens = _d[1], ycTokens = _d[2], aTokens = _d[3];
1047
- customAbiTokens = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], cTokens, true), yTokens, true), ycTokens, true), aTokens, true);
1048
- if (this.chainId === 5000) {
1049
- this.constantOptions = {};
1050
- }
1051
- this.multicallProvider = new MulticallProvider(this.chainId, this.provider);
1052
- if (!this.signer) return [3 /*break*/, 15];
1053
- _p.label = 11;
1054
- case 11:
1055
- _p.trys.push([11, 13, , 14]);
1056
- _e = this;
1057
- return [4 /*yield*/, this.signer.getAddress()];
1058
- case 12:
1059
- _e.signerAddress = _p.sent();
1060
- return [3 /*break*/, 14];
1061
- case 13:
1062
- err_1 = _p.sent();
1063
- this.signer = null;
1064
- return [3 /*break*/, 14];
1065
- case 14: return [3 /*break*/, 16];
1066
- case 15:
1067
- this.signerAddress = '';
1068
- _p.label = 16;
1069
- case 16:
1070
- this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
1071
- return [4 /*yield*/, this.updateFeeData()];
1072
- case 17:
1073
- _p.sent();
1074
- for (_i = 0, _f = Object.values(__assign(__assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA)); _i < _f.length; _i++) {
1075
- pool = _f[_i];
1076
- this.setContract(pool.swap_address, pool.swap_abi);
1077
- if (pool.token_address !== pool.swap_address) {
1078
- this.setContract(pool.token_address, ERC20Abi);
1079
- }
1080
- if (pool.gauge_address !== this.constants.ZERO_ADDRESS) {
1081
- this.setContract(pool.gauge_address, pool.gauge_abi);
1082
- }
1083
- if (pool.deposit_address && !this.contracts[pool.deposit_address]) {
1084
- this.setContract(pool.deposit_address, pool.deposit_abi);
1085
- }
1086
- for (_g = 0, _h = pool.underlying_coin_addresses; _g < _h.length; _g++) {
1087
- coinAddr = _h[_g];
1088
- this.setContract(coinAddr, ERC20Abi);
1089
- }
1090
- for (_j = 0, _k = pool.wrapped_coin_addresses; _j < _k.length; _j++) {
1091
- coinAddr = _k[_j];
1092
- if (customAbiTokens.includes(coinAddr))
1093
- continue;
1094
- if (coinAddr in this.contracts)
1095
- continue;
1096
- this.setContract(coinAddr, ERC20Abi);
1097
- }
1098
- // TODO add all coins
1099
- for (_l = 0, _m = pool.wrapped_coin_addresses; _l < _m.length; _l++) {
1100
- coinAddr = _m[_l];
1101
- if (cTokens.includes(coinAddr)) {
1102
- this.setContract(coinAddr, cERC20Abi);
1103
- }
1104
- if (aTokens.includes(coinAddr)) {
1105
- this.setContract(coinAddr, ERC20Abi);
1106
- }
1107
- if (yTokens.includes(coinAddr) || ycTokens.includes(coinAddr)) {
1108
- this.setContract(coinAddr, yERC20Abi);
1109
- }
1110
- }
1111
- if (pool.reward_contract) {
1112
- this.setContract(pool.reward_contract, streamerABI);
1113
- }
1114
- if (pool.sCurveRewards_address) {
1115
- this.setContract(pool.sCurveRewards_address, pool.sCurveRewards_abi);
1116
- }
1117
- }
1118
- this.setContract(this.constants.NATIVE_TOKEN.wrappedAddress, ERC20Abi);
1119
- this.setContract(this.constants.ALIASES.crv, ERC20Abi);
1120
- this.constants.DECIMALS[this.constants.ALIASES.crv] = 18;
1121
- _gaugeFactoryABI = this.chainId === 1 ? gaugeFactoryABI : gaugeFactorySidechainABI;
1122
- this.setContract(this.constants.ALIASES.gauge_factory, _gaugeFactoryABI);
1123
- if (this.chainId === 1) {
1124
- this.setContract(this.constants.ALIASES.minter, minterMainnetABI);
1125
- this.setContract(this.constants.ALIASES.gauge_factory_fraxtal, gaugeFactoryForFraxtalABI);
1126
- this.setContract(this.constants.ALIASES.fee_distributor_crvusd, feeDistributorCrvUSDABI);
1127
- }
1128
- this.setContract(this.constants.ALIASES.voting_escrow, votingEscrowABI);
1129
- this.setContract(this.constants.ALIASES.fee_distributor, feeDistributorABI);
1130
- this.setContract(this.constants.ALIASES.gauge_controller, gaugeControllerABI);
1131
- if (this.chainId == 137) {
1132
- this.setContract(this.constants.ALIASES.router, routerPolygonABI);
1133
- }
1134
- else if (OLD_CHAINS.includes(this.chainId)) {
1135
- this.setContract(this.constants.ALIASES.router, routerABI);
1136
- }
1137
- else {
1138
- this.setContract(this.constants.ALIASES.router, routerNgPoolsOnlyABI);
1139
- }
1140
- this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStakeABI);
1141
- this.setContract(this.constants.ALIASES.crypto_calc, cryptoCalcZapABI);
1142
- this.setContract(this.constants.ALIASES.stable_calc, StableCalcZapABI);
1143
- this.setContract(this.constants.ALIASES.factory, factoryABI);
1144
- if (!(this.chainId !== 1313161554 && this.chainId !== 252 && this.chainId !== 196 && this.chainId !== 5000)) return [3 /*break*/, 19];
1145
- factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
1146
- _o = this.constants.ALIASES;
1147
- return [4 /*yield*/, factoryContract.admin(this.constantOptions)];
1148
- case 18:
1149
- _o.factory_admin = (_p.sent()).toLowerCase();
1150
- this.setContract(this.constants.ALIASES.factory_admin, factoryAdminABI);
1151
- _p.label = 19;
1152
- case 19:
1153
- this.setContract(this.constants.ALIASES.crvusd_factory, factoryABI);
1154
- this.setContract(this.constants.ALIASES.eywa_factory, factoryEywaABI);
1155
- this.setContract(this.constants.ALIASES.crypto_factory, cryptoFactoryABI);
1156
- this.setContract(this.constants.ALIASES.twocrypto_factory, twocryptoFactoryABI);
1157
- this.setContract(this.constants.ALIASES.tricrypto_factory, tricryptoFactoryABI);
1158
- this.setContract(this.constants.ALIASES.stable_ng_factory, stableNgFactoryABI);
1159
- this.setContract(this.constants.ALIASES.anycall, anycallABI);
1160
- this.setContract(this.constants.ALIASES.voting_escrow_oracle, this.chainId === 1 ? votingEscrowOracleEthABI : votingEscrowOracleABI);
1161
- if (this.chainId === 1) {
1162
- this.setContract(this.constants.ALIASES.voting_parameter, votingProposalABI);
1163
- this.setContract(this.constants.ALIASES.voting_ownership, votingProposalABI);
1164
- this.setContract(this.constants.ALIASES.circulating_supply, circulatingSupplyABI);
1165
- }
1166
- if (L2Networks.includes(this.chainId)) {
1167
- curveInstance_1 = this;
1168
- curveInstance_1.setContract(curveInstance_1.constants.ALIASES.gas_oracle, gasOracleABI);
1169
- curveInstance_1.setContract(curveInstance_1.constants.ALIASES.gas_oracle_blob, gasOracleBlobABI);
1170
- // @ts-ignore
1171
- if (AbstractProvider.prototype.originalEstimate) {
1172
- // @ts-ignore
1173
- AbstractProvider.prototype.estimateGas = AbstractProvider.prototype.originalEstimate;
1174
- }
1175
- originalEstimate_1 = AbstractProvider.prototype.estimateGas;
1176
- oldEstimate = function (arg) {
1177
- return __awaiter(this, void 0, void 0, function () {
1178
- var originalEstimateFunc, gas;
1179
- return __generator(this, function (_a) {
1180
- switch (_a.label) {
1181
- case 0:
1182
- originalEstimateFunc = originalEstimate_1.bind(this);
1183
- return [4 /*yield*/, originalEstimateFunc(arg)];
1184
- case 1:
1185
- gas = _a.sent();
1186
- return [2 /*return*/, gas];
1187
- }
1188
- });
1189
- });
1190
- };
1191
- newEstimate = function (arg) {
1192
- return __awaiter(this, void 0, void 0, function () {
1193
- var L2EstimateGas, L1GasUsed, L1Fee, L2GasUsed;
1194
- return __generator(this, function (_a) {
1195
- switch (_a.label) {
1196
- case 0:
1197
- L2EstimateGas = originalEstimate_1.bind(this);
1198
- return [4 /*yield*/, curveInstance_1.contracts[curveInstance_1.constants.ALIASES.gas_oracle_blob].contract.getL1GasUsed(arg.data)];
1199
- case 1:
1200
- L1GasUsed = _a.sent();
1201
- return [4 /*yield*/, curveInstance_1.contracts[curveInstance_1.constants.ALIASES.gas_oracle_blob].contract.getL1Fee(arg.data)];
1202
- case 2:
1203
- L1Fee = _a.sent();
1204
- curveInstance_1.L1WeightedGasPrice = Number(L1Fee) / Number(L1GasUsed);
1205
- return [4 /*yield*/, L2EstimateGas(arg)];
1206
- case 3:
1207
- L2GasUsed = _a.sent();
1208
- return [2 /*return*/, [L2GasUsed, L1GasUsed]];
1209
- }
1210
- });
1211
- });
1212
- };
1213
- // @ts-ignore
1214
- AbstractProvider.prototype.estimateGas = newEstimate;
1215
- // @ts-ignore
1216
- AbstractProvider.prototype.originalEstimate = oldEstimate;
1217
- }
1218
- else {
1219
- // @ts-ignore
1220
- if (AbstractProvider.prototype.originalEstimate) {
1221
- // @ts-ignore
1222
- AbstractProvider.prototype.estimateGas = AbstractProvider.prototype.originalEstimate;
1223
- }
1224
- }
1225
- return [2 /*return*/];
843
+ const originalEstimateFunc = originalEstimate.bind(this);
844
+ const gas = yield originalEstimateFunc(arg);
845
+ return gas;
846
+ });
847
+ };
848
+ //Override
849
+ const newEstimate = function (arg) {
850
+ return __awaiter(this, void 0, void 0, function* () {
851
+ // @ts-ignore
852
+ const L2EstimateGas = originalEstimate.bind(this);
853
+ const L1GasUsed = yield curveInstance.contracts[curveInstance.constants.ALIASES.gas_oracle_blob].contract.getL1GasUsed(arg.data);
854
+ const L1Fee = yield curveInstance.contracts[curveInstance.constants.ALIASES.gas_oracle_blob].contract.getL1Fee(arg.data);
855
+ curveInstance.L1WeightedGasPrice = Number(L1Fee) / Number(L1GasUsed);
856
+ const L2GasUsed = yield L2EstimateGas(arg);
857
+ return [L2GasUsed, L1GasUsed];
858
+ });
859
+ };
860
+ // @ts-ignore
861
+ AbstractProvider.prototype.estimateGas = newEstimate;
862
+ // @ts-ignore
863
+ AbstractProvider.prototype.originalEstimate = oldEstimate;
864
+ }
865
+ else {
866
+ // @ts-ignore
867
+ if (AbstractProvider.prototype.originalEstimate) {
868
+ // @ts-ignore
869
+ AbstractProvider.prototype.estimateGas = AbstractProvider.prototype.originalEstimate;
1226
870
  }
1227
- });
871
+ }
1228
872
  });
1229
- };
1230
- Curve.prototype.setContract = function (address, abi) {
873
+ }
874
+ setContract(address, abi) {
1231
875
  // eslint-disable-next-line @typescript-eslint/no-this-alias
1232
- var curveInstance = this;
1233
- var proxyHandler = {
876
+ const curveInstance = this;
877
+ const proxyHandler = {
1234
878
  get: function (target, name) {
1235
879
  if (name === 'contract') {
1236
880
  return curveInstance.initContract(target['address'], target['abi'], curveInstance.signer || curveInstance.provider);
@@ -1243,71 +887,52 @@ var Curve = /** @class */ (function () {
1243
887
  }
1244
888
  },
1245
889
  };
1246
- var coreContract = {
1247
- address: address,
1248
- abi: abi,
890
+ const coreContract = {
891
+ address,
892
+ abi,
1249
893
  };
1250
894
  this.contracts[address] = new Proxy(coreContract, proxyHandler);
1251
- };
1252
- Curve.prototype._filterHiddenPools = function (pools) {
1253
- return __awaiter(this, void 0, void 0, function () {
1254
- var hiddenPools;
1255
- return __generator(this, function (_a) {
1256
- switch (_a.label) {
1257
- case 0: return [4 /*yield*/, _getHiddenPools()];
1258
- case 1:
1259
- hiddenPools = (_a.sent())[this.constants.NETWORK_NAME] || [];
1260
- // @ts-ignore
1261
- return [2 /*return*/, Object.fromEntries(Object.entries(pools).filter(function (_a) {
1262
- var id = _a[0];
1263
- return !hiddenPools.includes(id);
1264
- }))];
1265
- }
1266
- });
895
+ }
896
+ _filterHiddenPools(pools) {
897
+ return __awaiter(this, void 0, void 0, function* () {
898
+ const hiddenPools = (yield _getHiddenPools())[this.constants.NETWORK_NAME] || [];
899
+ // @ts-ignore
900
+ return Object.fromEntries(Object.entries(pools).filter(([id]) => !hiddenPools.includes(id)));
1267
901
  });
1268
- };
1269
- Curve.prototype._updateDecimalsAndGauges = function (pools) {
1270
- this.constants.DECIMALS = __assign(__assign({}, this.constants.DECIMALS), extractDecimals(pools));
1271
- this.constants.GAUGES = __spreadArray(__spreadArray([], this.constants.GAUGES, true), extractGauges(pools), true);
1272
- };
1273
- Curve.prototype.setCustomFeeData = function (customFeeData) {
1274
- this.feeData = __assign(__assign({}, this.feeData), customFeeData);
1275
- };
1276
- Curve.prototype.formatUnits = function (value, unit) {
902
+ }
903
+ _updateDecimalsAndGauges(pools) {
904
+ this.constants.DECIMALS = Object.assign(Object.assign({}, this.constants.DECIMALS), extractDecimals(pools));
905
+ this.constants.GAUGES = [...this.constants.GAUGES, ...extractGauges(pools)];
906
+ }
907
+ setCustomFeeData(customFeeData) {
908
+ this.feeData = Object.assign(Object.assign({}, this.feeData), customFeeData);
909
+ }
910
+ formatUnits(value, unit) {
1277
911
  return ethers.formatUnits(value, unit);
1278
- };
1279
- Curve.prototype.parseUnits = function (value, unit) {
912
+ }
913
+ parseUnits(value, unit) {
1280
914
  return ethers.parseUnits(value, unit);
1281
- };
1282
- Curve.prototype.updateFeeData = function () {
1283
- return __awaiter(this, void 0, void 0, function () {
1284
- var feeData;
1285
- return __generator(this, function (_a) {
1286
- switch (_a.label) {
1287
- case 0: return [4 /*yield*/, this.provider.getFeeData()];
1288
- case 1:
1289
- feeData = _a.sent();
1290
- if (feeData.maxFeePerGas === null || feeData.maxPriorityFeePerGas === null) {
1291
- delete this.options.maxFeePerGas;
1292
- delete this.options.maxPriorityFeePerGas;
1293
- this.options.gasPrice = this.feeData.gasPrice !== undefined ?
1294
- this.parseUnits(this.feeData.gasPrice.toString(), "gwei") :
1295
- (feeData.gasPrice || this.parseUnits("20", "gwei"));
1296
- }
1297
- else {
1298
- delete this.options.gasPrice;
1299
- this.options.maxFeePerGas = (this.feeData.maxFeePerGas !== undefined && this.feeData.maxFeePerGas !== null) ?
1300
- this.parseUnits(this.feeData.maxFeePerGas.toString(), "gwei") :
1301
- feeData.maxFeePerGas;
1302
- this.options.maxPriorityFeePerGas = (this.feeData.maxPriorityFeePerGas !== undefined && this.feeData.maxPriorityFeePerGas !== null) ?
1303
- this.parseUnits(this.feeData.maxPriorityFeePerGas.toString(), "gwei") :
1304
- feeData.maxPriorityFeePerGas;
1305
- }
1306
- return [2 /*return*/];
1307
- }
1308
- });
915
+ }
916
+ updateFeeData() {
917
+ return __awaiter(this, void 0, void 0, function* () {
918
+ const feeData = yield this.provider.getFeeData();
919
+ if (feeData.maxFeePerGas === null || feeData.maxPriorityFeePerGas === null) {
920
+ delete this.options.maxFeePerGas;
921
+ delete this.options.maxPriorityFeePerGas;
922
+ this.options.gasPrice = this.feeData.gasPrice !== undefined ?
923
+ this.parseUnits(this.feeData.gasPrice.toString(), "gwei") :
924
+ (feeData.gasPrice || this.parseUnits("20", "gwei"));
925
+ }
926
+ else {
927
+ delete this.options.gasPrice;
928
+ this.options.maxFeePerGas = (this.feeData.maxFeePerGas !== undefined && this.feeData.maxFeePerGas !== null) ?
929
+ this.parseUnits(this.feeData.maxFeePerGas.toString(), "gwei") :
930
+ feeData.maxFeePerGas;
931
+ this.options.maxPriorityFeePerGas = (this.feeData.maxPriorityFeePerGas !== undefined && this.feeData.maxPriorityFeePerGas !== null) ?
932
+ this.parseUnits(this.feeData.maxPriorityFeePerGas.toString(), "gwei") :
933
+ feeData.maxPriorityFeePerGas;
934
+ }
1309
935
  });
1310
- };
1311
- return Curve;
1312
- }());
1313
- export var curve = new Curve();
936
+ }
937
+ }
938
+ export const curve = new Curve();