@cygnus-wealth/data-models 0.0.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +366 -63
  2. package/dist/enums/AccountType.d.ts +41 -0
  3. package/dist/enums/AccountType.js +41 -0
  4. package/dist/enums/AssetType.d.ts +114 -0
  5. package/dist/enums/AssetType.js +114 -0
  6. package/dist/enums/Chain.d.ts +57 -0
  7. package/dist/enums/Chain.js +57 -0
  8. package/dist/enums/IntegrationSource.d.ts +47 -0
  9. package/dist/enums/IntegrationSource.js +47 -4
  10. package/dist/enums/LendingPositionType.d.ts +25 -0
  11. package/dist/enums/LendingPositionType.js +26 -0
  12. package/dist/enums/TransactionType.d.ts +50 -0
  13. package/dist/enums/TransactionType.js +50 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +1 -0
  16. package/dist/interfaces/Account.d.ts +92 -0
  17. package/dist/interfaces/ApiError.d.ts +61 -0
  18. package/dist/interfaces/ApiResponse.d.ts +60 -1
  19. package/dist/interfaces/Asset.d.ts +59 -0
  20. package/dist/interfaces/Balance.d.ts +52 -0
  21. package/dist/interfaces/BaseEntity.d.ts +61 -0
  22. package/dist/interfaces/FilterOptions.d.ts +68 -0
  23. package/dist/interfaces/IntegrationCredentials.d.ts +54 -0
  24. package/dist/interfaces/LendingPosition.d.ts +89 -4
  25. package/dist/interfaces/LiquidityPosition.d.ts +66 -2
  26. package/dist/interfaces/MarketData.d.ts +53 -0
  27. package/dist/interfaces/Metadata.d.ts +86 -0
  28. package/dist/interfaces/NFT.d.ts +55 -0
  29. package/dist/interfaces/PaginatedResponse.d.ts +59 -0
  30. package/dist/interfaces/Portfolio.d.ts +104 -2
  31. package/dist/interfaces/PortfolioAsset.d.ts +76 -0
  32. package/dist/interfaces/PortfolioAsset.js +1 -0
  33. package/dist/interfaces/PortfolioItem.d.ts +13 -0
  34. package/dist/interfaces/Price.d.ts +45 -2
  35. package/dist/interfaces/StakedPosition.d.ts +77 -0
  36. package/dist/interfaces/SyncStatus.d.ts +55 -0
  37. package/dist/interfaces/Transaction.d.ts +114 -2
  38. package/dist/types/AssetIdentifier.d.ts +61 -0
  39. package/dist/types/SortOrder.d.ts +50 -0
  40. package/dist/types/TimeRange.d.ts +51 -0
  41. package/package.json +29 -3
@@ -1,22 +1,72 @@
1
+ /**
2
+ * Standardized transaction type classification.
3
+ *
4
+ * Unified categorization for all financial operations across CEX, DEX,
5
+ * blockchain transfers, and DeFi protocols. Enables consistent transaction
6
+ * history and analytics across all integration sources.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { TransactionType } from '@cygnus-wealth/data-models';
11
+ *
12
+ * // Classify transaction based on operation
13
+ * function getTransactionIcon(type: TransactionType): string {
14
+ * switch(type) {
15
+ * case TransactionType.BUY:
16
+ * return '📈';
17
+ * case TransactionType.SELL:
18
+ * return '📉';
19
+ * case TransactionType.STAKE:
20
+ * return '🔒';
21
+ * case TransactionType.SWAP:
22
+ * return '🔄';
23
+ * default:
24
+ * return '📄';
25
+ * }
26
+ * }
27
+ * ```
28
+ *
29
+ * @since 0.0.1
30
+ * @stability standard
31
+ */
1
32
  export var TransactionType;
