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

Commit

Permalink
Merge pull request #60 from ionicprotocol/fix/lens-blocks-per-year-rate
Browse files Browse the repository at this point in the history
Leftovers fix and lens blocks per year rate
  • Loading branch information
vminkov authored May 6, 2024
2 parents ff2a7b8 + 6edc29e commit 2d81f9f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
5 changes: 5 additions & 0 deletions contracts/ionic/levered/LeveredPosition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ contract LeveredPosition is LeveredPositionStorage, IFlashLoanReceiver {
errorCode = collateralMarket.redeem(collateralMarket.balanceOf(address(this)));
if (errorCode != 0) revert RedeemFailed(errorCode);

if (stableAsset.balanceOf(address(this)) > 0) {
// convert all overborrowed leftovers/profits to the collateral asset
convertAllTo(stableAsset, collateralAsset);
}

// withdraw the redeemed collateral
withdrawAmount = collateralAsset.balanceOf(address(this));
collateralAsset.safeTransfer(withdrawTo, withdrawAmount);
Expand Down
2 changes: 1 addition & 1 deletion contracts/ionic/levered/LeveredPositionsLens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract LeveredPositionsLens is Initializable {

uint256 borrowAmount = ((_targetLeverageRatio - 1e18) * _equityAmount * collateralAssetPrice) /
(stableAssetPrice * 1e18);
return _stableMarket.borrowRatePerBlockAfterBorrow(borrowAmount);
return _stableMarket.borrowRatePerBlockAfterBorrow(borrowAmount) * factory.blocksPerYear();
}

/// @notice this is a lens fn, it is not intended to be used on-chain
Expand Down
4 changes: 2 additions & 2 deletions contracts/oracles/default/RedstoneAdapterPriceOracleWeETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract RedstoneAdapterPriceOracleWeETH is BasePriceOracle {
uint256 underlyingDecimals = uint256(ERC20Upgradeable(underlying).decimals());
return
underlyingDecimals <= 18
? uint256(oraclePrice) * (10 ** (18 - underlyingDecimals))
: uint256(oraclePrice) / (10 ** (underlyingDecimals - 18));
? uint256(oraclePrice) * (10**(18 - underlyingDecimals))
: uint256(oraclePrice) / (10**(underlyingDecimals - 18));
}
}
27 changes: 17 additions & 10 deletions contracts/test/DevTesting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ contract DevTesting is BaseTest {
ICErc20 usdcMarket;
ICErc20 usdtMarket;
ICErc20 wbtcMarket;
ICErc20 ezEthMarket;

// mode mainnet assets
address WETH = 0x4200000000000000000000000000000000000006;
Expand All @@ -54,6 +55,7 @@ contract DevTesting is BaseTest {
usdcMarket = ICErc20(0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038);
usdtMarket = ICErc20(0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3);
wbtcMarket = ICErc20(0xd70254C3baD29504789714A7c69d60Ec1127375C);
ezEthMarket = ICErc20(0x59e710215d45F584f44c0FEe83DA6d43D762D857);
} else {
ICErc20[] memory markets = pool.getAllMarkets();
wethMarket = markets[0];
Expand Down Expand Up @@ -140,6 +142,17 @@ contract DevTesting is BaseTest {
}
}

function testGetCashError() public debuggingOnly fork(MODE_MAINNET) {
ICErc20 market = ICErc20(0x49950319aBE7CE5c3A6C90698381b45989C99b46);
market.getCash();
}

function testWrsEthBalanceOfError() public debuggingOnly fork(MODE_MAINNET) {
address wrsEthMarketAddress = 0x49950319aBE7CE5c3A6C90698381b45989C99b46;
ERC20 wrsEth = ERC20(0xe7903B1F75C534Dd8159b313d92cDCfbC62cB3Cd);
wrsEth.balanceOf(0x1155b614971f16758C92c4890eD338C9e3ede6b7);
}

function testModeRepay() public debuggingOnly fork(MODE_MAINNET) {
address user = 0x1A3C4E9B49e4fc595fB7e5f723159bA73a9426e7;
ICErc20 market = usdcMarket;
Expand Down Expand Up @@ -194,12 +207,7 @@ contract DevTesting is BaseTest {
}

function testBorrowRateAtRatio() public debuggingOnly fork(MODE_MAINNET) {
uint256 rate = levPosLens.getBorrowRateAtRatio(
ICErc20(0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2),
ICErc20(0x59e710215d45F584f44c0FEe83DA6d43D762D857),
9988992945501686,
2e18
);
uint256 rate = levPosLens.getBorrowRateAtRatio(wethMarket, ezEthMarket, 9988992945501686, 2e18);
emit log_named_uint("borrow rate at ratio", rate);
}

Expand Down Expand Up @@ -313,7 +321,6 @@ contract DevTesting is BaseTest {

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

IonicComptroller pool = ezEthMarket.comptroller();
vm.prank(pool.admin());
Expand Down Expand Up @@ -470,14 +477,14 @@ contract DevTesting is BaseTest {
return returndata;
}

function testRawCall() public debuggingOnly fork(MODE_MAINNET) {
address caller = 0xF70CBE91fB1b1AfdeB3C45Fb8CDD2E1249b5b75E;
function testRawCall() public debuggingOnly forkAtBlock(MODE_MAINNET, 7337902) {
address caller = 0x2b81E6C41636BaEa95a1Da5c688cCcd938f9Af33;
address target = 0x9B506A03bBFf2a842866b10BC6732da72640cd45;

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

bytes
memory data = hex"534da46000000000000000000000000071ef7eda2be775e5a7aa8afd02c45f059833e9d20000000000000000000000002be717340023c9e14c1bb12cb3ecbcfd3c3fb0380000000000000000000000004200000000000000000000000000000000000006000000000000000000000000000000000000000000000000001329713137a5260000000000000000000000000000000000000000000000000000000000000001";
memory data = hex"534da46000000000000000000000000059e710215d45f584f44c0fee83da6d43d762d8570000000000000000000000002be717340023c9e14c1bb12cb3ecbcfd3c3fb0380000000000000000000000002416092f143378750bb29b79ed961ab195cceea500000000000000000000000000000000000000000000000015faebcf6161ab5d00000000000000000000000000000000000000000000000029a2241af62c0000";
vm.prank(caller);
_functionCall(target, data, "raw call failed");
}
Expand Down

0 comments on commit 2d81f9f

Please sign in to comment.