Pool depth does not affect price in Bolt. However, available inventory determines whether a trade can settle. Indexing pool state lets you pre-validate trades before submission and detect failed swaps in advance.
What to Index
The following table summarizes the critical pool state fields you should index:| Field | Description | Why It Matters |
|---|---|---|
| Available Inventory | The current balance of each asset in the pool | Determines whether a specific amountOut can be settled. If you request more output than available, the trade fails. |
| Fee Parameters | The swap fee rate (e.g., 0.0025 for 0.25%) | Required to compute amountOut in off-chain quoting. Fees are applied to the oracle price before settlement. |
| Oracle Reference ID | The authoritative oracle feed ID for the asset pair | Tells you which oracle publishes the reference price. Multiple pools may use different oracles for the same pair. |
| Minimum Swap Amount | The minimum amountIn required for any trade | Prevents spam and ensures meaningful trades. Swaps below this threshold are rejected by the contract. |
| Pool Thresholds | Inventory levels at which rebalancing or constraints are triggered | Some pools have dynamic behavior when inventory drops below a threshold. |
Querying Pool State by Blockchain
- Sui
- Archway
On Sui, query pool state using the Sui TypeScript SDK or JSON-RPC directly.Key points for Sui:
Sui Example
- Use
getObjectto fetch the pool object by its ID - Pool fields are nested under
content.fields - Parse inventory and fee rate from the field values
- Subscribe to events using
subscribeEventfor real-time updates
Setting Up a State Indexer
Connect to RPC
Establish a connection to a public or private RPC node for the blockchain where Bolt pools are deployed. Use a WebSocket connection for real-time updates if available.
Query Initial State
Fetch the initial pool state by querying each pool object or contract. Store the result in memory or a local database with a timestamp.
Subscribe to Events
Subscribe to swap events, rebalance events, and inventory updates emitted by Bolt pools. Events indicate when pool state changes.
Handle State Updates
When an event is received, parse it and update your local cache. Ensure your cache remains consistent with on-chain state.
Caching Strategy
Advanced Indexing Patterns
Event-Driven vs Polling
Event-Driven vs Polling
Event-driven indexing subscribes to on-chain events and updates state immediately when an event is received. This provides the lowest latency and most accurate state.
- Pros: Real-time updates, low computational overhead
- Cons: Requires WebSocket support, more complex event parsing
- Pros: Simple to implement, no WebSocket dependency
- Cons: Higher latency, higher RPC load, potential stale state
Handling Rebalance Events
Handling Rebalance Events
When a market maker rebalances a Bolt pool, inventory shifts significantly. Your indexer must detect and apply rebalance events immediately:
- Monitor for
PoolRebalanceor equivalent events - Parse the new inventory levels from the event
- Update your local cache synchronously
- If a pending quote was based on pre-rebalance inventory, consider it stale
Multi-Pool Indexing
Multi-Pool Indexing
If you’re integrating multiple Bolt pools, index all of them in parallel:
- Query all pool objects in a single batch RPC call to reduce latency
- Subscribe to events from all pools simultaneously
- Maintain a map of pool ID to cached state for O(1) lookup
- Periodically refresh all pools together to amortize RPC overhead
Detecting State Staleness
Monitor the timestamp or block height of your cached pool state. If your cache exceeds the staleness threshold:- Soft staleness (1-2 minutes old): Safe for most use cases; consider refreshing on the next RPC query window
- Hard staleness (5+ minutes old): Refresh immediately before submitting any trades
- Event-driven only: If you rely entirely on events and haven’t received an update in 10+ minutes, force a full state refresh as a sanity check
Related Documentation
Off-Chain Quoting
Use pool state to compute deterministic quotes off-chain.
Contract Math
Understand the pricing formulas that depend on pool parameters.