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

safe-global / safe-client-gateway / 14997886376

13 May 2025 01:27PM UTC coverage: 90.277% (-0.02%) from 90.296%
14997886376

Pull #2582

github

iamacook
feat: add caching to the Decoder Service
Pull Request #2582: feat: add caching to the Decoder Service

3289 of 3976 branches covered (82.72%)

Branch coverage included in aggregate %.

19 of 19 new or added lines in 4 files covered. (100.0%)

68 existing lines in 12 files now uncovered.

11399 of 12294 relevant lines covered (92.72%)

561.16 hits per line

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

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

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

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

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

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

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

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

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

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

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

139
  static getRateLimitCacheKey(prefix: string): string {
140
    return `${prefix}_${CacheRouter.RATE_LIMIT_KEY}`;
362✔
141
  }
142

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

391
  static getDecodedDataCacheKey(args: {
392
    chainId: string;
393
    data: `0x${string}`;
394
    to: `0x${string}`;
395
  }): string {
396
    return `${args.chainId}_${CacheRouter.DECODED_DATA_KEY}_${args.data}_${args.to}`;
82✔
397
  }
398

399
  static getDecodedDataCacheDir(args: {
400
    chainId: string;
401
    data: `0x${string}`;
402
    to: `0x${string}`;
403
  }): CacheDir {
404
    return new CacheDir(CacheRouter.getDecodedDataCacheKey(args), '');
82✔
405
  }
406

407
  static getDecodedDataContractsCacheKey(args: {
408
    chainIds: Array<string>;
409
    address: `0x${string}`;
410
    limit?: number;
411
    offset?: number;
412
  }): string {
413
    return `${args.chainIds.sort().join('_')}_${CacheRouter.DECODED_DATA_CONTRACTS_KEY}_${args.address}`;
6✔
414
  }
415

416
  static getDecodedDataContractsCacheDir(args: {
417
    chainIds: Array<string>;
418
    address: `0x${string}`;
419
    limit?: number;
420
    offset?: number;
421
  }): CacheDir {
422
    return new CacheDir(
6✔
423
      CacheRouter.getDecodedDataContractsCacheKey(args),
424
      `${args.limit}_${args.offset}`,
425
    );
426
  }
427

428
  static getAllTransactionsCacheDir(args: {
429
    chainId: string;
430
    safeAddress: `0x${string}`;
431
    ordering?: string;
432
    executed?: boolean;
433
    queued?: boolean;
434
    limit?: number;
435
    offset?: number;
436
  }): CacheDir {
437
    return new CacheDir(
76✔
438
      CacheRouter.getAllTransactionsKey(args),
439
      `${args.ordering}_${args.executed}_${args.queued}_${args.limit}_${args.offset}`,
440
    );
441
  }
442

443
  static getAllTransactionsKey(args: {
444
    chainId: string;
445
    safeAddress: `0x${string}`;
446
  }): string {
447
    return `${args.chainId}_${CacheRouter.ALL_TRANSACTIONS_KEY}_${args.safeAddress}`;
150✔
448
  }
449

450
  static getTokenCacheDir(args: {
451
    chainId: string;
452
    address: string;
453
  }): CacheDir {
454
    return new CacheDir(
1,430✔
455
      `${args.chainId}_${CacheRouter.TOKEN_KEY}_${args.address}`,
456
      '',
457
    );
458
  }
459

460
  static getTokensCacheKey(chainId: string): string {
461
    return `${chainId}_${CacheRouter.TOKENS_KEY}`;
8✔
462
  }
463

464
  static getTokensCacheDir(args: {
465
    chainId: string;
466
    limit?: number;
467
    offset?: number;
468
  }): CacheDir {
469
    return new CacheDir(
8✔
470
      CacheRouter.getTokensCacheKey(args.chainId),
471
      `${args.limit}_${args.offset}`,
472
    );
473
  }
474

475
  static getSafesByOwnerCacheDir(args: {
476
    chainId: string;
477
    ownerAddress: `0x${string}`;
478
  }): CacheDir {
479
    return new CacheDir(
32✔
480
      `${args.chainId}_${CacheRouter.OWNERS_SAFE_KEY}_${args.ownerAddress}`,
481
      '',
482
    );
483
  }
