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

safe-global / safe-client-gateway / 18004330328

25 Sep 2025 10:16AM UTC coverage: 87.972% (-1.2%) from 89.219%
18004330328

Pull #2712

github

LucieFaire
extract complex logic to separate func

Signed-off-by: dsh <11198975+LucieFaire@users.noreply.github.com>
Pull Request #2712: feat: Contract verification analysis

3623 of 4594 branches covered (78.86%)

Branch coverage included in aggregate %.

99 of 235 new or added lines in 22 files covered. (42.13%)

57 existing lines in 9 files now uncovered.

12504 of 13738 relevant lines covered (91.02%)

525.35 hits per line

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

96.36
/src/datasources/cache/cache.router.ts
1
import crypto from 'crypto';
208✔
2
import { CacheDir } from '@/datasources/cache/entities/cache-dir.entity';
208✔
3
import type { Address, Hash } from 'viem';
4

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

81
  static getAuthNonceCacheKey(nonce: string): string {
82
    return `${CacheRouter.AUTH_NONCE_KEY}_${nonce}`;
106✔
83
  }
84

85
  static getAuthNonceCacheDir(nonce: string): CacheDir {
86
    return new CacheDir(CacheRouter.getAuthNonceCacheKey(nonce), '');
106✔
87
  }
88

89
  static getBridgeChainsCacheDir(): CacheDir {
90
    return new CacheDir(CacheRouter.BRIDGE_CHAINS_KEY, '');
4✔
91
  }
92

93
  static getBalancesCacheKey(args: {
94
    chainId: string;
95
    safeAddress: Address;
96
  }): string {
97
    return `${args.chainId}_${CacheRouter.SAFE_BALANCES_KEY}_${args.safeAddress}`;
100✔
98
  }
99

100
  static getBalancesCacheDir(args: {
101
    chainId: string;
102
    safeAddress: Address;
103
    trusted?: boolean;
104
    excludeSpam?: boolean;
105
  }): CacheDir {
106
    return new CacheDir(
60✔
107
      CacheRouter.getBalancesCacheKey(args),
108
      `${args.trusted}_${args.excludeSpam}`,
109
    );
110
  }
111

112
  static getZerionBalancesCacheKey(args: {
113
    chainId: string;
114
    safeAddress: Address;
115
  }): string {
116
    return `${args.chainId}_${CacheRouter.ZERION_BALANCES_KEY}_${args.safeAddress}`;
24✔
117
  }
118

119
  static getZerionBalancesCacheDir(args: {
120
    chainId: string;
121
    safeAddress: Address;
122
    fiatCode: string;
123
  }): CacheDir {
124
    return new CacheDir(
24✔
125
      CacheRouter.getZerionBalancesCacheKey(args),
126
      args.fiatCode,
127
    );
128
  }
129

130
  static getZerionCollectiblesCacheKey(args: {
131
    chainId: string;
132
    safeAddress: Address;
133
  }): string {
134
    return `${args.chainId}_${CacheRouter.ZERION_COLLECTIBLES_KEY}_${args.safeAddress}`;
8✔
135
  }
136

137
  static getZerionCollectiblesCacheDir(args: {
138
    chainId: string;
139
    safeAddress: Address;
140
    limit?: number;
141
    offset?: number;
142
  }): CacheDir {
143
    return new CacheDir(
8✔
144
      CacheRouter.getZerionCollectiblesCacheKey(args),
145
      `${args.limit}_${args.offset}`,
146
    );
147
  }
148

149
  static getZerionPositionsCacheKey(args: {
150
    chainId: string;
151
    safeAddress: Address;
152
  }): string {
UNCOV
153
    return `${args.chainId}_${CacheRouter.ZERION_POSITIONS_KEY}_${args.safeAddress}`;
×
154
  }
155

156
  static getZerionPositionsCacheDir(args: {
157
    chainId: string;
158
    safeAddress: Address;
159
    fiatCode: string;
160
  }): CacheDir {
UNCOV
161
    return new CacheDir(
×
162
      CacheRouter.getZerionPositionsCacheKey(args),
163
      args.fiatCode,
164
    );
165
  }
