> 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/uniswap-v2.md).

# Uniswap V2

The Uniswap V2 adapter reports an account's V2 LP across any pair as the dilution-adjusted pro-rata share of both reserves, emitted as one Supplied leg per token.

The Uniswap V2 adapter reports an account's V2 LP across any pair as the dilution-adjusted pro-rata share of both reserves, emitted as one `Supplied` leg per token. One immutable meta-adapter serves every pair; the active set lives on NAVCalculator.

* **Type:** Meta-adapter
* **protocolSubId:** `keccak256("uniswap-v2")`
* **Instance key:** the Uniswap V2 pair address, widened to bytes32.
* **Source:** `UniswapV2PoolsMetaBalanceAdapter.sol`

## Positions returned

Per pair, up to two legs:

| Leg          | PositionKind | isDebt  | Description                          |
| ------------ | ------------ | ------- | ------------------------------------ |
| token0 share | `Supplied`   | `false` | Account's pro-rata share of reserve0 |
| token1 share | `Supplied`   | `false` | Account's pro-rata share of reserve1 |

Legs with zero amount, unregistered assets, or assets excluded by `assetFilter` are dropped.

## Balance calculation

<figure><picture><source srcset="https://1699303810-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUsQM4bzcmOPSgkWddkeN%2Fuploads%2F2cl7XiUDf9iBEjXETzcl%2Fmeta-uniswap-v2_D.png?alt=media&amp;token=63f60efc-2293-4229-bc86-a99dfeb17579" media="(prefers-color-scheme: dark)"><img src="https://1699303810-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUsQM4bzcmOPSgkWddkeN%2Fuploads%2FVxzvm2OQZAsO8v5jWyyQ%2Fmeta-uniswap-v2.png?alt=media&amp;token=3dd0f05f-4a77-4e01-986b-7df04c44a335" alt="Flowchart of the Uniswap V2 balance adapter: read calls derive position legs into PositionBalance entries."></picture><figcaption><p>Uniswap V2 adapter: how the underlying balances reported to the NAV Calculator are derived.</p></figcaption></figure>

Delegated to `UniswapV2PairLib.pairAmounts(pair, account)`. The LP balance is converted to reserves against an effective supply that includes the protocol fee LP the pair would mint on its next mint/burn, so amounts match what `burn` would return:

```
balance         = pair.balanceOf(account)
totalSupply     = pair.totalSupply()
(r0, r1)        = pair.getReserves()
effectiveSupply = totalSupply + pendingProtocolMint        // V2 _mintFee dilution

amount0 = balance × r0 / effectiveSupply
amount1 = balance × r1 / effectiveSupply
```

The dilution term mirrors V2's `_mintFee`:

```
pendingProtocolMint = totalSupply × (√k − √kLast) × numFactor / (rootKCoeff·√k + rootKLastCoeff·√kLast)
```

The coefficients `(numFactor, rootKCoeff, rootKLastCoeff)` come from a virtual `_mintFeeConstants()` hook that forks can override. Uniswap V2 and SushiSwap use `(1, 5, 1)`. The term is 0 when `feeTo` is unset, `kLast == 0`, or `√k <= √kLast`; `feeTo()` and `kLast()` are read defensively, so forks omitting them have no protocol fee.

{% hint style="info" %}
**An absent `feeTo()` and a malformed one differ.** Dropping dilution *raises* the reported share. A read that **fails** means a fork without protocol fees, so undiluted is correct. A read that **succeeds** but returns a non-address word means a malformed factory: the dilution is unknowable, so the pair is **dropped**.
{% endhint %}

## Identity

* **positionId:** `abi.encode(address pair)`, one positionId per pair instance.
* **positionKind:** `Supplied` for both legs.

There is no `labels` field on the position. `positionLabels(positionId)` returns `["AMM Liquidity Pool", "sym0/sym1"]` from the pair's onchain token symbols, shown only on the verbose reads (`getAccountPositionsVerbose` / `getAccountNavVerbose`); the breadcrumb is `[protocolName, ...labels]`.

## Constructor

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

| Parameter        | Description                                      |
| ---------------- | ------------------------------------------------ |
| `navCalculator_` | NAVCalculator contract for asset-registry access |

No protocol addresses are pinned; `token0`, `token1`, `factory` and reserves are read from the pair.

## Registration

Register once with `addMetaBalanceAdapter`, then enable each pair with `addMetaInstances`. The adapter holds no instance state; it reads its active set from `NAV_CALCULATOR.getMetaInstances(address(this))`.


---

# 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/uniswap-v2.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.
