Skip to content

Commit

Permalink
Merge pull request #81 from morpho-org/refactor/use-steth-directly
Browse files Browse the repository at this point in the history
Use stETH directly
  • Loading branch information
MathisGD authored Mar 5, 2024
2 parents d21e940 + 03039ae commit ad5e168
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.21;

import {IWstEth} from "./interfaces/IWstEth.sol";
import {IStEth} from "./interfaces/IStEth.sol";
import {MinimalAggregatorV3Interface} from "./interfaces/MinimalAggregatorV3Interface.sol";

import {ErrorsLib} from "./libraries/ErrorsLib.sol";
Expand All @@ -12,20 +12,21 @@ import {ErrorsLib} from "./libraries/ErrorsLib.sol";
/// @notice wstETH/ETH exchange rate price feed.
/// @dev This contract should only be used as price feed for `ChainlinkOracle`.
contract WstEthEthExchangeRateChainlinkAdapter is MinimalAggregatorV3Interface {
// @dev The calculated price has 18 decimals precision, whatever the value of `decimals`.
uint8 public constant decimals = 18;
string public constant description = "wstETH/ETH exchange rate";

IWstEth public immutable WST_ETH;
IStEth public immutable ST_ETH;

constructor(address wstEth) {
require(wstEth != address(0), ErrorsLib.ZERO_ADDRESS);
constructor(address stEth) {
require(stEth != address(0), ErrorsLib.ZERO_ADDRESS);

WST_ETH = IWstEth(wstEth);
ST_ETH = IStEth(stEth);
}

/// @dev Silently overflows if `stEthPerToken` is greater than `type(int256).max`.
/// @dev Silently overflows if `getPooledEthByShares`'s return value is greater than `type(int256).max`.
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
// It is assumed that `stEthPerToken` returns a price with 18 decimals precision.
return (0, int256(WST_ETH.stEthPerToken()), 0, 0, 0);
// It is assumed that `getPooledEthByShares` returns a price with 18 decimals precision.
return (0, int256(ST_ETH.getPooledEthByShares(1 ether)), 0, 0, 0);
}
}
6 changes: 6 additions & 0 deletions src/wsteth-exchange-rate-adapter/interfaces/IStEth.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

interface IStEth {
function getPooledEthByShares(uint256) external view returns (uint256);
}
6 changes: 0 additions & 6 deletions src/wsteth-exchange-rate-adapter/interfaces/IWstEth.sol

This file was deleted.

6 changes: 3 additions & 3 deletions test/WstEthEthExchangeRateChainlinkAdapterTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {ChainlinkOracle} from "../src/morpho-chainlink-v1/ChainlinkOracle.sol";
import "../src/wsteth-exchange-rate-adapter/WstEthEthExchangeRateChainlinkAdapter.sol";

contract WstEthEthExchangeRateChainlinkAdapterTest is Test {
IWstEth internal constant WST_ETH = IWstEth(0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0);
IStEth internal constant ST_ETH = IStEth(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);

WstEthEthExchangeRateChainlinkAdapter internal oracle;
ChainlinkOracle internal chainlinkOracle;

function setUp() public {
vm.createSelectFork(vm.envString("ETH_RPC_URL"));
oracle = new WstEthEthExchangeRateChainlinkAdapter(address(WST_ETH));
oracle = new WstEthEthExchangeRateChainlinkAdapter(address(ST_ETH));
chainlinkOracle = new ChainlinkOracle(
vaultZero, AggregatorV3Interface(address(oracle)), feedZero, feedZero, feedZero, 1, 18, 18
);
Expand All @@ -37,7 +37,7 @@ contract WstEthEthExchangeRateChainlinkAdapterTest is Test {
(uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) =
oracle.latestRoundData();
assertEq(roundId, 0);
assertEq(uint256(answer), WST_ETH.stEthPerToken());
assertEq(uint256(answer), ST_ETH.getPooledEthByShares(1 ether));
assertEq(startedAt, 0);
assertEq(updatedAt, 0);
assertEq(answeredInRound, 0);
Expand Down

0 comments on commit ad5e168

Please sign in to comment.