Data Flow & Processing
1. Event Processing Pipeline
Blockchain Event → Subsquid Processor → Event Decoder → State Manager → API Client
Step-by-Step Process
- Event Detection: Subsquid processor detects relevant blockchain events
- Event Decoding: Raw event data is decoded using protocol-specific ABIs
- State Update: Protocol state is updated based on event data
- Balance Calculation: Time-weighted balances are calculated
- Price Integration: USD values are calculated using price feeds
- Data Transmission: Processed data is sent to Absinthe API
2. Time-Weighted Balance Tracking
Window-Based Processing
- Configurable Windows: Balance snapshots taken at configurable intervals
- Trigger Events: Balance updates triggered by transfers or time windows
- Accurate Tracking: Maintains historical balance records with timestamps
Balance Calculation Example
// For a user holding 1000 LP tokens for 24 hours
const balanceWindow = {
userAddress: '0x...',
deltaAmount: 0, // No change in balance
startTs: 1640995200, // Start of day
endTs: 1641081600, // End of day
windowDurationMs: 86400000, // 24 hours
balanceBefore: '1000',
balanceAfter: '1000',
valueUsd: 5000, // Calculated USD value
};
3. Batch Processing
Optimization Features
- Batch Size Control: Configurable batch sizes for optimal performance
- Parallel Processing: Multiple protocols processed in parallel
- Memory Management: Efficient memory usage with streaming processing
- Error Recovery: Graceful handling of processing errors