Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jango/fee always from #234

Merged
merged 4 commits into from
Jan 19, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
touchup
  • Loading branch information
mejango committed Jan 18, 2025

Verified

This commit was signed with the committer’s verified signature.
mejango jango
commit 5aa807f52c744fa6913b688bbf3b1a64dee0ee4e
4 changes: 2 additions & 2 deletions src/JBMultiTerminal.sol
Original file line number Diff line number Diff line change
@@ -1637,7 +1637,7 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
if (leftoverAmount == 0) {
break;
} else {
// Notice here we take `feeAmountIn` on the stored `.amount`.
// Notice here we take `feeAmountFrom` on the stored `.amount`.
uint256 feeAmount = JBFees.feeAmountFrom({amountBeforeFee: heldFee.amount, feePercent: FEE});

// Keep a reference to the amount from which the fee was taken.
@@ -1653,7 +1653,7 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
newStartIndex = startIndex + i + 1;
} else {
// And here we overwrite with `feeAmountFrom` the `leftoverAmount`
feeAmount = JBFees.feeAmountIn({amountAfterFee: leftoverAmount, feePercent: FEE});
feeAmount = JBFees.feeAmountResultingIn({amountAfterFee: leftoverAmount, feePercent: FEE});

// Get fee from `leftoverAmount`.
unchecked {
4 changes: 2 additions & 2 deletions src/libraries/JBFees.sol
Original file line number Diff line number Diff line change
@@ -7,12 +7,12 @@ import {JBConstants} from "./../libraries/JBConstants.sol";

/// @notice Fee calculations.
library JBFees {
/// @notice Returns the amount of tokens to pay as a fee out of the specified `amount`.
/// @notice Returns the amount of tokens to pay as a fee relative to the specified `amount`.
/// @param amountAfterFee The amount that the fee is based on, as a fixed point number.
/// @param feePercent The fee percent, out of `JBConstants.MAX_FEE`.
/// @return The amount of tokens to pay as a fee, as a fixed point number with the same number of decimals as the
/// provided `amount`.
function feeAmountIn(uint256 amountAfterFee, uint256 feePercent) internal pure returns (uint256) {
function feeAmountResultingIn(uint256 amountAfterFee, uint256 feePercent) internal pure returns (uint256) {
// The amount of tokens from the `amount` to pay as a fee. If reverse, the fee taken from a payout of
// `amount`.
return mulDiv(amountAfterFee, JBConstants.MAX_FEE, JBConstants.MAX_FEE - feePercent) - amountAfterFee;
2 changes: 1 addition & 1 deletion test/trees/JBMultiTerminal/addToBalanceOf.tree
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ TestAddToBalanceOf_Local
│ ├── given return amount is zero
│ │ └── it will set heldFeesOf project to zero
│ ├── given return amount is non-zero and leftoverAmount GTEQ amountFromFee
│ │ └── it will return feeAmountIn
│ │ └── it will return feeAmountResultingIn
│ └── given return amount is non-zero and leftoverAmount LT amountFromFee
│ └── it will set heldFeesOf return feeAmountFrom and set leftoverAmount to zero
├── when shouldReturnHeldFees eq false
14 changes: 7 additions & 7 deletions test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ contract TestAddToBalanceOf_Local is JBMultiTerminalSetup {
// set by modifiers
uint256 payAmount;
uint256 feeAmount;
uint256 feeAmountIn;
uint256 feeAmountFrom;
uint256 amountFromFee;
uint256 leftOverAmount;
bool _shouldReturnHeldFees;
@@ -86,9 +86,9 @@ contract TestAddToBalanceOf_Local is JBMultiTerminalSetup {
assertEq(setFees[0].amount, feeAmount);

payAmount = 2e18;
feeAmountIn = JBFees.feeAmountFrom(feeAmount, 25);
feeAmountFrom = JBFees.feeAmountFrom(feeAmount, 25);

amountFromFee = feeAmount - feeAmountIn;
amountFromFee = feeAmount - feeAmountFrom;
leftOverAmount = payAmount - amountFromFee;

_shouldReturnHeldFees = true;
@@ -125,12 +125,12 @@ contract TestAddToBalanceOf_Local is JBMultiTerminalSetup {
// mock call to store recordAddedBalanceFor
mockExpect(
address(store),
abi.encodeCall(IJBTerminalStore.recordAddedBalanceFor, (_projectId, _native, payAmount + feeAmountIn)),
abi.encodeCall(IJBTerminalStore.recordAddedBalanceFor, (_projectId, _native, payAmount + feeAmountFrom)),
""
);

vm.expectEmit();
emit IJBFeeTerminal.ReturnHeldFees(_projectId, _native, payAmount, feeAmountIn, leftOverAmount, address(this));
emit IJBFeeTerminal.ReturnHeldFees(_projectId, _native, payAmount, feeAmountFrom, leftOverAmount, address(this));

_terminal.addToBalanceOf{value: payAmount}({
projectId: _projectId,
@@ -152,7 +152,7 @@ contract TestAddToBalanceOf_Local is JBMultiTerminalSetup {
{
// it will set heldFeesOf return feeAmountFrom and set leftoverAmount to zero
uint256 lowerPayAmount = 1e8;
uint256 returnedFee = JBFees.feeAmountIn(lowerPayAmount, 25);
uint256 returnedFee = JBFees.feeAmountResultingIn(lowerPayAmount, 25);

// mock call to store recordAddedBalanceFor
mockExpect(
@@ -186,7 +186,7 @@ contract TestAddToBalanceOf_Local is JBMultiTerminalSetup {
// mock call to store recordAddedBalanceFor
mockExpect(
address(store),
abi.encodeCall(IJBTerminalStore.recordAddedBalanceFor, (_projectId, _native, payAmount + feeAmountIn)),
abi.encodeCall(IJBTerminalStore.recordAddedBalanceFor, (_projectId, _native, payAmount + feeAmountFrom)),
""
);