Skip to content

Commit 756347b

Browse files
authored
Merge pull request #65 from morpho-org/feat/wsteth-oracle
wstETH/ETH oracle using exchange rate only
2 parents 3e7297c + ac54cd1 commit 756347b

13 files changed

+134
-26
lines changed

src/ChainlinkOracle.sol renamed to src/morpho-chainlink-v1/ChainlinkOracle.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
pragma solidity 0.8.21;
33

44
import {IChainlinkOracle} from "./interfaces/IChainlinkOracle.sol";
5-
import {IOracle} from "../lib/morpho-blue/src/interfaces/IOracle.sol";
5+
import {IOracle} from "../../lib/morpho-blue/src/interfaces/IOracle.sol";
66

77
import {AggregatorV3Interface, ChainlinkDataFeedLib} from "./libraries/ChainlinkDataFeedLib.sol";
88
import {IERC4626, VaultLib} from "./libraries/VaultLib.sol";
99
import {ErrorsLib} from "./libraries/ErrorsLib.sol";
10-
import {Math} from "../lib/openzeppelin-contracts/contracts/utils/math/Math.sol";
10+
import {Math} from "../../lib/openzeppelin-contracts/contracts/utils/math/Math.sol";
1111

1212
/// @title ChainlinkOracle
1313
/// @author Morpho Labs

src/interfaces/IChainlinkOracle.sol renamed to src/morpho-chainlink-v1/interfaces/IChainlinkOracle.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity >=0.5.0;
33

44
import {IERC4626} from "./IERC4626.sol";
55
import {AggregatorV3Interface} from "./AggregatorV3Interface.sol";
6-
import {IOracle} from "../../lib/morpho-blue/src/interfaces/IOracle.sol";
6+
import {IOracle} from "../../../lib/morpho-blue/src/interfaces/IOracle.sol";
77

88
/// @title IChainlinkOracle
99
/// @author Morpho Labs
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity 0.8.21;
3+
4+
import {IStEth} from "./interfaces/IStEth.sol";
5+
import {MinimalAggregatorV3Interface} from "./interfaces/MinimalAggregatorV3Interface.sol";
6+
7+
/// @title WstEthStEthExchangeRateChainlinkAdapter
8+
/// @author Morpho Labs
9+
/// @custom:contact security@morpho.org
10+
/// @notice wstETH/stETH exchange rate price feed.
11+
/// @dev This contract should only be deployed on Ethereum and used as a price feed for Morpho oracles.
12+
contract WstEthStEthExchangeRateChainlinkAdapter is MinimalAggregatorV3Interface {
13+
/// @inheritdoc MinimalAggregatorV3Interface
14+
// @dev The calculated price has 18 decimals precision, whatever the value of `decimals`.
15+
uint8 public constant decimals = 18;
16+
17+
/// @notice The description of the price feed.
18+
string public constant description = "wstETH/stETH exchange rate";
19+
20+
/// @notice The address of stETH on Ethereum.
21+
IStEth public constant ST_ETH = IStEth(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
22+
23+
/// @inheritdoc MinimalAggregatorV3Interface
24+
/// @dev Returns zero for roundId, startedAt, updatedAt and answeredInRound.
25+
/// @dev Silently overflows if `getPooledEthByShares`'s return value is greater than `type(int256).max`.
26+
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
27+
// It is assumed that `getPooledEthByShares` returns a price with 18 decimals precision.
28+
return (0, int256(ST_ETH.getPooledEthByShares(1 ether)), 0, 0, 0);
29+
}
30+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity >=0.5.0;
3+
4+
interface IStEth {
5+
function getPooledEthByShares(uint256) external view returns (uint256);
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.5.0;
3+
4+
/// @dev Inspired by
5+
/// https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol
6+
/// @dev This is the minimal feed interface required by `MorphoChainlinkOracleV2`.
7+
interface MinimalAggregatorV3Interface {
8+
/// @notice Returns the precision of the feed.
9+
function decimals() external view returns (uint8);
10+
11+
/// @notice Returns Chainlink's `latestRoundData` return values.
12+
/// @notice Only the `answer` field is used by `MorphoChainlinkOracleV2`.
13+
function latestRoundData()
14+
external
15+
view
16+
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
17+
}

0 commit comments

Comments
 (0)