@bananapus/721-hook-v6 0.0.10 → 0.0.11

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/README.md CHANGED
@@ -222,7 +222,7 @@ Each pay/cash out hook can then execute custom behavior based on the custom data
222
222
  A project using a 721 tiers hook can specify any number of NFT tiers (up to 65,535 total).
223
223
 
224
224
  - NFT tiers can be removed by the project owner as long as they are not locked (`cannotBeRemoved`). After removing tiers, call `cleanTiers()` on the store to optimize tier iteration.
225
- - NFT tiers can be added by the project owner as long as they respect the hook's `flags`. The flags specify if newly added tiers can have votes (voting units), if new tiers can have non-zero reserve frequencies, if new tiers can allow on-demand minting by the project's owner, and if overspending is allowed.
225
+ - NFT tiers can be added by the project owner as long as they respect the hook's `flags`. Tiers must be sorted by category in ascending order — the store reverts with `JB721TiersHookStore_InvalidCategorySortOrder` if not. The flags specify if newly added tiers can have votes (voting units), if new tiers can have non-zero reserve frequencies, if new tiers can allow on-demand minting by the project's owner, and if overspending is allowed.
226
226
 
227
227
  Each tier has the following properties:
228
228
 
@@ -235,8 +235,8 @@ Each tier has the following properties:
235
235
  - Voting units (optional). By default, each NFT's voting power equals its tier price. If `useVotingUnits` is true, a custom `votingUnits` value is used instead.
236
236
  - A flag to specify whether the NFTs in the tier can always be transferred, or if transfers can be paused depending on the project's ruleset.
237
237
  - A flag to specify whether the contract's owner can mint NFTs from the tier on-demand.
238
- - A split percent and a set of splits (optional). Each tier can route a percentage of its mint price to configured split recipients (other projects, addresses, etc.) every time an NFT from the tier is purchased. The remaining funds stay in the project's balance. The `splitPercent` is out of `JBConstants.SPLITS_TOTAL_PERCENT` (1,000,000,000).
239
- - A set of flags which restrict tiers added in the future (the votes/reserved frequency/on-demand minting/overspending flags noted above).
238
+ - A split percent and a set of splits (optional). Each tier can route a percentage of its mint price to configured split recipients (other projects, addresses, etc.) every time an NFT from the tier is purchased. The remaining funds stay in the project's balance. The `splitPercent` is out of `JBConstants.SPLITS_TOTAL_PERCENT` (1,000,000,000). When splits are active, the hook adjusts the returned weight so the terminal only mints tokens proportional to the amount that actually enters the project treasury (e.g., a 50% split on a 1 ETH payment results in half the normal token issuance). This weight adjustment can be disabled with the `issueTokensForSplits` flag, which gives payers full token credit regardless of where the funds go.
239
+ - A set of flags which restrict tiers added in the future (the votes/reserved frequency/on-demand minting/overspending/issueTokensForSplits flags noted above).
240
240
 
241
241
  Additional notes:
242
242
 
package/SKILLS.md CHANGED
@@ -25,7 +25,7 @@ Tiered ERC-721 NFT hook for Juicebox V6 that mints NFTs when a project is paid a
25
25
  | `afterPayRecordedWith(context)` | `JB721Hook` | Called by terminal after payment. Validates caller is a project terminal, delegates to virtual `_processPayment`. |
26
26
  | `_processPayment(context)` | `JB721TiersHook` | Normalizes payment value via pricing context, decodes payer metadata for tier IDs to mint, calls `_mintAll`, manages pay credits for overspending. Distributes tier split funds via `JB721TiersHookLib.distributeAll` if split amounts were forwarded. |
27
27
  | `afterCashOutRecordedWith(context)` | `JB721Hook` | Called by terminal during cash out. Decodes token IDs from metadata, validates ownership, burns NFTs, delegates to virtual `_didBurn`. Reverts if `msg.value != 0`. |
28
- | `beforePayRecordedWith(context)` | `JB721TiersHook` | Data hook: returns original weight, calculates per-tier split amounts via `JB721TiersHookLib.calculateSplitAmounts`, and sets this contract as the pay hook with the total split amount forwarded. |
28
+ | `beforePayRecordedWith(context)` | `JB721TiersHook` | Data hook: calculates per-tier split amounts via `JB721TiersHookLib.calculateSplitAmounts`, adjusts the weight proportionally so the terminal only mints tokens for the amount that actually enters the project (i.e., `weight = mulDiv(context.weight, amount - totalSplitAmount, amount)`), and sets this contract as the pay hook with the total split amount forwarded. If no splits, returns original weight unchanged. If splits consume the entire payment, returns weight 0. If the `issueTokensForSplits` flag is set, returns the full `context.weight` regardless of splits. |
29
29
  | `beforeCashOutRecordedWith(context)` | `JB721Hook` | Data hook: calculates `cashOutCount` (via virtual `cashOutWeightOf`) and `totalSupply` (via virtual `totalCashOutWeight`). Rejects if fungible tokens are also being cashed out. |
30
30
  | `adjustTiers(tiersToAdd, tierIdsToRemove)` | `JB721TiersHook` | Owner-only. Adds/removes tiers via `JB721TiersHookLib.adjustTiersFor` (DELEGATECALL). Requires `ADJUST_721_TIERS` permission. Registers tier splits in `JBSplits` if configured. |
31
31
  | `mintFor(tierIds, beneficiary)` | `JB721TiersHook` | Owner-only manual mint. Requires `MINT_721` permission. Passes `amount: type(uint256).max` and `isOwnerMint: true` to force the mint. |
