Package Logo
cypher_protocol
cypher_protocol@v0.0.4
Total Downloads
3
Published
19 hours ago
Publisher
User Avatar rixhy-cyd

Readme

Cypher Protocol Substreams

A comprehensive Substreams package for monitoring and processing Cypher Protocol events and calls on Ethereum networks. This project provides foundational modules for extracting, filtering, and processing blockchain data with a specific focus on the Cypher Protocol ecosystem.

Overview

This Substreams package is designed to monitor and process events from the Cypher Protocol smart contracts, including:

  • VotingEscrow: NFT-based voting power system
  • Election: Voting and bribe management
  • CypherToken: ERC-20 governance token
  • RewardDistributor: Merkle tree-based reward distribution
  • DistributionModule: Token emission management
  • Airdrop: Merkle tree-based airdrop distribution

Features

Core Functionality

  • Event Processing: Extract and decode all Ethereum events from successful transactions
  • Call Processing: Monitor all contract calls including internal calls
  • Advanced Filtering: Filter events and calls using complex expressions with logical operators
  • Transfer Tracking: Monitor both ERC-20 and ERC-721 transfer events
  • Contract-Specific Processing: Specialized event decoding for Cypher Protocol contracts
  • Dynamic Configuration: Configurable contract addresses without code changes

Key Modules

Basic Event and Call Processing

  • all_events: Extracts all events from successful transactions
  • all_calls: Extracts all calls including internal calls
  • index_events: Creates searchable indexes for events
  • index_calls: Creates searchable indexes for calls
  • index_events_and_calls: Combined indexing for both events and calls

Advanced Filtering

  • filtered_events: Filter events by address and signature
  • filtered_calls: Filter calls by contract, caller, and method
  • filtered_transactions: Filter complete transactions
  • filtered_events_and_calls: Combined filtering of events and calls

Cypher Protocol Specific

  • filter_cypher_events: Enhanced processor with configurable contract addresses

Installation and Setup

Prerequisites

  • Rust toolchain (latest stable)
  • Substreams CLI
  • WASM target: rustup target add wasm32-unknown-unknown

Building

# Build the WASM module
cargo build --target wasm32-unknown-unknown --release

# The compiled module will be available at:
# target/wasm32-unknown-unknown/release/cypher_protocol.wasm

Configuration

The package uses configurable contract addresses that can be set via parameters:

# Example parameter format for filter_cypher_events:
"query_string|contract_addresses_string"

# Where contract_addresses_string is:
"voting_escrow:0xaddr1,election:0xaddr2,cypher_token:0xaddr3,reward_distributor:0xaddr4,distribution_module:0xaddr5,airdrop:0xaddr6"

Usage Examples

Basic Event Filtering

# Filter events by address and signature
substreams run substreams.yaml filtered_events \
  --param='(evt_addr:0x1234... || evt_addr:0x5678...) && evt_sig:0xdeadbeef...'

Call Filtering

# Filter calls by contract and method
substreams run substreams.yaml filtered_calls \
  --param='call_method:0xa9059cbb && call_to:0xdac17f958d2ee523a2206206994597c13d831ec7'

Cypher Protocol Events

# Process Cypher Protocol events with configurable addresses
substreams run substreams.yaml filter_cypher_events \
  --param='(call_to:0x3cb7367ac1e6a439da1f1717f8055f02e3c9d56e || call_to:0xcccd218a58b53c67fc17d8c87cb90d83614e35fd)|voting_escrow:0xf65e1e90269373a60b2abdaf2dc52b2a5a8fdb5c,election:0x0c132c3841b9cdbb3a305275ee02d571a551ce70,cypher_token:0xd36f05bc341b3286c1fd15a809d3315741796f26,reward_distributor:0x7f91980325a294b2affaac6f26e1644864160d41,distribution_module:0x636bdc02170e04c917204f858fa110ce9a5bf05f,airdrop:0xfcbebe31e067a8c460563bcb1d7458fae1949f29'

Supported Event Types

VotingEscrow Events

  • CreateLock: User creates new lock position
  • DepositFor: Add tokens to existing lock
  • Withdraw: Withdraw expired lock
  • IncreaseUnlockTime: Extend lock duration
  • LockIndefinite: Convert to indefinite lock
  • UnlockIndefinite: Convert back to timed lock
  • Merge: Merge two lock positions
  • Transfer: NFT Transfer (ERC-721)
  • Approval: NFT Approval (ERC-721)

Election Events

  • Vote: User votes for candidate
  • BribeClaimed: User claims bribe reward
  • BribeAdded: Bribe added for candidate
  • CandidateEnabled: Candidate enabled for voting
  • CandidateDisabled: Candidate disabled
  • BribeTokenEnabled: Token approved for bribes
  • BribeTokenDisabled: Token disabled for bribes

CypherToken Events (ERC-20)

  • Transfer: ERC-20 Transfer
  • Approval: ERC-20 Approval

