Package Logo
aave_v3_polygon
aave_v3_polygon@v0.1.0
Total Downloads
1
Published
8 hours ago
Network
polygon polygon
Publisher
User Avatar PaulieB14

Readme

AAVE V3 Polygon Substreams

Full-fidelity Substreams indexer for the AAVE V3 lending protocol on Polygon. Covers every on-chain event including all V3-specific features (eMode, isolation mode, supply/borrow caps, portal bridging, multi-reward), aggregates reserve state and user positions into stores, and sinks to both PostgreSQL (operational) and ClickHouse (analytics) via substreams-sink-sql.

Network


What it indexes

Contracts tracked

Contract Address Deploy Block
Pool 0x794a61358D6845594F94dc1DB02A252b5b4814aD 25,825,791
PoolConfigurator 0x8145eddDf43f50276641b55bd3AD95944510021E 25,825,791
RewardsController 0x929EC64c34a17401F460460D4B9390518E5B473e 25,825,791

Events decoded

Pool — Supply · Withdraw · Borrow · Repay (+ useATokens) · LiquidationCall · FlashLoan (+ interestRateMode) · ReserveDataUpdated · SwapBorrowRateMode · ReserveUsedAsCollateralEnabled/Disabled · RebalanceStableBorrowRate · UserEModeSet · IsolationModeTotalDebtUpdated · MintUnbacked · BackUnbacked · MintedToTreasury · Paused / Unpaused

PoolConfigurator — ReserveInitialized · CollateralConfigurationChanged · ReserveBorrowingEnabled/Disabled · ReserveStableRateBorrowingEnabled/Disabled · ReserveActivated/Deactivated · ReserveFrozen/Unfrozen · ReservePaused/Unpaused · ReserveDropped · ReserveFactorChanged · SupplyCapChanged · BorrowCapChanged · LiquidationProtocolFeeChanged · UnbackedMintCapChanged · DebtCeilingChanged · EModeCategoryAdded · EModeCategoryUpdated · ReserveEModeChanged · SiloedBorrowingChanged · BorrowableInIsolationChanged · ReserveFlashLoaningEnabled · InterestRateStrategyChanged

RewardsController — RewardsAccrued (+ reward token) · RewardsClaimed (+ claimer + reward token) · AssetConfigUpdated


Module pipeline

Polygon Block
     │
     ▼
map_aave_events           ← decodes all events from 3 contracts
     │
  ┌──┴─────────────────────────────────────────────────┐
  │        │          │         │      │      │     │   │
  ▼        ▼          ▼         ▼      ▼      ▼     ▼   ▼
store_   store_     store_   store_  store_  store_ store_
reserve_ reserve_   user_    protocol user_  isol_  emode_
state    lifetime   collat-  _stats   emode  debt   categories
(proto)  _totals    eral     (bigint) (str)  (str)  (str)
         (bigint)   (string)
  │        │          │         │      │      │
  └────────┴──────────┴─────────┴──────┴──────┘
                      │ (all store deltas)
                      ▼
                    db_out ──► PostgreSQL  (30+ tables + 8 views)
                               ClickHouse  (30+ tables + 10 MVs + 6 query views)

Stores (8 total)

Store Policy Purpose
store_reserve_state set (proto) Full V3 reserve state including caps, eMode, flags
store_reserve_lifetime_totals add (bigint) Cumulative supply/borrow/flash/portal/treasury totals
store_user_collateral set (string) Current collateral flag per user per reserve
store_protocol_stats add (bigint) Protocol-wide counters
store_user_emode set (string) V3: current eMode category per user
store_isolation_debt set (string) V3: current isolation debt per reserve
store_emode_categories set (string) V3: current eMode category config

V3 vs V2 Differences

