Skip to content

Commit

Permalink
chore: further improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisGD committed Feb 8, 2024
1 parent 3d30b9e commit 9609f74
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const config: HardhatUserConfig = {
settings: {
optimizer: {
enabled: true,
runs: 200,
runs: 999999,
},
viaIR: true,
},
Expand All @@ -40,7 +40,7 @@ const config: HardhatUserConfig = {
settings: {
optimizer: {
enabled: true,
runs: 200,
runs: 999999,
},
viaIR: true,
},
Expand Down
15 changes: 9 additions & 6 deletions src/FixedRateIrm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ contract FixedRateIrm is IFixedRateIrm {
/* STORAGE */

/// @notice Borrow rates.
mapping(Id => uint256) public _borrowRate;
mapping(Id => uint256) public borrowRateStored;

/* SETTER */

/// @inheritdoc IFixedRateIrm
/// @notice Sets the borrow rate for a market.
/// @dev A rate can be set by anybody, but only once.
/// @dev `borrowRate` reverts on rate not set, so the rate needs to be set before the market creation.
/// @dev The creator of a market with this IRM would typically batch setting of the rate with the market creation.
function setBorrowRate(Id id, uint256 newBorrowRate) external {
require(_borrowRate[id] == 0, RATE_SET);
require(borrowRateStored[id] == 0, RATE_SET);
require(newBorrowRate != 0, RATE_ZERO);

_borrowRate[id] = newBorrowRate;
borrowRateStored[id] = newBorrowRate;

emit SetBorrowRate(id, newBorrowRate);
}
Expand All @@ -48,15 +51,15 @@ contract FixedRateIrm is IFixedRateIrm {

/// @inheritdoc IIrm
function borrowRateView(MarketParams memory marketParams, Market memory) external view returns (uint256) {
uint256 borrowRateCached = _borrowRate[marketParams.id()];
uint256 borrowRateCached = borrowRateStored[marketParams.id()];
require(borrowRateCached != 0, RATE_NOT_SET);
return borrowRateCached;
}

/// @inheritdoc IIrm
/// @dev Reverts on not set rate, so the rate has to be set before the market creation.
function borrowRate(MarketParams memory marketParams, Market memory) external view returns (uint256) {
uint256 borrowRateCached = _borrowRate[marketParams.id()];
uint256 borrowRateCached = borrowRateStored[marketParams.id()];
require(borrowRateCached != 0, RATE_NOT_SET);
return borrowRateCached;
}
Expand Down
4 changes: 1 addition & 3 deletions src/interfaces/IFixedRateIrm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {Id} from "../../lib/morpho-blue/src/interfaces/IMorpho.sol";
/// @author Morpho Labs
/// @custom:contact security@morpho.org
interface IFixedRateIrm is IIrm {
/// @notice Sets the borrow rate for a market.
/// @dev A rate can be set by anybody, but only once.
/// @dev The creator of a market with this IRM would typically batch setting of the rate with the market creation.
function borrowRateStored(Id id) external returns (uint256);
function setBorrowRate(Id id, uint256 newBorrowRate) external;
}
2 changes: 1 addition & 1 deletion test/forge/FixedRateIrmTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract FixedRateIrmTest is Test {
vm.assume(newBorrowRate != 0);

fixedRateIrm.setBorrowRate(id, newBorrowRate);
assertEq(fixedRateIrm._borrowRate(id), newBorrowRate);
assertEq(fixedRateIrm.borrowRateStored(id), newBorrowRate);
}

function testSetBorrowRateEvent(Id id, uint256 newBorrowRate) external {
Expand Down

0 comments on commit 9609f74

Please sign in to comment.