RewardDistributor Events

  • RootAdded: New merkle root added
  • Claimed: User claimed reward

DistributionModule Events

  • TokensEmitted: Tokens emitted to recipient
  • EmissionAddressUpdated: Emission address changed

Airdrop Events

  • CypherTokenClaimed: CypherToken claimed
  • VeCypherNftClaimed: VeCypherNft claimed

Query Language

The package supports a powerful query language for filtering events and calls:

Operators

  • ||: Logical OR
  • &&: Logical AND
  • (): Parentheses for grouping

Event Filters

  • evt_addr:0x...: Filter by event contract address
  • evt_sig:0x...: Filter by event signature

Call Filters

  • call_to:0x...: Filter by called contract address
  • call_from:0x...: Filter by caller address
  • call_method:0x...: Filter by method signature (4 bytes)

Example Queries

# Complex event filtering
'(evt_addr:0x1234... || evt_addr:0x5678...) && evt_sig:0xdeadbeef...'

# Combined event and call filtering
'evt_sig:0x9bb8f83800000000000000000000000000000000000000000000000000000000 || (call_method:0xa9059cbb && call_to:0xdac17f958d2ee523a2206206994597c13d831ec7)'

Output Formats

ProcessedEvents

The filter_cypher_events module outputs structured data:

message ProcessedEvents {
  repeated TransferEvent transfer_events = 1;
  repeated ContractEvent contract_events = 2;
  Clock clock = 3;
}

message TransferEvent {
  string from = 1;
  string to = 2;
  string value = 3;
  string token_id = 4;
  string hash = 5;
  uint64 block_number = 6;
  uint64 timestamp = 7;
}

message ContractEvent {
  string contract_name = 1;
  string event_name = 2;
  map<string, string> event_data = 3;
  uint64 block_number = 4;
  string transaction_hash = 5;
  uint64 timestamp = 6;
  string contract_address = 7;
}

Error Handling and Logging

The package includes comprehensive error handling and logging:

  • Verbose Comments: All functions include detailed documentation
  • Standard Logging: Uses Substreams logging framework
  • Error Handling: Graceful handling of malformed data
  • Debug Information: Extensive debug logging for troubleshooting

Development

Project Structure

src/
├── calls.rs          # Call processing modules
├── events.rs         # Event processing modules
├── combined.rs       # Combined processing and Cypher Protocol specific logic
├── lib.rs           # Module exports and initialization
└── pb/              # Generated protobuf bindings

Testing

# Run unit tests
cargo test

# Run with verbose output
cargo test -- --nocapture

Adding New Event Types

To add support for new event types:

  1. Add event signature constants in combined.rs
  2. Add event processing logic in extract_event_data()
  3. Create specific extractor functions for the new event
  4. Update the event matching logic in process_contract_event()

Dependencies

  • substreams: Core Substreams framework
  • substreams-ethereum: Ethereum-specific functionality
  • num-bigint: Big integer arithmetic for token amounts
  • hex: Hexadecimal encoding/decoding
  • ethabi: Ethereum ABI parsing
  • anyhow: Error handling

License

This project is part of the Substreams foundational modules ecosystem.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with comprehensive logging and error handling
  4. Add tests for new functionality
  5. Submit a pull request

Support

For issues and questions:

  • Check the Substreams documentation
  • Review the extensive logging output for debugging
  • Ensure contract addresses are correctly configured
  • Verify event signatures match your contract ABIs

Documentation

Modules

Maps icon
Maps

map
all_events

215cceeca329f0a6944cd3b94149073657a0b302
map all_events (
blocksf.ethereum.type.v2.Block
)  -> 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 cypher-protocol@v0.0.4 all_events

map
all_calls

df3c2bd57fc83b2f8f1e6fe2515b850aed02056c

all_calls gives you all the calls in a block (including internal calls), with basic block hash/number/timestamp and transaction hash

substreams gui cypher-protocol@v0.0.4 all_calls

map
filtered_events

ddb7fc60d95c1a464789e27f40dcc398e78b47ce
Default param : (evt_addr:0x0c132c3841b9cdbb3a305275ee02d571a551ce70 && evt_sig:0xaf4a25d952f154adc41b6013f71acb2e54da6640f14719f9df338a44e8386b9d) || (evt_addr:0xfcbebe31e067a8c460563bcb1d7458fae1949f29 && (evt_sig:0x31669547984da566846915fb762cb166f2eebdde20f7e2c18661a66dccb73ccd || evt_sig:0x2d1204e07079b0def044ad7317b04cbf907b52294259c8d33dd592a9ccce2bd9))

filtered_events reads from all_events and applies a filter on the event addresses and signatures. Supported operators are: logical or ||, logical and && and parenthesis: () Addresses to match must be written as 0x-prefixed hexadecimal, lowercase, prefixed by evt_addr: and signatures by evt_sig:. Example: (evt_addr:0x1234... || evt_addr:0x5678...) && evt_sig:0xdeadbeef...