@@ -86,7 +86,7 @@ Tiered ERC-721 NFT hook for Juicebox V6 that mints NFTs when a project is paid a
86
86
  | `JBStored721Tier` | `uint104 price`, `uint32 remainingSupply`, `uint32 initialSupply`, `uint32 splitPercent`, `uint24 category`, `uint8 discountPercent`, `uint16 reserveFrequency`, `uint8 packedBools` (allowOwnerMint, transfersPausable, useVotingUnits, cannotBeRemoved, cannotIncreaseDiscountPercent) | Internal storage in `JB721TiersHookStore`. Voting units stored separately in `_tierVotingUnitsOf` when `useVotingUnits` is true. |
87
87
  | `JB721InitTiersConfig` | `JB721TierConfig[] tiers`, `uint32 currency`, `uint8 decimals`, `IJBPrices prices` | `initialize` -- defines tiers and pricing context |
88
88
  | `JBDeploy721TiersHookConfig` | `string name`, `string symbol`, `string baseUri`, `IJB721TokenUriResolver tokenUriResolver`, `string contractUri`, `JB721InitTiersConfig tiersConfig`, `address reserveBeneficiary`, `JB721TiersHookFlags flags` | `deployHookFor`, `launchProjectFor` |
89
- | `JB721TiersHookFlags` | `bool noNewTiersWithReserves`, `bool noNewTiersWithVotes`, `bool noNewTiersWithOwnerMinting`, `bool preventOverspending` | `initialize`, `recordFlags` |
89
+ | `JB721TiersHookFlags` | `bool noNewTiersWithReserves`, `bool noNewTiersWithVotes`, `bool noNewTiersWithOwnerMinting`, `bool preventOverspending`, `bool issueTokensForSplits` | `initialize`, `recordFlags` |
90
90
  | `JB721TiersRulesetMetadata` | `bool pauseTransfers`, `bool pauseMintPendingReserves` | Packed into `JBRulesetMetadata.metadata` per-ruleset (bit 0 = pauseTransfers, bit 1 = pauseMintPendingReserves) |
91
91
  | `JBPayDataHookRulesetConfig` | `uint48 mustStartAtOrAfter`, `uint32 duration`, `uint112 weight`, `uint32 weightCutPercent`, `IJBRulesetApprovalHook approvalHook`, `JBPayDataHookRulesetMetadata metadata`, `JBSplitGroup[] splitGroups`, `JBFundAccessLimitGroup[] fundAccessLimitGroups` | `JB721TiersHookProjectDeployer` -- wraps core ruleset config with `useDataHookForPay: true` hardcoded |
92
92
  | `JBPayDataHookRulesetMetadata` | Same as `JBRulesetMetadata` minus `allowSetCustomToken` (hardcoded false) and `useDataHookForPay` (hardcoded true) and `dataHook` (set to deployed hook). Includes `ownerMustSendPayouts`. | `launchProjectFor`, `launchRulesetsFor`, `queueRulesetsOf` |
@@ -138,7 +138,7 @@ Each tier has configurable voting power:
138
138
  - Each tier can route a percentage of its mint price to configured split recipients. The `splitPercent` field (out of `JBConstants.SPLITS_TOTAL_PERCENT` = 1,000,000,000) determines how much of the price is forwarded.
139
139
  - Split recipients are stored in `JBSplits` using group IDs computed as `uint256(uint160(hookAddress)) | (uint256(tierId) << 160)`.
140
140
  - Splits are registered via `JB721TiersHookLib._setSplitGroupsFor` when tiers with `splits` are added.
141
- - In `beforePayRecordedWith`, `calculateSplitAmounts` decodes tier IDs from payer metadata, computes `mulDiv(price, splitPercent, SPLITS_TOTAL_PERCENT)` per tier, and returns the total to be forwarded to the hook.
141
+ - In `beforePayRecordedWith`, `calculateSplitAmounts` decodes tier IDs from payer metadata, computes `mulDiv(price, splitPercent, SPLITS_TOTAL_PERCENT)` per tier, and returns the total to be forwarded to the hook. The weight is adjusted down proportionally unless the `issueTokensForSplits` flag is set, in which case the full `context.weight` is returned.
142
142
  - In `afterPayRecordedWith`, `distributeAll` distributes forwarded funds to each tier's split group recipients. Leftover after all splits goes back to the project's balance via `addToBalance`.
143
143
  - Split recipients can be projects (via `terminal.pay` or `terminal.addToBalance`) or plain addresses (direct ETH transfer or `SafeERC20.safeTransfer`). Splits with no `projectId` and no `beneficiary` are skipped -- their share stays in the leftover and is routed to the project's own balance via `addToBalanceOf`, preventing a misconfigured split from bricking the payout distribution.
144
144
 
@@ -169,6 +169,8 @@ Each tier has configurable voting power:
169
169
  - **Max initial supply per tier is 999,999,999** (`_ONE_BILLION - 1`). Exceeding this would cause token ID overflow into the next tier's ID space.
170
170
  - **`noNewTiersWithVotes` blocks all voting power**: It rejects tiers where voting units would be non-zero, whether from custom `votingUnits` or from a non-zero `price` (when `useVotingUnits` is false).
171
171
  - **`firstOwnerOf` is lazy**: The first owner is only stored when the token is first transferred away from its original holder. Before any transfer, `firstOwnerOf` returns the current owner.
