From e3e22111cf5fb7d0080cbe0e2c692ee77f69a5fa Mon Sep 17 00:00:00 2001 From: "Pawel Troka, Ph.D. Eng" Date: Thu, 30 Nov 2023 13:45:18 +0100 Subject: [PATCH 1/8] make all fee parameters configurable --- src/FeeCalculator.sol | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 8373dca..50b6021 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -34,6 +34,62 @@ 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 { + 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 { + 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 { + 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 { + 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 { + redemptionFeeShift = _redemptionFeeShift; + } + + /// @notice Sets the redemption fee constant. + /// @dev Can only be called by the current owner. + /// @param _redemptionFeeShift The new redemption fee shift. + function setRedemptionFeeConstant(SD59x18 _redemptionFeeConstant) external onlyOwner { + 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 { + 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 { + dustAssetRedemptionRelativeFee = _dustAssetRedemptionRelativeFee; + } + /// @notice Sets up the fee distribution among recipients. /// @param recipients The addresses of the fee recipients. /// @param shares The share of the fee each recipient should receive. From a570e8f98a25e447fa95c003577de00112079448 Mon Sep 17 00:00:00 2001 From: "Pawel Troka, Ph.D. Eng" Date: Thu, 30 Nov 2023 13:48:01 +0100 Subject: [PATCH 2/8] add note about only contract owner being able to call fee setup --- src/FeeCalculator.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 50b6021..c5ba14c 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -91,6 +91,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab } /// @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 { From da780fbdf27ba5e74169ce0c2ab1b5c738a37211 Mon Sep 17 00:00:00 2001 From: "Pawel Troka, Ph.D. Eng" Date: Thu, 30 Nov 2023 14:02:31 +0100 Subject: [PATCH 3/8] fix setRedemptionFeeConstant doc --- src/FeeCalculator.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index c5ba14c..468c530 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -71,7 +71,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @notice Sets the redemption fee constant. /// @dev Can only be called by the current owner. - /// @param _redemptionFeeShift The new redemption fee shift. + /// @param _redemptionFeeConstant The new redemption fee shift. function setRedemptionFeeConstant(SD59x18 _redemptionFeeConstant) external onlyOwner { redemptionFeeConstant = _redemptionFeeConstant; } From 0384818c7c98ae39354e3c73088791ac2f9626f5 Mon Sep 17 00:00:00 2001 From: "Pawel Troka, Ph.D. Eng" Date: Mon, 4 Dec 2023 11:58:41 +0100 Subject: [PATCH 4/8] add some basic validation to setting fee parameters --- src/FeeCalculator.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 468c530..d5a07d3 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -38,6 +38,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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; } @@ -45,6 +46,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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 && _depositFeeRatioScale <= one, "Deposit fee ratio scale must be between 0 and 1"); depositFeeRatioScale = _depositFeeRatioScale; } @@ -52,6 +54,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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; } @@ -59,6 +62,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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; } @@ -66,6 +70,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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; } @@ -73,6 +78,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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; } @@ -80,6 +86,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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; } @@ -87,6 +94,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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; } From fa307a68a7d9735a89d6924907a802019152bd1b Mon Sep 17 00:00:00 2001 From: "Pawel Troka, Ph.D. Eng" Date: Mon, 4 Dec 2023 12:10:43 +0100 Subject: [PATCH 5/8] add setting fee parameters validation tests --- test/FeeCalculator.t.sol | 96 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/test/FeeCalculator.t.sol b/test/FeeCalculator.t.sol index dd79ac8..380ae65 100644 --- a/test/FeeCalculator.t.sol +++ b/test/FeeCalculator.t.sol @@ -658,4 +658,100 @@ 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 testSetDepositFeeRatioScaleReverts() public { + SD59x18 invalid = sd(1.2 * 1e18); + vm.expectRevert("Deposit fee ratio scale must be between 0 and 1"); + feeCalculator.setDepositFeeRatioScale(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 between 0 and 1"); + 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); + } } From 25d6f5c515d980edbfd7bee398de17afdf8a8c82 Mon Sep 17 00:00:00 2001 From: "Pawel Troka, Ph.D. Eng" Date: Mon, 4 Dec 2023 12:11:01 +0100 Subject: [PATCH 6/8] reformat code --- src/FeeCalculator.sol | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index d5a07d3..362ab42 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -46,7 +46,10 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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 && _depositFeeRatioScale <= one, "Deposit fee ratio scale must be between 0 and 1"); + require( + _depositFeeRatioScale >= zero && _depositFeeRatioScale <= one, + "Deposit fee ratio scale must be between 0 and 1" + ); depositFeeRatioScale = _depositFeeRatioScale; } @@ -54,7 +57,10 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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"); + require( + _singleAssetDepositRelativeFee >= zero && _singleAssetDepositRelativeFee <= one, + "Single asset deposit relative fee must be between 0 and 1" + ); singleAssetDepositRelativeFee = _singleAssetDepositRelativeFee; } @@ -62,7 +68,9 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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"); + require( + _redemptionFeeScale >= zero && _redemptionFeeScale <= one, "Redemption fee scale must be between 0 and 1" + ); redemptionFeeScale = _redemptionFeeScale; } @@ -70,7 +78,9 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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"); + require( + _redemptionFeeShift >= zero && _redemptionFeeShift <= one, "Redemption fee shift must be between 0 and 1" + ); redemptionFeeShift = _redemptionFeeShift; } @@ -78,7 +88,10 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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"); + require( + _redemptionFeeConstant >= zero && _redemptionFeeConstant <= one, + "Redemption fee constant must be between 0 and 1" + ); redemptionFeeConstant = _redemptionFeeConstant; } @@ -86,7 +99,10 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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"); + require( + _singleAssetRedemptionRelativeFee >= zero && _singleAssetRedemptionRelativeFee <= one, + "Single asset redemption relative fee must be between 0 and 1" + ); singleAssetRedemptionRelativeFee = _singleAssetRedemptionRelativeFee; } @@ -94,7 +110,10 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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"); + require( + _dustAssetRedemptionRelativeFee >= zero && _dustAssetRedemptionRelativeFee <= one, + "Dust asset redemption relative fee must be between 0 and 1" + ); dustAssetRedemptionRelativeFee = _dustAssetRedemptionRelativeFee; } From 44ff3ebe73bab7acd806aea08aa9695f43fa7c4a Mon Sep 17 00:00:00 2001 From: "Pawel Troka, Ph.D. Eng" Date: Mon, 4 Dec 2023 13:21:04 +0100 Subject: [PATCH 7/8] allow deposit fee ratio scale above 1 --- src/FeeCalculator.sol | 5 +---- test/FeeCalculator.t.sol | 8 +------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 362ab42..8d769d7 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -46,10 +46,7 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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 && _depositFeeRatioScale <= one, - "Deposit fee ratio scale must be between 0 and 1" - ); + require(_depositFeeRatioScale >= zero, "Deposit fee ratio scale must be above 0"); depositFeeRatioScale = _depositFeeRatioScale; } diff --git a/test/FeeCalculator.t.sol b/test/FeeCalculator.t.sol index 380ae65..e468d39 100644 --- a/test/FeeCalculator.t.sol +++ b/test/FeeCalculator.t.sol @@ -665,12 +665,6 @@ contract FeeCalculatorTest is Test { feeCalculator.setDepositFeeScale(invalid); } - function testSetDepositFeeRatioScaleReverts() public { - SD59x18 invalid = sd(1.2 * 1e18); - vm.expectRevert("Deposit fee ratio scale must be between 0 and 1"); - feeCalculator.setDepositFeeRatioScale(invalid); - } - function testSetSingleAssetDepositRelativeFeeReverts() public { SD59x18 invalid = sd(1.3 * 1e18); vm.expectRevert("Single asset deposit relative fee must be between 0 and 1"); @@ -715,7 +709,7 @@ contract FeeCalculatorTest is Test { function testSetDepositFeeRatioScaleNegativeReverts() public { SD59x18 invalid = sd(-0.2 * 1e18); - vm.expectRevert("Deposit fee ratio scale must be between 0 and 1"); + vm.expectRevert("Deposit fee ratio scale must be above 0"); feeCalculator.setDepositFeeRatioScale(invalid); } From e8b08e452ac6d9c279c045af5cda6f242a0eceac Mon Sep 17 00:00:00 2001 From: "Pawel Troka, Ph.D. Eng" Date: Mon, 4 Dec 2023 14:47:21 +0100 Subject: [PATCH 8/8] externally called setters should take int256 and cast it to sd59x18 inside --- src/FeeCalculator.sol | 56 +++++++++++++++++++++++----------------- test/FeeCalculator.t.sol | 30 ++++++++++----------- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 8d769d7..c8392f8 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -37,81 +37,89 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator, Ownab /// @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; + 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(SD59x18 _depositFeeRatioScale) external onlyOwner { - require(_depositFeeRatioScale >= zero, "Deposit fee ratio scale must be above 0"); - depositFeeRatioScale = _depositFeeRatioScale; + 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(SD59x18 _singleAssetDepositRelativeFee) external onlyOwner { + function setSingleAssetDepositRelativeFee(int256 _singleAssetDepositRelativeFee) external onlyOwner { + SD59x18 singleAssetDepositRelativeFeeSD = sd(_singleAssetDepositRelativeFee); require( - _singleAssetDepositRelativeFee >= zero && _singleAssetDepositRelativeFee <= one, + singleAssetDepositRelativeFeeSD >= zero && singleAssetDepositRelativeFeeSD <= one, "Single asset deposit relative fee must be between 0 and 1" ); - singleAssetDepositRelativeFee = _singleAssetDepositRelativeFee; + 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(SD59x18 _redemptionFeeScale) external onlyOwner { + function setRedemptionFeeScale(int256 _redemptionFeeScale) external onlyOwner { + SD59x18 redemptionFeeScaleSD = sd(_redemptionFeeScale); require( - _redemptionFeeScale >= zero && _redemptionFeeScale <= one, "Redemption fee scale must be between 0 and 1" + redemptionFeeScaleSD >= zero && redemptionFeeScaleSD <= one, "Redemption fee scale must be between 0 and 1" ); - redemptionFeeScale = _redemptionFeeScale; + 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(SD59x18 _redemptionFeeShift) external onlyOwner { + function setRedemptionFeeShift(int256 _redemptionFeeShift) external onlyOwner { + SD59x18 redemptionFeeShiftSD = sd(_redemptionFeeShift); require( - _redemptionFeeShift >= zero && _redemptionFeeShift <= one, "Redemption fee shift must be between 0 and 1" + redemptionFeeShiftSD >= zero && redemptionFeeShiftSD <= one, "Redemption fee shift must be between 0 and 1" ); - redemptionFeeShift = _redemptionFeeShift; + 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(SD59x18 _redemptionFeeConstant) external onlyOwner { + function setRedemptionFeeConstant(int256 _redemptionFeeConstant) external onlyOwner { + SD59x18 redemptionFeeConstantSD = sd(_redemptionFeeConstant); require( - _redemptionFeeConstant >= zero && _redemptionFeeConstant <= one, + redemptionFeeConstantSD >= zero && redemptionFeeConstantSD <= one, "Redemption fee constant must be between 0 and 1" ); - redemptionFeeConstant = _redemptionFeeConstant; + 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(SD59x18 _singleAssetRedemptionRelativeFee) external onlyOwner { + function setSingleAssetRedemptionRelativeFee(int256 _singleAssetRedemptionRelativeFee) external onlyOwner { + SD59x18 singleAssetRedemptionRelativeFeeSD = sd(_singleAssetRedemptionRelativeFee); require( - _singleAssetRedemptionRelativeFee >= zero && _singleAssetRedemptionRelativeFee <= one, + singleAssetRedemptionRelativeFeeSD >= zero && singleAssetRedemptionRelativeFeeSD <= one, "Single asset redemption relative fee must be between 0 and 1" ); - singleAssetRedemptionRelativeFee = _singleAssetRedemptionRelativeFee; + 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(SD59x18 _dustAssetRedemptionRelativeFee) external onlyOwner { + function setDustAssetRedemptionRelativeFee(int256 _dustAssetRedemptionRelativeFee) external onlyOwner { + SD59x18 dustAssetRedemptionRelativeFeeSD = sd(_dustAssetRedemptionRelativeFee); require( - _dustAssetRedemptionRelativeFee >= zero && _dustAssetRedemptionRelativeFee <= one, + dustAssetRedemptionRelativeFeeSD >= zero && dustAssetRedemptionRelativeFeeSD <= one, "Dust asset redemption relative fee must be between 0 and 1" ); - dustAssetRedemptionRelativeFee = _dustAssetRedemptionRelativeFee; + dustAssetRedemptionRelativeFee = dustAssetRedemptionRelativeFeeSD; } /// @notice Sets up the fee distribution among recipients. diff --git a/test/FeeCalculator.t.sol b/test/FeeCalculator.t.sol index e468d39..a5cf6ca 100644 --- a/test/FeeCalculator.t.sol +++ b/test/FeeCalculator.t.sol @@ -660,91 +660,91 @@ contract FeeCalculatorTest is Test { } function testSetDepositFeeScaleReverts() public { - SD59x18 invalid = sd(1.1 * 1e18); + int256 invalid = (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); + int256 invalid = (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); + int256 invalid = (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); + int256 invalid = (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); + int256 invalid = (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); + int256 invalid = (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); + int256 invalid = (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); + int256 invalid = (-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); + int256 invalid = (-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); + int256 invalid = (-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); + int256 invalid = (-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); + int256 invalid = (-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); + int256 invalid = (-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); + int256 invalid = (-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); + int256 invalid = (-0.8 * 1e18); vm.expectRevert("Dust asset redemption relative fee must be between 0 and 1"); feeCalculator.setDustAssetRedemptionRelativeFee(invalid); }