-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1297 from morpho-dao/fix/staked-eth
Staked ETH Refactor
- Loading branch information
Showing
17 changed files
with
185 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: GNU AGPLv3 | ||
pragma solidity ^0.8.0; | ||
|
||
interface ILido { | ||
function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256); | ||
|
||
function submit(address _referral) external payable returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
// SPDX-License-Identifier: GNU AGPLv3 | ||
pragma solidity 0.8.13; | ||
|
||
import "../interfaces/IInterestRatesManager.sol"; | ||
import "../interfaces/lido/ILido.sol"; | ||
|
||
import "./LensStorage.sol"; | ||
|
||
/// @title IndexesLens. | ||
/// @author Morpho Labs. | ||
/// @custom:contact [email protected] | ||
/// @notice Intermediary layer exposing endpoints to query live data related to the Morpho Protocol market indexes & rates. | ||
abstract contract IndexesLens is LensStorage { | ||
using WadRayMath for uint256; | ||
|
||
/// PUBLIC /// | ||
|
||
/// @notice Returns the updated peer-to-peer supply index. | ||
|
@@ -78,10 +83,12 @@ abstract contract IndexesLens is LensStorage { | |
Types.PoolIndexes memory lastPoolIndexes = morpho.poolIndexes(_poolToken); | ||
underlyingToken = market.underlyingToken; | ||
|
||
(poolSupplyIndex, poolBorrowIndex) = _getPoolIndexes(market.underlyingToken); | ||
|
||
InterestRatesModel.GrowthFactors memory growthFactors = InterestRatesModel | ||
.computeGrowthFactors( | ||
poolSupplyIndex = pool.getReserveNormalizedIncome(underlyingToken), | ||
poolBorrowIndex = pool.getReserveNormalizedVariableDebt(underlyingToken), | ||
poolSupplyIndex, | ||
poolBorrowIndex, | ||
lastPoolIndexes, | ||
market.p2pIndexCursor, | ||
market.reserveFactor | ||
|
@@ -129,10 +136,12 @@ abstract contract IndexesLens is LensStorage { | |
Types.Delta memory delta = morpho.deltas(_poolToken); | ||
Types.PoolIndexes memory lastPoolIndexes = morpho.poolIndexes(_poolToken); | ||
|
||
(poolSupplyIndex, poolBorrowIndex) = _getPoolIndexes(market.underlyingToken); | ||
|
||
InterestRatesModel.GrowthFactors memory growthFactors = InterestRatesModel | ||
.computeGrowthFactors( | ||
poolSupplyIndex = pool.getReserveNormalizedIncome(market.underlyingToken), | ||
poolBorrowIndex = pool.getReserveNormalizedVariableDebt(market.underlyingToken), | ||
poolSupplyIndex, | ||
poolBorrowIndex, | ||
lastPoolIndexes, | ||
market.p2pIndexCursor, | ||
market.reserveFactor | ||
|
@@ -170,10 +179,12 @@ abstract contract IndexesLens is LensStorage { | |
Types.Delta memory delta = morpho.deltas(_poolToken); | ||
Types.PoolIndexes memory lastPoolIndexes = morpho.poolIndexes(_poolToken); | ||
|
||
(poolSupplyIndex, poolBorrowIndex) = _getPoolIndexes(market.underlyingToken); | ||
|
||
InterestRatesModel.GrowthFactors memory growthFactors = InterestRatesModel | ||
.computeGrowthFactors( | ||
poolSupplyIndex = pool.getReserveNormalizedIncome(market.underlyingToken), | ||
poolBorrowIndex = pool.getReserveNormalizedVariableDebt(market.underlyingToken), | ||
poolSupplyIndex, | ||
poolBorrowIndex, | ||
lastPoolIndexes, | ||
market.p2pIndexCursor, | ||
market.reserveFactor | ||
|
@@ -190,4 +201,25 @@ abstract contract IndexesLens is LensStorage { | |
}) | ||
); | ||
} | ||
|
||
/// @notice Returns the current pool indexes. | ||
/// @param _underlyingToken The address of the underlying token. | ||
/// @return poolSupplyIndex The pool supply index. | ||
/// @return poolBorrowIndex The pool borrow index. | ||
function _getPoolIndexes(address _underlyingToken) | ||
internal | ||
view | ||
returns (uint256 poolSupplyIndex, uint256 poolBorrowIndex) | ||
{ | ||
poolSupplyIndex = pool.getReserveNormalizedIncome(_underlyingToken); | ||
poolBorrowIndex = pool.getReserveNormalizedVariableDebt(_underlyingToken); | ||
|
||
if (_underlyingToken == ST_ETH) { | ||
uint256 rebaseIndex = ILido(ST_ETH).getPooledEthByShares(WadRayMath.RAY); | ||
uint256 baseRebaseIndex = morpho.interestRatesManager().ST_ETH_BASE_REBASE_INDEX(); | ||
|
||
poolSupplyIndex = poolSupplyIndex.rayMul(rebaseIndex).rayDiv(baseRebaseIndex); | ||
poolBorrowIndex = poolBorrowIndex.rayMul(rebaseIndex).rayDiv(baseRebaseIndex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.