> For the complete documentation index, see [llms.txt](https://docs.pancakeswap.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pancakeswap.finance/chinese/huan-ying-lai-dao-pancakeswap/how-to-guides/v3-v2-migration/how-v3-apr-is-calculated.md).

# v3 APR 如何计算

{% hint style="info" %}
在 V3 流动性和农场中，借助全新的非同质化流动性和可自定义价格区间的能力，每个 LP 头寸都将拥有自己的 LP 手续费和 CAKE 流动性挖矿 APR。
{% endhint %}

总 APR 由 LP 手续费 APR 和 CAKE 奖励 APR 组合而成

### LP 手续费

理论上来说，给定一个价格区间和用户即将添加的流动性，我们可以按如下方式估算预期的未来 7 天手续费

$$
fee\_{next7d} = fee\_{in} \frac{\Delta{L}}{L\_{in} + \Delta{L}}
$$

* $$fee\_{in}$$ ：过去 7 天内在用户指定价格区间中累积的手续费金额
* $$L\_{in}$$：用户指定价格区间中的当前流动性
* $$\Delta{L}$$：用户想要添加到该价格区间的流动性

#### 区间内手续费

对于 $$fee\_{in}$$，我们使用历史交易量数据、手续费档位和历史价格数据来估算区间内的价格

$$fee\_{in} = f\_tV\_{7d}\frac{T\_{in}}{T\_{7d}}$$

* $$f\_t$$：手续费档位
* $$V\_{7d}$$：过去 7 天的总交易量
* $$T\_{in}$$：过去 7 天内价格停留在该价格区间内的时长，以秒为单位
* $$T\_{7d}$$：以秒为单位的 7 天

### Cake APR

#### 矿池分配

MC v3 中每秒的总奖励 cake 通过 upkeep 实现，可由 `latestPeriodCakePerSecond` 推导得出

`cakePerSecond = lastestPeriodCakePerSecond / 1e12 / 1e18`

在每个矿池中，我们可以使用 `poolInfo`，通过 `poolInfo.allocPoint / totalAllocPoint` 相除来获得 `poolWeight`

#### 全局 Cake APR

全局 APR 使用活跃且已质押流动性的总量以及矿池 CAKE 奖励释放量来计算。

`APR (global) = (cakePerSecond * 31536000) / (totalAllocPoint / pool.allocPoint) * 100 * cakeUSD / totalStakedLiquidityUSD`

`totalStakedLiquidityUSD` 表示当前矿池活跃的已质押流动性（以美元计），由所有在 MasterChef v3 中质押的、处于区间内的头寸刻度组成。

#### 头寸 Cake APR

各个头寸的 APR 可能因其价格区间设置而有所不同。

$$
ARP\_p = {\frac{USD\_{r}}{USD\_{p}}} {\frac{L\_{p}}{L\_{lm}}}
$$

* $$USD\_r$$：矿池中每年赚取的 CAKE 奖励美元价值
* $$USD\_p$$：头寸中的总美元价值
* $$L\_{p}$$：头寸流动性
* $$L\_{lm}$$：由 LMPool 追踪的总质押流动性


---

# 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.pancakeswap.finance/chinese/huan-ying-lai-dao-pancakeswap/how-to-guides/v3-v2-migration/how-v3-apr-is-calculated.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.
