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

Add fee cap #161

Merged
merged 4 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 4 additions & 3 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Id, Market, MarketLib} from "src/libraries/MarketLib.sol";
import {SafeTransferLib} from "src/libraries/SafeTransferLib.sol";

uint256 constant WAD = 1e18;
uint256 constant FEE_CAP = 0.2e18;
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved
uint256 constant ALPHA = 0.5e18;

contract Blue {
Expand Down Expand Up @@ -78,11 +79,11 @@ contract Blue {
isLltvEnabled[lltv] = true;
}

// @notice It is the owner's responsibility to ensure a fee recipient is set before setting a non-zero fee.
/// @notice It is the owner's responsibility to ensure a fee recipient is set before setting a non-zero fee.
function setFee(Market calldata market, uint256 newFee) external onlyOwner {
Id id = market.id();
require(lastUpdate[id] != 0, "unknown market");
require(newFee <= WAD, "fee must be <= 1");
require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED);
require(newFee <= FEE_CAP, Errors.FEE_CAP_EXCEEDED);
fee[id] = newFee;
}

Expand Down
2 changes: 2 additions & 0 deletions src/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ library Errors {

string internal constant LLTV_TOO_HIGH = "LLTV too high";

string internal constant FEE_CAP_EXCEEDED = "fee must be <= 20%";
MathisGD marked this conversation as resolved.
Show resolved Hide resolved

string internal constant IRM_NOT_ENABLED = "IRM not enabled";

string internal constant LLTV_NOT_ENABLED = "LLTV not enabled";
Expand Down
8 changes: 4 additions & 4 deletions test/forge/Blue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ contract BlueTest is Test {
}

function testSetFee(uint256 fee) public {
fee = bound(fee, 0, WAD);
fee = bound(fee, 0, FEE_CAP);

vm.prank(OWNER);
blue.setFee(market, fee);
Expand All @@ -199,10 +199,10 @@ contract BlueTest is Test {
}

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

vm.prank(OWNER);
vm.expectRevert("fee must be <= 1");
vm.expectRevert(bytes(Errors.FEE_CAP_EXCEEDED));
blue.setFee(market, fee);
}

Expand Down Expand Up @@ -242,7 +242,7 @@ contract BlueTest is Test {
amountLent = bound(amountLent, 1, 2 ** 64);
amountBorrowed = bound(amountBorrowed, 1, amountLent);
timeElapsed = bound(timeElapsed, 1, 365 days);
fee = bound(fee, 0, 1e18);
fee = bound(fee, 0, FEE_CAP);
address recipient = OWNER;

vm.startPrank(OWNER);
Expand Down