484

485
  static getMessageByHashCacheKey(args: {
486
    chainId: string;
487
    messageHash: string;
488
  }): string {
489
    return `${args.chainId}_${CacheRouter.MESSAGE_KEY}_${args.messageHash}`;
80✔
490
  }
491

492
  static getMessageByHashCacheDir(args: {
493
    chainId: string;
494
    messageHash: string;
495
  }): CacheDir {
496
    return new CacheDir(this.getMessageByHashCacheKey(args), '');
76✔
497
  }
498

499
  static getMessagesBySafeCacheKey(args: {
500
    chainId: string;
501
    safeAddress: `0x${string}`;
502
  }): string {
503
    return `${args.chainId}_${CacheRouter.MESSAGES_KEY}_${args.safeAddress}`;
98✔
504
  }
505

506
  static getMessagesBySafeCacheDir(args: {
507
    chainId: string;
508
    safeAddress: `0x${string}`;
509
    limit?: number;
510
    offset?: number;
511
  }): CacheDir {
512
    return new CacheDir(
70✔
513
      this.getMessagesBySafeCacheKey(args),
514
      `${args.limit}_${args.offset}`,
515
    );
516
  }
517

518
  static getChainsCacheKey(): string {
519
    return CacheRouter.CHAINS_KEY;
48✔
520
  }
521

522
  static getChainsCacheDir(args: {
523
    limit?: number;
524
    offset?: number;
525
  }): CacheDir {
526
    return new CacheDir(
34✔
527
      CacheRouter.getChainsCacheKey(),
528
      `${args.limit}_${args.offset}`,
529
    );
530
  }
531

532
  static getChainCacheKey(chainId: string): string {
533
    return `${chainId}_${CacheRouter.CHAIN_KEY}`;
2,180✔
534
  }
535

536
  static getChainCacheDir(chainId: string): CacheDir {
537
    return new CacheDir(CacheRouter.getChainCacheKey(chainId), '');
2,166✔
538
  }
539

540
  static getRelayKey(args: {
541
    chainId: string;
542
    address: `0x${string}`;
543
  }): string {
544
    return `${args.chainId}_${CacheRouter.RELAY_KEY}_${args.address}`;
466✔
545
  }
546

547
  static getRelayCacheDir(args: {
548
    chainId: string;
549
    address: `0x${string}`;
550
  }): CacheDir {
551
    return new CacheDir(CacheRouter.getRelayKey(args), '');
466✔
552
  }
553

554
  static getSafeAppsKey(chainId: string): string {
555
    return `${chainId}_${CacheRouter.SAFE_APPS_KEY}`;
4✔
556
  }
557

558
  static getSafeAppsCacheDir(args: {
559
    chainId?: string;
560
    clientUrl?: string;
561
    onlyListed?: boolean;
562
    url?: string;
563
  }): CacheDir {
564
    return new CacheDir(
90✔
565
      `${args.chainId}_${CacheRouter.SAFE_APPS_KEY}`,
566
      `${args.clientUrl}_${args.onlyListed}_${args.url}`,
567
    );
568
  }
569

570
  static getNativeCoinPriceCacheDir(args: {
571
    nativeCoinId: string;
572
    fiatCode: string;
573
  }): CacheDir {
574
    return new CacheDir(
42✔
575
      `${args.nativeCoinId}_${CacheRouter.NATIVE_COIN_PRICE_KEY}_${args.fiatCode}`,
576
      '',
577
    );
578
  }
579

580
  static getTokenPriceCacheDir(args: {
581
    chainName: string;
582
    fiatCode: string;
583
    tokenAddress: string;
584
  }): CacheDir {
585
    return new CacheDir(
214✔
586
      `${args.chainName}_${CacheRouter.TOKEN_PRICE_KEY}_${args.tokenAddress}_${args.fiatCode}`,
587
      '',
588
    );
589
  }
590

591
  static getPriceFiatCodesCacheDir(): CacheDir {
592
    return new CacheDir(CacheRouter.SAFE_FIAT_CODES_KEY, '');
10✔
593
  }
594