166

167
  static getRateLimitCacheKey(prefix: string): string {
168
    return `${prefix}_${CacheRouter.RATE_LIMIT_KEY}`;
376✔
169
  }
170

171
  static getSafeCacheDir(args: {
172
    chainId: string;
173
    safeAddress: Address;
174
  }): CacheDir {
175
    return new CacheDir(CacheRouter.getSafeCacheKey(args), '');
866✔
176
  }
177

178
  static getSafeCacheKey(args: {
179
    chainId: string;
180
    safeAddress: Address;
181
  }): string {
182
    return `${args.chainId}_${CacheRouter.SAFE_KEY}_${args.safeAddress}`;
898✔
183
  }
184

185
  static getIsSafeCacheDir(args: {
186
    chainId: string;
187
    safeAddress: Address;
188
  }): CacheDir {
189
    return new CacheDir(CacheRouter.getIsSafeCacheKey(args), '');
68✔
190
  }
191

192
  static getIsSafeCacheKey(args: {
193
    chainId: string;
194
    safeAddress: Address;
195
  }): string {
196
    return `${args.chainId}_${CacheRouter.SAFE_EXISTS_KEY}_${args.safeAddress}`;
72✔
197
  }
198

199
  static getBackboneCacheDir(chainId: string): CacheDir {
200
    return new CacheDir(`${chainId}_${CacheRouter.BACKBONE_KEY}`, '');
16✔
201
  }
202

203
  static getSingletonsCacheDir(chainId: string): CacheDir {
204
    return new CacheDir(`${chainId}_${CacheRouter.SINGLETONS_KEY}`, '');
68✔
205
  }
206

207
  static getCollectiblesCacheDir(args: {
208
    chainId: string;
209
    safeAddress: Address;
210
    limit?: number;
211
    offset?: number;
212
    trusted?: boolean;
213
    excludeSpam?: boolean;
214
  }): CacheDir {
215
    return new CacheDir(
10✔
216
      CacheRouter.getCollectiblesKey(args),
217
      `${args.limit}_${args.offset}_${args.trusted}_${args.excludeSpam}`,
218
    );
219
  }
220

221
  static getCollectiblesKey(args: {
222
    chainId: string;
223
    safeAddress: Address;
224
  }): string {
225
    return `${args.chainId}_${CacheRouter.SAFE_COLLECTIBLES_KEY}_${args.safeAddress}`;
52✔
226
  }
227

228
  static getDelegatesCacheKey(args: {
229
    chainId: string;
230
    safeAddress?: Address;
231
  }): string {
232
    return `${args.chainId}_${CacheRouter.DELEGATES_KEY}_${args.safeAddress}`;
182✔
233
  }
234

235
  static getDelegatesCacheDir(args: {
236
    chainId: string;
237
    safeAddress?: Address;
238
    delegate?: Address;
239
    delegator?: Address;
240
    label?: string;
241
    limit?: number;
242
    offset?: number;
243
  }): CacheDir {
244
    return new CacheDir(
176✔
245
      CacheRouter.getDelegatesCacheKey(args),
246
      `${args.delegate}_${args.delegator}_${args.label}_${args.limit}_${args.offset}`,
247
    );
248
  }
249

250
  static getFirebaseOAuth2TokenCacheDir(): CacheDir {
251
    return new CacheDir(CacheRouter.FIREBASE_OAUTH2_TOKEN_KEY, '');
8✔
252
  }
253

254
  static getTransferCacheDir(args: {
255
    chainId: string;
256
    transferId: string;
257
  }): CacheDir {
258
    return new CacheDir(
10✔
259
      `${args.chainId}_${CacheRouter.TRANSFER_KEY}_${args.transferId}`,
260
      '',
261
    );
262
  }
263

