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

safe-global / safe-client-gateway / 15161591014

21 May 2025 12:00PM UTC coverage: 89.831% (-0.5%) from 90.359%
15161591014

Pull #2571

github

iamacook
feat: scaffold bridge mapper
Pull Request #2571: feat: scaffold bridge datasource

3333 of 4054 branches covered (82.22%)

Branch coverage included in aggregate %.

76 of 159 new or added lines in 17 files covered. (47.8%)

28 existing lines in 2 files now uncovered.

11588 of 12556 relevant lines covered (92.29%)

557.27 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

390
  static getAllTransactionsCacheDir(args: {
391
    chainId: string;
392
    safeAddress: `0x${string}`;
393
    ordering?: string;
394
    executed?: boolean;
395
    queued?: boolean;
396
    limit?: number;
397
    offset?: number;
398
  }): CacheDir {
399
    return new CacheDir(
76✔
400
      CacheRouter.getAllTransactionsKey(args),
401
      `${args.ordering}_${args.executed}_${args.queued}_${args.limit}_${args.offset}`,
402
    );
403
  }
404

405
  static getAllTransactionsKey(args: {
406
    chainId: string;
407
    safeAddress: `0x${string}`;
408
  }): string {
409
    return `${args.chainId}_${CacheRouter.ALL_TRANSACTIONS_KEY}_${args.safeAddress}`;
150✔
410
  }
411

412
  static getTokenCacheDir(args: {
413
    chainId: string;
414
    address: string;
415
  }): CacheDir {
416
    return new CacheDir(
1,430✔
417
      `${args.chainId}_${CacheRouter.TOKEN_KEY}_${args.address}`,
418
      '',
419
    );
420
  }
421

422
  static getTokensCacheKey(chainId: string): string {
423
    return `${chainId}_${CacheRouter.TOKENS_KEY}`;
8✔
424
  }
425

426
  static getTokensCacheDir(args: {
427
    chainId: string;
428
    limit?: number;
429
    offset?: number;
430
  }): CacheDir {
431
    return new CacheDir(
8✔
432
      CacheRouter.getTokensCacheKey(args.chainId),
433
      `${args.limit}_${args.offset}`,
434
    );
435
  }
436

437
  static getSafesByOwnerCacheDir(args: {
438
    chainId: string;
439
    ownerAddress: `0x${string}`;
440
  }): CacheDir {
441
    return new CacheDir(
32✔
442
      `${args.chainId}_${CacheRouter.OWNERS_SAFE_KEY}_${args.ownerAddress}`,
443
      '',
444
    );
445
  }
446

447
  static getMessageByHashCacheKey(args: {
448
    chainId: string;
449
    messageHash: string;
450
  }): string {
451
    return `${args.chainId}_${CacheRouter.MESSAGE_KEY}_${args.messageHash}`;
90✔
452
  }
453

454
  static getMessageByHashCacheDir(args: {
455
    chainId: string;
456
    messageHash: string;
457
  }): CacheDir {
458
    return new CacheDir(this.getMessageByHashCacheKey(args), '');
86✔
459
  }
460

461
  static getMessagesBySafeCacheKey(args: {
462
    chainId: string;
463
    safeAddress: `0x${string}`;
464
  }): string {
465
    return `${args.chainId}_${CacheRouter.MESSAGES_KEY}_${args.safeAddress}`;
98✔
466
  }
467

468
  static getMessagesBySafeCacheDir(args: {
469
    chainId: string;
470
    safeAddress: `0x${string}`;
471
    limit?: number;
472
    offset?: number;
473
  }): CacheDir {
474
    return new CacheDir(
70✔
475
      this.getMessagesBySafeCacheKey(args),
476
      `${args.limit}_${args.offset}`,
477
    );
478
  }
479

480
  static getChainsCacheKey(): string {
481
    return CacheRouter.CHAINS_KEY;
48✔
482
  }
483

484
  static getChainsCacheDir(args: {
485
    limit?: number;
486
    offset?: number;
487
  }): CacheDir {
488
    return new CacheDir(
34✔
489
      CacheRouter.getChainsCacheKey(),
490
      `${args.limit}_${args.offset}`,
491
    );
492
  }
493

494
  static getChainCacheKey(chainId: string): string {
495
    return `${chainId}_${CacheRouter.CHAIN_KEY}`;
2,176✔
496
  }
497

498
  static getChainCacheDir(chainId: string): CacheDir {
499
    return new CacheDir(CacheRouter.getChainCacheKey(chainId), '');
2,162✔
500
  }
501

502
  static getRelayKey(args: {
503
    chainId: string;
504
    address: `0x${string}`;
505
  }): string {
506
    return `${args.chainId}_${CacheRouter.RELAY_KEY}_${args.address}`;
466✔
507
  }
508

509
  static getRelayCacheDir(args: {
510
    chainId: string;
511
    address: `0x${string}`;
512
  }): CacheDir {
513
    return new CacheDir(CacheRouter.getRelayKey(args), '');
466✔
514
  }
515

516
  static getSafeAppsKey(chainId: string): string {
517
    return `${chainId}_${CacheRouter.SAFE_APPS_KEY}`;
4✔
518
  }
519

520
  static getSafeAppsCacheDir(args: {
521
    chainId?: string;
522
    clientUrl?: string;
523
    onlyListed?: boolean;
524
    url?: string;
525
  }): CacheDir {
526
    return new CacheDir(
90✔
527
      `${args.chainId}_${CacheRouter.SAFE_APPS_KEY}`,
528
      `${args.clientUrl}_${args.onlyListed}_${args.url}`,
529
    );
530
  }
531

532
  static getNativeCoinPriceCacheDir(args: {
533
    nativeCoinId: string;
534
    fiatCode: string;
535
  }): CacheDir {
536
    return new CacheDir(
42✔
537
      `${args.nativeCoinId}_${CacheRouter.NATIVE_COIN_PRICE_KEY}_${args.fiatCode}`,
538
      '',
539
    );
540
  }
541

542
  static getTokenPriceCacheDir(args: {
543
    chainName: string;
544
    fiatCode: string;
545
    tokenAddress: string;
546
  }): CacheDir {
547
    return new CacheDir(
214✔
548
      `${args.chainName}_${CacheRouter.TOKEN_PRICE_KEY}_${args.tokenAddress}_${args.fiatCode}`,
549
      '',
550
    );
551
  }
552

553
  static getPriceFiatCodesCacheDir(): CacheDir {
554
    return new CacheDir(CacheRouter.SAFE_FIAT_CODES_KEY, '');
10✔
555
  }
556

557
  static getAccountCacheDir(address: `0x${string}`): CacheDir {
558
    return new CacheDir(`${CacheRouter.ACCOUNT_KEY}_${address}`, '');
86✔
559
  }
560

561
  static getAccountDataTypesCacheDir(): CacheDir {
562
    return new CacheDir(CacheRouter.ACCOUNT_DATA_TYPES_KEY, '');
20✔
563
  }
564

565
  static getAccountDataSettingsCacheDir(address: `0x${string}`): CacheDir {
566
    return new CacheDir(
22✔
567
      `${CacheRouter.ACCOUNT_DATA_SETTINGS_KEY}_${address}`,
568
      '',
569
    );
570
  }
571

572
  static getCounterfactualSafeCacheDir(
573
    chainId: string,
574
    predictedAddress: `0x${string}`,
575
  ): CacheDir {
576
    return new CacheDir(
24✔
577
      `${chainId}_${CacheRouter.COUNTERFACTUAL_SAFE_KEY}_${predictedAddress}`,
578
      '',
579
    );
580
  }
581

582
  static getCounterfactualSafesCacheDir(address: `0x${string}`): CacheDir {
583
    return new CacheDir(
76✔
584
      `${CacheRouter.COUNTERFACTUAL_SAFES_KEY}_${address}`,
585
      '',
586
    );
587
  }
588

589
  static getRpcRequestsKey(chainId: string): string {
590
    return `${chainId}_${CacheRouter.RPC_REQUESTS_KEY}`;
16✔
591
  }
592

593
  static getRpcRequestsCacheDir(args: {
594
    chainId: string;
595
    method: string;
596
    params: string;
597
  }): CacheDir {
598
    return new CacheDir(
12✔
599
      CacheRouter.getRpcRequestsKey(args.chainId),
600
      `${args.method}_${args.params}`,
601
    );
602
  }
603

604
  // Kiln uses different endpoints for mainnet/testnet
605
  static getStakingDeploymentsCacheDir(url: string): CacheDir {
606
    return new CacheDir(`${this.STAKING_DEPLOYMENTS_KEY}_${url}`, '');
52✔
607
  }
608

609
  static getStakingNetworkStatsCacheDir(): CacheDir {
610
    return new CacheDir(this.STAKING_NETWORK_STATS_KEY, '');
22✔
611
  }
612

613
  static getStakingDedicatedStakingStatsCacheDir(): CacheDir {
614
    return new CacheDir(this.STAKING_DEDICATED_STAKING_STATS_KEY, '');
14✔
615
  }
616

617
  static getStakingPooledStakingStatsCacheDir(pool: `0x${string}`): CacheDir {
618
    return new CacheDir(`${this.STAKING_POOLED_STAKING_STATS_KEY}_${pool}`, '');
4✔
619
  }
620

621
  static getStakingDefiVaultStatsCacheDir(args: {
622
    chainId: string;
623
    vault: `0x${string}`;
624
  }): CacheDir {
625
    return new CacheDir(
6✔
626
      `${args.chainId}_${this.STAKING_DEFI_VAULT_STATS_KEY}_${args.vault}`,
627
      '',
628
    );
629
  }
630

631
  static getStakingDefiVaultStakesCacheDir(args: {
632
    chainId: string;
633
    safeAddress: `0x${string}`;
634
    vault: `0x${string}`;
635
  }): CacheDir {
636
    return new CacheDir(
6✔
637
      `${args.chainId}_${this.STAKING_DEFI_VAULT_STAKES_KEY}_${args.safeAddress}_${args.vault}`,
638
      '',
639
    );
640
  }
641

642
  static getStakingDefiMorphoExtraRewardsCacheDir(args: {
643
    chainId: string;
644
    safeAddress: `0x${string}`;
645
  }): CacheDir {
646
    return new CacheDir(
4✔
647
      `${args.chainId}_${this.STAKING_DEFI_MORPHO_EXTRA_REWARDS_KEY}_${args.safeAddress}`,
648
      '',
649
    );
650
  }
651

652
  /**
653
   * Calculated the chain/Safe-specific cache key of {@link Stake}.
654
   *
655
   * @param {string} args.chainId - Chain ID
656
   * @param {string} args.safeAddress - Safe address
657
   * @returns {string} - Cache key
658
   */
659
  static getStakingStakesCacheKey(args: {
660
    chainId: string;
661
    safeAddress: `0x${string}`;
662
  }): string {
663
    return `${args.chainId}_${CacheRouter.STAKING_STAKES_KEY}_${args.safeAddress}`;
56✔
664
  }
665

666
  /**
667
   * Calculate cache directory for staking stakes.
668
   *
669
   * Note: This function hashes the validators' public keys to keep the
670
   * cache field short and deterministic. Redis and other cache systems
671
   * may experience performance degradation with long fields.
672
   *
673
   * @param {string} args.chainId - Chain ID
674
   * @param {string} args.safeAddress - Safe address
675
   * @param {string} args.validatorsPublicKeys - Array of validators public keys
676
   * @returns {@link CacheDir} - Cache directory
677
   */
678
  static getStakingStakesCacheDir(args: {
679
    chainId: string;
680
    safeAddress: `0x${string}`;
681
    validatorsPublicKeys: Array<`0x${string}`>;
682
  }): CacheDir {
683
    const hash = crypto.createHash('sha256');
22✔
684
    hash.update(args.validatorsPublicKeys.join('_'));
22✔
685
    return new CacheDir(
22✔
686
      CacheRouter.getStakingStakesCacheKey(args),
687
      hash.digest('hex'),
688
    );
689
  }
690

691
  static getUnsupportedChainEventCacheKey(chainId: string): string {
692
    return `${chainId}_${this.UNSUPPORTED_CHAIN_EVENT}`;
54✔
693
  }
694

695
  static getStakingTransactionStatusCacheDir(args: {
696
    chainId: string;
697
    txHash: `0x${string}`;
698
  }): CacheDir {
699
    return new CacheDir(
8✔
700
      `${args.chainId}_${CacheRouter.STAKING_TRANSACTION_STATUS_KEY}_${args.txHash}`,
701
      '',
702
    );
703
  }
704

705
  static getTargetedSafeCacheKey(outreachId: number): string {
706
    return `${CacheRouter.TARGETED_MESSAGING_TARGETED_SAFE_KEY}_${outreachId}`;
52✔
707
  }
708

709
  static getTargetedSafeCacheDir(args: {
710
    outreachId: number;
711
    safeAddress: `0x${string}`;
712
  }): CacheDir {
713
    return new CacheDir(
18✔
714
      CacheRouter.getTargetedSafeCacheKey(args.outreachId),
715
      args.safeAddress,
716
    );
717
  }
718

719
  static getSubmissionCacheKey(outreachId: number): string {
720
    return `${CacheRouter.TARGETED_MESSAGING_SUBMISSION_KEY}_${outreachId}`;
20✔
721
  }
722

723
  static getSubmissionCacheDir(args: {
724
    outreachId: number;
725
    safeAddress: `0x${string}`;
726
    signerAddress: `0x${string}`;
727
  }): CacheDir {
728
    return new CacheDir(
12✔
729
      CacheRouter.getSubmissionCacheKey(args.outreachId),
730
      `${args.safeAddress}_${args.signerAddress}`,
731
    );
732
  }
733

734
  static getOutreachesCacheDir(): CacheDir {
UNCOV
735
    return new CacheDir(CacheRouter.TARGETED_MESSAGING_OUTREACHES, '');
×
736
  }
737

738
  static getOutreachFileProcessorCacheKey(): string {
739
    return CacheRouter.TARGETED_MESSAGING_OUTREACH_FILE_PROCESSOR_LOCK;
66✔
740
  }
741

742
  static getOutreachFileProcessorCacheDir(): CacheDir {
743
    return new CacheDir(CacheRouter.getOutreachFileProcessorCacheKey(), '');
42✔
744
  }
745

746
  /**
747
   * Gets the in-memory cache key for the given cacheDir.
748
   */
749
  static getMemoryKey(cacheDir: CacheDir): string {
750
    return `${cacheDir.key}:${cacheDir.field}`;
306✔
751
  }
752

753
  /**
754
   * Gets Redis cache key for the ORM query cache.
755
   *
756
   * @param {string} prefix - Prefix for the cache key
757
   * @param {string} chainId - Chain ID
758
   * @param {string} safeAddress - Safe address
759
   *
760
   * @returns {string} - Cache key
761
   */
762
  static getOrnCacheKey(
763
    prefix: string,
764
    chainId: string,
765
    safeAddress: `0x${string}`,
766
  ): string {
767
    return `${CacheRouter.ORM_QUERY_CACHE_KEY}:${prefix}:${chainId}:${safeAddress}`;
254✔
768
  }
769
}
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