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

safe-global / safe-client-gateway / 9936800916

15 Jul 2024 09:15AM UTC coverage: 48.164% (-0.02%) from 48.183%
9936800916

push

github

hectorgomezv
Add cache management for AccountDataSettings

415 of 2593 branches covered (16.0%)

Branch coverage included in aggregate %.

1 of 8 new or added lines in 2 files covered. (12.5%)

1 existing line in 1 file now uncovered.

4267 of 7128 relevant lines covered (59.86%)

13.01 hits per line

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

59.38
/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 ACTIVE_ACCOUNT_DATA_TYPES_KEY =
16✔
6
    'active_account_data_types';
7
  private static readonly ACCOUNT_DATA_SETTINGS_KEY = 'account_data_settings';
16✔
8
  private static readonly ACCOUNT_DATA_TYPES_KEY = 'account_data_types';
16✔
9
  private static readonly ALL_TRANSACTIONS_KEY = 'all_transactions';
16✔
10
  private static readonly AUTH_NONCE_KEY = 'auth_nonce';
16✔
11
  private static readonly BACKBONE_KEY = 'backbone';
16✔
12
  private static readonly CHAIN_KEY = 'chain';
16✔
13
  private static readonly CHAINS_KEY = 'chains';
16✔
14
  private static readonly CONTRACT_KEY = 'contract';
16✔
15
  private static readonly CREATION_TRANSACTION_KEY = 'creation_transaction';
16✔
16
  private static readonly DELEGATES_KEY = 'delegates';
16✔
17
  private static readonly INCOMING_TRANSFERS_KEY = 'incoming_transfers';
16✔
18
  private static readonly MESSAGE_KEY = 'message';
16✔
19
  private static readonly MESSAGES_KEY = 'messages';
16✔
20
  private static readonly MODULE_TRANSACTION_KEY = 'module_transaction';
16✔
21
  private static readonly MODULE_TRANSACTIONS_KEY = 'module_transactions';
16✔
22
  private static readonly MULTISIG_TRANSACTION_KEY = 'multisig_transaction';
16✔
23
  private static readonly MULTISIG_TRANSACTIONS_KEY = 'multisig_transactions';
16✔
24
  private static readonly NATIVE_COIN_PRICE_KEY = 'native_coin_price';
16✔
25
  private static readonly OWNERS_SAFE_KEY = 'owner_safes';
16✔
26
  private static readonly RELAY_KEY = 'relay';
16✔
27
  private static readonly SAFE_APPS_KEY = 'safe_apps';
16✔
28
  private static readonly SAFE_BALANCES_KEY = 'safe_balances';
16✔
29
  private static readonly SAFE_COLLECTIBLES_KEY = 'safe_collectibles';
16✔
30
  private static readonly SAFE_EXISTS_KEY = 'safe_exists';
16✔
31
  private static readonly SAFE_FIAT_CODES_KEY = 'safe_fiat_codes';
16✔
32
  private static readonly SAFE_KEY = 'safe';
16✔
33
  private static readonly SINGLETONS_KEY = 'singletons';
16✔
34
  private static readonly TOKEN_KEY = 'token';
16✔
35
  private static readonly TOKEN_PRICE_KEY = 'token_price';
16✔
36
  private static readonly TOKENS_KEY = 'tokens';
16✔
37
  private static readonly TRANSFER_KEY = 'transfer';
16✔
38
  private static readonly TRANSFERS_KEY = 'transfers';
16✔
39
  private static readonly ZERION_BALANCES_KEY = 'zerion_balances';
16✔
40
  private static readonly ZERION_COLLECTIBLES_KEY = 'zerion_collectibles';
16✔
41
  private static readonly RATE_LIMIT_KEY = 'rate_limit';
16✔
42

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

193
  static getTransferCacheDir(args: {
194
    chainId: string;
195
    transferId: string;
196
  }): CacheDir {
197
    return new CacheDir(
×
198
      `${args.chainId}_${CacheRouter.TRANSFER_KEY}_${args.transferId}`,
199
      '',
200
    );
201
  }
