From 53696c80e0abced58de07e8ba349724d4d5a5aad Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Mon, 29 Jan 2024 03:00:52 +0530 Subject: [PATCH 1/2] feat: update resolver --- .../mainnet/metamorpho/interface.sol | 16 +++++++ .../protocols/mainnet/metamorpho/main.sol | 39 +++++++++++++++- test/mainnet/metamorpho.ts | 44 +++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/contracts/protocols/mainnet/metamorpho/interface.sol b/contracts/protocols/mainnet/metamorpho/interface.sol index a6d0d92..f70c0e2 100644 --- a/contracts/protocols/mainnet/metamorpho/interface.sol +++ b/contracts/protocols/mainnet/metamorpho/interface.sol @@ -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 + ); } \ No newline at end of file diff --git a/contracts/protocols/mainnet/metamorpho/main.sol b/contracts/protocols/mainnet/metamorpho/main.sol index 7c36133..aa52a59 100644 --- a/contracts/protocols/mainnet/metamorpho/main.sol +++ b/contracts/protocols/mainnet/metamorpho/main.sol @@ -12,6 +12,7 @@ contract MetamorphoResolver { using MorphoBalancesLib for IMorpho; address internal constant MORPHO_BLUE = 0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb; + address internal constant REWARDS_EMISSIONS = 0xf27fa85b6748c8a64d4b0D3D6083Eb26f18BDE8e; struct VaultData { bool isToken; @@ -19,6 +20,7 @@ contract MetamorphoResolver { string symbol; uint256 decimals; address asset; + uint256 assetDecimals; uint256 totalAssets; uint256 totalSupply; uint256 convertToShares; @@ -47,6 +49,7 @@ contract MetamorphoResolver { uint256 fee; bool enabled; // Whether the market is in the withdraw queue uint256 apy; + uint256 underlyingDecimals; VaultData vaultData; } @@ -84,6 +87,7 @@ contract MetamorphoResolver { vaultToken.symbol(), vaultToken.decimals(), vaultToken.asset(), + _underlyingToken.decimals(), vaultToken.totalAssets(), vaultToken.totalSupply(), vaultToken.convertToShares(10 ** _underlyingToken.decimals()), // example convertToShares @@ -141,7 +145,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); @@ -180,6 +186,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. diff --git a/test/mainnet/metamorpho.ts b/test/mainnet/metamorpho.ts index 948c513..85269b0 100644 --- a/test/mainnet/metamorpho.ts +++ b/test/mainnet/metamorpho.ts @@ -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", @@ -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(); }); @@ -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); + }); }); }); From 5a4fb520b86eb45372b0708146428fa96e7f63ed Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Mon, 29 Jan 2024 03:03:17 +0530 Subject: [PATCH 2/2] wip --- contracts/protocols/mainnet/metamorpho/main.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/protocols/mainnet/metamorpho/main.sol b/contracts/protocols/mainnet/metamorpho/main.sol index aa52a59..4d66d26 100644 --- a/contracts/protocols/mainnet/metamorpho/main.sol +++ b/contracts/protocols/mainnet/metamorpho/main.sol @@ -49,7 +49,6 @@ contract MetamorphoResolver { uint256 fee; bool enabled; // Whether the market is in the withdraw queue uint256 apy; - uint256 underlyingDecimals; VaultData vaultData; }