264
  static getTransfersCacheDir(args: {
265
    chainId: string;
266
    safeAddress: string;
267
    onlyErc20: boolean;
268
    onlyErc721: boolean;
269
    limit?: number;
270
    offset?: number;
271
    to?: string;
272
  }): CacheDir {
273
    return new CacheDir(
120✔
274
      CacheRouter.getTransfersCacheKey(args),
275
      `${args.onlyErc20}_${args.onlyErc721}_${args.limit}_${args.offset}_${args.to}`,
276
    );
277
  }
278

279
  static getTransfersCacheKey(args: {
280
    chainId: string;
281
    safeAddress: string;
282
  }): string {
283
    return `${args.chainId}_${CacheRouter.TRANSFERS_KEY}_${args.safeAddress}`;
180✔
284
  }
285

286
  static getModuleTransactionCacheDir(args: {
287
    chainId: string;
288
    moduleTransactionId: string;
289
  }): CacheDir {
290
    return new CacheDir(
12✔
291
      `${args.chainId}_${CacheRouter.MODULE_TRANSACTION_KEY}_${args.moduleTransactionId}`,
292
      '',
293
    );
294
  }
295

296
  static getModuleTransactionsCacheDir(args: {
297
    chainId: string;
298
    safeAddress: Address;
299
    to?: string;
300
    txHash?: string;
301
    module?: string;
302
    limit?: number;
303
    offset?: number;
304
  }): CacheDir {
305
    return new CacheDir(
70✔
306
      CacheRouter.getModuleTransactionsCacheKey(args),
307
      `${args.to}_${args.module}_${args.txHash}_${args.limit}_${args.offset}`,
308
    );
309
  }
310

311
  static getModuleTransactionsCacheKey(args: {
312
    chainId: string;
313
    safeAddress: Address;
314
  }): string {
315
    return `${args.chainId}_${CacheRouter.MODULE_TRANSACTIONS_KEY}_${args.safeAddress}`;
84✔
316
  }
317

318
  static getIncomingTransfersCacheDir(args: {
319
    chainId: string;
320
    safeAddress: string;
321
    executionDateGte?: string;
322
    executionDateLte?: string;
323
    to?: string;
324
    value?: string;
325
    tokenAddress?: string;
326
    txHash?: string;
327
    limit?: number;
328
    offset?: number;
329
  }): CacheDir {
330
    return new CacheDir(
52✔
331
      CacheRouter.getIncomingTransfersCacheKey(args),
332
      `${args.executionDateGte}_${args.executionDateLte}_${args.to}_${args.value}_${args.tokenAddress}_${args.txHash}_${args.limit}_${args.offset}`,
333
    );
334
  }
335

336
  static getIncomingTransfersCacheKey(args: {
337
    chainId: string;
338
    safeAddress: string;
339
  }): string {
340
    return `${args.chainId}_${CacheRouter.INCOMING_TRANSFERS_KEY}_${args.safeAddress}`;
82✔
341
  }
342

343
  static getIndexingCacheDir(chainId: string): CacheDir {
344
    return new CacheDir(`${chainId}_${CacheRouter.INDEXING_KEY}`, '');
12✔
345
  }
346

347
  static getMultisigTransactionsCacheDir(args: {
348
    chainId: string;
349
    safeAddress: string;
350
    ordering?: string;
351
    executed?: boolean;
352
    trusted?: boolean;
353
    executionDateGte?: string;
354
    executionDateLte?: string;
355
    to?: string;
356
    value?: string;
357
    nonce?: string;
358
    nonceGte?: number;
359
    limit?: number;
360
    offset?: number;
361
  }): CacheDir {
362
    return new CacheDir(
240✔
363
      CacheRouter.getMultisigTransactionsCacheKey(args),
364
      `${args.ordering}_${args.executed}_${args.trusted}_${args.executionDateGte}_${args.executionDateLte}_${args.to}_${args.value}_${args.nonce}_${args.nonceGte}_${args.limit}_${args.offset}`,
365
    );
366
  }
367

368
  static getMultisigTransactionsCacheKey(args: {
369
    chainId: string;
370
    safeAddress: string;
371
  }): string {
372
    return `${args.chainId}_${CacheRouter.MULTISIG_TRANSACTIONS_KEY}_${args.safeAddress}`;
344✔
373
  }