2
33
  (function (TransactionType) {
34
+ /** Purchase of an asset with fiat or another asset */
3
35
  TransactionType["BUY"] = "BUY";
36
+ /** Sale of an asset for fiat or another asset */
4
37
  TransactionType["SELL"] = "SELL";
38
+ /** Incoming transfer of assets to account */
5
39
  TransactionType["TRANSFER_IN"] = "TRANSFER_IN";
40
+ /** Outgoing transfer of assets from account */
6
41
  TransactionType["TRANSFER_OUT"] = "TRANSFER_OUT";
42
+ /** Exchange of one asset for another via DEX or CEX */
7
43
  TransactionType["SWAP"] = "SWAP";
44
+ /** Locking assets for staking rewards */
8
45
  TransactionType["STAKE"] = "STAKE";
46
+ /** Unlocking previously staked assets */
9
47
  TransactionType["UNSTAKE"] = "UNSTAKE";
48
+ /** Claiming earned staking or liquidity rewards */
10
49
  TransactionType["CLAIM_REWARD"] = "CLAIM_REWARD";
50
+ /** Adding assets to a liquidity pool */
11
51
  TransactionType["PROVIDE_LIQUIDITY"] = "PROVIDE_LIQUIDITY";
52
+ /** Removing assets from a liquidity pool */
12
53
  TransactionType["REMOVE_LIQUIDITY"] = "REMOVE_LIQUIDITY";
54
+ /** Borrowing assets from a lending protocol */
13
55
  TransactionType["BORROW"] = "BORROW";
56
+ /** Repaying borrowed assets to a lending protocol */
14
57
  TransactionType["REPAY"] = "REPAY";
58
+ /** Forced liquidation of collateralized position */
15
59
  TransactionType["LIQUIDATION"] = "LIQUIDATION";
60
+ /** Creation of new tokens (NFT minting, token minting) */
16
61
  TransactionType["MINT"] = "MINT";
62
+ /** Destruction of tokens */
17
63
  TransactionType["BURN"] = "BURN";
64
+ /** Transaction fee payment */
18
65
  TransactionType["FEE"] = "FEE";
66
+ /** Dividend payment received */
19
67
  TransactionType["DIVIDEND"] = "DIVIDEND";
68
+ /** Interest payment received or paid */
20
69
  TransactionType["INTEREST"] = "INTEREST";
70
+ /** Other or unclassified transaction type */
21
71
  TransactionType["OTHER"] = "OTHER";
22
72
  })(TransactionType || (TransactionType = {}));
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { Chain } from './enums/Chain';
3
3
  export { IntegrationSource } from './enums/IntegrationSource';
4
4
  export { TransactionType } from './enums/TransactionType';
5
5
  export { AccountType } from './enums/AccountType';
6
+ export { LendingPositionType } from './enums/LendingPositionType';
6
7
  export { BaseEntity } from './interfaces/BaseEntity';
7
8
  export { Metadata } from './interfaces/Metadata';
8
9
  export { Asset } from './interfaces/Asset';
@@ -15,6 +16,7 @@ export { StakedPosition } from './interfaces/StakedPosition';
15
16
  export { LendingPosition } from './interfaces/LendingPosition';
16
17
  export { Account } from './interfaces/Account';
17
18
  export { Portfolio } from './interfaces/Portfolio';
19
+ export { PortfolioAsset } from './interfaces/PortfolioAsset';
18
20
  export { Transaction } from './interfaces/Transaction';
19
21
  export { IntegrationCredentials } from './interfaces/IntegrationCredentials';
20
22
  export { SyncStatus } from './interfaces/SyncStatus';
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@ export { Chain } from './enums/Chain';
4
4
  export { IntegrationSource } from './enums/IntegrationSource';
5
5
  export { TransactionType } from './enums/TransactionType';
6
6
  export { AccountType } from './enums/AccountType';
7
+ export { LendingPositionType } from './enums/LendingPositionType';
@@ -7,18 +7,110 @@ import { LendingPosition } from './LendingPosition';
7
7
  import { NFT } from './NFT';
8
8
  import { Price } from './Price';
9
9
  import { Metadata } from './Metadata';
