Package Logo
kamino-finance-events
kamino-finance-events@v2.0.1
Total Downloads
45
Published
13 hours ago
Publisher
User Avatar PaulieB14

Readme

Kamino Finance Substreams v2.0.0

Comprehensive Substreams package for indexing all Kamino Finance protocol activity on Solana - with stores and SQL sink support.

Architecture

sf.solana.type.v1.Block
        |
        v
+-------------------+
| map_kamino_events  |  Extract ALL Kamino events from 4 programs
+--------+----------+
         |
    +----+----+--------------+
    v         v              v
+--------+ +----------+ +--------------+
|store_  | |store_    | |db_out        |
|reserves| |user_     | |(SQL sink)    |
|        | |positions | |              |
+--------+ +----------+ +--------------+

Modules

Module Type Description
map_kamino_events Map Extracts and decodes all Kamino instructions using real Anchor discriminators
store_reserves Store Tracks reserve metadata (mints, markets) by reserve address
store_user_positions Store Tracks user deposit/borrow positions per reserve
db_out Map (Sink) Outputs DatabaseChanges for PostgreSQL/ClickHouse via substreams-sink-sql

Quick Start

# Stream events (GUI mode)
substreams gui ./substreams.yaml map_kamino_events -s 300000000 -t +100

# Stream events (JSON output)
substreams run ./substreams.yaml map_kamino_events \
  -e mainnet.sol.streamingfast.io:443 \
  -s 300000000 -t +1000 -o jsonl

# Run SQL sink to PostgreSQL
substreams-sink-sql setup "psql://user:pass@localhost:5432/kamino?sslmode=disable" ./kamino-finance-events-v2.0.0.spkg
substreams-sink-sql run "psql://user:pass@localhost:5432/kamino?sslmode=disable" ./kamino-finance-events-v2.0.0.spkg

Monitored Programs

Program ID Events
klend (Lending) KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD deposit, withdraw, borrow, repay, liquidate, flash_borrow, flash_repay, deposit_and_collateralize, withdraw_and_redeem
Liquidity E35i5qn7872eEmBt15e5VGhziUBzCTm43XCSWvDoQNNv deposit, withdraw, invest, divest, rebalance, swap
kVault kvauTFR3qESFtbxNsJnCU5yCCGPKGastMCHSsXzkvba deposit, withdraw, invest, divest
kFarms FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr init_farm, refresh_farms, init_obligation_farms

Key Features

  • Real Anchor discriminators - Uses SHA256-based instruction matching (not hardcoded bytes)
  • Actual decoded amounts - Parses u64 values from instruction data (not placeholders)
  • Inner instruction support - Handles CPI calls for complete event coverage
  • Full account resolution - Resolves all accounts including loaded addresses
  • Store modules - Track reserve metadata and user positions across blocks
  • SQL sink ready - Direct PostgreSQL/ClickHouse integration via db_out

SQL Schema

The db_out module writes to 4 tables:

  • kamino_lend_events - All lending operations with user, reserve, amounts
  • kamino_liquidity_events - Liquidity pool operations
  • kamino_vault_events - Vault deposit/withdraw operations
  • kamino_multiply_events - Farm/multiply operations

See schema.sql for the full schema with indexes.

Building from Source

# Prerequisites: Rust, substreams CLI, buf CLI
rustup target add wasm32-unknown-unknown

# Clone
git clone https://github.com/PaulieB14/Kamino-Substreams.git
cd Kamino-Substreams

# Build
substreams build

# Visualize module graph
substreams graph

# Test with small block range
substreams run ./substreams.yaml map_kamino_events -s 300000000 -t +100

Network

  • Blockchain: Solana Mainnet
  • Initial Block: 300,000,000
  • Package: kamino-finance-events v2.0.0

Changelog

v2.0.0

  • Complete architecture redesign with 4 modules (map, 2 stores, SQL sink)
  • Real Anchor instruction discriminator matching via SHA256
  • Actual u64 amount decoding from instruction data
  • Inner instruction (CPI) parsing for complete coverage
  • store_reserves for tracking reserve metadata
  • store_user_positions for tracking user deposit/borrow positions
  • db_out SQL sink with PostgreSQL schema
  • Updated dependencies (substreams 0.7, substreams-solana 0.14)
  • Proper [lib] crate-type cdylib (was incorrectly [[bin]])
  • Added kVault and kFarms program monitoring
  • Comprehensive SQL schema with indexes

v1.0.1

  • Initial release with single map module

License

MIT

Links

Documentation

Modules

Maps icon
Maps

map
map_kamino_events

f100034c3501ae5c29a9e8627494e69ab9a8753f
map map_kamino_events (
blocksf.solana.type.v1.Block
)  -> kamino.v1.KaminoEvents

Extracts and decodes all Kamino Finance protocol events from Solana blocks.

Monitors 4 Kamino programs using real Anchor instruction discriminators:

  • klend (KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD): Lending operations
  • Liquidity (E35i5qn7872eEmBt15e5VGhziUBzCTm43XCSWvDoQNNv): Liquidity management
  • kVault (kvauTFR3qESFtbxNsJnCU5yCCGPKGastMCHSsXzkvba): Vault strategies
  • kFarms (FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr): Farm rewards

Parses real amounts from instruction data (u64 LE after 8-byte discriminator). Handles both top-level and inner (CPI) instructions.

substreams gui kamino-finance-events@v2.0.1 map_kamino_events

map
db_out

58aae93860f6b8b55959079c84e2ecc69d73dc95

Transforms Kamino events into SQL database changes for PostgreSQL or ClickHouse. Tables: kamino_lend_events, kamino_liquidity_events, kamino_vault_events, kamino_multiply_events

substreams gui kamino-finance-events@v2.0.1 db_out
Stores icon
Stores

store
store_reserves

30ca2fee556d59c08f69915e9bb0c60a5da78771

Tracks Kamino lending reserve metadata by reserve address. Stores lending market association, mint addresses, and cumulative stats.

substreams gui kamino-finance-events@v2.0.1 store_reserves

store
store_user_positions

b86663a15c1004495451d37d528a90298108ce96

Tracks user lending positions (deposits and borrows) per reserve. Key format: {user}:{reserve}

substreams gui kamino-finance-events@v2.0.1 store_user_positions
Protobuf

Protobuf Docs Explorer

kamino.v1
sf.solana.type.v1
sol.instructions.v1
sol.transactions.v1