374

375
  static getMultisigTransactionCacheDir(args: {
376
    chainId: string;
377
    safeTransactionHash: string;
378
  }): CacheDir {
379
    return new CacheDir(CacheRouter.getMultisigTransactionCacheKey(args), '');
138✔
380
  }
381

382
  static getMultisigTransactionCacheKey(args: {
383
    chainId: string;
384
    safeTransactionHash: string;
385
  }): string {
386
    return `${args.chainId}_${CacheRouter.MULTISIG_TRANSACTION_KEY}_${args.safeTransactionHash}`;
202✔
387
  }
388

389
  static getCreationTransactionCacheDir(args: {
390
    chainId: string;
391
    safeAddress: Address;
392
  }): CacheDir {
393
    return new CacheDir(
18✔
394
      `${args.chainId}_${CacheRouter.CREATION_TRANSACTION_KEY}_${args.safeAddress}`,
395
      '',
396
    );
397
  }
398

399
  static getDecodedDataCacheKey(args: {
400
    chainId: string;
401
    data: Address;
402
    to: Address;
403
  }): string {
404
    return `${args.chainId}_${CacheRouter.DECODED_DATA_KEY}_${args.data}_${args.to}`;
524✔
405
  }
406

407
  static getDecodedDataCacheDir(args: {
408
    chainId: string;
409
    data: Address;
410
    to: Address;
411
  }): CacheDir {
412
    return new CacheDir(CacheRouter.getDecodedDataCacheKey(args), '');
524✔
413
  }
414

415
  static getContractsCacheKey(args: {
416
    chainId: string;
417
    address: Address;
418
  }): string {
419
    return `${args.chainId}_${CacheRouter.CONTRACTS_KEY}_${args.address}`;
1,332✔
420
  }
421

422
  static getContractsCacheDir(args: {
423
    chainId: string;
424
    address: Address;
425
  }): CacheDir {
426
    return new CacheDir(CacheRouter.getContractsCacheKey(args), '');
1,332✔
427
  }
428

429
  static getTrustedForDelegateCallContractsCacheKey(chainId: string): string {
430
    return `${chainId}_${CacheRouter.TRUSTED_FOR_DELEGATE_CALL_CONTRACTS_KEY}`;
14✔
431
  }
432

433
  static getTrustedForDelegateCallContractsCacheDir(args: {
434
    chainId: string;
435
    limit?: number;
436
    offset?: number;
437
  }): CacheDir {
438
    return new CacheDir(
14✔
439
      CacheRouter.getTrustedForDelegateCallContractsCacheKey(args.chainId),
440
      `${args.limit}_${args.offset}`,
441
    );
442
  }
443

444
  static getAllTransactionsCacheDir(args: {
445
    chainId: string;
446
    safeAddress: Address;
447
    ordering?: string;
448
    executed?: boolean;
449
    queued?: boolean;
450
    limit?: number;
451
    offset?: number;
452
  }): CacheDir {
453
    return new CacheDir(
76✔
454
      CacheRouter.getAllTransactionsKey(args),
455
      `${args.ordering}_${args.executed}_${args.queued}_${args.limit}_${args.offset}`,
456
    );
457
  }
458

459
  static getAllTransactionsKey(args: {
460
    chainId: string;
461
    safeAddress: Address;
462
  }): string {
463
    return `${args.chainId}_${CacheRouter.ALL_TRANSACTIONS_KEY}_${args.safeAddress}`;
148✔
464
  }
465

466
  static getTokenCacheDir(args: {
467
    chainId: string;
468
    address: string;
469
  }): CacheDir {
470
    return new CacheDir(
1,430✔
471
      `${args.chainId}_${CacheRouter.TOKEN_KEY}_${args.address}`,
472
      '',
473
    );
474
  }
475

476
  static getTokensCacheKey(chainId: string): string {
477
    return `${chainId}_${CacheRouter.TOKENS_KEY}`;
8✔
478
  }
