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

Lens calcs zero div fix #58

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion contracts/ionic/levered/LeveredPosition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ contract LeveredPosition is LeveredPositionStorage, IFlashLoanReceiver {
debtValue = (borrowedAssetPrice * debtAmount) / 1e18;
}

// TODO check if positionValue > debtValue
// s / ( s - b )
return (positionValue * 1e18) / (positionValue - debtValue);
}
Expand Down Expand Up @@ -378,7 +379,7 @@ contract LeveredPosition is LeveredPositionStorage, IFlashLoanReceiver {
stableAssetPrice
);

ICErc20(address(collateralMarket)).flash(flashLoanCollateralAmount, abi.encode(stableToBorrow));
collateralMarket.flash(flashLoanCollateralAmount, abi.encode(stableToBorrow));
// the execution will first receive a callback to receiveFlashLoan()
// then it continues from here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ contract IonicFlywheelLensRouter {
uint256 yieldValuePerBlock = (collateralValue * supplyRatePerBlock) / 1e18;
uint256 interestOwedValuePerBlock = (borrowsValue * borrowRatePerBlock) / 1e18;

if (collateralValue == 0) return 0;
return ((int256(yieldValuePerBlock) - int256(interestOwedValuePerBlock)) * blocksPerYear) / int256(collateralValue);
}

Expand Down
7 changes: 7 additions & 0 deletions contracts/test/FLRTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ contract FLRTest is BaseTest {
emit log_named_int("apr", apr);
}

function testNetAprMode() public fork(MODE_MAINNET) {
address user = 0xf0AC0F92E7da747E6757379771e5c9e5ea35D85A;
int256 blocks = 30 * 24 * 365 * 60;
int256 apr = lensRouter.getUserNetApr(user, blocks);
emit log_named_int("apr", apr);
}

function testNetAprChapel() public fork(BSC_CHAPEL) {
address user = 0x8982aa50bb919E42e9204f12e5b59D053Eb2A602;
int256 blocks = 26 * 24 * 365 * 60;
Expand Down
Loading