Skip to content

Commit bb11beb

Browse files
Merge pull request #72 from morpho-org/refactor/answer
Refactor answer
2 parents 589468f + 8d13031 commit bb11beb

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
pragma solidity 0.8.21;
33

4-
import {IStEth} from "../interfaces/IStEth.sol";
4+
import {IWstEth} from "../interfaces/IWstEth.sol";
55
import {MinimalAggregatorV3Interface} from "../interfaces/MinimalAggregatorV3Interface.sol";
66

77
import {ErrorsLib} from "../libraries/ErrorsLib.sol";
@@ -15,15 +15,16 @@ contract WstEthEthExchangeRateChainlinkAdapter is MinimalAggregatorV3Interface {
1515
uint8 public constant decimals = 18;
1616
string public constant description = "wstETH/ETH exchange rate";
1717

18-
IStEth public immutable ST_ETH;
18+
IWstEth public immutable WST_ETH;
1919

20-
constructor(address stEth) {
21-
require(stEth != address(0), ErrorsLib.ZERO_ADDRESS);
22-
ST_ETH = IStEth(stEth);
20+
constructor(address wstEth) {
21+
require(wstEth != address(0), ErrorsLib.ZERO_ADDRESS);
22+
23+
WST_ETH = IWstEth(wstEth);
2324
}
2425

2526
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
26-
uint256 answer = ST_ETH.getPooledEthByShares(10 ** decimals);
27-
return (0, int256(answer), 0, 0, 0);
27+
// It is assumed that `stEthPerToken` returns a price with 18 decimals precision.
28+
return (0, int256(WST_ETH.stEthPerToken()), 0, 0, 0);
2829
}
2930
}

src/interfaces/IStEth.sol

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/interfaces/IWstEth.sol

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 IWstEth {
5+
function stEthPerToken() external view returns (uint256);
6+
}

test/WstEthEthExchangeRateChainlinkAdapterTest.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import "../src/ChainlinkOracle.sol";
99
import "./helpers/Constants.sol";
1010

1111
contract WstEthEthExchangeRateChainlinkAdapterTest is Test {
12-
IStEth internal constant ST_ETH = IStEth(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
12+
IWstEth internal constant WST_ETH = IWstEth(0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0);
1313

1414
WstEthEthExchangeRateChainlinkAdapter internal oracle;
1515
ChainlinkOracle internal chainlinkOracle;
1616

1717
function setUp() public {
1818
vm.createSelectFork(vm.envString("ETH_RPC_URL"));
19-
oracle = new WstEthEthExchangeRateChainlinkAdapter(address(ST_ETH));
19+
oracle = new WstEthEthExchangeRateChainlinkAdapter(address(WST_ETH));
2020
chainlinkOracle = new ChainlinkOracle(vaultZero, oracle, feedZero, feedZero, feedZero, 1, 18, 18);
2121
}
2222

@@ -37,7 +37,7 @@ contract WstEthEthExchangeRateChainlinkAdapterTest is Test {
3737
(uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) =
3838
oracle.latestRoundData();
3939
assertEq(roundId, 0);
40-
assertEq(uint256(answer), ST_ETH.getPooledEthByShares(10 ** 18));
40+
assertEq(uint256(answer), WST_ETH.stEthPerToken());
4141
assertEq(startedAt, 0);
4242
assertEq(updatedAt, 0);
4343
assertEq(answeredInRound, 0);

0 commit comments

Comments
 (0)