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

Commit 2d81f9f

Browse files
authored
Merge pull request #60 from ionicprotocol/fix/lens-blocks-per-year-rate
Leftovers fix and lens blocks per year rate
2 parents ff2a7b8 + 6edc29e commit 2d81f9f

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

contracts/ionic/levered/LeveredPosition.sol

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ contract LeveredPosition is LeveredPositionStorage, IFlashLoanReceiver {
8282
errorCode = collateralMarket.redeem(collateralMarket.balanceOf(address(this)));
8383
if (errorCode != 0) revert RedeemFailed(errorCode);
8484

85+
if (stableAsset.balanceOf(address(this)) > 0) {
86+
// convert all overborrowed leftovers/profits to the collateral asset
87+
convertAllTo(stableAsset, collateralAsset);
88+
}
89+
8590
// withdraw the redeemed collateral
8691
withdrawAmount = collateralAsset.balanceOf(address(this));
8792
collateralAsset.safeTransfer(withdrawTo, withdrawAmount);

contracts/ionic/levered/LeveredPositionsLens.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ contract LeveredPositionsLens is Initializable {
7575

7676
uint256 borrowAmount = ((_targetLeverageRatio - 1e18) * _equityAmount * collateralAssetPrice) /
7777
(stableAssetPrice * 1e18);
78-
return _stableMarket.borrowRatePerBlockAfterBorrow(borrowAmount);
78+
return _stableMarket.borrowRatePerBlockAfterBorrow(borrowAmount) * factory.blocksPerYear();
7979
}
8080

8181
/// @notice this is a lens fn, it is not intended to be used on-chain

contracts/oracles/default/RedstoneAdapterPriceOracleWeETH.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ contract RedstoneAdapterPriceOracleWeETH is BasePriceOracle {
6363
uint256 underlyingDecimals = uint256(ERC20Upgradeable(underlying).decimals());
6464
return
6565
underlyingDecimals <= 18
66-
? uint256(oraclePrice) * (10 ** (18 - underlyingDecimals))
67-
: uint256(oraclePrice) / (10 ** (underlyingDecimals - 18));
66+
? uint256(oraclePrice) * (10**(18 - underlyingDecimals))
67+
: uint256(oraclePrice) / (10**(underlyingDecimals - 18));
6868
}
6969
}

contracts/test/DevTesting.t.sol

+17-10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ contract DevTesting is BaseTest {
3333
ICErc20 usdcMarket;
3434
ICErc20 usdtMarket;
3535
ICErc20 wbtcMarket;
36+
ICErc20 ezEthMarket;
3637

3738
// mode mainnet assets
3839
address WETH = 0x4200000000000000000000000000000000000006;
@@ -54,6 +55,7 @@ contract DevTesting is BaseTest {
5455
usdcMarket = ICErc20(0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038);
5556
usdtMarket = ICErc20(0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3);
5657
wbtcMarket = ICErc20(0xd70254C3baD29504789714A7c69d60Ec1127375C);
58+
ezEthMarket = ICErc20(0x59e710215d45F584f44c0FEe83DA6d43D762D857);
5759
} else {
5860
ICErc20[] memory markets = pool.getAllMarkets();
5961
wethMarket = markets[0];
@@ -140,6 +142,17 @@ contract DevTesting is BaseTest {
140142
}
141143
}
142144

145+
function testGetCashError() public debuggingOnly fork(MODE_MAINNET) {
146+
ICErc20 market = ICErc20(0x49950319aBE7CE5c3A6C90698381b45989C99b46);
147+
market.getCash();
148+
}
149+
150+
function testWrsEthBalanceOfError() public debuggingOnly fork(MODE_MAINNET) {
151+
address wrsEthMarketAddress = 0x49950319aBE7CE5c3A6C90698381b45989C99b46;
152+
ERC20 wrsEth = ERC20(0xe7903B1F75C534Dd8159b313d92cDCfbC62cB3Cd);
153+
wrsEth.balanceOf(0x1155b614971f16758C92c4890eD338C9e3ede6b7);
154+
}
155+
143156
function testModeRepay() public debuggingOnly fork(MODE_MAINNET) {
144157
address user = 0x1A3C4E9B49e4fc595fB7e5f723159bA73a9426e7;
145158
ICErc20 market = usdcMarket;
@@ -194,12 +207,7 @@ contract DevTesting is BaseTest {
194207
}
195208

196209
function testBorrowRateAtRatio() public debuggingOnly fork(MODE_MAINNET) {
197-
uint256 rate = levPosLens.getBorrowRateAtRatio(
198-
ICErc20(0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2),
199-
ICErc20(0x59e710215d45F584f44c0FEe83DA6d43D762D857),
200-
9988992945501686,
201-
2e18
202-
);
210+
uint256 rate = levPosLens.getBorrowRateAtRatio(wethMarket, ezEthMarket, 9988992945501686, 2e18);
203211
emit log_named_uint("borrow rate at ratio", rate);
204212
}
205213

@@ -313,7 +321,6 @@ contract DevTesting is BaseTest {
313321

314322
function testModeBorrowRate() public fork(MODE_MAINNET) {
315323
//ICErc20[] memory markets = pool.getAllMarkets();
316-
ICErc20 ezEthMarket = ICErc20(0x59e710215d45F584f44c0FEe83DA6d43D762D857);
317324

318325
IonicComptroller pool = ezEthMarket.comptroller();
319326
vm.prank(pool.admin());
@@ -470,14 +477,14 @@ contract DevTesting is BaseTest {
470477
return returndata;
471478
}
472479

473-
function testRawCall() public debuggingOnly fork(MODE_MAINNET) {
474-
address caller = 0xF70CBE91fB1b1AfdeB3C45Fb8CDD2E1249b5b75E;
480+
function testRawCall() public debuggingOnly forkAtBlock(MODE_MAINNET, 7337902) {
481+
address caller = 0x2b81E6C41636BaEa95a1Da5c688cCcd938f9Af33;
475482
address target = 0x9B506A03bBFf2a842866b10BC6732da72640cd45;
476483

477484
ERC20(WETH).allowance(caller, target);
478485

479486
bytes
480-
memory data = hex"534da46000000000000000000000000071ef7eda2be775e5a7aa8afd02c45f059833e9d20000000000000000000000002be717340023c9e14c1bb12cb3ecbcfd3c3fb0380000000000000000000000004200000000000000000000000000000000000006000000000000000000000000000000000000000000000000001329713137a5260000000000000000000000000000000000000000000000000000000000000001";
487+
memory data = hex"534da46000000000000000000000000059e710215d45f584f44c0fee83da6d43d762d8570000000000000000000000002be717340023c9e14c1bb12cb3ecbcfd3c3fb0380000000000000000000000002416092f143378750bb29b79ed961ab195cceea500000000000000000000000000000000000000000000000015faebcf6161ab5d00000000000000000000000000000000000000000000000029a2241af62c0000";
481488
vm.prank(caller);
482489
_functionCall(target, data, "raw call failed");
483490
}

0 commit comments

Comments
 (0)