202

203
  static getTransfersCacheDir(args: {
204
    chainId: string;
205
    safeAddress: string;
206
    onlyErc20: boolean;
207
    onlyErc721: boolean;
208
    limit?: number;
209
    offset?: number;
210
  }): CacheDir {
211
    return new CacheDir(
×
212
      CacheRouter.getTransfersCacheKey(args),
213
      `${args.onlyErc20}_${args.onlyErc721}_${args.limit}_${args.offset}`,
214
    );
215
  }
216

217
  static getTransfersCacheKey(args: {
218
    chainId: string;
219
    safeAddress: string;
220
  }): string {
221
    return `${args.chainId}_${CacheRouter.TRANSFERS_KEY}_${args.safeAddress}`;
40✔
222
  }
223

224
  static getModuleTransactionCacheDir(args: {
225
    chainId: string;
226
    moduleTransactionId: string;
227
  }): CacheDir {
228
    return new CacheDir(
×
229
      `${args.chainId}_${CacheRouter.MODULE_TRANSACTION_KEY}_${args.moduleTransactionId}`,
230
      '',
231
    );
232
  }
233

234
  static getModuleTransactionsCacheDir(args: {
235
    chainId: string;
236
    safeAddress: `0x${string}`;
237
    to?: string;
238
    txHash?: string;
239
    module?: string;
240
    limit?: number;
241
    offset?: number;
242
  }): CacheDir {
243
    return new CacheDir(
×
244
      CacheRouter.getModuleTransactionsCacheKey(args),
245
      `${args.to}_${args.module}_${args.txHash}_${args.limit}_${args.offset}`,
246
    );
247
  }
248

249
  static getModuleTransactionsCacheKey(args: {
250
    chainId: string;
251
    safeAddress: `0x${string}`;
252
  }): string {
253
    return `${args.chainId}_${CacheRouter.MODULE_TRANSACTIONS_KEY}_${args.safeAddress}`;
6✔
254
  }
255

256
  static getIncomingTransfersCacheDir(args: {
257
    chainId: string;
258
    safeAddress: string;
259
    executionDateGte?: string;
260
    executionDateLte?: string;
261
    to?: string;
262
    value?: string;
263
    tokenAddress?: string;
264
    limit?: number;
265
    offset?: number;
266
  }): CacheDir {
267
    return new CacheDir(
×
268
      CacheRouter.getIncomingTransfersCacheKey(args),
269
      `${args.executionDateGte}_${args.executionDateLte}_${args.to}_${args.value}_${args.tokenAddress}_${args.limit}_${args.offset}`,
270
    );
271
  }
272

273
  static getIncomingTransfersCacheKey(args: {
274
    chainId: string;
275
    safeAddress: string;
276
  }): string {
277
    return `${args.chainId}_${CacheRouter.INCOMING_TRANSFERS_KEY}_${args.safeAddress}`;
16✔
278
  }
279

280
  static getMultisigTransactionsCacheDir(args: {
281
    chainId: string;
282
    safeAddress: string;
283
    ordering?: string;
284
    executed?: boolean;
285
    trusted?: boolean;
286
    executionDateGte?: string;
287
    executionDateLte?: string;
288
    to?: string;
289
    value?: string;
290
    nonce?: string;
291
    nonceGte?: number;
292
    limit?: number;
293
    offset?: number;
294
  }): CacheDir {
295
    return new CacheDir(
×
296
      CacheRouter.getMultisigTransactionsCacheKey(args),
297
      `${args.ordering}_${args.executed}_${args.trusted}_${args.executionDateGte}_${args.executionDateLte}_${args.to}_${args.value}_${args.nonce}_${args.nonceGte}_${args.limit}_${args.offset}`,
298
    );
299
  }
300

301
  static getMultisigTransactionsCacheKey(args: {
302
    chainId: string;
303
    safeAddress: string;
304
  }): string {
305
    return `${args.chainId}_${CacheRouter.MULTISIG_TRANSACTIONS_KEY}_${args.safeAddress}`;
52✔
306
  }
