From bf3a71c0d67b7e75ab7abea575ac273861a878cc Mon Sep 17 00:00:00 2001 From: Tom Rpl Date: Mon, 27 Nov 2023 17:11:27 +0100 Subject: [PATCH] feat(snippets): updating MM code --- lib/metamorpho | 2 +- src/metamorpho/MetamorphoSnippets.sol | 28 ++++++++----------- .../metamorpho/TestMetamorphoSnippets.sol | 5 ++-- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/metamorpho b/lib/metamorpho index 74d51b9..303271e 160000 --- a/lib/metamorpho +++ b/lib/metamorpho @@ -1 +1 @@ -Subproject commit 74d51b9f5bb1fb484f0db0e8f7aa67d0f62bcc78 +Subproject commit 303271ebb30fe88dedbeeff7c1d624b9cee63509 diff --git a/src/metamorpho/MetamorphoSnippets.sol b/src/metamorpho/MetamorphoSnippets.sol index c28049b..e064719 100644 --- a/src/metamorpho/MetamorphoSnippets.sol +++ b/src/metamorpho/MetamorphoSnippets.sol @@ -4,11 +4,11 @@ pragma solidity ^0.8.0; import {IMetaMorpho} from "@metamorpho/interfaces/IMetaMorpho.sol"; import {ConstantsLib} from "@metamorpho/libraries/ConstantsLib.sol"; -import {MarketParamsLib} from "@morpho-blue/libraries/MarketParamsLib.sol"; -import {Id, IMorpho, Market, MarketParams} from "@morpho-blue/interfaces/IMorpho.sol"; -import {IrmMock} from "@metamorpho/mocks/IrmMock.sol"; -import {MorphoBalancesLib} from "@morpho-blue/libraries/periphery/MorphoBalancesLib.sol"; -import {MathLib, WAD} from "@morpho-blue/libraries/MathLib.sol"; +import {MarketParamsLib} from "../../lib/metamorpho/lib/morpho-blue/src/libraries/MarketParamsLib.sol"; +import {Id, IMorpho, Market, MarketParams} from "../../lib/metamorpho/lib/morpho-blue/src/interfaces/IMorpho.sol"; +import {IIrm} from "../../lib/metamorpho/lib/morpho-blue/src/interfaces/IIrm.sol"; +import {MorphoBalancesLib} from "../../lib/metamorpho/lib/morpho-blue/src/libraries/periphery/MorphoBalancesLib.sol"; +import {MathLib, WAD} from "../../lib/metamorpho/lib/morpho-blue/src/libraries/MathLib.sol"; import {Math} from "@openzeppelin/utils/math/Math.sol"; import {ERC20} from "@openzeppelin/token/ERC20/ERC20.sol"; @@ -52,7 +52,7 @@ contract MetamorphoSnippets { return supplyQueueList; } - // The following function will return the current withdraw queue of the vault + // // The following function will return the current withdraw queue of the vault function withdrawQueueVault() public view returns (Id[] memory withdrawQueueList) { uint256 queueLength = vault.supplyQueueLength(); withdrawQueueList = new Id[](queueLength); @@ -75,7 +75,7 @@ contract MetamorphoSnippets { (uint256 totalSupplyAssets,, uint256 totalBorrowAssets,) = morpho.expectedMarketBalances(marketParams); // Get the borrow rate - uint256 borrowRate = IrmMock(marketParams.irm).borrowRateView(marketParams, market); + uint256 borrowRate = IIrm(marketParams.irm).borrowRateView(marketParams, market); // Get the supply rate uint256 utilization = totalBorrowAssets == 0 ? 0 : totalBorrowAssets.wDivUp(totalSupplyAssets); @@ -86,17 +86,11 @@ contract MetamorphoSnippets { function supplyAPRVault() public view returns (uint256 avgSupplyRate) { uint256 ratio; uint256 queueLength = vault.withdrawQueueLength(); - - // TODO: Verify that the idle liquidity is taken into account uint256 totalAmount = totalDepositVault(); for (uint256 i; i < queueLength; ++i) { Id idMarket = vault.withdrawQueue(i); - - (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) = - (morpho.idToMarketParams(idMarket)); - - MarketParams memory marketParams = MarketParams(loanToken, collateralToken, oracle, irm, lltv); + MarketParams memory marketParams = morpho.idToMarketParams(idMarket); Market memory market = morpho.market(idMarket); uint256 currentSupplyAPR = supplyAPRMarket(marketParams, market); @@ -107,7 +101,7 @@ contract MetamorphoSnippets { avgSupplyRate = ratio.wDivUp(totalAmount); } - // --- MANAGING FUNCTIONS --- + // // --- MANAGING FUNCTIONS --- // deposit in the vault a nb of asset function depositInVault(uint256 assets, address onBehalf) public returns (uint256 shares) { @@ -134,6 +128,6 @@ contract MetamorphoSnippets { redeemed = vault.redeem(maxToRedeem, receiver, onBehalf); } - // TODO: - // Reallocation example + // // TODO: + // // Reallocation example } diff --git a/test/forge/metamorpho/TestMetamorphoSnippets.sol b/test/forge/metamorpho/TestMetamorphoSnippets.sol index 60b775d..1a167aa 100644 --- a/test/forge/metamorpho/TestMetamorphoSnippets.sol +++ b/test/forge/metamorpho/TestMetamorphoSnippets.sol @@ -3,8 +3,7 @@ pragma solidity ^0.8.0; import {MetamorphoSnippets} from "@snippets/metamorpho/MetamorphoSnippets.sol"; import "@metamorpho-test/helpers/IntegrationTest.sol"; -import "@morpho-blue/libraries/SharesMathLib.sol"; -import {MorphoBalancesLib} from "@morpho-blue/libraries/periphery/MorphoBalancesLib.sol"; + import {SafeCast} from "@openzeppelin/utils/math/SafeCast.sol"; contract TestIntegrationSnippets is IntegrationTest { @@ -15,11 +14,11 @@ contract TestIntegrationSnippets is IntegrationTest { using MathLib for uint256; using Math for uint256; using MarketParamsLib for MarketParams; - using SharesMathLib for uint256; function setUp() public virtual override { super.setUp(); snippets = new MetamorphoSnippets(address(vault), address(morpho)); + _setCap(allMarkets[0], CAP); _sortSupplyQueueIdleLast(); }