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

safe-global / safe-client-gateway / 16990838651

15 Aug 2025 01:19PM UTC coverage: 89.011% (-0.5%) from 89.496%
16990838651

push

github

web-flow
fix: update test config with zerionPositions ff (#2679)

Signed-off-by: dsh <11198975+LucieFaire@users.noreply.github.com>

3510 of 4357 branches covered (80.56%)

Branch coverage included in aggregate %.

12244 of 13342 relevant lines covered (91.77%)

535.34 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

155
  static getZerionPositionsCacheDir(args: {
156
    chainId: string;
157
    safeAddress: `0x${string}`;
158
    fiatCode: string;
159
  }): CacheDir {
160
    return new CacheDir(
×
161
      CacheRouter.getZerionPositionsCacheKey(args),
162
      args.fiatCode,
163
    );
164
  }
165

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

170
  static getSafeCacheDir(args: {
171
    chainId: string;
172
    safeAddress: `0x${string}`;
173
  }): CacheDir {
174
    return new CacheDir(CacheRouter.getSafeCacheKey(args), '');
868✔
175
  }
176

177
  static getSafeCacheKey(args: {
178
    chainId: string;
179
    safeAddress: `0x${string}`;
180
  }): string {
181
    return `${args.chainId}_${CacheRouter.SAFE_KEY}_${args.safeAddress}`;
902✔
182
  }
183

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

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

198
  static getContractCacheDir(args: {
199
    chainId: string;
200
    contractAddress: `0x${string}`;
201
  }): CacheDir {
202
    return new CacheDir(
6✔
203
      `${args.chainId}_${CacheRouter.CONTRACT_KEY}_${args.contractAddress}`,
204
      '',
205
    );
206
  }
207

208
  static getTrustedForDelegateCallContractsCacheKey(chainId: string): string {
209
    return `${chainId}_${CacheRouter.TRUSTED_FOR_DELEGATE_CALL_CONTRACTS_KEY}`;
16✔
210
  }
211

212
  static getTrustedForDelegateCallContractsCacheDir(chainId: string): CacheDir {
213
    return new CacheDir(
16✔
214
      CacheRouter.getTrustedForDelegateCallContractsCacheKey(chainId),
215
      '',
216
    );
217
  }
218

219
  static getBackboneCacheDir(chainId: string): CacheDir {
220
    return new CacheDir(`${chainId}_${CacheRouter.BACKBONE_KEY}`, '');
16✔
221
  }
222

223
  static getSingletonsCacheDir(chainId: string): CacheDir {
224
    return new CacheDir(`${chainId}_${CacheRouter.SINGLETONS_KEY}`, '');
68✔
225
  }
226

227
  static getCollectiblesCacheDir(args: {
228
    chainId: string;
229
    safeAddress: `0x${string}`;
230
    limit?: number;
231
    offset?: number;
232
    trusted?: boolean;
233
    excludeSpam?: boolean;
234
  }): CacheDir {
235
    return new CacheDir(
10✔
236
      CacheRouter.getCollectiblesKey(args),
237
      `${args.limit}_${args.offset}_${args.trusted}_${args.excludeSpam}`,
238
    );
239
  }
240

241
  static getCollectiblesKey(args: {
242
    chainId: string;
243
    safeAddress: `0x${string}`;
244
  }): string {
245
    return `${args.chainId}_${CacheRouter.SAFE_COLLECTIBLES_KEY}_${args.safeAddress}`;
52✔
246
  }
247

248
  static getDelegatesCacheKey(args: {
249
    chainId: string;
250
    safeAddress?: `0x${string}`;
251
  }): string {
252
    return `${args.chainId}_${CacheRouter.DELEGATES_KEY}_${args.safeAddress}`;
178✔
253
  }
254

255
  static getDelegatesCacheDir(args: {
256
    chainId: string;
257
    safeAddress?: `0x${string}`;
258
    delegate?: `0x${string}`;
259
    delegator?: `0x${string}`;
260
    label?: string;
261
    limit?: number;
262
    offset?: number;
263
  }): CacheDir {
264
    return new CacheDir(
172✔
265
      CacheRouter.getDelegatesCacheKey(args),
266
      `${args.delegate}_${args.delegator}_${args.label}_${args.limit}_${args.offset}`,
267
    );
268
  }
269

270
  static getFirebaseOAuth2TokenCacheDir(): CacheDir {
271
    return new CacheDir(CacheRouter.FIREBASE_OAUTH2_TOKEN_KEY, '');
8✔
272
  }
273

274
  static getTransferCacheDir(args: {
275
    chainId: string;
276
    transferId: string;
277
  }): CacheDir {
278
    return new CacheDir(
10✔
279
      `${args.chainId}_${CacheRouter.TRANSFER_KEY}_${args.transferId}`,
280
      '',
281
    );
282
  }
283

284
  static getTransfersCacheDir(args: {
285
    chainId: string;
286
    safeAddress: string;
287
    onlyErc20: boolean;
288
    onlyErc721: boolean;
289
    limit?: number;
290
    offset?: number;
291
  }): CacheDir {
292
    return new CacheDir(
118✔
293
      CacheRouter.getTransfersCacheKey(args),
294
      `${args.onlyErc20}_${args.onlyErc721}_${args.limit}_${args.offset}`,
295
    );
296
  }
297

298
  static getTransfersCacheKey(args: {
299
    chainId: string;
300
    safeAddress: string;
301
  }): string {
302
    return `${args.chainId}_${CacheRouter.TRANSFERS_KEY}_${args.safeAddress}`;
178✔
303
  }
304

305
  static getModuleTransactionCacheDir(args: {
306
    chainId: string;
307
    moduleTransactionId: string;
308
  }): CacheDir {
309
    return new CacheDir(
12✔
310
      `${args.chainId}_${CacheRouter.MODULE_TRANSACTION_KEY}_${args.moduleTransactionId}`,
311
      '',
312
    );
313
  }
314

315
  static getModuleTransactionsCacheDir(args: {
316
    chainId: string;
317
    safeAddress: `0x${string}`;
318
    to?: string;
319
    txHash?: string;
320
    module?: string;
321
    limit?: number;
322
    offset?: number;
323
  }): CacheDir {
324
    return new CacheDir(
70✔
325
      CacheRouter.getModuleTransactionsCacheKey(args),
326
      `${args.to}_${args.module}_${args.txHash}_${args.limit}_${args.offset}`,
327
    );
328
  }
329

330
  static getModuleTransactionsCacheKey(args: {
331
    chainId: string;
332
    safeAddress: `0x${string}`;
333
  }): string {
334
    return `${args.chainId}_${CacheRouter.MODULE_TRANSACTIONS_KEY}_${args.safeAddress}`;
86✔
335
  }
336

337
  static getIncomingTransfersCacheDir(args: {
338
    chainId: string;
339
    safeAddress: string;
340
    executionDateGte?: string;
341
    executionDateLte?: string;
342
    to?: string;
343
    value?: string;
344
    tokenAddress?: string;
345
    txHash?: string;
346
    limit?: number;
347
    offset?: number;
348
  }): CacheDir {
349
    return new CacheDir(
50✔
350
      CacheRouter.getIncomingTransfersCacheKey(args),
351
      `${args.executionDateGte}_${args.executionDateLte}_${args.to}_${args.value}_${args.tokenAddress}_${args.txHash}_${args.limit}_${args.offset}`,
352
    );
353
  }
354

355
  static getIncomingTransfersCacheKey(args: {
356
    chainId: string;
357
    safeAddress: string;
358
  }): string {
359
    return `${args.chainId}_${CacheRouter.INCOMING_TRANSFERS_KEY}_${args.safeAddress}`;
80✔
360
  }
361

362
  static getIndexingCacheDir(chainId: string): CacheDir {
363
    return new CacheDir(`${chainId}_${CacheRouter.INDEXING_KEY}`, '');
12✔
364
  }
365

366
  static getMultisigTransactionsCacheDir(args: {
367
    chainId: string;
368
    safeAddress: string;
369
    ordering?: string;
370
    executed?: boolean;
371
    trusted?: boolean;
372
    executionDateGte?: string;
373
    executionDateLte?: string;
374
    to?: string;
375
    value?: string;
376
    nonce?: string;
377
    nonceGte?: number;
378
    limit?: number;
379
    offset?: number;
380
  }): CacheDir {
381
    return new CacheDir(
240✔
382
      CacheRouter.getMultisigTransactionsCacheKey(args),
383
      `${args.ordering}_${args.executed}_${args.trusted}_${args.executionDateGte}_${args.executionDateLte}_${args.to}_${args.value}_${args.nonce}_${args.nonceGte}_${args.limit}_${args.offset}`,
384
    );
385
  }
386

387
  static getMultisigTransactionsCacheKey(args: {
388
    chainId: string;
389
    safeAddress: string;
390
  }): string {
391
    return `${args.chainId}_${CacheRouter.MULTISIG_TRANSACTIONS_KEY}_${args.safeAddress}`;
342✔
392
  }
393

394
  static getMultisigTransactionCacheDir(args: {
395
    chainId: string;
396
    safeTransactionHash: string;
397
  }): CacheDir {
398
    return new CacheDir(CacheRouter.getMultisigTransactionCacheKey(args), '');
138✔
399
  }
400

401
  static getMultisigTransactionCacheKey(args: {
402
    chainId: string;
403
    safeTransactionHash: string;
404
  }): string {
405
    return `${args.chainId}_${CacheRouter.MULTISIG_TRANSACTION_KEY}_${args.safeTransactionHash}`;
200✔
406
  }
407

408
  static getCreationTransactionCacheDir(args: {
409
    chainId: string;
410
    safeAddress: `0x${string}`;
411
  }): CacheDir {
412
    return new CacheDir(
18✔
413
      `${args.chainId}_${CacheRouter.CREATION_TRANSACTION_KEY}_${args.safeAddress}`,
414
      '',
415
    );
416
  }
417

418
  static getDecodedDataCacheKey(args: {
419
    chainId: string;
420
    data: `0x${string}`;
421
    to: `0x${string}`;
422
  }): string {
423
    return `${args.chainId}_${CacheRouter.DECODED_DATA_KEY}_${args.data}_${args.to}`;
524✔
424
  }
425

426
  static getDecodedDataCacheDir(args: {
427
    chainId: string;
428
    data: `0x${string}`;
429
    to: `0x${string}`;
430
  }): CacheDir {
431
    return new CacheDir(CacheRouter.getDecodedDataCacheKey(args), '');
524✔
432
  }
433

434
  static getDecodedDataContractsCacheKey(args: {
435
    chainIds: Array<string>;
436
    address: `0x${string}`;
437
    limit?: number;
438
    offset?: number;
439
  }): string {
440
    return `${args.chainIds.sort().join('_')}_${CacheRouter.DECODED_DATA_CONTRACTS_KEY}_${args.address}`;
1,342✔
441
  }
442

443
  static getDecodedDataContractsCacheDir(args: {
444
    chainIds: Array<string>;
445
    address: `0x${string}`;
446
    limit?: number;
447
    offset?: number;
448
  }): CacheDir {
449
    return new CacheDir(
1,342✔
450
      CacheRouter.getDecodedDataContractsCacheKey(args),
451
      `${args.limit}_${args.offset}`,
452
    );
453
  }
454

455
  static getAllTransactionsCacheDir(args: {
456
    chainId: string;
457
    safeAddress: `0x${string}`;
458
    ordering?: string;
459
    executed?: boolean;
460
    queued?: boolean;
461
    limit?: number;
462
    offset?: number;
463
  }): CacheDir {
464
    return new CacheDir(
76✔
465
      CacheRouter.getAllTransactionsKey(args),
466
      `${args.ordering}_${args.executed}_${args.queued}_${args.limit}_${args.offset}`,
467
    );
468
  }
469

470
  static getAllTransactionsKey(args: {
471
    chainId: string;
472
    safeAddress: `0x${string}`;
473
  }): string {
474
    return `${args.chainId}_${CacheRouter.ALL_TRANSACTIONS_KEY}_${args.safeAddress}`;
150✔
475
  }
476

477
  static getTokenCacheDir(args: {
478
    chainId: string;
479
    address: string;
480
  }): CacheDir {
481
    return new CacheDir(
1,430✔
482
      `${args.chainId}_${CacheRouter.TOKEN_KEY}_${args.address}`,
483
      '',
484
    );
485
  }
486

487
  static getTokensCacheKey(chainId: string): string {
488
    return `${chainId}_${CacheRouter.TOKENS_KEY}`;
8✔
489
  }
490

491
  static getTokensCacheDir(args: {
492
    chainId: string;
493
    limit?: number;
494
    offset?: number;
495
  }): CacheDir {
496
    return new CacheDir(
8✔
497
      CacheRouter.getTokensCacheKey(args.chainId),
498
      `${args.limit}_${args.offset}`,
499
    );
500
  }
501

502
  static getSafesByOwnerCacheDir(args: {
503
    chainId: string;
504
    ownerAddress: `0x${string}`;
505
  }): CacheDir {
506
    return new CacheDir(
32✔
507
      `${args.chainId}_${CacheRouter.OWNERS_SAFE_KEY}_${args.ownerAddress}`,
508
      '',
509
    );
510
  }
511

512
  static getMessageByHashCacheKey(args: {
513
    chainId: string;
514
    messageHash: string;
515
  }): string {
516
    return `${args.chainId}_${CacheRouter.MESSAGE_KEY}_${args.messageHash}`;
80✔
517
  }
518

519
  static getMessageByHashCacheDir(args: {
520
    chainId: string;
521
    messageHash: string;
522
  }): CacheDir {
523
    return new CacheDir(this.getMessageByHashCacheKey(args), '');
76✔
524
  }
525

526
  static getMessagesBySafeCacheKey(args: {
527
    chainId: string;
528
    safeAddress: `0x${string}`;
529
  }): string {
530
    return `${args.chainId}_${CacheRouter.MESSAGES_KEY}_${args.safeAddress}`;
98✔
531
  }
532

533
  static getMessagesBySafeCacheDir(args: {
534
    chainId: string;
535
    safeAddress: `0x${string}`;
536
    limit?: number;
537
    offset?: number;
538
  }): CacheDir {
539
    return new CacheDir(
70✔
540
      this.getMessagesBySafeCacheKey(args),
541
      `${args.limit}_${args.offset}`,
542
    );
543
  }
544

545
  static getChainsCacheKey(): string {
546
    return CacheRouter.CHAINS_KEY;
48✔
547
  }
548

549
  static getChainsCacheDir(args: {
550
    limit?: number;
551
    offset?: number;
552
  }): CacheDir {
553
    return new CacheDir(
34✔
554
      CacheRouter.getChainsCacheKey(),
555
      `${args.limit}_${args.offset}`,
556
    );
557
  }
558

559
  static getChainCacheKey(chainId: string): string {
560
    return `${chainId}_${CacheRouter.CHAIN_KEY}`;
2,206✔
561
  }
562

563
  static getChainCacheDir(chainId: string): CacheDir {
564
    return new CacheDir(CacheRouter.getChainCacheKey(chainId), '');
2,192✔
565
  }
566

567
  static getRelayKey(args: {
568
    chainId: string;
569
    address: `0x${string}`;
570
  }): string {
571
    return `${args.chainId}_${CacheRouter.RELAY_KEY}_${args.address}`;
466✔
572
  }
573

574
  static getRelayCacheDir(args: {
575
    chainId: string;
576
    address: `0x${string}`;
577
  }): CacheDir {
578
    return new CacheDir(CacheRouter.getRelayKey(args), '');
466✔
579
  }
580

581
  static getSafeAppsKey(chainId: string): string {
582
    return `${chainId}_${CacheRouter.SAFE_APPS_KEY}`;
4✔
583
  }
584

585
  static getSafeAppsCacheDir(args: {
586
    chainId?: string;
587
    clientUrl?: string;
588
    onlyListed?: boolean;
589
    url?: string;
590
  }): CacheDir {
591
    return new CacheDir(
90✔
592
      `${args.chainId}_${CacheRouter.SAFE_APPS_KEY}`,
593
      `${args.clientUrl}_${args.onlyListed}_${args.url}`,
594
    );
595
  }
596

597
  static getNativeCoinPriceCacheDir(args: {
598
    nativeCoinId: string;
599
    fiatCode: string;
600
  }): CacheDir {
601
    return new CacheDir(
42✔
602
      `${args.nativeCoinId}_${CacheRouter.NATIVE_COIN_PRICE_KEY}_${args.fiatCode}`,
603
      '',
604
    );
605
  }
606

607
  static getTokenPriceCacheDir(args: {
608
    chainName: string;
609
    fiatCode: string;
610
    tokenAddress: string;
611
  }): CacheDir {
612
    return new CacheDir(
214✔
613
      `${args.chainName}_${CacheRouter.TOKEN_PRICE_KEY}_${args.tokenAddress}_${args.fiatCode}`,
614
      '',
615
    );
616
  }
617

618
  static getPriceFiatCodesCacheDir(): CacheDir {
619
    return new CacheDir(CacheRouter.SAFE_FIAT_CODES_KEY, '');
10✔
620
  }
621

622
  static getAccountCacheDir(address: `0x${string}`): CacheDir {
623
    return new CacheDir(`${CacheRouter.ACCOUNT_KEY}_${address}`, '');
80✔
624
  }
625

626
  static getAccountDataTypesCacheDir(): CacheDir {
627
    return new CacheDir(CacheRouter.ACCOUNT_DATA_TYPES_KEY, '');
20✔
628
  }
629

630
  static getAccountDataSettingsCacheDir(address: `0x${string}`): CacheDir {
631
    return new CacheDir(
22✔
632
      `${CacheRouter.ACCOUNT_DATA_SETTINGS_KEY}_${address}`,
633
      '',
634
    );
635
  }
636

637
  static getCounterfactualSafeCacheDir(
638
    chainId: string,
639
    predictedAddress: `0x${string}`,
640
  ): CacheDir {
641
    return new CacheDir(
24✔
642
      `${chainId}_${CacheRouter.COUNTERFACTUAL_SAFE_KEY}_${predictedAddress}`,
643
      '',
644
    );
645
  }
646

647
  static getCounterfactualSafesCacheDir(address: `0x${string}`): CacheDir {
648
    return new CacheDir(
86✔
649
      `${CacheRouter.COUNTERFACTUAL_SAFES_KEY}_${address}`,
650
      '',
651
    );
652
  }
653

654
  static getRpcRequestsKey(chainId: string): string {
655
    return `${chainId}_${CacheRouter.RPC_REQUESTS_KEY}`;
16✔
656
  }
657

658
  static getRpcRequestsCacheDir(args: {
659
    chainId: string;
660
    method: string;
661
    params: string;
662
  }): CacheDir {
663
    return new CacheDir(
12✔
664
      CacheRouter.getRpcRequestsKey(args.chainId),
665
      `${args.method}_${args.params}`,
666
    );
667
  }
668

669
  static getStakingDeploymentsCacheDir(
670
    cacheType: 'earn' | 'staking',
671
  ): CacheDir {
672
    return new CacheDir(this.STAKING_DEPLOYMENTS_KEY, cacheType);
52✔
673
  }
674

675
  static getStakingRewardsFeeCacheDir(args: {
676
    cacheType: 'earn' | 'staking';
677
    chainId: string;
678
    contract: `0x${string}`;
679
  }): CacheDir {
680
    return new CacheDir(
22✔
681
      `${args.chainId}_${this.STAKING_REWARDS_FEE_KEY}_${args.contract}`,
682
      args.cacheType,
683
    );
684
  }
685

686
  static getStakingNetworkStatsCacheDir(
687
    cacheType: 'earn' | 'staking',
688
  ): CacheDir {
689
    return new CacheDir(this.STAKING_NETWORK_STATS_KEY, cacheType);
22✔
690
  }
691

692
  static getStakingDedicatedStakingStatsCacheDir(
693
    cacheType: 'earn' | 'staking',
694
  ): CacheDir {
695
    return new CacheDir(this.STAKING_DEDICATED_STAKING_STATS_KEY, cacheType);
14✔
696
  }
697

698
  static getStakingPooledStakingStatsCacheDir(args: {
699
    cacheType: 'earn' | 'staking';
700
    pool: `0x${string}`;
701
  }): CacheDir {
702
    return new CacheDir(
4✔
703
      `${this.STAKING_POOLED_STAKING_STATS_KEY}_${args.pool}`,
704
      args.cacheType,
705
    );
706
  }
707

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

719
  static getStakingDefiVaultStakesCacheDir(args: {
720
    cacheType: 'earn' | 'staking';
721
    chainId: string;
722
    safeAddress: `0x${string}`;
723
    vault: `0x${string}`;
724
  }): CacheDir {
725
    return new CacheDir(
6✔
726
      `${args.chainId}_${this.STAKING_DEFI_VAULT_STAKES_KEY}_${args.safeAddress}_${args.vault}`,
727
      args.cacheType,
728
    );
729
  }
730

731
  static getStakingDefiMorphoExtraRewardsCacheDir(args: {
732
    cacheType: 'earn' | 'staking';
733
    chainId: string;
734
    safeAddress: `0x${string}`;
735
  }): CacheDir {
736
    return new CacheDir(
4✔
737
      `${args.chainId}_${this.STAKING_DEFI_MORPHO_EXTRA_REWARDS_KEY}_${args.safeAddress}`,
738
      args.cacheType,
739
    );
740
  }
741

742
  /**
743
   * Calculated the chain/Safe-specific cache key of {@link Stake}.
744
   *
745
   * @param {string} args.chainId - Chain ID
746
   * @param {string} args.safeAddress - Safe address
747
   * @returns {string} - Cache key
748
   */
749
  static getStakingStakesCacheKey(args: {
750
    chainId: string;
751
    safeAddress: `0x${string}`;
752
  }): string {
753
    return `${args.chainId}_${CacheRouter.STAKING_STAKES_KEY}_${args.safeAddress}`;
88✔
754
  }
755

756
  /**
757
   * Calculate cache directory for staking stakes.
758
   *
759
   * Note: This function hashes the validators' public keys to keep the
760
   * cache field short and deterministic. Redis and other cache systems
761
   * may experience performance degradation with long fields.
762
   *
763
   * @param {string} args.cacheType - Cache type (earn or staking)
764
   * @param {string} args.chainId - Chain ID
765
   * @param {string} args.safeAddress - Safe address
766
   * @param {string} args.validatorsPublicKeys - Array of validators public keys
767
   * @returns {@link CacheDir} - Cache directory
768
   */
769
  static getStakingStakesCacheDir(args: {
770
    cacheType: 'earn' | 'staking';
771
    chainId: string;
772
    safeAddress: `0x${string}`;
773
    validatorsPublicKeys: Array<`0x${string}`>;
774
  }): CacheDir {
775
    const hash = crypto.createHash('sha256');
22✔
776
    hash.update(args.validatorsPublicKeys.join('_'));
22✔
777
    return new CacheDir(
22✔
778
      CacheRouter.getStakingStakesCacheKey(args),
779
      `${args.cacheType}_${hash.digest('hex')}`,
780
    );
781
  }
782

783
  static getUnsupportedChainEventCacheKey(chainId: string): string {
784
    return `${chainId}_${this.UNSUPPORTED_CHAIN_EVENT}`;
54✔
785
  }
786

787
  static getStakingTransactionStatusCacheDir(args: {
788
    cacheType: 'earn' | 'staking';
789
    chainId: string;
790
    txHash: `0x${string}`;
791
  }): CacheDir {
792
    return new CacheDir(
8✔
793
      `${args.chainId}_${CacheRouter.STAKING_TRANSACTION_STATUS_KEY}_${args.txHash}`,
794
      args.cacheType,
795
    );
796
  }
797

798
  static getTargetedSafeCacheKey(outreachId: number): string {
799
    return `${CacheRouter.TARGETED_MESSAGING_TARGETED_SAFE_KEY}_${outreachId}`;
52✔
800
  }
801

802
  static getTargetedSafeCacheDir(args: {
803
    outreachId: number;
804
    safeAddress: `0x${string}`;
805
  }): CacheDir {
806
    return new CacheDir(
18✔
807
      CacheRouter.getTargetedSafeCacheKey(args.outreachId),
808
      args.safeAddress,
809
    );
810
  }
811

812
  static getSubmissionCacheKey(outreachId: number): string {
813
    return `${CacheRouter.TARGETED_MESSAGING_SUBMISSION_KEY}_${outreachId}`;
20✔
814
  }
815

816
  static getSubmissionCacheDir(args: {
817
    outreachId: number;
818
    safeAddress: `0x${string}`;
819
    signerAddress: `0x${string}`;
820
  }): CacheDir {
821
    return new CacheDir(
12✔
822
      CacheRouter.getSubmissionCacheKey(args.outreachId),
823
      `${args.safeAddress}_${args.signerAddress}`,
824
    );
825
  }
826

827
  static getOutreachesCacheDir(): CacheDir {
828
    return new CacheDir(CacheRouter.TARGETED_MESSAGING_OUTREACHES, '');
×
829
  }
830

831
  static getOutreachFileProcessorCacheKey(): string {
832
    return CacheRouter.TARGETED_MESSAGING_OUTREACH_FILE_PROCESSOR_LOCK;
66✔
833
  }
834

835
  static getOutreachFileProcessorCacheDir(): CacheDir {
836
    return new CacheDir(CacheRouter.getOutreachFileProcessorCacheKey(), '');
42✔
837
  }
838

839
  static getTransactionsExportCacheKey(args: {
840
    chainId: string;
841
    safeAddress: `0x${string}`;
842
  }): string {
843
    return `${args.chainId}_${CacheRouter.TRANSACTIONS_EXPORT_KEY}_${args.safeAddress}`;
10✔
844
  }
845

846
  static getTransactionsExportCacheDir(args: {
847
    chainId: string;
848
    safeAddress: `0x${string}`;
849
    executionDateGte?: string;
850
    executionDateLte?: string;
851
    limit?: number;
852
    offset?: number;
853
  }): CacheDir {
854
    return new CacheDir(
10✔
855
      CacheRouter.getTransactionsExportCacheKey(args),
856
      `${args.executionDateGte}_${args.executionDateLte}_${args.limit}_${args.offset}`,
857
    );
858
  }
859

860
  /**
861
   * Gets the in-memory cache key for the given cacheDir.
862
   */
863
  static getMemoryKey(cacheDir: CacheDir): string {
864
    return `${cacheDir.key}:${cacheDir.field}`;
306✔
865
  }
866

867
  /**
868
   * Gets Redis cache key for the ORM query cache.
869
   *
870
   * @param {string} prefix - Prefix for the cache key
871
   * @param {string} chainId - Chain ID
872
   * @param {string} safeAddress - Safe address
873
   *
874
   * @returns {string} - Cache key
875
   */
876
  static getOrnCacheKey(
877
    prefix: string,
878
    chainId: string,
879
    safeAddress: `0x${string}`,
880
  ): string {
881
    return `${CacheRouter.ORM_QUERY_CACHE_KEY}:${prefix}:${chainId}:${safeAddress}`;
344✔
882
  }
883
}
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