A high-performance Substreams package for extracting and processing events from Polymarket contracts on Polygon. This package provides real-time data streaming for prediction market activities, trading events, and market maker operations.
Polymarket is a decentralized prediction market platform built on Ethereum and Polygon. This Substreams package indexes key events from Polymarket's smart contracts to provide:
0x4bfb41d5b3570defd03c39a9a4d8de6bd8b8982e
0x4D97DCd97eC945f40cF65F87097ACe5EA0476045
0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174
map_ctf_exchange_events
Extracts and processes events from the CTF Exchange contract, including:
map_ctf_events
Processes Conditional Tokens Framework events:
map_usdc_events
Tracks USDC token transfers and approvals for collateral management.
map_trading_data
Combines data from all modules to create enriched trading information:
git clone https://github.com/Polymarket/polymarket-substreams.git
cd polymarket-substreams
substreams build
substreams auth
# Run CTF Exchange events
substreams gui substreams.yaml map_ctf_exchange_events
# Run trading data aggregation
substreams gui substreams.yaml map_trading_data
substreams run -e polygon.streamingfast.io:443 substreams.yaml map_ctf_exchange_events --start-block 50000000 --stop-block 50000100
substreams gui substreams.yaml map_trading_data --start-block -1000
message Trade {
string transaction_hash = 1;
uint32 log_index = 2;
google.protobuf.Timestamp timestamp = 3;
uint64 block_number = 4;
string trader = 5;
string market_id = 6;
string outcome_token = 7;
string amount = 8;
string price = 9;
string fee = 10;
string trade_type = 11; // "buy" or "sell"
}
message Market {
string market_id = 1;
string condition_id = 2;
string question_id = 3;
string oracle = 4;
uint32 outcome_slot_count = 5;
google.protobuf.Timestamp creation_timestamp = 6;
string status = 7; // "open", "closed", "resolved"
}
This Substreams implementation provides significant performance improvements over traditional subgraphs:
To add support for additional Polymarket contracts:
src/lib.rs
substreams.yaml
with new moduleThe map_trading_data
module can be extended to include:
To publish this Substreams package:
substreams pack
substreams registry login
substreams registry publish polymarket-v0.1.0.spkg
Contributions are welcome! Please see our Contributing Guidelines for details.
This project is licensed under the MIT License - see the LICENSE file for details.
substreams gui polymarket@v0.1.0 map_ctf_exchange_events
substreams gui polymarket@v0.1.0 map_ctf_events
substreams gui polymarket@v0.1.0 map_usdc_events
substreams gui polymarket@v0.1.0 map_trading_data
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@v0.1.0 ethcommon:all_events
index_events
sets the following keys on the block:
substreams gui polymarket@v0.1.0 ethcommon:index_events
message
Calls
message
Call
message
Events
message
Event
message
EventsAndCalls
message
Transactions
message
Transaction
enum
DetailLevel
message
Modules
message
Binary
message
Module
message
Package
message
PackageMetadata
message
ModuleMetadata
message
Clock
message
BlockRef
message
FileDescriptorSet
message
FileDescriptorProto
message
DescriptorProto
message
ExtensionRangeOptions
message
FieldDescriptorProto
message
OneofDescriptorProto
message
EnumDescriptorProto
message
EnumValueDescriptorProto
message
ServiceDescriptorProto
message
MethodDescriptorProto
message
FileOptions
message
MessageOptions
message
FieldOptions
message
OneofOptions
message
EnumOptions
message
EnumValueOptions
message
ServiceOptions
message
MethodOptions
message
UninterpretedOption
message
SourceCodeInfo
message
GeneratedCodeInfo
message
Any
message
Timestamp
message
Duration
message
Request
message
Response
message
BlockUndoSignal
message
BlockScopedData
message
SessionInit
message
InitialSnapshotComplete
message
InitialSnapshotData
message
MapModuleOutput
message
StoreModuleOutput
message
OutputDebugInfo
message
ModulesProgress
message
ModuleProgress
message
BlockRange
message
StoreDelta
message
Block
message
BlockHeader
message
Uint64NestedArray
message
Uint64Array
message
BigInt
message
TransactionTrace
message
AccessTuple
message
TransactionReceipt
message
Log
message
Call
message
StorageChange
message
BalanceChange
message
NonceChange
message
AccountCreation
message
CodeChange
message
GasChange
message
HeaderOnlyBlock
message
BlockWithRefs
message
TransactionTraceWithBlockRef
message
TransactionRefs
message
BlockRef
enum
TransactionTraceStatus
enum
CallType
message
CtfExchangeEvents
message
CtfEvents
message
UsdcEvents
message
TradingData
message
Trade
message
Market
message
User
message
Ctf_ConditionPreparation
message
Ctf_ConditionResolution
message
Ctf_PositionSplit
message
Ctf_PositionMerge
message
Ctf_PositionRedeem
message
Usdc_Transfer
message
Usdc_Approval
message
Ctfexchange_FeeCharged
message
Ctfexchange_NewAdmin
message
Ctfexchange_NewOperator
message
Ctfexchange_OrderCancelled
message
Ctfexchange_OrderFilled
message
Ctfexchange_OrdersMatched
message
Ctfexchange_ProxyFactoryUpdated
message
Ctfexchange_RemovedAdmin
message
Ctfexchange_RemovedOperator
message
Ctfexchange_SafeFactoryUpdated
message
Ctfexchange_TokenRegistered
message
Ctfexchange_TradingPaused
message
Ctfexchange_TradingUnpaused
message
RpcCalls
message
RpcCall
message
RpcResponses
message
RpcResponse
message
DeployRequest
message
Parameter
message
DeployResponse
message
UpdateRequest
message
UpdateResponse
message
InfoRequest
message
InfoResponse
message
SinkProgress
message
PackageInfo
message
ListRequest
message
ListResponse
message
DeploymentWithStatus
message
RemoveRequest
message
RemoveResponse
message
PauseRequest
message
PauseResponse
message
StopRequest
message
StopResponse
message
ResumeRequest
message
ResumeResponse
enum
DeploymentStatus