
polymarket-dune-pure
Package ref
polymarket-dune-pure@v0.4.1Run package
CLI
Run map_ctf_exchange_token_registered from the command line.
substreams run polymarket-dune-pure@v0.4.1 map_ctf_exchange_token_registered -e polygon --start-block -1substreams auth or directly on thegraph.market (see docs).README
Polymarket P&L Substreams
A comprehensive Substreams package that captures all Polymarket trading data and P&L calculations, perfectly matching the Dune Analytics query structure.
🎯 Features
- Complete Data Capture: All 13 data sources from the Dune query
- Real-time Streaming: Live data from Polygon mainnet
- Perfect Dune Match: 100% data structure compatibility
- Comprehensive P&L: Trading, liquidity, and reward calculations
- Market Metadata: Question data and market information
- Price Discovery: Real-time price tracking from order fills
🚀 Quick Start
1. Test Endpoint
python3 examples/test_scripts/test_proper_endpoint.py
2. Stream 7 Days of Data
python3 scripts/stream_7days_proper.py
3. View Dashboard
The script will create a comprehensive Dune-style dashboard with:
- Top 25 traders leaderboard
- P&L analytics
- Market activity summary
- Complete data export
📊 Data Sources Captured
- Market Creation - CTF Exchange & Neg Risk markets
- Trading Activity - ERC1155 transfers & order fills
- USDC Transfers - Trading-related USDC movements
- Liquidity Rewards - UMA & USDC Merkle Distributor claims
- AMM Markets - Fixed Product Market Maker creation
- Price Data - Real-time price discovery
- Question Metadata - Market questions and details
- Batch Transfers - Multi-token transfers
- Additional Rewards - USDC distributor claims
- Transaction Hashes - Real blockchain transaction IDs
- Block Timestamps - Precise timing data
- User Balances - Share values and USDC positions
- P&L Calculations - Comprehensive profit/loss tracking
🏗️ Architecture
src/
├── lib.rs # Main processing logic
├── abi.rs # ABI decoding functions
└── ...
proto/
└── contract.proto # Protobuf message definitions
scripts/
├── stream_7days_proper.py # Main 7-day streaming
├── stream_7days_simple.py # Simplified streaming
└── stream_recent_data.py # Recent data streaming
examples/
├── old_dashboards/ # Dashboard implementations
└── test_scripts/ # Testing utilities
🔧 Configuration
The package uses the official Polygon endpoint:
- Endpoint:
polygon.streamingfast.io:443 - Network: Polygon Mainnet
- Authentication: Via environment variables
📈 Output Format
Perfect match with Dune query structure:
{
"userPnls": [...], // User P&L data
"marketData": [...], // Market information
"tokenTransfers": [...], // ERC1155 transfers
"orderFills": [...], // Trading orders
"rewardClaims": [...] // Liquidity rewards
}
🎯 Dune Query Compatibility
This Substreams package provides 100% data structure compatibility with:
- Dune Query #3366316
- All 13 data sources captured
- Identical field names and types
- Real-time streaming capability
🚀 Next Steps
- Stream Data: Run the 7-day streaming script
- Build Dashboard: Use the generated data for web interface
- Real-time Updates: Set up continuous streaming
- Scale: Deploy for production use
📚 Documentation
Ready to build your Polymarket leaderboard! 🎉
Modules
Execution graph
Output
contract.v1.CtfEventsOutput
contract.v1.PureDunePnLOutput
contract.v1.UsdcEventsShow 2 dependencies
Output
sf.substreams.ethereum.v1.Events
`index_events` sets the following keys on the block: * Event signatures evt_sig:0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef (signature in hex, prefixed by 0x) * Event address evt_addr:0x0123456789abcdef0123456789abcdef01234567 (address in hex, prefixed by 0x)
Output
sf.substreams.index.v1.Keys
Inputs