595
  static getAccountCacheDir(address: `0x${string}`): CacheDir {
596
    return new CacheDir(`${CacheRouter.ACCOUNT_KEY}_${address}`, '');
84✔
597
  }
598

599
  static getAccountDataTypesCacheDir(): CacheDir {
600
    return new CacheDir(CacheRouter.ACCOUNT_DATA_TYPES_KEY, '');
20✔
601
  }
602

603
  static getAccountDataSettingsCacheDir(address: `0x${string}`): CacheDir {
604
    return new CacheDir(
22✔
605
      `${CacheRouter.ACCOUNT_DATA_SETTINGS_KEY}_${address}`,
606
      '',
607
    );
608
  }
609

610
  static getCounterfactualSafeCacheDir(
611
    chainId: string,
612
    predictedAddress: `0x${string}`,
613
  ): CacheDir {
614
    return new CacheDir(
24✔
615
      `${chainId}_${CacheRouter.COUNTERFACTUAL_SAFE_KEY}_${predictedAddress}`,
616
      '',
617
    );
618
  }
619

620
  static getCounterfactualSafesCacheDir(address: `0x${string}`): CacheDir {
621
    return new CacheDir(
82✔
622
      `${CacheRouter.COUNTERFACTUAL_SAFES_KEY}_${address}`,
623
      '',
624
    );
625
  }
626

627
  static getRpcRequestsKey(chainId: string): string {
628
    return `${chainId}_${CacheRouter.RPC_REQUESTS_KEY}`;
16✔
629
  }
630

631
  static getRpcRequestsCacheDir(args: {
632
    chainId: string;
633
    method: string;
634
    params: string;
635
  }): CacheDir {
636
    return new CacheDir(
12✔
637
      CacheRouter.getRpcRequestsKey(args.chainId),
638
      `${args.method}_${args.params}`,
639
    );
640
  }
641

642
  // TODO: remove passing url and the associated configuration once Base is
643
  // fully migrated to the Kiln mainnet API.
644
  static getStakingDeploymentsCacheDir(url: string): CacheDir {
645
    return new CacheDir(`${this.STAKING_DEPLOYMENTS_KEY}_${url}`, '');
52✔
646
  }
647

648
  static getStakingNetworkStatsCacheDir(): CacheDir {
649
    return new CacheDir(this.STAKING_NETWORK_STATS_KEY, '');
22✔
650
  }
651

652
  static getStakingDedicatedStakingStatsCacheDir(): CacheDir {
653
    return new CacheDir(this.STAKING_DEDICATED_STAKING_STATS_KEY, '');
14✔
654
  }
655

656
  static getStakingPooledStakingStatsCacheDir(pool: `0x${string}`): CacheDir {
657
    return new CacheDir(`${this.STAKING_POOLED_STAKING_STATS_KEY}_${pool}`, '');
4✔
658
  }
659

660
  static getStakingDefiVaultStatsCacheDir(args: {
661
    chainId: string;
662
    vault: `0x${string}`;
663
  }): CacheDir {
664
    return new CacheDir(
6✔
665
      `${args.chainId}_${this.STAKING_DEFI_VAULT_STATS_KEY}_${args.vault}`,
666
      '',
667
    );
668
  }
669

670
  static getStakingDefiVaultStakesCacheDir(args: {
671
    chainId: string;
672
    safeAddress: `0x${string}`;
673
    vault: `0x${string}`;
674
  }): CacheDir {
675
    return new CacheDir(
6✔
676
      `${args.chainId}_${this.STAKING_DEFI_VAULT_STAKES_KEY}_${args.safeAddress}_${args.vault}`,
677
      '',
678
    );
679
  }
680

681
  static getStakingDefiMorphoExtraRewardsCacheDir(args: {
682
    chainId: string;
683
    safeAddress: `0x${string}`;
684
  }): CacheDir {
685
    return new CacheDir(
4✔
686
      `${args.chainId}_${this.STAKING_DEFI_MORPHO_EXTRA_REWARDS_KEY}_${args.safeAddress}`,
687
      '',
688
    );
689
  }
690

