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

safe-global / safe-client-gateway / 17978771535

24 Sep 2025 01:47PM UTC coverage: 89.224% (+0.04%) from 89.181%
17978771535

push

github

tmjssz
test: enhance SafeShieldService tests with additional scenarios for error handling and transaction decoding

3736 of 4596 branches covered (81.29%)

Branch coverage included in aggregate %.

12584 of 13695 relevant lines covered (91.89%)

529.07 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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