diff --git a/src/wsteth-exchange-rate-adapter/WstEthEthExchangeRateChainlinkAdapter.sol b/src/wsteth-exchange-rate-adapter/WstEthEthExchangeRateChainlinkAdapter.sol index 69f4237..883e618 100644 --- a/src/wsteth-exchange-rate-adapter/WstEthEthExchangeRateChainlinkAdapter.sol +++ b/src/wsteth-exchange-rate-adapter/WstEthEthExchangeRateChainlinkAdapter.sol @@ -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"; @@ -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); } } diff --git a/src/wsteth-exchange-rate-adapter/interfaces/IStEth.sol b/src/wsteth-exchange-rate-adapter/interfaces/IStEth.sol new file mode 100644 index 0000000..347947e --- /dev/null +++ b/src/wsteth-exchange-rate-adapter/interfaces/IStEth.sol @@ -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); +} diff --git a/src/wsteth-exchange-rate-adapter/interfaces/IWstEth.sol b/src/wsteth-exchange-rate-adapter/interfaces/IWstEth.sol deleted file mode 100644 index 23de267..0000000 --- a/src/wsteth-exchange-rate-adapter/interfaces/IWstEth.sol +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -pragma solidity >=0.5.0; - -interface IWstEth { - function stEthPerToken() external view returns (uint256); -} diff --git a/test/WstEthEthExchangeRateChainlinkAdapterTest.sol b/test/WstEthEthExchangeRateChainlinkAdapterTest.sol index b8de806..9a90420 100644 --- a/test/WstEthEthExchangeRateChainlinkAdapterTest.sol +++ b/test/WstEthEthExchangeRateChainlinkAdapterTest.sol @@ -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 ); @@ -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);