Package Logo
polymarket-dune-pure
polymarket-dune-pure@v0.4.1
Total Downloads
3
Published
1 months ago
Network
polygon polygon
Publisher
User Avatar PaulieB14

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

  1. Market Creation - CTF Exchange & Neg Risk markets
  2. Trading Activity - ERC1155 transfers & order fills
  3. USDC Transfers - Trading-related USDC movements
  4. Liquidity Rewards - UMA & USDC Merkle Distributor claims
  5. AMM Markets - Fixed Product Market Maker creation
  6. Price Data - Real-time price discovery
  7. Question Metadata - Market questions and details
  8. Batch Transfers - Multi-token transfers
  9. Additional Rewards - USDC distributor claims
  10. Transaction Hashes - Real blockchain transaction IDs
  11. Block Timestamps - Precise timing data
  12. User Balances - Share values and USDC positions
  13. 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

  1. Stream Data: Run the 7-day streaming script
  2. Build Dashboard: Use the generated data for web interface
  3. Real-time Updates: Set up continuous streaming
  4. Scale: Deploy for production use

📚 Documentation


Ready to build your Polymarket leaderboard! 🎉

Documentation

Modules

Maps icon
Maps

map
map_ctf_exchange_token_registered

64c043dff25ffca9c9b93bee350fff9ad9791a81
map map_ctf_exchange_token_registered (
blocksf.ethereum.type.v2.Block
)  -> contract.v1.TokenRegisteredEvents
substreams gui polymarket-dune-pure@v0.4.1 map_ctf_exchange_token_registered

map
map_neg_risk_ctf_exchange_token_registered

daebfa3f497c57ca564fa0c785d95dc2314af6ba
map map_neg_risk_ctf_exchange_token_registered (
)  -> contract.v1.NegRiskTokenRegisteredEvents
substreams gui polymarket-dune-pure@v0.4.1 map_neg_risk_ctf_exchange_token_registered

map
map_fpmm_factory_creation

80080b70feed9eb5a2ff32aee786e5f2708f62b6
map map_fpmm_factory_creation (
)  -> contract.v1.FpmmFactoryEvents
substreams gui polymarket-dune-pure@v0.4.1 map_fpmm_factory_creation

map
map_ctf_exchange_order_filled

59e1734528403ebfd2047d7cabedd32dfb1e23b8
map map_ctf_exchange_order_filled (
)  -> contract.v1.OrderFilledEvents
substreams gui polymarket-dune-pure@v0.4.1 map_ctf_exchange_order_filled

map
map_neg_risk_ctf_exchange_order_filled

d1f18d5d86aea65268a25a72ef4adbca91ff68f7
map map_neg_risk_ctf_exchange_order_filled (
)  -> contract.v1.OrderFilledEvents
substreams gui polymarket-dune-pure@v0.4.1 map_neg_risk_ctf_exchange_order_filled

map
map_erc1155_transfer_single

4fe839d907f6f1c7aed5e9de6a3a17dfba7124d8
map map_erc1155_transfer_single (
)  -> contract.v1.Erc1155TransferSingleEvents
substreams gui polymarket-dune-pure@v0.4.1 map_erc1155_transfer_single

map
map_erc1155_transfer_batch

184373735e0e6ae45201842790490936f5a95ce4
map map_erc1155_transfer_batch (
)  -> contract.v1.Erc1155TransferBatchEvents
substreams gui polymarket-dune-pure@v0.4.1 map_erc1155_transfer_batch

map
map_erc20_transfer

2e891d4e2ad25aeafe3280998607dde2ae4a16c8
substreams gui polymarket-dune-pure@v0.4.1 map_erc20_transfer

map
map_uma_merkle_distributor

4a70b409cc6405f271fc0915f141f105c6a58e32
map map_uma_merkle_distributor (
)  -> contract.v1.MerkleDistributorEvents
substreams gui polymarket-dune-pure@v0.4.1 map_uma_merkle_distributor

map
map_usdc_merkle_distributor

c05176a6aa8f49c949567e7498c9fab9b73fbc33
map map_usdc_merkle_distributor (
)  -> contract.v1.MerkleDistributorEvents
substreams gui polymarket-dune-pure@v0.4.1 map_usdc_merkle_distributor

map
map_ctf_events

99f7a1e911480a47e620cadbf097f17f97711a49
map map_ctf_events (
)  -> contract.v1.CtfEvents
substreams gui polymarket-dune-pure@v0.4.1 map_ctf_events

map
map_usdc_events

4f8558da4125a5bdf592552029d36ddfbc8b4155
map map_usdc_events (
)  -> contract.v1.UsdcEvents
substreams gui polymarket-dune-pure@v0.4.1 map_usdc_events

map
map_pure_dune_pnl

b73dc1858639097c39677b01ca077b8a60d60f7f
map map_pure_dune_pnl (
)  -> contract.v1.PureDunePnL
substreams gui polymarket-dune-pure@v0.4.1 map_pure_dune_pnl

map
ethcommon:all_events

963652a247fd23d0823dde62d21ae54c783b6073
map ethcommon:all_events (
)  -> sf.substreams.ethereum.v1.Events

all_events gives you all the events in a block (from successful transactions), with basic block hash/number/timestamp and transaction hash

substreams gui polymarket-dune-pure@v0.4.1 ethcommon:all_events
Block Indexes icon
Block Indexes

blockIndex
ethcommon:index_events

87255243f80f5d4755cd826ec57bf70696a4d7b6

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)
substreams gui polymarket-dune-pure@v0.4.1 ethcommon:index_events
Protobuf

Protobuf Docs Explorer

sf.ethereum.type.v2
sf.ethereum.substreams.v1
contract.v1