diff --git a/contracts/ionic/strategies/flywheel/IonicFlywheelLensRouter.sol b/contracts/ionic/strategies/flywheel/IonicFlywheelLensRouter.sol index 601722c4..c8c87a20 100644 --- a/contracts/ionic/strategies/flywheel/IonicFlywheelLensRouter.sol +++ b/contracts/ionic/strategies/flywheel/IonicFlywheelLensRouter.sol @@ -189,7 +189,21 @@ contract IonicFlywheelLensRouter { ICErc20 market, int256 blocksPerYear ) internal returns (int256) { - return (int256(market.supplyRatePerBlock()) - int256(market.borrowRatePerBlock())) * blocksPerYear; + uint256 borrows = market.borrowBalanceCurrent(user); + uint256 supplied = market.balanceOfUnderlying(user); + uint256 supplyRatePerBlock = market.supplyRatePerBlock(); + uint256 borrowRatePerBlock = market.borrowRatePerBlock(); + + IonicComptroller comptroller = market.comptroller(); + BasePriceOracle oracle = comptroller.oracle(); + uint256 assetPrice = oracle.getUnderlyingPrice(market); + uint256 collateralValue = (supplied * assetPrice) / 1e18; + uint256 borrowsValue = (borrows * assetPrice) / 1e18; + + uint256 yieldValuePerBlock = (collateralValue * supplyRatePerBlock) / 1e18; + uint256 interestOwedValuePerBlock = (borrowsValue * borrowRatePerBlock) / 1e18; + + return ((int256(yieldValuePerBlock) - int256(interestOwedValuePerBlock)) * blocksPerYear) / int256(collateralValue); } struct AdjustedUserNetAprVars {