Skip to content

Commit

Permalink
Merge pull request #32 from neutral-protocol/interface-update
Browse files Browse the repository at this point in the history
chore: extend fee sharing interface to be action-specific
  • Loading branch information
0xmichalis authored Jan 4, 2024
2 parents ff220ff + 2862c30 commit 8a3ffe4
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 46 deletions.
30 changes: 27 additions & 3 deletions src/FeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ contract FeeCalculator is IFeeCalculator, Ownable {
require(feeAmount > 0, "Fee must be greater than 0");
}

/// @notice Calculates the total fee among the recipients according to their shares.
/// @notice Calculates the fee shares and recipients based on the total fee.
/// @param totalFee The total fee to be distributed.
/// @return recipients The addresses of the fee recipients.
/// @return feesDenominatedInPoolTokens The amount of fees each recipient should receive.
function calculateFeeAmongShares(uint256 totalFee)
external
function calculateFeeShares(uint256 totalFee)
internal
view
returns (address[] memory recipients, uint256[] memory feesDenominatedInPoolTokens)
{
Expand Down Expand Up @@ -193,6 +193,30 @@ contract FeeCalculator is IFeeCalculator, Ownable {
require(feeAmount > 0, "Fee must be greater than 0");
}

/// @notice Calculates the fee shares and recipients for a deposit based on the total fee.
/// @param totalFee The total fee to be shared.
/// @return recipients The addresses of the fee recipients.
/// @return feesDenominatedInPoolTokens The amount of fees each recipient should receive.
function calculateDepositFeeShares(uint256 totalFee)
external
view
returns (address[] memory recipients, uint256[] memory feesDenominatedInPoolTokens)
{
return calculateFeeShares(totalFee);
}

/// @notice Calculates the fee shares and recipients for a redemption based on the total fee.
/// @param totalFee The total fee to be shared.
/// @return recipients The addresses of the fee recipients.
/// @return feesDenominatedInPoolTokens The amount of fees each recipient should receive.
function calculateRedemptionFeeShares(uint256 totalFee)
external
view
returns (address[] memory recipients, uint256[] memory feesDenominatedInPoolTokens)
{
return calculateFeeShares(totalFee);
}

/// @notice Gets the balance of the TCO2 token in a given pool.
/// @param pool The address of the pool.
/// @param tco2 The address of the TCO2 token.
Expand Down
15 changes: 12 additions & 3 deletions src/interfaces/IFeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ interface IFeeCalculator {
view
returns (uint256 feeAmount);

/// @notice Calculates the total fee among the recipients according to their shares.
/// @param totalFee The total fee to be distributed.
/// @notice Calculates the fee shares and recipients for a deposit based on the total fee.
/// @param totalFee The total fee to be shared.
/// @return recipients The addresses of the fee recipients.
/// @return feesDenominatedInPoolTokens The amount of fees each recipient should receive.
function calculateFeeAmongShares(uint256 totalFee)
function calculateDepositFeeShares(uint256 totalFee)
external
view
returns (address[] memory recipients, uint256[] memory feesDenominatedInPoolTokens);

/// @notice Calculates the fee shares and recipients for a redemption based on the total fee.
/// @param totalFee The total fee to be shared.
/// @return recipients The addresses of the fee recipients.
/// @return feesDenominatedInPoolTokens The amount of fees each recipient should receive.
function calculateRedemptionFeeShares(uint256 totalFee)
external
view
returns (address[] memory recipients, uint256[] memory feesDenominatedInPoolTokens);
Expand Down
2 changes: 1 addition & 1 deletion test/FeeCalculator.fuzzy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ contract FeeCalculatorTestFuzzy is Test {

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

// Assert
assertEq(gotRecipients.length, recipients.length);
Expand Down
54 changes: 27 additions & 27 deletions test/FeeCalculator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand All @@ -92,7 +92,7 @@ contract FeeCalculatorTest is Test {
// Act
uint256 feeAmount =
feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), redemptionAmount);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateRedemptionFeeShares(feeAmount);

// Assert
assertEq(recipients[0], feeRecipient);
Expand All @@ -111,7 +111,7 @@ contract FeeCalculatorTest is Test {
// Act
uint256 feeAmount =
feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), redemptionAmount);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateRedemptionFeeShares(feeAmount);

// Assert
assertEq(recipients[0], feeRecipient);
Expand All @@ -132,7 +132,7 @@ contract FeeCalculatorTest is Test {
// Act
uint256 feeAmount =
feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), redemptionAmount);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateRedemptionFeeShares(feeAmount);

// Assert
assertEq(recipients[0], feeRecipient);
Expand Down Expand Up @@ -160,7 +160,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient1);
Expand Down Expand Up @@ -191,7 +191,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient1);
Expand All @@ -212,7 +212,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand Down Expand Up @@ -261,7 +261,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand All @@ -279,7 +279,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand Down Expand Up @@ -316,7 +316,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient1);
Expand Down Expand Up @@ -362,7 +362,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient1);
Expand All @@ -389,7 +389,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand Down Expand Up @@ -481,7 +481,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand All @@ -499,7 +499,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand Down Expand Up @@ -532,7 +532,7 @@ contract FeeCalculatorTest is Test {
// Act
uint256 feeAmount =
feeCalculator.calculateRedemptionFees(address(mockToken), address(mockPool), redemptionAmount);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateFeeAmongShares(feeAmount);
(address[] memory recipients, uint256[] memory fees) = feeCalculator.calculateRedemptionFeeShares(feeAmount);

// Assert
assertEq(recipients[0], feeRecipient);
Expand All @@ -550,7 +550,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand All @@ -568,7 +568,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand All @@ -586,7 +586,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand All @@ -605,7 +605,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand All @@ -623,7 +623,7 @@ contract FeeCalculatorTest is Test {

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

// Assert
assertEq(recipients[0], feeRecipient);
Expand Down Expand Up @@ -766,7 +766,7 @@ contract FeeCalculatorTest is Test {

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

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

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

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

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

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

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

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

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

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

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

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

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

// Assert
assertEq(fees[0], depositAmount * 91 / 100);
Expand Down
Loading

0 comments on commit 8a3ffe4

Please sign in to comment.