Package Logo
aave_v2_polygon
aave_v2_polygon@v0.1.2
Total Downloads
3
Published
8 hours ago
Network
polygon polygon
Publisher
User Avatar PaulieB14

Readme

AAVE V2 Polygon Substreams

Full-fidelity Substreams indexer for the AAVE V2 lending protocol on Polygon. Covers every on-chain event, aggregates reserve state and user positions into stores, and sinks to both PostgreSQL (operational) and ClickHouse (analytics) via substreams-sink-sql.

substreams.dev Network


What it indexes

Contracts tracked (verified via Etherscan API v2)

Contract Address Deploy Block
LendingPool 0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf 12,687,245
LendingPoolConfigurator 0x26db2B833021583566323E3b8985999981b9F1F3 12,687,253
IncentivesController 0x357D51124f59836DeD84c8a1730D72B749d8BC23 12,486,774

Events decoded

LendingPool — Deposit · Withdraw · Borrow · Repay · LiquidationCall · FlashLoan · ReserveDataUpdated · Swap (rate-mode) · ReserveUsedAsCollateralEnabled/Disabled · RebalanceStableBorrowRate · Paused / Unpaused

LendingPoolConfigurator — ReserveInitialized · CollateralConfigurationChanged · BorrowingEnabled/Disabled · ReserveActivated/Deactivated · ReserveFrozen/Unfrozen · ReserveFactorChanged

IncentivesController — RewardsAccrued · RewardsClaimed


Module pipeline

Polygon Block
     │
     ▼
map_aave_events           ← decodes all events from 3 contracts
     │
  ┌──┴──────────────────────────┐
  │        │          │         │
  ▼        ▼          ▼         ▼
store_   store_     store_   store_
reserve_ reserve_   user_    protocol_
state    lifetime   collat-  stats
(proto)  _totals    eral
         (bigint)   (string) (bigint)
  │        │          │
  └────────┴──────────┘
           │ (store deltas)
           ▼
         db_out ──► PostgreSQL  (14 normalized tables + 4 views)
                    ClickHouse  (14 tables + 6 materialized views)

Stores

Store Policy Keys
store_reserve_state set (proto) reserve:{address}
store_reserve_lifetime_totals add (bigint) {reserve}:{metric}
store_user_collateral set (string) {user}:{reserve}
store_protocol_stats add (bigint) total:{action}, user:{addr}:{action}_count

ClickHouse Materialized Views

View Purpose
mv_hourly_rates OHLC for liquidity rate, variable + stable borrow rates per reserve
mv_daily_volumes Deposit / withdrawal / borrow / repay volumes per reserve per day
mv_daily_flash_loans Flash loan volume, fee revenue, unique initiators per day
mv_daily_liquidations Collateral seized, debt covered, liquidator activity per day
mv_user_borrow_modes Stable vs variable preference per user per reserve
mv_rate_swap_daily Daily stable ↔ variable swap frequency (market stress signal)

What this adds beyond the AAVE V2 subgraph

Feature Subgraph This Substreams
All lending events
Reserve configuration history
User collateral flags
Lifetime per-reserve totals
Incentives tracking
Rate OHLC (hourly)
Flash loan analytics
Liquidation analytics (daily)
Rate swap frequency tracking
ClickHouse analytical sink
No indexer availability issues
Sub-second historical backfill

Quick start

Prerequisites

brew install streamingfast/tap/substreams
brew install streamingfast/tap/substreams-sink-sql
substreams auth   # authenticate with The Graph Market

Stream live data

substreams gui aave-v2-polygon@v0.1.0

Run the PostgreSQL sink

# Start local databases
docker compose up -d

# Apply schema and start syncing
PG_DSN="psql://aave:aave_dev@localhost:5432/aave?sslmode=disable"
substreams-sink-sql setup "$PG_DSN" ./aave-v2-polygon-v0.1.0.spkg
substreams-sink-sql run  "$PG_DSN" ./aave-v2-polygon-v0.1.0.spkg

Run the ClickHouse sink

# Build the clickhouse spkg
substreams build substreams-clickhouse.yaml

