Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fee): add max fee #118

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
}

function submitFee(uint256 newFee) external onlyOwner {
require(newFee <= WAD, ErrorsLib.MAX_FEE_EXCEEDED);
require(newFee <= MAX_FEE, ErrorsLib.MAX_FEE_EXCEEDED);
require(newFee != fee, ErrorsLib.ALREADY_SET);

if (newFee < fee || timelock == 0) {
_setFee(newFee);
} else {
// Safe "unchecked" cast because newFee <= WAD.
// Safe "unchecked" cast because newFee <= MAX_FEE.
pendingFee = PendingUint192(uint192(newFee), uint64(block.timestamp));

emit EventsLib.SubmitFee(newFee);
Expand Down Expand Up @@ -512,7 +512,7 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
function _setFee(uint256 newFee) internal {
require(newFee == 0 || feeRecipient != address(0), ErrorsLib.ZERO_FEE_RECIPIENT);

// Safe "unchecked" cast because newFee <= WAD.
// Safe "unchecked" cast because newFee <= MAX_FEE.
fee = uint96(newFee);

emit EventsLib.SetFee(newFee);
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/ConstantsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ uint8 constant DECIMALS_OFFSET = 6;
/// @dev The maximum supply/withdraw queue size ensuring the cost of depositing/withdrawing from the vault fits in a
/// block.
uint256 constant MAX_QUEUE_SIZE = 64;

/// @dev The maximum fee the vault can have (50%).
uint256 constant MAX_FEE = 0.5e18;
18 changes: 16 additions & 2 deletions test/forge/FeeTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ contract FeeTest is BaseTest {

function testSetFeeAccrueFee(uint256 deposited, uint256 fee, uint256 blocks) public {
deposited = bound(deposited, MIN_TEST_ASSETS, MAX_TEST_ASSETS);
fee = bound(fee, 0, WAD);
fee = bound(fee, 0, MAX_FEE);
blocks = _boundBlocks(blocks);

vm.assume(fee != FEE);
Expand Down Expand Up @@ -232,8 +232,22 @@ contract FeeTest is BaseTest {
vault.submitFee(fee);
}

function testSubmitFeeMaxFeeExceeded(uint256 fee) public {
fee = bound(fee, MAX_FEE + 1, type(uint256).max);

vm.prank(OWNER);
vm.expectRevert(bytes(ErrorsLib.MAX_FEE_EXCEEDED));
vault.submitFee(fee);
}

function testSubmitFeeAlreadySet() public {
vm.prank(OWNER);
vm.expectRevert(bytes(ErrorsLib.ALREADY_SET));
vault.submitFee(FEE);
}

function testAcceptFeeNotOwner(uint256 fee) public {
fee = bound(fee, FEE + 1, WAD);
fee = bound(fee, FEE + 1, MAX_FEE);

_setTimelock(1);

Expand Down
16 changes: 4 additions & 12 deletions test/forge/TimelockTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ contract TimelockTest is BaseTest {
}

function testSubmitFeeIncreased(uint256 fee) public {
fee = bound(fee, FEE + 1, WAD);
fee = bound(fee, FEE + 1, MAX_FEE);

vm.prank(OWNER);
vault.submitFee(fee);
Expand All @@ -159,16 +159,8 @@ contract TimelockTest is BaseTest {
assertEq(submittedAt, block.timestamp, "submittedAt");
}

function testSubmitFeeIncreasedMaxFeeExceeded(uint256 fee) public {
fee = bound(fee, WAD + 1, type(uint256).max);

vm.prank(OWNER);
vm.expectRevert(bytes(ErrorsLib.MAX_FEE_EXCEEDED));
vault.submitFee(fee);
}

function testAcceptFee(uint256 fee) public {
fee = bound(fee, FEE + 1, WAD);
fee = bound(fee, FEE + 1, MAX_FEE);

vm.prank(OWNER);
vault.submitFee(fee);
Expand All @@ -192,7 +184,7 @@ contract TimelockTest is BaseTest {
}

function testAcceptFeeTimelockNotElapsed(uint256 fee, uint256 elapsed) public {
fee = bound(fee, FEE + 1, WAD);
fee = bound(fee, FEE + 1, MAX_FEE);
elapsed = bound(elapsed, 1, TIMELOCK - 1);

vm.prank(OWNER);
Expand All @@ -206,7 +198,7 @@ contract TimelockTest is BaseTest {
}

function testAcceptFeeTimelockExpirationExceeded(uint256 fee, uint256 elapsed) public {
fee = bound(fee, FEE + 1, WAD);
fee = bound(fee, FEE + 1, MAX_FEE);
elapsed = bound(elapsed, TIMELOCK + TIMELOCK_EXPIRATION + 1, type(uint64).max);

vm.prank(OWNER);
Expand Down
2 changes: 1 addition & 1 deletion test/forge/helpers/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {MorphoLib} from "@morpho-blue/libraries/periphery/MorphoLib.sol";
import {MorphoBalancesLib} from "@morpho-blue/libraries/periphery/MorphoBalancesLib.sol";

import "src/libraries/ConstantsLib.sol";
import "@morpho-blue/libraries/ConstantsLib.sol";
import {ORACLE_PRICE_SCALE} from "@morpho-blue/libraries/ConstantsLib.sol";

import {IrmMock} from "src/mocks/IrmMock.sol";
import {ERC20Mock} from "src/mocks/ERC20Mock.sol";
Expand Down