Package Logo
sei-scanner
sei-scanner@v0.1.1
Total Downloads
461
Published
1 weeks ago
Publisher
User Avatar Rimantovas

Readme

SEI DEX Scanner - Substreams Module

A real-time blockchain data processor for tracking trading activity, liquidity changes, and token balances across multiple DEX protocols on the SEI blockchain (Sailor, Dragonswap V1/V2).

Network: sei-mainnet Start Block: 126504154

Quick Start

Build

substreams build

Compiles Rust to WASM and generates protobuf bindings.

Stream Data

substreams auth                # Authenticate first
substreams gui                 # Launch interactive streaming interface

Package & Publish

substreams pack                # Create .spkg file for distribution
substreams registry login      # Login to substreams.dev
substreams registry publish    # Publish to registry

Modules

The pipeline processes blockchain data through 7 stages:

  1. map_pool_created - Discovers new liquidity pools from factory contracts
  2. store_pools - Stores canonical pool metadata (tokens, fees, addresses)
  3. map_swaps - Extracts swap/trade events from pools
  4. map_mints - Tracks liquidity additions
  5. map_burns - Tracks liquidity removals
  6. map_token_accounts - Monitors ERC20 token balance changes
  7. graph_out - Combines all outputs into unified structured message

Supported DEX Protocols

  • Sailor (Uniswap V3 fork) - Factory: 0xa51136931fdd3875902618bf6b3abe38ab2d703b
  • Dragonswap V2 (Uniswap V3 fork)
  • Dragonswap V1 (Uniswap V2 style)

Architecture

The DEX handler system uses a trait-based pattern (src/dex_handlers/mod.rs) for protocol-agnostic event processing. Each DEX implements:

  • Pool creation detection
  • Swap/trade extraction
  • Liquidity position tracking (mint/burn)

Adding a new DEX:

  1. Create handler in src/dex_handlers/ implementing DexHandler trait
  2. Add ABI JSON files to abi/ directory
  3. Register ABIs in build.rs
  4. Add handler to get_handlers() in src/maps/pool_mappings.rs

Key Features

  • Quote Token System - Standardized pricing against SEI, USDC, USDT
  • Uniswap V3 Math - Handles concentrated liquidity calculations (sqrtPriceX96)
  • Multi-Protocol Support - Extensible handler pattern for new DEX protocols
  • Real-time Processing - Streams blockchain data as it's produced

Troubleshooting

Issue Solution
Build fails Ensure wasm32-unknown-unknown target: rustup target add wasm32-unknown-unknown
Missing proto definitions Run substreams build to regenerate bindings
Handler not firing Verify contract address and event signature in handler, check registration in pool_mappings.rs

See CLAUDE.md for detailed architecture and implementation guidance.

Documentation

Modules

Maps icon
Maps

map
map_pool_created

a4ae97fa13aa9c1d1c075f0a10087a1d0386a262
map map_pool_created (
blocksf.ethereum.type.v2.Block
)  -> trading.Pool
substreams gui sei-scanner@v0.1.1 map_pool_created

map
map_swaps

1effff39ef6f15b23cb9997e6d5346bfad3a3bef
substreams gui sei-scanner@v0.1.1 map_swaps

map
map_mints

ff781ce664cf603e46e656c04c129e03f23d9739
substreams gui sei-scanner@v0.1.1 map_mints

map
map_burns

fef887ca7915c66bf2c05679c86c446bcdf5a026
substreams gui sei-scanner@v0.1.1 map_burns

map
map_token_accounts

1f762ab5486506d8c66c7a304590c9ea88c410ae
map map_token_accounts (
)  -> trading.TokenAccounts
substreams gui sei-scanner@v0.1.1 map_token_accounts

map
graph_out

95422a0883826cb5a1d1486e431741d58c12f3e8
substreams gui sei-scanner@v0.1.1 graph_out
Stores icon
Stores

store
store_pools

ef05dfb2b78c2a4155e6c0417df41121c3d8324e
store <set,trading.Pool> store_pools (
)
substreams gui sei-scanner@v0.1.1 store_pools
Protobuf

Protobuf Docs Explorer

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