A TypeScript-based blockchain data extraction tool for tracking liquidity pool participation on the Base network. This tool queries blockchain events to generate CSV ledgers of liquidity provider activity for reward distribution calculations.
This repository contains two versions for processing different types of liquidity pools:
- v2.ts - Processes Uniswap V2-style pools with simple Mint/Burn events
- v3.ts - Processes Uniswap V3-style concentrated liquidity pools with complex position management
Both scripts query blockchain logs via the HyperSync API, match related events, and output structured CSV files for reward calculations.
- ✅ Memory-efficient streaming log processing
- ✅ Robust retry logic with exponential backoff
- ✅ Event correlation across transaction boundaries
- ✅ CSV output for easy data analysis
- ✅ Support for both V2 and V3 liquidity pool types
- Node.js (v18 or higher recommended)
- npm or yarn
- HyperSync API key (obtain from HyperSync)
- Clone the repository:
git clone <repository-url>
cd st0x-rewards-script- Install dependencies:
npm install- Create environment file:
cp .env.example .env- Add your HyperSync API key to
.env:
HYPERSYNC_API_KEY=your_api_key_here
The default script processes V2-style pools:
npm startThis executes src/v2.ts which:
- Queries Transfer, Mint, and Burn events
- Matches events by transaction hash
- Outputs to CSV with columns: type, transactionHash, blockNumber, amount, amount0, amount1, user
To process V3-style concentrated liquidity pools:
npx ts-node src/v3.tsThis executes src/v3.ts which:
- Queries Transfer, Mint, Collect, IncreaseLiquidity, and DecreaseLiquidity events
- Performs sophisticated event matching by log index
- Outputs comprehensive liquidity tracking data
Edit src/v2.ts to modify:
const FROM_BLOCK = 39557809;
const TO_BLOCK = 40719263;
const CL_POOL = "0xb804FA2e3631465455594538067001E7A0f83D37";
const NFT_CONTRACT = "0xb804FA2e3631465455594538067001E7A0f83D37";Edit src/v3.ts to modify:
const FROM_BLOCK = 38913515;
const TO_BLOCK = 40249153;
const CL_POOL = "0x40a8e39AbA67debEdab94F76D21114AB39909c5a";
const NFT_CONTRACT = "0xa990c6a764b73bf43cee5bb40339c3322fb9d55f";The scripts only capture events within the specified FROM_BLOCK to TO_BLOCK range. This means:
This can cause:
- Decrease events without corresponding increase events
- Imbalanced liquidity calculations (appears to decrease more than increased)
- Incomplete position history
Solutions:
- Set FROM_BLOCK to the pool creation block to capture complete history
- Use a blockchain explorer to find the pool creation block
- Adjust FROM_BLOCK based on when you need to start tracking
V3 pools emit events from both the Pool contract and Position Manager contract:
- Mint (pool) + IncreaseLiquidity (manager) = Same operation
- Burn (pool) + DecreaseLiquidity (manager) = Same operation
The script outputs only IncreaseLiquidity and DecreaseLiquidity to avoid double-counting. Pool events (Mint/Burn) are used internally for matching and user attribution but not written as separate CSV rows.
CSV with the following columns:
type- Event type (mint/burn)transactionHash- Transaction hashblockNumber- Block numberamount- NFT token amountamount0- Pool token0 amountamount1- Pool token1 amountuser- Address of the user
CSV with the following event types:
increaseLiquidity - Liquidity added to position
type= 'increaseLiquidity'transactionHash- Transaction hashblockNumber- Block numberamount- Liquidity amount addedamount0- Token0 amountamount1- Token1 amountuser- User address (from Transfer event)
decreaseLiquidity - Liquidity removed from position
type= 'decreaseLiquidity'transactionHash- Transaction hashblockNumber- Block numberamount- Liquidity amount removedamount0- Token0 amountamount1- Token1 amountuser- User address (from Collect event)
collect - Fee collection (without liquidity removal)
type= 'collect'transactionHash- Transaction hashblockNumber- Block numberamount- 0 (no liquidity change)amount0- Token0 fees collectedamount1- Token1 fees collecteduser- Recipient address
Both scripts use the HyperSync API for efficient blockchain log querying:
- Chain ID: 8453 (Base network)
- Streaming callback architecture for memory efficiency
- Automatic pagination via
next_blockparameter
V2 Approach:
- Matches Transfer events with corresponding Mint/Burn events
- Groups by transaction hash
- Validates log index ordering
V3 Approach:
- More complex matching for concentrated liquidity positions
- Correlates IncreaseLiquidity/DecreaseLiquidity with Mint/Collect
- Tracks position-level changes across multiple transactions
Both scripts implement exponential backoff:
- Max 5 retry attempts
- Delays: 1s, 2s, 4s, 8s, 10s
- Automatic recovery from transient API failures
This repository includes a Nix flake for reproducible development:
nix developnpm install
npm run build # If you add a build script- TypeScript - Type-safe JavaScript
- ethers.js v6 - Ethereum interaction and ABI decoding
- axios - HTTP client for API requests
- HyperSync API - Efficient blockchain log queries
- ts-node - TypeScript execution runtime
ethers- Blockchain interactionaxios- HTTP requestsdotenv- Environment variable management
@safe-global/protocol-kit- Safe wallet integration@wagmi/core- Ethereum wallet connectionsviem- Alternative Ethereum librarypinata-web3- IPFS integration
If you encounter rate limiting:
- Reduce the block range size
- Add delays between requests
- Contact HyperSync for increased limits
For large block ranges:
- Process data in smaller chunks
- Adjust the
next_blockpagination - Monitor memory usage with
node --max-old-space-size=4096
If events aren't matching correctly:
- Verify contract addresses
- Check ABI definitions match deployed contracts
- Ensure block range includes complete transactions
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
[Add license information]
For issues or questions:
- Open a GitHub issue
- Contact the development team
Potential improvements:
- CLI interface for dynamic configuration
- Unit tests for event matching logic
- Configuration file support
- Real-time streaming mode
- Support for additional networks
- Automated reward calculation
- Database output option