Pulsar APRs Calculations

Details of 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

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.

How is volatility calculated?

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

The formula for volatility calculation is as follows:

τ - 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:

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

α - 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:

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

The liquidity is calculated as:

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

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

This can further be used into driving regulator sigmoid using:

α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.

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

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.

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:

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

The TVL for entire pool can be calculated as

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

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.

Last updated