691
  /**
692
   * Calculated the chain/Safe-specific cache key of {@link Stake}.
693
   *
694
   * @param {string} args.chainId - Chain ID
695
   * @param {string} args.safeAddress - Safe address
696
   * @returns {string} - Cache key
697
   */
698
  static getStakingStakesCacheKey(args: {
699
    chainId: string;
700
    safeAddress: `0x${string}`;
701
  }): string {
702
    return `${args.chainId}_${CacheRouter.STAKING_STAKES_KEY}_${args.safeAddress}`;
56✔
703
  }
704

705
  /**
706
   * Calculate cache directory for staking stakes.
707
   *
708
   * Note: This function hashes the validators' public keys to keep the
709
   * cache field short and deterministic. Redis and other cache systems
710
   * may experience performance degradation with long fields.
711
   *
712
   * @param {string} args.chainId - Chain ID
713
   * @param {string} args.safeAddress - Safe address
714
   * @param {string} args.validatorsPublicKeys - Array of validators public keys
715
   * @returns {@link CacheDir} - Cache directory
716
   */
717
  static getStakingStakesCacheDir(args: {
718
    chainId: string;
719
    safeAddress: `0x${string}`;
720
    validatorsPublicKeys: Array<`0x${string}`>;
721
  }): CacheDir {
722
    const hash = crypto.createHash('sha256');
22✔
723
    hash.update(args.validatorsPublicKeys.join('_'));
22✔
724
    return new CacheDir(
22✔
725
      CacheRouter.getStakingStakesCacheKey(args),
726
      hash.digest('hex'),
727
    );
728
  }
729

730
  static getUnsupportedChainEventCacheKey(chainId: string): string {
731
    return `${chainId}_${this.UNSUPPORTED_CHAIN_EVENT}`;
54✔
732
  }
733

734
  static getStakingTransactionStatusCacheDir(args: {
735
    chainId: string;
736
    txHash: `0x${string}`;
737
  }): CacheDir {
738
    return new CacheDir(
8✔
739
      `${args.chainId}_${CacheRouter.STAKING_TRANSACTION_STATUS_KEY}_${args.txHash}`,
740
      '',
741
    );
742
  }
743

744
  static getTargetedSafeCacheKey(outreachId: number): string {
745
    return `${CacheRouter.TARGETED_MESSAGING_TARGETED_SAFE_KEY}_${outreachId}`;
52✔
746
  }
747

748
  static getTargetedSafeCacheDir(args: {
749
    outreachId: number;
750
    safeAddress: `0x${string}`;
751
  }): CacheDir {
752
    return new CacheDir(
18✔
753
      CacheRouter.getTargetedSafeCacheKey(args.outreachId),
754
      args.safeAddress,
755
    );
756
  }
757

758
  static getSubmissionCacheKey(outreachId: number): string {
759
    return `${CacheRouter.TARGETED_MESSAGING_SUBMISSION_KEY}_${outreachId}`;
20✔
760
  }
761

762
  static getSubmissionCacheDir(args: {
763
    outreachId: number;
764
    safeAddress: `0x${string}`;
765
    signerAddress: `0x${string}`;
766
  }): CacheDir {
767
    return new CacheDir(
12✔
768
      CacheRouter.getSubmissionCacheKey(args.outreachId),
769
      `${args.safeAddress}_${args.signerAddress}`,
770
    );
771
  }
772

773
  static getOutreachesCacheDir(): CacheDir {
UNCOV
774
    return new CacheDir(CacheRouter.TARGETED_MESSAGING_OUTREACHES, '');
×
775
  }
776

777
  static getOutreachFileProcessorCacheKey(): string {
778
    return CacheRouter.TARGETED_MESSAGING_OUTREACH_FILE_PROCESSOR_LOCK;
66✔
779
  }
780

781
  static getOutreachFileProcessorCacheDir(): CacheDir {
782
    return new CacheDir(CacheRouter.getOutreachFileProcessorCacheKey(), '');
42✔
783
  }
784

785
  /**
786
   * Gets the in-memory cache key for the given cacheDir.
787
   */
788
  static getMemoryKey(cacheDir: CacheDir): string {
789
    return `${cacheDir.key}:${cacheDir.field}`;
306✔
790
  }
791
}
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