10
+ /**
11
+ * Aggregate container for all holdings from a single source.
12
+ *
13
+ * Represents a complete account (wallet, CEX account, brokerage, etc.) with all
14
+ * associated balances, DeFi positions, and NFTs. Central aggregation point for
15
+ * calculating total account value and tracking synchronization state.
16
+ *
17
+ * **Design Pattern:** Aggregate root pattern collecting all holdings from one
18
+ * source. Supports flexible position types (balances, liquidity, staking, lending)
19
+ * to accommodate diverse account types (spot, DeFi, wallet).
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { Account, AccountType, IntegrationSource } from '@cygnus-wealth/data-models';
24
+ *
25
+ * // MetaMask wallet account with balances and DeFi positions
26
+ * const walletAccount: Account = {
27
+ * id: 'metamask-wallet-1',
28
+ * name: 'Main Wallet',
29
+ * type: AccountType.WALLET,
30
+ * source: IntegrationSource.METAMASK,
31
+ * sourceAccountId: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
32
+ * balances: [
33
+ * {
34
+ * assetId: 'ethereum-eth',
35
+ * asset: {...},
36
+ * amount: '5.0',
37
+ * value: { value: 10000, currency: 'USD', timestamp: new Date() }
38
+ * },
39
+ * {
40
+ * assetId: 'ethereum-usdc',
41
+ * asset: {...},
42
+ * amount: '15000'
43
+ * }
44
+ * ],
45
+ * liquidityPositions: [
46
+ * {
47
+ * id: 'uniswap-eth-usdc-1',
48
+ * protocol: 'Uniswap V2',
49
+ * poolName: 'ETH/USDC',
50
+ * tokens: [...]
51
+ * }
52
+ * ],
53
+ * stakedPositions: [
54
+ * {
55
+ * id: 'lido-steth-1',
56
+ * protocol: 'Lido',
57
+ * stakedAmount: '2.0',
58
+ * rewards: [...]
59
+ * }
60
+ * ],
61
+ * totalValue: {
62
+ * value: 30000, // Sum of all positions
63
+ * currency: 'USD',
64
+ * timestamp: new Date()
65
+ * },
66
+ * lastSynced: new Date()
67
+ * };
68
+ *
69
+ * // Kraken CEX spot account
70
+ * const cexAccount: Account = {
71
+ * id: 'kraken-spot-1',
72
+ * name: 'Kraken Spot Trading',
73
+ * type: AccountType.SPOT,
74
+ * source: IntegrationSource.KRAKEN,
75
+ * balances: [...],
76
+ * totalValue: { value: 50000, currency: 'USD', timestamp: new Date() },
77
+ * lastSynced: new Date()
78
+ * };
79
+ * ```
80
+ *
81
+ * @since 0.0.1
82
+ * @stability standard
83
+ *
84
+ * @see {@link AccountType} for account classification
85
+ * @see {@link IntegrationSource} for source identification
86
+ * @see {@link Balance} for asset holdings
87
+ * @see {@link Portfolio} for multi-account aggregation
88
+ */
10
89
  export interface Account {
90
+ /** Unique identifier for this account */
11
91
  id: string;
92
+ /** User-friendly account name (e.g., 'Main Wallet', 'Trading Account') */
12
93
  name: string;
94
+ /** Type of account for categorization and specialized processing */
13
95
  type: AccountType;
96
+ /** Data source providing this account's information */
14
97
  source: IntegrationSource;
98
+ /** Source-specific account identifier (wallet address, exchange account ID, etc.) */
15
99
  sourceAccountId?: string;
100
+ /** Array of asset balances held in this account */
16
101
  balances: Balance[];
102
+ /** Array of DEX liquidity positions (for DeFi accounts) */
17
103
  liquidityPositions?: LiquidityPosition[];
104
+ /** Array of staking positions (for PoS and liquid staking) */
18
105
  stakedPositions?: StakedPosition[];
106
+ /** Array of lending/borrowing positions (for DeFi money markets) */
19
107
  lendingPositions?: LendingPosition[];
108
+ /** Array of NFTs held in this account */
20
109
  nfts?: NFT[];
110
+ /** Total value of all holdings in this account (sum of all positions) */
21
111
  totalValue?: Price;
112
+ /** Timestamp of last successful data synchronization */
22
113
  lastSynced?: Date;
114
+ /** Source-specific metadata (connection status, permissions, etc.) */
23
115
  metadata?: Metadata;
24
116
  }
