@paraswap/dex-lib 2.12.12-rfqtests.1 → 2.12.12

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 (105) hide show
  1. package/build/abi/augustus.json +375 -0
  2. package/build/abi/woo-fi-v2/IntegrationHelper.abi.json +116 -0
  3. package/build/abi/woo-fi-v2/WooOracleV2.abi.json +358 -0
  4. package/build/abi/woo-fi-v2/WooPPV2.abi.json +580 -0
  5. package/build/config.js +3 -3
  6. package/build/dex/aave-v3/tokens/arbitrum.json +20 -20
  7. package/build/dex/aave-v3/tokens/avalanche.json +44 -20
  8. package/build/dex/aave-v3/tokens/fantom.json +30 -30
  9. package/build/dex/aave-v3/tokens/optimism.json +18 -18
  10. package/build/dex/aave-v3/tokens/polygon.json +60 -42
  11. package/build/dex/generic-rfq/rate-fetcher.js +0 -1
  12. package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
  13. package/build/dex/generic-rfq/validators.d.ts +1 -1
  14. package/build/dex/generic-rfq/validators.js +26 -36
  15. package/build/dex/generic-rfq/validators.js.map +1 -1
  16. package/build/dex/hashflow/rate-fetcher.d.ts +14 -0
  17. package/build/dex/hashflow/rate-fetcher.js +37 -0
  18. package/build/dex/hashflow/rate-fetcher.js.map +1 -0
  19. package/build/dex/hashflow/validators.d.ts +3 -0
  20. package/build/dex/hashflow/validators.js +12 -0
  21. package/build/dex/hashflow/validators.js.map +1 -0
  22. package/build/dex/{test-aave-v3 → test-dex}/config.d.ts +1 -1
  23. package/build/dex/{test-aave-v3 → test-dex}/config.js +3 -3
  24. package/build/dex/test-dex/config.js.map +1 -0
  25. package/build/dex/{test-aave-v3/test-aave-v3-pool.d.ts → test-dex/test-dex-pool.d.ts} +3 -3
  26. package/build/dex/{test-aave-v3/test-aave-v3-pool.js → test-dex/test-dex-pool.js} +7 -7
  27. package/build/dex/test-dex/test-dex-pool.js.map +1 -0
  28. package/build/dex/{test-aave-v3/test-aave-v3.d.ts → test-dex/test-dex.d.ts} +8 -8
  29. package/build/dex/{test-aave-v3/test-aave-v3.js → test-dex/test-dex.js} +7 -7
  30. package/build/dex/test-dex/test-dex.js.map +1 -0
  31. package/build/dex/{test-aave-v3 → test-dex}/types.d.ts +1 -1
  32. package/build/dex/{test-aave-v3 → test-dex}/types.js.map +1 -1
  33. package/build/dex/uniswap-v3/config.js +13 -0
  34. package/build/dex/uniswap-v3/config.js.map +1 -1
  35. package/build/dex/woo-fi-v2/config.d.ts +4 -0
  36. package/build/dex/woo-fi-v2/config.js +87 -0
  37. package/build/dex/woo-fi-v2/config.js.map +1 -0
  38. package/build/dex/woo-fi-v2/constants.d.ts +5 -0
  39. package/build/dex/woo-fi-v2/constants.js +15 -0
  40. package/build/dex/woo-fi-v2/constants.js.map +1 -0
  41. package/build/dex/woo-fi-v2/decoders.d.ts +6 -0
  42. package/build/dex/woo-fi-v2/decoders.js +29 -0
  43. package/build/dex/woo-fi-v2/decoders.js.map +1 -0
  44. package/build/dex/woo-fi-v2/types.d.ts +41 -0
  45. package/build/dex/woo-fi-v2/types.js +3 -0
  46. package/build/dex/woo-fi-v2/types.js.map +1 -0
  47. package/build/dex/woo-fi-v2/utils.d.ts +2 -0
  48. package/build/dex/woo-fi-v2/utils.js +24 -0
  49. package/build/dex/woo-fi-v2/utils.js.map +1 -0
  50. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
  51. package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
  52. package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
  53. package/build/dex/woo-fi-v2/woo-fi-v2-math.d.ts +16 -0
  54. package/build/dex/woo-fi-v2/woo-fi-v2-math.js +137 -0
  55. package/build/dex/woo-fi-v2/woo-fi-v2-math.js.map +1 -0
  56. package/build/dex/woo-fi-v2/woo-fi-v2-pool.d.ts +12 -0
  57. package/build/dex/woo-fi-v2/woo-fi-v2-pool.js +79 -0
  58. package/build/dex/woo-fi-v2/woo-fi-v2-pool.js.map +1 -0
  59. package/build/dex/woo-fi-v2/woo-fi-v2.d.ts +52 -0
  60. package/build/dex/woo-fi-v2/woo-fi-v2.js +310 -0
  61. package/build/dex/woo-fi-v2/woo-fi-v2.js.map +1 -0
  62. package/build/lib/log-messages-suppressor.d.ts +30 -0
  63. package/build/lib/log-messages-suppressor.js +107 -0
  64. package/build/lib/log-messages-suppressor.js.map +1 -0
  65. package/build/lib/stateful-rpc-poller/state-polling-manager.d.ts +23 -0
  66. package/build/lib/stateful-rpc-poller/state-polling-manager.js +173 -0
  67. package/build/lib/stateful-rpc-poller/state-polling-manager.js.map +1 -0
  68. package/build/lib/stateful-rpc-poller/stateful-rpc-poller.d.ts +72 -0
  69. package/build/lib/stateful-rpc-poller/stateful-rpc-poller.js +369 -0
  70. package/build/lib/stateful-rpc-poller/stateful-rpc-poller.js.map +1 -0
  71. package/build/lib/stateful-rpc-poller/types.d.ts +35 -0
  72. package/build/lib/stateful-rpc-poller/types.js +10 -0
  73. package/build/lib/stateful-rpc-poller/types.js.map +1 -0
  74. package/build/lib/stateful-rpc-poller/utils.d.ts +4 -0
  75. package/build/lib/stateful-rpc-poller/utils.js +17 -0
  76. package/build/lib/stateful-rpc-poller/utils.js.map +1 -0
  77. package/build/lib/validators.d.ts +7 -0
  78. package/build/lib/validators.js +27 -0
  79. package/build/lib/validators.js.map +1 -0
  80. package/package.json +1 -1
  81. package/src/config.ts +3 -3
  82. package/src/dex/generic-rfq/generic-rfq-e2e.test.ts +71 -85
  83. package/src/dex/generic-rfq/rate-fetcher.ts +0 -1
  84. package/src/dex/generic-rfq/validators.test.ts +32 -6
  85. package/src/dex/generic-rfq/validators.ts +32 -57
  86. package/src/dex/uniswap-v3/config.ts +13 -0
  87. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +76 -0
  88. package/tests/constants-e2e.ts +0 -2
  89. package/tests/utils-e2e.ts +48 -59
  90. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  91. package/.idea/misc.xml +0 -6
  92. package/.idea/modules.xml +0 -8
  93. package/.idea/vcs.xml +0 -6
  94. package/.vscode/launch.json +0 -21
  95. package/build/dex/aave-v3/tokens/mainnet.json +0 -44
  96. package/build/dex/balancer-v2/VirtualBoostedPool.d.ts +0 -79
  97. package/build/dex/balancer-v2/VirtualBoostedPool.js +0 -382
  98. package/build/dex/balancer-v2/VirtualBoostedPool.js.map +0 -1
  99. package/build/dex/test-aave-v3/config.js.map +0 -1
  100. package/build/dex/test-aave-v3/test-aave-v3-pool.js.map +0 -1
  101. package/build/dex/test-aave-v3/test-aave-v3.js.map +0 -1
  102. package/src/dex/generic-rfq/generic-rfq-e2e-arbitrum.test.ts +0 -360
  103. package/src/dex/generic-rfq/generic-rfq-e2e-bsc.test.ts +0 -346
  104. package/src/dex/generic-rfq/generic-rfq-e2e-polygon.test.ts +0 -360
  105. /package/build/dex/{test-aave-v3 → test-dex}/types.js +0 -0
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.WooFiV2 = void 0;
27
+ const constants_1 = require("../../constants");
28
+ const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
29
+ const utils_1 = require("../../utils");
30
+ const decoders_1 = require("../../lib/decoders");
31
+ const simple_exchange_1 = require("../simple-exchange");
32
+ const config_1 = require("./config");
33
+ const woo_fi_v2_pool_1 = require("./woo-fi-v2-pool");
34
+ const woo_fi_v2_math_1 = require("./woo-fi-v2-math");
35
+ const constants_2 = require("./constants");
36
+ const ts_essentials_1 = require("ts-essentials");
37
+ const ethers_1 = require("ethers");
38
+ const decoders_2 = require("../../lib/decoders");
39
+ const utils_2 = require("./utils");
40
+ const state_polling_manager_1 = require("../../lib/stateful-rpc-poller/state-polling-manager");
41
+ class WooFiV2 extends simple_exchange_1.SimpleExchange {
42
+ constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}, config = config_1.WooFiV2Config[dexKey][network]) {
43
+ super(dexHelper, dexKey);
44
+ this.network = network;
45
+ this.dexHelper = dexHelper;
46
+ this.adapters = adapters;
47
+ this.config = config;
48
+ this.hasConstantPriceLargeAmounts = false;
49
+ this.needWrapNative = true;
50
+ this.isFeeOnTransferSupported = false;
51
+ this.vaultUSDBalance = 0;
52
+ const loggerName = `${dexKey}-${network}`;
53
+ this.logger = dexHelper.getLogger(loggerName);
54
+ // Normalise once all config addresses and use across all scenarios
55
+ this.config = this._toLowerForAllConfigAddresses();
56
+ this.quoteTokenAddress = this.config.quoteToken.address;
57
+ // Do not do it singleton, because different networks will have different
58
+ // states at the same time
59
+ this.math = new woo_fi_v2_math_1.WooFiV2Math(dexHelper.getLogger(`${loggerName}_math`), this.quoteTokenAddress);
60
+ this.pollingManager = state_polling_manager_1.StatePollingManager.getInstance(dexHelper);
61
+ }
62
+ _toLowerForAllConfigAddresses() {
63
+ // If new config property will be added, the TS will throw compile error
64
+ const newConfig = {
65
+ wooPPV2Address: this.config.wooPPV2Address.toLowerCase(),
66
+ wooOracleV2Address: this.config.wooOracleV2Address.toLowerCase(),
67
+ integrationHelperAddress: this.config.integrationHelperAddress.toLowerCase(),
68
+ quoteToken: {
69
+ ...this.config.quoteToken,
70
+ address: this.config.quoteToken.address.toLowerCase(),
71
+ },
72
+ };
73
+ return newConfig;
74
+ }
75
+ get baseTokens() {
76
+ if (!this._baseTokens) {
77
+ throw new Error(`Base tokens are not set for ${this.dexKey}-${this.network}. Not properly initialized`);
78
+ }
79
+ return this._baseTokens;
80
+ }
81
+ async initializePricing(blockNumber) {
82
+ await this.initializeTokensAndAddresses();
83
+ this._initializePollingPool();
84
+ }
85
+ getAdapters(side) {
86
+ return this.adapters[side] ? this.adapters[side] : null;
87
+ }
88
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
89
+ if (side === constants_1.SwapSide.BUY)
90
+ return [];
91
+ if (this.tokenByAddress === undefined) {
92
+ this.logger.error(`tokenByAddress is undefined in getPoolIdentifiers`);
93
+ return [];
94
+ }
95
+ const _srcToken = this.dexHelper.config.wrapETH(srcToken);
96
+ const _destToken = this.dexHelper.config.wrapETH(destToken);
97
+ const _srcAddress = _srcToken.address.toLowerCase();
98
+ const _destAddress = _destToken.address.toLowerCase();
99
+ if (_srcAddress === _destAddress)
100
+ return [];
101
+ if (!this.tokenByAddress[_srcAddress] ||
102
+ !this.tokenByAddress[_destAddress]) {
103
+ return [];
104
+ }
105
+ return [this.getIdentifier()];
106
+ }
107
+ getIdentifier() {
108
+ return `${this.dexKey}_wooppv2`;
109
+ }
110
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
111
+ if (side === constants_1.SwapSide.BUY)
112
+ return null;
113
+ try {
114
+ if (this.tokenByAddress === undefined) {
115
+ this.logger.error(`tokenByAddress is undefined in getPricesVolume`);
116
+ return null;
117
+ }
118
+ const _srcToken = this.dexHelper.config.wrapETH(srcToken);
119
+ const _destToken = this.dexHelper.config.wrapETH(destToken);
120
+ const _srcAddress = _srcToken.address.toLowerCase();
121
+ const _destAddress = _destToken.address.toLowerCase();
122
+ if (_srcAddress === _destAddress)
123
+ return null;
124
+ if (!this.tokenByAddress[_srcAddress] ||
125
+ !this.tokenByAddress[_destAddress])
126
+ return null;
127
+ const expectedIdentifier = this.getIdentifier();
128
+ if (limitPools !== undefined &&
129
+ !limitPools.some(p => p === expectedIdentifier))
130
+ return null;
131
+ const unitVolume = (0, utils_1.getBigIntPow)(_srcToken.decimals);
132
+ const _amounts = [unitVolume, ...amounts.slice(1)];
133
+ (0, ts_essentials_1.assert)(this.pollingPool, 'pollingPool is not initialized in getPricesVolume');
134
+ const state = await this.pollingPool.getState(blockNumber);
135
+ if (state === null) {
136
+ this.logger.error(`State is null in getPricesVolume`);
137
+ return null;
138
+ }
139
+ if (state.value.isPaused) {
140
+ this.logger.warn(`${this.dexKey} is paused on ${this.network} in getPricesVolume`);
141
+ return null;
142
+ }
143
+ this.math.state = state.value;
144
+ const _prices = this.math.query(_srcAddress, _destAddress, _amounts);
145
+ if (!_prices)
146
+ return null;
147
+ const unit = _prices[0];
148
+ return [
149
+ {
150
+ unit,
151
+ prices: [0n, ..._prices.slice(1)],
152
+ data: {},
153
+ poolIdentifier: expectedIdentifier,
154
+ exchange: this.dexKey,
155
+ gasCost: constants_2.WOO_FI_V2_GAS_COST,
156
+ poolAddresses: [this.config.wooPPV2Address],
157
+ },
158
+ ];
159
+ }
160
+ catch (e) {
161
+ this.logger.error(`Error_getPricesVolume ${srcToken.symbol || srcToken.address}, ${destToken.symbol || destToken.address}, ${side}:`, e);
162
+ return null;
163
+ }
164
+ }
165
+ getCalldataGasCost(poolPrices) {
166
+ return CALLDATA_GAS_COST.DEX_OVERHEAD + CALLDATA_GAS_COST.ADDRESS;
167
+ }
168
+ getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
169
+ if (side === constants_1.SwapSide.BUY)
170
+ throw new Error(`Buy not supported`);
171
+ let rebateTo = this.rebateTo;
172
+ if (rebateTo === undefined) {
173
+ this.logger.error(`rebateTo is undefined in getAdapterParam`);
174
+ rebateTo = constants_1.NULL_ADDRESS;
175
+ }
176
+ const payload = this.abiCoder.encodeParameter('address', rebateTo);
177
+ return {
178
+ targetExchange: this.config.wooPPV2Address,
179
+ payload,
180
+ networkFee: '0',
181
+ };
182
+ }
183
+ async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
184
+ if (side === constants_1.SwapSide.BUY)
185
+ throw new Error(`Buy not supported`);
186
+ const _srcToken = srcToken.toLowerCase();
187
+ const _destToken = destToken.toLowerCase();
188
+ let rebateTo = this.rebateTo;
189
+ if (rebateTo === undefined) {
190
+ this.logger.error(`rebateTo is undefined in getAdapterParam`);
191
+ rebateTo = constants_1.NULL_ADDRESS;
192
+ }
193
+ const swapData = utils_2.ifaces.PPV2.encodeFunctionData('swap', [
194
+ _srcToken,
195
+ _destToken,
196
+ srcAmount,
197
+ constants_2.MIN_CONVERSION_RATE,
198
+ this.augustusAddress,
199
+ rebateTo,
200
+ ]);
201
+ const transferParams = this.erc20Interface.encodeFunctionData('transfer', [
202
+ this.config.wooPPV2Address,
203
+ srcAmount,
204
+ ]);
205
+ return {
206
+ callees: [srcToken, this.config.wooPPV2Address],
207
+ calldata: [transferParams, swapData],
208
+ values: ['0', '0'],
209
+ networkFee: '0',
210
+ };
211
+ }
212
+ async updatePoolState() {
213
+ await this.initializeTokensAndAddresses();
214
+ this._initializePollingPool();
215
+ if (this.tokenByAddress === undefined) {
216
+ this.logger.error(`tokenByAddress is undefined in updatePoolState`);
217
+ return;
218
+ }
219
+ (0, ts_essentials_1.assert)(this.pollingPool, 'pollingPool is not initialized in updatePoolState');
220
+ const state = await this.pollingPool.getState();
221
+ if (!state) {
222
+ this.logger.error(`Failed to updatePoolState. State is null. VaultUSDBalance: ${this.vaultUSDBalance} was not updated`);
223
+ return;
224
+ }
225
+ const tokenBalancesUSD = await Promise.all(Object.values(this.tokenByAddress).map(t => this.dexHelper.getTokenUSDPrice(t, state.value.tokenInfos[t.address].reserve)));
226
+ this.vaultUSDBalance = tokenBalancesUSD.reduce((sum, curr) => sum + curr);
227
+ }
228
+ async getTopPoolsForToken(tokenAddress, limit) {
229
+ const wrappedTokenAddress = this.dexHelper.config
230
+ .wrapETH({ address: tokenAddress, decimals: 0 })
231
+ .address.toLowerCase();
232
+ if (this.tokenByAddress === undefined) {
233
+ this.logger.error(`tokenByAddress is undefined in getTopPoolsForToken`);
234
+ return [];
235
+ }
236
+ if (!this.tokenByAddress[wrappedTokenAddress])
237
+ return [];
238
+ (0, ts_essentials_1.assert)(this.pollingPool, 'pollingPool is not initialized in getTopPoolsForToken');
239
+ const latestState = await this.pollingPool.getState();
240
+ if (!latestState)
241
+ return [];
242
+ if (latestState.value.isPaused) {
243
+ this.logger.warn(`Paused on ${this.network} in getTopPoolsForToken`);
244
+ return [];
245
+ }
246
+ const connectorTokens = wrappedTokenAddress === this.quoteTokenAddress
247
+ ? this.baseTokens
248
+ : [this.tokenByAddress[this.quoteTokenAddress]];
249
+ return [
250
+ {
251
+ exchange: this.dexKey,
252
+ address: this.config.wooPPV2Address,
253
+ connectorTokens,
254
+ liquidityUSD: this.vaultUSDBalance,
255
+ },
256
+ ];
257
+ }
258
+ _initializeTokenByAddress(baseTokens) {
259
+ this.tokenByAddress = baseTokens.reduce((acc, cur) => {
260
+ acc[cur.address] = cur;
261
+ return acc;
262
+ }, { [this.quoteTokenAddress]: this.config.quoteToken });
263
+ }
264
+ async _fetchBaseTokensAndFeeWallet() {
265
+ return (await this.dexHelper.multiWrapper.aggregate([
266
+ {
267
+ target: this.augustusAddress,
268
+ callData: this.augustusInterface.encodeFunctionData('getFeeWallet', []),
269
+ decodeFunction: decoders_2.addressDecode,
270
+ },
271
+ {
272
+ target: this.config.integrationHelperAddress,
273
+ callData: utils_2.ifaces.integrationHelper.encodeFunctionData('allBaseTokens'),
274
+ decodeFunction: decoders_1.addressArrayDecode,
275
+ },
276
+ ])).flat();
277
+ }
278
+ async _fetchDecimals(baseTokenAddresses) {
279
+ return this.dexHelper.multiWrapper.aggregate(baseTokenAddresses.map(address => {
280
+ return {
281
+ target: address,
282
+ callData: this.erc20Interface.encodeFunctionData('decimals'),
283
+ decodeFunction: decoders_1.uint8ToNumber,
284
+ };
285
+ }));
286
+ }
287
+ async initializeTokensAndAddresses() {
288
+ const [rebateTo, ...baseTokenAddresses] = await this._fetchBaseTokensAndFeeWallet();
289
+ (0, ts_essentials_1.assert)(ethers_1.ethers.utils.isAddress(rebateTo), 'Invalid rebateTo address');
290
+ this.rebateTo = rebateTo;
291
+ const decimals = await this._fetchDecimals(baseTokenAddresses);
292
+ (0, ts_essentials_1.assert)(decimals.length === baseTokenAddresses.length, 'Decimals length mismatch');
293
+ this._baseTokens = baseTokenAddresses.reduce((acc, curr, i) => {
294
+ acc.push({
295
+ address: curr,
296
+ decimals: decimals[i],
297
+ });
298
+ return acc;
299
+ }, []);
300
+ this._initializeTokenByAddress(this.baseTokens);
301
+ }
302
+ _initializePollingPool() {
303
+ (0, ts_essentials_1.assert)(this.tokenByAddress, 'tokenByAddress is not properly');
304
+ this.pollingPool = new woo_fi_v2_pool_1.WooFiV2PollingPool(this.dexKey, this.getIdentifier(), this.dexHelper, this.config, Object.values(this.tokenByAddress));
305
+ this.pollingManager.initializeAllPendingPools();
306
+ }
307
+ }
308
+ exports.WooFiV2 = WooFiV2;
309
+ WooFiV2.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.WooFiV2Config);
310
+ //# sourceMappingURL=woo-fi-v2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"woo-fi-v2.js","sourceRoot":"","sources":["../../../src/dex/woo-fi-v2/woo-fi-v2.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,+CAAkE;AAClE,2EAA6D;AAC7D,uCAAkE;AAElE,iDAAuE;AAGvE,wDAAoD;AACpD,qCAAmD;AACnD,qDAAsD;AACtD,qDAA+C;AAC/C,2CAAsE;AACtE,iDAAuC;AACvC,mCAAg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AE,QAAQ,CAAC,CAAC,CAAC;aACtB,CAAC,CAAC;YACH,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClD,CAAC;IAEO,sBAAsB;QAC5B,IAAA,sBAAM,EAAC,IAAI,CAAC,cAAc,EAAE,gCAAgC,CAAC,CAAC;QAE9D,IAAI,CAAC,WAAW,GAAG,IAAI,mCAAkB,CACvC,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,aAAa,EAAE,EACpB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,MAAM,EACX,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CACnC,CAAC;QAEF,IAAI,CAAC,cAAc,CAAC,yBAAyB,EAAE,CAAC;IAClD,CAAC;;AAtbH,0BAubC;AAjae,0BAAkB,GAC9B,IAAA,6BAAqB,EAAC,sBAAa,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { Logger, LogLevels } from '../types';
2
+ export declare const DEFAULT_LOG_PUBLISH_PERIOD_MS = 60000;
3
+ export declare const DEFAULT_LOG_DISCARD_PERIOD_MS: number;
4
+ export declare const DEFAULT_LOG_MAX_IDENTITIES_TO_SHOW = 10;
5
+ export declare type StandardStringEnum = Readonly<Record<string, string>>;
6
+ export declare type MessageInfo<T extends StandardStringEnum> = {
7
+ key: keyof T;
8
+ message: T[keyof T];
9
+ logLevel: LogLevels;
10
+ };
11
+ export declare type MessageData = {
12
+ counter: number;
13
+ lastLoggedAtMs: number;
14
+ identificationInfos: string[];
15
+ };
16
+ export declare type AggregatedLogForEntity<T extends StandardStringEnum> = {
17
+ [key in keyof T]?: MessageData;
18
+ };
19
+ export declare class LogMessagesSuppressor<T extends StandardStringEnum> {
20
+ readonly entityName: string;
21
+ private _allMessages;
22
+ protected logger: Logger;
23
+ static instances: Record<string, LogMessagesSuppressor<any>>;
24
+ private _aggregatedLogs;
25
+ constructor(entityName: string, _allMessages: Record<keyof T, MessageInfo<T>>, logger: Logger);
26
+ static getLogSuppressorInstance<T extends StandardStringEnum>(entityName: string, allMessages: Record<keyof T, MessageInfo<T>>, logger: Logger): LogMessagesSuppressor<any>;
27
+ logMessage(msgKey: keyof T, identificationInfo?: string, ...args: unknown[]): void;
28
+ private _formatLogMessage;
29
+ private _clearMessageData;
30
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LogMessagesSuppressor = exports.DEFAULT_LOG_MAX_IDENTITIES_TO_SHOW = exports.DEFAULT_LOG_DISCARD_PERIOD_MS = exports.DEFAULT_LOG_PUBLISH_PERIOD_MS = void 0;
7
+ const ts_essentials_1 = require("ts-essentials");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ exports.DEFAULT_LOG_PUBLISH_PERIOD_MS = 60000;
10
+ // After this period previous logs, even if unpublished, would be discarded
11
+ // Because most likely they are outdated
12
+ exports.DEFAULT_LOG_DISCARD_PERIOD_MS = 15 * 60 * 1000;
13
+ // We may have hundreds of pools failing at the same time,
14
+ // and we don't want to show them all
15
+ exports.DEFAULT_LOG_MAX_IDENTITIES_TO_SHOW = 10;
16
+ /*
17
+ * This is helper module to reduce frequency of logging of spamming messages
18
+ *
19
+ * 1. You can only have predefined set of log messages to log
20
+ * First time log message is received, it is published with all arguments.
21
+ * Limitation - message can not include variables, but you can pass them as args
22
+ * If within cooldown period received another message of the same category, it
23
+ * is not published, but counter is increased with addition of some entity identifier
24
+ *
25
+ * 2. There is no background task running. In order to keep relevance of logs,
26
+ * if after certain amount of time we didn't receive logs, then we discarded accumulated ones
27
+ * on the next received ones and only publish relevant ones
28
+ */
29
+ class LogMessagesSuppressor {
30
+ constructor(entityName, _allMessages, logger) {
31
+ this.entityName = entityName;
32
+ this._allMessages = _allMessages;
33
+ this.logger = logger;
34
+ this._aggregatedLogs = {};
35
+ }
36
+ static getLogSuppressorInstance(entityName, allMessages, logger) {
37
+ const instance = LogMessagesSuppressor.instances[entityName];
38
+ if (instance === undefined) {
39
+ LogMessagesSuppressor.instances[entityName] =
40
+ new LogMessagesSuppressor(entityName, allMessages, logger);
41
+ }
42
+ else {
43
+ (0, ts_essentials_1.assert)(lodash_1.default.isEqual(allMessages, instance._allMessages), 'getLogSuppressorInstance: try to get existing instance with different allMessagesInfo');
44
+ (0, ts_essentials_1.assert)(lodash_1.default.isEqual(logger, instance.logger), 'getLogSuppressorInstance: try to get existing instance with different logger');
45
+ }
46
+ return LogMessagesSuppressor.instances[entityName];
47
+ }
48
+ logMessage(msgKey, identificationInfo = '', ...args) {
49
+ const msgInfo = this._allMessages[msgKey];
50
+ (0, ts_essentials_1.assert)(msgInfo !== undefined, `Used unrecognized msgKey=${String(msgKey)} to get msgInfo`);
51
+ if (this._aggregatedLogs[msgKey] === undefined) {
52
+ this._aggregatedLogs[msgKey] = {
53
+ counter: 0,
54
+ identificationInfos: identificationInfo === '' ? [] : [identificationInfo],
55
+ lastLoggedAtMs: 0,
56
+ };
57
+ }
58
+ const msgData = this._aggregatedLogs[msgKey];
59
+ (0, ts_essentials_1.assert)(msgData !== undefined, `msgData is undefined for msgKey=${String(msgKey)}`);
60
+ const nowMs = Date.now();
61
+ const elapsedSinceLastPublish = nowMs - msgData.lastLoggedAtMs;
62
+ if (elapsedSinceLastPublish > exports.DEFAULT_LOG_PUBLISH_PERIOD_MS) {
63
+ // Accumulated logs are too old to have any relevance, so better to discard them
64
+ if (elapsedSinceLastPublish > exports.DEFAULT_LOG_DISCARD_PERIOD_MS) {
65
+ this._clearMessageData(msgData);
66
+ }
67
+ // Make actual logging
68
+ // Logging is done using original logger of the entity to keep module info
69
+ // and not override it
70
+ this.logger[msgInfo.logLevel](this._formatLogMessage(msgData, msgInfo.message), ...args);
71
+ this._clearMessageData(msgData);
72
+ }
73
+ else {
74
+ msgData.counter++;
75
+ if (identificationInfo !== '') {
76
+ msgData.identificationInfos.push(identificationInfo);
77
+ }
78
+ }
79
+ }
80
+ _formatLogMessage(msgData, message) {
81
+ const { counter, identificationInfos } = msgData;
82
+ let identities = identificationInfos && identificationInfos.length === 0
83
+ ? ''
84
+ : ` for entities: ${identificationInfos.length > exports.DEFAULT_LOG_MAX_IDENTITIES_TO_SHOW
85
+ ? identificationInfos
86
+ .slice(exports.DEFAULT_LOG_MAX_IDENTITIES_TO_SHOW)
87
+ .join(',')
88
+ : identificationInfos.join(',')}`;
89
+ if (identificationInfos &&
90
+ identificationInfos.length > exports.DEFAULT_LOG_MAX_IDENTITIES_TO_SHOW) {
91
+ identities = `${identities}... ${identificationInfos.length} total`;
92
+ }
93
+ return `${this.entityName}: logged ${counter} occurrences of: "${message}"${identities}. `;
94
+ }
95
+ _clearMessageData(messageData) {
96
+ messageData.counter = 0;
97
+ if (messageData.identificationInfos) {
98
+ messageData.identificationInfos.length = 0;
99
+ }
100
+ messageData.lastLoggedAtMs = Date.now();
101
+ }
102
+ }
103
+ exports.LogMessagesSuppressor = LogMessagesSuppressor;
104
+ // I don't really like this any, but couldn't come up with better solution
105
+ // in reasonable time. So, in order to unblock myself, do this
106
+ LogMessagesSuppressor.instances = {};
107
+ //# sourceMappingURL=log-messages-suppressor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-messages-suppressor.js","sourceRoot":"","sources":["../../src/lib/log-messages-suppressor.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAuC;AACvC,oDAAuB;AAGV,QAAA,6BAA6B,GAAG,KAAM,CAAC;AAEpD,2EAA2E;AAC3E,wCAAwC;AAC3B,QAAA,6BAA6B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE5D,0DAA0D;AAC1D,qCAAqC;AACxB,QAAA,kCAAkC,GAAG,EAAE,CAAC;AAoBrD;;;;;;;;;;;;GAYG;AAEH,MAAa,qBAAqB;IAOhC,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AK,CAAC,0CAAkC,CAAC;qBACzC,IAAI,CAAC,GAAG,CAAC;gBACd,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAClC,EAAE,CAAC;QAET,IACE,mBAAmB;YACnB,mBAAmB,CAAC,MAAM,GAAG,0CAAkC,EAC/D;YACA,UAAU,GAAG,GAAG,UAAU,OAAO,mBAAmB,CAAC,MAAM,QAAQ,CAAC;SACrE;QAED,OAAO,GAAG,IAAI,CAAC,UAAU,YAAY,OAAO,qBAAqB,OAAO,IAAI,UAAU,IAAI,CAAC;IAC7F,CAAC;IAEO,iBAAiB,CAAC,WAAwB;QAChD,WAAW,CAAC,OAAO,GAAG,CAAC,CAAC;QACxB,IAAI,WAAW,CAAC,mBAAmB,EAAE;YACnC,WAAW,CAAC,mBAAmB,CAAC,MAAM,GAAG,CAAC,CAAC;SAC5C;QACD,WAAW,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC1C,CAAC;;AAnHH,sDAoHC;AAnHC,0EAA0E;AAC1E,8DAA8D;AACvD,+BAAS,GAA+C,EAAE,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { IDexHelper } from '../../dex-helper';
2
+ import { IStatefulRpcPoller } from './types';
3
+ export declare class StatePollingManager {
4
+ protected dexHelper: IDexHelper;
5
+ private static __instances;
6
+ static getInstance(dexHelper: IDexHelper): StatePollingManager;
7
+ private _lastProcessedBlockNumber;
8
+ private logger;
9
+ private _registeredPendingPools;
10
+ private _poolsToInstances;
11
+ private _poolsToBeUpdated;
12
+ private _idlePools;
13
+ private constructor();
14
+ get isMaster(): boolean;
15
+ enableStateTracking(identifierKey: string): void;
16
+ disableStateTracking(identifierKey: string): void;
17
+ onBlockNumber(blockNumber: number): Promise<void>;
18
+ protected _updatePoolStates(poolsToBeUpdated: IStatefulRpcPoller<any, any>[], blockNumber?: number | 'latest', numberOfChunks?: number): Promise<number>;
19
+ private _keyToPoolInstance;
20
+ initializeAllPendingPools(): void;
21
+ registerPendingPool<T, M>(statefulRpcPoller: IStatefulRpcPoller<T, M>): void;
22
+ initializePool<T, M>(statefulRpcPoller: IStatefulRpcPoller<T, M>): void;
23
+ }