479

480
  static getTokensCacheDir(args: {
481
    chainId: string;
482
    limit?: number;
483
    offset?: number;
484
  }): CacheDir {
485
    return new CacheDir(
8✔
486
      CacheRouter.getTokensCacheKey(args.chainId),
487
      `${args.limit}_${args.offset}`,
488
    );
489
  }
490

491
  static getSafesByOwnerCacheDir(args: {
492
    chainId: string;
493
    ownerAddress: Address;
494
  }): CacheDir {
495
    return new CacheDir(
32✔
496
      `${args.chainId}_${CacheRouter.OWNERS_SAFE_KEY}_${args.ownerAddress}`,
497
      '',
498
    );
499
  }
500

501
  static getMessageByHashCacheKey(args: {
502
    chainId: string;
503
    messageHash: string;
504
  }): string {
505
    return `${args.chainId}_${CacheRouter.MESSAGE_KEY}_${args.messageHash}`;
74✔
506
  }
507

508
  static getMessageByHashCacheDir(args: {
509
    chainId: string;
510
    messageHash: string;
511
  }): CacheDir {
512
    return new CacheDir(this.getMessageByHashCacheKey(args), '');
70✔
513
  }
514

515
  static getMessagesBySafeCacheKey(args: {
516
    chainId: string;
517
    safeAddress: Address;
518
  }): string {
519
    return `${args.chainId}_${CacheRouter.MESSAGES_KEY}_${args.safeAddress}`;
98✔
520
  }
521

522
  static getMessagesBySafeCacheDir(args: {
523
    chainId: string;
524
    safeAddress: Address;
525
    limit?: number;
526
    offset?: number;
527
  }): CacheDir {
528
    return new CacheDir(
70✔
529
      this.getMessagesBySafeCacheKey(args),
530
      `${args.limit}_${args.offset}`,
531
    );
532
  }
533

534
  static getChainsCacheKey(): string {
535
    return CacheRouter.CHAINS_KEY;
48✔
536
  }
537

538
  static getChainsCacheDir(args: {
539
    limit?: number;
540
    offset?: number;
541
  }): CacheDir {
542
    return new CacheDir(
34✔
543
      CacheRouter.getChainsCacheKey(),
544
      `${args.limit}_${args.offset}`,
545
    );
546
  }
547

548
  static getChainCacheKey(chainId: string): string {
549
    return `${chainId}_${CacheRouter.CHAIN_KEY}`;
2,210✔
550
  }
551

552
  static getChainCacheDir(chainId: string): CacheDir {
553
    return new CacheDir(CacheRouter.getChainCacheKey(chainId), '');
2,196✔
554
  }
555

556
  static getRelayKey(args: { chainId: string; address: Address }): string {
557
    return `${args.chainId}_${CacheRouter.RELAY_KEY}_${args.address}`;
466✔
558
  }
559

560
  static getRelayCacheDir(args: {
561
    chainId: string;
562
    address: Address;
563
  }): CacheDir {
564
    return new CacheDir(CacheRouter.getRelayKey(args), '');
466✔
565
  }
566

567
  static getSafeAppsKey(chainId: string): string {
568
    return `${chainId}_${CacheRouter.SAFE_APPS_KEY}`;
4✔
569
  }
570

571
  static getSafeAppsCacheDir(args: {
572
    chainId?: string;
573
    clientUrl?: string;
574
    onlyListed?: boolean;
575
    url?: string;
576
  }): CacheDir {
577
    return new CacheDir(
90✔
578
      `${args.chainId}_${CacheRouter.SAFE_APPS_KEY}`,
579
      `${args.clientUrl}_${args.onlyListed}_${args.url}`,
580
    );
581
  }
582

583
  static getNativeCoinPriceCacheDir(args: {
584
    nativeCoinId: string;
585
    fiatCode: string;
586
  }): CacheDir {
587
    return new CacheDir(
42✔
588
      `${args.nativeCoinId}_${CacheRouter.NATIVE_COIN_PRICE_KEY}_${args.fiatCode}`,
589
      '',
590
    );
591
  }
