Skip to content

Commit f6bc337

Browse files
linuxninja39claude
andcommitted
feat: add ChainFamily types and extend wallet identity model per en-o8w
New types: - ChainFamily enum (evm, solana, sui, bitcoin, cosmos, aptos) - Caip2ChainId string type for WalletConnect v2 interop Extended types: - WalletConnection: supportedChainFamilies field - ConnectedAccount: chainFamily field - WatchAddress: chainFamily field - TrackedAddress: chainFamily field for integration routing - AddressRequest: chainFamily field for routing - AccountId: format extended to {connectionId}:{chainFamily}:{address} - IntegrationSource: added SUI, BITCOIN, COSMOS, APTOS members Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3855cc6 commit f6bc337

11 files changed

Lines changed: 128 additions & 3 deletions

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
"import": "./dist/enums/Chain.js",
2222
"require": "./dist/cjs/enums/Chain.js"
2323
},
24+
"./enums/ChainFamily": {
25+
"types": "./dist/enums/ChainFamily.d.ts",
26+
"import": "./dist/enums/ChainFamily.js",
27+
"require": "./dist/cjs/enums/ChainFamily.js"
28+
},
2429
"./enums/IntegrationSource": {
2530
"types": "./dist/enums/IntegrationSource.d.ts",
2631
"import": "./dist/enums/IntegrationSource.js",

src/enums/ChainFamily.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Classification of blockchain protocol families.
3+
*
4+
* Groups blockchain networks by their underlying protocol family rather than
5+
* individual chain identity. Used for routing (which integration handles which
6+
* addresses), discovery (which standard detects which providers), and display
7+
* (chain family badges in UI).
8+
*
9+
* `ChainFamily` is distinct from `Chain` — a chain family contains multiple
10+
* chains (e.g., EVM family includes Ethereum, Polygon, Arbitrum, etc.).
11+
*
12+
* This is a closed enum. Adding new families requires Enterprise Architecture
13+
* approval, a new integration bounded context, and correlation registry entries.
14+
*
15+
* @example
16+
* ```typescript
17+
* import { ChainFamily } from '@cygnus-wealth/data-models';
18+
*
19+
* // Route address to correct integration
20+
* function getIntegration(family: ChainFamily) {
21+
* switch (family) {
22+
* case ChainFamily.EVM:
23+
* return evmIntegration;
24+
* case ChainFamily.SOLANA:
25+
* return solIntegration;
26+
* default:
27+
* throw new Error(`No integration for ${family}`);
28+
* }
29+
* }
30+
* ```
31+
*
32+
* @since 1.5.0
33+
* @stability extended
34+
*
35+
* @see {@link Chain} for specific chain identification within a family
36+
*/
37+
export enum ChainFamily {
38+
/** EVM-compatible chains (Ethereum, Polygon, Arbitrum, Optimism, Avalanche, BSC, Base) */
39+
EVM = 'evm',
40+
41+
/** Solana mainnet */
42+
SOLANA = 'solana',
43+
44+
/** SUI mainnet (Move-based L1) */
45+
SUI = 'sui',
46+
47+
/** Bitcoin mainnet (UTXO model) */
48+
BITCOIN = 'bitcoin',
49+
50+
/** Cosmos ecosystem chains (Cosmos Hub, Osmosis, etc.) */
51+
COSMOS = 'cosmos',
52+
53+
/** Aptos mainnet (Move-based L1) */
54+
APTOS = 'aptos',
55+
}

src/enums/IntegrationSource.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ export enum IntegrationSource {
7676
/** Data fetched directly from blockchain via RPC */
7777
BLOCKCHAIN_DIRECT = 'BLOCKCHAIN_DIRECT',
7878

79+
/** SUI blockchain integration */
80+
SUI = 'SUI',
81+
82+
/** Bitcoin blockchain integration */
83+
BITCOIN = 'BITCOIN',
84+
85+
/** Cosmos ecosystem integration */
86+
COSMOS = 'COSMOS',
87+
88+
/** Aptos blockchain integration */
89+
APTOS = 'APTOS',
90+
7991
/** Other or unclassified data source */
8092
OTHER = 'OTHER'
8193
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Enums
22
export { AssetType } from './enums/AssetType';
33
export { Chain } from './enums/Chain';
4+
export { ChainFamily } from './enums/ChainFamily';
45
export { IntegrationSource } from './enums/IntegrationSource';
56
export { TransactionType } from './enums/TransactionType';
67
export { AccountType } from './enums/AccountType';
@@ -38,6 +39,7 @@ export { PortfolioAsset } from './interfaces/PortfolioAsset';
3839
export type { WalletProviderId } from './types/WalletProviderId';
3940
export type { WalletConnectionId } from './types/WalletConnectionId';
4041
export type { AccountId } from './types/AccountId';
42+
export type { Caip2ChainId } from './types/Caip2ChainId';
4143

4244
// Multi-Wallet Connection Models
4345
export type { WalletConnection } from './interfaces/WalletConnection';

src/interfaces/AddressRequest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AccountId } from '../types/AccountId';
22
import { Chain } from '../enums/Chain';
3+
import { ChainFamily } from '../enums/ChainFamily';
34

45
/**
56
* Request to query data for a specific account address.
@@ -31,6 +32,9 @@ export interface AddressRequest {
3132
/** Checksummed address to query */
3233
address: string;
3334

35+
/** Chain family for routing to the correct integration */
36+
chainFamily: ChainFamily;
37+
3438
/** Chains to query for this address */
3539
chainScope: Chain[];
3640
}

