All packages

kamino-finance-events

PaulieB14
v2.0.1/0 downloads

Package ref

kamino-finance-events@v2.0.1

Run package

CLI

Run db_out from the command line.

substreams run kamino-finance-events@v2.0.1 db_out -e solana --start-block -1
Authenticate by running substreams auth or directly on thegraph.market (see docs).

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

ModuleTypeDescription
map_kamino_eventsMapExtracts and decodes all Kamino instructions using real Anchor discriminators
store_reservesStoreTracks reserve metadata (mints, markets) by reserve address
store_user_positionsStoreTracks user deposit/borrow positions per reserve
db_outMap (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

ProgramIDEvents
klend (Lending)KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjDdeposit, withdraw, borrow, repay, liquidate, flash_borrow, flash_repay, deposit_and_collateralize, withdraw_and_redeem
LiquidityE35i5qn7872eEmBt15e5VGhziUBzCTm43XCSWvDoQNNvdeposit, withdraw, invest, divest, rebalance, swap
kVaultkvauTFR3qESFtbxNsJnCU5yCCGPKGastMCHSsXzkvbadeposit, withdraw, invest, divest
kFarmsFarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hrinit_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

Modules

Execution graph

4 modules
mapMain

db_out

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

from #300000000

Output

sf.substreams.sink.database.v1.DatabaseChanges

map

map_kamino_events

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.

from #300000000
store

store_reserves

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

from #300000000

Update policy

set