substreams gui cypher-protocol@v0.0.4 filtered_events

map
filtered_calls

adbeddb2fd51396d2745548f2c89a552a86b28dd
Default param : call_method:0xa9059cbb && call_to:0xdac17f958d2ee523a2206206994597c13d831ec7

filtered_calls reads from all_calls and applies a filter on the called contract, the caller and the method 4-bytes signature Supported operators are: logical or ||, logical and && and parenthesis: () Addresses to match must be written as 0x-prefixed hexadecimal, lowercase, prefixed by call_to: or call_from:, methods by call_method:. Example: (call_to:0x1234... || call_from:0x1234...) && call_method:0xdeadbeef...

substreams gui cypher-protocol@v0.0.4 filtered_calls

map
filtered_transactions

ea8bf52754fa8945567138c95980d91bfce4cc9e
map filtered_transactions (
paramsstring
)  -> sf.substreams.ethereum.v1.Transactions
Default param : evt_sig:0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31 || (call_method:0xa9059cbb && call_to:0xdac17f958d2ee523a2206206994597c13d831ec7)

filtered_transactions reads from ethereum blocks and applies a filter on the events (addresses and signatures) as well as calls (from, to and method). Supported operators are: logical or ||, logical and && and parenthesis: () Addresses and signatures to match must be written as 0x-prefixed hexadecimal, lowercase, prefixed by evt_addr:, evt_sig:, call_to:, call_from: or call_method:. Example: ((evt_addr:0x1234... || evt_addr:0x5678...) && evt_sig:0xdeadbeef...) || call_to:0x01010101...

substreams gui cypher-protocol@v0.0.4 filtered_transactions

map
filtered_events_and_calls

148361fd22cafd2224886d1a9638abf8081935a2
Default param : call_to:0x3cb7367ac1e6a439da1f1717f8055f02e3c9d56e || call_to:0xcccd218a58b53c67fc17d8c87cb90d83614e35fd || evt_sig:0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

filtered_events_and_calls reads from all_calls and all_events, then applies a filter to extract the items that interest you, based on called contract, caller, call method, event address and event signature. Supported operators are: logical or ||, logical and && and parenthesis: () Addresses and signatures to match must be written as 0x-prefixed hexadecimal, lowercase, prefixed by evt_addr:, evt_sig:, call_to:, call_from: or call_method:. Example: evt_sig:0x9bb8f83800000000000000000000000000000000000000000000000000000000 || (call_method:0xa9059cbb && call_to:0xdac17f958d2ee523a2206206994597c13d831ec7)

substreams gui cypher-protocol@v0.0.4 filtered_events_and_calls

map
filter_cypher_events

58b918c07a542ae7e18396f12d6b42497b5cb44d
Default param : (call_to:0x3cb7367ac1e6a439da1f1717f8055f02e3c9d56e || call_to:0xcccd218a58b53c67fc17d8c87cb90d83614e35fd)

filter_cypher_events is an enhanced version that accepts configurable contract addresses. Parameter format: "query_string|contract_addresses_string" Where query_string is the same as unified_events_and_calls_processor And contract_addresses_string is: "voting_escrow:0xaddr1,election:0xaddr2,cypher_token:0xaddr3,reward_distributor:0xaddr4,distribution_module:0xaddr5,airdrop:0xaddr6" This allows dynamic configuration of Cypher Protocol contract addresses without code changes. Processing behavior is identical to unified_events_and_calls_processor but uses configurable addresses.

substreams gui cypher-protocol@v0.0.4 filter_cypher_events
Block Indexes icon
Block Indexes

blockIndex
index_events

040d00a7fc6d77afa47acdf0fe18fa223144ce02

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 cypher-protocol@v0.0.4 index_events

blockIndex
index_calls

66fa1acdcdde1fc83ffff9b6fda67769d42e02aa

index_calls sets the following keys on the block:

  • Call contract call_to:0x0123456789abcdef0123456789abcdef01234567 (contract address in hex, prefixed by 0x)
  • Caller call_from:0x0123456789abcdef0123456789abcdef01234567 (caller address in hex, prefixed by 0x)
  • Call method call_method:0x01234567 (4 bytes of method signature in hex, prefixed by 0x)
substreams gui cypher-protocol@v0.0.4 index_calls

blockIndex
index_events_and_calls

dd7b58432ec302f310b58ada5a508ee6380727d5

index_events_and_calls 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)
  • Call contract call_to:0x0123456789abcdef0123456789abcdef01234567 (contract address in hex, prefixed by 0x)
  • Caller call_from:0x0123456789abcdef0123456789abcdef01234567 (caller address in hex, prefixed by 0x)
  • Call method call_method:0x01234567 (4 bytes of method signature in hex, prefixed by 0x)
substreams gui cypher-protocol@v0.0.4 index_events_and_calls
Protobuf

Protobuf Docs Explorer

sf.ethereum.type.v2
sf.ethereum.substreams.v1
sf.ethereum.transform.v1