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

make all fee parameters configurable #23

Merged
merged 8 commits into from
Dec 4, 2023
81 changes: 81 additions & 0 deletions src/FeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,88 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab

constructor() Ownable(msg.sender) {}

/// @notice Sets the deposit fee scale.
/// @dev Can only be called by the current owner.
/// @param _depositFeeScale The new deposit fee scale.
function setDepositFeeScale(SD59x18 _depositFeeScale) external onlyOwner {
require(_depositFeeScale >= zero && _depositFeeScale <= one, "Deposit fee scale must be between 0 and 1");
depositFeeScale = _depositFeeScale;
}

/// @notice Sets the deposit fee ratio scale.
/// @dev Can only be called by the current owner.
/// @param _depositFeeRatioScale The new deposit fee ratio scale.
function setDepositFeeRatioScale(SD59x18 _depositFeeRatioScale) external onlyOwner {
require(_depositFeeRatioScale >= zero, "Deposit fee ratio scale must be above 0");
depositFeeRatioScale = _depositFeeRatioScale;
}

/// @notice Sets the single asset deposit relative fee.
/// @dev Can only be called by the current owner.
/// @param _singleAssetDepositRelativeFee The new single asset deposit relative fee.
function setSingleAssetDepositRelativeFee(SD59x18 _singleAssetDepositRelativeFee) external onlyOwner {
require(
_singleAssetDepositRelativeFee >= zero && _singleAssetDepositRelativeFee <= one,
"Single asset deposit relative fee must be between 0 and 1"
);
singleAssetDepositRelativeFee = _singleAssetDepositRelativeFee;
}

/// @notice Sets the redemption fee scale.
/// @dev Can only be called by the current owner.
/// @param _redemptionFeeScale The new redemption fee scale.
function setRedemptionFeeScale(SD59x18 _redemptionFeeScale) external onlyOwner {
require(
_redemptionFeeScale >= zero && _redemptionFeeScale <= one, "Redemption fee scale must be between 0 and 1"
);
redemptionFeeScale = _redemptionFeeScale;
}

/// @notice Sets the redemption fee shift.
/// @dev Can only be called by the current owner.
/// @param _redemptionFeeShift The new redemption fee shift.
function setRedemptionFeeShift(SD59x18 _redemptionFeeShift) external onlyOwner {
require(
_redemptionFeeShift >= zero && _redemptionFeeShift <= one, "Redemption fee shift must be between 0 and 1"
);
redemptionFeeShift = _redemptionFeeShift;
}

/// @notice Sets the redemption fee constant.
/// @dev Can only be called by the current owner.
/// @param _redemptionFeeConstant The new redemption fee shift.
function setRedemptionFeeConstant(SD59x18 _redemptionFeeConstant) external onlyOwner {
require(
_redemptionFeeConstant >= zero && _redemptionFeeConstant <= one,
"Redemption fee constant must be between 0 and 1"
);
redemptionFeeConstant = _redemptionFeeConstant;
}

/// @notice Sets the single asset redemption relative fee.
/// @dev Can only be called by the current owner.
/// @param _singleAssetRedemptionRelativeFee The new single asset redemption relative fee.
function setSingleAssetRedemptionRelativeFee(SD59x18 _singleAssetRedemptionRelativeFee) external onlyOwner {
require(
_singleAssetRedemptionRelativeFee >= zero && _singleAssetRedemptionRelativeFee <= one,
"Single asset redemption relative fee must be between 0 and 1"
);
singleAssetRedemptionRelativeFee = _singleAssetRedemptionRelativeFee;
}

/// @notice Sets the dust asset redemption relative fee.
/// @dev Can only be called by the current owner.
/// @param _dustAssetRedemptionRelativeFee The new dust asset redemption relative fee.
function setDustAssetRedemptionRelativeFee(SD59x18 _dustAssetRedemptionRelativeFee) external onlyOwner {
require(
_dustAssetRedemptionRelativeFee >= zero && _dustAssetRedemptionRelativeFee <= one,
"Dust asset redemption relative fee must be between 0 and 1"
);
dustAssetRedemptionRelativeFee = _dustAssetRedemptionRelativeFee;
}