592

593
  static getTokenPriceCacheDir(args: {
594
    chainName: string;
595
    fiatCode: string;
596
    tokenAddress: string;
597
  }): CacheDir {
598
    return new CacheDir(
214✔
599
      `${args.chainName}_${CacheRouter.TOKEN_PRICE_KEY}_${args.tokenAddress}_${args.fiatCode}`,
600
      '',
601
    );
602
  }
603

604
  static getPriceFiatCodesCacheDir(): CacheDir {
605
    return new CacheDir(CacheRouter.SAFE_FIAT_CODES_KEY, '');
10✔
606
  }
607

608
  static getAccountCacheDir(address: Address): CacheDir {
609
    return new CacheDir(`${CacheRouter.ACCOUNT_KEY}_${address}`, '');
78✔
610
  }
611

612
  static getAccountDataTypesCacheDir(): CacheDir {
613
    return new CacheDir(CacheRouter.ACCOUNT_DATA_TYPES_KEY, '');
20✔
614
  }
615

616
  static getAccountDataSettingsCacheDir(address: Address): CacheDir {
617
    return new CacheDir(
22✔
618
      `${CacheRouter.ACCOUNT_DATA_SETTINGS_KEY}_${address}`,
619
      '',
620
    );
621
  }
622

623
  static getCounterfactualSafeCacheDir(
624
    chainId: string,
625
    predictedAddress: Address,
626
  ): CacheDir {
627
    return new CacheDir(
24✔
628
      `${chainId}_${CacheRouter.COUNTERFACTUAL_SAFE_KEY}_${predictedAddress}`,
629
      '',
630
    );
631
  }
632

633
  static getCounterfactualSafesCacheDir(address: Address): CacheDir {
634
    return new CacheDir(
80✔
635
      `${CacheRouter.COUNTERFACTUAL_SAFES_KEY}_${address}`,
636
      '',
637
    );
638
  }
639

640
  static getRpcRequestsKey(chainId: string): string {
641
    return `${chainId}_${CacheRouter.RPC_REQUESTS_KEY}`;
16✔
642
  }
643

644
  static getRpcRequestsCacheDir(args: {
645
    chainId: string;
646
    method: string;
647
    params: string;
648
  }): CacheDir {
649
    return new CacheDir(
12✔
650
      CacheRouter.getRpcRequestsKey(args.chainId),
651
      `${args.method}_${args.params}`,
652
    );
653
  }
654

655
  static getStakingDeploymentsCacheDir(
656
    cacheType: 'earn' | 'staking',
657
  ): CacheDir {
658
    return new CacheDir(this.STAKING_DEPLOYMENTS_KEY, cacheType);
52✔
659
  }
660

661
  static getStakingRewardsFeeCacheDir(args: {
662
    cacheType: 'earn' | 'staking';
663
    chainId: string;
664
    contract: Address;
665
  }): CacheDir {
666
    return new CacheDir(
22✔
667
      `${args.chainId}_${this.STAKING_REWARDS_FEE_KEY}_${args.contract}`,
668
      args.cacheType,
669
    );
670
  }
671

672
  static getStakingNetworkStatsCacheDir(
673
    cacheType: 'earn' | 'staking',
674
  ): CacheDir {
675
    return new CacheDir(this.STAKING_NETWORK_STATS_KEY, cacheType);
22✔
676
  }
677

678
  static getStakingDedicatedStakingStatsCacheDir(
679
    cacheType: 'earn' | 'staking',
680
  ): CacheDir {
681
    return new CacheDir(this.STAKING_DEDICATED_STAKING_STATS_KEY, cacheType);
14✔
682
  }
683

684
  static getStakingPooledStakingStatsCacheDir(args: {
685
    cacheType: 'earn' | 'staking';
686
    pool: Address;
687
  }): CacheDir {
688
    return new CacheDir(
4✔
689
      `${this.STAKING_POOLED_STAKING_STATS_KEY}_${args.pool}`,
690
      args.cacheType,
691
    );
692
  }