Feature V2 Substreams This V3 Substreams
Core lending events
Reserve configuration history
User collateral flags
Lifetime per-reserve totals
Rate OHLC (hourly)
Flash loan analytics ✅ (+ debt mode)
Liquidation analytics (daily)
Rate swap frequency
ClickHouse analytical sink
eMode (efficiency mode)
Isolation mode debt tracking
Supply / borrow caps
Liquidation protocol fee
Portal bridge (MintUnbacked / BackUnbacked)
Per-reserve pause
Siloed borrowing flag
Borrowable-in-isolation flag
Flash loan enable per reserve
Multi-reward (RewardsController)
Treasury mint tracking
Debt ceiling (isolation mode)
Repay via aTokens
eMode category analytics
Portal daily MV
Reward distribution daily MV

ClickHouse Materialized Views (10 total)

View Purpose
mv_hourly_rates OHLC for liquidity rate, variable + stable borrow rates per reserve
mv_daily_volumes Supply/withdrawal/borrow/repay volumes per reserve per day
mv_daily_flash_loans Flash loan volume, fee revenue, debt-mode count 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)
mv_emode_daily V3: Daily eMode category adoption and unique user counts
mv_isolation_debt_hourly V3: Hourly isolation debt OHLC per reserve
mv_portal_daily V3: Daily unbacked mint/back volumes per reserve
mv_reward_daily V3: Daily reward accruals and claims per reward token

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 ./substreams.yaml map_aave_events

Run the PostgreSQL sink

# Start local databases
docker compose up -d

PG_DSN="psql://aave:aave_dev@localhost:5432/aave?sslmode=disable"

# Build and sink
substreams build
substreams-sink-sql setup "$PG_DSN" ./aave_v3_polygon-v0.1.0.spkg
substreams-sink-sql run  "$PG_DSN" ./aave_v3_polygon-v0.1.0.spkg

Run the ClickHouse sink

substreams build substreams-clickhouse.yaml

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

Build from source

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

PostgreSQL tables (30+)

Core lending

Table Description
aave_supplies All Supply events (V3 rename of Deposit)
aave_withdrawals All Withdraw events
aave_borrows All Borrow events
aave_repays All Repay events (includes use_a_tokens flag)
aave_liquidations All LiquidationCall events
aave_flash_loans All FlashLoan events (includes interest_rate_mode)
aave_rate_swaps Stable↔variable rate mode swaps
aave_rebalances Stable borrow rate rebalances
aave_reserve_rate_history Full rate history (every ReserveDataUpdated)

V3-only events

Table Description
aave_user_emode History of user eMode category changes
aave_user_emode_current Current eMode category per user (upserted)
aave_isolation_debt History of isolation mode debt updates
aave_isolation_debt_current Current isolation debt per reserve (upserted)
aave_mint_unbacked Portal bridge mint events
aave_back_unbacked Portal bridge back events
aave_treasury_mints Accrued interest minted to treasury
aave_emode_categories eMode category add/update history
aave_emode_categories_current Current eMode category config (upserted)
aave_reserve_emode_history Reserve eMode category assignment changes
aave_supply_cap_history Supply cap change history
aave_borrow_cap_history Borrow cap change history
aave_debt_ceiling_history Isolation mode debt ceiling change history

Rewards (multi-reward)

Table Description
aave_rewards_accrued wMATIC/multi-reward accruals (includes reward token)
aave_rewards_claimed Reward claims (includes reward token and claimer)
aave_reward_configs Emission config updates per (asset, reward) pair

Current state (upserted)

Table Description
aave_reserves Current reserve state (V3 extended with caps, eMode, flags)
aave_reserve_totals Lifetime cumulative totals per reserve (V3 extended)
aave_user_collateral Current collateral flag per user per reserve

Views

View Description
v_reserve_net_flows Net supply/borrow flows and portal activity per reserve
v_reserve_rates_pct Latest rates as percentages with all V3 config fields
v_flash_loan_leaderboard Top initiators by volume
v_liquidation_leaderboard Top liquidators by count
v_emode_usage Active users per eMode category with config
v_portal_summary Unbacked outstanding vs backed per reserve
v_isolation_utilisation Isolation debt vs ceiling per reserve

License

Apache 2.0

Documentation

Modules

Maps icon
Maps

map
map_aave_events

3aa862408a3a0b23b8a0704920695ba10f0dc752
map map_aave_events (
blocksf.ethereum.type.v2.Block
)  -> aave.v1.AaveEvents

