Balance Management
The BalanceManager contract handles all fund custody and balance tracking within the CLOB system.Balance States
Funds in the CLOB system exist in two states:| State | Description |
|---|---|
| Available | Funds deposited but not committed to orders |
| Locked | Funds committed to open orders |
Deposits
Token Deposits
- Approve the BalanceManager to spend your tokens
- Call
deposit()through the CLOBRouter - Funds become available in your CLOB balance
ETH Deposits
For native ETH:- Call
depositETH()with value - ETH is wrapped to WETH automatically
- WETH becomes available in your CLOB balance
Withdrawals
Callwithdraw() through the CLOBRouter to move funds back to your wallet.
Important: Only available (unlocked) funds can be withdrawn. To withdraw locked funds, cancel the associated orders first.
Fund Locking
When you place an order:- Required funds move from available to locked
- Locked funds are reserved for that specific order
- Locked funds return to available
- You can then withdraw or use for new orders
Trade Settlement
When orders match:- Locked funds transfer between buyer and seller
- Fees are deducted automatically
- Counterparty receives funds in their available balance
Fee Structure
| Fee Type | When Applied |
|---|---|
| Maker Fee | Order adds liquidity (resting order) |
| Taker Fee | Order removes liquidity (crossing order) |
Balance Queries
Available Balance
Locked Balance
Total Balance
A user’s total funds = available + sum(locked across all pools)Security
Fund Isolation
- Each user’s funds are tracked separately
- Locked funds are isolated per OrderBook
- No cross-user fund access
Authorization
| Operation | Authorized Callers |
|---|---|
deposit | CLOBRouter |
withdraw | CLOBRouter |
lock | OrderBook |
unlock | OrderBook |
transferLockedFrom | OrderBook |
Error Handling
| Error | Cause | Resolution |
|---|---|---|
InsufficientBalance | Not enough available funds | Deposit more or cancel orders |
ZeroAmount | Attempted zero-value operation | Use non-zero amount |
UnauthorizedCaller | Caller not authorized | Use CLOBRouter |
TransferError | Token transfer failed | Check token approval/balance |
NativeTransferFailed | ETH transfer failed | Check recipient can receive ETH |
Events
| Event | Description |
|---|---|
Deposit | Funds deposited |
Withdrawal | Funds withdrawn |
Lock | Funds locked for order |
Unlock | Funds unlocked |
TransferFrom | Settlement transfer |
TransferLockedFrom | Locked fund transfer |