@bananapus/core-v6 0.0.69 → 0.0.71

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/foundry.toml CHANGED
@@ -2,7 +2,7 @@
2
2
  solc = '0.8.28'
3
3
  bytecode_hash = "none"
4
4
  evm_version = 'cancun'
5
- optimizer_runs = 150
5
+ optimizer_runs = 200
6
6
  libs = ["node_modules", "lib"]
7
7
  fs_permissions = [{ access = "read-write", path = "./"}]
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananapus/core-v6",
3
- "version": "0.0.69",
3
+ "version": "0.0.71",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -168,12 +168,15 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
168
168
  //*********************************************************************//
169
169
 
170
170
  /// @notice Whether this terminal is currently measuring an incoming ERC-20 balance delta.
171
- bool transient _acceptingToken;
171
+ bool internal transient _acceptingToken;
172
172
 
173
173
  /// @notice Source project ID for the same-terminal split pay currently being recorded.
174
174
  /// @dev After `_pay` consumes and clears this value, `_fulfillPayHookSpecificationsFor` reuses the slot to return
175
175
  /// the fee basis to `executePayout`.
176
- uint256 transient _internalSplitPayProjectId;
176
+ uint256 internal transient _internalSplitPayProjectId;
177
+
178
+ /// @notice The in-flight fee amount that can credit `currentReferralProjectId`.
179
+ uint256 internal transient _feeReferralCreditAmount;
177
180
 
178
181
  //*********************************************************************//
179
182
  // -------------------------- constructor ---------------------------- //
@@ -676,7 +679,7 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
676
679
  returns (uint256 beneficiaryTokenCount)
677
680
  {
678
681
  // Get a reference to the beneficiary's balance before the payment.
679
- uint256 beneficiaryBalanceBefore = TOKENS.totalBalanceOf({holder: beneficiary, projectId: projectId});
682
+ uint256 beneficiaryBalanceBefore = _totalBalanceOf({holder: beneficiary, projectId: projectId});
680
683
 
681
684
  // Accept the funds.
682
685
  uint256 acceptedAmount =
@@ -694,7 +697,7 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
694
697
  });
695
698
 
696
699
  // Get a reference to the beneficiary's balance after the payment.
697
- uint256 beneficiaryBalanceAfter = TOKENS.totalBalanceOf({holder: beneficiary, projectId: projectId});
700
+ uint256 beneficiaryBalanceAfter = _totalBalanceOf({holder: beneficiary, projectId: projectId});
698
701
 
699
702
  // Set the beneficiary token count.
700
703
  if (beneficiaryBalanceAfter > beneficiaryBalanceBefore) {
@@ -1764,6 +1767,17 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
1764
1767
  // Keep a reference to the token amount to forward to the store.
1765
1768
  JBTokenAmount memory tokenAmount = _tokenAmountOf({projectId: projectId, token: token, value: amount});
1766
1769
 
1770
+ // Credit only the one pay call currently being made by `_processFee`. Ordinary split pays to project #1 can
1771
+ // happen while `currentReferralProjectId` is set, but they are not protocol-fee payments. Consume this before
1772
+ // recording the payment so fee-project data hooks cannot reenter and use the in-flight credit.
1773
+ if (
1774
+ projectId == JBConstants.FEE_BENEFICIARY_PROJECT_ID && currentReferralProjectId != 0
1775
+ && _feeReferralCreditAmount != 0
1776
+ ) {
1777
+ delete _feeReferralCreditAmount;
1778
+ STORE.recordFeeReferralCreditOf({referralProjectId: currentReferralProjectId, amount: tokenAmount});
1779
+ }
1780
+
1767
1781
  // Record the payment.
1768
1782
  // Keep a reference to the ruleset the payment is being made during.
1769
1783
  // Keep a reference to the pay hook specifications.
@@ -1772,15 +1786,6 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
1772
1786
  payer: payer, amount: tokenAmount, projectId: projectId, beneficiary: beneficiary, metadata: metadata
1773
1787
  });
1774
1788
 
1775
- // Credit the originating fee-paying call's referral project. This is only meaningful when this pay is a
1776
- // protocol-fee payment landing on the fee project AND a referral was set by the outer entry point (or
1777
- // restored from a held fee by `processHeldFeesOf`). The store handles the no-op case when either input is
1778
- // zero. Done here (after `recordPaymentFrom`) instead of inside the store so the credit logic stays in the
1779
- // terminal and the store is never asked to call back into us.
1780
- if (projectId == JBConstants.FEE_BENEFICIARY_PROJECT_ID && currentReferralProjectId != 0) {
1781
- STORE.recordFeeReferralCreditOf({referralProjectId: currentReferralProjectId, amount: tokenAmount});
1782
- }
1783
-
1784
1789
  // Only the value retained in the destination balance needs later cashout fee recovery. Non-feeless pay-hook
1785
1790
  // forwards pay their source-equivalent fee inline before leaving the project.
1786
1791
  if (internalSplitPayProjectId != 0) {
@@ -1862,9 +1867,11 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
1862
1867
  )
1863
1868
  internal
1864
1869
  {
1870
+ if (feeTerminal == IJBTerminal(address(this))) _feeReferralCreditAmount = amount;
1865
1871
  try this.executeProcessFee({
1866
1872
  projectId: projectId, token: token, amount: amount, beneficiary: beneficiary, feeTerminal: feeTerminal
1867
1873
  }) {
1874
+ delete _feeReferralCreditAmount;
1868
1875
  emit ProcessFee({
1869
1876
  projectId: projectId,
1870
1877
  token: token,
@@ -1874,6 +1881,7 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
1874
1881
  caller: _msgSender()
1875
1882
  });
1876
1883
  } catch (bytes memory reason) {
1884
+ delete _feeReferralCreditAmount;
1877
1885
  // Fee processing is fail-open for project liveness: a broken project #1 terminal or fee route must not
1878
1886
  // trap payouts, cash outs, allowances, held-fee processing, or terminal migration. The fee is forgiven,
1879
1887
  // credited back to the originating project on this terminal, and surfaced through `FeeReverted`.
@@ -2324,6 +2332,14 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
2324
2332
  JBTokenAmount({token: token, decimals: context.decimals, currency: context.currency, value: value});
2325
2333
  }
2326
2334
 
2335
+ /// @notice Returns a holder's total token balance for a project.
2336
+ /// @param holder The holder to get a balance for.
2337
+ /// @param projectId The ID of the project to get a balance for.
2338
+ /// @return balance The holder's total project token balance.
2339
+ function _totalBalanceOf(address holder, uint256 projectId) internal view returns (uint256 balance) {
2340
+ return TOKENS.totalBalanceOf({holder: holder, projectId: projectId});
2341
+ }
2342
+
2327
2343
  //*********************************************************************//
2328
2344
  // -------------------------- private helpers ------------------------ //
2329
2345
  //*********************************************************************//