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

Commit 36ebd53

Browse files
authored
Merge pull request #58 from ionicprotocol/fix/lens-collateral-zero
Lens calcs zero div fix
2 parents 9aa8960 + 088e6b0 commit 36ebd53

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

contracts/ionic/levered/LeveredPosition.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ contract LeveredPosition is LeveredPositionStorage, IFlashLoanReceiver {
223223
debtValue = (borrowedAssetPrice * debtAmount) / 1e18;
224224
}
225225

226+
// TODO check if positionValue > debtValue
226227
// s / ( s - b )
227228
return (positionValue * 1e18) / (positionValue - debtValue);
228229
}
@@ -378,7 +379,7 @@ contract LeveredPosition is LeveredPositionStorage, IFlashLoanReceiver {
378379
stableAssetPrice
379380
);
380381

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

contracts/ionic/strategies/flywheel/IonicFlywheelLensRouter.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ contract IonicFlywheelLensRouter {
203203
uint256 yieldValuePerBlock = (collateralValue * supplyRatePerBlock) / 1e18;
204204
uint256 interestOwedValuePerBlock = (borrowsValue * borrowRatePerBlock) / 1e18;
205205

206+
if (collateralValue == 0) return 0;
206207
return ((int256(yieldValuePerBlock) - int256(interestOwedValuePerBlock)) * blocksPerYear) / int256(collateralValue);
207208
}
208209

contracts/test/FLRTest.t.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ contract FLRTest is BaseTest {
144144
emit log_named_int("apr", apr);
145145
}
146146

147+
function testNetAprMode() public fork(MODE_MAINNET) {
148+
address user = 0xf0AC0F92E7da747E6757379771e5c9e5ea35D85A;
149+
int256 blocks = 30 * 24 * 365 * 60;
150+
int256 apr = lensRouter.getUserNetApr(user, blocks);
151+
emit log_named_int("apr", apr);
152+
}
153+
147154
function testNetAprChapel() public fork(BSC_CHAPEL) {
148155
address user = 0x8982aa50bb919E42e9204f12e5b59D053Eb2A602;
149156
int256 blocks = 26 * 24 * 365 * 60;

0 commit comments

Comments
 (0)