307

308
  static getMultisigTransactionCacheDir(args: {
309
    chainId: string;
310
    safeTransactionHash: string;
311
  }): CacheDir {
312
    return new CacheDir(CacheRouter.getMultisigTransactionCacheKey(args), '');
×
313
  }
314

315
  static getMultisigTransactionCacheKey(args: {
316
    chainId: string;
317
    safeTransactionHash: string;
318
  }): string {
319
    return `${args.chainId}_${CacheRouter.MULTISIG_TRANSACTION_KEY}_${args.safeTransactionHash}`;
24✔
320
  }
321

322
  static getCreationTransactionCacheDir(args: {
323
    chainId: string;
324
    safeAddress: `0x${string}`;
325
  }): CacheDir {
326
    return new CacheDir(
×
327
      `${args.chainId}_${CacheRouter.CREATION_TRANSACTION_KEY}_${args.safeAddress}`,
328
      '',
329
    );
330
  }
331

332
  static getAllTransactionsCacheDir(args: {
333
    chainId: string;
334
    safeAddress: `0x${string}`;
335
    ordering?: string;
336
    executed?: boolean;
337
    queued?: boolean;
338
    limit?: number;
339
    offset?: number;
340
  }): CacheDir {
341
    return new CacheDir(
×
342
      CacheRouter.getAllTransactionsKey(args),
343
      `${args.ordering}_${args.executed}_${args.queued}_${args.limit}_${args.offset}`,
344
    );
345
  }
346

347
  static getAllTransactionsKey(args: {
348
    chainId: string;
349
    safeAddress: `0x${string}`;
350
  }): string {
351
    return `${args.chainId}_${CacheRouter.ALL_TRANSACTIONS_KEY}_${args.safeAddress}`;
46✔
352
  }
353

354
  static getTokenCacheDir(args: {
355
    chainId: string;
356
    address: string;
357
  }): CacheDir {
358
    return new CacheDir(
×
359
      `${args.chainId}_${CacheRouter.TOKEN_KEY}_${args.address}`,
360
      '',
361
    );
362
  }
363

364
  static getTokensCacheKey(chainId: string): string {
365
    return `${chainId}_${CacheRouter.TOKENS_KEY}`;
×
366
  }
367

368
  static getTokensCacheDir(args: {
369
    chainId: string;
370
    limit?: number;
371
    offset?: number;
372
  }): CacheDir {
373
    return new CacheDir(
×
374
      CacheRouter.getTokensCacheKey(args.chainId),
375
      `${args.limit}_${args.offset}`,
376
    );
377
  }
378

379
  static getSafesByOwnerCacheDir(args: {
380
    chainId: string;
381
    ownerAddress: `0x${string}`;
382
  }): CacheDir {
383
    return new CacheDir(
2✔
384
      `${args.chainId}_${CacheRouter.OWNERS_SAFE_KEY}_${args.ownerAddress}`,
385
      '',
386
    );
387
  }
388

389
  static getMessageByHashCacheKey(args: {
390
    chainId: string;
391
    messageHash: string;
392
  }): string {
393
    return `${args.chainId}_${CacheRouter.MESSAGE_KEY}_${args.messageHash}`;
2✔
394
  }
395

396
  static getMessageByHashCacheDir(args: {
397
    chainId: string;
398
    messageHash: string;
399
  }): CacheDir {
400
    return new CacheDir(this.getMessageByHashCacheKey(args), '');
×
401
  }
402

403
  static getMessagesBySafeCacheKey(args: {
404
    chainId: string;
405
    safeAddress: `0x${string}`;
406
  }): string {
407
    return `${args.chainId}_${CacheRouter.MESSAGES_KEY}_${args.safeAddress}`;
4✔
408
  }
409

