Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

net apr logic fix #56

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion contracts/ionic/strategies/flywheel/IonicFlywheelLensRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading