APY and APR

You can query latest APY and APR on chain and subgraph

All rates queried on chain or subgraph, are expressed in RAY units i.e. 10^27. All emmissions are expressed in WAD unists i.e. 10^18.

APY: Compounding interest accrued by deposit or borrow on LendingPool​

APR: Non Compounding rewards earned as part of LiquidityMinig​

Fetch Data

Subgraph

Use subgraph to query reserve data.

{
reserves {
name
underlyingAsset
liquidityRate
stableBorrowRate
variableBorrowRate
aEmissionPerSecond
vEmissionPerSecond
sEmissionPerSecond
totalATokenSupply
totalCurrentVariableDebt
}
}

On-Chain

APR: getAssetData to fetch liquidity mining incentives for a/s/vToken.

APY: getReserveDatato fetch deposit and borrow rates of asset.

[, liquidityIndex, variableBorrowIndex,
currentLiquidityRate, currentVariableBorrowRate,
currentStableBorrowRate, ,
aTokenAddress, stableDebtTokenAddress,
variableDebtTokenAddress, , ] = LendingPool.getReserveData(asset.address)
// asset is the ERC20 deposited or borrowed, eg. DAI, WETH
​
[,aEmissionPerSecond,] = IcentivesController.getAssetData(aTokenAddress)
[,vEmissionPerSecond,] = IcentivesController.getAssetData(variableDebtTokenAddress)
[,sEmissionPerSecond,] = IcentivesController.getAssetData(stableDebtTokenAddress)

Compute Data

Calculate rates asπŸ‘‡πŸ»with js, python or whatever you like πŸ˜‰

RAY = 10^27
​
// deposit and borrow calculation
​
percentDepositAPY = 100 * liquidityRate/RAY
percentVariableBorrowAPY = 100 * variableBorrowRate/RAY
percentStableBorrowAPY = 100 * variableBorrowRate/RAY
​
// AAVE incentives calculation
​
aEmissionPerYear = aEmissionPerSecond * SECONDS_PER_YEAR
vEmissionPerYear = vEmissionPerSecond * SECONDS_PER_YEAR
​
percentDepositAPR = 100 * (aEmissionPerYear * REWARD_PRICE_ETH * TOKEN_DECIMALS)/
(totalATokenSupply * TOKEN_PRICE_ETH * REWARD_DECIMALS)
percentBorrowAPR = 100 * (vEmissionPerYear * REWARD_PRICE_ETH * TOKEN_DECIMALS)/
(totalCurrentVariableDebt * TOKEN_PRICE_ETH * REWARD_DECIMALS)

​

​

​