harb/subgraph/base_sepolia/CLAUDE.md
2025-07-24 16:08:17 +02:00

2.2 KiB

Subgraph - CLAUDE.md

The Graph Protocol subgraph for indexing KRAIKEN protocol events and state.

Overview

This subgraph indexes:

  • Token transfers and supply changes
  • Staking positions and Harberger tax events
  • Liquidity manager recentering events
  • User statistics and protocol metrics

Schema Design

Core Entities

Stats - Global protocol statistics

  • Token supplies (KRAIKEN and STAKE)
  • Minting/burning metrics with hourly projections
  • Tax collection statistics
  • Staking percentages and average rates

Position - Individual staking positions

  • Holder address and staked amount
  • Self-assessed tax rate
  • Last update timestamp

Snatch - Harberger tax position takeover events

  • Old and new holder details
  • Tax rate changes
  • Transaction metadata

User - Aggregated user statistics

  • Total taxes paid/received
  • Staking history
  • Minting/burning activity

Development Commands

# Install dependencies
npm install

# Generate AssemblyScript types from schema
npm run codegen

# Build the subgraph
npm run build

# Deploy to The Graph Studio
npm run deploy

# Local development (requires graph-node)
npm run create-local
npm run deploy-local

Event Handlers

Kraiken Contract Events

  • Transfer - Track token movements and supply changes
  • TaxPaid - Record tax collection events
  • Mint/Burn - Update supply statistics

Stake Contract Events

  • Staked - Create/update position entities
  • Snatched - Record position takeovers
  • TaxRateChanged - Update position tax rates

Query Examples

# Get current protocol statistics
query GetStats {
  stats(id: "0x00") {
    kraikenTotalSupply
    percentageStaked
    averageTaxRate
    mintedLastDay
  }
}

# Get top staking positions
query TopStakers {
  positions(first: 10, orderBy: amount, orderDirection: desc) {
    holder
    amount
    rate
  }
}

Deployment Notes

  • Network: Base Sepolia (testnet)
  • Start Block: Configured in subgraph.yaml
  • API Endpoint: Available after deployment to Studio

Code Quality

  • All handlers must be idempotent
  • Use BigInt for all numeric values
  • Handle null cases explicitly
  • Keep entity updates minimal for performance