chaincodec-registry
Schema registry for ChainCodec — CSDL parser, in-memory store, and fingerprint-based lookup.
chaincodec-registry manages blockchain event schemas in the CSDL (Chain Schema Definition Language) format and provides fast O(1) fingerprint-based lookup. Load a directory of schemas once at startup, then resolve any eth_getLogs topic0 to a full schema instantly.
Features
- CSDL parser — parse human-readable YAML schema definitions (single or multi-doc)
- In-memory registry — thread-safe
MemoryRegistryindexed by fingerprint and name - Directory loading — load an entire folder of
.csdlfiles in one call - Fingerprint lookup — O(1) schema resolution from topic0 hash during live decoding
- Version management — schemas carry a
versionfield; multiple versions coexist safely - 50+ bundled schemas — ERC-20/721/1155, Uniswap, Aave, Compound, ChainLink, and more
Installation
[]
= "0.1"
= "0.1"
CSDL schema format
CSDL (Chain Schema Definition Language) is a concise YAML format:
schema ERC20Transfer:
version: 1
chains:
event: Transfer
fingerprint: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
fields:
from:
to:
value:
meta:
standard: ERC-20
description: "ERC-20 token transfer"
One file can hold multiple schemas separated by ---:
schema ERC20Transfer:
# ...
---
schema ERC20Approval:
version: 1
event: Approval
fingerprint: "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"
fields:
owner:
spender:
value:
Supported field types
| CSDL type | Solidity type | NormalizedValue variant |
|---|---|---|
address |
address |
Address(String) |
uint256 |
uint256 |
Uint256(u128) |
uint128 |
uint128 |
Uint256(u128) |
int256 |
int256 |
Int256(i128) |
bool |
bool |
Bool(bool) |
bytes32 |
bytes32 |
Bytes(Vec<u8>) |
bytes |
bytes |
BytesDynamic(Vec<u8>) |
string |
string |
String(String) |
address[] |
address[] |
Array(Vec<NormalizedValue>) |
tuple |
struct | Tuple(Vec<NormalizedValue>) |
Quick start
use ;
use SchemaRegistry;
// Option A: parse from a YAML string
let schemas = parse_all?;
println!;
// Option B: load a single file
let mut registry = new;
registry.load_file?;
// Option C: load all .csdl files in a directory (recursive)
registry.load_directory?;
println!;
Looking up schemas
// By fingerprint — used during live log decoding (O(1))
let fp = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
if let Some = registry.get_by_fingerprint
// By name
if let Some = registry.get_by_name
// Iterate all schemas
for schema in registry.all_schemas
Registering schemas programmatically
use ;
use IndexMap;
let mut fields = new;
fields.insert;
fields.insert;
fields.insert;
let schema = Schema ;
registry.register?;
Bundled schemas (50+)
Load all schemas from the chaincodec/schemas/ directory:
registry.load_directory?;
| Category | Schemas |
|---|---|
| Token standards | ERC-20, ERC-721, ERC-1155, ERC-4337, WETH |
| DEXes | Uniswap V2, Uniswap V3, Curve, Balancer, SushiSwap, DODO |
| Lending | Aave V2, Aave V3, Compound V2, Compound V3, MakerDAO |
| Oracles | ChainLink Aggregator, ChainLink VRF, ChainLink CCIP |
| Liquid staking | Lido, Rocket Pool, Stader, Frax |
| Yield | Yearn, Convex, Synthetix V3 |
| Derivatives | GMX V1, dYdX V4, Perpetual Protocol |
| Bridges | Wormhole, LayerZero V2, Hop, Celer |
| Other | ENS, Safe Multisig, CryptoPunks, BAYC, Bancor V3 |
Ecosystem
| Crate | Purpose |
|---|---|
| chaincodec-core | Traits, types, primitives |
| chaincodec-evm | EVM ABI event & call decoder |
| chaincodec-registry | CSDL schema registry (this crate) |
| chaincodec-batch | Rayon parallel batch decode |
| chaincodec-stream | Live WebSocket event streaming |
License
MIT — see LICENSE