
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.
| Contract | Address | Deploy Block |
|---|---|---|
| LendingPool | 0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf |
12,687,245 |
| LendingPoolConfigurator | 0x26db2B833021583566323E3b8985999981b9F1F3 |
12,687,253 |
| IncentivesController | 0x357D51124f59836DeD84c8a1730D72B749d8BC23 |
12,486,774 |
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
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)
| 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 |
| 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) |
| 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 | ❌ | ✅ |
brew install streamingfast/tap/substreams
brew install streamingfast/tap/substreams-sink-sql
substreams auth # authenticate with The Graph Market
substreams gui aave-v2-polygon@v0.1.0
# 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
# 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
git clone https://github.com/PaulieB14/aave-v2-polygon
cd aave-v2-polygon
substreams build
| 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.
Apache 2.0
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_eventsCombines 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_outTracks 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_stateLifetime 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_totalsTracks 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_collateralProtocol-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