# 🔎Methodology

vaults.fyi utilizes onchain data to track yields over a given period of time. We query blockchains hourly and obtain the share price of the specific DeFi vaults curated on our platform. This share price, indicative of a lender’s stake in a vault, can be used to calculate yield over time. By sourcing data directly and avoiding external API endpoints, we strive for accuracy and dependability.

For example, when calculating a vault’s 7-day APY on January 7th, we compare the share price on that day with the share price from January 1st and then extrapolate this difference over an entire year. This method is similarly applied when determining 1-day and 30-day APYs.

To efficiently automate this process, we implement specialized smart contracts that fetch and transform data using a single function. These contracts are deployed in a static call, which is temporary and does not affect blockchain storage, thereby incurring any cost. This method allows us to read data directly from the blockchain. Our approach saves on calls and enables the use of one result to calculate the next within the same call, a technique not possible with standard multi-call processes. We use services like Infura, Alchemy, and Ankr RPCs to execute these calls. Once the data is retrieved, it is stored in our backend database.

## Calculating APY from historical data

Due to the vast amount of data involved and the limitations in indexing speed, it is impractical to query blockchains every time a new block is added. Instead, we calculate yield using accrued interest, an obtainable figure for most yield-bearing products. This allows APY to be extrapolated from limited data points.

### Simple interest

We use the following formula to calculate APY for simple (i.e., not compounding) interest:

The interest rate is determined by this formula:

Share price is calculated with the data that we query:

### Compounding interest

To determine compounding interest, we use the following formula:

The interest rate is determined by this formula:

Share price is calculated with the data that we query:

### Rewards APY

To calculate the rewards APY for a desired time range (1 day, 7 days, 30 days), we:

Estimate the number of reward tokens distributed per token deposited in the vault during the chosen period.

Calculate the average price ratio between the reward token and the deposited token for that period.

Use this ratio to convert the accumulated reward tokens' value to a single deposited token's value.

Compare this converted value to the initial deposit to determine the APY.

The average of the reward token price (**PIT **- Price In Token) to deposited token price is calculated using the formula:

The APY at time range of `xday`

is calculated using the formula:

## Obtaining the data we need

In order to execute the calculations outlined above, accessing onchain data is essential. Our method of obtaining a vault's share price depends on the type of vault. You can read more about each method below.

### ERC-4626

In the case of ERC-4626 vaults, we can call the `totalSupply`

and `totalAssets`

smart contract functions to calculate share price.

`totalSupply`

= total shares

`totalAssets`

= total shares value

### Not ERC-4626

If a vault is not ERC-4626 compliant, proxies for the above functions can usually be found in the following functions:

`mint`

`deposit`

`burn`

`redeem`

You can see an example of this in the code snippets below.

The functions provided are typical examples and not an exhaustive list; some vaults may require individual solutions.

### Liquid staking tokens

To calculate APY for LSTs (e.g., Lido) and other vaults that periodically update their earnings (e.g., Yearn vaults), we use the `totalSupply`

and `getEthValue(totalSupply)`

functions.

`totalSupply`

= total shares

`getEthValue(totalSupply)`

= total shares value

One challenge we face is accounting for the irregular intervals at which some vaults update their earnings — leading to sudden and significant fluctuations in APY. Understanding this nuance is essential for accurately interpreting discrepancies on vaults.fyi.

### Rebasing supply vaults

Vaults that gradually increase the user's LP token balance, such as those on Aave, are known as rebasing supply vaults. We calculate the share price for rebasing supply vaults with the `totalSupply`

and `scaledTotalSupply`

functions.

`scaledTotalSupply`

= total shares

`totalSupply`

= total shares value

### Staking mechanism vaults

Vaults that do not compound automatically (e.g., StakeWise) are known as staking mechanism vaults. These vaults do not compound interest automatically, instead making users periodically harvest and redeposit it to maximize yield. Calculating returns in such scenarios can be complex, as the total shares:value ratio does not reflect share price accurately.

Instead, we can ascertain the actual share price with the following formulas:

These formulas result in a simulated calculation of `totalSupply`

. It is not directly fetched from the blockchain.

### Real-world assets

RWAs on vaults.fyi are ERC-20 tokens that reflect investments in offchain financial assets. To assess the yield of RWAs we use:

The

`totalSupply`

function to calculate total shares.The

`RWAOracle.price`

function to fetch share price.The

`StablecoinOracle.price`

function to fetch the underlying asset's (i.e, a stablecoin) price.

These functions are used in the following formulas to calculate yield:

Last updated