Skip to content

Commit

Permalink
Merge pull request #30 from neutral-protocol/more-updates
Browse files Browse the repository at this point in the history
More updates
  • Loading branch information
0xmichalis authored Dec 21, 2023
2 parents 306d97f + 488a95a commit ce1afc9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
10 changes: 8 additions & 2 deletions src/FeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ contract FeeCalculator is IFeeCalculator, Ownable {
if (
current == total //single asset (or no assets) special case
) {
uint256 fee = intoUint256(amount_float * singleAssetDepositRelativeFee);
return fee;
return intoUint256(amount_float * singleAssetDepositRelativeFee);
}

SD59x18 ta = sd(int256(current));
Expand Down Expand Up @@ -320,4 +319,11 @@ contract FeeCalculator is IFeeCalculator, Ownable {

return intoUint256(fee_float);
}

/// @notice Returns the current fee setup.
/// @return recipients shares The fee recipients and their share of the total fee.
function getFeeSetup() external view returns (address[] memory recipients, uint256[] memory shares) {
recipients = _recipients;
shares = _shares;
}
}
2 changes: 2 additions & 0 deletions src/interfaces/IFeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface IFeeCalculator {
/// tokens for this deposit.
function calculateDepositFees(address tco2, address pool, uint256 depositAmount)
external
view
returns (uint256 feeAmount);

/// @notice Calculates the redemption fees for a given amount.
Expand All @@ -27,6 +28,7 @@ interface IFeeCalculator {
/// tokens for this redemption.
function calculateRedemptionFees(address tco2, address pool, uint256 redemptionAmount)
external
view
returns (uint256 feeAmount);

/// @notice Calculates the total fee among the recipients according to their shares.
Expand Down
10 changes: 5 additions & 5 deletions test/FeeCalculator.fuzzy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ contract FeeCalculatorTestFuzzy is Test {
mockToken.setTokenBalance(address(mockPool), current);

// Act
try feeCalculator.calculateDepositFees(address(mockToken), address(mockPool), depositAmount) returns (
uint256 feeAmount
) {} catch Error(string memory reason) {
try feeCalculator.calculateDepositFees(address(mockToken), address(mockPool), depositAmount) {}
catch Error(string memory reason) {
assertTrue(
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
|| keccak256(bytes("Fee must be lower or equal to deposit amount")) == keccak256(bytes(reason)),
Expand Down Expand Up @@ -278,11 +277,12 @@ contract FeeCalculatorTestFuzzy is Test {

// Act
uint256 feeAmount = feeCalculator.calculateDepositFees(address(mockToken), address(mockPool), depositAmount);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(address[] memory gotRecipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);

// Assert
assertEq(gotRecipients.length, recipients.length);
for (uint256 i = 0; i < recipients.length; i++) {
assertEq(recipients[i], recipients[i]);
assertEq(gotRecipients[i], recipients[i]);
}

assertEq(fees.sumOf(), 11526003792614720250);
Expand Down
34 changes: 27 additions & 7 deletions test/FeeCalculator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ contract FeeCalculatorTest is Test {
feeCalculator.feeSetup(recipients, feeShares);
}

function testGetFeeSetup() public {
address feeRecipient1 = 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B;
address feeRecipient2 = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c;

address[] memory recipients = new address[](2);
recipients[0] = feeRecipient1;
recipients[1] = feeRecipient2;
uint256[] memory feeShares = new uint256[](2);
feeShares[0] = 30;
feeShares[1] = 70;

feeCalculator.feeSetup(recipients, feeShares);

(address[] memory _recipients, uint256[] memory _feeShares) = feeCalculator.getFeeSetup();
assertEq(_recipients[0], feeRecipient1);
assertEq(_recipients[1], feeRecipient2);
assertEq(_feeShares[0], 30);
assertEq(_feeShares[1], 70);
}

function testCalculateDepositFeesNormalCase() public {
// Arrange
// Set up your test data
Expand Down Expand Up @@ -746,7 +766,7 @@ contract FeeCalculatorTest is Test {

// Act
uint256 feeAmount = feeCalculator.calculateDepositFees(address(mockToken), address(mockPool), 100 * 1e18);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);

// Assert
assertEq(fees[0], 9718378209069523938 / 2);
Expand All @@ -761,7 +781,7 @@ contract FeeCalculatorTest is Test {

// Act
uint256 feeAmount = feeCalculator.calculateDepositFees(address(mockToken), address(mockPool), 100 * 1e18);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);

// Assert
assertEq(fees[0], 1299819671838098442);
Expand All @@ -776,7 +796,7 @@ contract FeeCalculatorTest is Test {

// Act
uint256 feeAmount = feeCalculator.calculateDepositFees(address(mockToken), address(mockPool), 100 * 1e18);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);

// Assert
assertEq(fees[0], 67 * 1e18);
Expand All @@ -791,7 +811,7 @@ contract FeeCalculatorTest is Test {

// Act
uint256 feeAmount = feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), 100e18);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);

// Assert
assertEq(fees[0], 3778028623870480400);
Expand All @@ -806,7 +826,7 @@ contract FeeCalculatorTest is Test {

// Act
uint256 feeAmount = feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), 100e18);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);

// Assert
assertEq(fees[0], 2303907724666580660);
Expand All @@ -821,7 +841,7 @@ contract FeeCalculatorTest is Test {

// Act
uint256 feeAmount = feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), 100 * 1e18);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);

assertEq(fees[0], 83 * 1e18);
}
Expand All @@ -838,7 +858,7 @@ contract FeeCalculatorTest is Test {

// Act
uint256 feeAmount = feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), depositAmount);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);

// Assert
assertEq(fees[0], depositAmount * 91 / 100);
Expand Down
2 changes: 1 addition & 1 deletion test/TestUtilities.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract MockPool is IERC20 {
return true;
}

function balanceOf(address account) external pure returns (uint256) {
function balanceOf(address) external pure returns (uint256) {
return 0;
}
}
Expand Down

0 comments on commit ce1afc9

Please sign in to comment.