CH_DSN="clickhouse://aave:aave_dev@localhost:9000/aave"
substreams-sink-sql setup "$CH_DSN" ./aave_v2_polygon_clickhouse-v0.1.0.spkg
substreams-sink-sql run  "$CH_DSN" ./aave_v2_polygon_clickhouse-v0.1.0.spkg

Build from source

git clone https://github.com/PaulieB14/aave-v2-polygon
cd aave-v2-polygon
substreams build

PostgreSQL tables

Table Description
aave_deposits All deposit events
aave_withdrawals All withdrawal events
aave_borrows All borrow events (stable + variable)
aave_repays All repay events
aave_liquidations All liquidation events
aave_flash_loans All flash loan events
aave_rate_swaps Stable ↔ variable rate mode swaps
aave_rebalances Stable borrow rate rebalances
aave_reserve_rate_history Full rate history (every ReserveDataUpdated)
aave_incentives_accrued wMATIC reward accruals
aave_incentives_claimed wMATIC reward claims
aave_reserves Current reserve state (upserted)
aave_reserve_totals Lifetime cumulative totals per reserve
aave_user_collateral Current collateral flag per user per reserve

Plus convenience views: v_reserve_net_flows, v_reserve_rates_pct, v_flash_loan_leaderboard, v_liquidation_leaderboard.


License

Apache 2.0

Documentation

Modules

Maps icon
Maps

map
map_aave_events

844b5bcbd2d7250a8441b703fbaaf910fcb371c6
map map_aave_events (
blocksf.ethereum.type.v2.Block
)  -> aave.v1.AaveEvents

Scans every Polygon block for events emitted by the AAVE V2 LendingPool, LendingPoolConfigurator, and IncentivesController contracts. Outputs a strongly-typed AaveEvents message.

substreams gui aave-v2-polygon@v0.1.2 map_aave_events

map
db_out

7b4c03c7f65bf9685dac961a449bfbec55604167

Combines raw AAVE events with store deltas to produce a stream of DatabaseChanges for the substreams-sink-sql PostgreSQL sink. Tables: aave_deposits, aave_withdrawals, aave_borrows, aave_repays, aave_liquidations, aave_flash_loans, aave_rate_swaps, aave_rebalances, aave_reserve_rate_history, aave_reserves (state), aave_reserve_totals, aave_user_collateral, aave_incentives_accrued, aave_incentives_claimed.

substreams gui aave-v2-polygon@v0.1.2 db_out
Stores icon
Stores

store
store_reserve_state

c2bb4d609aacd77760c6d5b6086220f07926b3a6
store <set,aave.v1.ReserveState> store_reserve_state (
)

Tracks the latest configuration and rate data for each reserve. Updated by ReserveDataUpdated, ReserveInitialized, CollateralConfigurationChanged, ReserveFactor/Borrowing/Active/Frozen events. Key: "reserve:{address}".

substreams gui aave-v2-polygon@v0.1.2 store_reserve_state

store
store_reserve_lifetime_totals

0a774485ec3c33dad192fff1ed97e5c3db72129b
store <add,bigint> store_reserve_lifetime_totals (
)

Lifetime cumulative totals per reserve for deposits, withdrawals, borrows, repays, liquidations, and flash-loans (raw token amounts). Key: "{reserve}:{metric}" — e.g. "0xabc...:deposits".

substreams gui aave-v2-polygon@v0.1.2 store_reserve_lifetime_totals

store
store_user_collateral

80165b57b039e2e49b86bf683f157922afd27fec
store <set,string> store_user_collateral (
)

Tracks which reserves each user has enabled as collateral. Value: "{enabled}:{block}:{timestamp}". Key: "{user}:{reserve}".

substreams gui aave-v2-polygon@v0.1.2 store_user_collateral

store
store_protocol_stats

b7856b61a86c331e8a70d46f5466cd3756297015
store <add,bigint> store_protocol_stats (
)

Protocol-wide rolling action counters and per-user event counts. Keys: "total:{action}", "user:{addr}:{action}_count", "liquidator:{addr}:count".

substreams gui aave-v2-polygon@v0.1.2 store_protocol_stats
Protobuf

Protobuf Docs Explorer

aave.v1