> For the complete documentation index, see [llms.txt](https://docs.kpk.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kpk.io/funds/infrastructure/architecture/onchain-accounting/meta-balance-adapters/aave-v3.md). Agents can also search and read this documentation through its [MCP server](https://docs.kpk.io/~gitbook/mcp).

# Aave V3

One immutable meta-adapter that reports an account's lending positions across any Aave V3 instance (Core, Prime, an L2 market, …).

One immutable meta-adapter that reports an account's lending positions across *any* Aave V3 instance (Core, Prime, an L2 market, …). Each instance is identified by its **ProtocolDataProvider** address; reserves are enumerated onchain via `getAllReservesTokens()`.

* **Type:** Meta-adapter
* **protocolSubId:** `keccak256("aave-v3-lending")` (brand `aave`, ecosystem `aave-v3`)
* **Instance key:** the instance's ProtocolDataProvider address, widened to `bytes32`
* **Source:** `AaveV3InstancesMetaBalanceAdapter.sol`

## Positions returned

Up to two legs per registered reserve, per instance:

| Leg        | PositionKind | isDebt  | isLocked | Description                                                          |
| ---------- | ------------ | ------- | -------- | -------------------------------------------------------------------- |
| Supply     | `Supplied`   | `false` | `false`  | aToken balance when `usageAsCollateralEnabled == false`              |
| Collateral | `Collateral` | `false` | `false`  | aToken balance when `usageAsCollateralEnabled == true`               |
| Borrow     | `Borrowed`   | `true`  | `false`  | Variable + stable debt, summed; emitted only when the total is `> 0` |

Reserves not registered on NAVCalculator are skipped; `assetFilter` is respected. If the account **borrows** a reserve whose asset is unregistered, the instance reports **nothing at all**, supply and collateral legs included, rather than credit legs with no offsetting debt. Borrowed reserves are read from Aave's user-configuration bitmap (`getUserConfiguration`); if it is unavailable the adapter falls back to a full scan. See [Never report collateral without its debt](https://docs.kpk.io/funds/infrastructure/architecture/onchain-accounting/balance-adapters.md#how-an-adapter-is-built).

## Balance calculation

<figure><picture><source srcset="https://1699303810-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUsQM4bzcmOPSgkWddkeN%2Fuploads%2FidXBOeIHKDh9prbVdC7N%2Fmeta-aave-v3_D.png?alt=media&amp;token=ac78389f-0d67-4943-b5cd-93dd2a5ef604" media="(prefers-color-scheme: dark)"><img src="https://1699303810-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUsQM4bzcmOPSgkWddkeN%2Fuploads%2FuAyhbUvP87udZDrYVHM9%2Fmeta-aave-v3.png?alt=media&amp;token=1c384c60-2dde-4e8a-9ccc-d56c72f317fe" alt="Flowchart of the Aave V3 balance adapter: read calls derive position legs into PositionBalance entries."></picture><figcaption><p>Aave V3 adapter: how the underlying balances reported to the NAV Calculator are derived.</p></figcaption></figure>

Per instance, the ProtocolDataProvider (`_toAddress(instance)`) is queried. For each reserve from `getAllReservesTokens()`:

```
(aTokenBalance, stableDebt, variableDebt, …, usageAsCollateral) = dp.getUserReserveData(asset, account)

supply leg:   amount = aTokenBalance              kind = usageAsCollateral ? Collateral : Supplied
borrow leg:   amount = variableDebt + stableDebt  isDebt = true, kind = Borrowed   (if > 0)
```

Variable and stable debt are summed into one `Borrowed` leg per reserve, because two legs would share the same `(chainId, protocolSubId, positionId, balanceAsset.asset, positionKind)` key. Legacy stable debt can still persist, so any remaining stable debt is folded into the variable amount.

The instance Pool address (used in `positionId`) is resolved via `dp.ADDRESSES_PROVIDER().getPool()`.

## Identity

* **positionId:** `abi.encode(address pool)`, one per instance Pool; the reserve is carried in `balanceAsset`, not the `positionId`
* **positionKind:** `Supplied` · `Collateral` · `Borrowed`
* **labels:** `positionLabels(positionId)` returns `["Market", "<market id>"]` (the instance's onchain market id, e.g. Aave Core or Aave Lido); verbose reads only.
* **shape enumeration:** [`positionIds()`](https://docs.kpk.io/funds/infrastructure/architecture/onchain-accounting/concepts/position-identity.md#enumerating-position-shapes) advertises the **Pool** for each configured instance, the id the legs emit, not the `ProtocolDataProvider` coordinate. `_instancePositions` resolves the Pool from the same hook, so the emitted and advertised ids cannot drift apart.

## Constructor

```solidity
constructor(address navCalculator_)
```

| Parameter        | Description                                                                               |
| ---------------- | ----------------------------------------------------------------------------------------- |
| `navCalculator_` | NAVCalculator address (must be a contract); source of the instance set and asset registry |

## Registration

Registered with `addMetaBalanceAdapter(adapter, instances)`; instances are adjusted with `addMetaInstances` / `removeMetaInstances`. Each coordinate is a ProtocolDataProvider address widened to `bytes32`. A malformed coordinate is isolated per instance by the fan-out.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.kpk.io/funds/infrastructure/architecture/onchain-accounting/meta-balance-adapters/aave-v3.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
