Skip to content

Commit ac54cd1

Browse files
Merge pull request #83 from morpho-org/refactor/various-improvements
Various improvements to wstETH adapter
2 parents 9cc2150 + e370ed9 commit ac54cd1

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/wsteth-exchange-rate-adapter/WstEthEthExchangeRateChainlinkAdapter.sol renamed to src/wsteth-exchange-rate-adapter/WstEthStEthExchangeRateChainlinkAdapter.sol

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@ pragma solidity 0.8.21;
44
import {IStEth} from "./interfaces/IStEth.sol";
55
import {MinimalAggregatorV3Interface} from "./interfaces/MinimalAggregatorV3Interface.sol";
66

7-
/// @title WstEthEthExchangeRateChainlinkAdapter
7+
/// @title WstEthStEthExchangeRateChainlinkAdapter
88
/// @author Morpho Labs
99
/// @custom:contact security@morpho.org
10-
/// @notice wstETH/ETH exchange rate price feed.
11-
/// @dev This contract should only be used as price feed for `ChainlinkOracle`.
12-
contract WstEthEthExchangeRateChainlinkAdapter is MinimalAggregatorV3Interface {
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
1314
// @dev The calculated price has 18 decimals precision, whatever the value of `decimals`.
1415
uint8 public constant decimals = 18;
15-
string public constant description = "wstETH/ETH exchange rate";
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.
1621
IStEth public constant ST_ETH = IStEth(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
1722

23+
/// @inheritdoc MinimalAggregatorV3Interface
24+
/// @dev Returns zero for roundId, startedAt, updatedAt and answeredInRound.
1825
/// @dev Silently overflows if `getPooledEthByShares`'s return value is greater than `type(int256).max`.
1926
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
2027
// It is assumed that `getPooledEthByShares` returns a price with 18 decimals precision.

src/wsteth-exchange-rate-adapter/interfaces/MinimalAggregatorV3Interface.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ pragma solidity >=0.5.0;
33

44
/// @dev Inspired by
55
/// 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`.
67
interface MinimalAggregatorV3Interface {
8+
/// @notice Returns the precision of the feed.
79
function decimals() external view returns (uint8);
810

11+
/// @notice Returns Chainlink's `latestRoundData` return values.
12+
/// @notice Only the `answer` field is used by `MorphoChainlinkOracleV2`.
913
function latestRoundData()
1014
external
1115
view

test/WstEthEthExchangeRateChainlinkAdapterTest.sol renamed to test/WstEthStEthExchangeRateChainlinkAdapterTest.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ pragma solidity ^0.8.0;
44
import "./helpers/Constants.sol";
55
import "../lib/forge-std/src/Test.sol";
66
import {ChainlinkOracle} from "../src/morpho-chainlink-v1/ChainlinkOracle.sol";
7-
import "../src/wsteth-exchange-rate-adapter/WstEthEthExchangeRateChainlinkAdapter.sol";
7+
import "../src/wsteth-exchange-rate-adapter/WstEthStEthExchangeRateChainlinkAdapter.sol";
88

9-
contract WstEthEthExchangeRateChainlinkAdapterTest is Test {
9+
contract WstEthStEthExchangeRateChainlinkAdapterTest is Test {
1010
IStEth internal constant ST_ETH = IStEth(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
1111

12-
WstEthEthExchangeRateChainlinkAdapter internal oracle;
12+
WstEthStEthExchangeRateChainlinkAdapter internal oracle;
1313
ChainlinkOracle internal chainlinkOracle;
1414

1515
function setUp() public {
1616
vm.createSelectFork(vm.envString("ETH_RPC_URL"));
17-
oracle = new WstEthEthExchangeRateChainlinkAdapter();
17+
oracle = new WstEthStEthExchangeRateChainlinkAdapter();
1818
chainlinkOracle = new ChainlinkOracle(
1919
vaultZero, AggregatorV3Interface(address(oracle)), feedZero, feedZero, feedZero, 1, 18, 18
2020
);
@@ -25,7 +25,7 @@ contract WstEthEthExchangeRateChainlinkAdapterTest is Test {
2525
}
2626

2727
function testDescription() public {
28-
assertEq(oracle.description(), "wstETH/ETH exchange rate");
28+
assertEq(oracle.description(), "wstETH/stETH exchange rate");
2929
}
3030

3131
function testLatestRoundData() public {
@@ -44,7 +44,7 @@ contract WstEthEthExchangeRateChainlinkAdapterTest is Test {
4444
assertLe(uint256(answer), 1.5e18); // Max bounds of the exchange rate. Should work for a long enough time.
4545
}
4646

47-
function testOracleWstEthEthExchangeRate() public {
47+
function testOracleWstEthStEthExchangeRate() public {
4848
(, int256 expectedPrice,,,) = oracle.latestRoundData();
4949
assertEq(chainlinkOracle.price(), uint256(expectedPrice) * 10 ** (36 + 18 - 18 - 18));
5050
}

0 commit comments

Comments
 (0)