Skip to content

Commit d71392b

Browse files
committed
refactor: use errors lib
1 parent 53cfbcc commit d71392b

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/adapters/WstEthOracle.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pragma solidity 0.8.21;
44
import {IStEth} from "../interfaces/IStEth.sol";
55
import {AggregatorV3Interface} from "../interfaces/AggregatorV3Interface.sol";
66

7+
import {ErrorsLib} from "../libraries/ErrorsLib.sol";
8+
79
/// @title WstEthOracle
810
/// @author Morpho Labs
911
/// @custom:contact [email protected]
@@ -17,7 +19,7 @@ contract WstEthOracle is AggregatorV3Interface {
1719
IStEth public immutable ST_ETH;
1820

1921
constructor(address stEth) {
20-
require(stEth != address(0), "WstEthOracle: ZERO_ADDRESS");
22+
require(stEth != address(0), ErrorsLib.ZERO_ADDRESS);
2123
ST_ETH = IStEth(stEth);
2224
}
2325

@@ -27,7 +29,7 @@ contract WstEthOracle is AggregatorV3Interface {
2729

2830
function latestRoundData() public view returns (uint80, int256, uint256, uint256, uint80) {
2931
uint256 answer = ST_ETH.getPooledEthByShares(10 ** decimals);
30-
require(answer < type(uint256).max, "WstEthOracle: OVERFLOW");
32+
require(answer < type(uint256).max, ErrorsLib.OVERFLOW);
3133
return (0, int256(answer), 0, 0, 0);
3234
}
3335
}

src/libraries/ErrorsLib.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ library ErrorsLib {
1414

1515
/// @notice Thrown when the vault conversion sample is not 1 while vault = address(0).
1616
string constant VAULT_CONVERSION_SAMPLE_IS_NOT_ONE = "vault conversion sample is not one";
17+
18+
/// @notice Thrown when the zero address is passed as argument.
19+
string constant ZERO_ADDRESS = "zero address";
20+
21+
/// @notice Thrown when the computation will overflow.
22+
string constant OVERFLOW = "overflow";
1723
}

test/WstEthOracle.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
pragma solidity ^0.8.0;
33

4+
import "../src/libraries/ErrorsLib.sol";
5+
46
import "../lib/forge-std/src/Test.sol";
57
import "../src/adapters/WstEthOracle.sol";
68

@@ -20,7 +22,7 @@ contract ChainlinkOracleTest is Test {
2022
abi.encodeWithSelector(ST_ETH.getPooledEthByShares.selector, 10 ** 18),
2123
abi.encode(type(uint256).max)
2224
);
23-
vm.expectRevert("WstEthOracle: OVERFLOW");
25+
vm.expectRevert(bytes(ErrorsLib.OVERFLOW));
2426
oracle.latestRoundData();
2527
}
2628

@@ -30,7 +32,7 @@ contract ChainlinkOracleTest is Test {
3032
abi.encodeWithSelector(ST_ETH.getPooledEthByShares.selector, 10 ** 18),
3133
abi.encode(type(uint256).max)
3234
);
33-
vm.expectRevert("WstEthOracle: OVERFLOW");
35+
vm.expectRevert(bytes(ErrorsLib.OVERFLOW));
3436
oracle.getRoundData(1);
3537
}
3638

@@ -39,7 +41,7 @@ contract ChainlinkOracleTest is Test {
3941
}
4042

4143
function testDeployZeroAddress() public {
42-
vm.expectRevert("WstEthOracle: ZERO_ADDRESS");
44+
vm.expectRevert(bytes(ErrorsLib.ZERO_ADDRESS));
4345
new WstEthOracle(address(0));
4446
}
4547

0 commit comments

Comments
 (0)