Wallet Entities
This document describes the core entities in the wallets domain and their relationships.
Entity Relationship Diagram
Wallet
The Wallet entity represents a custodial wallet that can hold multiple tokens across a specific blockchain.
Properties
- id:
WalletId- Unique identifier composed of owner and blockchain - blockchain:
Blockchain- The blockchain this wallet operates on - owner:
WalletOwner- The owner identifier (usually a user ID) - balance:
Amount- Current native token balance - feeMultiplier:
Amount- Multiplier for transaction fees (default: 1.0) - depositsEnabled:
boolean- Whether deposits are allowed - withdrawalsEnabled:
boolean- Whether withdrawals are allowed - updatedAt:
Date- Last update timestamp - createdAt:
Date- Creation timestamp
Key Methods
Static Methods
create(owner, blockchain)- Creates a new walletfromDto(dto)- Creates wallet from DTOfromId(id)- Creates wallet from ID
Instance Methods
derivePathFor(purposeIndex, index)- Gets derivation path for address generationnativeCoin()- Returns the native coin ID for this blockchainextendedPublicKey()- Gets the extended public key from environmentmnemonic()- Gets the mnemonic phrase from environmentupdateBalance(amount)- Updates the wallet balanceupdateFeeMultiplier(multiplier)- Updates fee multiplierupdateDepositsEnabled(enabled)- Enables/disables depositsupdateWithdrawalsEnabled(enabled)- Enables/disables withdrawals
Usage Example
// Create a new wallet
const wallet = Wallet.create(
WalletOwner.fromString('user123'),
Blockchain.fromString('ETH')
)
// Update settings
wallet.updateDepositsEnabled(false)
wallet.updateFeeMultiplier(Amount.fromString('1.5'))WalletAddress
The WalletAddress entity represents a specific address within a wallet for receiving funds. It's an abstract class with two concrete implementations.
Properties
- id:
WalletAddressId- Unique identifier - wallet:
Wallet- Parent wallet reference - purposeIndex:
number- Purpose index in HD derivation (usually 0 for deposits) - index:
number- Address index in HD derivation - address:
BlockchainAddress- The actual blockchain address - balance:
Amount- Current balance at this address - inUse:
boolean- Whether address is currently assigned to a user - lastUsedAt:
Date- When address was last used - updatedAt:
Date- Last update timestamp - createdAt:
Date- Creation timestamp
Key Methods
updateBalance(amount)- Updates address balancemarkAsUsedAt()- Updates last used timestampmarkAsInUse()- Marks address as in usemarkAsAvailable()- Marks address as available for reuseisToken()- Abstract method to check if it's a token addresscoinId()- Abstract method to get coin ID
Concrete Implementations
WalletNativeAddress
For native blockchain tokens (ETH, BTC, SOL, etc.)
WalletTokenAddress
For specific tokens (USDT, USDC, etc.) - extends a native address with token information
Transaction
The Transaction entity represents a blockchain transaction within the system.
Properties
- id:
TransactionId- Unique identifier - wallet:
Wallet- Associated wallet - motive:
TransactionMotive- Purpose of transaction (deposit, withdrawal, sweep, etc.) - amount:
Amount- Transaction amount - senders:
TransactionParticipant[]- Sending addresses and amounts - recipients:
TransactionParticipant[]- Receiving addresses and amounts - status:
TransactionStatus- Current status (pending, confirmed, failed, etc.) - token:
Token- Optional token (for token transfers) - txHash:
BlockchainTxHash- Optional blockchain transaction hash - updatedAt:
Date- Last update timestamp - createdAt:
Date- Creation timestamp
Key Methods
Static Methods
create(wallet, senders, recipients, motive, token?)- Creates new transactionfromDto(dto)- Creates transaction from DTO
Instance Methods
updateStatus(status)- Updates transaction statusparticipants()- Gets all participants (senders + recipients)addresses()- Gets all involved addressesisWaitingForSettlement()- Checks if transaction is within settlement window
Transaction Motives
- DEPOSIT - Incoming funds from external source
- WITHDRAWAL - Outgoing funds to external destination
- SWEEP - Internal consolidation of funds
- FEE - Fee payment transaction
- RESOURCE - Resource allocation (e.g., Tron energy)
Transaction Statuses
- PENDING - Created but not yet sent
- SENT - Sent to blockchain
- CONFIRMED - Confirmed on blockchain
- FAILED - Failed to process
- CANCELLED - Manually cancelled
WalletToken
The WalletToken entity represents the holding of a specific token within a wallet.
Properties
- wallet:
Wallet- Parent wallet - token:
Token- Token information - balance:
Amount- Current token balance - depositsEnabled:
boolean- Whether deposits are enabled for this token - withdrawalsEnabled:
boolean- Whether withdrawals are enabled for this token - updatedAt:
Date- Last update timestamp - createdAt:
Date- Creation timestamp
Key Methods
updateBalance(amount)- Updates token balanceupdateDepositsEnabled(enabled)- Enables/disables depositsupdateWithdrawalsEnabled(enabled)- Enables/disables withdrawals
Address Generation Strategy
The system uses HD (Hierarchical Deterministic) wallet derivation with the following structure:
m/blockchain_derivation_path/account'/purpose_index/address_index- account: Derived from wallet owner
- purpose_index: Always 0 for deposit addresses
- address_index: Incremental index (0 to 1000 max)
When the maximum number of addresses is reached, the system reuses the oldest used address.
State Management
Address Lifecycle
- Created - New address generated
- In Use - Assigned to user for deposits
- Available - Can be reused after period of inactivity
Transaction Lifecycle
- Created - Transaction object created
- Pending - Waiting to be sent
- Sent - Submitted to blockchain
- Confirmed - Confirmed on blockchain
- Failed/Cancelled - Terminal states
Balance Updates
Balances are updated through various triggers:
- Deposit detection
- Transaction confirmation
- Manual balance scans
- Sweep operations
