Skip to content

Commit

Permalink
Merge pull request #120 from Instadapp/metamorpho-resolver
Browse files Browse the repository at this point in the history
Update resolver
  • Loading branch information
shriyatyagii authored Jan 28, 2024
2 parents fd787b0 + 5a4fb52 commit 1d85540
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
16 changes: 16 additions & 0 deletions contracts/protocols/mainnet/metamorpho/interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,20 @@ 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);
}

interface IRewardsEmissions {
function rewardsEmissions(
address sender,
address urd,
address rewardToken,
bytes32 marketId
)
external
view
returns (
uint256 supplyRewardTokensPerYear,
uint256 borrowRewardTokensPerYear,
uint256 collateralRewardTokensPerYear
);
}
38 changes: 37 additions & 1 deletion contracts/protocols/mainnet/metamorpho/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ contract MetamorphoResolver {
using MorphoBalancesLib for IMorpho;

address internal constant MORPHO_BLUE = 0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb;
address internal constant REWARDS_EMISSIONS = 0xf27fa85b6748c8a64d4b0D3D6083Eb26f18BDE8e;

struct VaultData {
bool isToken;
string name;
string symbol;
uint256 decimals;
address asset;
uint256 assetDecimals;
uint256 totalAssets;
uint256 totalSupply;
uint256 convertToShares;
Expand Down Expand Up @@ -84,6 +86,7 @@ contract MetamorphoResolver {
vaultToken.symbol(),
vaultToken.decimals(),
vaultToken.asset(),
_underlyingToken.decimals(),
vaultToken.totalAssets(),
vaultToken.totalSupply(),
vaultToken.convertToShares(10 ** _underlyingToken.decimals()), // example convertToShares
Expand Down Expand Up @@ -141,7 +144,9 @@ contract MetamorphoResolver {
return _vaultPreview;
}

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

VaultData[] memory _vaultDatas = getVaultDetails(vaultAddresses);
Expand Down Expand Up @@ -180,6 +185,37 @@ contract MetamorphoResolver {
return _metaMorphotData;
}

// Note sender, urd and rewardToken lengths must be equal.
function getRewardEmissions(
address[] memory sender, // Sender of each reward token
address[] memory urd, // Urd of each reward token
address[] memory rewardToken, // Array of all reward tokens
bytes32 marketId // Market ID whose rewards we need to calculate
) public view returns (uint256[] memory, uint256[] memory, uint256[] memory) {
IRewardsEmissions rewardsContract = IRewardsEmissions(REWARDS_EMISSIONS);

uint256 length = rewardToken.length;

uint256[] memory supplyRewards = new uint256[](length);
uint256[] memory borrowRewards = new uint256[](length);
uint256[] memory collateralRewards = new uint256[](length);

for (uint8 i = 0; i < length; i++) {
(
supplyRewards[i],
borrowRewards[i],
collateralRewards[i]
) = rewardsContract.rewardsEmissions(
sender[i],
urd[i],
rewardToken[i],
marketId
);
}

return (supplyRewards, borrowRewards, collateralRewards);
}

/// @notice Returns the current APY of the vault on a Morpho Blue market.
/// @param marketParams The morpho blue market parameters.
/// @param market The morpho blue market state.
Expand Down
44 changes: 44 additions & 0 deletions test/mainnet/metamorpho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ describe("Metamorpho Resolver", () => {
'0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB',
];

const sender = '0x640428D38189B11B844dAEBDBAAbbdfbd8aE0143'
const morphoURD = '0x678dDC1d07eaa166521325394cDEb1E4c086DF43'
const wstethURD = '0x2EfD4625d0c149EbADf118EC5446c6de24d916A4'
const morphoAddress = '0x9994E35Db50125E0DF82e4c2dde62496CE330999'
const wstethAddress = '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'
const wstethEthId = "0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41"
const wstethUsdcId = "0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc"

before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
Expand All @@ -36,6 +44,20 @@ describe("Metamorpho Resolver", () => {
let resolver: InstaMetamorphoResolver;

before(async () => {
// await hre.network.provider.request({
// method: "hardhat_reset",
// params: [
// {
// forking: {
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// // @ts-ignore
// jsonRpcUrl: hre.config.networks.hardhat.forking.url,
// blockNumber: 19107703,
// },
// },
// ],
// });

const deployer = new InstaMetamorphoResolver__factory(signer);
resolver = await deployer.deploy();
});
Expand Down Expand Up @@ -87,5 +109,27 @@ describe("Metamorpho Resolver", () => {

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

it("should get wsteth-eth reward details", async () => {
const rewards = await resolver.getRewardEmissions(
[sender, sender],
[morphoURD, wstethURD],
[morphoAddress, wstethAddress],
wstethEthId
);

console.log("rewards wsteth-eth:>> ", rewards);
});

it("should get wsteth-usdc reward details", async () => {
const rewards = await resolver.getRewardEmissions(
[sender, sender],
[morphoURD, wstethURD],
[morphoAddress, wstethAddress],
wstethUsdcId
);

console.log("rewards wsteth-usdc:>> ", rewards);
});
});
});

0 comments on commit 1d85540

Please sign in to comment.