Skip to content

Commit

Permalink
refactor: remove errors from lib
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisGD committed Feb 5, 2024
1 parent 84f2fd2 commit 6ae27d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 9 additions & 3 deletions src/FixedRateIrm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity 0.8.19;
import {IIrm} from "../lib/morpho-blue/src/interfaces/IIrm.sol";
import {IFixedRateIrm} from "./interfaces/IFixedRateIrm.sol";

import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {MarketParamsLib} from "../lib/morpho-blue/src/libraries/MarketParamsLib.sol";
import {Id, MarketParams, Market} from "../lib/morpho-blue/src/interfaces/IMorpho.sol";

Expand All @@ -19,6 +18,13 @@ contract FixedRateIrm is IFixedRateIrm {
/// @notice Emitted when a borrow rate is set.
event SetBorrowRate(Id indexed id, uint256 newBorrowRate);

/* ERRORS */

/// @dev Thrown when the rate is already set for this market.
string public constant RATE_ALREADY_SET = "rate already set";
/// @dev Thrown when trying to set the rate at zero.
string public constant RATE_ZERO = "rate zero";

/* STORAGE */

/// @notice Borrow rates.
Expand All @@ -28,8 +34,8 @@ contract FixedRateIrm is IFixedRateIrm {

/// @inheritdoc IFixedRateIrm
function setBorrowRate(Id id, uint256 newBorrowRate) external {
require(_borrowRate[id] == 0, ErrorsLib.RATE_ALREADY_SET);
require(newBorrowRate != 0, ErrorsLib.RATE_ZERO);
require(_borrowRate[id] == 0, RATE_ALREADY_SET);
require(newBorrowRate != 0, RATE_ZERO);

_borrowRate[id] = newBorrowRate;

Expand Down
6 changes: 0 additions & 6 deletions src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,4 @@ library ErrorsLib {

/// @dev Thrown when the caller is not Morpho.
string internal constant NOT_MORPHO = "not Morpho";

/// @dev Thrown when the rate is already set for this market.
string internal constant RATE_ALREADY_SET = "rate already set";

/// @dev Thrown when trying to set the rate at zero.
string internal constant RATE_ZERO = "rate zero";
}
4 changes: 2 additions & 2 deletions test/forge/FixedRateIrmTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ contract FixedRateIrmTest is Test {
vm.assume(newBorrowRate1 != 0);
vm.assume(newBorrowRate2 != 0);
fixedRateIrm.setBorrowRate(id, newBorrowRate1);
vm.expectRevert(bytes(ErrorsLib.RATE_ALREADY_SET));
vm.expectRevert("rate already set");
fixedRateIrm.setBorrowRate(id, newBorrowRate2);
}

function testSetBorrowRateRateZero(Id id) external {
vm.expectRevert(bytes(ErrorsLib.RATE_ZERO));
vm.expectRevert("rate zero");
fixedRateIrm.setBorrowRate(id, 0);
}

Expand Down

0 comments on commit 6ae27d9

Please sign in to comment.