Skip to content

Commit

Permalink
fix: handle idle markets APY
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Grimal committed Jan 8, 2024
1 parent 18ed954 commit 9c99de4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/blue/BlueSnippets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ contract BlueSnippets {
view
returns (uint256 borrowRate)
{
borrowRate = IIrm(marketParams.irm).borrowRateView(marketParams, market).wTaylorCompounded(1);
if (marketParams.irm == address(0)) {
borrowRate = 0;
} else {
borrowRate = IIrm(marketParams.irm).borrowRateView(marketParams, market).wTaylorCompounded(1);
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/metamorpho/MetaMorphoSnippets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ contract MetaMorphoSnippets {
(uint256 totalSupplyAssets,, uint256 totalBorrowAssets,) = morpho.expectedMarketBalances(marketParams);

// Get the borrow rate
uint256 borrowRate = IIrm(marketParams.irm).borrowRateView(marketParams, market);
uint256 borrowRate;
if (marketParams.irm != address(0)) {
borrowRate = IIrm(marketParams.irm).borrowRateView(marketParams, market).wTaylorCompounded(1);
}

// Get the supply rate
uint256 utilization = totalBorrowAssets == 0 ? 0 : totalBorrowAssets.wDivUp(totalSupplyAssets);
Expand Down
9 changes: 9 additions & 0 deletions test/forge/blue/TestBlueSnippets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ contract TestIntegrationSnippets is BaseTest {
assertEq(borrowTrue, borrowToTest, "Diff in snippets vs integration borrowAPY test");
}

function testBorrowAPYIdleMarket(Market memory market) public {
MarketParams memory idleMarket;
idleMarket.loanToken = address(loanToken);

uint256 borrowRate = snippets.borrowAPY(idleMarket, market);

assertEq(borrowRate, 0, "borrow rate");
}

function testSupplyAPYEqual0(Market memory market) public {
vm.assume(market.totalBorrowAssets == 0);
vm.assume(market.totalSupplyAssets > 100000);
Expand Down
15 changes: 15 additions & 0 deletions test/forge/metamorpho/TestMetaMorphoSnippets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ contract TestMetaMorphoSnippets is IntegrationTest {
assertEq(snippets.supplyAPYMarket(marketParams, market), 0, "Diff in snippets vs integration supplyAPY test");
}

function testSupplyAPYIdleMarket() public {
Market memory market;
MarketParams memory idleMarket;
idleMarket.loanToken = address(loanToken);

vm.prank(MORPHO_OWNER);
morpho.enableIrm(address(0));

morpho.createMarket(idleMarket);

uint256 supplyAPY = snippets.supplyAPYMarket(idleMarket, market);

assertEq(supplyAPY, 0, "supply APY");
}

function testSupplyAPYMarket(Market memory market) public {
vm.assume(market.totalBorrowAssets > 0);
vm.assume(market.totalBorrowShares > 0);
Expand Down

0 comments on commit 9c99de4

Please sign in to comment.