useSyncOraclePriceStore
Synchronizes oracle price data for specified markets to the oracle price store. This hook manages oracle clients for different oracle sources (Pyth, Switchboard, etc.) and keeps price data updated in real-time.Signature
Parameters
Array of markets and their corresponding oracle account addresses to monitor.
How frequently (in milliseconds) to update the oracle price store with the latest local price data.
Behavior
- Oracle Client Initialization: Creates oracle clients for all supported oracle sources (Pyth, Switchboard, etc.) when the connection and Drift client are ready
-
Account Monitoring: Uses the
BulkAccountLoaderto subscribe to oracle account updates for each market -
Price Processing: When oracle account data changes:
- Decodes the oracle price data using the appropriate oracle client
- Converts price data to
BigNumformat with proper precision - Updates the local price store state with the new data
-
Store Synchronization: Periodically syncs the local price state to the global
OraclePriceStoreat the specified refresh rate
Price Data Format
Each market’s price data includes:Example
Example: Single Market Price
Implementation Details
-
Oracle Clients: Automatically initializes clients for all supported oracle sources:
- Pyth
- Switchboard
- QuoteAsset (for stable coins)
- Prelaunch Oracle
-
Bulk Account Loader: Uses the shared
BulkAccountLoaderfor efficient account monitoring with minimal RPC calls -
Local State Management: Maintains a local copy of price data using
useImmerto prevent excessive re-renders. The store is only updated at the specifiedrefreshTimeMsinterval - Cleanup: Automatically removes account callbacks from the bulk loader when the component unmounts or when the markets list changes
Performance Considerations
The hook uses a two-tier update strategy:
- Oracle account changes are processed immediately and stored locally
- The global store is updated at the
refreshTimeMsinterval
Source
source/react/src/hooks/oraclePrice/useSyncOraclePriceStore.ts:38