Skip to content

Commit ececffb

Browse files
committed
refactor: update answer computation
1 parent e57e0fb commit ececffb

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed
Lines changed: 9 additions & 6 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";
@@ -14,15 +14,18 @@ import {ErrorsLib} from "../libraries/ErrorsLib.sol";
1414
contract WstEthEthExchangeRateChainlinkAdapter is MinimalAggregatorV3Interface {
1515
uint8 public constant decimals = 18;
1616

17-
IStEth public immutable ST_ETH;
17+
IWstEth public immutable WST_ETH;
18+
uint256 public immutable WSTETH_DECIMALS;
1819

19-
constructor(address stEth) {
20-
require(stEth != address(0), ErrorsLib.ZERO_ADDRESS);
21-
ST_ETH = IStEth(stEth);
20+
constructor(address wstEth) {
21+
require(wstEth != address(0), ErrorsLib.ZERO_ADDRESS);
22+
23+
WST_ETH = IWstEth(wstEth);
24+
WSTETH_DECIMALS = WST_ETH.decimals();
2225
}
2326

2427
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
25-
uint256 answer = ST_ETH.getPooledEthByShares(10 ** decimals);
28+
uint256 answer = WST_ETH.stEthPerToken() * 10 ** (WSTETH_DECIMALS - decimals);
2629
return (0, int256(answer), 0, 0, 0);
2730
}
2831
}

src/interfaces/IWstEth.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity >=0.5.0;
3+
4+
interface IWstEth {
5+
function decimals() external view returns (uint8);
6+
function stEthPerToken() external view returns (uint256);
7+
}

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

@@ -33,7 +33,7 @@ contract WstEthEthExchangeRateChainlinkAdapterTest is Test {
3333
(uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) =
3434
oracle.latestRoundData();
3535
assertEq(roundId, 0);
36-
assertEq(uint256(answer), ST_ETH.getPooledEthByShares(10 ** 18));
36+
assertEq(uint256(answer), WST_ETH.stEthPerToken());
3737
assertEq(startedAt, 0);
3838
assertEq(updatedAt, 0);
3939
assertEq(answeredInRound, 0);

0 commit comments

Comments
 (0)