The Annual Percentage Yield (APY) for supplying or borrowing in each market can be calculated using the value of supplyRatePerBlock (for supply APY) or borrowRatePerBlock (for borrow APY) in this formula:
Rate = bToken.supplyRatePerBlock(); // Integer
Rate = 37893566
ETH Mantissa = 1 * 10 ^ 18 (ETH has 18 decimal places)
Blocks Per Day = 20 * 60 * 24 (based on 20 blocks occurring every minute)
Days Per Year = 365
APY = ((((Rate / ETH Mantissa * Blocks Per Day + 1) ^ Days Per Year - 1)) - 1) * 100
Here is an example of calculating the supply and borrow APY with Web3.js JavaScript:
constethMantissa=1e18;constblocksPerDay=20*60*24;constdaysPerYear=365;constbToken=newweb3.eth.Contract(sEthAbi, sEthAddress);constsupplyRatePerBlock=awaitbToken.methods.supplyRatePerBlock().call();constborrowRatePerBlock=awaitbToken.methods.borrowRatePerBlock().call();constsupplyApy= (((Math.pow((supplyRatePerBlock / ethMantissa * blocksPerDay) +1, daysPerYear))) -1) *100;constborrowApy= (((Math.pow((borrowRatePerBlock / ethMantissa * blocksPerDay) +1, daysPerYear))) -1) *100;console.log(`Supply APY for ETH ${supplyApy} %`);console.log(`Borrow APY for ETH ${borrowApy} %`);