src/interfaces/ConnectedAccount.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AccountId } from '../types/AccountId';
22
import { Chain } from '../enums/Chain';
3+
import { ChainFamily } from '../enums/ChainFamily';
34

45
/**
56
* A single account within a wallet connection.
@@ -40,6 +41,9 @@ export interface ConnectedAccount {
4041
/** User-assigned label (default: truncated address) */
4142
accountLabel: string;
4243

44+
/** Chain family this account belongs to */
45+
chainFamily: ChainFamily;
46+
4347
/** Chains to track this account on (default: all supported by the connection) */
4448
chainScope: Chain[];
4549

src/interfaces/TrackedAddress.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AccountId } from '../types/AccountId';
22
import { WalletConnectionId } from '../types/WalletConnectionId';
33
import { WalletProviderId } from '../types/WalletProviderId';
44
import { Chain } from '../enums/Chain';
5+
import { ChainFamily } from '../enums/ChainFamily';
56

67
/**
78
* An address being tracked for portfolio purposes with full account context.
@@ -49,6 +50,9 @@ export interface TrackedAddress {
4950
/** Label of the parent wallet connection */
5051
connectionLabel: string;
5152

53+
/** Chain family of this tracked address, used for integration routing */
54+
chainFamily: ChainFamily;
55+
5256
/** Chains to query for this address */
5357
chainScope: Chain[];
5458
}

src/interfaces/WalletConnection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { WalletConnectionId } from '../types/WalletConnectionId';
22
import { WalletProviderId } from '../types/WalletProviderId';
33
import { Chain } from '../enums/Chain';
4+
import { ChainFamily } from '../enums/ChainFamily';
45
import { ConnectedAccount } from './ConnectedAccount';
56

67
/**
@@ -64,6 +65,9 @@ export interface WalletConnection {
6465
/** Chains this wallet connection supports */
6566
supportedChains: Chain[];
6667

68+
/** Chain families this wallet connection supports (e.g., EVM, Solana, SUI) */
69+
supportedChainFamilies: ChainFamily[];
70+
6771
/** ISO 8601 timestamp of initial connection */
6872
connectedAt: string;
6973

src/interfaces/WatchAddress.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AccountId } from '../types/AccountId';
22
import { Chain } from '../enums/Chain';
3+
import { ChainFamily } from '../enums/ChainFamily';
34

45
/**
56
* An address tracked independently of any wallet connection.
@@ -36,6 +37,9 @@ export interface WatchAddress {
3637
/** User-assigned label */
3738
addressLabel: string;
3839

40+
/** Chain family of this watched address */
41+
chainFamily: ChainFamily;
42+
3943
/** Chains to track this address on */
4044
chainScope: Chain[];
4145

src/types/AccountId.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/**
22
* Unique identifier for a specific account across the system.
33
*
4-
* Format: `{walletConnectionId}:{checksummedAddress}` for connected accounts
5-
* (e.g., `metamask:a1b2c3d4:0xAbC...123`), or `watch:{checksummedAddress}`
4+
* Format: `{walletConnectionId}:{chainFamily}:{address}` for connected accounts
5+
* (e.g., `metamask:a1b2c3d4:evm:0xAbC...123`), or `watch:{address}`
66
* for watch addresses.
77
*
8+
* The `chainFamily` segment (introduced in en-o8w) disambiguates addresses
9+
* from the same wallet connection that span different chain families.
10+
*
811
* This is the primary key used throughout the system to reference a specific
912
* account. It disambiguates the same address appearing in different wallet
1013
* connections (e.g., imported into both MetaMask and Rabby).
@@ -13,7 +16,8 @@
1316
* ```typescript
1417
* import { AccountId } from '@cygnus-wealth/data-models';
1518
*
16-
* const connectedAccountId: AccountId = 'metamask:a1b2c3d4:0xAbCdEf1234567890';
19+
* const evmAccountId: AccountId = 'metamask:a1b2c3d4:evm:0xAbCdEf1234567890';
20+
* const solanaAccountId: AccountId = 'phantom:abc123:solana:7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU';
1721
* const watchAccountId: AccountId = 'watch:0xAbCdEf1234567890';
1822
* ```
1923
*

0 commit comments

Comments
 (0)