• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-client-gateway / 14839292980

05 May 2025 02:48PM UTC coverage: 90.288% (-0.2%) from 90.497%
14839292980

push

github

web-flow
feat(amqp): add heartbeat and reconnect time configuration options (#2572)

This PR introduces configuration options for the AMQP heartbeat interval and reconnect time, improving connection stability and management. Previously, these values were not configurable, which could result in the client prematurely closing the connection.

3291 of 3975 branches covered (82.79%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

51 existing lines in 8 files now uncovered.

11389 of 12284 relevant lines covered (92.71%)

559.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.31
/src/datasources/cache/cache.router.ts
1
import crypto from 'crypto';
188✔
2
import { CacheDir } from '@/datasources/cache/entities/cache-dir.entity';
188✔
3

4
export class CacheRouter {
188✔
5
  private static readonly ACCOUNT_DATA_SETTINGS_KEY = 'account_data_settings';
188✔
6
  private static readonly ACCOUNT_DATA_TYPES_KEY = 'account_data_types';
188✔
7
  private static readonly ACCOUNT_KEY = 'account';
188✔
8
  private static readonly ALL_TRANSACTIONS_KEY = 'all_transactions';
188✔
9
  private static readonly AUTH_NONCE_KEY = 'auth_nonce';
188✔
10
  private static readonly BACKBONE_KEY = 'backbone';
188✔
11
  private static readonly CHAIN_KEY = 'chain';
188✔
12
  private static readonly CHAINS_KEY = 'chains';
188✔
13
  private static readonly CONTRACT_KEY = 'contract';
188✔
14
  private static readonly TRUSTED_FOR_DELEGATE_CALL_CONTRACTS_KEY =
188✔
15
    'trusted_contracts';
16
  private static readonly COUNTERFACTUAL_SAFE_KEY = 'counterfactual_safe';
188✔
17
  private static readonly COUNTERFACTUAL_SAFES_KEY = 'counterfactual_safes';
188✔
18
  private static readonly CREATION_TRANSACTION_KEY = 'creation_transaction';
188✔
19
  private static readonly DELEGATES_KEY = 'delegates';
188✔
20
  private static readonly FIREBASE_OAUTH2_TOKEN_KEY = 'firebase_oauth2_token';
188✔
21
  private static readonly INCOMING_TRANSFERS_KEY = 'incoming_transfers';
188✔
22
  private static readonly INDEXING_KEY = 'indexing';
188✔
23
  private static readonly MESSAGE_KEY = 'message';
188✔
24
  private static readonly MESSAGES_KEY = 'messages';
188✔
25
  private static readonly MODULE_TRANSACTION_KEY = 'module_transaction';
188✔
26
  private static readonly MODULE_TRANSACTIONS_KEY = 'module_transactions';
188✔
27
  private static readonly MULTISIG_TRANSACTION_KEY = 'multisig_transaction';
188✔
28
  private static readonly MULTISIG_TRANSACTIONS_KEY = 'multisig_transactions';
188✔
29
  private static readonly NATIVE_COIN_PRICE_KEY = 'native_coin_price';
188✔
30
  private static readonly OWNERS_SAFE_KEY = 'owner_safes';
188✔
31
  private static readonly RATE_LIMIT_KEY = 'rate_limit';
188✔
32
  private static readonly RELAY_KEY = 'relay';
188✔
33
  private static readonly RPC_REQUESTS_KEY = 'rpc_requests';
188✔
34
  private static readonly SAFE_APPS_KEY = 'safe_apps';
188✔
35
  private static readonly SAFE_BALANCES_KEY = 'safe_balances';
188✔
36
  private static readonly SAFE_COLLECTIBLES_KEY = 'safe_collectibles';
188✔
37
  private static readonly SAFE_EXISTS_KEY = 'safe_exists';
188✔
38
  private static readonly SAFE_FIAT_CODES_KEY = 'safe_fiat_codes';
188✔
39
  private static readonly SAFE_KEY = 'safe';
188✔
40
  private static readonly SINGLETONS_KEY = 'singletons';
188✔
41
  private static readonly STAKING_DEDICATED_STAKING_STATS_KEY =
188✔
42
    'staking_dedicated_staking_stats';
43
  private static readonly STAKING_DEFI_VAULT_STATS_KEY =
188✔
44
    'staking_defi_vault_stats';
45
  private static readonly STAKING_DEFI_VAULT_STAKES_KEY =
188✔
46
    'staking_defi_vault_stakes';
47
  private static readonly STAKING_DEFI_MORPHO_EXTRA_REWARDS_KEY =
188✔
48
    'staking_defi_morpho_extra_rewards';
49
  private static readonly STAKING_DEPLOYMENTS_KEY = 'staking_deployments';
188✔
50
  private static readonly STAKING_NETWORK_STATS_KEY = 'staking_network_stats';
188✔
51
  private static readonly STAKING_POOLED_STAKING_STATS_KEY =
188✔
52
    'staking_pooled_staking_stats';
53
  private static readonly STAKING_STAKES_KEY = 'staking_stakes';
188✔
54
  private static readonly STAKING_TRANSACTION_STATUS_KEY =
188✔
55
    'staking_transaction_status';
56
  private static readonly TARGETED_MESSAGING_OUTREACHES =
188✔
57
    'targeted_messaging_outreaches';
58
  private static readonly TARGETED_MESSAGING_OUTREACH_FILE_PROCESSOR_LOCK =
188✔
59
    'targeted_messaging_outreach_file_processor_lock';
60
  private static readonly TARGETED_MESSAGING_SUBMISSION_KEY =
188✔
61
    'targeted_messaging_submission';
62
  private static readonly TARGETED_MESSAGING_TARGETED_SAFE_KEY =
188✔
63
    'targeted_messaging_targeted_safe';
64
  private static readonly TOKEN_KEY = 'token';
188✔
65
  private static readonly TOKEN_PRICE_KEY = 'token_price';
188✔
66
  private static readonly TOKENS_KEY = 'tokens';
188✔
67
  private static readonly TRANSFER_KEY = 'transfer';
188✔
68
  private static readonly TRANSFERS_KEY = 'transfers';
188✔
69
  private static readonly UNSUPPORTED_CHAIN_EVENT = 'unsupported_chain_event';
188✔
70
  private static readonly ZERION_BALANCES_KEY = 'zerion_balances';
188✔
71
  private static readonly ZERION_COLLECTIBLES_KEY = 'zerion_collectibles';
188✔
72

73
  static getAuthNonceCacheKey(nonce: string): string {
74
    return `${CacheRouter.AUTH_NONCE_KEY}_${nonce}`;
106✔
75
  }
76

77
  static getAuthNonceCacheDir(nonce: string): CacheDir {
78
    return new CacheDir(CacheRouter.getAuthNonceCacheKey(nonce), '');
106✔
79
  }
80

81
  static getBalancesCacheKey(args: {
82
    chainId: string;
83
    safeAddress: `0x${string}`;
84
  }): string {
85
    return `${args.chainId}_${CacheRouter.SAFE_BALANCES_KEY}_${args.safeAddress}`;
100✔
86
  }
87

88
  static getBalancesCacheDir(args: {
89
    chainId: string;
90
    safeAddress: `0x${string}`;
91
    trusted?: boolean;
92
    excludeSpam?: boolean;
93
  }): CacheDir {
94
    return new CacheDir(
60✔
95
      CacheRouter.getBalancesCacheKey(args),
96
      `${args.trusted}_${args.excludeSpam}`,
97
    );
98
  }
99

100
  static getZerionBalancesCacheKey(args: {
101
    chainId: string;
102
    safeAddress: `0x${string}`;
103
  }): string {
104
    return `${args.chainId}_${CacheRouter.ZERION_BALANCES_KEY}_${args.safeAddress}`;
24✔
105
  }
106

107
  static getZerionBalancesCacheDir(args: {
108
    chainId: string;
109
    safeAddress: `0x${string}`;
110
    fiatCode: string;
111
  }): CacheDir {
112
    return new CacheDir(
24✔
113
      CacheRouter.getZerionBalancesCacheKey(args),
114
      args.fiatCode,
115
    );
116
  }
117

118
  static getZerionCollectiblesCacheKey(args: {
119
    chainId: string;
120
    safeAddress: `0x${string}`;
121
  }): string {
122
    return `${args.chainId}_${CacheRouter.ZERION_COLLECTIBLES_KEY}_${args.safeAddress}`;
8✔
123
  }
124

125
  static getZerionCollectiblesCacheDir(args: {
126
    chainId: string;
127
    safeAddress: `0x${string}`;
128
    limit?: number;
129
    offset?: number;
130
  }): CacheDir {
131
    return new CacheDir(
8✔
132
      CacheRouter.getZerionCollectiblesCacheKey(args),
133
      `${args.limit}_${args.offset}`,
134
    );
135
  }
136

137
  static getRateLimitCacheKey(prefix: string): string {
138
    return `${prefix}_${CacheRouter.RATE_LIMIT_KEY}`;
358✔
139
  }
140

141
  static getSafeCacheDir(args: {
142
    chainId: string;
143
    safeAddress: `0x${string}`;
144
  }): CacheDir {
145
    return new CacheDir(CacheRouter.getSafeCacheKey(args), '');
856✔
146
  }
147

148
  static getSafeCacheKey(args: {
149
    chainId: string;
150
    safeAddress: `0x${string}`;
151
  }): string {
152
    return `${args.chainId}_${CacheRouter.SAFE_KEY}_${args.safeAddress}`;
888✔
153
  }
154

155
  static getIsSafeCacheDir(args: {
156
    chainId: string;
157
    safeAddress: `0x${string}`;
158
  }): CacheDir {
159
    return new CacheDir(CacheRouter.getIsSafeCacheKey(args), '');
68✔
160
  }
161

162
  static getIsSafeCacheKey(args: {
163
    chainId: string;
164
    safeAddress: `0x${string}`;
165
  }): string {
166
    return `${args.chainId}_${CacheRouter.SAFE_EXISTS_KEY}_${args.safeAddress}`;
72✔
167
  }
168

169
  static getContractCacheDir(args: {
170
    chainId: string;
171
    contractAddress: `0x${string}`;
172
  }): CacheDir {
173
    return new CacheDir(
1,322✔
174
      `${args.chainId}_${CacheRouter.CONTRACT_KEY}_${args.contractAddress}`,
175
      '',
176
    );
177
  }
178

179
  static getTrustedForDelegateCallContractsCacheKey(chainId: string): string {
180
    return `${chainId}_${CacheRouter.TRUSTED_FOR_DELEGATE_CALL_CONTRACTS_KEY}`;
16✔
181
  }
182

183
  static getTrustedForDelegateCallContractsCacheDir(chainId: string): CacheDir {
184
    return new CacheDir(
16✔
185
      CacheRouter.getTrustedForDelegateCallContractsCacheKey(chainId),
186
      '',
187
    );
188
  }
189

190
  static getBackboneCacheDir(chainId: string): CacheDir {
191
    return new CacheDir(`${chainId}_${CacheRouter.BACKBONE_KEY}`, '');
16✔
192
  }
193

194
  static getSingletonsCacheDir(chainId: string): CacheDir {
195
    return new CacheDir(`${chainId}_${CacheRouter.SINGLETONS_KEY}`, '');
68✔
196
  }
197

198
  static getCollectiblesCacheDir(args: {
199
    chainId: string;
200
    safeAddress: `0x${string}`;
201
    limit?: number;
202
    offset?: number;
203
    trusted?: boolean;
204
    excludeSpam?: boolean;
205
  }): CacheDir {
206
    return new CacheDir(
10✔
207
      CacheRouter.getCollectiblesKey(args),
208
      `${args.limit}_${args.offset}_${args.trusted}_${args.excludeSpam}`,
209
    );
210
  }
211

212
  static getCollectiblesKey(args: {
213
    chainId: string;
214
    safeAddress: `0x${string}`;
215
  }): string {
216
    return `${args.chainId}_${CacheRouter.SAFE_COLLECTIBLES_KEY}_${args.safeAddress}`;
52✔
217
  }
218

219
  static getDelegatesCacheKey(args: {
220
    chainId: string;
221
    safeAddress?: `0x${string}`;
222
  }): string {
223
    return `${args.chainId}_${CacheRouter.DELEGATES_KEY}_${args.safeAddress}`;
172✔
224
  }
225

226
  static getDelegatesCacheDir(args: {
227
    chainId: string;
228
    safeAddress?: `0x${string}`;
229
    delegate?: `0x${string}`;
230
    delegator?: `0x${string}`;
231
    label?: string;
232
    limit?: number;
233
    offset?: number;
234
  }): CacheDir {
235
    return new CacheDir(
166✔
236
      CacheRouter.getDelegatesCacheKey(args),
237
      `${args.delegate}_${args.delegator}_${args.label}_${args.limit}_${args.offset}`,
238
    );
239
  }
240

241
  static getFirebaseOAuth2TokenCacheDir(): CacheDir {
242
    return new CacheDir(CacheRouter.FIREBASE_OAUTH2_TOKEN_KEY, '');
8✔
243
  }
244

245
  static getTransferCacheDir(args: {
246
    chainId: string;
247
    transferId: string;
248
  }): CacheDir {
249
    return new CacheDir(
10✔
250
      `${args.chainId}_${CacheRouter.TRANSFER_KEY}_${args.transferId}`,
251
      '',
252
    );
253
  }
254

255
  static getTransfersCacheDir(args: {
256
    chainId: string;
257
    safeAddress: string;
258
    onlyErc20: boolean;
259
    onlyErc721: boolean;
260
    limit?: number;
261
    offset?: number;
262
  }): CacheDir {
263
    return new CacheDir(
118✔
264
      CacheRouter.getTransfersCacheKey(args),
265
      `${args.onlyErc20}_${args.onlyErc721}_${args.limit}_${args.offset}`,
266
    );
267
  }
268

269
  static getTransfersCacheKey(args: {
270
    chainId: string;
271
    safeAddress: string;
272
  }): string {
273
    return `${args.chainId}_${CacheRouter.TRANSFERS_KEY}_${args.safeAddress}`;
178✔
274
  }
275

276
  static getModuleTransactionCacheDir(args: {
277
    chainId: string;
278
    moduleTransactionId: string;
279
  }): CacheDir {
280
    return new CacheDir(
12✔
281
      `${args.chainId}_${CacheRouter.MODULE_TRANSACTION_KEY}_${args.moduleTransactionId}`,
282
      '',
283
    );
284
  }
285

286
  static getModuleTransactionsCacheDir(args: {
287
    chainId: string;
288
    safeAddress: `0x${string}`;
289
    to?: string;
290
    txHash?: string;
291
    module?: string;
292
    limit?: number;
293
    offset?: number;
294
  }): CacheDir {
295
    return new CacheDir(
70✔
296
      CacheRouter.getModuleTransactionsCacheKey(args),
297
      `${args.to}_${args.module}_${args.txHash}_${args.limit}_${args.offset}`,
298
    );
299
  }
300

301
  static getModuleTransactionsCacheKey(args: {
302
    chainId: string;
303
    safeAddress: `0x${string}`;
304
  }): string {
305
    return `${args.chainId}_${CacheRouter.MODULE_TRANSACTIONS_KEY}_${args.safeAddress}`;
84✔
306
  }
307

308
  static getIncomingTransfersCacheDir(args: {
309
    chainId: string;
310
    safeAddress: string;
311
    executionDateGte?: string;
312
    executionDateLte?: string;
313
    to?: string;
314
    value?: string;
315
    tokenAddress?: string;
316
    txHash?: string;
317
    limit?: number;
318
    offset?: number;
319
  }): CacheDir {
320
    return new CacheDir(
52✔
321
      CacheRouter.getIncomingTransfersCacheKey(args),
322
      `${args.executionDateGte}_${args.executionDateLte}_${args.to}_${args.value}_${args.tokenAddress}_${args.txHash}_${args.limit}_${args.offset}`,
323
    );
324
  }
325

326
  static getIncomingTransfersCacheKey(args: {
327
    chainId: string;
328
    safeAddress: string;
329
  }): string {
330
    return `${args.chainId}_${CacheRouter.INCOMING_TRANSFERS_KEY}_${args.safeAddress}`;
82✔
331
  }
332

333
  static getIndexingCacheDir(chainId: string): CacheDir {
334
    return new CacheDir(`${chainId}_${CacheRouter.INDEXING_KEY}`, '');
12✔
335
  }
336

337
  static getMultisigTransactionsCacheDir(args: {
338
    chainId: string;
339
    safeAddress: string;
340
    ordering?: string;
341
    executed?: boolean;
342
    trusted?: boolean;
343
    executionDateGte?: string;
344
    executionDateLte?: string;
345
    to?: string;
346
    value?: string;
347
    nonce?: string;
348
    nonceGte?: number;
349
    limit?: number;
350
    offset?: number;
351
  }): CacheDir {
352
    return new CacheDir(
240✔
353
      CacheRouter.getMultisigTransactionsCacheKey(args),
354
      `${args.ordering}_${args.executed}_${args.trusted}_${args.executionDateGte}_${args.executionDateLte}_${args.to}_${args.value}_${args.nonce}_${args.nonceGte}_${args.limit}_${args.offset}`,
355
    );
356
  }
357

358
  static getMultisigTransactionsCacheKey(args: {
359
    chainId: string;
360
    safeAddress: string;
361
  }): string {
362
    return `${args.chainId}_${CacheRouter.MULTISIG_TRANSACTIONS_KEY}_${args.safeAddress}`;
344✔
363
  }
364

365
  static getMultisigTransactionCacheDir(args: {
366
    chainId: string;
367
    safeTransactionHash: string;
368
  }): CacheDir {
369
    return new CacheDir(CacheRouter.getMultisigTransactionCacheKey(args), '');
132✔
370
  }
371

372
  static getMultisigTransactionCacheKey(args: {
373
    chainId: string;
374
    safeTransactionHash: string;
375
  }): string {
376
    return `${args.chainId}_${CacheRouter.MULTISIG_TRANSACTION_KEY}_${args.safeTransactionHash}`;
196✔
377
  }
378

379
  static getCreationTransactionCacheDir(args: {
380
    chainId: string;
381
    safeAddress: `0x${string}`;
382
  }): CacheDir {
383
    return new CacheDir(
18✔
384
      `${args.chainId}_${CacheRouter.CREATION_TRANSACTION_KEY}_${args.safeAddress}`,
385
      '',
386
    );
387
  }
388

389
  static getAllTransactionsCacheDir(args: {
390
    chainId: string;
391
    safeAddress: `0x${string}`;
392
    ordering?: string;
393
    executed?: boolean;
394
    queued?: boolean;
395
    limit?: number;
396
    offset?: number;
397
  }): CacheDir {
398
    return new CacheDir(
76✔
399
      CacheRouter.getAllTransactionsKey(args),
400
      `${args.ordering}_${args.executed}_${args.queued}_${args.limit}_${args.offset}`,
401
    );
402
  }
403

404
  static getAllTransactionsKey(args: {
405
    chainId: string;
406
    safeAddress: `0x${string}`;
407
  }): string {
408
    return `${args.chainId}_${CacheRouter.ALL_TRANSACTIONS_KEY}_${args.safeAddress}`;
148✔
409
  }
410

411
  static getTokenCacheDir(args: {
412
    chainId: string;
413
    address: string;
414
  }): CacheDir {
415
    return new CacheDir(
1,430✔
416
      `${args.chainId}_${CacheRouter.TOKEN_KEY}_${args.address}`,
417
      '',
418
    );
419
  }
420

421
  static getTokensCacheKey(chainId: string): string {
422
    return `${chainId}_${CacheRouter.TOKENS_KEY}`;
8✔
423
  }
424

425
  static getTokensCacheDir(args: {
426
    chainId: string;
427
    limit?: number;
428
    offset?: number;
429
  }): CacheDir {
430
    return new CacheDir(
8✔
431
      CacheRouter.getTokensCacheKey(args.chainId),
432
      `${args.limit}_${args.offset}`,
433
    );
434
  }
435

436
  static getSafesByOwnerCacheDir(args: {
437
    chainId: string;
438
    ownerAddress: `0x${string}`;
439
  }): CacheDir {
440
    return new CacheDir(
32✔
441
      `${args.chainId}_${CacheRouter.OWNERS_SAFE_KEY}_${args.ownerAddress}`,
442
      '',
443
    );
444
  }
445

446
  static getMessageByHashCacheKey(args: {
447
    chainId: string;
448
    messageHash: string;
449
  }): string {
450
    return `${args.chainId}_${CacheRouter.MESSAGE_KEY}_${args.messageHash}`;
84✔
451
  }
452

453
  static getMessageByHashCacheDir(args: {
454
    chainId: string;
455
    messageHash: string;
456
  }): CacheDir {
457
    return new CacheDir(this.getMessageByHashCacheKey(args), '');
80✔
458
  }
459

460
  static getMessagesBySafeCacheKey(args: {
461
    chainId: string;
462
    safeAddress: `0x${string}`;
463
  }): string {
464
    return `${args.chainId}_${CacheRouter.MESSAGES_KEY}_${args.safeAddress}`;
98✔
465
  }
466

467
  static getMessagesBySafeCacheDir(args: {
468
    chainId: string;
469
    safeAddress: `0x${string}`;
470
    limit?: number;
471
    offset?: number;
472
  }): CacheDir {
473
    return new CacheDir(
70✔
474
      this.getMessagesBySafeCacheKey(args),
475
      `${args.limit}_${args.offset}`,
476
    );
477
  }
478

479
  static getChainsCacheKey(): string {
480
    return CacheRouter.CHAINS_KEY;
48✔
481
  }
482

483
  static getChainsCacheDir(args: {
484
    limit?: number;
485
    offset?: number;
486
  }): CacheDir {
487
    return new CacheDir(
34✔
488
      CacheRouter.getChainsCacheKey(),
489
      `${args.limit}_${args.offset}`,
490
    );
491
  }
492

493
  static getChainCacheKey(chainId: string): string {
494
    return `${chainId}_${CacheRouter.CHAIN_KEY}`;
2,162✔
495
  }
496

497
  static getChainCacheDir(chainId: string): CacheDir {
498
    return new CacheDir(CacheRouter.getChainCacheKey(chainId), '');
2,148✔
499
  }
500

501
  static getRelayKey(args: {
502
    chainId: string;
503
    address: `0x${string}`;
504
  }): string {
505
    return `${args.chainId}_${CacheRouter.RELAY_KEY}_${args.address}`;
466✔
506
  }
507

508
  static getRelayCacheDir(args: {
509
    chainId: string;
510
    address: `0x${string}`;
511
  }): CacheDir {
512
    return new CacheDir(CacheRouter.getRelayKey(args), '');
466✔
513
  }
514

515
  static getSafeAppsKey(chainId: string): string {
516
    return `${chainId}_${CacheRouter.SAFE_APPS_KEY}`;
4✔
517
  }
518

519
  static getSafeAppsCacheDir(args: {
520
    chainId?: string;
521
    clientUrl?: string;
522
    onlyListed?: boolean;
523
    url?: string;
524
  }): CacheDir {
525
    return new CacheDir(
90✔
526
      `${args.chainId}_${CacheRouter.SAFE_APPS_KEY}`,
527
      `${args.clientUrl}_${args.onlyListed}_${args.url}`,
528
    );
529
  }
530

531
  static getNativeCoinPriceCacheDir(args: {
532
    nativeCoinId: string;
533
    fiatCode: string;
534
  }): CacheDir {
535
    return new CacheDir(
42✔
536
      `${args.nativeCoinId}_${CacheRouter.NATIVE_COIN_PRICE_KEY}_${args.fiatCode}`,
537
      '',
538
    );
539
  }
540

541
  static getTokenPriceCacheDir(args: {
542
    chainName: string;
543
    fiatCode: string;
544
    tokenAddress: string;
545
  }): CacheDir {
546
    return new CacheDir(
214✔
547
      `${args.chainName}_${CacheRouter.TOKEN_PRICE_KEY}_${args.tokenAddress}_${args.fiatCode}`,
548
      '',
549
    );
550
  }
551

552
  static getPriceFiatCodesCacheDir(): CacheDir {
553
    return new CacheDir(CacheRouter.SAFE_FIAT_CODES_KEY, '');
10✔
554
  }
555

556
  static getAccountCacheDir(address: `0x${string}`): CacheDir {
557
    return new CacheDir(`${CacheRouter.ACCOUNT_KEY}_${address}`, '');
82✔
558
  }
559

560
  static getAccountDataTypesCacheDir(): CacheDir {
561
    return new CacheDir(CacheRouter.ACCOUNT_DATA_TYPES_KEY, '');
20✔
562
  }
563

564
  static getAccountDataSettingsCacheDir(address: `0x${string}`): CacheDir {
565
    return new CacheDir(
22✔
566
      `${CacheRouter.ACCOUNT_DATA_SETTINGS_KEY}_${address}`,
567
      '',
568
    );
569
  }
570

571
  static getCounterfactualSafeCacheDir(
572
    chainId: string,
573
    predictedAddress: `0x${string}`,
574
  ): CacheDir {
575
    return new CacheDir(
24✔
576
      `${chainId}_${CacheRouter.COUNTERFACTUAL_SAFE_KEY}_${predictedAddress}`,
577
      '',
578
    );
579
  }
580

581
  static getCounterfactualSafesCacheDir(address: `0x${string}`): CacheDir {
582
    return new CacheDir(
80✔
583
      `${CacheRouter.COUNTERFACTUAL_SAFES_KEY}_${address}`,
584
      '',
585
    );
586
  }
587

588
  static getRpcRequestsKey(chainId: string): string {
589
    return `${chainId}_${CacheRouter.RPC_REQUESTS_KEY}`;
16✔
590
  }
591

592
  static getRpcRequestsCacheDir(args: {
593
    chainId: string;
594
    method: string;
595
    params: string;
596
  }): CacheDir {
597
    return new CacheDir(
12✔
598
      CacheRouter.getRpcRequestsKey(args.chainId),
599
      `${args.method}_${args.params}`,
600
    );
601
  }
602

603
  // TODO: remove passing url and the associated configuration once Base is
604
  // fully migrated to the Kiln mainnet API.
605
  static getStakingDeploymentsCacheDir(url: string): CacheDir {
606
    return new CacheDir(`${this.STAKING_DEPLOYMENTS_KEY}_${url}`, '');
52✔
607
  }
608

609
  static getStakingNetworkStatsCacheDir(): CacheDir {
610
    return new CacheDir(this.STAKING_NETWORK_STATS_KEY, '');
22✔
611
  }
612

613
  static getStakingDedicatedStakingStatsCacheDir(): CacheDir {
614
    return new CacheDir(this.STAKING_DEDICATED_STAKING_STATS_KEY, '');
14✔
615
  }
616

617
  static getStakingPooledStakingStatsCacheDir(pool: `0x${string}`): CacheDir {
618
    return new CacheDir(`${this.STAKING_POOLED_STAKING_STATS_KEY}_${pool}`, '');
4✔
619
  }
620

621
  static getStakingDefiVaultStatsCacheDir(args: {
622
    chainId: string;
623
    vault: `0x${string}`;
624
  }): CacheDir {
625
    return new CacheDir(
6✔
626
      `${args.chainId}_${this.STAKING_DEFI_VAULT_STATS_KEY}_${args.vault}`,
627
      '',
628
    );
629
  }
630

631
  static getStakingDefiVaultStakesCacheDir(args: {
632
    chainId: string;
633
    safeAddress: `0x${string}`;
634
    vault: `0x${string}`;
635
  }): CacheDir {
636
    return new CacheDir(
6✔
637
      `${args.chainId}_${this.STAKING_DEFI_VAULT_STAKES_KEY}_${args.safeAddress}_${args.vault}`,
638
      '',
639
    );
640
  }
641

642
  static getStakingDefiMorphoExtraRewardsCacheDir(args: {
643
    chainId: string;
644
    safeAddress: `0x${string}`;
645
  }): CacheDir {
646
    return new CacheDir(
4✔
647
      `${args.chainId}_${this.STAKING_DEFI_MORPHO_EXTRA_REWARDS_KEY}_${args.safeAddress}`,
648
      '',
649
    );
650
  }
651

652
  /**
653
   * Calculated the chain/Safe-specific cache key of {@link Stake}.
654
   *
655
   * @param {string} args.chainId - Chain ID
656
   * @param {string} args.safeAddress - Safe address
657
   * @returns {string} - Cache key
658
   */
659
  static getStakingStakesCacheKey(args: {
660
    chainId: string;
661
    safeAddress: `0x${string}`;
662
  }): string {
663
    return `${args.chainId}_${CacheRouter.STAKING_STAKES_KEY}_${args.safeAddress}`;
54✔
664
  }
665

666
  /**
667
   * Calculate cache directory for staking stakes.
668
   *
669
   * Note: This function hashes the validators' public keys to keep the
670
   * cache field short and deterministic. Redis and other cache systems
671
   * may experience performance degradation with long fields.
672
   *
673
   * @param {string} args.chainId - Chain ID
674
   * @param {string} args.safeAddress - Safe address
675
   * @param {string} args.validatorsPublicKeys - Array of validators public keys
676
   * @returns {@link CacheDir} - Cache directory
677
   */
678
  static getStakingStakesCacheDir(args: {
679
    chainId: string;
680
    safeAddress: `0x${string}`;
681
    validatorsPublicKeys: Array<`0x${string}`>;
682
  }): CacheDir {
683
    const hash = crypto.createHash('sha256');
22✔
684
    hash.update(args.validatorsPublicKeys.join('_'));
22✔
685
    return new CacheDir(
22✔
686
      CacheRouter.getStakingStakesCacheKey(args),
687
      hash.digest('hex'),
688
    );
689
  }
690

691
  static getUnsupportedChainEventCacheKey(chainId: string): string {
692
    return `${chainId}_${this.UNSUPPORTED_CHAIN_EVENT}`;
54✔
693
  }
694

695
  static getStakingTransactionStatusCacheDir(args: {
696
    chainId: string;
697
    txHash: `0x${string}`;
698
  }): CacheDir {
699
    return new CacheDir(
8✔
700
      `${args.chainId}_${CacheRouter.STAKING_TRANSACTION_STATUS_KEY}_${args.txHash}`,
701
      '',
702
    );
703
  }
704

705
  static getTargetedSafeCacheKey(outreachId: number): string {
706
    return `${CacheRouter.TARGETED_MESSAGING_TARGETED_SAFE_KEY}_${outreachId}`;
52✔
707
  }
708

709
  static getTargetedSafeCacheDir(args: {
710
    outreachId: number;
711
    safeAddress: `0x${string}`;
712
  }): CacheDir {
713
    return new CacheDir(
18✔
714
      CacheRouter.getTargetedSafeCacheKey(args.outreachId),
715
      args.safeAddress,
716
    );
717
  }
718

719
  static getSubmissionCacheKey(outreachId: number): string {
720
    return `${CacheRouter.TARGETED_MESSAGING_SUBMISSION_KEY}_${outreachId}`;
20✔
721
  }
722

723
  static getSubmissionCacheDir(args: {
724
    outreachId: number;
725
    safeAddress: `0x${string}`;
726
    signerAddress: `0x${string}`;
727
  }): CacheDir {
728
    return new CacheDir(
12✔
729
      CacheRouter.getSubmissionCacheKey(args.outreachId),
730
      `${args.safeAddress}_${args.signerAddress}`,
731
    );
732
  }
733

734
  static getOutreachesCacheDir(): CacheDir {
UNCOV
735
    return new CacheDir(CacheRouter.TARGETED_MESSAGING_OUTREACHES, '');
×
736
  }
737

738
  static getOutreachFileProcessorCacheKey(): string {
739
    return CacheRouter.TARGETED_MESSAGING_OUTREACH_FILE_PROCESSOR_LOCK;
66✔
740
  }
741

742
  static getOutreachFileProcessorCacheDir(): CacheDir {
743
    return new CacheDir(CacheRouter.getOutreachFileProcessorCacheKey(), '');
42✔
744
  }
745

746
  /**
747
   * Gets the in-memory cache key for the given cacheDir.
748
   */
749
  static getMemoryKey(cacheDir: CacheDir): string {
750
    return `${cacheDir.key}:${cacheDir.field}`;
306✔
751
  }
752
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc