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

safe-global / safe-client-gateway / 10404779821

15 Aug 2024 01:42PM UTC coverage: 46.856% (-0.09%) from 46.944%
10404779821

Pull #1825

github

iamacook
Fix lint
Pull Request #1825: Add caching layer to RPC requests

480 of 2893 branches covered (16.59%)

Branch coverage included in aggregate %.

9 of 31 new or added lines in 2 files covered. (29.03%)

3 existing lines in 3 files now uncovered.

4558 of 7859 relevant lines covered (58.0%)

12.49 hits per line

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

58.25
/src/datasources/cache/cache.router.ts
1
import { CacheDir } from '@/datasources/cache/entities/cache-dir.entity';
16✔
2

3
export class CacheRouter {
16✔
4
  private static readonly ACCOUNT_KEY = 'account';
16✔
5
  private static readonly ACCOUNT_DATA_SETTINGS_KEY = 'account_data_settings';
16✔
6
  private static readonly ACCOUNT_DATA_TYPES_KEY = 'account_data_types';
16✔
7
  private static readonly ALL_TRANSACTIONS_KEY = 'all_transactions';
16✔
8
  private static readonly AUTH_NONCE_KEY = 'auth_nonce';
16✔
9
  private static readonly BACKBONE_KEY = 'backbone';
16✔
10
  private static readonly CHAIN_KEY = 'chain';
16✔
11
  private static readonly CHAINS_KEY = 'chains';
16✔
12
  private static readonly CONTRACT_KEY = 'contract';
16✔
13
  private static readonly COUNTERFACTUAL_SAFE_KEY = 'counterfactual_safe';
16✔
14
  private static readonly COUNTERFACTUAL_SAFES_KEY = 'counterfactual_safes';
16✔
15
  private static readonly CREATION_TRANSACTION_KEY = 'creation_transaction';
16✔
16
  private static readonly DELEGATES_KEY = 'delegates';
16✔
17
  private static readonly FIREBASE_OAUTH2_TOKEN_KEY = 'firebase_oauth2_token';
16✔
18
  private static readonly INCOMING_TRANSFERS_KEY = 'incoming_transfers';
16✔
19
  private static readonly MESSAGE_KEY = 'message';
16✔
20
  private static readonly MESSAGES_KEY = 'messages';
16✔
21
  private static readonly MODULE_TRANSACTION_KEY = 'module_transaction';
16✔
22
  private static readonly MODULE_TRANSACTIONS_KEY = 'module_transactions';
16✔
23
  private static readonly MULTISIG_TRANSACTION_KEY = 'multisig_transaction';
16✔
24
  private static readonly MULTISIG_TRANSACTIONS_KEY = 'multisig_transactions';
16✔
25
  private static readonly NATIVE_COIN_PRICE_KEY = 'native_coin_price';
16✔
26
  private static readonly OWNERS_SAFE_KEY = 'owner_safes';
16✔
27
  private static readonly RELAY_KEY = 'relay';
16✔
28
  private static readonly RPC_REQUESTS_KEY = 'rpc_requests';
16✔
29
  private static readonly SAFE_APPS_KEY = 'safe_apps';
16✔
30
  private static readonly SAFE_BALANCES_KEY = 'safe_balances';
16✔
31
  private static readonly SAFE_COLLECTIBLES_KEY = 'safe_collectibles';
16✔
32
  private static readonly SAFE_EXISTS_KEY = 'safe_exists';
16✔
33
  private static readonly SAFE_FIAT_CODES_KEY = 'safe_fiat_codes';
16✔
34
  private static readonly SAFE_KEY = 'safe';
16✔
35
  private static readonly SINGLETONS_KEY = 'singletons';
16✔
36
  private static readonly TOKEN_KEY = 'token';
16✔
37
  private static readonly TOKEN_PRICE_KEY = 'token_price';
16✔
38
  private static readonly TOKENS_KEY = 'tokens';
16✔
39
  private static readonly TRANSFER_KEY = 'transfer';
16✔
40
  private static readonly TRANSFERS_KEY = 'transfers';
16✔
41
  private static readonly ZERION_BALANCES_KEY = 'zerion_balances';
16✔
42
  private static readonly ZERION_COLLECTIBLES_KEY = 'zerion_collectibles';
16✔
43
  private static readonly RATE_LIMIT_KEY = 'rate_limit';
16✔
44

45
  static getAuthNonceCacheKey(nonce: string): string {
46
    return `${CacheRouter.AUTH_NONCE_KEY}_${nonce}`;
×
47
  }
48

49
  static getAuthNonceCacheDir(nonce: string): CacheDir {
50
    return new CacheDir(CacheRouter.getAuthNonceCacheKey(nonce), '');
×
51
  }
52

53
  static getBalancesCacheKey(args: {
54
    chainId: string;
55
    safeAddress: `0x${string}`;
56
  }): string {
57
    return `${args.chainId}_${CacheRouter.SAFE_BALANCES_KEY}_${args.safeAddress}`;
28✔
58
  }
59

60
  static getBalancesCacheDir(args: {
61
    chainId: string;
62
    safeAddress: `0x${string}`;
63
    trusted?: boolean;
64
    excludeSpam?: boolean;
65
  }): CacheDir {
66
    return new CacheDir(
×
67
      CacheRouter.getBalancesCacheKey(args),
68
      `${args.trusted}_${args.excludeSpam}`,
69
    );
70
  }
71

72
  static getZerionBalancesCacheKey(args: {
73
    chainId: string;
74
    safeAddress: `0x${string}`;
75
  }): string {
76
    return `${args.chainId}_${CacheRouter.ZERION_BALANCES_KEY}_${args.safeAddress}`;
×
77
  }
78

79
  static getZerionBalancesCacheDir(args: {
80
    chainId: string;
81
    safeAddress: `0x${string}`;
82
    fiatCode: string;
83
  }): CacheDir {
84
    return new CacheDir(
×
85
      CacheRouter.getZerionBalancesCacheKey(args),
86
      args.fiatCode,
87
    );
88
  }
89

90
  static getZerionCollectiblesCacheKey(args: {
91
    chainId: string;
92
    safeAddress: `0x${string}`;
93
  }): string {
94
    return `${args.chainId}_${CacheRouter.ZERION_COLLECTIBLES_KEY}_${args.safeAddress}`;
×
95
  }
96

97
  static getZerionCollectiblesCacheDir(args: {
98
    chainId: string;
99
    safeAddress: `0x${string}`;
100
    limit?: number;
101
    offset?: number;
102
  }): CacheDir {
103
    return new CacheDir(
×
104
      CacheRouter.getZerionCollectiblesCacheKey(args),
105
      `${args.limit}_${args.offset}`,
106
    );
107
  }
108

109
  static getRateLimitCacheKey(prefix: string): string {
110
    return `${prefix}_${CacheRouter.RATE_LIMIT_KEY}`;
×
111
  }
112

113
  static getSafeCacheDir(args: {
114
    chainId: string;
115
    safeAddress: `0x${string}`;
116
  }): CacheDir {
117
    return new CacheDir(CacheRouter.getSafeCacheKey(args), '');
×
118
  }
119

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

127
  static getIsSafeCacheDir(args: {
128
    chainId: string;
129
    safeAddress: `0x${string}`;
130
  }): CacheDir {
131
    return new CacheDir(CacheRouter.getIsSafeCacheKey(args), '');
×
132
  }
133

134
  static getIsSafeCacheKey(args: {
135
    chainId: string;
136
    safeAddress: `0x${string}`;
137
  }): string {
138
    return `${args.chainId}_${CacheRouter.SAFE_EXISTS_KEY}_${args.safeAddress}`;
×
139
  }
140

141
  static getContractCacheDir(args: {
142
    chainId: string;
143
    contractAddress: `0x${string}`;
144
  }): CacheDir {
145
    return new CacheDir(
2✔
146
      `${args.chainId}_${CacheRouter.CONTRACT_KEY}_${args.contractAddress}`,
147
      '',
148
    );
149
  }
150

151
  static getBackboneCacheDir(chainId: string): CacheDir {
152
    return new CacheDir(`${chainId}_${CacheRouter.BACKBONE_KEY}`, '');
×
153
  }
154

155
  static getSingletonsCacheDir(chainId: string): CacheDir {
156
    return new CacheDir(`${chainId}_${CacheRouter.SINGLETONS_KEY}`, '');
×
157
  }
158

159
  static getCollectiblesCacheDir(args: {
160
    chainId: string;
161
    safeAddress: `0x${string}`;
162
    limit?: number;
163
    offset?: number;
164
    trusted?: boolean;
165
    excludeSpam?: boolean;
166
  }): CacheDir {
167
    return new CacheDir(
×
168
      CacheRouter.getCollectiblesKey(args),
169
      `${args.limit}_${args.offset}_${args.trusted}_${args.excludeSpam}`,
170
    );
171
  }
172

173
  static getCollectiblesKey(args: {
174
    chainId: string;
175
    safeAddress: `0x${string}`;
176
  }): string {
177
    return `${args.chainId}_${CacheRouter.SAFE_COLLECTIBLES_KEY}_${args.safeAddress}`;
30✔
178
  }
179

180
  static getDelegatesCacheDir(args: {
181
    chainId: string;
182
    safeAddress?: `0x${string}`;
183
    delegate?: `0x${string}`;
184
    delegator?: `0x${string}`;
185
    label?: string;
186
    limit?: number;
187
    offset?: number;
188
  }): CacheDir {
189
    return new CacheDir(
×
190
      `${args.chainId}_${CacheRouter.DELEGATES_KEY}_${args.safeAddress}`,
191
      `${args.delegate}_${args.delegator}_${args.label}_${args.limit}_${args.offset}`,
192
    );
193
  }
194

195
  static getFirebaseOAuth2TokenCacheDir(): CacheDir {
196
    return new CacheDir(CacheRouter.FIREBASE_OAUTH2_TOKEN_KEY, '');
×
197
  }
198

199
  static getTransferCacheDir(args: {
200
    chainId: string;
201
    transferId: string;
202
  }): CacheDir {
203
    return new CacheDir(
×
204
      `${args.chainId}_${CacheRouter.TRANSFER_KEY}_${args.transferId}`,
205
      '',
206
    );
207
  }
208

209
  static getTransfersCacheDir(args: {
210
    chainId: string;
211
    safeAddress: string;
212
    onlyErc20: boolean;
213
    onlyErc721: boolean;
214
    limit?: number;
215
    offset?: number;
216
  }): CacheDir {
217
    return new CacheDir(
×
218
      CacheRouter.getTransfersCacheKey(args),
219
      `${args.onlyErc20}_${args.onlyErc721}_${args.limit}_${args.offset}`,
220
    );
221
  }
222

223
  static getTransfersCacheKey(args: {
224
    chainId: string;
225
    safeAddress: string;
226
  }): string {
227
    return `${args.chainId}_${CacheRouter.TRANSFERS_KEY}_${args.safeAddress}`;
40✔
228
  }
229

230
  static getModuleTransactionCacheDir(args: {
231
    chainId: string;
232
    moduleTransactionId: string;
233
  }): CacheDir {
234
    return new CacheDir(
×
235
      `${args.chainId}_${CacheRouter.MODULE_TRANSACTION_KEY}_${args.moduleTransactionId}`,
236
      '',
237
    );
238
  }
239

240
  static getModuleTransactionsCacheDir(args: {
241
    chainId: string;
242
    safeAddress: `0x${string}`;
243
    to?: string;
244
    txHash?: string;
245
    module?: string;
246
    limit?: number;
247
    offset?: number;
248
  }): CacheDir {
249
    return new CacheDir(
×
250
      CacheRouter.getModuleTransactionsCacheKey(args),
251
      `${args.to}_${args.module}_${args.txHash}_${args.limit}_${args.offset}`,
252
    );
253
  }
254

255
  static getModuleTransactionsCacheKey(args: {
256
    chainId: string;
257
    safeAddress: `0x${string}`;
258
  }): string {
259
    return `${args.chainId}_${CacheRouter.MODULE_TRANSACTIONS_KEY}_${args.safeAddress}`;
6✔
260
  }
261

262
  static getIncomingTransfersCacheDir(args: {
263
    chainId: string;
264
    safeAddress: string;
265
    executionDateGte?: string;
266
    executionDateLte?: string;
267
    to?: string;
268
    value?: string;
269
    tokenAddress?: string;
270
    txHash?: string;
271
    limit?: number;
272
    offset?: number;
273
  }): CacheDir {
274
    return new CacheDir(
×
275
      CacheRouter.getIncomingTransfersCacheKey(args),
276
      `${args.executionDateGte}_${args.executionDateLte}_${args.to}_${args.value}_${args.tokenAddress}_${args.txHash}_${args.limit}_${args.offset}`,
277
    );
278
  }
279

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

287
  static getMultisigTransactionsCacheDir(args: {
288
    chainId: string;
289
    safeAddress: string;
290
    ordering?: string;
291
    executed?: boolean;
292
    trusted?: boolean;
293
    executionDateGte?: string;
294
    executionDateLte?: string;
295
    to?: string;
296
    value?: string;
297
    nonce?: string;
298
    nonceGte?: number;
299
    limit?: number;
300
    offset?: number;
301
  }): CacheDir {
302
    return new CacheDir(
×
303
      CacheRouter.getMultisigTransactionsCacheKey(args),
304
      `${args.ordering}_${args.executed}_${args.trusted}_${args.executionDateGte}_${args.executionDateLte}_${args.to}_${args.value}_${args.nonce}_${args.nonceGte}_${args.limit}_${args.offset}`,
305
    );
306
  }
307

308
  static getMultisigTransactionsCacheKey(args: {
309
    chainId: string;
310
    safeAddress: string;
311
  }): string {
312
    return `${args.chainId}_${CacheRouter.MULTISIG_TRANSACTIONS_KEY}_${args.safeAddress}`;
52✔
313
  }
314

315
  static getMultisigTransactionCacheDir(args: {
316
    chainId: string;
317
    safeTransactionHash: string;
318
  }): CacheDir {
319
    return new CacheDir(CacheRouter.getMultisigTransactionCacheKey(args), '');
×
320
  }
321

322
  static getMultisigTransactionCacheKey(args: {
323
    chainId: string;
324
    safeTransactionHash: string;
325
  }): string {
326
    return `${args.chainId}_${CacheRouter.MULTISIG_TRANSACTION_KEY}_${args.safeTransactionHash}`;
24✔
327
  }
328

329
  static getCreationTransactionCacheDir(args: {
330
    chainId: string;
331
    safeAddress: `0x${string}`;
332
  }): CacheDir {
333
    return new CacheDir(
×
334
      `${args.chainId}_${CacheRouter.CREATION_TRANSACTION_KEY}_${args.safeAddress}`,
335
      '',
336
    );
337
  }
338

339
  static getAllTransactionsCacheDir(args: {
340
    chainId: string;
341
    safeAddress: `0x${string}`;
342
    ordering?: string;
343
    executed?: boolean;
344
    queued?: boolean;
345
    limit?: number;
346
    offset?: number;
347
  }): CacheDir {
348
    return new CacheDir(
×
349
      CacheRouter.getAllTransactionsKey(args),
350
      `${args.ordering}_${args.executed}_${args.queued}_${args.limit}_${args.offset}`,
351
    );
352
  }
353

354
  static getAllTransactionsKey(args: {
355
    chainId: string;
356
    safeAddress: `0x${string}`;
357
  }): string {
358
    return `${args.chainId}_${CacheRouter.ALL_TRANSACTIONS_KEY}_${args.safeAddress}`;
46✔
359
  }
360

361
  static getTokenCacheDir(args: {
362
    chainId: string;
363
    address: string;
364
  }): CacheDir {
365
    return new CacheDir(
×
366
      `${args.chainId}_${CacheRouter.TOKEN_KEY}_${args.address}`,
367
      '',
368
    );
369
  }
370

371
  static getTokensCacheKey(chainId: string): string {
372
    return `${chainId}_${CacheRouter.TOKENS_KEY}`;
×
373
  }
374

375
  static getTokensCacheDir(args: {
376
    chainId: string;
377
    limit?: number;
378
    offset?: number;
379
  }): CacheDir {
380
    return new CacheDir(
×
381
      CacheRouter.getTokensCacheKey(args.chainId),
382
      `${args.limit}_${args.offset}`,
383
    );
384
  }
385

386
  static getSafesByOwnerCacheDir(args: {
387
    chainId: string;
388
    ownerAddress: `0x${string}`;
389
  }): CacheDir {
390
    return new CacheDir(
2✔
391
      `${args.chainId}_${CacheRouter.OWNERS_SAFE_KEY}_${args.ownerAddress}`,
392
      '',
393
    );
394
  }
395

396
  static getMessageByHashCacheKey(args: {
397
    chainId: string;
398
    messageHash: string;
399
  }): string {
400
    return `${args.chainId}_${CacheRouter.MESSAGE_KEY}_${args.messageHash}`;
2✔
401
  }
402

403
  static getMessageByHashCacheDir(args: {
404
    chainId: string;
405
    messageHash: string;
406
  }): CacheDir {
407
    return new CacheDir(this.getMessageByHashCacheKey(args), '');
×
408
  }
409

410
  static getMessagesBySafeCacheKey(args: {
411
    chainId: string;
412
    safeAddress: `0x${string}`;
413
  }): string {
414
    return `${args.chainId}_${CacheRouter.MESSAGES_KEY}_${args.safeAddress}`;
4✔
415
  }
416

417
  static getMessagesBySafeCacheDir(args: {
418
    chainId: string;
419
    safeAddress: `0x${string}`;
420
    limit?: number;
421
    offset?: number;
422
  }): CacheDir {
423
    return new CacheDir(
×
424
      this.getMessagesBySafeCacheKey(args),
425
      `${args.limit}_${args.offset}`,
426
    );
427
  }
428

429
  static getChainsCacheKey(): string {
430
    return CacheRouter.CHAINS_KEY;
2✔
431
  }
432

433
  static getChainsCacheDir(args: {
434
    limit?: number;
435
    offset?: number;
436
  }): CacheDir {
437
    return new CacheDir(
×
438
      CacheRouter.getChainsCacheKey(),
439
      `${args.limit}_${args.offset}`,
440
    );
441
  }
442

443
  static getChainCacheKey(chainId: string): string {
444
    return `${chainId}_${CacheRouter.CHAIN_KEY}`;
22✔
445
  }
446

447
  static getChainCacheDir(chainId: string): CacheDir {
448
    return new CacheDir(CacheRouter.getChainCacheKey(chainId), '');
20✔
449
  }
450

451
  static getRelayKey(args: {
452
    chainId: string;
453
    address: `0x${string}`;
454
  }): string {
455
    return `${args.chainId}_${CacheRouter.RELAY_KEY}_${args.address}`;
×
456
  }
457

458
  static getRelayCacheDir(args: {
459
    chainId: string;
460
    address: `0x${string}`;
461
  }): CacheDir {
462
    return new CacheDir(CacheRouter.getRelayKey(args), '');
×
463
  }
464

465
  static getSafeAppsKey(chainId: string): string {
466
    return `${chainId}_${CacheRouter.SAFE_APPS_KEY}`;
2✔
467
  }
468

469
  static getSafeAppsCacheDir(args: {
470
    chainId?: string;
471
    clientUrl?: string;
472
    onlyListed?: boolean;
473
    url?: string;
474
  }): CacheDir {
475
    return new CacheDir(
4✔
476
      `${args.chainId}_${CacheRouter.SAFE_APPS_KEY}`,
477
      `${args.clientUrl}_${args.onlyListed}_${args.url}`,
478
    );
479
  }
480

481
  static getNativeCoinPriceCacheDir(args: {
482
    nativeCoinId: string;
483
    fiatCode: string;
484
  }): CacheDir {
485
    return new CacheDir(
×
486
      `${args.nativeCoinId}_${CacheRouter.NATIVE_COIN_PRICE_KEY}_${args.fiatCode}`,
487
      '',
488
    );
489
  }
490

491
  static getTokenPriceCacheDir(args: {
492
    chainName: string;
493
    fiatCode: string;
494
    tokenAddress: string;
495
  }): CacheDir {
496
    return new CacheDir(
×
497
      `${args.chainName}_${CacheRouter.TOKEN_PRICE_KEY}_${args.tokenAddress}_${args.fiatCode}`,
498
      '',
499
    );
500
  }
501

502
  static getPriceFiatCodesCacheDir(): CacheDir {
503
    return new CacheDir(CacheRouter.SAFE_FIAT_CODES_KEY, '');
×
504
  }
505

506
  static getAccountCacheDir(address: `0x${string}`): CacheDir {
507
    return new CacheDir(`${CacheRouter.ACCOUNT_KEY}_${address}`, '');
×
508
  }
509

510
  static getAccountDataTypesCacheDir(): CacheDir {
511
    return new CacheDir(CacheRouter.ACCOUNT_DATA_TYPES_KEY, '');
×
512
  }
513

514
  static getAccountDataSettingsCacheDir(address: `0x${string}`): CacheDir {
515
    return new CacheDir(
×
516
      `${CacheRouter.ACCOUNT_DATA_SETTINGS_KEY}_${address}`,
517
      '',
518
    );
519
  }
520

521
  static getCounterfactualSafeCacheDir(
522
    chainId: string,
523
    predictedAddress: `0x${string}`,
524
  ): CacheDir {
525
    return new CacheDir(
×
526
      `${chainId}_${CacheRouter.COUNTERFACTUAL_SAFE_KEY}_${predictedAddress}`,
527
      '',
528
    );
529
  }
530

531
  static getCounterfactualSafesCacheDir(address: `0x${string}`): CacheDir {
532
    return new CacheDir(
×
533
      `${CacheRouter.COUNTERFACTUAL_SAFES_KEY}_${address}`,
534
      '',
535
    );
536
  }
537

538
  static getRpcRequestsKey(chainId: string): string {
NEW
539
    return `${chainId}_${CacheRouter.RPC_REQUESTS_KEY}`;
×
540
  }
541

542
  static getRpcRequestsCacheDir(args: {
543
    chainId: string;
544
    method: string;
545
    params: string;
546
  }): CacheDir {
NEW
547
    return new CacheDir(
×
548
      CacheRouter.getRpcRequestsKey(args.chainId),
549
      `${args.method}_${args.params}`,
550
    );
551
  }
552
}
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