> 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/onchain-accounting.md).

# Onchain Accounting

KPK's onchain accounting system produces a verifiable, manipulation-resistant **Net Asset Value (NAV)** for each fund by composing three layers of onchain infrastructure into a single contract — the **NAV Calculator** — deployed once per chain.

{% hint style="info" %}
Each fund's NAV is computed independently on every chain where it operates, then aggregated offchain into a single global figure. Every computation input — balances and prices — is read from onchain sources and is independently verifiable.
{% endhint %}

### How it fits together

The NAV Calculator inherits two libraries of behaviour — **Balances** and **Prices** — and combines them into the NAV layer.

{% stepper %}
{% step %}

#### Balance layer

For each tracked asset, the NAV Calculator collects the account's holdings from a set of registered **balance adapters**. A built-in `ERC20DefaultBalanceAdapter` reports plain wallet balances; protocol adapters report positions that are not visible as a simple `balanceOf` (Morpho supply shares, Aave aTokens, staked LP, reward accruals, …). Each adapter returns balance-only **`PositionBalance`** entries tagged with a machine-readable identity (the `protocolBrand`/`protocolId`/`protocolSubId` taxonomy, `positionId`, `positionKind`, `isLocked`).
{% endstep %}

{% step %}

#### Price layer

Each balance is priced by the asset's single **primary price feed** (Chainlink, Redstone, API3, or a custom composite adapter). Any additional trustworthy source is a **monitor feed**, read only to check the primary for divergence — never to price NAV. If the primary is stale, the asset is added to `NAV.stalePriceAssets` and the reading is flagged unreliable; if the primary diverges from a monitor (or, for stablecoins, strays from $1) beyond tolerance, the asset is added to `NAV.irregularPriceAssets` as a soft alert. If monitors are configured but **none of them was readable**, the divergence check could not run at all, and the asset is added to `NAV.monitorsUnhealthyPriceAssets` — so a clean `irregular` flag is never mistaken for a check that actually happened.
{% endstep %}

{% step %}

#### Aggregation layer

On each chain, the NAV Calculator prices every position and sums them into a **chain-local NAV** (`int256`, in the quote asset's decimals — 8 for USD). Debt positions subtract. The offchain **NAV Worker** collects per-chain values and sums them into the **global NAV** used for subscriptions and redemptions.
{% endstep %}
{% endstepper %}

<figure><img src="/files/sh0OGUhbuVfMevTiF9cw" alt="Flowchart: getAccountNav gathers balance-adapter positions, prices each, aggregates a per-chain NAV, and an off-chain worker sums healthy chains into a global NAV."><figcaption><p>NAV computation pipeline: balance adapters report positions, prices value them, the per-chain NAV is aggregated, and the off-chain worker sums chains into the global NAV.</p></figcaption></figure>

### Architecture

* A single **`NAVCalculator`** is deployed per chain as a UUPS proxy at a canonical CREATE2 address (identical across chains). It is **fund-agnostic** — one instance prices any account on that chain.
* It inherits the `Prices` and `Balances` registries, and delegates heavy registry mutations and read loops to external libraries (`NAVRegistryLib`, `PriceFeedLib`) to stay under the EIP-170 contract-size limit.
* Human-readable labels come from the NAV Calculator's own **verbose read methods** (`getAccountNavVerbose` / `getAccountPositionsVerbose`) — the label-enrichment path is inlined into the contract rather than split into a separate lens. There is no standalone lens contract.
* Chains where the funds hold positions: **Ethereum, Optimism, Arbitrum, Base, Gnosis** — the NAV is also live (canonical layer only) on 19 more chains. See [Deployment addresses](/funds/infrastructure/onchain-accounting/deployment-addresses.md).
* **License:** the contracts are released under **BUSL-1.1** (licensor KPK; converts to GPL-2.0-or-later on 2030-07-01), with a GPL-2.0-or-later exception for the bundled Uniswap V3 math libraries.

### Key contracts

| Component       | Contract                             | Purpose                                                                                                                                |
| --------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| NAV Calculator  | `NAVCalculator` (UUPS proxy)         | Registers assets, feeds, and adapters; prices balances; returns chain NAV and positions, plus labelled `*Verbose` reads for dashboards |
| Default adapter | `ERC20DefaultBalanceAdapter`         | Reports plain wallet balances for every registered ERC-20 + the native token                                                           |
| Balance adapter | Various (plain & meta)               | Report protocol positions as balance-only `PositionBalance` entries                                                                    |
| Price feed      | Chainlink / Redstone / API3 / custom | Return a price and staleness signal per asset                                                                                          |

### Explore the section

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Contracts</strong></td><td>The NAV Calculator — the contract you read from.</td><td><a href="/pages/ak6r52XnPrtcv9I94JJf">/pages/ak6r52XnPrtcv9I94JJf</a></td></tr><tr><td><strong>Concepts</strong></td><td>Position identity and the stale-price / sequencer model.</td><td><a href="/pages/IDHZP5LmfUqUT9S04APr">/pages/IDHZP5LmfUqUT9S04APr</a></td></tr><tr><td><strong>Price feeds</strong></td><td>The 27 custom feeds and how prices are resolved.</td><td><a href="/pages/Myx8yVbXzc9sXEcD0YPP">/pages/Myx8yVbXzc9sXEcD0YPP</a></td></tr><tr><td><strong>Balance adapters</strong></td><td>The default + singleton adapters that locate positions.</td><td><a href="/pages/DUJjfVIW8kmMnZQjtppj">/pages/DUJjfVIW8kmMnZQjtppj</a></td></tr><tr><td><strong>Meta balance adapters</strong></td><td>One adapter per protocol, serving many instances.</td><td><a href="/pages/WVS5FrCAb7oPDpSaxXEw">/pages/WVS5FrCAb7oPDpSaxXEw</a></td></tr><tr><td><strong>Assisted balance adapters</strong></td><td>Permissionless, owner-fed adapters for positions not discoverable on-chain.</td><td><a href="/pages/5jla9uxBHtbur2nGloBe">/pages/5jla9uxBHtbur2nGloBe</a></td></tr><tr><td><strong>Deployment addresses</strong></td><td>Per-chain contract addresses for each chain.</td><td><a href="/pages/fIz7s9PU3bussEkJhewJ">/pages/fIz7s9PU3bussEkJhewJ</a></td></tr><tr><td><strong>Code examples</strong></td><td>Read NAV, positions, and prices in TypeScript / Python.</td><td><a href="/pages/38GRfyQJrH7sfAjMKAIq">/pages/38GRfyQJrH7sfAjMKAIq</a></td></tr></tbody></table>


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.kpk.io/funds/infrastructure/onchain-accounting.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