Scans every Polygon block for events emitted by the AAVE V3 Pool, PoolConfigurator, and RewardsController contracts. Outputs a strongly-typed AaveEvents message including all V3-specific events: eMode, isolation mode, portal, supply/borrow caps, and multi-reward RewardsController events.

substreams gui aave-v3-polygon@v0.1.0 map_aave_events

map
db_out

6018f48c915e7654194df67288ab7a896af8778a

Combines raw AAVE V3 events with store deltas to produce a stream of DatabaseChanges for the substreams-sink-sql PostgreSQL sink. Tables: aave_supplies, aave_withdrawals, aave_borrows, aave_repays, aave_liquidations, aave_flash_loans, aave_rate_swaps, aave_rebalances, aave_reserve_rate_history, aave_mint_unbacked, aave_back_unbacked, aave_treasury_mints, aave_user_emode, aave_user_emode_current, aave_isolation_debt, aave_isolation_debt_current, aave_emode_categories, aave_emode_categories_current, aave_reserve_emode_history, aave_supply_cap_history, aave_borrow_cap_history, aave_debt_ceiling_history, aave_rewards_accrued, aave_rewards_claimed, aave_reward_configs, aave_reserves (state), aave_reserve_totals, aave_user_collateral.

substreams gui aave-v3-polygon@v0.1.0 db_out
Stores icon
Stores

store
store_reserve_state

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

Tracks the latest configuration and rate data for each reserve. Extended for V3: supply_cap, borrow_cap, liquidation_protocol_fee, unbacked_mint_cap, debt_ceiling, emode_category, siloed_borrowing, borrowable_in_isolation, flash_loan_enabled, is_paused, is_dropped. Key: "reserve:{address}".

substreams gui aave-v3-polygon@v0.1.0 store_reserve_state

store
store_reserve_lifetime_totals

9253b96e669ed4228e9fdb97d6063f7348222a00
store <add,bigint> store_reserve_lifetime_totals (
)

Lifetime cumulative totals per reserve. Extended for V3: unbacked_minted, unbacked_backed, back_unbacked_fees, treasury_minted, atoken_repay_count. Key: "{reserve}:{metric}".

substreams gui aave-v3-polygon@v0.1.0 store_reserve_lifetime_totals

store
store_user_collateral

ddc0cec534e794d1c6d6c2d629afa91bd7f47365
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-v3-polygon@v0.1.0 store_user_collateral

store
store_protocol_stats

ba75d0cf0472514afa523038d5aed8fa91535a0f
store <add,bigint> store_protocol_stats (
)

Protocol-wide rolling action counters and per-user event counts. Extended for V3: emode_sets, mint_unbacked, back_unbacked, treasury_mints. Keys: "total:{action}", "user:{addr}:{action}_count", "liquidator:{addr}:count".

substreams gui aave-v3-polygon@v0.1.0 store_protocol_stats

store
store_user_emode

416d414075824a1c52ad7e9beccae423d0b9f5a8
store <set,string> store_user_emode (
)

NEW in V3: Tracks the current eMode efficiency category per user. Value: "{category_id}:{block}:{timestamp}". Key: "{user}".

substreams gui aave-v3-polygon@v0.1.0 store_user_emode

store
store_isolation_debt

ed253bab025697706e094e1595454f0d80c4c679
store <set,string> store_isolation_debt (
)

NEW in V3: Tracks the current isolation mode total debt per reserve. Value: "{total_debt}:{block}:{timestamp}". Key: "{asset}".

substreams gui aave-v3-polygon@v0.1.0 store_isolation_debt

store
store_emode_categories

c51777a1ac4328c57d3a8403bdac88efa89d1d1e
store <set,string> store_emode_categories (
)

NEW in V3: Tracks the current eMode category configuration. Value: "{ltv}|{liq_threshold}|{liq_bonus}|{oracle}|{label}|{block}". Key: "{category_id}".

substreams gui aave-v3-polygon@v0.1.0 store_emode_categories
Protobuf

Protobuf Docs Explorer

aave.v1