Substreams for indexing Hypercore blockchain data.
This repository contains Substreams modules for extracting and processing Hypercore blockchain data, with support for ClickHouse as a sink database.
A Hypercore Block contains:
message Block {
BlockHeader block_header = 1 ;
repeated Fill fills = 2 ;
repeated Event events = 3 ;
}
message BlockHeader {
uint64 block_number = 1 ;
google.protobuf.Timestamp block_time = 2 ;
}
All events are wrapped in an Event message that contains metadata and a list of event bodies:
message Event {
google.protobuf.Timestamp time = 1 ;
bytes hash = 2 ;
repeated EventBody events = 3 ;
}
The EventBody message uses a oneof to represent different event types:
Event Type
Description
ClickHouse Table
Delegation
Staking delegation/undelegation events
delegations
CDeposit
Cross-chain deposit events
c_deposits
CWithdrawal
Cross-chain withdrawal events
c_withdrawals
Funding
Funding rate events with deltas
funding_deltas
ValidatorRewards
Validator reward distributions
validator_rewards
LedgerUpdate
Account ledger changes (see below)
Various tables
Represents staking delegation or undelegation events.
Field
Type
Description
user
bytes
User address performing the delegation
validator
bytes
Validator address
amount
string
Delegation amount
is_undelegate
bool
true if undelegating, false if delegating
CDeposit (Cross-chain Deposit)
Represents cross-chain deposit events.
Field
Type
Description
user
bytes
User address receiving the deposit
amount
string
Deposit amount
CWithdrawal (Cross-chain Withdrawal)
Represents cross-chain withdrawal events.
Field
Type
Description
user
bytes
User address initiating withdrawal
amount
string
Withdrawal amount
is_finalized
bool
Whether the withdrawal is finalized
Contains funding rate deltas for perpetual positions.
Field
Type
Description
deltas
repeated FundingDelta
List of funding deltas
Field
Type
Description
user
bytes
User address
coin
string
Trading pair/coin symbol
funding_amount
string
Funding payment amount
szi
string
Signed position size
funding_rate
string
Funding rate applied
Contains validator reward distributions.
Field
Type
Description
validator_to_reward
repeated ValidatorReward
List of validator rewards
Field
Type
Description
validator
bytes
Validator address
reward
string
Reward amount
LedgerUpdate events represent changes to user account ledgers. Each update includes:
message LedgerUpdate {
repeated bytes users = 1 ;
LedgerUpdateDelta delta = 2 ;
}
Ledger Update Delta Types
Delta Type
Description
ClickHouse Table
SpotTransfer
Spot token transfers
ledger_spot_transfers
CStakingTransfer
Cross-chain staking transfers
ledger_c_staking_transfers
AccountClassTransfer
Transfers between spot and perp accounts
ledger_account_class_transfers
InternalTransfer
Internal USDC transfers
ledger_internal_transfers
SubAccountTransfer
Sub-account USDC transfers
ledger_sub_account_transfers
Send
Cross-DEX token sends
ledger_sends
Deposit
USDC deposits
ledger_deposits
Withdraw
USDC withdrawals
ledger_withdrawals
VaultDeposit
Vault deposits
ledger_vault_deposits
RewardsClaim
Rewards claims
ledger_rewards_claims
VaultWithdraw
Vault withdrawals
ledger_vault_withdrawals
VaultLeaderCommission
Vault leader commission payments
ledger_vault_leader_commissions
DeployGasAuction
Gas auction deployments
ledger_deploy_gas_auctions
AccountActivationGas
Account activation gas fees
ledger_account_activation_gas
ActivateDexAbstraction
DEX abstraction activations
ledger_activate_dex_abstractions
Liquidation
Account liquidations
ledger_liquidations
SpotGenesis
Spot genesis token allocations
ledger_spot_genesis
VaultDistribution
Vault profit distributions
ledger_vault_distributions
BorrowLend
Borrow/lend operations
ledger_borrow_lends
VaultCreate
Vault creation events
ledger_vault_creates
Ledger Update Delta Details
Field
Type
Description
token
string
Token symbol
amount
string
Transfer amount
usdc_value
string
USDC equivalent value
user
bytes
Source user address
destination
bytes
Destination user address
fee
string
Transfer fee
native_token_fee
string
Fee in native token
nonce
uint64
Transaction nonce
fee_token
string
Token used for fee payment
Field
Type
Description
token
string
Token symbol
amount
string
Transfer amount
is_deposit
bool
true if deposit, false if withdrawal
Field
Type
Description
usdc
string
USDC amount transferred
to_perp
bool
true if transferring to perp, false if to spot
Field
Type
Description
usdc
string
USDC amount
user
bytes
Source user address
destination
bytes
Destination user address
fee
string
Transfer fee
Field
Type
Description
usdc
string
USDC amount
user
bytes
Source user/sub-account address
destination
bytes
Destination user/sub-account address
Field
Type
Description
user
bytes
Source user address
destination
bytes
Destination user address
source_dex
string
Source DEX identifier
destination_dex
string
Destination DEX identifier
token
string
Token symbol
amount
string
Token amount
usdc_value
string
USDC equivalent value
fee
string
Transfer fee
native_token_fee
string
Fee in native token
nonce
uint64
Transaction nonce
fee_token
string
Token used for fee payment
Field
Type
Description
usdc
string
USDC deposit amount
Field
Type
Description
usdc
string
USDC withdrawal amount
nonce
uint64
Withdrawal nonce
fee
string
Withdrawal fee
Field
Type
Description
vault
bytes
Vault address
usdc
string
USDC deposit amount
Field
Type
Description
amount
string
Claimed reward amount
token
string
Reward token symbol
Field
Type
Description
vault
bytes
Vault address
user
bytes
User withdrawing
requested_usd
string
Requested USD amount
commission
string
Commission charged
closing_cost
string
Position closing cost
basis
string
Cost basis
net_withdrawn_usd
string
Net withdrawn USD amount
Field
Type
Description
user
bytes
Vault leader address
usdc
string
Commission amount in USDC
Field
Type
Description
token
string
Token symbol
amount
string
Gas auction amount
Field
Type
Description
amount
string
Gas amount
token
string
Token symbol
Field
Type
Description
dex
string
DEX identifier
token
string
Token symbol
amount
string
Amount for activation
Field
Type
Description
liquidated_ntl_pos
string
Liquidated notional position value
account_value
string
Account value at liquidation
leverage_type
LeverageType
CROSS or ISOLATED
liquidated_positions
repeated LiquidatedPosition
List of liquidated positions
Field
Type
Description
coin
string
Coin/trading pair
szi
string
Signed position size
Field
Type
Description
token
string
Token symbol
amount
string
Genesis allocation amount
Field
Type
Description
vault
bytes
Vault address
usdc
string
Distribution amount in USDC
Field
Type
Description
token
string
Token symbol
amount
string
Borrow/lend amount
interest_amount
string
Interest amount
operation
string
Operation type (borrow/repay/lend/withdraw)
Field
Type
Description
vault
bytes
New vault address
usdc
string
Initial USDC deposit
fee
string
Creation fee
Fills represent trade executions on Hypercore.
message Fill {
bytes user = 1 ;
string coin = 2 ;
string price = 3 ;
string size = 4 ;
FillSide side = 5 ;
google.protobuf.Timestamp time = 6 ;
string start_position = 7 ;
TradingDirection direction = 8 ;
string closed_pnl = 9 ;
bytes hash = 10 ;
uint64 order_id = 11 ;
bool crossed = 12 ;
string fee = 13 ;
uint64 transaction_id = 14 ;
string fee_token = 15 ;
uint64 twap_id = 16 ;
bytes client_order_id = 17 ;
FillLiquidation liquidation = 18 ;
}
Field
Type
Description
user
bytes
User address
coin
string
Trading pair (e.g., "BTC", "ETH")
price
string
Execution price
size
string
Fill size
side
FillSide
ASK or BUY
time
Timestamp
Fill timestamp
start_position
string
Position size before fill
direction
TradingDirection
Trading direction (see below)
closed_pnl
string
Realized PnL from closing position
hash
bytes
Transaction hash
order_id
uint64
Order identifier
crossed
bool
Whether the order crossed the spread
fee
string
Trading fee
transaction_id
uint64
Transaction identifier
fee_token
string
Token used for fee payment
twap_id
uint64
TWAP order identifier (0 if not TWAP)
client_order_id
bytes
Client-specified order ID
liquidation
FillLiquidation
Liquidation details (if applicable)
Value
Description
FILL_SIDE_UNSPECIFIED
Unknown side
FILL_SIDE_ASK
Sell side
FILL_SIDE_BUY
Buy side
Value
Description
TRADING_DIRECTION_UNSPECIFIED
Unknown direction
TRADING_DIRECTION_BUY
Spot buy
TRADING_DIRECTION_SELL
Spot sell
TRADING_DIRECTION_OPEN_LONG
Open long position
TRADING_DIRECTION_CLOSE_LONG
Close long position
TRADING_DIRECTION_OPEN_SHORT
Open short position
TRADING_DIRECTION_CLOSE_SHORT
Close short position
TRADING_DIRECTION_LONG_TO_SHORT
Flip from long to short
TRADING_DIRECTION_SHORT_TO_LONG
Flip from short to long
TRADING_DIRECTION_SPOT_DUST_CONVERSION
Dust conversion
TRADING_DIRECTION_LIQUIDATED_CROSS_LONG
Cross long liquidation
TRADING_DIRECTION_LIQUIDATED_CROSS_SHORT
Cross short liquidation
TRADING_DIRECTION_LIQUIDATED_ISOLATED_LONG
Isolated long liquidation
TRADING_DIRECTION_LIQUIDATED_ISOLATED_SHORT
Isolated short liquidation
TRADING_DIRECTION_AUTO_DELEVERAGING
Auto-deleveraging event
TRADING_DIRECTION_SETTLEMENT
Position settlement
TRADING_DIRECTION_NET_CHILD_VAULTS
Net child vault positions
TRADING_DIRECTION_BACKSTOP_BORROW_LIQUIDATION
Backstop borrow liquidation
Present when the fill is part of a liquidation:
Field
Type
Description
liquidated_user
bytes
Address of liquidated user
mark_px
string
Mark price at liquidation
method
string
Liquidation method
The ClickHouse schema is organized in layers:
blocks - Block metadata
TEMPLATE_EVENT - Base template for all event tables
Each event type has its own table inheriting from TEMPLATE_EVENT, with projections for efficient querying by common fields like user, validator, coin, etc.
All event tables share these base fields from TEMPLATE_EVENT:
Field
Type
Description
block_num
UInt64
Block number
block_hash
String
Block hash (hex with 0x prefix)
timestamp
DateTime('UTC')
Block timestamp
minute
UInt32
Relative minute number for partitioning
event_index
UInt32
Event index within the block
event_hash
String
Event/transaction hash (hex with 0x prefix)
event_time
DateTime('UTC')
Event-specific timestamp
Running with Substreams Sink
substreams-sink-sql run \
clickhouse://< connection-string> \
clickhouse/substreams.yaml \
-e < hypercore-endpoint> \
< start-block> :< stop-block>
Apache-2.0