# Pulsar APRs Calculations

### How are fees generated in Pulsar?

Fees in Pulsar are dynamic than static fees such as 0.3% on each swap. The reason for this is to provide better returns to liquidity providers and combat impermanent loss.

The optimal fees depends on the nature of the asset's behavior, the following indicators are monitored:

1. Volatility
2. Liquidity
3. Trading Volume&#x20;

High liquidity is supported by beneficial conditions for providers, which consist of high trading volume with low volatility. In this case, the following situations are possible for providers.

<figure><img src="/files/fRUOHYnR34DYdECM29u5" alt=""><figcaption></figcaption></figure>

### How is volatility calculated?

The volatility is calculated based on time-weighted moving average (TWAPs)

The formula for volatility calculation is as follows:

<figure><img src="/files/VRd5BYZIQUExYy8DMrQ3" alt=""><figcaption></figcaption></figure>

τ - the time points corresponding to the available price observations,

𝑃(τ) - the value of the price at the τ moment,

∆𝑡(τ) - the time during which this price was maintained,

𝑇- time period (in seconds).

It’s to be noted that the price here is based on logarithm than absolute prices which means a price move from $100 to $120 is high volatility than from $10,000 to $12,000

So the actual formula for calculating volatility in Pulsar is:

<figure><img src="/files/aqIlcVpsce36liohq9fs" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/zyS0DPgPlTvnUl6QhjJB" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/B12anDlCo94bcznRyrip" alt=""><figcaption></figcaption></figure>

Once we receive the volatility, the fees is calculated by deriving sum of two sigmoids.

<figure><img src="/files/ezgshwbnLWuO0VqO0S9B" alt=""><figcaption></figcaption></figure>

α - allows scaling the maximum value of the sigmoid β - is responsible for the linear shift along the x-axis γ - regulates the "steepness" of the sigmoid

The final formula is:

<figure><img src="/files/AJ4YHHam8s3URDDvocRy" alt=""><figcaption></figcaption></figure>

This however doesn’t take into consideration two other important factors: volume and liquidity.

The liquidity is calculated as:

<figure><img src="/files/DylcKMPbUsOodM2TAiFP" alt=""><figcaption></figcaption></figure>

and the Volume is stored in the Pool’s data storage. Using this forumula we can get the amount of liquidity used:

<figure><img src="/files/x727GLkEPT2G0hfHOBuf" alt=""><figcaption></figcaption></figure>

The ratio of total liquidity and used liquidity is calculated as follows:

<figure><img src="/files/Ualwpy8S6WBr2qAyLLg7" alt=""><figcaption></figcaption></figure>

This can further be used into driving regulator sigmoid using:

<figure><img src="/files/T8AuoOv4YCdiApf4iBnO" alt=""><figcaption></figcaption></figure>

αR equal to 1

### How is effective fee calculated?

Now that we’ve volatility, volume and liquidity parameters. We can input them into final formula to calculate effective fees.

<figure><img src="/files/NEj5QTrzyEpNSDVNJROL" alt=""><figcaption></figcaption></figure>

The Fee base is the minimum possible fee value that is: **0.01**

### Positions & Ticks

To provide liquidity in ranges rather than 0 to infinity as compared to V2, the liquidity is divided into ticks. There is a tick at every 1 basis points (0.01%) of price. So if there’s a token which’s initial price is $5, there will be a tick at every $0.0005.

Liquidity providers can provide liquidity within tick ranges, the tick spacing in Pulsar is 60 which means the most concentrated position can at-least be within 60 ticks. So in our example LPs can provide liquidity within $0.06 - $0.03 price range.

Tick also provides us with granularity of prices.

### Fees for Positions

Swap fees are collected only when a price range is engaged (used in trades).

<figure><img src="/files/AmbxCJKU0kIhMtkgb0UJ" alt=""><figcaption></figcaption></figure>

If price of asset is increasing the ticks are crossed left → right

If price of asset is decreasing the ticks are crossed left ← right

The fees generated are stored globally at pool level rather than per position level. As on a single swap there can be multiple ticks moved either left→right or left ← right. To make accounting simpler and make contract gas efficient Ticks only keep track of how much fees were generated outside of them. Having ticks that know how much fees were accumulated outside of them will allow us to calculated how much fees were accumulated inside of a position

Since position is range of ticks, the fees is distributed the position to the amount of liquidity they provide.

### How are Pools APRs calculated?

The pools APRs are calculated by calculating fees generated in 24 hours over the active TVL.

<figure><img src="/files/CJNYYmfMQ6qr1zFxpf2Y" alt=""><figcaption></figcaption></figure>

Here feesInToken0Current is fetched from subgraph, and feeInToken0Previous is also fetched from subgraph by calculating block number of timestamp in last 24 hours.

The block number is calculated as:

<figure><img src="/files/OknoTJz9De6uad4Nbi0D" alt=""><figcaption></figcaption></figure>

Pool active TVL is calculate by iterating over positions under a pool and only considering in-range positions. The in range position condition is:

<figure><img src="/files/IlW8BrxoD8T1ekHqafzV" alt=""><figcaption></figcaption></figure>

The TVL for entire pool can be calculated as

<figure><img src="/files/5JTU3Yjqf8OSkk73eZao" alt=""><figcaption></figcaption></figure>

This will give us estimated APR for active TVL that has generated fees in last 24 hours.

### Positions APR

1. Get Position’s last fee via snapshot (where fee was collected) in GLMR
   1. Get collected fees in GLMR
   2. Get pending fees at that block # in GLMR
   3. Sum the total fees
2. Get Positions current fee in GLMR
   1. Get fee collected so far in GLMR
   2. Get pending fee in GLMR
   3. Sum the total fees
3. Subtract Current Fee by Previous Fee ( #2 - #1 )
4. Get the Time elapsed by last snapshot and current timestamp
5. Get Position’s TVL in GLMR
6. Calculate APR by

   <figure><img src="/files/7Zw0JCbPRK9TVrQTskWI" alt=""><figcaption></figcaption></figure>

### Farms APR

1. Get users share of liquidity pool by dividing user liquidity over the total liquidity of farming pool a.k.a virtual pool.
2. Calculate user’s liquidity value in GLMR
3. Calculate rewards per second value in GLMR.
4. Calculate APR by multiplying reward per second with 86400 and with 365. This will give reward in GLMR per year. Now divide this by user’s liquidity value in GLMR to get APR.

<figure><img src="/files/HLtqfGZfaejImvt8Rke8" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: 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:

```
GET https://docs.stellaswap.com/dex-core/decentralized-exchange/faq/pulsar-aprs-calculations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
