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

safe-global / safe-client-gateway / 18189645427

02 Oct 2025 09:54AM UTC coverage: 89.099% (-0.1%) from 89.197%
18189645427

Pull #2721

github

tmjssz
fix: remove unnecessary txInfo extraction
Pull Request #2721: refactor(safe-shield): Enhanced transaction decoding via TransactionsService

3761 of 4638 branches covered (81.09%)

Branch coverage included in aggregate %.

39 of 40 new or added lines in 4 files covered. (97.5%)

20 existing lines in 5 files now uncovered.

12667 of 13800 relevant lines covered (91.79%)

526.08 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

157
  static getZerionPositionsCacheDir(args: {
158
    chainId: string;
159
    safeAddress: Address;
160
    fiatCode: string;
161
    refresh?: string;
162
  }): CacheDir {
163
    return new CacheDir(
×
164
      CacheRouter.getZerionPositionsCacheKey(args),
165
      `${args.fiatCode}_${args.refresh ?? ''}`,
×
166
    );
167
  }
168

169
  static getRateLimitCacheKey(prefix: string): string {
170
    return `${prefix}_${CacheRouter.RATE_LIMIT_KEY}`;
384✔
171
  }
172

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

550
  static getChainCacheKey(chainId: string): string {
551
    return `${chainId}_${CacheRouter.CHAIN_KEY}`;
2,198✔
552
  }
553

554
  static getChainCacheDir(chainId: string): CacheDir {
555
    return new CacheDir(CacheRouter.getChainCacheKey(chainId), '');
2,184✔
556
  }
557

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

815
  static getOutreachesCacheDir(): CacheDir {
816
    return new CacheDir(CacheRouter.TARGETED_MESSAGING_OUTREACHES, '');
×
817
  }
818

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

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

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

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

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

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

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

891
  /**
892
   * Gets cache directory for recipient analysis results.
893
   *
894
   * @param {string} args.chainId - Chain ID
895
   * @param {Address[]} args.recipients - Array of recipient addresses
896
   * @returns {CacheDir} - Cache directory
897
   */
898
  static getRecipientAnalysisCacheDir(args: {
899
    chainId: string;
900
    recipients: Array<Address>;
901
  }): CacheDir {
902
    const recipientsHash = crypto.createHash('sha256');
8✔
903
    recipientsHash.update(args.recipients.sort().join(','));
8✔
904
    return new CacheDir(
8✔
905
      `${args.chainId}_${CacheRouter.RECIPIENT_ANALYSIS_KEY}`,
906
      recipientsHash.digest('hex'),
907
    );
908
  }
909
}
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