Overview
This reference documents the database schema used by LeoKit for storing quotes, transactions, tokens, and operational data. Use this schema for backend integrations, analytics, and custom implementations.Core Tables
quotes Table
Stores all quote requests and responses with timing information.Field Descriptions
| Field | Type | Description | Constraints |
|---|---|---|---|
| id | UUID | Unique quote identifier | PRIMARY KEY |
| timestamp | BIGINT | Unix timestamp (milliseconds) | - |
| created_at | TIMESTAMPTZ | Timestamp with timezone | - |
| response_time | NUMERIC | API response time in ms | - |
| from_address | TEXT | Source wallet address | Nullable |
| to_address | TEXT | Destination wallet address | NOT NULL |
| quote_offers | JSONB | Array of protocol quotes | NOT NULL |
| client_api | TEXT | Client API key identifier | NOT NULL |
| quoting_type | TEXT | ’http’ or ‘streaming’ | NOT NULL |
| from_asset | TEXT | Source asset (CHAIN.SYMBOL-ADDRESS) | NOT NULL |
| to_asset | TEXT | Destination asset (CHAIN.SYMBOL-ADDRESS) | NOT NULL |
| amount | TEXT | Input amount in base units | NOT NULL |
Example Row
Indexes
deposits Table
Stores deposit transaction details after quote selection.Field Descriptions
| Field | Type | Description | Constraints |
|---|---|---|---|
| id | SERIAL | Auto-incrementing ID | PRIMARY KEY |
| client_api | TEXT | Client API key identifier | NOT NULL |
| quote_id | UUID | Reference to quotes.id | UNIQUE, NOT NULL |
| req_id | TEXT | Custom request identifier | Nullable |
| transaction | JSONB | Unsigned transaction data | NOT NULL |
| created_at | TIMESTAMPTZ | Creation timestamp | DEFAULT NOW() |
Example Row
Indexes
tx_status Table
Tracks transaction status and updates over time.Field Descriptions
| Field | Type | Description | Constraints |
|---|---|---|---|
| id | SERIAL | Auto-incrementing ID | PRIMARY KEY |
| quote_id | UUID | Reference to quotes.id | Nullable |
| deposit_id | INTEGER | Reference to deposits.id | FOREIGN KEY |
| tx_hash | TEXT | Blockchain transaction hash | Nullable |
| req_id | TEXT | Custom request identifier | Nullable |
| status | TEXT | Transaction status | NOT NULL |
| protocol | TEXT | Protocol name | NOT NULL |
| response | JSONB | Status response from protocol | NOT NULL |
| updated_at | TIMESTAMPTZ | Last update timestamp | DEFAULT NOW() |
Status Values
| Status | Description |
|---|---|
| pending | Transaction submitted but not confirmed |
| processing | Transaction confirmed, swap in progress |
| completed | Swap completed successfully |
| failed | Transaction or swap failed |
| refunded | Transaction refunded due to error |
Example Row
Indexes
Asset & Pricing Tables
tokens Table
Stores token metadata and pricing information.Field Descriptions
| Field | Type | Description | Constraints |
|---|---|---|---|
| id | SERIAL | Auto-incrementing ID | PRIMARY KEY |
| blockchain | TEXT | Blockchain short name (ETH, BSC, etc.) | NOT NULL |
| symbol | TEXT | Token symbol | NOT NULL |
| address | TEXT | Contract address (NULL for native) | Nullable |
| decimals | INTEGER | Token decimals | NOT NULL |
| price_usd | NUMERIC | Current price in USD | Nullable |
| coingecko_id | TEXT | CoinGecko API identifier | Nullable |
| is_popular | BOOLEAN | Flag for popular tokens | DEFAULT FALSE |
| updated_at | TIMESTAMPTZ | Last price update | - |
| icon_url | TEXT | Token icon URL | Nullable |
Example Rows
Indexes
gas_prices Table
Stores historical gas price data per chain.Field Descriptions
| Field | Type | Description | Constraints |
|---|---|---|---|
| id | SERIAL | Auto-incrementing ID | PRIMARY KEY |
| chain | TEXT | Blockchain short name | NOT NULL |
| price | NUMERIC | Gas price in chain units | NOT NULL |
| timestamp | BIGINT | Unix timestamp (milliseconds) | NOT NULL |
| created_at | TIMESTAMPTZ | Record creation time | DEFAULT NOW() |
Gas Price Units by Chain
| Chain Type | Unit | Description |
|---|---|---|
| EVM | gwei | 10^9 wei |
| Bitcoin | sat/vbyte | Satoshis per virtual byte |
| Cosmos | native | Native token units |
| NEAR | TGas | TeraGas units |
Example Rows
Indexes
Error & Debug Tables
error_logs Table
Stores error traces for debugging and support.Field Descriptions
| Field | Type | Description | Constraints |
|---|---|---|---|
| id | SERIAL | Auto-incrementing ID | PRIMARY KEY |
| trace_id | TEXT | Unique error trace ID | UNIQUE, NOT NULL |
| client_api | TEXT | Client API key identifier | NOT NULL |
| error_details | JSONB | Error message and stack | NOT NULL |
| endpoint | TEXT | API endpoint that errored | NOT NULL |
| request_params | JSONB | Request parameters | Nullable |
| timestamp | TIMESTAMPTZ | Error occurrence time | DEFAULT NOW() |
Example Row
Indexes
Cleanup Policy
Error logs older than 30 days are automatically purged:Client Configuration
clients Table (Reference)
Stores API key configurations and permissions.Field Descriptions
| Field | Type | Description |
|---|---|---|
| id | SERIAL | Auto-incrementing ID |
| api_key | TEXT | Unique API key |
| name | TEXT | Client name/organization |
| enabled_protocols | TEXT[] | Array of enabled protocols |
| fee_recipient | TEXT | Affiliate fee recipient address |
| affiliate_bps | INTEGER | Default affiliate fee (BPS) |
| rate_limit | INTEGER | Requests per minute limit |
| created_at | TIMESTAMPTZ | Account creation time |
| updated_at | TIMESTAMPTZ | Last configuration update |
Relationships
Entity Relationship Diagram
Join Examples
Get Quote with Deposit and Status
Get Client Analytics
Get Popular Tokens
Data Retention
Recommended Retention Policies
| Table | Retention Period | Cleanup Query |
|---|---|---|
| quotes | 90 days | DELETE FROM quotes WHERE created_at < NOW() - INTERVAL '90 days' |
| deposits | 90 days | DELETE FROM deposits WHERE created_at < NOW() - INTERVAL '90 days' |
| tx_status | 90 days | DELETE FROM tx_status WHERE updated_at < NOW() - INTERVAL '90 days' |
| error_logs | 30 days | DELETE FROM error_logs WHERE timestamp < NOW() - INTERVAL '30 days' |
| gas_prices | 7 days | DELETE FROM gas_prices WHERE created_at < NOW() - INTERVAL '7 days' |
| tokens | Indefinite | N/A (update pricing only) |
Archival Strategy
For long-term analytics, consider archiving old records to separate tables:Performance Optimization
Query Optimization Tips
- Use appropriate indexes for your query patterns
- Partition large tables by date (monthly partitions recommended)
- Use JSONB indexes for frequently queried JSON fields
- Analyze query plans with EXPLAIN ANALYZE
- Vacuum regularly to maintain table performance