Skip to content

Commit

Permalink
feat(snippets): updating MM code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrpl committed Nov 27, 2023
1 parent 3c39483 commit bf3a71c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
28 changes: 11 additions & 17 deletions src/metamorpho/MetamorphoSnippets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -134,6 +128,6 @@ contract MetamorphoSnippets {
redeemed = vault.redeem(maxToRedeem, receiver, onBehalf);
}

// TODO:
// Reallocation example
// // TODO:
// // Reallocation example
}
5 changes: 2 additions & 3 deletions test/forge/metamorpho/TestMetamorphoSnippets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
Expand Down

0 comments on commit bf3a71c

Please sign in to comment.