/// @notice Sets up the fee distribution among recipients.
/// @dev Can only be called by the current owner.
/// @param recipients The addresses of the fee recipients.
/// @param shares The share of the fee each recipient should receive.
function feeSetup(address[] memory recipients, uint256[] memory shares) external onlyOwner {
Expand Down
90 changes: 90 additions & 0 deletions test/FeeCalculator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,94 @@ contract FeeCalculatorTest is Test {
vm.expectRevert("Total shares must equal 100");
feeCalculator.feeSetup(_recipients, _feeShares);
}

function testSetDepositFeeScaleReverts() public {
SD59x18 invalid = sd(1.1 * 1e18);
vm.expectRevert("Deposit fee scale must be between 0 and 1");
feeCalculator.setDepositFeeScale(invalid);
}

function testSetSingleAssetDepositRelativeFeeReverts() public {
SD59x18 invalid = sd(1.3 * 1e18);
vm.expectRevert("Single asset deposit relative fee must be between 0 and 1");
feeCalculator.setSingleAssetDepositRelativeFee(invalid);
}

function testSetRedemptionFeeScaleReverts() public {
SD59x18 invalid = sd(1.4 * 1e18);
vm.expectRevert("Redemption fee scale must be between 0 and 1");
feeCalculator.setRedemptionFeeScale(invalid);
}

function testSetRedemptionFeeShiftReverts() public {
SD59x18 invalid = sd(1.5 * 1e18);
vm.expectRevert("Redemption fee shift must be between 0 and 1");
feeCalculator.setRedemptionFeeShift(invalid);
}

function testSetRedemptionFeeConstantReverts() public {
SD59x18 invalid = sd(1.6 * 1e18);
vm.expectRevert("Redemption fee constant must be between 0 and 1");
feeCalculator.setRedemptionFeeConstant(invalid);
}

function testSetSingleAssetRedemptionRelativeFeeReverts() public {
SD59x18 invalid = sd(1.7 * 1e18);
vm.expectRevert("Single asset redemption relative fee must be between 0 and 1");
feeCalculator.setSingleAssetRedemptionRelativeFee(invalid);
}

function testSetDustAssetRedemptionRelativeFeeReverts() public {
SD59x18 invalid = sd(1.8 * 1e18);
vm.expectRevert("Dust asset redemption relative fee must be between 0 and 1");
feeCalculator.setDustAssetRedemptionRelativeFee(invalid);
}

function testSetDepositFeeScaleNegativeReverts() public {
SD59x18 invalid = sd(-0.1 * 1e18);
vm.expectRevert("Deposit fee scale must be between 0 and 1");
feeCalculator.setDepositFeeScale(invalid);
}

function testSetDepositFeeRatioScaleNegativeReverts() public {
SD59x18 invalid = sd(-0.2 * 1e18);
vm.expectRevert("Deposit fee ratio scale must be above 0");
feeCalculator.setDepositFeeRatioScale(invalid);
}

function testSetSingleAssetDepositRelativeFeeNegativeReverts() public {
SD59x18 invalid = sd(-0.3 * 1e18);
vm.expectRevert("Single asset deposit relative fee must be between 0 and 1");
feeCalculator.setSingleAssetDepositRelativeFee(invalid);
}

function testSetRedemptionFeeScaleNegativeReverts() public {
SD59x18 invalid = sd(-0.4 * 1e18);
vm.expectRevert("Redemption fee scale must be between 0 and 1");
feeCalculator.setRedemptionFeeScale(invalid);
}

function testSetRedemptionFeeShiftNegativeReverts() public {
SD59x18 invalid = sd(-0.5 * 1e18);
vm.expectRevert("Redemption fee shift must be between 0 and 1");
feeCalculator.setRedemptionFeeShift(invalid);
}

function testSetRedemptionFeeConstantNegativeReverts() public {
SD59x18 invalid = sd(-0.6 * 1e18);
vm.expectRevert("Redemption fee constant must be between 0 and 1");
feeCalculator.setRedemptionFeeConstant(invalid);
}

function testSetSingleAssetRedemptionRelativeFeeNegativeReverts() public {
SD59x18 invalid = sd(-0.7 * 1e18);
vm.expectRevert("Single asset redemption relative fee must be between 0 and 1");
feeCalculator.setSingleAssetRedemptionRelativeFee(invalid);
}

function testSetDustAssetRedemptionRelativeFeeNegativeReverts() public {
SD59x18 invalid = sd(-0.8 * 1e18);
vm.expectRevert("Dust asset redemption relative fee must be between 0 and 1");
feeCalculator.setDustAssetRedemptionRelativeFee(invalid);
}
}