@bananapus/core-v6 0.0.41 → 0.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananapus/core-v6",
3
- "version": "0.0.41",
3
+ "version": "0.0.42",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -88,9 +88,6 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
88
88
  // ------------------------ internal constants ----------------------- //
89
89
  //*********************************************************************//
90
90
 
91
- /// @notice Denominator for forward-calculating this terminal's fee from a pre-fee amount.
92
- uint256 internal constant _FEE_AMOUNT_FROM_DENOMINATOR = JBConstants.MAX_FEE / FEE;
93
-
94
91
  /// @notice Project ID #1 receives fees. It should be the first project launched during the deployment process.
95
92
  uint256 internal constant _FEE_BENEFICIARY_PROJECT_ID = 1;
96
93
 
@@ -1782,9 +1779,7 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
1782
1779
  // Move the start index forward to the held fee after the current one.
1783
1780
  newStartIndex = startIndex + i + 1;
1784
1781
  } else {
1785
- // Use the floor variant here. The minimum 1-unit fee applies when a fee is created, not while
1786
- // splitting an already-held fee entry across repayments.
1787
- feeAmount = JBFees.feeAmountResultingInFloorForFee25(leftoverAmount);
1782
+ feeAmount = JBFees.feeAmountResultingIn({amountAfterFee: leftoverAmount, feePercent: FEE});
1788
1783
 
1789
1784
  // Get fee from `leftoverAmount`.
1790
1785
  unchecked {
@@ -2202,12 +2197,9 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
2202
2197
  //*********************************************************************//
2203
2198
 
2204
2199
  /// @notice The terminal fee charged from a pre-fee `amount`.
2205
- /// @dev Returns at least 1 for nonzero feeable amounts so dust payouts cannot bypass protocol fees.
2206
2200
  /// @param amount The amount before the fee is applied.
2207
- /// @return feeAmount The fee amount.
2208
- function _feeAmountFrom(uint256 amount) private pure returns (uint256 feeAmount) {
2209
- feeAmount = amount / _FEE_AMOUNT_FROM_DENOMINATOR;
2210
-
2211
- return feeAmount == 0 && amount != 0 ? 1 : feeAmount;
2201
+ /// @return The fee amount.
2202
+ function _feeAmountFrom(uint256 amount) private pure returns (uint256) {
2203
+ return JBFees.feeAmountFrom({amountBeforeFee: amount, feePercent: FEE});
2212
2204
  }
2213
2205
  }
@@ -5,68 +5,26 @@ import {mulDiv} from "@prb/math/src/Common.sol";
5
5
 
6
6
  import {JBConstants} from "./../libraries/JBConstants.sol";
7
7
 
8
- /// @notice Utility functions for calculating the protocol fee (2.5%) in both directions: forward (fee from a pre-fee
9
- /// amount) and backward (the pre-fee amount that would yield a given post-fee amount). Used by `JBMultiTerminal`
10
- /// during payouts, surplus allowance usage, and cash outs.
11
- /// @dev Fee dust protection: if a nonzero amount with a nonzero fee would otherwise round to 0, returns 1 wei to
12
- /// prevent fee bypass via many tiny transfers.
8
+ /// @notice Fee calculations.
13
9
  library JBFees {
14
- /// @notice Returns the fee that would be taken from `amountBeforeFee`.
15
- /// @dev Use this to forward-calculate the fee from a known pre-fee amount.
16
- /// @dev If a nonzero amount and nonzero fee would otherwise produce a zero fee, returns 1 so feeable dust payouts
17
- /// cannot bypass protocol fees by splitting across tiny transfers.
18
- /// @param amountBeforeFee The amount before the fee is applied, as a fixed point number.
19
- /// @param feePercent The fee percent, out of `JBConstants.MAX_FEE`.
20
- /// @return The fee amount, as a fixed point number with the same number of decimals as the provided `amount`.
21
- function feeAmountFrom(uint256 amountBeforeFee, uint256 feePercent) internal pure returns (uint256) {
22
- uint256 feeAmount = feeAmountFromFloor({amountBeforeFee: amountBeforeFee, feePercent: feePercent});
23
-
24
- return feeAmount == 0 && amountBeforeFee != 0 && feePercent != 0 ? 1 : feeAmount;
25
- }
26
-
27
- /// @notice Returns the floor-rounded fee that would be taken from `amountBeforeFee`.
28
- /// @dev Fee rounding error is bounded by N-1 wei (N = number of splits). Economically insignificant. Rounds down
29
- /// (mulDiv floors), so the fee beneficiary may receive up to 1 wei less per split.
30
- /// @param amountBeforeFee The amount before the fee is applied, as a fixed point number.
31
- /// @param feePercent The fee percent, out of `JBConstants.MAX_FEE`.
32
- /// @return The floor-rounded fee amount, as a fixed point number with the same number of decimals as the provided
33
- /// `amount`.
34
- function feeAmountFromFloor(uint256 amountBeforeFee, uint256 feePercent) internal pure returns (uint256) {
35
- return mulDiv(amountBeforeFee, feePercent, JBConstants.MAX_FEE);
36
- }
37
-
38
10
  /// @notice Returns the fee amount that, when added to `amountAfterFee`, produces the gross amount needed to yield
39
11
  /// `amountAfterFee` after the fee is deducted.
40
12
  /// @dev Use this to back-calculate the fee from a desired post-fee payout.
41
- /// @dev If a nonzero amount and nonzero fee would otherwise produce a zero fee, returns 1 so feeable dust payouts
42
- /// cannot bypass protocol fees by splitting across tiny transfers.
43
13
  /// @param amountAfterFee The desired post-fee amount, as a fixed point number.
44
14
  /// @param feePercent The fee percent, out of `JBConstants.MAX_FEE`.
45
15
  /// @return The fee amount, as a fixed point number with the same number of decimals as the provided `amount`.
46
16
  function feeAmountResultingIn(uint256 amountAfterFee, uint256 feePercent) internal pure returns (uint256) {
47
- uint256 feeAmount = feeAmountResultingInFloor({amountAfterFee: amountAfterFee, feePercent: feePercent});
48
-
49
- return feeAmount == 0 && amountAfterFee != 0 && feePercent != 0 ? 1 : feeAmount;
50
- }
51
-
52
- /// @notice Returns the floor-rounded fee amount that, when added to `amountAfterFee`, produces the gross amount
53
- /// needed to yield `amountAfterFee` after the fee is deducted.
54
- /// @dev Use this when adjusting an existing held-fee entry, where applying the 1-unit minimum again would double
55
- /// charge dust.
56
- /// @param amountAfterFee The desired post-fee amount, as a fixed point number.
57
- /// @param feePercent The fee percent, out of `JBConstants.MAX_FEE`.
58
- /// @return The floor-rounded fee amount, as a fixed point number with the same number of decimals as the provided
59
- /// `amount`.
60
- function feeAmountResultingInFloor(uint256 amountAfterFee, uint256 feePercent) internal pure returns (uint256) {
61
17
  return mulDiv(amountAfterFee, JBConstants.MAX_FEE, JBConstants.MAX_FEE - feePercent) - amountAfterFee;
62
18
  }
63
19
 
64
- /// @notice Returns the floor-rounded fee amount resulting in `amountAfterFee` for a 2.5% fee.
65
- /// @dev Equivalent to `feeAmountResultingInFloor(amountAfterFee, 25)`, but avoids the generic `mulDiv` path.
66
- /// @param amountAfterFee The desired post-fee amount, as a fixed point number.
67
- /// @return The floor-rounded fee amount.
68
- function feeAmountResultingInFloorForFee25(uint256 amountAfterFee) internal pure returns (uint256) {
69
- // The specialized denominator is `(JBConstants.MAX_FEE - 25) / 25`.
70
- return amountAfterFee / 39;
20
+ /// @notice Returns the fee that would be taken from `amountBeforeFee`.
21
+ /// @dev Use this to forward-calculate the fee from a known pre-fee amount.
22
+ /// @dev Fee rounding error is bounded by N-1 wei (N = number of splits). Economically
23
+ /// insignificant. Rounds down (mulDiv floors), so the fee beneficiary may receive up to 1 wei less per split.
24
+ /// @param amountBeforeFee The amount before the fee is applied, as a fixed point number.
25
+ /// @param feePercent The fee percent, out of `JBConstants.MAX_FEE`.
26
+ /// @return The fee amount, as a fixed point number with the same number of decimals as the provided `amount`.
27
+ function feeAmountFrom(uint256 amountBeforeFee, uint256 feePercent) internal pure returns (uint256) {
28
+ return mulDiv(amountBeforeFee, feePercent, JBConstants.MAX_FEE);
71
29
  }
72
30
  }