From 0a938c0e1f6ecaa824c6bfb238fc6ed35a8d3ec9 Mon Sep 17 00:00:00 2001 From: "Pawel Troka, Ph.D. Eng" Date: Wed, 22 Nov 2023 11:18:44 +0100 Subject: [PATCH] adapt tests for `10 percent flat fee for deposits and redemptions when there is a single asset in the pool or the pool is empty` also add few new tests --- test/FeeCalculator.t.sol | 78 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/test/FeeCalculator.t.sol b/test/FeeCalculator.t.sol index 9d1d551..2908b37 100644 --- a/test/FeeCalculator.t.sol +++ b/test/FeeCalculator.t.sol @@ -147,7 +147,7 @@ contract FeeCalculatorTest is Test { assertApproxEqRel(fees[0], intoUint256((redemptionFeeScale + redemptionFeeConstant).mul(ud(redemptionAmount))), 1e15);//we allow 0.1% discrepancy } - function testCalculateRedemptionFees_FullMonopolization_ZeroFees() public { + function testCalculateRedemptionFees_FullMonopolization_FeesCappedAt10Percent() public { // Arrange // Set up your test data uint256 redemptionAmount = 1 * 1e18; @@ -159,6 +159,23 @@ contract FeeCalculatorTest is Test { // Act (address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateRedemptionFee(address(mockToken), address(mockPool), redemptionAmount); + // Assert + assertEq(recipients[0], feeRecipient); + assertEq(fees[0], redemptionAmount/10); + } + + function testCalculateRedemptionFees_AlmostFullMonopolization_ZeroFees() public { + // Arrange + // Set up your test data + uint256 redemptionAmount = 1 * 1e18; + + // Set up mock pool + mockPool.setTotalSupply(1e6 * 1e18 + 1); + mockToken.setTokenBalance(address(mockPool), 1e6 * 1e18); + + // Act + (address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateRedemptionFee(address(mockToken), address(mockPool), redemptionAmount); + // Assert assertEq(recipients[0], feeRecipient); assertEq(fees[0], 0); @@ -503,7 +520,7 @@ contract FeeCalculatorTest is Test { } } - function testCalculateDepositFees_EmptyPool_FeeCappedAt36Percent() public { + function testCalculateDepositFees_EmptyPool_FeeCappedAt10Percent() public { // Arrange // Set up your test data uint256 depositAmount = 100*1e18; @@ -517,10 +534,44 @@ contract FeeCalculatorTest is Test { // Assert assertEq(recipients[0], feeRecipient); - assertEq(fees[0], 36 * 1e18); + assertEq(fees[0], depositAmount/10); + } + + function testCalculateDepositFees_AlmostEmptyPool_FeeAlmostCappedAt36Percent() public { + // Arrange + // Set up your test data + uint256 depositAmount = 100*1e18; + + // Set up mock pool + mockPool.setTotalSupply(1); + mockToken.setTokenBalance(address(mockPool), 0); + + // Act + (address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateDepositFees(address(mockToken), address(mockPool), depositAmount); + + // Assert + assertEq(recipients[0], feeRecipient); + assertEq(fees[0], 35999999999999999154); } - function testCalculateDepositFees_TotalEqualCurrent_FeeCappedAt36Percent() public { + function testCalculateRedemptionFees_TotalEqualCurrent_FeeCappedAt10Percent() public { + // Arrange + // Set up your test data + uint256 redemptionAmount = 100; + + // Set up mock pool + mockPool.setTotalSupply(1000); + mockToken.setTokenBalance(address(mockPool), 1000); + + // Act + (address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateRedemptionFee(address(mockToken), address(mockPool), redemptionAmount); + + // Assert + assertEq(recipients[0], feeRecipient); + assertEq(fees[0], redemptionAmount/10); + } + + function testCalculateDepositFees_TotalEqualCurrent_FeeCappedAt10Percent() public { // Arrange // Set up your test data uint256 depositAmount = 100*1e18; @@ -534,7 +585,24 @@ contract FeeCalculatorTest is Test { // Assert assertEq(recipients[0], feeRecipient); - assertEq(fees[0], 36*1e18); + assertEq(fees[0], depositAmount/10); + } + + function testCalculateDepositFees_TotalAlmostEqualCurrent_FeeAlmostCappedAt36Percent() public { + // Arrange + // Set up your test data + uint256 depositAmount = 100*1e18; + + // Set up mock pool + mockPool.setTotalSupply(1000); + mockToken.setTokenBalance(address(mockPool), 999); + + // Act + (address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateDepositFees(address(mockToken), address(mockPool), depositAmount); + + // Assert + assertEq(recipients[0], feeRecipient); + assertEq(fees[0], 35999999999999999161); } function testCalculateDepositFees_ZeroCurrent_NormalFees() public {