diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 22d48b9..61277f4 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -163,7 +163,10 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator { /// @param total The total supply of the pool. /// @return The calculated deposit fee. function getDepositFee(uint256 amount, uint256 current, uint256 total) private view returns (uint256) { - require(total >= current); + require( + total >= current, + "The total volume in the pool must be greater than or equal to the volume for an individual asset" + ); SD59x18 amount_float = sd(int256(amount)); @@ -194,8 +197,11 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator { /// @param total The total supply of the pool. /// @return The calculated redemption fee. function getRedemptionFee(uint256 amount, uint256 current, uint256 total) private view returns (uint256) { - require(total >= current); - require(amount <= current); + require( + total >= current, + "The total volume in the pool must be greater than or equal to the volume for an individual asset" + ); + require(amount <= current, "The amount to be redeemed cannot exceed the current balance of the pool"); SD59x18 amount_float = sd(int256(amount)); diff --git a/test/FeeCalculator.t.sol b/test/FeeCalculator.t.sol index c90988d..ad01ca3 100644 --- a/test/FeeCalculator.t.sol +++ b/test/FeeCalculator.t.sol @@ -497,6 +497,70 @@ contract FeeCalculatorTest is Test { feeCalculator.calculateDepositFees(address(mockToken), address(mockPool), depositAmount); } + function testCalculateDepositFees_CurrentGreaterThanTotal_ExceptionShouldBeThrown() public { + // Arrange + // Set up your test data + uint256 depositAmount = 1; + + // Set up mock pool + mockPool.setTotalSupply(1000 * 1e18); + mockToken.setTokenBalance(address(mockPool), 1500 * 1e18); + + // Act + vm.expectRevert( + "The total volume in the pool must be greater than or equal to the volume for an individual asset" + ); + (address[] memory recipients, uint256[] memory fees) = + feeCalculator.calculateDepositFees(address(mockToken), address(mockPool), depositAmount); + } + + function testCalculateRedemptionFees_CurrentGreaterThanTotal_ExceptionShouldBeThrown() public { + // Arrange + // Set up your test data + uint256 depositAmount = 1; + + // Set up mock pool + mockPool.setTotalSupply(1000 * 1e18); + mockToken.setTokenBalance(address(mockPool), 1500 * 1e18); + + // Act & Assert + vm.expectRevert( + "The total volume in the pool must be greater than or equal to the volume for an individual asset" + ); + (address[] memory recipients, uint256[] memory fees) = + feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), depositAmount); + } + + function testCalculateRedemptionFees_AmountGreaterThanCurrent_ExceptionShouldBeThrown() public { + // Arrange + // Set up your test data + uint256 depositAmount = 600 * 1e18; + + // Set up mock pool + mockPool.setTotalSupply(1000 * 1e18); + mockToken.setTokenBalance(address(mockPool), 500 * 1e18); + + // Act + vm.expectRevert("The amount to be redeemed cannot exceed the current balance of the pool"); + (address[] memory recipients, uint256[] memory fees) = + feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), depositAmount); + } + + function testCalculateRedemptionFees_ZeroRedemption_ExceptionShouldBeThrown() public { + // Arrange + // Set up your test data + uint256 depositAmount = 0; + + // Set up mock pool + mockPool.setTotalSupply(1000 * 1e18); + mockToken.setTokenBalance(address(mockPool), 500 * 1e18); + + // Act & Assert + vm.expectRevert("redemptionAmount must be > 0"); + (address[] memory recipients, uint256[] memory fees) = + feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), depositAmount); + } + function testCalculateDepositFees_EmptyPool_FeeCappedAt10Percent() public { // Arrange // Set up your test data @@ -837,6 +901,55 @@ contract FeeCalculatorTest is Test { return sum; } + function testFeeSetup_RecipientsEmpty_ShouldThrowError() public { + // Arrange + // Set up your test data + address[] memory _recipients = new address[](0); + uint256[] memory _feeShares = new uint256[](0); + + // Act & Assert + vm.expectRevert("Total shares must equal 100"); + feeCalculator.feeSetup(_recipients, _feeShares); + } + + function testFeeSetup_RecipientsAndSharesDifferentLength_ShouldThrowError() public { + // Arrange + // Set up your test data + address feeRecipient1 = 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B; + address feeRecipient2 = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c; + address[] memory _recipients = new address[](2); + _recipients[0] = feeRecipient1; + _recipients[1] = feeRecipient2; + uint256[] memory _feeShares = new uint256[](3); + _feeShares[0] = 20; + _feeShares[1] = 20; + _feeShares[2] = 60; + + // Act & Assert + vm.expectRevert("Recipients and shares arrays must have the same length"); + feeCalculator.feeSetup(_recipients, _feeShares); + } + + function testFeeSetup_RecipientsAndSharesSameLengthButSharesSumUpTo101_ShouldThrowError() public { + // Arrange + // Set up your test data + address feeRecipient1 = 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B; + address feeRecipient2 = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c; + address feeRecipient3 = 0xb1bB642E2CD1E3254d3395f02483e3DA7baF2d83; + address[] memory _recipients = new address[](3); + _recipients[0] = feeRecipient1; + _recipients[1] = feeRecipient2; + _recipients[2] = feeRecipient3; + uint256[] memory _feeShares = new uint256[](3); + _feeShares[0] = 21; + _feeShares[1] = 20; + _feeShares[2] = 60; + + // Act & Assert + vm.expectRevert("Total shares must equal 100"); + feeCalculator.feeSetup(_recipients, _feeShares); + } + function testFeeSetupFuzzy(address[] memory recipients, uint8 firstShare) public { vm.assume(recipients.length <= 100); vm.assume(recipients.length > 1); //at least two recipients