172
+ - **Tiers must be sorted by category, NOT price.** `recordAddTiers` reverts with `JB721TiersHookStore_InvalidCategorySortOrder` if tiers aren't in ascending category order. The `JB721InitTiersConfig` struct comment previously said "sorted by price" but the code enforces category ordering. Within the same category, tiers can be in any order.
173
+ - **Always use `JB721TiersHookProjectDeployer.launchProjectFor` even without NFTs.** Pass an empty tiers array to enable future NFT additions without migration. If a project is launched via `JBController.launchProjectFor` instead, adding NFT tiers later requires wiring a new data hook into a new ruleset — using the 721 deployer from the start avoids this.
172
174
 
173
175
  ## Example Integration
174
176
 
@@ -223,7 +225,8 @@ tiers[0] = JB721TierConfig({
223
225
  noNewTiersWithReserves: false,
224
226
  noNewTiersWithVotes: false,
225
227
  noNewTiersWithOwnerMinting: false,
226
- preventOverspending: false
228
+ preventOverspending: false,
229
+ issueTokensForSplits: false
227
230
  })
228
231
  }),
229
232
  launchProjectConfig: launchConfig, // JBLaunchProjectConfig with rulesets, terminals, etc.
@@ -167,7 +167,7 @@ mapping(address hook => mapping(uint256 tierId => JBStored721Tier)) internal _st
167
167
 
168
168
 
169
169
  ### _tierIdAfter
170
- Returns the ID of the tier which comes after the provided tier ID (sorted by price).
170
+ Returns the ID of the tier which comes after the provided tier ID (sorted by category).
171
171
 
172
172
  *If empty, assume the next tier ID should come after.*
173
173
 
