> 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/meta-balance-adapters/pancakeswap-v3.md).

# PancakeSwap V3

A **meta-adapter** that reports an account's **PancakeSwap V3 concentrated-liquidity LP** — both the in-range liquidity (`Supplied`) and the full uncollected fees (`Fees`) of every NFT position the account holds. PancakeSwap V3 is a Uniswap V3 fork; this adapter subclasses the [Uniswap V3](/funds/infrastructure/onchain-accounting/meta-balance-adapters/uniswap-v3.md) meta-adapter. It differs in exactly two ways: it reports the `pancakeswap-v3` brand/product slug instead of `uniswap-v3`, and it overrides the `_slot0` read to handle PancakeSwap's ABI divergence (below). Everything else — the on-chain NPM enumeration, the live-`slot0` pricing, the full-fee accounting, the per-pool fault isolation — is identical.

* **Type:** [Meta-adapter](/funds/infrastructure/onchain-accounting/meta-balance-adapters.md)
* **protocolSubId:** `keccak256("pancakeswap-v3")` (brand `pancakeswap`, ecosystem `pancakeswap-v3`)
* **Instance key:** the PancakeSwap V3 pool address, widened to bytes32.
* **Source:** [`PancakeSwapV3PoolsMetaBalanceAdapter.sol`](https://github.com/karpatkey/onchain-accounting/blob/main/src/balances/MetaBalanceAdapters/pancakeswap/PancakeSwapV3PoolsMetaBalanceAdapter.sol)

{% hint style="info" %}
This subclass overrides the `_slot0` read because PancakeSwap declares `slot0().feeProtocol` as `uint32` vs Uniswap's `uint8`, so the strict full-tuple decode needs a PancakeSwap-specific ABI. The base reads the pool's live `slot0` to compute instantaneous in-range amounts, so this override is what lets the shared valuation path work unchanged against PancakeSwap pools. It changes how the tuple is *decoded*, not which price is used.
{% endhint %}

***

## Positions returned

Per NFT the account holds in a configured pool, up to four legs (token0/token1 × liquidity/fees):

| Leg              | PositionKind | isDebt  | isLocked | Description                                                                    |
| ---------------- | ------------ | ------- | -------- | ------------------------------------------------------------------------------ |
| token0 liquidity | `Supplied`   | `false` | `false`  | token0 amount of the position's in-range liquidity                             |
| token1 liquidity | `Supplied`   | `false` | `false`  | token1 amount of the position's in-range liquidity                             |
| token0 fees      | `Fees`       | `false` | `false`  | Full uncollected token0 fees (settled `tokensOwed0` + `feeGrowthInside` delta) |
| token1 fees      | `Fees`       | `false` | `false`  | Full uncollected token1 fees (settled `tokensOwed1` + `feeGrowthInside` delta) |

**Both** pool tokens must be registered in NAVCalculator or the whole instance is dropped (the liquidity split needs **both** prices). Each pool's fan-out is isolated by the meta base's per-instance `try/catch`, so a bad/unfeeded instance discards only that pool, never the account's whole LP set. Legs with zero amount, or assets excluded by `assetFilter`, are dropped. `isLocked` is `false` for every leg. The NFT `tokenId` rides in each leg's `positionInstanceId`. Per-account discovery is bounded by `MAX_POSITIONS` (1000) — see [Uniswap V3](/funds/infrastructure/onchain-accounting/meta-balance-adapters/uniswap-v3.md#positions-returned).

***

## Balance calculation

<figure><img src="/files/OgRXKx58FUO4Svslru2E" alt="Flowchart of the PancakeSwap V3 balance adapter: read calls derive position legs into PositionBalance entries."><figcaption><p>PancakeSwap V3 adapter — how the underlying balances reported to the NAV Calculator are derived.</p></figcaption></figure>

Identical to [Uniswap V3](/funds/infrastructure/onchain-accounting/meta-balance-adapters/uniswap-v3.md#balance-calculation), except for the `_slot0` decode override. For each configured pool the adapter enumerates the account's NPM NFTs, keeps those in the pool, reads `NPM.positions(tokenId)` and the pool's live `slot0`, and derives the legs via `UniswapV3PoolLib.positionAmounts(...)`.

**Liquidity legs (`Supplied`)** — the in-range token0/token1 amounts computed from the pool's **live `slot0`** price (`sqrtPriceX96`, `tick`) — the instantaneous on-chain withdrawable split. See the [Uniswap V3 note](/funds/infrastructure/onchain-accounting/meta-balance-adapters/uniswap-v3.md#balance-calculation) on why reading the live spot is safe under the async NAV-consumer model.

**Fee legs (`Fees`)** — the **full uncollected** fees: settled `tokensOwed0` / `tokensOwed1` **plus** the `feeGrowthInside` delta accrued since the position's last interaction, from the pool's current tick.

***

## Identity

* **positionId:** `abi.encode(address pool)` — the pool address (the instance coordinate). Each fee tier is its own pool; all of an account's NFTs in the same pool share one positionId and **sum**.
* **positionInstanceId:** `bytes32(tokenId)` — the NFT id, the ephemeral per-item handle (excluded from the identity key); not in `positionId` and not in `labels`.
* **positionKind:** `Supplied` for liquidity legs, `Fees` for fee legs.
* **labels:** there is no `labels` field on the position. The adapter implements `positionLabels(positionId)`, which returns `["AMM Liquidity Pool", "<sym0>/<sym1> <fee>%"]` — token symbols + fee tier read live from the pool, surfaced only by the verbose reads.

***

## Constructor

```solidity
constructor(
    address positionManager_,
    address navCalculator_
)
```

| Parameter          | Description                                                                                                              |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------ |
| `positionManager_` | The PancakeSwap V3 NonfungiblePositionManager (canonical CREATE2 address) — the chain-level constant. Must be a contract |
| `navCalculator_`   | NAVCalculator contract for asset-registry access. Must be a contract                                                     |

The pool addresses are **not** pinned — they are the governed instance set on NAVCalculator. Like its base, this adapter is `GPL-2.0-or-later` (it links the Uniswap V3 math libraries).

***

## Registration

Register the adapter once with `addMetaBalanceAdapter(adapter, pools)`, then enable each pool with `addMetaInstances(adapter, pools)` and drop coverage with `removeMetaInstances`. The instance coordinate is the PancakeSwap V3 pool address widened to bytes32. The adapter reads its active set from `NAV_CALCULATOR.getMetaInstances(address(this))`. See [Meta balance adapters](/funds/infrastructure/onchain-accounting/meta-balance-adapters.md).


---

# 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/meta-balance-adapters/pancakeswap-v3.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.
