Skip to content

Commit

Permalink
Merge branch 'main' into morpho-blue
Browse files Browse the repository at this point in the history
  • Loading branch information
shriyatyagii committed Jan 18, 2024
2 parents afaeff2 + f770729 commit c1ffbcb
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 12 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json

This file was deleted.

17 changes: 16 additions & 1 deletion contracts/protocols/mainnet/erc4626/interfaces.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
pragma solidity >=0.8.19;

type Id is bytes32;

interface TokenInterface {
function balanceOf(address) external view returns (uint256);
Expand Down Expand Up @@ -52,3 +54,16 @@ interface VaultInterface {

function maxRedeem(address owner) external view returns (uint256);
}

interface MorphoBlueInterface {
function idToMarketParams(Id id)
external
view
returns (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv);
}

interface MetaMorphoInterface {
function fee() external view returns (uint96);
function supplyQueue(uint256) external view returns (Id);
function config(Id) external view returns (uint184 cap, bool enabled, uint64 removableAt);
}
71 changes: 63 additions & 8 deletions contracts/protocols/mainnet/erc4626/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity >=0.8.0;
import "./interfaces.sol";

contract Resolver {
address internal constant MORPHO_BLUE = 0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb;

struct VaultData {
bool isToken;
string name;
Expand All @@ -25,6 +27,18 @@ contract Resolver {
uint256 previewMint;
uint256 previewWithdraw;
uint256 previewRedeem;
uint256 decimals;
uint256 underlyingDecimals;
}

struct MetaMorphoDetails {
uint256 totalCap;
address loanToken;
address collateralToken;
uint256 lltv;
uint256 fee;
bool enabled; // Whether the market is in the withdraw queue
VaultData vaultData;
}

function getVaultDetails(address[] memory vaultAddresses) public view returns (VaultData[] memory) {
Expand Down Expand Up @@ -53,6 +67,8 @@ contract Resolver {
continue;
}

TokenInterface _underlyingToken = TokenInterface(vaultToken.asset());

_vaultData[i] = VaultData(
isToken,
vaultToken.name(),
Expand All @@ -61,8 +77,8 @@ contract Resolver {
vaultToken.asset(),
vaultToken.totalAssets(),
vaultToken.totalSupply(),
vaultToken.convertToShares(10**vaultToken.decimals()), // example convertToShares for 10 ** decimal
vaultToken.convertToAssets(10**vaultToken.decimals()) // example convertToAssets for 10 ** decimal
vaultToken.convertToShares(10 ** _underlyingToken.decimals()), // example convertToShares
vaultToken.convertToAssets(10 ** vaultToken.decimals()) // example convertToAssets for 10 ** decimal
);
}

Expand Down Expand Up @@ -95,11 +111,10 @@ contract Resolver {
return _tokenAllowance;
}

function getVaultPreview(uint256 amount, address[] memory vaultAddresses)
public
view
returns (VaultPreview[] memory)
{
function getVaultPreview(
uint256 amount,
address[] memory vaultAddresses
) public view returns (VaultPreview[] memory) {
VaultPreview[] memory _vaultPreview = new VaultPreview[](vaultAddresses.length);

for (uint256 i = 0; i < vaultAddresses.length; i++) {
Expand All @@ -109,12 +124,52 @@ contract Resolver {
_vaultPreview[i].previewMint = vaultToken.previewMint(amount);
_vaultPreview[i].previewWithdraw = vaultToken.previewWithdraw(amount);
_vaultPreview[i].previewRedeem = vaultToken.previewRedeem(amount);
_vaultPreview[i].decimals = vaultToken.decimals();
TokenInterface _underlyingToken = TokenInterface(vaultToken.asset());
_vaultPreview[i].underlyingDecimals = _underlyingToken.decimals();
}

return _vaultPreview;
}

function getMetaMorphoDetails(address[] memory vaultAddresses) public view returns (MetaMorphoDetails[] memory) {
MetaMorphoDetails[] memory _metaMorphotData = new MetaMorphoDetails[](vaultAddresses.length);

VaultData[] memory _vaultDatas = getVaultDetails(vaultAddresses);

for (uint256 i = 0; i < vaultAddresses.length; i++) {
MetaMorphoInterface vaultToken = MetaMorphoInterface(vaultAddresses[i]);

try vaultToken.fee() {} catch {
continue;
}

try vaultToken.supplyQueue(0) {} catch {
continue;
}

(
_metaMorphotData[i].loanToken,
_metaMorphotData[i].collateralToken,
,
,
_metaMorphotData[i].lltv
) = MorphoBlueInterface(MORPHO_BLUE).idToMarketParams(vaultToken.supplyQueue(0));

uint184 cap;
(cap, _metaMorphotData[i].enabled, ) = vaultToken.config(vaultToken.supplyQueue(0));

_metaMorphotData[i].totalCap = uint256(cap);

_metaMorphotData[i].fee = vaultToken.fee();

_metaMorphotData[i].vaultData = _vaultDatas[i];
}

return _metaMorphotData;
}
}

contract InstaERC4626Resolver is Resolver {
string public constant name = "ERC4626-Resolver-v1";
string public constant name = "ERC4626-Resolver-v1.1";
}
14 changes: 12 additions & 2 deletions test/mainnet/erc4626.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { parseUnits, parseEther } from "ethers/lib/utils";
import { ethers, network } from "hardhat";
import { parseEther } from "ethers/lib/utils";
import { ethers } from "hardhat";
import { InstaERC4626Resolver, InstaERC4626Resolver__factory } from "../../typechain";

describe("ERC4626 Resolvers", () => {
Expand Down Expand Up @@ -93,5 +93,15 @@ describe("ERC4626 Resolvers", () => {

console.log("_vaultPreview :>> ", _vaultPreview);
});

it("gets MetaMorpho Details", async () => {
const metaMorphoMarkets = [
'0x38989bba00bdf8181f4082995b3deae96163ac5d',
'0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB',
]
const _metamorphpDetails = await resolver.getMetaMorphoDetails(metaMorphoMarkets);

console.log("_metamorphpDetails :>> ", _metamorphpDetails);
});
});
});

0 comments on commit c1ffbcb

Please sign in to comment.