All packages

aave_v3_polygon

PaulieB14
v0.1.1/29 downloads/Repository

Package ref

aave-v3-polygon@v0.1.1

Run package

CLI

Run db_out from the command line.

substreams run aave-v3-polygon@v0.1.1 db_out -e polygon
Authenticate by running substreams auth or directly on thegraph.market (see docs).

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

ContractAddressDeploy Block
Pool0x794a61358D6845594F94dc1DB02A252b5b4814aD25,825,791
PoolConfigurator0x8145eddDf43f50276641b55bd3AD95944510021E25,825,791
RewardsController0x929EC64c34a17401F460460D4B9390518E5B473e25,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)

StorePolicyPurpose
store_reserve_stateset (proto)Full V3 reserve state including caps, eMode, flags
store_reserve_lifetime_totalsadd (bigint)Cumulative supply/borrow/flash/portal/treasury totals
store_user_collateralset (string)Current collateral flag per user per reserve
store_protocol_statsadd (bigint)Protocol-wide counters
store_user_emodeset (string)V3: current eMode category per user
store_isolation_debtset (string)V3: current isolation debt per reserve
store_emode_categoriesset (string)V3: current eMode category config

V3 vs V2 Differences

FeatureV2 SubstreamsThis 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)

ViewPurpose
mv_hourly_ratesOHLC for liquidity rate, variable + stable borrow rates per reserve
mv_daily_volumesSupply/withdrawal/borrow/repay volumes per reserve per day
mv_daily_flash_loansFlash loan volume, fee revenue, debt-mode count per day
mv_daily_liquidationsCollateral seized, debt covered, liquidator activity per day
mv_user_borrow_modesStable vs variable preference per user per reserve
mv_rate_swap_dailyDaily stable↔variable swap frequency (market stress signal)
mv_emode_dailyV3: Daily eMode category adoption and unique user counts
mv_isolation_debt_hourlyV3: Hourly isolation debt OHLC per reserve
mv_portal_dailyV3: Daily unbacked mint/back volumes per reserve
mv_reward_dailyV3: 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.1.spkg
substreams-sink-sql run  "$PG_DSN" ./aave_v3_polygon-v0.1.1.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.1.spkg
substreams-sink-sql run  "$CH_DSN" ./aave_v3_polygon_clickhouse-v0.1.1.spkg

Build from source

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

PostgreSQL tables (30+)

Core lending

TableDescription
aave_suppliesAll Supply events (V3 rename of Deposit)
aave_withdrawalsAll Withdraw events
aave_borrowsAll Borrow events
aave_repaysAll Repay events (includes use_a_tokens flag)
aave_liquidationsAll LiquidationCall events
aave_flash_loansAll FlashLoan events (includes interest_rate_mode)
aave_rate_swapsStable↔variable rate mode swaps
aave_rebalancesStable borrow rate rebalances
aave_reserve_rate_historyFull rate history (every ReserveDataUpdated)

V3-only events

TableDescription
aave_user_emodeHistory of user eMode category changes
aave_user_emode_currentCurrent eMode category per user (upserted)
aave_isolation_debtHistory of isolation mode debt updates
aave_isolation_debt_currentCurrent isolation debt per reserve (upserted)
aave_mint_unbackedPortal bridge mint events
aave_back_unbackedPortal bridge back events
aave_treasury_mintsAccrued interest minted to treasury
aave_emode_categorieseMode category add/update history
aave_emode_categories_currentCurrent eMode category config (upserted)
aave_reserve_emode_historyReserve eMode category assignment changes
aave_supply_cap_historySupply cap change history
aave_borrow_cap_historyBorrow cap change history
aave_debt_ceiling_historyIsolation mode debt ceiling change history

Rewards (multi-reward)

TableDescription
aave_rewards_accruedwMATIC/multi-reward accruals (includes reward token)
aave_rewards_claimedReward claims (includes reward token and claimer)
aave_reward_configsEmission config updates per (asset, reward) pair

Current state (upserted)

TableDescription
aave_reservesCurrent reserve state (V3 extended with caps, eMode, flags)
aave_reserve_totalsLifetime cumulative totals per reserve (V3 extended)
aave_user_collateralCurrent collateral flag per user per reserve

Views

ViewDescription
v_reserve_net_flowsNet supply/borrow flows and portal activity per reserve
v_reserve_rates_pctLatest rates as percentages with all V3 config fields
v_flash_loan_leaderboardTop initiators by volume
v_liquidation_leaderboardTop liquidators by count
v_emode_usageActive users per eMode category with config
v_portal_summaryUnbacked outstanding vs backed per reserve
v_isolation_utilisationIsolation debt vs ceiling per reserve

License

Apache 2.0

Modules

Execution graph

9 modules
mapMain

db_out

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.

from #25825791

Output

sf.substreams.sink.database.v1.DatabaseChanges

map

map_aave_events

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.

from #25825791
store

store_emode_categories

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

from #25825791

Store value

string

Update policy

set

store

store_isolation_debt

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

from #25825791

Store value

string

Update policy

set

store

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".

from #25825791

Store value

bigint

Update policy

add

store

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}".

from #25825791

Store value

bigint

Update policy

add

store

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}".

from #25825791

Update policy

set

store

store_user_collateral

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

from #25825791

Store value

string

Update policy

set

store

store_user_emode

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

from #25825791

Store value

string

Update policy

set