693

694
  static getStakingDefiVaultStatsCacheDir(args: {
695
    cacheType: 'earn' | 'staking';
696
    chainId: string;
697
    vault: Address;
698
  }): CacheDir {
699
    return new CacheDir(
6✔
700
      `${args.chainId}_${this.STAKING_DEFI_VAULT_STATS_KEY}_${args.vault}`,
701
      args.cacheType,
702
    );
703
  }
704

705
  static getStakingDefiVaultStakesCacheDir(args: {
706
    cacheType: 'earn' | 'staking';
707
    chainId: string;
708
    safeAddress: Address;
709
    vault: Address;
710
  }): CacheDir {
711
    return new CacheDir(
6✔
712
      `${args.chainId}_${this.STAKING_DEFI_VAULT_STAKES_KEY}_${args.safeAddress}_${args.vault}`,
713
      args.cacheType,
714
    );
715
  }
716

717
  static getStakingDefiMorphoExtraRewardsCacheDir(args: {
718
    cacheType: 'earn' | 'staking';
719
    chainId: string;
720
    safeAddress: Address;
721
  }): CacheDir {
722
    return new CacheDir(
4✔
723
      `${args.chainId}_${this.STAKING_DEFI_MORPHO_EXTRA_REWARDS_KEY}_${args.safeAddress}`,
724
      args.cacheType,
725
    );
726
  }
727

728
  /**
729
   * Calculated the chain/Safe-specific cache key of {@link Stake}.
730
   *
731
   * @param {string} args.chainId - Chain ID
732
   * @param {string} args.safeAddress - Safe address
733
   * @returns {string} - Cache key
734
   */
735
  static getStakingStakesCacheKey(args: {
736
    chainId: string;
737
    safeAddress: Address;
738
  }): string {
739
    return `${args.chainId}_${CacheRouter.STAKING_STAKES_KEY}_${args.safeAddress}`;
84✔
740
  }
741

742
  /**
743
   * Calculate cache directory for staking stakes.
744
   *
745
   * Note: This function hashes the validators' public keys to keep the
746
   * cache field short and deterministic. Redis and other cache systems
747
   * may experience performance degradation with long fields.
748
   *
749
   * @param {string} args.cacheType - Cache type (earn or staking)
750
   * @param {string} args.chainId - Chain ID
751
   * @param {string} args.safeAddress - Safe address
752
   * @param {string} args.validatorsPublicKeys - Array of validators public keys
753
   * @returns {@link CacheDir} - Cache directory
754
   */
755
  static getStakingStakesCacheDir(args: {
756
    cacheType: 'earn' | 'staking';
757
    chainId: string;
758
    safeAddress: Address;
759
    validatorsPublicKeys: Array<Address>;
760
  }): CacheDir {
761
    const hash = crypto.createHash('sha256');
22✔
762
    hash.update(args.validatorsPublicKeys.join('_'));
22✔
763
    return new CacheDir(
22✔
764
      CacheRouter.getStakingStakesCacheKey(args),
765
      `${args.cacheType}_${hash.digest('hex')}`,
766
    );
767
  }
768

769
  static getUnsupportedChainEventCacheKey(chainId: string): string {
770
    return `${chainId}_${this.UNSUPPORTED_CHAIN_EVENT}`;
54✔
771
  }
772

773
  static getStakingTransactionStatusCacheDir(args: {
774
    cacheType: 'earn' | 'staking';
775
    chainId: string;
776
    txHash: Hash;
777
  }): CacheDir {
778
    return new CacheDir(
8✔
779
      `${args.chainId}_${CacheRouter.STAKING_TRANSACTION_STATUS_KEY}_${args.txHash}`,
780
      args.cacheType,
781
    );
782
  }
783

784
  static getTargetedSafeCacheKey(outreachId: number): string {
785
    return `${CacheRouter.TARGETED_MESSAGING_TARGETED_SAFE_KEY}_${outreachId}`;
52✔
786
  }
