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

hicommonwealth / commonwealth / 14138176371

28 Mar 2025 09:27PM UTC coverage: 45.276% (-0.3%) from 45.546%
14138176371

push

github

web-flow
Merge pull request #11608 from hicommonwealth/11469-spike-ensure-that-token-balance-cache-is-working-against-the-various-svm-rpc-nodes

Refactor Sol TBC/Groups for multiple svms(Eclipse)

1487 of 3677 branches covered (40.44%)

Branch coverage included in aggregate %.

3 of 51 new or added lines in 5 files covered. (5.88%)

3 existing lines in 3 files now uncovered.

2831 of 5860 relevant lines covered (48.31%)

39.09 hits per line

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

44.74
/libs/model/src/services/tokenBalanceCache/tokenBalanceCache.ts
1
import { logger, stats } from '@hicommonwealth/core';
2
import { BalanceSourceType } from '@hicommonwealth/shared';
3
import { getCosmosBalances, getEvmBalances } from './providers';
4
import { getSolanaBalances } from './providers/getSolanaBalances';
5
import {
6
  Balances,
7
  GetBalancesOptions,
8
  GetCosmosBalancesOptions,
9
  GetErcBalanceOptions,
10
  GetEvmBalancesOptions,
11
  GetSPLBalancesOptions,
12
} from './types';
13

14
const log = logger(import.meta);
32✔
15

16
/**
17
 * This is the main function through which all balances should be fetched.
18
 * This function supports all balance sources and is fully compatible with Redis caching.
19
 */
20
export async function getBalances(
21
  options: GetBalancesOptions,
22
  ttl?: number,
23
): Promise<Balances> {
24
  if (options.addresses.length === 0) return {};
3!
25

26
  let balances: Balances = {};
3✔
27

28
  try {
3✔
29
    if (
3!
30
      options.balanceSourceType === BalanceSourceType.CosmosNative ||
9✔
31
      options.balanceSourceType === BalanceSourceType.CW20 ||
32
      options.balanceSourceType === BalanceSourceType.CW721
33
    ) {
34
      balances = await getCosmosBalances(options, ttl);
×
35
    } else if (
3!
36
      options.balanceSourceType == BalanceSourceType.SPL ||
6✔
37
      options.balanceSourceType == BalanceSourceType.SOLNFT
38
    ) {
UNCOV
39
      balances = await getSolanaBalances(options, ttl);
×
40
    } else {
41
      balances = await getEvmBalances(options as GetEvmBalancesOptions, ttl);
3✔
42
    }
43
  } catch (e) {
44
    const chainId =
45
      options.balanceSourceType == BalanceSourceType.SPL
×
46
        ? 'solana'
47
        : (options as GetEvmBalancesOptions).sourceOptions.evmChainId ||
×
48
          (options as GetCosmosBalancesOptions).sourceOptions.cosmosChainId;
49
    const contractAddress =
50
      (options as GetSPLBalancesOptions).mintAddress ||
×
51
      (options as GetErcBalanceOptions).sourceOptions.contractAddress;
52
    const msg =
53
      `Failed to fetch balance(s) for ${options.addresses.length} address(es)` +
×
54
      `on chain ${chainId}${contractAddress && ' for contract '}${
×
55
        contractAddress || ''
×
56
      }`;
57

58
    log.error(msg, e instanceof Error ? e : undefined, {
×
59
      fingerprint: `TBC: ${chainId} - ${contractAddress}`,
60
      addresses: options.addresses.slice(0, 5),
61
      contractAddress: (options as GetErcBalanceOptions).sourceOptions
62
        .contractAddress,
63
      evmChainId: (options as GetEvmBalancesOptions).sourceOptions.evmChainId,
64
      cosmosChainId: (options as GetCosmosBalancesOptions).sourceOptions
65
        .cosmosChainId,
66
    });
67
  }
68

69
  stats().incrementBy(
3✔
70
    'tbc.successful.balance.fetch',
71
    Object.keys(balances).length,
72
    {
73
      balance_source_type: options.balanceSourceType,
74
    },
75
  );
76
  return balances;
3✔
77
}
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