@@ -1,5 +1,66 @@
1
+ /**
2
+ * Standardized error structure for API responses.
3
+ *
4
+ * Provides machine-readable error codes and human-readable messages for
5
+ * consistent error handling across all integrations. Details field allows
6
+ * source-specific error information like stack traces or validation errors.
7
+ *
8
+ * **Design Pattern:** Structured error with code for programmatic handling
9
+ * and message for display. Details field accommodates varying error contexts.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { ApiError } from '@cygnus-wealth/data-models';
14
+ *
15
+ * // Simple error
16
+ * const simpleError: ApiError = {
17
+ * code: 'UNAUTHORIZED',
18
+ * message: 'Invalid API key'
19
+ * };
20
+ *
21
+ * // Error with validation details
22
+ * const validationError: ApiError = {
23
+ * code: 'VALIDATION_ERROR',
24
+ * message: 'Request validation failed',
25
+ * details: {
26
+ * fields: {
27
+ * amount: 'Must be positive number',
28
+ * symbol: 'Required field'
29
+ * }
30
+ * }
31
+ * };
32
+ *
33
+ * // Error with stack trace (development)
34
+ * const serverError: ApiError = {
35
+ * code: 'INTERNAL_ERROR',
36
+ * message: 'An unexpected error occurred',
37
+ * details: {
38
+ * stack: 'Error: ...',
39
+ * timestamp: new Date().toISOString()
40
+ * }
41
+ * };
42
+ *
43
+ * // Common error codes
44
+ * const errorCodes = {
45
+ * RATE_LIMIT: 'Too many requests',
46
+ * NOT_FOUND: 'Resource not found',
47
+ * UNAUTHORIZED: 'Authentication required',
48
+ * FORBIDDEN: 'Insufficient permissions',
49
+ * TIMEOUT: 'Request timeout',
50
+ * NETWORK_ERROR: 'Network connection failed'
51
+ * };
52
+ * ```
53
+ *
54
+ * @since 0.0.1
55
+ * @stability standard
56
+ *
57
+ * @see {@link ApiResponse} for error usage in responses
58
+ */
1
59
  export interface ApiError {
60
+ /** Machine-readable error code (e.g., 'RATE_LIMIT', 'UNAUTHORIZED') */
2
61
  code: string;
62
+ /** Human-readable error message for display */
3
63
  message: string;
64
+ /** Optional error-specific details (stack trace, field errors, etc.) */
4
65
  details?: unknown;
5
66
  }
@@ -1,7 +1,66 @@
1
1
  import { ApiError } from './ApiError';