410
  static getMessagesBySafeCacheDir(args: {
411
    chainId: string;
412
    safeAddress: `0x${string}`;
413
    limit?: number;
414
    offset?: number;
415
  }): CacheDir {
416
    return new CacheDir(
×
417
      this.getMessagesBySafeCacheKey(args),
418
      `${args.limit}_${args.offset}`,
419
    );
420
  }
421

422
  static getChainsCacheKey(): string {
423
    return CacheRouter.CHAINS_KEY;
2✔
424
  }
425

426
  static getChainsCacheDir(args: {
427
    limit?: number;
428
    offset?: number;
429
  }): CacheDir {
430
    return new CacheDir(
×
431
      CacheRouter.getChainsCacheKey(),
432
      `${args.limit}_${args.offset}`,
433
    );
434
  }
435

436
  static getChainCacheKey(chainId: string): string {
437
    return `${chainId}_${CacheRouter.CHAIN_KEY}`;
22✔
438
  }
439

440
  static getChainCacheDir(chainId: string): CacheDir {
441
    return new CacheDir(CacheRouter.getChainCacheKey(chainId), '');
20✔
442
  }
443

444
  static getRelayKey(args: {
445
    chainId: string;
446
    address: `0x${string}`;
447
  }): string {
448
    return `${args.chainId}_${CacheRouter.RELAY_KEY}_${args.address}`;
×
449
  }
450

451
  static getRelayCacheDir(args: {
452
    chainId: string;
453
    address: `0x${string}`;
454
  }): CacheDir {
455
    return new CacheDir(CacheRouter.getRelayKey(args), '');
×
456
  }
457

458
  static getSafeAppsKey(chainId: string): string {
459
    return `${chainId}_${CacheRouter.SAFE_APPS_KEY}`;
2✔
460
  }
461

462
  static getSafeAppsCacheDir(args: {
463
    chainId?: string;
464
    clientUrl?: string;
465
    onlyListed?: boolean;
466
    url?: string;
467
  }): CacheDir {
468
    return new CacheDir(
4✔
469
      `${args.chainId}_${CacheRouter.SAFE_APPS_KEY}`,
470
      `${args.clientUrl}_${args.onlyListed}_${args.url}`,
471
    );
472
  }
473

474
  static getNativeCoinPriceCacheDir(args: {
475
    nativeCoinId: string;
476
    fiatCode: string;
477
  }): CacheDir {
478
    return new CacheDir(
×
479
      `${args.nativeCoinId}_${CacheRouter.NATIVE_COIN_PRICE_KEY}_${args.fiatCode}`,
480
      '',
481
    );
482
  }
483

484
  static getTokenPriceCacheDir(args: {
485
    chainName: string;
486
    fiatCode: string;
487
    tokenAddress: string;
488
  }): CacheDir {
489
    return new CacheDir(
×
490
      `${args.chainName}_${CacheRouter.TOKEN_PRICE_KEY}_${args.tokenAddress}_${args.fiatCode}`,
491
      '',
492
    );
493
  }
494

495
  static getPriceFiatCodesCacheDir(): CacheDir {
496
    return new CacheDir(CacheRouter.SAFE_FIAT_CODES_KEY, '');
×
497
  }
498

499
  static getAccountCacheDir(address: `0x${string}`): CacheDir {
500
    return new CacheDir(`${CacheRouter.ACCOUNT_KEY}_${address}`, '');
×
501
  }
502

503
  static getActiveAccountDataTypesCacheDir(): CacheDir {
504
    return new CacheDir(CacheRouter.ACTIVE_ACCOUNT_DATA_TYPES_KEY, '');
×
505
  }
506

507
  static getAccountDataTypesCacheDir(): CacheDir {
508
    return new CacheDir(CacheRouter.ACCOUNT_DATA_TYPES_KEY, '');
×
509
  }
510

511
  static getAccountDataSettingsCacheDir(address: `0x${string}`): CacheDir {
NEW
512
    return new CacheDir(
×
513
      `${CacheRouter.ACCOUNT_DATA_SETTINGS_KEY}_${address}`,
514
      '',
515
    );
516
  }
517
}
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