@@ -386,7 +386,7 @@ function tiersOf(
386
386
  |`hook`|`address`|The 721 contract to get the tiers of.|
387
387
  |`categories`|`uint256[]`|An array tier categories to get tiers from. Send an empty array to get all categories.|
388
388
  |`includeResolvedUri`|`bool`|If set to `true`, if the contract has a token URI resolver, its content will be resolved and included.|
389
- |`startingId`|`uint256`|The ID of the first tier to get (sorted by price). Send 0 to get all active tiers.|
389
+ |`startingId`|`uint256`|The ID of the first tier to get (sorted by category). Send 0 to get all active tiers.|
390
390
  |`size`|`uint256`|The number of tiers to include.|
391
391
 
392
392
  **Returns**
@@ -561,7 +561,7 @@ function totalCashOutWeight(address hook) public view override returns (uint256
561
561
 
562
562
  ### _firstSortedTierIdOf
563
563
 
564
- Get the first tier ID from an 721 contract (when sorted by price) within a provided category.
564
+ Get the first tier ID from an 721 contract (when sorted by category) within a provided category.
565
565
 
566
566
 
567
567
  ```solidity
@@ -669,7 +669,7 @@ function _isTierRemovedWithRefresh(
669
669
 
670
670
  ### _lastSortedTierIdOf
671
671
 
672
- The last sorted tier ID from an 721 contract (when sorted by price).
672
+ The last sorted tier ID from an 721 contract (when sorted by category).
673
673
 
674
674
 
675
675
  ```solidity
@@ -690,7 +690,7 @@ function _lastSortedTierIdOf(address hook) internal view returns (uint256 id);
690
690
 
691
691
  ### _nextSortedTierIdOf
692
692
 
693
- Get the tier ID which comes after the provided one when sorted by price.
693
+ Get the tier ID which comes after the provided one when sorted by category.
694
694
 
695
695
 
696
696
  ```solidity
@@ -3,7 +3,7 @@
3
3
 
4
4
  Config to initialize a `JB721TiersHook` with tiers and price data.
5
5
 
6
- *The `tiers` must be sorted by price (from least to greatest).*
6
+ *The `tiers` must be sorted by category (from least to greatest).*
7
7
 
8
8
  **Notes:**
9
9
  - member: tiers The tiers to initialize the hook with.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananapus/721-hook-v6",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,6 +22,7 @@ import {IJB721TiersHook} from "./interfaces/IJB721TiersHook.sol";
22
22
  import {IJB721TiersHookStore} from "./interfaces/IJB721TiersHookStore.sol";
23
23
  import {IJB721TokenUriResolver} from "./interfaces/IJB721TokenUriResolver.sol";
24
24
  import {JB721TiersHookLib} from "./libraries/JB721TiersHookLib.sol";
25
+ import {mulDiv} from "@prb/math/src/Common.sol";
25
26
  import {JB721TiersRulesetMetadataResolver} from "./libraries/JB721TiersRulesetMetadataResolver.sol";
26
27
  import {JB721InitTiersConfig} from "./structs/JB721InitTiersConfig.sol";
27
28
  import {JB721Tier} from "./structs/JB721Tier.sol";
@@ -162,7 +163,8 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
162
163
  /// @notice The data calculated before a payment is recorded in the terminal store.
163
164
  /// @dev Overrides the base to calculate the split amount to forward based on tier split percentages.
164
165
  /// @param context The payment context.
165
- /// @return weight The weight to use for token minting (unchanged from ruleset weight).
166
+ /// @return weight The weight to use for token minting, adjusted down when tier splits route funds away from the
167
+ /// project (unless `issueTokensForSplits` is set).
166
168
  /// @return hookSpecifications The hook specifications, with the split amount to forward.
167
169
  function beforePayRecordedWith(JBBeforePayRecordedContext calldata context)
168
170
  public
@@ -171,13 +173,24 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
171
173
  override(JB721Hook, IJBRulesetDataHook)
172
174
  returns (uint256 weight, JBPayHookSpecification[] memory hookSpecifications)
173
175
  {
174
- weight = context.weight;
175
176
  hookSpecifications = new JBPayHookSpecification[](1);
176
177
 
177
178
  // Calculate per-tier split amounts via the library.
178
179
  (uint256 totalSplitAmount, bytes memory splitMetadata) =
179
180
  JB721TiersHookLib.calculateSplitAmounts(STORE, address(this), METADATA_ID_TARGET, context.metadata);
180
181
 
182
+ // Adjust weight so the terminal mints tokens only for the amount that actually enters the project.
183
+ if (totalSplitAmount == 0 || STORE.flagsOf(address(this)).issueTokensForSplits) {
184
+ // No splits, or hook configured to give full token credit regardless — full weight.
185
+ weight = context.weight;
186
+ } else if (context.amount.value > totalSplitAmount) {
187
+ // Partial splits — scale weight by the fraction that enters the project.
188
+ weight = mulDiv(context.weight, context.amount.value - totalSplitAmount, context.amount.value);
189
+ } else {
190
+ // Splits consume the entire payment — no tokens should be minted.
191
+ weight = 0;
192
+ }
193
+
181
194
  hookSpecifications[0] = JBPayHookSpecification({hook: this, amount: totalSplitAmount, metadata: splitMetadata});
182
195
  }
183
196
 
@@ -255,7 +268,7 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
255
268
  // Set the flags if needed.
256
269
  if (
257
270
  flags.noNewTiersWithReserves || flags.noNewTiersWithVotes || flags.noNewTiersWithOwnerMinting
258
- || flags.preventOverspending
271
+ || flags.preventOverspending || flags.issueTokensForSplits
259
272
  ) STORE.recordFlags(flags);
260
273
 
261
274
  // Transfer ownership to the initializer.
@@ -132,7 +132,7 @@ contract JB721TiersHookStore is IJB721TiersHookStore {
132
132
  /// @custom:returns The stored tier, as a `JBStored721Tier` struct.
133
133
  mapping(address hook => mapping(uint256 tierId => JBStored721Tier)) internal _storedTierOf;
134
134
 
135
- /// @notice Returns the ID of the tier which comes after the provided tier ID (sorted by price).
135
+ /// @notice Returns the ID of the tier which comes after the provided tier ID (sorted by category).
136
136
  /// @dev If empty, assume the next tier ID should come after.
137
137
  /// @custom:param hook The address of the 721 contract to get the next tier ID from.
138
138
  /// @custom:param tierId The ID of the tier to get the next tier ID in relation to.
@@ -247,7 +247,7 @@ contract JB721TiersHookStore is IJB721TiersHookStore {
247
247
  /// @param categories An array tier categories to get tiers from. Send an empty array to get all categories.
248
248
  /// @param includeResolvedUri If set to `true`, if the contract has a token URI resolver, its content will be
249
249
  /// resolved and included.
250
- /// @param startingId The ID of the first tier to get (sorted by price). Send 0 to get all active tiers.
250
+ /// @param startingId The ID of the first tier to get (sorted by category). Send 0 to get all active tiers.
251
251
  /// @param size The number of tiers to include.
252
252
  /// @return tiers An array of active 721 tiers.
253
253
  function tiersOf(
@@ -482,7 +482,7 @@ contract JB721TiersHookStore is IJB721TiersHookStore {
482
482
  // -------------------------- internal views ------------------------- //
483
483
  //*********************************************************************//
484
484
 
485
- /// @notice Get the first tier ID from an 721 contract (when sorted by price) within a provided category.
485
+ /// @notice Get the first tier ID from an 721 contract (when sorted by category) within a provided category.
486
486
  /// @param hook The 721 contract to get the first sorted tier ID of.
487
487
  /// @param category The category to get the first sorted tier ID within. Send 0 for the first ID across all tiers,
488
488
  /// which might not be in the 0th category if the 0th category does not exist.
@@ -578,7 +578,7 @@ contract JB721TiersHookStore is IJB721TiersHookStore {
578
578
  return bitmapWord.isTierIdRemoved(tierId);
579
579
  }
580
580
 
581
- /// @notice The last sorted tier ID from an 721 contract (when sorted by price).
581
+ /// @notice The last sorted tier ID from an 721 contract (when sorted by category).
582
582
  /// @param hook The 721 contract to get the last sorted tier ID of.
583
583
  /// @return id The last sorted tier ID.
584
584
  function _lastSortedTierIdOf(address hook) internal view returns (uint256 id) {
@@ -587,7 +587,7 @@ contract JB721TiersHookStore is IJB721TiersHookStore {
587
587
  if (id == 0) id = maxTierIdOf[hook];
588
588
  }
589
589
 
590
- /// @notice Get the tier ID which comes after the provided one when sorted by price.
590
+ /// @notice Get the tier ID which comes after the provided one when sorted by category.
591
591
  /// @param hook The 721 contract to get the next sorted tier ID from.
592
592
  /// @param id The tier ID to get the next sorted tier ID relative to.
593
593
  /// @param max The maximum tier ID.
@@ -782,7 +782,7 @@ contract JB721TiersHookStore is IJB721TiersHookStore {
782
782
  revert JB721TiersHookStore_MaxTiersExceeded(currentMaxTierIdOf + tiersToAdd.length, type(uint16).max);
783
783
  }
784
784
 
785
- // Keep a reference to the current last sorted tier ID (sorted by price).
785
+ // Keep a reference to the current last sorted tier ID (sorted by category).
786
786
  uint256 currentLastSortedTierId = _lastSortedTierIdOf(msg.sender);
787
787
 
788
788
  // Initialize an array for the new tier IDs to be returned.
@@ -6,7 +6,7 @@ import {IJBPrices} from "@bananapus/core-v6/src/interfaces/IJBPrices.sol";
6
6
  import {JB721TierConfig} from "./JB721TierConfig.sol";
7
7
 
8
8
  /// @notice Config to initialize a `JB721TiersHook` with tiers and price data.
9
- /// @dev The `tiers` must be sorted by price (from least to greatest).
9
+ /// @dev The `tiers` must be sorted by category (from least to greatest).
10
10
  /// @custom:member tiers The tiers to initialize the hook with.
11
11
  /// @custom:member currency The currency that the tier prices are denoted in. See `JBPrices`.
12
12
  /// @custom:member decimals The number of decimals in the fixed point tier prices.
@@ -9,9 +9,12 @@ pragma solidity ^0.8.0;
9
9
  /// `allowOwnerMint` set to true will revert.
10
10
  /// @custom:member preventOverspending A boolean indicating whether payments attempting to spend more than the price of
11
11
  /// the NFTs being minted will revert.
12
+ /// @custom:member issueTokensForSplits A boolean indicating whether payers receive token credit for the portion of
13
+ /// their payment that is routed to tier splits. When false (default), weight is reduced proportionally.
12
14
  struct JB721TiersHookFlags {
13
15
  bool noNewTiersWithReserves;
14
16
  bool noNewTiersWithVotes;
15
17
  bool noNewTiersWithOwnerMinting;
16
18
  bool preventOverspending;
19
+ bool issueTokensForSplits;
17
20
  }
@@ -798,6 +798,7 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
798
798
  reserveBeneficiary: reserveBeneficiary,
799
799
  flags: JB721TiersHookFlags({
800
800
  preventOverspending: false,
801
+ issueTokensForSplits: false,
801
802
  noNewTiersWithReserves: false,
802
803
  noNewTiersWithVotes: false,
803
804
  noNewTiersWithOwnerMinting: true
@@ -891,6 +892,7 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
891
892
  reserveBeneficiary: reserveBeneficiary,
892
893
  flags: JB721TiersHookFlags({
893
894
  preventOverspending: false,
895
+ issueTokensForSplits: false,
894
896
  noNewTiersWithReserves: false,
895
897
  noNewTiersWithVotes: false,
896
898
  noNewTiersWithOwnerMinting: true
@@ -4,7 +4,7 @@ pragma solidity 0.8.26;
4
4
  import "../utils/UnitTestSetup.sol";
5
5
  import {IJB721TiersHookStore} from "../../src/interfaces/IJB721TiersHookStore.sol";
6
6
 
7
- /// @notice Regression test for L-34: defaultReserveBeneficiaryOf is globally overwritten when adding a tier with
7
+ /// @notice defaultReserveBeneficiaryOf is globally overwritten when adding a tier with
8
8
  /// useReserveBeneficiaryAsDefault=true.
9
9
  contract Test_L34_ReserveBeneficiaryOverwrite is UnitTestSetup {
10
10
  using stdStorage for StdStorage;
@@ -5,13 +5,13 @@ import "../utils/UnitTestSetup.sol";
5
5
  import {IJB721TiersHookStore} from "../../src/interfaces/IJB721TiersHookStore.sol";
6
6
  import {JB721TiersHookLib} from "../../src/libraries/JB721TiersHookLib.sol";
7
7
 
8
- /// @notice Regression test for L-35: calculateSplitAmounts cached the tierOf result to avoid a duplicate external call.
8
+ /// @notice calculateSplitAmounts caches the tierOf result to avoid a duplicate external call.
9
9
  /// Verifies that the cached tier lookup returns the same split amounts as reading price and splitPercent individually.
10
10
  contract Test_L35_CacheTierLookup is UnitTestSetup {
11
11
  using stdStorage for StdStorage;
12
12
 
13
13
  /// @notice Verify that calculateSplitAmounts returns correct per-tier amounts when multiple tiers have different
14
- /// prices and split percentages. This exercises the cached `tier` variable introduced by L-35.
14
+ /// prices and split percentages. This exercises the cached `tier` variable.
15
15
  function test_calculateSplitAmounts_multiTier_correctAmounts() public {
16
16
  ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
17
17
  IJB721TiersHookStore hookStore = testHook.STORE();
@@ -10,7 +10,7 @@ import {IJBSplits} from "@bananapus/core-v6/src/interfaces/IJBSplits.sol";
10
10
  import {IJBController} from "@bananapus/core-v6/src/interfaces/IJBController.sol";
11
11
  import {IJBTerminal} from "@bananapus/core-v6/src/interfaces/IJBTerminal.sol";
12
12
 
13
- /// @notice Regression test for L-36: Split with no beneficiary and no projectId should route funds to the project's
13
+ /// @notice Split with no beneficiary and no projectId should route funds to the project's
14
14
  /// balance instead of silently dropping them.
15
15
  contract Test_L36_SplitNoBeneficiary is UnitTestSetup {
16
16
  using stdStorage for StdStorage;
@@ -585,6 +585,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
585
585
  IJB721TiersHookStore(address(store)),
586
586
  JB721TiersHookFlags({
587
587
  preventOverspending: false,
588
+ issueTokensForSplits: false,
588
589
  noNewTiersWithReserves: false,
589
590
  noNewTiersWithVotes: false,
590
591
  noNewTiersWithOwnerMinting: true
@@ -715,6 +716,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
715
716
  }),
716
717
  JB721TiersHookFlags({
717
718
  preventOverspending: false,
719
+ issueTokensForSplits: false,
718
720
  noNewTiersWithReserves: false,
719
721
  noNewTiersWithVotes: false,
720
722
  noNewTiersWithOwnerMinting: true
@@ -904,6 +906,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
904
906
  IJB721TiersHookStore(address(store)),
905
907
  JB721TiersHookFlags({
906
908
  preventOverspending: false,
909
+ issueTokensForSplits: false,
907
910
  noNewTiersWithReserves: false,
908
911
  noNewTiersWithVotes: true,
909
912
  noNewTiersWithOwnerMinting: true
@@ -1023,6 +1026,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
1023
1026
  IJB721TiersHookStore(address(store)),
1024
1027
  JB721TiersHookFlags({
1025
1028
  preventOverspending: false,
1029
+ issueTokensForSplits: false,
1026
1030
  noNewTiersWithReserves: true, // <-- This is the flag we're testing.
1027
1031
  noNewTiersWithVotes: false,
1028
1032
  noNewTiersWithOwnerMinting: true
@@ -1141,6 +1145,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
1141
1145
  }),
1142
1146
  JB721TiersHookFlags({
1143
1147
  preventOverspending: false,
1148
+ issueTokensForSplits: false,
1144
1149
  noNewTiersWithReserves: false,
1145
1150
  noNewTiersWithVotes: false,
1146
1151
  noNewTiersWithOwnerMinting: true
@@ -1213,6 +1218,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
1213
1218
  IJB721TiersHookStore(address(store)),
1214
1219
  JB721TiersHookFlags({
1215
1220
  preventOverspending: false,
1221
+ issueTokensForSplits: false,
1216
1222
  noNewTiersWithReserves: false,
1217
1223
  noNewTiersWithVotes: false,
1218
1224
  noNewTiersWithOwnerMinting: true
@@ -1359,6 +1365,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
1359
1365
  IJB721TiersHookStore(address(store)),
1360
1366
  JB721TiersHookFlags({
1361
1367
  preventOverspending: false,
1368
+ issueTokensForSplits: false,
1362
1369
  noNewTiersWithReserves: false,
1363
1370
  noNewTiersWithVotes: true, // <-- This is the flag we're testing.
1364
1371
  noNewTiersWithOwnerMinting: true
@@ -1444,6 +1451,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
1444
1451
  IJB721TiersHookStore(address(store)),
1445
1452
  JB721TiersHookFlags({
1446
1453
  preventOverspending: false,
1454
+ issueTokensForSplits: false,
1447
1455
  noNewTiersWithReserves: false,
1448
1456
  noNewTiersWithVotes: true, // <-- This is the flag we're testing.
1449
1457
  noNewTiersWithOwnerMinting: true
@@ -1578,6 +1586,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
1578
1586
  IJB721TiersHookStore(address(store)),
1579
1587
  JB721TiersHookFlags({
1580
1588
  preventOverspending: false,
1589
+ issueTokensForSplits: false,
1581
1590
  noNewTiersWithReserves: false,
1582
1591
  noNewTiersWithVotes: false,
1583
1592
  noNewTiersWithOwnerMinting: true
@@ -1686,6 +1695,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
1686
1695
  }),
1687
1696
  JB721TiersHookFlags({
1688
1697
  preventOverspending: false,
1698
+ issueTokensForSplits: false,
1689
1699
  noNewTiersWithReserves: false,
1690
1700
  noNewTiersWithVotes: false,
1691
1701
  noNewTiersWithOwnerMinting: true
@@ -1762,6 +1772,7 @@ contract Test_adjustTier_Unit is UnitTestSetup {
1762
1772
  }),
1763
1773
  JB721TiersHookFlags({
1764
1774
  preventOverspending: false,
1775
+ issueTokensForSplits: false,
1765
1776
  noNewTiersWithReserves: false,
1766
1777
  noNewTiersWithVotes: false,
1767
1778
  noNewTiersWithOwnerMinting: true
@@ -38,6 +38,7 @@ contract Test_Getters_Constructor_Unit is UnitTestSetup {
38
38
  address(0),
39
39
  JB721TiersHookFlags({
40
40
  preventOverspending: false,
41
+ issueTokensForSplits: false,
41
42
  noNewTiersWithReserves: true,
42
43
  noNewTiersWithVotes: true,
43
44
  noNewTiersWithOwnerMinting: true
@@ -544,6 +545,7 @@ contract Test_Getters_Constructor_Unit is UnitTestSetup {
544
545
  }),
545
546
  JB721TiersHookFlags({
546
547
  preventOverspending: false,
548
+ issueTokensForSplits: false,
547
549
  noNewTiersWithReserves: true,
548
550
  noNewTiersWithVotes: true,
549
551
  noNewTiersWithOwnerMinting: true
@@ -7,6 +7,7 @@ import {JBSplit} from "@bananapus/core-v6/src/structs/JBSplit.sol";
7
7
  import {IJBSplitHook} from "@bananapus/core-v6/src/interfaces/IJBSplitHook.sol";
8
8
  import {IJBSplits} from "@bananapus/core-v6/src/interfaces/IJBSplits.sol";
9
9
  import {IJBController} from "@bananapus/core-v6/src/interfaces/IJBController.sol";
10
+ import {JB721TiersHookFlags} from "../../src/structs/JB721TiersHookFlags.sol";
10
11
 
11
12
  contract Test_TierSplitRouting is UnitTestSetup {
12
13
  using stdStorage for StdStorage;
@@ -91,8 +92,8 @@ contract Test_TierSplitRouting is UnitTestSetup {
91
92
 
92
93
  (uint256 weight, JBPayHookSpecification[] memory specs) = testHook.beforePayRecordedWith(context);
93
94
 
94
- // Weight unchanged.
95
- assertEq(weight, 10e18);
95
+ // Weight adjusted for 50% split: 10e18 * 0.5 = 5e18.
96
+ assertEq(weight, 5e18);
96
97
  // Hook spec should forward 50% of 1 ETH = 0.5 ETH.
97
98
  assertEq(specs.length, 1);
98
99
  assertEq(specs[0].amount, 0.5 ether);
@@ -184,6 +185,121 @@ contract Test_TierSplitRouting is UnitTestSetup {
184
185
  assertEq(specs[0].amount, 2.3 ether);
185
186
  }
186
187
 
188
+ // ──────────────────────────────────────────────
189
+ // Test: weight adjusted for splits
190
+ // ──────────────────────────────────────────────
191
+
192
+ function test_beforePayRecorded_weightAdjustedForSplits() public {
193
+ ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
194
+ IJB721TiersHookStore hookStore = testHook.STORE();
195
+
196
+ // Add a tier with 30% split.
197
+ JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
198
+ tierConfigs[0] = _tierConfigWithSplit(1 ether, 300_000_000); // 30%
199
+ vm.prank(address(testHook));
200
+ uint256[] memory tierIds = hookStore.recordAddTiers(tierConfigs);
201
+
202
+ uint16[] memory mintIds = new uint16[](1);
203
+ mintIds[0] = uint16(tierIds[0]);
204
+ bytes memory payerMetadata = _buildPayerMetadata(address(testHook), mintIds);
205
+
206
+ JBBeforePayRecordedContext memory context = JBBeforePayRecordedContext({
207
+ terminal: mockTerminalAddress,
208
+ payer: beneficiary,
209
+ amount: JBTokenAmount({
210
+ token: JBConstants.NATIVE_TOKEN,
211
+ value: 1 ether,
212
+ decimals: 18,
213
+ currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
214
+ }),
215
+ projectId: projectId,
216
+ rulesetId: 0,
217
+ beneficiary: beneficiary,
218
+ weight: 10e18,
219
+ reservedPercent: 5000,
220
+ metadata: payerMetadata
221
+ });
222
+
223
+ (uint256 weight,) = testHook.beforePayRecordedWith(context);
224
+
225
+ // Weight adjusted for 30% split: 10e18 * 0.7 = 7e18.
226
+ assertEq(weight, 7e18);
227
+ }
228
+
229
+ function test_beforePayRecorded_noSplitPercent_weightUnchanged() public {
230
+ ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
231
+ IJB721TiersHookStore hookStore = testHook.STORE();
232
+
233
+ // Add a tier with 0% split.
234
+ JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
235
+ tierConfigs[0] = _tierConfigWithSplit(1 ether, 0);
236
+ vm.prank(address(testHook));
237
+ uint256[] memory tierIds = hookStore.recordAddTiers(tierConfigs);
238
+
239
+ uint16[] memory mintIds = new uint16[](1);
240
+ mintIds[0] = uint16(tierIds[0]);
241
+ bytes memory payerMetadata = _buildPayerMetadata(address(testHook), mintIds);
242
+
243
+ JBBeforePayRecordedContext memory context = JBBeforePayRecordedContext({
244
+ terminal: mockTerminalAddress,
245
+ payer: beneficiary,
246
+ amount: JBTokenAmount({
247
+ token: JBConstants.NATIVE_TOKEN,
248
+ value: 1 ether,
249
+ decimals: 18,
250
+ currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
251
+ }),
252
+ projectId: projectId,
253
+ rulesetId: 0,
254
+ beneficiary: beneficiary,
255
+ weight: 10e18,
256
+ reservedPercent: 5000,
257
+ metadata: payerMetadata
258
+ });
259
+
260
+ (uint256 weight,) = testHook.beforePayRecordedWith(context);
261
+
262
+ // No split = weight unchanged.
263
+ assertEq(weight, 10e18);
264
+ }
265
+
266
+ function test_beforePayRecorded_fullSplitPercent_weightZero() public {
267
+ ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
268
+ IJB721TiersHookStore hookStore = testHook.STORE();
269
+
270
+ // Add a tier with 100% split, priced at full payment amount.
271
+ JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
272
+ tierConfigs[0] = _tierConfigWithSplit(1 ether, 1_000_000_000); // 100%
273
+ vm.prank(address(testHook));
274
+ uint256[] memory tierIds = hookStore.recordAddTiers(tierConfigs);
275
+
276
+ uint16[] memory mintIds = new uint16[](1);
277
+ mintIds[0] = uint16(tierIds[0]);
278
+ bytes memory payerMetadata = _buildPayerMetadata(address(testHook), mintIds);
279
+
280
+ JBBeforePayRecordedContext memory context = JBBeforePayRecordedContext({
281
+ terminal: mockTerminalAddress,
282
+ payer: beneficiary,
283
+ amount: JBTokenAmount({
284
+ token: JBConstants.NATIVE_TOKEN,
285
+ value: 1 ether,
286
+ decimals: 18,
287
+ currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
288
+ }),
289
+ projectId: projectId,
290
+ rulesetId: 0,
291
+ beneficiary: beneficiary,
292
+ weight: 10e18,
293
+ reservedPercent: 5000,
294
+ metadata: payerMetadata
295
+ });
296
+
297
+ (uint256 weight,) = testHook.beforePayRecordedWith(context);
298
+
299
+ // 100% split of full amount = weight 0.
300
+ assertEq(weight, 0);
301
+ }
302
+
187
303
  // ──────────────────────────────────────────────
188
304
  // Test: afterPayRecordedWith distributes to split beneficiary
189
305
  // ──────────────────────────────────────────────
@@ -272,4 +388,110 @@ contract Test_TierSplitRouting is UnitTestSetup {
272
388
  // NFT should have been minted.
273
389
  assertEq(testHook.balanceOf(beneficiary), 1);
274
390
  }
391
+
392
+ // ──────────────────────────────────────────────
393
+ // Test: issueTokensForSplits flag gives full weight with partial splits
394
+ // ──────────────────────────────────────────────
395
+
396
+ function test_beforePayRecorded_issueTokensForSplits_fullWeight() public {
397
+ ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
398
+ IJB721TiersHookStore hookStore = testHook.STORE();
399
+
400
+ // Set the issueTokensForSplits flag.
401
+ vm.prank(address(testHook));
402
+ hookStore.recordFlags(
403
+ JB721TiersHookFlags({
404
+ noNewTiersWithReserves: false,
405
+ noNewTiersWithVotes: false,
406
+ noNewTiersWithOwnerMinting: false,
407
+ preventOverspending: false,
408
+ issueTokensForSplits: true
409
+ })
410
+ );
411
+
412
+ // Add a tier with 50% split.
413
+ JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
414
+ tierConfigs[0] = _tierConfigWithSplit(1 ether, 500_000_000); // 50%
415
+ vm.prank(address(testHook));
416
+ uint256[] memory tierIds = hookStore.recordAddTiers(tierConfigs);
417
+
418
+ uint16[] memory mintIds = new uint16[](1);
419
+ mintIds[0] = uint16(tierIds[0]);
420
+ bytes memory payerMetadata = _buildPayerMetadata(address(testHook), mintIds);
421
+
422
+ JBBeforePayRecordedContext memory context = JBBeforePayRecordedContext({
423
+ terminal: mockTerminalAddress,
424
+ payer: beneficiary,
425
+ amount: JBTokenAmount({
426
+ token: JBConstants.NATIVE_TOKEN,
427
+ value: 1 ether,
428
+ decimals: 18,
429
+ currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
430
+ }),
431
+ projectId: projectId,
432
+ rulesetId: 0,
433
+ beneficiary: beneficiary,
434
+ weight: 10e18,
435
+ reservedPercent: 5000,
436
+ metadata: payerMetadata
437
+ });
438
+
439
+ (uint256 weight,) = testHook.beforePayRecordedWith(context);
440
+
441
+ // Flag set — weight should be full despite 50% split.
442
+ assertEq(weight, 10e18);
443
+ }
444
+
445
+ // ──────────────────────────────────────────────
446
+ // Test: issueTokensForSplits flag gives full weight even when splits consume entire payment
447
+ // ──────────────────────────────────────────────
448
+
449
+ function test_beforePayRecorded_issueTokensForSplits_fullSplit_stillFullWeight() public {
450
+ ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
451
+ IJB721TiersHookStore hookStore = testHook.STORE();
452
+
453
+ // Set the issueTokensForSplits flag.
454
+ vm.prank(address(testHook));
455
+ hookStore.recordFlags(
456
+ JB721TiersHookFlags({
457
+ noNewTiersWithReserves: false,
458
+ noNewTiersWithVotes: false,
459
+ noNewTiersWithOwnerMinting: false,
460
+ preventOverspending: false,
461
+ issueTokensForSplits: true
462
+ })
463
+ );
464
+
465
+ // Add a tier with 100% split, priced at full payment amount.
466
+ JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
467
+ tierConfigs[0] = _tierConfigWithSplit(1 ether, 1_000_000_000); // 100%
468
+ vm.prank(address(testHook));
469
+ uint256[] memory tierIds = hookStore.recordAddTiers(tierConfigs);
470
+
471
+ uint16[] memory mintIds = new uint16[](1);
472
+ mintIds[0] = uint16(tierIds[0]);
473
+ bytes memory payerMetadata = _buildPayerMetadata(address(testHook), mintIds);
474
+
475
+ JBBeforePayRecordedContext memory context = JBBeforePayRecordedContext({
476
+ terminal: mockTerminalAddress,
477
+ payer: beneficiary,
478
+ amount: JBTokenAmount({
479
+ token: JBConstants.NATIVE_TOKEN,
480
+ value: 1 ether,
481
+ decimals: 18,
482
+ currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
483
+ }),
484
+ projectId: projectId,
485
+ rulesetId: 0,
486
+ beneficiary: beneficiary,
487
+ weight: 10e18,
488
+ reservedPercent: 5000,
489
+ metadata: payerMetadata
490
+ });
491
+
492
+ (uint256 weight,) = testHook.beforePayRecordedWith(context);
493
+
494
+ // Flag set — weight should be full despite 100% split consuming entire payment.
495
+ assertEq(weight, 10e18);
496
+ }
275
497
  }