2
- export interface ApiResponse<T> {
2
+ /**
3
+ * Generic API response wrapper with success/error discrimination.
4
+ *
5
+ * Standard envelope for all API responses providing consistent structure for
6
+ * success and error handling. Mutually exclusive data/error pattern ensures
7
+ * type-safe response processing.
8
+ *
9
+ * **Design Pattern:** Result monad pattern with discriminated union - exactly
10
+ * one of data or error is present based on success flag. Timestamp enables
11
+ * response caching and freshness tracking.
12
+ *
13
+ * @template T - Response data type (should be object, not primitive)
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { ApiResponse, Account } from '@cygnus-wealth/data-models';
18
+ *
19
+ * // Successful response
20
+ * const successResponse: ApiResponse<Account> = {
21
+ * success: true,
22
+ * data: {
23
+ * id: 'wallet-1',
24
+ * name: 'Main Wallet',
25
+ * type: AccountType.WALLET,
26
+ * balances: [...]
27
+ * },
28
+ * timestamp: new Date()
29
+ * };
30
+ *
31
+ * // Error response
32
+ * const errorResponse: ApiResponse<Account> = {
33
+ * success: false,
34
+ * error: {
35
+ * code: 'RATE_LIMIT',
36
+ * message: 'Rate limit exceeded. Retry after 60 seconds.'
37
+ * },
38
+ * timestamp: new Date()
39
+ * };
40
+ *
41
+ * // Type-safe handling
42
+ * function handleResponse(response: ApiResponse<Account>) {
43
+ * if (response.success && response.data) {
44
+ * console.log('Account:', response.data.name);
45
+ * } else if (response.error) {
46
+ * console.error('Error:', response.error.message);
47
+ * }
48
+ * }
49
+ * ```
50
+ *
51
+ * @since 0.0.1
52
+ * @stability standard
53
+ *
54
+ * @see {@link ApiError} for error structure
55
+ * @see {@link PaginatedResponse} for paginated data
56
+ */
57
+ export interface ApiResponse<T extends object> {
58
+ /** Indicates whether the API call succeeded */
3
59
  success: boolean;
60
+ /** Response data (present if success === true) */
4
61
  data?: T;
62
+ /** Error details (present if success === false) */
5
63
  error?: ApiError;
64
+ /** Timestamp when the response was generated */
6
65
  timestamp: Date;
7
66
  }
@@ -1,18 +1,77 @@
1
1
  import { AssetType } from '../enums/AssetType';
2
2
  import { Chain } from '../enums/Chain';
3
3
  import { Metadata } from './Metadata';
4
+ /**
5
+ * Universal asset representation normalizing data from multiple sources.
6
+ *
7
+ * Core entity representing any tradeable or holdable financial instrument including
8
+ * cryptocurrencies, stocks, ETFs, NFTs, bonds, fiat currencies, and commodities.
9
+ * Designed to accommodate data from CEX APIs, DEX subgraphs, blockchain RPCs,
10
+ * and traditional finance systems.
11
+ *
12
+ * **Design Pattern:** Flexible field set supports source-specific identifiers
13
+ * (contractAddress for tokens, cusip/isin for securities, coingeckoId for market data)
14
+ * while maintaining consistent core identity (id, symbol, name, type).
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { Asset, AssetType, Chain } from '@cygnus-wealth/data-models';
19
+ *
20
+ * // ERC-20 token from blockchain
21
+ * const usdcAsset: Asset = {
22
+ * id: 'ethereum-usdc',
23
+ * symbol: 'USDC',
24
+ * name: 'USD Coin',
25
+ * type: AssetType.CRYPTOCURRENCY,
26
+ * decimals: 6,
27
+ * contractAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
28
+ * chain: Chain.ETHEREUM,
29
+ * coingeckoId: 'usd-coin'
30
+ * };
31
+ *
32
+ * // Traditional stock from brokerage
33
+ * const appleStock: Asset = {
34
+ * id: 'us-aapl',
35
+ * symbol: 'AAPL',
36
+ * name: 'Apple Inc.',
37
+ * type: AssetType.STOCK,
38
+ * cusip: '037833100',
39
+ * isin: 'US0378331005'
40
+ * };
41
+ * ```
42
+ *
43
+ * @since 0.0.1
44
+ * @stability standard
45
+ *
46
+ * @see {@link AssetType} for classification values
47
+ * @see {@link Chain} for blockchain identifiers
48
+ * @see {@link NFT} for NFT-specific extensions
49
+ */
4
50
  export interface Asset {
51
+ /** Unique identifier across all sources (e.g., 'ethereum-usdc', 'us-aapl') */
5
52
  id: string;
53
+ /** Trading symbol or ticker (e.g., 'USDC', 'AAPL', 'BTC') */
6
54
  symbol: string;
55
+ /** Human-readable asset name (e.g., 'USD Coin', 'Apple Inc.') */
7
56
  name: string;
57
+ /** Asset classification for filtering and display logic */
8
58
  type: AssetType;
59
+ /** Decimal places for balance precision (e.g., 18 for ETH, 6 for USDC, 2 for USD) */
9
60
  decimals?: number;
61
+ /** Smart contract address for blockchain tokens (ERC-20, SPL, etc.) */
10
62
  contractAddress?: string;
63
+ /** Blockchain network for token assets */
11
64
  chain?: Chain;
65
+ /** URL to asset logo or icon for UI display */
12
66
  logoUrl?: string;
67
+ /** CoinGecko API identifier for market data integration */
13
68
  coingeckoId?: string;
69
+ /** CoinMarketCap API identifier for market data integration */
14
70
  cmc_id?: string;
71
+ /** CUSIP identifier for North American securities */
15
72
  cusip?: string;
73
+ /** ISIN identifier for international securities */
16
74
  isin?: string;
75
+ /** Source-specific additional data and custom fields */
17
76
  metadata?: Metadata;
18
77
  }
@@ -1,13 +1,65 @@
1
1
  import { Asset } from './Asset';
2
2
  import { Price } from './Price';
3
3
  import { Metadata } from './Metadata';
4
+ /**
5
+ * Asset quantity with market value and profit/loss tracking.
6
+ *
7
+ * Represents the amount of an asset held in an account along with valuation
8
+ * and performance metrics. Uses string for amount to preserve precision beyond
9
+ * JavaScript number limits (e.g., for high-decimal tokens or very large quantities).
10
+ *
11
+ * **Design Pattern:** Composition of Asset reference, quantity, current value,
12
+ * and historical cost basis for P&L calculations. The amount field stores raw
13
+ * quantity respecting the asset's decimal places.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { Balance, Asset, AssetType } from '@cygnus-wealth/data-models';
18
+ *
19
+ * // Cryptocurrency balance with P&L
20
+ * const ethBalance: Balance = {
21
+ * assetId: 'ethereum-eth',
22
+ * asset: {
23
+ * id: 'ethereum-eth',
24
+ * symbol: 'ETH',
25
+ * name: 'Ethereum',
26
+ * type: AssetType.CRYPTOCURRENCY,
27
+ * decimals: 18
28
+ * },
29
+ * amount: '2.5', // 2.5 ETH
30
+ * value: {
31
+ * value: 5000,
32
+ * currency: 'USD',
33
+ * timestamp: new Date()
34
+ * },
35
+ * cost_basis: 4000, // Purchased for $4000
36
+ * unrealized_pnl: 1000, // Current profit
37
+ * realized_pnl: 0
38
+ * };
39
+ * ```
40
+ *
41
+ * @since 0.0.1
42
+ * @stability standard
43
+ *
44
+ * @see {@link Asset} for asset definition
45
+ * @see {@link Price} for valuation structure
46
+ * @see {@link PortfolioAsset} for composed portfolio view
47
+ */
4
48
  export interface Balance {
49
+ /** Reference to the Asset.id being held */
5
50
  assetId: string;
51
+ /** Complete asset details for display and calculations */
6
52
  asset: Asset;
53
+ /** Quantity held as string to preserve precision (respects asset.decimals) */
7
54
  amount: string;
55
+ /** Current market value of the balance (amount * current price) */
8
56
  value?: Price;
57
+ /** Total cost paid to acquire this balance (in value.currency) */
9
58
  cost_basis?: number;
59
+ /** Profit/loss from realized sales (in value.currency) */
10
60
  realized_pnl?: number;
61
+ /** Profit/loss from current market value vs cost basis (value.value - cost_basis) */
11
62
  unrealized_pnl?: number;
63
+ /** Source-specific additional data and custom fields */
12
64
  metadata?: Metadata;
13
65
  }
@@ -1,5 +1,66 @@
1
+ /**
2
+ * Base entity interface providing common identity and timestamp fields.
3
+ *
4
+ * BaseEntity serves as the foundational building block for all entity types in the
5
+ * CygnusWealth system. It establishes the pattern for entity identity and audit
6
+ * tracking across all bounded contexts.
7
+ *
8
+ * In Domain-Driven Design terms, this represents the common characteristics of all
9
+ * Entities (objects with identity), as distinguished from Value Objects (objects
10
+ * defined by their attributes).
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * interface Account extends BaseEntity {
15
+ * name: string;
16
+ * type: AccountType;
17
+ * }
18
+ *
19
+ * const account: Account = {
20
+ * id: "acc_123",
21
+ * createdAt: new Date("2025-01-01T00:00:00Z"),
22
+ * updatedAt: new Date("2025-01-01T00:00:00Z"),
23
+ * name: "Main Wallet",
24
+ * type: AccountType.WALLET
25
+ * };
26
+ * ```
27
+ *
28
+ * @since 0.0.1
29
+ * @stability core
30
+ *
31
+ * @see {@link Account} for an example entity using BaseEntity
32
+ * @see {@link Portfolio} for another example entity
33
+ */
1
34
  export interface BaseEntity {
35
+ /**
36
+ * Unique identifier for the entity.
37
+ *
38
+ * Format varies by entity type but must be globally unique within the entity's
39
+ * bounded context. Common patterns include:
40
+ * - UUID v4: `"550e8400-e29b-41d4-a716-446655440000"`
41
+ * - Prefixed ID: `"acc_123"`, `"txn_abc"`
42
+ * - Composite ID: `"eth-ethereum"`, `"btc-mainnet"`
43
+ *
44
+ * Consumers should treat IDs as opaque strings and not parse or derive meaning
45
+ * from their structure, as ID formats may evolve.
46
+ */
2
47
  id: string;
48
+ /**
49
+ * Timestamp when the entity was first created.
50
+ *
51
+ * Must be in UTC timezone. Immutable after initial creation.
52
+ * Used for audit trails and chronological sorting.
53
+ *
54
+ * @example new Date("2025-01-01T00:00:00Z")
55
+ */
3
56
  createdAt: Date;
57
+ /**
58
+ * Timestamp when the entity was last modified.
59
+ *
60
+ * Must be in UTC timezone. Updated on every mutation.
61
+ * Used for cache invalidation and optimistic locking.
62
+ *
63
+ * @example new Date("2025-01-15T14:30:00Z")
64
+ */
4
65
  updatedAt: Date;
5
66
  }
@@ -2,11 +2,79 @@ import { Chain } from '../enums/Chain';
2
2
  import { AssetType } from '../enums/AssetType';
3
3
  import { IntegrationSource } from '../enums/IntegrationSource';
4
4
  import { TimeRange } from '../types/TimeRange';
5
+ /**
6
+ * Flexible filtering criteria for portfolio and transaction queries.
7
+ *
8
+ * Composable filter interface supporting multi-dimensional filtering across
9
+ * chains, asset types, sources, time ranges, and value thresholds. All filters
10
+ * use AND logic between different filter types and OR logic within array filters.
11
+ *
12
+ * **Filter Logic:**
13
+ * - Multiple filter types are combined with AND
14
+ * - Array values within a filter type are combined with OR
15
+ * - Example: chains=[ETHEREUM, POLYGON] AND assetTypes=[CRYPTOCURRENCY]
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { FilterOptions, Chain, AssetType, IntegrationSource } from '@cygnus-wealth/data-models';
20
+ *
21
+ * // Filter for Ethereum/Polygon crypto assets
22
+ * const cryptoFilter: FilterOptions = {
23
+ * chains: [Chain.ETHEREUM, Chain.POLYGON],
24
+ * assetTypes: [AssetType.CRYPTOCURRENCY]
25
+ * };
26
+ *
27
+ * // Filter for high-value positions in last 30 days
28
+ * const recentHighValueFilter: FilterOptions = {
29
+ * minValue: 10000, // >= $10k
30
+ * timeRange: {
31
+ * start: new Date('2025-09-11'),
32
+ * end: new Date('2025-10-11')
33
+ * }
34
+ * };
35
+ *
36
+ * // Filter for wallet assets only
37
+ * const walletFilter: FilterOptions = {
38
+ * sources: [
39
+ * IntegrationSource.METAMASK,
40
+ * IntegrationSource.RABBY,
41
+ * IntegrationSource.PHANTOM
42
+ * ]
43
+ * };
44
+ *
45
+ * // Complex multi-dimensional filter
46
+ * const complexFilter: FilterOptions = {
47
+ * chains: [Chain.ETHEREUM],
48
+ * assetTypes: [AssetType.CRYPTOCURRENCY, AssetType.NFT],
49
+ * sources: [IntegrationSource.METAMASK],
50
+ * minValue: 1000,
51
+ * maxValue: 50000,
52
+ * timeRange: {
53
+ * start: new Date('2025-01-01'),
54
+ * end: new Date()
55
+ * }
56
+ * };
57
+ * ```
58
+ *
59
+ * @since 0.0.1
60
+ * @stability standard
61
+ *
62
+ * @see {@link Chain} for blockchain filtering
63
+ * @see {@link AssetType} for asset classification filtering
64
+ * @see {@link IntegrationSource} for source filtering
65
+ * @see {@link TimeRange} for time-based filtering
66
+ */
5
67
  export interface FilterOptions {
68
+ /** Filter by blockchain networks (OR within array) */
6
69
  chains?: Chain[];
70
+ /** Filter by asset types (OR within array) */
7
71
  assetTypes?: AssetType[];
72
+ /** Filter by data sources (OR within array) */
8
73
  sources?: IntegrationSource[];
74
+ /** Filter by time range (inclusive start and end) */
9
75
  timeRange?: TimeRange;
76
+ /** Minimum value threshold (inclusive, in base currency like USD) */
10
77
  minValue?: number;
78
+ /** Maximum value threshold (inclusive, in base currency like USD) */
11
79
  maxValue?: number;
12
80
  }