Skip to content

Commit

Permalink
Merge pull request #23 from neutral-protocol/feature/make-all-fee-par…
Browse files Browse the repository at this point in the history
…ameters-configurable

make all fee parameters configurable
  • Loading branch information
kosecki123 authored Dec 4, 2023
2 parents 7ea7302 + e8b08e4 commit 6ad8bb8
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/FeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,96 @@ 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(int256 _depositFeeScale) external onlyOwner {
SD59x18 depositFeeScaleSD = sd(_depositFeeScale);
require(depositFeeScaleSD >= zero && depositFeeScaleSD <= one, "Deposit fee scale must be between 0 and 1");
depositFeeScale = depositFeeScaleSD;
}

/// @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(int256 _depositFeeRatioScale) external onlyOwner {
SD59x18 depositFeeRatioScaleSD = sd(_depositFeeRatioScale);
require(depositFeeRatioScaleSD >= zero, "Deposit fee ratio scale must be above 0");
depositFeeRatioScale = depositFeeRatioScaleSD;
}

/// @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(int256 _singleAssetDepositRelativeFee) external onlyOwner {
SD59x18 singleAssetDepositRelativeFeeSD = sd(_singleAssetDepositRelativeFee);
require(
singleAssetDepositRelativeFeeSD >= zero && singleAssetDepositRelativeFeeSD <= one,
"Single asset deposit relative fee must be between 0 and 1"
);
singleAssetDepositRelativeFee = singleAssetDepositRelativeFeeSD;
}

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

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

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

/// @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(int256 _singleAssetRedemptionRelativeFee) external onlyOwner {
SD59x18 singleAssetRedemptionRelativeFeeSD = sd(_singleAssetRedemptionRelativeFee);
require(
singleAssetRedemptionRelativeFeeSD >= zero && singleAssetRedemptionRelativeFeeSD <= one,
"Single asset redemption relative fee must be between 0 and 1"
);
singleAssetRedemptionRelativeFee = singleAssetRedemptionRelativeFeeSD;
}

/// @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(int256 _dustAssetRedemptionRelativeFee) external onlyOwner {
SD59x18 dustAssetRedemptionRelativeFeeSD = sd(_dustAssetRedemptionRelativeFee);
require(
dustAssetRedemptionRelativeFeeSD >= zero && dustAssetRedemptionRelativeFeeSD <= one,
"Dust asset redemption relative fee must be between 0 and 1"
);
dustAssetRedemptionRelativeFee = dustAssetRedemptionRelativeFeeSD;
}

/// @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 {
int256 invalid = (1.1 * 1e18);
vm.expectRevert("Deposit fee scale must be between 0 and 1");
feeCalculator.setDepositFeeScale(invalid);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit 6ad8bb8

Please sign in to comment.