> 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.md).

# Onchain Accounting

Verifiable, manipulation-resistant NAV for each fund, composed from onchain balances and prices in one contract per chain.

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><picture><source srcset="/files/LaTCrsqSvhZBxAxkeBaS" media="(prefers-color-scheme: dark)"><img src="https://1699303810-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUsQM4bzcmOPSgkWddkeN%2Fuploads%2FyfvhUMazsxRaTpwRV5RX%2F02-nav-pipeline.png?alt=media&amp;token=0c107e30-8ba3-462a-afa4-a0dc463ba07c" 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."></picture><figcaption><p>NAV computation pipeline: balance adapters report positions, prices value them, the per-chain NAV is aggregated, and the offchain 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, BSC, Polygon, Arc**; the NAV is also live (canonical layer only) on 17 more chains. See [Deployment addresses](/funds/infrastructure/architecture/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 on its inclusion list (tokens whose address a meta-adapter claims are excluded) |
| 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="/funds/infrastructure/architecture/onchain-accounting/contracts.md">Contracts</a></td></tr><tr><td><strong>Concepts</strong></td><td>Position identity and the stale-price / sequencer model.</td><td><a href="/funds/infrastructure/architecture/onchain-accounting/concepts.md">Concepts</a></td></tr><tr><td><strong>Price feeds</strong></td><td>The custom feeds and how prices are resolved.</td><td><a href="/funds/infrastructure/architecture/onchain-accounting/price-feeds.md">Price feeds</a></td></tr><tr><td><strong>Balance adapters</strong></td><td>The default + singleton adapters that locate positions.</td><td><a href="/funds/infrastructure/architecture/onchain-accounting/balance-adapters.md">Balance adapters</a></td></tr><tr><td><strong>Meta balance adapters</strong></td><td>One adapter per protocol, serving many instances.</td><td><a href="/funds/infrastructure/architecture/onchain-accounting/meta-balance-adapters.md">Meta balance adapters</a></td></tr><tr><td><strong>Assisted balance adapters</strong></td><td>Permissionless, owner-fed adapters for positions not discoverable onchain.</td><td><a href="/funds/infrastructure/architecture/onchain-accounting/assisted-balance-adapters.md">Assisted balance adapters</a></td></tr><tr><td><strong>Attested balance adapters</strong></td><td>Proof-verified adapters for positions the chain can verify but not value.</td><td><a href="/funds/infrastructure/architecture/onchain-accounting/attested-balance-adapters.md">Attested balance adapters</a></td></tr><tr><td><strong>Deployment addresses</strong></td><td>Per-chain contract addresses for each chain.</td><td><a href="/funds/infrastructure/architecture/onchain-accounting/deployment-addresses.md">Deployment addresses</a></td></tr><tr><td><strong>Code examples</strong></td><td>Read NAV, positions, and prices in TypeScript / Python.</td><td><a href="/funds/infrastructure/architecture/onchain-accounting/code-examples.md">Code examples</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 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.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.
