Skip to content

Commit

Permalink
feat: custom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinEgalite committed Oct 10, 2024
1 parent 36ce4e3 commit 5e73c64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/MorphoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ contract MorphoToken is ERC20VotesUpgradeable, ERC20PermitUpgradeable, Ownable2S
/// @dev the symbol of the token.
string internal constant SYMBOL = "MORPHO";

/* ERRORS */

/// @notice Reverts if the address is the zero address.
error ZeroAddress();

/* PUBLIC */

function initialize(address dao, address wrapper) public initializer {
require(dao != address(0), "MorphoToken: wrapper is the zero address");
require(wrapper != address(0), "MorphoToken: wrapper is the zero address");
require(dao != address(0), ZeroAddress());
require(wrapper != address(0), ZeroAddress());

ERC20VotesUpgradeable.__ERC20Votes_init();
ERC20Upgradeable.__ERC20_init(NAME, SYMBOL);
Expand Down
14 changes: 11 additions & 3 deletions src/Wrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ contract Wrapper {
/// @dev The address of the new morpho token.
address public immutable NEW_MORPHO;

/* ERRORS */

/// @notice Reverts if the address is the zero address.
error ZeroAddress();

/// @notice Reverts if the address is the contract address.
error SelfAddress();

/* CONSTRUCTOR */

/// @dev morphoToken address can be precomputed using create2.
constructor(address morphoToken) {
require(morphoToken != address(0), "Wrapper: zero address");
require(morphoToken != address(0), ZeroAddress());

NEW_MORPHO = morphoToken;
}
Expand All @@ -31,8 +39,8 @@ contract Wrapper {

/// @dev Compliant to `ERC20Wrapper` contract from OZ for convenience.
function depositFor(address account, uint256 amount) public returns (bool) {
require(account != address(0), "Wrapper: zero address");
require(account != address(this), "Wrapper: self address");
require(account != address(0), ZeroAddress());
require(account != address(this), SelfAddress());

IERC20(LEGACY_MORPHO).transferFrom(msg.sender, address(this), amount);
IERC20(NEW_MORPHO).transfer(account, amount);
Expand Down

0 comments on commit 5e73c64

Please sign in to comment.