787

788
  static getTargetedSafeCacheDir(args: {
789
    outreachId: number;
790
    safeAddress: Address;
791
  }): CacheDir {
792
    return new CacheDir(
18✔
793
      CacheRouter.getTargetedSafeCacheKey(args.outreachId),
794
      args.safeAddress,
795
    );
796
  }
797

798
  static getSubmissionCacheKey(outreachId: number): string {
799
    return `${CacheRouter.TARGETED_MESSAGING_SUBMISSION_KEY}_${outreachId}`;
20✔
800
  }
801

802
  static getSubmissionCacheDir(args: {
803
    outreachId: number;
804
    safeAddress: Address;
805
    signerAddress: Address;
806
  }): CacheDir {
807
    return new CacheDir(
12✔
808
      CacheRouter.getSubmissionCacheKey(args.outreachId),
809
      `${args.safeAddress}_${args.signerAddress}`,
810
    );
811
  }
812

813
  static getOutreachesCacheDir(): CacheDir {
UNCOV
814
    return new CacheDir(CacheRouter.TARGETED_MESSAGING_OUTREACHES, '');
×
815
  }
816

817
  static getOutreachFileProcessorCacheKey(): string {
818
    return CacheRouter.TARGETED_MESSAGING_OUTREACH_FILE_PROCESSOR_LOCK;
66✔
819
  }
820

821
  static getOutreachFileProcessorCacheDir(): CacheDir {
822
    return new CacheDir(CacheRouter.getOutreachFileProcessorCacheKey(), '');
42✔
823
  }
824

825
  static getTransactionsExportCacheKey(args: {
826
    chainId: string;
827
    safeAddress: Address;
828
  }): string {
829
    return `${args.chainId}_${CacheRouter.TRANSACTIONS_EXPORT_KEY}_${args.safeAddress}`;
10✔
830
  }
831

832
  static getTransactionsExportCacheDir(args: {
833
    chainId: string;
834
    safeAddress: Address;
835
    executionDateGte?: string;
836
    executionDateLte?: string;
837
    limit?: number;
838
    offset?: number;
839
  }): CacheDir {
840
    return new CacheDir(
10✔
841
      CacheRouter.getTransactionsExportCacheKey(args),
842
      `${args.executionDateGte}_${args.executionDateLte}_${args.limit}_${args.offset}`,
843
    );
844
  }
845

846
  /**
847
   * Gets the in-memory cache key for the given cacheDir.
848
   */
849
  static getMemoryKey(cacheDir: CacheDir): string {
850
    return `${cacheDir.key}:${cacheDir.field}`;
306✔
851
  }
852

853
  /**
854
   * Gets Redis cache key for the ORM query cache.
855
   *
856
   * @param {string} prefix - Prefix for the cache key
857
   * @param {string} chainId - Chain ID
858
   * @param {string} safeAddress - Safe address
859
   *
860
   * @returns {string} - Cache key
861
   */
862
  static getOrnCacheKey(
863
    prefix: string,
864
    chainId: string,
865
    safeAddress: Address,
866
  ): string {
867
    return `${CacheRouter.ORM_QUERY_CACHE_KEY}:${prefix}:${chainId}:${safeAddress}`;
396✔
868
  }
869

870
  /**
871
   * Gets cache directory for contract analysis results.
872
   *
873
   * @param {string} args.chainId - Chain ID
874
   * @param {Address[]} args.contracts - Array of contract addresses
875
   * @returns {CacheDir} - Cache directory
876
   */
877
  static getContractAnalysisCacheDir(args: {
878
    chainId: string;
879
    contracts: Array<Address>;
880
  }): CacheDir {
NEW
881
    const contractsHash = crypto.createHash('sha256');
×
NEW
882
    contractsHash.update(args.contracts.sort().join(','));
×
NEW
883
    return new CacheDir(
×
884
      `${args.chainId}_${CacheRouter.CONTRACT_ANALYSIS_KEY}`,
885
      contractsHash.digest('hex'),
886
    );
887
  }
888
}
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