@bananapus/721-hook-v6 0.0.8 → 0.0.10
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/SKILLS.md +2 -1
- package/foundry.toml +1 -1
- package/package.json +5 -5
- package/src/JB721TiersHook.sol +9 -9
- package/src/JB721TiersHookDeployer.sol +2 -2
- package/src/JB721TiersHookProjectDeployer.sol +24 -20
- package/src/JB721TiersHookStore.sol +20 -12
- package/src/abstract/JB721Hook.sol +44 -44
- package/src/interfaces/IJB721Hook.sol +1 -0
- package/src/interfaces/IJB721TiersHook.sol +73 -17
- package/src/interfaces/IJB721TiersHookDeployer.sol +5 -0
- package/src/interfaces/IJB721TiersHookProjectDeployer.sol +2 -1
- package/src/interfaces/IJB721TiersHookStore.sol +11 -0
- package/src/interfaces/IJB721TokenUriResolver.sol +1 -0
- package/src/libraries/JB721TiersHookLib.sol +21 -9
- package/src/structs/JB721TierConfig.sol +3 -1
- package/test/regression/L34_ReserveBeneficiaryOverwrite.t.sol +154 -0
- package/test/regression/L35_CacheTierLookup.t.sol +188 -0
- package/test/regression/L36_SplitNoBeneficiary.t.sol +146 -0
- package/test/unit/M6_TierSupplyCheck.t.sol +1 -1
package/SKILLS.md
CHANGED
|
@@ -140,7 +140,7 @@ Each tier has configurable voting power:
|
|
|
140
140
|
- Splits are registered via `JB721TiersHookLib._setSplitGroupsFor` when tiers with `splits` are added.
|
|
141
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.
|
|
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
|
-
- Split recipients can be projects (via `terminal.pay` or `terminal.addToBalance`) or plain addresses (direct ETH transfer or `SafeERC20.safeTransfer`).
|
|
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
|
|
|
145
145
|
## Gotchas
|
|
146
146
|
|
|
@@ -160,6 +160,7 @@ Each tier has configurable voting power:
|
|
|
160
160
|
- The `_update` override in `JB721TiersHook` checks `tier.transfersPausable` and consults the current ruleset's metadata for `transfersPaused`. Transfers to `address(0)` (burns) are never blocked.
|
|
161
161
|
- **IERC2981 declared but not implemented**: `supportsInterface` returns `true` for `IERC2981`, but no `royaltyInfo` function is implemented. Callers querying `royaltyInfo` will get a revert. This appears intentional -- the interface is declared for future extension or to signal capability to marketplaces that may override behavior.
|
|
162
162
|
- **Tier splits**: Each tier can route a percentage of its mint price to configured split recipients. `splitPercent` is out of `JBConstants.SPLITS_TOTAL_PERCENT` (1,000,000,000). Split group IDs are `uint256(uint160(hookAddress)) | (uint256(tierId) << 160)`.
|
|
163
|
+
- **`useReserveBeneficiaryAsDefault` overwrites globally**: Adding a tier with `useReserveBeneficiaryAsDefault: true` silently overwrites `defaultReserveBeneficiaryOf` for ALL existing tiers that lack a tier-specific beneficiary. A `SetDefaultReserveBeneficiary` event is emitted when the default changes.
|
|
163
164
|
- **Removing tiers does not update the sorted list**: `recordRemoveTierIds` only marks tiers in the bitmap. Call `cleanTiers()` afterward to remove them from the iteration sequence.
|
|
164
165
|
- `JB721TiersHookStore` is a **shared singleton** -- all hook instances on the same chain use the same store, keyed by `address(hook)`.
|
|
165
166
|
- The `ERC721` abstract uses `_initialize(name, symbol)` instead of a constructor, making it clone-compatible. The standard `_owners` mapping is `internal` (not `private`).
|
package/foundry.toml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bananapus/721-hook-v6",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"artifacts": "source ./.env && npx sphinx artifacts --org-id 'ea165b21-7cdc-4d7b-be59-ecdd4c26bee4' --project-name 'nana-721-hook-v6'"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@bananapus/address-registry-v6": "^0.0.
|
|
21
|
-
"@bananapus/core-v6": "^0.0.
|
|
22
|
-
"@bananapus/ownable-v6": "^0.0.
|
|
23
|
-
"@bananapus/permission-ids-v6": "^0.0.
|
|
20
|
+
"@bananapus/address-registry-v6": "^0.0.4",
|
|
21
|
+
"@bananapus/core-v6": "^0.0.10",
|
|
22
|
+
"@bananapus/ownable-v6": "^0.0.6",
|
|
23
|
+
"@bananapus/permission-ids-v6": "^0.0.5",
|
|
24
24
|
"@openzeppelin/contracts": "5.2.0",
|
|
25
25
|
"@prb/math": "^4.1.0",
|
|
26
26
|
"solady": "^0.1.8"
|
package/src/JB721TiersHook.sol
CHANGED
|
@@ -23,12 +23,12 @@ import {IJB721TiersHookStore} from "./interfaces/IJB721TiersHookStore.sol";
|
|
|
23
23
|
import {IJB721TokenUriResolver} from "./interfaces/IJB721TokenUriResolver.sol";
|
|
24
24
|
import {JB721TiersHookLib} from "./libraries/JB721TiersHookLib.sol";
|
|
25
25
|
import {JB721TiersRulesetMetadataResolver} from "./libraries/JB721TiersRulesetMetadataResolver.sol";
|
|
26
|
+
import {JB721InitTiersConfig} from "./structs/JB721InitTiersConfig.sol";
|
|
26
27
|
import {JB721Tier} from "./structs/JB721Tier.sol";
|
|
27
28
|
import {JB721TierConfig} from "./structs/JB721TierConfig.sol";
|
|
28
|
-
import {JB721TiersSetDiscountPercentConfig} from "./structs/JB721TiersSetDiscountPercentConfig.sol";
|
|
29
|
-
import {JB721InitTiersConfig} from "./structs/JB721InitTiersConfig.sol";
|
|
30
29
|
import {JB721TiersHookFlags} from "./structs/JB721TiersHookFlags.sol";
|
|
31
30
|
import {JB721TiersMintReservesConfig} from "./structs/JB721TiersMintReservesConfig.sol";
|
|
31
|
+
import {JB721TiersSetDiscountPercentConfig} from "./structs/JB721TiersSetDiscountPercentConfig.sol";
|
|
32
32
|
|
|
33
33
|
/// @title JB721TiersHook
|
|
34
34
|
/// @notice A Juicebox project can use this hook to sell tiered ERC-721 NFTs with different prices and metadata. When
|
|
@@ -190,13 +190,6 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
|
|
|
190
190
|
return STORE.cashOutWeightOf({hook: address(this), tokenIds: tokenIds});
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
/// @notice Indicates if this contract adheres to the specified interface.
|
|
194
|
-
/// @dev See {IERC165-supportsInterface}.
|
|
195
|
-
/// @param interfaceId The ID of the interface to check for adherence to.
|
|
196
|
-
function supportsInterface(bytes4 interfaceId) public view override(IERC165, JB721Hook) returns (bool) {
|
|
197
|
-
return interfaceId == type(IJB721TiersHook).interfaceId || JB721Hook.supportsInterface(interfaceId);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
193
|
/// @notice Initializes a cloned copy of the original hook contract.
|
|
201
194
|
/// @param projectId The ID of the project this this hook is associated with.
|
|
202
195
|
/// @param name The name of the NFT collection.
|
|
@@ -269,6 +262,13 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
|
|
|
269
262
|
_transferOwnership(_msgSender());
|
|
270
263
|
}
|
|
271
264
|
|
|
265
|
+
/// @notice Indicates if this contract adheres to the specified interface.
|
|
266
|
+
/// @dev See {IERC165-supportsInterface}.
|
|
267
|
+
/// @param interfaceId The ID of the interface to check for adherence to.
|
|
268
|
+
function supportsInterface(bytes4 interfaceId) public view override(IERC165, JB721Hook) returns (bool) {
|
|
269
|
+
return interfaceId == type(IJB721TiersHook).interfaceId || JB721Hook.supportsInterface(interfaceId);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
272
|
/// @notice The metadata URI of the NFT with the specified token ID.
|
|
273
273
|
/// @dev Defers to the `tokenUriResolver` if it is set. Otherwise, use the `tokenUri` corresponding with the NFT's
|
|
274
274
|
/// tier.
|
|
@@ -3,12 +3,12 @@ pragma solidity 0.8.26;
|
|
|
3
3
|
|
|
4
4
|
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
5
5
|
import {JBOwnable} from "@bananapus/ownable-v6/src/JBOwnable.sol";
|
|
6
|
-
import {LibClone} from "solady/src/utils/LibClone.sol";
|
|
7
6
|
import {ERC2771Context} from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
|
|
7
|
+
import {LibClone} from "solady/src/utils/LibClone.sol";
|
|
8
8
|
|
|
9
9
|
import {JB721TiersHook} from "./JB721TiersHook.sol";
|
|
10
|
-
import {IJB721TiersHookDeployer} from "./interfaces/IJB721TiersHookDeployer.sol";
|
|
11
10
|
import {IJB721TiersHook} from "./interfaces/IJB721TiersHook.sol";
|
|
11
|
+
import {IJB721TiersHookDeployer} from "./interfaces/IJB721TiersHookDeployer.sol";
|
|
12
12
|
import {IJB721TiersHookStore} from "./interfaces/IJB721TiersHookStore.sol";
|
|
13
13
|
import {JBDeploy721TiersHookConfig} from "./structs/JBDeploy721TiersHookConfig.sol";
|
|
14
14
|
|
|
@@ -13,14 +13,14 @@ import {JBPermissionIds} from "@bananapus/permission-ids-v6/src/JBPermissionIds.
|
|
|
13
13
|
import {ERC2771Context} from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
|
|
14
14
|
import {Context} from "@openzeppelin/contracts/utils/Context.sol";
|
|
15
15
|
|
|
16
|
+
import {IJB721TiersHook} from "./interfaces/IJB721TiersHook.sol";
|
|
16
17
|
import {IJB721TiersHookDeployer} from "./interfaces/IJB721TiersHookDeployer.sol";
|
|
17
18
|
import {IJB721TiersHookProjectDeployer} from "./interfaces/IJB721TiersHookProjectDeployer.sol";
|
|
18
|
-
import {IJB721TiersHook} from "./interfaces/IJB721TiersHook.sol";
|
|
19
19
|
import {JBDeploy721TiersHookConfig} from "./structs/JBDeploy721TiersHookConfig.sol";
|
|
20
|
-
import {JBLaunchRulesetsConfig} from "./structs/JBLaunchRulesetsConfig.sol";
|
|
21
|
-
import {JBQueueRulesetsConfig} from "./structs/JBQueueRulesetsConfig.sol";
|
|
22
20
|
import {JBLaunchProjectConfig} from "./structs/JBLaunchProjectConfig.sol";
|
|
21
|
+
import {JBLaunchRulesetsConfig} from "./structs/JBLaunchRulesetsConfig.sol";
|
|
23
22
|
import {JBPayDataHookRulesetConfig} from "./structs/JBPayDataHookRulesetConfig.sol";
|
|
23
|
+
import {JBQueueRulesetsConfig} from "./structs/JBQueueRulesetsConfig.sol";
|
|
24
24
|
|
|
25
25
|
/// @title JB721TiersHookProjectDeployer
|
|
26
26
|
/// @notice Deploys a project and a 721 tiers hook for it. Can be used to queue rulesets for the project if given
|
|
@@ -195,6 +195,27 @@ contract JB721TiersHookProjectDeployer is ERC2771Context, JBPermissioned, IJB721
|
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
//*********************************************************************//
|
|
199
|
+
// -------------------------- internal views ------------------------- //
|
|
200
|
+
//*********************************************************************//
|
|
201
|
+
|
|
202
|
+
/// @dev ERC-2771 specifies the context as being a single address (20 bytes).
|
|
203
|
+
function _contextSuffixLength() internal view virtual override(ERC2771Context, Context) returns (uint256) {
|
|
204
|
+
return ERC2771Context._contextSuffixLength();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/// @notice The calldata. Preferred to use over `msg.data`.
|
|
208
|
+
/// @return calldata The `msg.data` of this call.
|
|
209
|
+
function _msgData() internal view override(ERC2771Context, Context) returns (bytes calldata) {
|
|
210
|
+
return ERC2771Context._msgData();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/// @notice The message's sender. Preferred to use over `msg.sender`.
|
|
214
|
+
/// @return sender The address which sent this call.
|
|
215
|
+
function _msgSender() internal view override(ERC2771Context, Context) returns (address sender) {
|
|
216
|
+
return ERC2771Context._msgSender();
|
|
217
|
+
}
|
|
218
|
+
|
|
198
219
|
//*********************************************************************//
|
|
199
220
|
// ------------------------ internal functions ----------------------- //
|
|
200
221
|
//*********************************************************************//
|
|
@@ -393,21 +414,4 @@ contract JB721TiersHookProjectDeployer is ERC2771Context, JBPermissioned, IJB721
|
|
|
393
414
|
projectId: projectId, rulesetConfigurations: rulesetConfigurations, memo: queueRulesetsConfig.memo
|
|
394
415
|
});
|
|
395
416
|
}
|
|
396
|
-
|
|
397
|
-
/// @notice The calldata. Preferred to use over `msg.data`.
|
|
398
|
-
/// @return calldata The `msg.data` of this call.
|
|
399
|
-
function _msgData() internal view override(ERC2771Context, Context) returns (bytes calldata) {
|
|
400
|
-
return ERC2771Context._msgData();
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/// @notice The message's sender. Preferred to use over `msg.sender`.
|
|
404
|
-
/// @return sender The address which sent this call.
|
|
405
|
-
function _msgSender() internal view override(ERC2771Context, Context) returns (address sender) {
|
|
406
|
-
return ERC2771Context._msgSender();
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/// @dev ERC-2771 specifies the context as being a single address (20 bytes).
|
|
410
|
-
function _contextSuffixLength() internal view virtual override(ERC2771Context, Context) returns (uint256) {
|
|
411
|
-
return ERC2771Context._contextSuffixLength();
|
|
412
|
-
}
|
|
413
417
|
}
|
|
@@ -383,18 +383,6 @@ contract JB721TiersHookStore is IJB721TiersHookStore {
|
|
|
383
383
|
// -------------------------- public views --------------------------- //
|
|
384
384
|
//*********************************************************************//
|
|
385
385
|
|
|
386
|
-
/// @notice Get the tier with the provided ID from the provided 721 contract.
|
|
387
|
-
/// @param hook The 721 contract to get the tier from.
|
|
388
|
-
/// @param id The ID of the tier to get.
|
|
389
|
-
/// @param includeResolvedUri If set to `true`, if the contract has a token URI resolver, its content will be
|
|
390
|
-
/// resolved and included.
|
|
391
|
-
/// @return The tier.
|
|
392
|
-
function tierOf(address hook, uint256 id, bool includeResolvedUri) public view override returns (JB721Tier memory) {
|
|
393
|
-
return _getTierFrom({
|
|
394
|
-
hook: hook, tierId: id, storedTier: _storedTierOf[hook][id], includeResolvedUri: includeResolvedUri
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
|
|
398
386
|
/// @notice Get the number of NFTs that the specified address has from the specified 721 contract (across all
|
|
399
387
|
/// tiers).
|
|
400
388
|
/// @param hook The 721 contract to get the balance within.
|
|
@@ -454,6 +442,18 @@ contract JB721TiersHookStore is IJB721TiersHookStore {
|
|
|
454
442
|
return tokenId / _ONE_BILLION;
|
|
455
443
|
}
|
|
456
444
|
|
|
445
|
+
/// @notice Get the tier with the provided ID from the provided 721 contract.
|
|
446
|
+
/// @param hook The 721 contract to get the tier from.
|
|
447
|
+
/// @param id The ID of the tier to get.
|
|
448
|
+
/// @param includeResolvedUri If set to `true`, if the contract has a token URI resolver, its content will be
|
|
449
|
+
/// resolved and included.
|
|
450
|
+
/// @return The tier.
|
|
451
|
+
function tierOf(address hook, uint256 id, bool includeResolvedUri) public view override returns (JB721Tier memory) {
|
|
452
|
+
return _getTierFrom({
|
|
453
|
+
hook: hook, tierId: id, storedTier: _storedTierOf[hook][id], includeResolvedUri: includeResolvedUri
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
|
|
457
457
|
/// @notice The combined cash out weight for all NFTs from the provided 721 contract.
|
|
458
458
|
/// @param hook The 721 contract to get the total cash out weight of.
|
|
459
459
|
/// @return weight The total cash out weight.
|
|
@@ -763,6 +763,10 @@ contract JB721TiersHookStore is IJB721TiersHookStore {
|
|
|
763
763
|
}
|
|
764
764
|
|
|
765
765
|
/// @notice Record newly added tiers.
|
|
766
|
+
/// @dev WARNING: If any tier in `tiersToAdd` has `useReserveBeneficiaryAsDefault` set to `true`, its
|
|
767
|
+
/// `reserveBeneficiary` will overwrite the hook's global `defaultReserveBeneficiaryOf`. This affects ALL existing
|
|
768
|
+
/// tiers that do not have a tier-specific reserve beneficiary set via `_reserveBeneficiaryOf`. Callers should be
|
|
769
|
+
/// aware of this side effect when using `adjustTiers` to add new tiers.
|
|
766
770
|
/// @param tiersToAdd The tiers to add.
|
|
767
771
|
/// @return tierIds The IDs of the tiers being added.
|
|
768
772
|
function recordAddTiers(JB721TierConfig[] calldata tiersToAdd)
|
|
@@ -884,8 +888,12 @@ contract JB721TiersHookStore is IJB721TiersHookStore {
|
|
|
884
888
|
// Set the reserve beneficiary if needed.
|
|
885
889
|
if (tierToAdd.reserveBeneficiary != address(0) && tierToAdd.reserveFrequency != 0) {
|
|
886
890
|
if (tierToAdd.useReserveBeneficiaryAsDefault) {
|
|
891
|
+
// WARNING: This overwrites the global default for ALL tiers without a tier-specific beneficiary.
|
|
887
892
|
if (defaultReserveBeneficiaryOf[msg.sender] != tierToAdd.reserveBeneficiary) {
|
|
888
893
|
defaultReserveBeneficiaryOf[msg.sender] = tierToAdd.reserveBeneficiary;
|
|
894
|
+
emit SetDefaultReserveBeneficiary({
|
|
895
|
+
hook: msg.sender, newBeneficiary: tierToAdd.reserveBeneficiary, caller: msg.sender
|
|
896
|
+
});
|
|
889
897
|
}
|
|
890
898
|
} else {
|
|
891
899
|
_reserveBeneficiaryOf[msg.sender][tierId] = tierToAdd.reserveBeneficiary;
|
|
@@ -17,8 +17,8 @@ import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
|
17
17
|
import {IERC2981} from "@openzeppelin/contracts/interfaces/IERC2981.sol";
|
|
18
18
|
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
19
19
|
|
|
20
|
-
import {ERC721} from "./ERC721.sol";
|
|
21
20
|
import {IJB721Hook} from "../interfaces/IJB721Hook.sol";
|
|
21
|
+
import {ERC721} from "./ERC721.sol";
|
|
22
22
|
|
|
23
23
|
/// @title JB721Hook
|
|
24
24
|
/// @notice When a project which uses this hook is paid, this hook may mint NFTs to the payer, depending on this hook's
|
|
@@ -68,26 +68,6 @@ abstract contract JB721Hook is ERC721, IJB721Hook {
|
|
|
68
68
|
// ------------------------- external views -------------------------- //
|
|
69
69
|
//*********************************************************************//
|
|
70
70
|
|
|
71
|
-
/// @notice The data calculated before a payment is recorded in the terminal store. This data is provided to the
|
|
72
|
-
/// terminal's `pay(...)` transaction.
|
|
73
|
-
/// @dev Sets this contract as the pay hook. Part of `IJBRulesetDataHook`.
|
|
74
|
-
/// @param context The payment context passed to this contract by the `pay(...)` function.
|
|
75
|
-
/// @return weight The new `weight` to use, overriding the ruleset's `weight`.
|
|
76
|
-
/// @return hookSpecifications The amount and data to send to pay hooks (this contract) instead of adding to the
|
|
77
|
-
/// terminal's balance.
|
|
78
|
-
function beforePayRecordedWith(JBBeforePayRecordedContext calldata context)
|
|
79
|
-
public
|
|
80
|
-
view
|
|
81
|
-
virtual
|
|
82
|
-
override
|
|
83
|
-
returns (uint256 weight, JBPayHookSpecification[] memory hookSpecifications)
|
|
84
|
-
{
|
|
85
|
-
// Forward the received weight and use this contract as the only pay hook.
|
|
86
|
-
weight = context.weight;
|
|
87
|
-
hookSpecifications = new JBPayHookSpecification[](1);
|
|
88
|
-
hookSpecifications[0] = JBPayHookSpecification({hook: this, amount: 0, metadata: bytes("")});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
71
|
/// @notice The data calculated before a cash out is recorded in the terminal store. This data is provided to the
|
|
92
72
|
/// terminal's `cashOutTokensOf(...)` transaction.
|
|
93
73
|
/// @dev Sets this contract as the cash out hook. Part of `IJBRulesetDataHook`.
|
|
@@ -138,6 +118,26 @@ abstract contract JB721Hook is ERC721, IJB721Hook {
|
|
|
138
118
|
cashOutTaxRate = context.cashOutTaxRate;
|
|
139
119
|
}
|
|
140
120
|
|
|
121
|
+
/// @notice The data calculated before a payment is recorded in the terminal store. This data is provided to the
|
|
122
|
+
/// terminal's `pay(...)` transaction.
|
|
123
|
+
/// @dev Sets this contract as the pay hook. Part of `IJBRulesetDataHook`.
|
|
124
|
+
/// @param context The payment context passed to this contract by the `pay(...)` function.
|
|
125
|
+
/// @return weight The new `weight` to use, overriding the ruleset's `weight`.
|
|
126
|
+
/// @return hookSpecifications The amount and data to send to pay hooks (this contract) instead of adding to the
|
|
127
|
+
/// terminal's balance.
|
|
128
|
+
function beforePayRecordedWith(JBBeforePayRecordedContext calldata context)
|
|
129
|
+
public
|
|
130
|
+
view
|
|
131
|
+
virtual
|
|
132
|
+
override
|
|
133
|
+
returns (uint256 weight, JBPayHookSpecification[] memory hookSpecifications)
|
|
134
|
+
{
|
|
135
|
+
// Forward the received weight and use this contract as the only pay hook.
|
|
136
|
+
weight = context.weight;
|
|
137
|
+
hookSpecifications = new JBPayHookSpecification[](1);
|
|
138
|
+
hookSpecifications[0] = JBPayHookSpecification({hook: this, amount: 0, metadata: bytes("")});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
141
|
/// @notice Required by the IJBRulesetDataHook interfaces. Return false to not leak any permissions.
|
|
142
142
|
function hasMintPermissionFor(uint256, JBRuleset memory, address) external pure returns (bool) {
|
|
143
143
|
return false;
|
|
@@ -175,24 +175,6 @@ abstract contract JB721Hook is ERC721, IJB721Hook {
|
|
|
175
175
|
// ---------------------- external transactions ---------------------- //
|
|
176
176
|
//*********************************************************************//
|
|
177
177
|
|
|
178
|
-
/// @notice Mints one or more NFTs to the `context.beneficiary` upon payment if conditions are met. Part of
|
|
179
|
-
/// `IJBPayHook`.
|
|
180
|
-
/// @dev Reverts if the calling contract is not one of the project's terminals.
|
|
181
|
-
/// @param context The payment context passed in by the terminal.
|
|
182
|
-
// slither-disable-next-line locked-ether
|
|
183
|
-
function afterPayRecordedWith(JBAfterPayRecordedContext calldata context) external payable virtual override {
|
|
184
|
-
uint256 projectId = PROJECT_ID;
|
|
185
|
-
|
|
186
|
-
// Make sure the caller is a terminal of the project, and that the call is being made on behalf of an
|
|
187
|
-
// interaction with the correct project.
|
|
188
|
-
if (!DIRECTORY.isTerminalOf(projectId, IJBTerminal(msg.sender)) || context.projectId != projectId) {
|
|
189
|
-
revert JB721Hook_InvalidPay();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Process the payment.
|
|
193
|
-
_processPayment(context);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
178
|
/// @notice Burns the specified NFTs upon token holder cash out, reclaiming funds from the project's balance for
|
|
197
179
|
/// `context.beneficiary`. Part of `IJBCashOutHook`.
|
|
198
180
|
/// @dev Reverts if the calling contract is not one of the project's terminals.
|
|
@@ -241,10 +223,32 @@ abstract contract JB721Hook is ERC721, IJB721Hook {
|
|
|
241
223
|
_didBurn(decodedTokenIds);
|
|
242
224
|
}
|
|
243
225
|
|
|
226
|
+
/// @notice Mints one or more NFTs to the `context.beneficiary` upon payment if conditions are met. Part of
|
|
227
|
+
/// `IJBPayHook`.
|
|
228
|
+
/// @dev Reverts if the calling contract is not one of the project's terminals.
|
|
229
|
+
/// @param context The payment context passed in by the terminal.
|
|
230
|
+
// slither-disable-next-line locked-ether
|
|
231
|
+
function afterPayRecordedWith(JBAfterPayRecordedContext calldata context) external payable virtual override {
|
|
232
|
+
uint256 projectId = PROJECT_ID;
|
|
233
|
+
|
|
234
|
+
// Make sure the caller is a terminal of the project, and that the call is being made on behalf of an
|
|
235
|
+
// interaction with the correct project.
|
|
236
|
+
if (!DIRECTORY.isTerminalOf(projectId, IJBTerminal(msg.sender)) || context.projectId != projectId) {
|
|
237
|
+
revert JB721Hook_InvalidPay();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Process the payment.
|
|
241
|
+
_processPayment(context);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
244
|
//*********************************************************************//
|
|
245
|
-
//
|
|
245
|
+
// ------------------------ internal functions ----------------------- //
|
|
246
246
|
//*********************************************************************//
|
|
247
247
|
|
|
248
|
+
/// @notice Executes after NFTs have been burned via cash out.
|
|
249
|
+
/// @param tokenIds The token IDs of the NFTs that were burned.
|
|
250
|
+
function _didBurn(uint256[] memory tokenIds) internal virtual;
|
|
251
|
+
|
|
248
252
|
/// @notice Initializes the contract by associating it with a project and adding ERC721 details.
|
|
249
253
|
/// @param projectId The ID of the project that this contract is associated with.
|
|
250
254
|
/// @param name The name of the NFT collection.
|
|
@@ -254,10 +258,6 @@ abstract contract JB721Hook is ERC721, IJB721Hook {
|
|
|
254
258
|
PROJECT_ID = projectId;
|
|
255
259
|
}
|
|
256
260
|
|
|
257
|
-
/// @notice Executes after NFTs have been burned via cash out.
|
|
258
|
-
/// @param tokenIds The token IDs of the NFTs that were burned.
|
|
259
|
-
function _didBurn(uint256[] memory tokenIds) internal virtual;
|
|
260
|
-
|
|
261
261
|
/// @notice Process a received payment.
|
|
262
262
|
/// @param context The payment context passed in by the terminal.
|
|
263
263
|
function _processPayment(JBAfterPayRecordedContext calldata context) internal virtual;
|
|
@@ -6,6 +6,7 @@ import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
|
|
|
6
6
|
import {IJBPayHook} from "@bananapus/core-v6/src/interfaces/IJBPayHook.sol";
|
|
7
7
|
import {IJBRulesetDataHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetDataHook.sol";
|
|
8
8
|
|
|
9
|
+
/// @notice A 721 hook that integrates with Juicebox as a data hook, pay hook, and cash out hook.
|
|
9
10
|
interface IJB721Hook is IJBRulesetDataHook, IJBPayHook, IJBCashOutHook {
|
|
10
11
|
/// @notice The directory of terminals and controllers for projects.
|
|
11
12
|
/// @return The directory contract.
|
|
@@ -13,11 +13,29 @@ import {JB721TiersHookFlags} from "../structs/JB721TiersHookFlags.sol";
|
|
|
13
13
|
import {JB721TiersMintReservesConfig} from "../structs/JB721TiersMintReservesConfig.sol";
|
|
14
14
|
import {JB721TiersSetDiscountPercentConfig} from "../structs/JB721TiersSetDiscountPercentConfig.sol";
|
|
15
15
|
|
|
16
|
+
/// @notice A 721 tiers hook that mints tiered NFTs for payments and tracks their cash out weight.
|
|
16
17
|
interface IJB721TiersHook is IJB721Hook {
|
|
18
|
+
/// @notice Emitted when pay credits are added for an account.
|
|
19
|
+
/// @param amount The amount of credits added.
|
|
20
|
+
/// @param newTotalCredits The new total credits balance for the account.
|
|
21
|
+
/// @param account The account that received the credits.
|
|
22
|
+
/// @param caller The address that called the function.
|
|
17
23
|
event AddPayCredits(
|
|
18
24
|
uint256 indexed amount, uint256 indexed newTotalCredits, address indexed account, address caller
|
|
19
25
|
);
|
|
26
|
+
|
|
27
|
+
/// @notice Emitted when a new tier is added.
|
|
28
|
+
/// @param tierId The ID of the tier that was added.
|
|
29
|
+
/// @param tier The configuration of the tier that was added.
|
|
30
|
+
/// @param caller The address that called the function.
|
|
20
31
|
event AddTier(uint256 indexed tierId, JB721TierConfig tier, address caller);
|
|
32
|
+
|
|
33
|
+
/// @notice Emitted when an NFT is minted from a payment.
|
|
34
|
+
/// @param tokenId The token ID of the minted NFT.
|
|
35
|
+
/// @param tierId The ID of the tier the NFT was minted from.
|
|
36
|
+
/// @param beneficiary The address that received the NFT.
|
|
37
|
+
/// @param totalAmountPaid The total amount paid in the transaction.
|
|
38
|
+
/// @param caller The address that called the function.
|
|
21
39
|
event Mint(
|
|
22
40
|
uint256 indexed tokenId,
|
|
23
41
|
uint256 indexed tierId,
|
|
@@ -25,25 +43,55 @@ interface IJB721TiersHook is IJB721Hook {
|
|
|
25
43
|
uint256 totalAmountPaid,
|
|
26
44
|
address caller
|
|
27
45
|
);
|
|
46
|
+
|
|
47
|
+
/// @notice Emitted when a reserved NFT is minted.
|
|
48
|
+
/// @param tokenId The token ID of the minted reserved NFT.
|
|
49
|
+
/// @param tierId The ID of the tier the reserved NFT was minted from.
|
|
50
|
+
/// @param beneficiary The address that received the reserved NFT.
|
|
51
|
+
/// @param caller The address that called the function.
|
|
28
52
|
event MintReservedNft(uint256 indexed tokenId, uint256 indexed tierId, address indexed beneficiary, address caller);
|
|
53
|
+
|
|
54
|
+
/// @notice Emitted when a tier is removed.
|
|
55
|
+
/// @param tierId The ID of the tier that was removed.
|
|
56
|
+
/// @param caller The address that called the function.
|
|
29
57
|
event RemoveTier(uint256 indexed tierId, address caller);
|
|
58
|
+
|
|
59
|
+
/// @notice Emitted when the base URI is set.
|
|
60
|
+
/// @param baseUri The new base URI.
|
|
61
|
+
/// @param caller The address that called the function.
|
|
30
62
|
event SetBaseUri(string indexed baseUri, address caller);
|
|
63
|
+
|
|
64
|
+
/// @notice Emitted when the contract URI is set.
|
|
65
|
+
/// @param uri The new contract URI.
|
|
66
|
+
/// @param caller The address that called the function.
|
|
31
67
|
event SetContractUri(string indexed uri, address caller);
|
|
68
|
+
|
|
69
|
+
/// @notice Emitted when a tier's discount percent is set.
|
|
70
|
+
/// @param tierId The ID of the tier whose discount percent was set.
|
|
71
|
+
/// @param discountPercent The new discount percent.
|
|
72
|
+
/// @param caller The address that called the function.
|
|
32
73
|
event SetDiscountPercent(uint256 indexed tierId, uint256 discountPercent, address caller);
|
|
74
|
+
|
|
75
|
+
/// @notice Emitted when a tier's encoded IPFS URI is set.
|
|
76
|
+
/// @param tierId The ID of the tier whose encoded IPFS URI was set.
|
|
77
|
+
/// @param encodedUri The new encoded IPFS URI.
|
|
78
|
+
/// @param caller The address that called the function.
|
|
33
79
|
event SetEncodedIPFSUri(uint256 indexed tierId, bytes32 encodedUri, address caller);
|
|
80
|
+
|
|
81
|
+
/// @notice Emitted when the token URI resolver is set.
|
|
82
|
+
/// @param resolver The new token URI resolver.
|
|
83
|
+
/// @param caller The address that called the function.
|
|
34
84
|
event SetTokenUriResolver(IJB721TokenUriResolver indexed resolver, address caller);
|
|
85
|
+
|
|
86
|
+
/// @notice Emitted when pay credits are used by an account.
|
|
87
|
+
/// @param amount The amount of credits used.
|
|
88
|
+
/// @param newTotalCredits The new total credits balance for the account.
|
|
89
|
+
/// @param account The account that used the credits.
|
|
90
|
+
/// @param caller The address that called the function.
|
|
35
91
|
event UsePayCredits(
|
|
36
92
|
uint256 indexed amount, uint256 indexed newTotalCredits, address indexed account, address caller
|
|
37
93
|
);
|
|
38
94
|
|
|
39
|
-
/// @notice The contract storing and managing project rulesets.
|
|
40
|
-
/// @return The rulesets contract.
|
|
41
|
-
function RULESETS() external view returns (IJBRulesets);
|
|
42
|
-
|
|
43
|
-
/// @notice The contract that stores and manages data for this contract's NFTs.
|
|
44
|
-
/// @return The store contract.
|
|
45
|
-
function STORE() external view returns (IJB721TiersHookStore);
|
|
46
|
-
|
|
47
95
|
/// @notice The base URI for the NFT `tokenUris`.
|
|
48
96
|
/// @return The base URI string.
|
|
49
97
|
function baseURI() external view returns (string memory);
|
|
@@ -68,6 +116,14 @@ interface IJB721TiersHook is IJB721Hook {
|
|
|
68
116
|
/// @return prices The prices contract used to resolve the value of payments in other currencies.
|
|
69
117
|
function pricingContext() external view returns (uint256 currency, uint256 decimals, IJBPrices prices);
|
|
70
118
|
|
|
119
|
+
/// @notice The contract storing and managing project rulesets.
|
|
120
|
+
/// @return The rulesets contract.
|
|
121
|
+
function RULESETS() external view returns (IJBRulesets);
|
|
122
|
+
|
|
123
|
+
/// @notice The contract that stores and manages data for this contract's NFTs.
|
|
124
|
+
/// @return The store contract.
|
|
125
|
+
function STORE() external view returns (IJB721TiersHookStore);
|
|
126
|
+
|
|
71
127
|
/// @notice Add or remove tiers.
|
|
72
128
|
/// @param tiersToAdd The tiers to add, as an array of `JB721TierConfig` structs.
|
|
73
129
|
/// @param tierIdsToRemove The tiers to remove, as an array of tier IDs.
|
|
@@ -94,15 +150,6 @@ interface IJB721TiersHook is IJB721Hook {
|
|
|
94
150
|
)
|
|
95
151
|
external;
|
|
96
152
|
|
|
97
|
-
/// @notice Set the discount percent for a tier.
|
|
98
|
-
/// @param tierId The ID of the tier to set the discount of.
|
|
99
|
-
/// @param discountPercent The discount percent to set.
|
|
100
|
-
function setDiscountPercentOf(uint256 tierId, uint256 discountPercent) external;
|
|
101
|
-
|
|
102
|
-
/// @notice Set the discount percent for multiple tiers.
|
|
103
|
-
/// @param configs The configs to set the discount percent for.
|
|
104
|
-
function setDiscountPercentsOf(JB721TiersSetDiscountPercentConfig[] calldata configs) external;
|
|
105
|
-
|
|
106
153
|
/// @notice Manually mint NFTs from the provided tiers.
|
|
107
154
|
/// @param tierIds The IDs of the tiers to mint from.
|
|
108
155
|
/// @param beneficiary The address to mint to.
|
|
@@ -118,6 +165,15 @@ interface IJB721TiersHook is IJB721Hook {
|
|
|
118
165
|
/// @param count The number of reserved NFTs to mint.
|
|
119
166
|
function mintPendingReservesFor(uint256 tierId, uint256 count) external;
|
|
120
167
|
|
|
168
|
+
/// @notice Set the discount percent for a tier.
|
|
169
|
+
/// @param tierId The ID of the tier to set the discount of.
|
|
170
|
+
/// @param discountPercent The discount percent to set.
|
|
171
|
+
function setDiscountPercentOf(uint256 tierId, uint256 discountPercent) external;
|
|
172
|
+
|
|
173
|
+
/// @notice Set the discount percent for multiple tiers.
|
|
174
|
+
/// @param configs The configs to set the discount percent for.
|
|
175
|
+
function setDiscountPercentsOf(JB721TiersSetDiscountPercentConfig[] calldata configs) external;
|
|
176
|
+
|
|
121
177
|
/// @notice Update this hook's URI metadata properties.
|
|
122
178
|
/// @param baseUri The new base URI.
|
|
123
179
|
/// @param contractUri The new contract URI.
|
|
@@ -4,7 +4,12 @@ pragma solidity ^0.8.0;
|
|
|
4
4
|
import {IJB721TiersHook} from "./IJB721TiersHook.sol";
|
|
5
5
|
import {JBDeploy721TiersHookConfig} from "../structs/JBDeploy721TiersHookConfig.sol";
|
|
6
6
|
|
|
7
|
+
/// @notice Deploys 721 tiers hooks for projects.
|
|
7
8
|
interface IJB721TiersHookDeployer {
|
|
9
|
+
/// @notice Emitted when a 721 tiers hook is deployed for a project.
|
|
10
|
+
/// @param projectId The ID of the project the hook was deployed for.
|
|
11
|
+
/// @param hook The deployed hook contract.
|
|
12
|
+
/// @param caller The address that called the function.
|
|
8
13
|
event HookDeployed(uint256 indexed projectId, IJB721TiersHook hook, address caller);
|
|
9
14
|
|
|
10
15
|
/// @notice Deploys a 721 tiers hook for the specified project.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
-
import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
|
|
5
4
|
import {IJBController} from "@bananapus/core-v6/src/interfaces/IJBController.sol";
|
|
5
|
+
import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
|
|
6
6
|
|
|
7
7
|
import {IJB721TiersHook} from "./IJB721TiersHook.sol";
|
|
8
8
|
import {IJB721TiersHookDeployer} from "./IJB721TiersHookDeployer.sol";
|
|
@@ -11,6 +11,7 @@ import {JBLaunchProjectConfig} from "../structs/JBLaunchProjectConfig.sol";
|
|
|
11
11
|
import {JBLaunchRulesetsConfig} from "../structs/JBLaunchRulesetsConfig.sol";
|
|
12
12
|
import {JBQueueRulesetsConfig} from "../structs/JBQueueRulesetsConfig.sol";
|
|
13
13
|
|
|
14
|
+
/// @notice Deploys projects with 721 tiers hooks attached.
|
|
14
15
|
interface IJB721TiersHookProjectDeployer {
|
|
15
16
|
/// @notice The directory of terminals and controllers for projects.
|
|
16
17
|
/// @return The directory contract.
|
|
@@ -6,9 +6,20 @@ import {JB721Tier} from "../structs/JB721Tier.sol";
|
|
|
6
6
|
import {JB721TierConfig} from "../structs/JB721TierConfig.sol";
|
|
7
7
|
import {JB721TiersHookFlags} from "../structs/JB721TiersHookFlags.sol";
|
|
8
8
|
|
|
9
|
+
/// @notice Stores and manages data for 721 tiers hooks.
|
|
9
10
|
interface IJB721TiersHookStore {
|
|
11
|
+
/// @notice Emitted when removed tiers are cleaned from the sorting sequence.
|
|
12
|
+
/// @param hook The 721 contract whose tiers were cleaned.
|
|
13
|
+
/// @param caller The address that called the function.
|
|
10
14
|
event CleanTiers(address indexed hook, address caller);
|
|
11
15
|
|
|
16
|
+
/// @notice Emitted when the default reserve beneficiary is changed.
|
|
17
|
+
/// @dev This affects ALL tiers that do not have a tier-specific reserve beneficiary set.
|
|
18
|
+
/// @param hook The 721 contract whose default reserve beneficiary was changed.
|
|
19
|
+
/// @param newBeneficiary The new default reserve beneficiary address.
|
|
20
|
+
/// @param caller The address that triggered the change.
|
|
21
|
+
event SetDefaultReserveBeneficiary(address indexed hook, address indexed newBeneficiary, address caller);
|
|
22
|
+
|
|
12
23
|
/// @notice Get the number of NFTs that the specified address owns from the specified 721 contract.
|
|
13
24
|
/// @param hook The 721 contract to get the balance within.
|
|
14
25
|
/// @param owner The address to check the balance of.
|
|
@@ -17,6 +17,7 @@ import {JBSplitGroup} from "@bananapus/core-v6/src/structs/JBSplitGroup.sol";
|
|
|
17
17
|
|
|
18
18
|
import {IJB721TiersHookStore} from "../interfaces/IJB721TiersHookStore.sol";
|
|
19
19
|
import {IJB721TokenUriResolver} from "../interfaces/IJB721TokenUriResolver.sol";
|
|
20
|
+
import {JB721Tier} from "../structs/JB721Tier.sol";
|
|
20
21
|
import {JB721TierConfig} from "../structs/JB721TierConfig.sol";
|
|
21
22
|
import {JBIpfsDecoder} from "./JBIpfsDecoder.sol";
|
|
22
23
|
|
|
@@ -52,6 +53,7 @@ library JB721TiersHookLib {
|
|
|
52
53
|
for (uint256 i; i < tierIdsToRemove.length; i++) {
|
|
53
54
|
emit RemoveTier({tierId: tierIdsToRemove[i], caller: caller});
|
|
54
55
|
}
|
|
56
|
+
// slither-disable-next-line reentrancy-events
|
|
55
57
|
store.recordRemoveTierIds(tierIdsToRemove);
|
|
56
58
|
}
|
|
57
59
|
|
|
@@ -141,12 +143,10 @@ library JB721TiersHookLib {
|
|
|
141
143
|
|
|
142
144
|
for (uint256 i; i < tierIdsToMint.length; i++) {
|
|
143
145
|
// slither-disable-next-line calls-loop
|
|
144
|
-
|
|
145
|
-
if (splitPercent != 0) {
|
|
146
|
-
// slither-disable-next-line calls-loop
|
|
147
|
-
uint256 price = store.tierOf(hook, tierIdsToMint[i], false).price;
|
|
146
|
+
JB721Tier memory tier = store.tierOf(hook, tierIdsToMint[i], false);
|
|
147
|
+
if (tier.splitPercent != 0) {
|
|
148
148
|
splitTierIds[splitTierCount] = tierIdsToMint[i];
|
|
149
|
-
splitAmounts[splitTierCount] = mulDiv(price, splitPercent, JBConstants.SPLITS_TOTAL_PERCENT);
|
|
149
|
+
splitAmounts[splitTierCount] = mulDiv(tier.price, tier.splitPercent, JBConstants.SPLITS_TOTAL_PERCENT);
|
|
150
150
|
totalSplitAmount += splitAmounts[splitTierCount];
|
|
151
151
|
splitTierCount++;
|
|
152
152
|
}
|
|
@@ -237,9 +237,13 @@ library JB721TiersHookLib {
|
|
|
237
237
|
for (uint256 j; j < tierSplits.length; j++) {
|
|
238
238
|
uint256 payoutAmount = mulDiv(amount, tierSplits[j].percent, leftoverPercentage);
|
|
239
239
|
if (payoutAmount != 0) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
// Only subtract from leftover if the split has a valid recipient.
|
|
241
|
+
// Splits with no projectId and no beneficiary are skipped — their share
|
|
242
|
+
// stays in leftoverAmount and is added to the project's balance below.
|
|
243
|
+
if (_sendPayoutToSplit(directory, tierSplits[j], token, payoutAmount, isNativeToken)) {
|
|
244
|
+
unchecked {
|
|
245
|
+
leftoverAmount -= payoutAmount;
|
|
246
|
+
}
|
|
243
247
|
}
|
|
244
248
|
}
|
|
245
249
|
unchecked {
|
|
@@ -252,6 +256,9 @@ library JB721TiersHookLib {
|
|
|
252
256
|
}
|
|
253
257
|
}
|
|
254
258
|
|
|
259
|
+
/// @notice Sends a payout to a split recipient.
|
|
260
|
+
/// @return sent Whether the funds were actually sent. Returns false if the split has no valid recipient
|
|
261
|
+
/// (no projectId and no beneficiary), so the caller can route the funds elsewhere.
|
|
255
262
|
function _sendPayoutToSplit(
|
|
256
263
|
IJBDirectory directory,
|
|
257
264
|
JBSplit memory split,
|
|
@@ -260,17 +267,19 @@ library JB721TiersHookLib {
|
|
|
260
267
|
bool isNativeToken
|
|
261
268
|
)
|
|
262
269
|
private
|
|
270
|
+
returns (bool sent)
|
|
263
271
|
{
|
|
264
272
|
if (split.projectId != 0) {
|
|
265
273
|
// slither-disable-next-line calls-loop
|
|
266
274
|
IJBTerminal terminal = directory.primaryTerminalOf(split.projectId, token);
|
|
267
|
-
if (address(terminal) == address(0)) return;
|
|
275
|
+
if (address(terminal) == address(0)) return false;
|
|
268
276
|
|
|
269
277
|
if (split.preferAddToBalance) {
|
|
270
278
|
_terminalAddToBalance(terminal, split.projectId, token, amount, isNativeToken);
|
|
271
279
|
} else {
|
|
272
280
|
_terminalPay(terminal, split.projectId, token, amount, split.beneficiary, isNativeToken);
|
|
273
281
|
}
|
|
282
|
+
return true;
|
|
274
283
|
} else if (split.beneficiary != address(0)) {
|
|
275
284
|
if (isNativeToken) {
|
|
276
285
|
// slither-disable-next-line arbitrary-send-eth,calls-loop
|
|
@@ -279,7 +288,10 @@ library JB721TiersHookLib {
|
|
|
279
288
|
} else {
|
|
280
289
|
SafeERC20.safeTransfer(IERC20(token), split.beneficiary, amount);
|
|
281
290
|
}
|
|
291
|
+
return true;
|
|
282
292
|
}
|
|
293
|
+
// No projectId and no beneficiary — return false so the funds go to the project's balance.
|
|
294
|
+
return false;
|
|
283
295
|
}
|
|
284
296
|
|
|
285
297
|
function _addToBalance(
|
|
@@ -18,7 +18,9 @@ import {JBSplit} from "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
|
18
18
|
/// @custom:member allowOwnerMint A boolean indicating whether the contract's owner can mint NFTs from this tier
|
|
19
19
|
/// on-demand.
|
|
20
20
|
/// @custom:member useReserveBeneficiaryAsDefault A boolean indicating whether this tier's `reserveBeneficiary` should
|
|
21
|
-
/// be stored as the default beneficiary for all tiers.
|
|
21
|
+
/// be stored as the default beneficiary for all tiers. WARNING: Setting this to `true` overwrites the global
|
|
22
|
+
/// `defaultReserveBeneficiaryOf` for the hook, which affects ALL existing tiers that do not have a tier-specific
|
|
23
|
+
/// reserve beneficiary. Use with caution when calling `adjustTiers` on hooks with existing tiers.
|
|
22
24
|
/// @custom:member transfersPausable A boolean indicating whether transfers for NFTs in tier can be paused.
|
|
23
25
|
/// @custom:member useVotingUnits A boolean indicating whether the `votingUnits` should be used to calculate voting
|
|
24
26
|
/// power. If `useVotingUnits` is false, voting power is based on the tier's price.
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.26;
|
|
3
|
+
|
|
4
|
+
import "../utils/UnitTestSetup.sol";
|
|
5
|
+
import {IJB721TiersHookStore} from "../../src/interfaces/IJB721TiersHookStore.sol";
|
|
6
|
+
|
|
7
|
+
/// @notice Regression test for L-34: defaultReserveBeneficiaryOf is globally overwritten when adding a tier with
|
|
8
|
+
/// useReserveBeneficiaryAsDefault=true.
|
|
9
|
+
contract Test_L34_ReserveBeneficiaryOverwrite is UnitTestSetup {
|
|
10
|
+
using stdStorage for StdStorage;
|
|
11
|
+
|
|
12
|
+
address alice = makeAddr("alice");
|
|
13
|
+
address bob = makeAddr("bob");
|
|
14
|
+
|
|
15
|
+
/// @notice Verify that adding a tier with useReserveBeneficiaryAsDefault=true overwrites the global default
|
|
16
|
+
/// and emits the SetDefaultReserveBeneficiary event.
|
|
17
|
+
function test_addTierWithDefaultBeneficiary_overwritesGlobal() public {
|
|
18
|
+
ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
|
|
19
|
+
IJB721TiersHookStore hookStore = testHook.STORE();
|
|
20
|
+
|
|
21
|
+
// Add tier 1: alice as default reserve beneficiary.
|
|
22
|
+
JB721TierConfig[] memory tier1Configs = new JB721TierConfig[](1);
|
|
23
|
+
tier1Configs[0].price = 1 ether;
|
|
24
|
+
tier1Configs[0].initialSupply = uint32(100);
|
|
25
|
+
tier1Configs[0].category = uint24(1);
|
|
26
|
+
tier1Configs[0].encodedIPFSUri = bytes32(uint256(0x1234));
|
|
27
|
+
tier1Configs[0].reserveFrequency = 5;
|
|
28
|
+
tier1Configs[0].reserveBeneficiary = alice;
|
|
29
|
+
tier1Configs[0].useReserveBeneficiaryAsDefault = true;
|
|
30
|
+
|
|
31
|
+
vm.prank(address(testHook));
|
|
32
|
+
uint256[] memory tier1Ids = hookStore.recordAddTiers(tier1Configs);
|
|
33
|
+
|
|
34
|
+
// Verify alice is the default reserve beneficiary.
|
|
35
|
+
assertEq(hookStore.defaultReserveBeneficiaryOf(address(testHook)), alice);
|
|
36
|
+
|
|
37
|
+
// Verify tier 1 uses alice as its reserve beneficiary (via the default).
|
|
38
|
+
assertEq(hookStore.reserveBeneficiaryOf(address(testHook), tier1Ids[0]), alice);
|
|
39
|
+
|
|
40
|
+
// Add tier 2: no useReserveBeneficiaryAsDefault, with a per-tier beneficiary.
|
|
41
|
+
JB721TierConfig[] memory tier2Configs = new JB721TierConfig[](1);
|
|
42
|
+
tier2Configs[0].price = 2 ether;
|
|
43
|
+
tier2Configs[0].initialSupply = uint32(100);
|
|
44
|
+
tier2Configs[0].category = uint24(2);
|
|
45
|
+
tier2Configs[0].encodedIPFSUri = bytes32(uint256(0x5678));
|
|
46
|
+
tier2Configs[0].reserveFrequency = 5;
|
|
47
|
+
tier2Configs[0].reserveBeneficiary = bob;
|
|
48
|
+
tier2Configs[0].useReserveBeneficiaryAsDefault = false;
|
|
49
|
+
|
|
50
|
+
vm.prank(address(testHook));
|
|
51
|
+
uint256[] memory tier2Ids = hookStore.recordAddTiers(tier2Configs);
|
|
52
|
+
|
|
53
|
+
// Default should still be alice.
|
|
54
|
+
assertEq(hookStore.defaultReserveBeneficiaryOf(address(testHook)), alice);
|
|
55
|
+
|
|
56
|
+
// Tier 2 should use bob (tier-specific).
|
|
57
|
+
assertEq(hookStore.reserveBeneficiaryOf(address(testHook), tier2Ids[0]), bob);
|
|
58
|
+
|
|
59
|
+
// Now add tier 3: bob as the NEW default reserve beneficiary.
|
|
60
|
+
// This should overwrite the default, affecting tier 1 which relies on the default.
|
|
61
|
+
JB721TierConfig[] memory tier3Configs = new JB721TierConfig[](1);
|
|
62
|
+
tier3Configs[0].price = 3 ether;
|
|
63
|
+
tier3Configs[0].initialSupply = uint32(100);
|
|
64
|
+
tier3Configs[0].category = uint24(3);
|
|
65
|
+
tier3Configs[0].encodedIPFSUri = bytes32(uint256(0x9ABC));
|
|
66
|
+
tier3Configs[0].reserveFrequency = 5;
|
|
67
|
+
tier3Configs[0].reserveBeneficiary = bob;
|
|
68
|
+
tier3Configs[0].useReserveBeneficiaryAsDefault = true;
|
|
69
|
+
|
|
70
|
+
vm.prank(address(testHook));
|
|
71
|
+
uint256[] memory tier3Ids = hookStore.recordAddTiers(tier3Configs);
|
|
72
|
+
|
|
73
|
+
// Default should now be bob.
|
|
74
|
+
assertEq(hookStore.defaultReserveBeneficiaryOf(address(testHook)), bob);
|
|
75
|
+
|
|
76
|
+
// Tier 1 should now resolve to bob (the new default), NOT alice.
|
|
77
|
+
// This is the documented global overwrite behavior.
|
|
78
|
+
assertEq(hookStore.reserveBeneficiaryOf(address(testHook), tier1Ids[0]), bob);
|
|
79
|
+
|
|
80
|
+
// Tier 2 should still use bob (tier-specific, unaffected by default change).
|
|
81
|
+
assertEq(hookStore.reserveBeneficiaryOf(address(testHook), tier2Ids[0]), bob);
|
|
82
|
+
|
|
83
|
+
// Tier 3 should also resolve to bob (via the default).
|
|
84
|
+
assertEq(hookStore.reserveBeneficiaryOf(address(testHook), tier3Ids[0]), bob);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/// @notice Verify that the SetDefaultReserveBeneficiary event is emitted when the default changes.
|
|
88
|
+
function test_addTierWithDefaultBeneficiary_emitsEvent() public {
|
|
89
|
+
ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
|
|
90
|
+
IJB721TiersHookStore hookStore = testHook.STORE();
|
|
91
|
+
|
|
92
|
+
JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
|
|
93
|
+
tierConfigs[0].price = 1 ether;
|
|
94
|
+
tierConfigs[0].initialSupply = uint32(100);
|
|
95
|
+
tierConfigs[0].category = uint24(1);
|
|
96
|
+
tierConfigs[0].encodedIPFSUri = bytes32(uint256(0x1234));
|
|
97
|
+
tierConfigs[0].reserveFrequency = 5;
|
|
98
|
+
tierConfigs[0].reserveBeneficiary = alice;
|
|
99
|
+
tierConfigs[0].useReserveBeneficiaryAsDefault = true;
|
|
100
|
+
|
|
101
|
+
// Expect the SetDefaultReserveBeneficiary event.
|
|
102
|
+
vm.expectEmit(true, true, false, true, address(hookStore));
|
|
103
|
+
emit IJB721TiersHookStore.SetDefaultReserveBeneficiary({
|
|
104
|
+
hook: address(testHook), newBeneficiary: alice, caller: address(testHook)
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
vm.prank(address(testHook));
|
|
108
|
+
hookStore.recordAddTiers(tierConfigs);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// @notice Verify that no event is emitted when the beneficiary is already the same.
|
|
112
|
+
function test_addTierWithSameDefaultBeneficiary_noEvent() public {
|
|
113
|
+
ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
|
|
114
|
+
IJB721TiersHookStore hookStore = testHook.STORE();
|
|
115
|
+
|
|
116
|
+
// First, set alice as the default.
|
|
117
|
+
JB721TierConfig[] memory tier1Configs = new JB721TierConfig[](1);
|
|
118
|
+
tier1Configs[0].price = 1 ether;
|
|
119
|
+
tier1Configs[0].initialSupply = uint32(100);
|
|
120
|
+
tier1Configs[0].category = uint24(1);
|
|
121
|
+
tier1Configs[0].encodedIPFSUri = bytes32(uint256(0x1234));
|
|
122
|
+
tier1Configs[0].reserveFrequency = 5;
|
|
123
|
+
tier1Configs[0].reserveBeneficiary = alice;
|
|
124
|
+
tier1Configs[0].useReserveBeneficiaryAsDefault = true;
|
|
125
|
+
|
|
126
|
+
vm.prank(address(testHook));
|
|
127
|
+
hookStore.recordAddTiers(tier1Configs);
|
|
128
|
+
|
|
129
|
+
// Now add another tier with the same default — no event should be emitted.
|
|
130
|
+
JB721TierConfig[] memory tier2Configs = new JB721TierConfig[](1);
|
|
131
|
+
tier2Configs[0].price = 2 ether;
|
|
132
|
+
tier2Configs[0].initialSupply = uint32(100);
|
|
133
|
+
tier2Configs[0].category = uint24(2);
|
|
134
|
+
tier2Configs[0].encodedIPFSUri = bytes32(uint256(0x5678));
|
|
135
|
+
tier2Configs[0].reserveFrequency = 5;
|
|
136
|
+
tier2Configs[0].reserveBeneficiary = alice;
|
|
137
|
+
tier2Configs[0].useReserveBeneficiaryAsDefault = true;
|
|
138
|
+
|
|
139
|
+
// Record the logs to verify no SetDefaultReserveBeneficiary event is emitted.
|
|
140
|
+
vm.recordLogs();
|
|
141
|
+
|
|
142
|
+
vm.prank(address(testHook));
|
|
143
|
+
hookStore.recordAddTiers(tier2Configs);
|
|
144
|
+
|
|
145
|
+
Vm.Log[] memory logs = vm.getRecordedLogs();
|
|
146
|
+
for (uint256 i; i < logs.length; i++) {
|
|
147
|
+
// SetDefaultReserveBeneficiary event signature.
|
|
148
|
+
assertTrue(
|
|
149
|
+
logs[i].topics[0] != keccak256("SetDefaultReserveBeneficiary(address,address,address)"),
|
|
150
|
+
"SetDefaultReserveBeneficiary should not be emitted when beneficiary unchanged"
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.26;
|
|
3
|
+
|
|
4
|
+
import "../utils/UnitTestSetup.sol";
|
|
5
|
+
import {IJB721TiersHookStore} from "../../src/interfaces/IJB721TiersHookStore.sol";
|
|
6
|
+
import {JB721TiersHookLib} from "../../src/libraries/JB721TiersHookLib.sol";
|
|
7
|
+
|
|
8
|
+
/// @notice Regression test for L-35: calculateSplitAmounts cached the tierOf result to avoid a duplicate external call.
|
|
9
|
+
/// Verifies that the cached tier lookup returns the same split amounts as reading price and splitPercent individually.
|
|
10
|
+
contract Test_L35_CacheTierLookup is UnitTestSetup {
|
|
11
|
+
using stdStorage for StdStorage;
|
|
12
|
+
|
|
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.
|
|
15
|
+
function test_calculateSplitAmounts_multiTier_correctAmounts() public {
|
|
16
|
+
ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
|
|
17
|
+
IJB721TiersHookStore hookStore = testHook.STORE();
|
|
18
|
+
|
|
19
|
+
// Add 3 tiers with different prices and split percents.
|
|
20
|
+
JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](3);
|
|
21
|
+
|
|
22
|
+
// Tier A: 1 ETH, 25% split -> 0.25 ETH
|
|
23
|
+
tierConfigs[0].price = 1 ether;
|
|
24
|
+
tierConfigs[0].initialSupply = uint32(100);
|
|
25
|
+
tierConfigs[0].category = uint24(1);
|
|
26
|
+
tierConfigs[0].encodedIPFSUri = bytes32(uint256(0x1111));
|
|
27
|
+
tierConfigs[0].splitPercent = 250_000_000; // 25%
|
|
28
|
+
|
|
29
|
+
// Tier B: 2 ETH, 50% split -> 1 ETH
|
|
30
|
+
tierConfigs[1].price = 2 ether;
|
|
31
|
+
tierConfigs[1].initialSupply = uint32(100);
|
|
32
|
+
tierConfigs[1].category = uint24(2);
|
|
33
|
+
tierConfigs[1].encodedIPFSUri = bytes32(uint256(0x2222));
|
|
34
|
+
tierConfigs[1].splitPercent = 500_000_000; // 50%
|
|
35
|
+
|
|
36
|
+
// Tier C: 0.5 ETH, 100% split -> 0.5 ETH
|
|
37
|
+
tierConfigs[2].price = 0.5 ether;
|
|
38
|
+
tierConfigs[2].initialSupply = uint32(100);
|
|
39
|
+
tierConfigs[2].category = uint24(3);
|
|
40
|
+
tierConfigs[2].encodedIPFSUri = bytes32(uint256(0x3333));
|
|
41
|
+
tierConfigs[2].splitPercent = 1_000_000_000; // 100%
|
|
42
|
+
|
|
43
|
+
vm.prank(address(testHook));
|
|
44
|
+
uint256[] memory tierIds = hookStore.recordAddTiers(tierConfigs);
|
|
45
|
+
|
|
46
|
+
// Build payer metadata requesting all 3 tiers.
|
|
47
|
+
uint16[] memory mintIds = new uint16[](3);
|
|
48
|
+
mintIds[0] = uint16(tierIds[0]);
|
|
49
|
+
mintIds[1] = uint16(tierIds[1]);
|
|
50
|
+
mintIds[2] = uint16(tierIds[2]);
|
|
51
|
+
bytes memory payerMetadata = _buildPayerMetadata(address(testHook), mintIds);
|
|
52
|
+
|
|
53
|
+
JBBeforePayRecordedContext memory context = JBBeforePayRecordedContext({
|
|
54
|
+
terminal: mockTerminalAddress,
|
|
55
|
+
payer: beneficiary,
|
|
56
|
+
amount: JBTokenAmount({
|
|
57
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
58
|
+
value: 3.5 ether,
|
|
59
|
+
decimals: 18,
|
|
60
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
61
|
+
}),
|
|
62
|
+
projectId: projectId,
|
|
63
|
+
rulesetId: 0,
|
|
64
|
+
beneficiary: beneficiary,
|
|
65
|
+
weight: 10e18,
|
|
66
|
+
reservedPercent: 5000,
|
|
67
|
+
metadata: payerMetadata
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
(, JBPayHookSpecification[] memory specs) = testHook.beforePayRecordedWith(context);
|
|
71
|
+
|
|
72
|
+
// Total split = 0.25 + 1.0 + 0.5 = 1.75 ETH
|
|
73
|
+
assertEq(specs[0].amount, 1.75 ether, "Total split amount should be 1.75 ETH");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/// @notice Verify that a tier with splitPercent == 0 contributes nothing to the total, even when cached.
|
|
77
|
+
function test_calculateSplitAmounts_zeroSplitSkipped() public {
|
|
78
|
+
ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
|
|
79
|
+
IJB721TiersHookStore hookStore = testHook.STORE();
|
|
80
|
+
|
|
81
|
+
// Tier A: 1 ETH, 50% split
|
|
82
|
+
// Tier B: 3 ETH, 0% split (should be skipped)
|
|
83
|
+
JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](2);
|
|
84
|
+
tierConfigs[0].price = 1 ether;
|
|
85
|
+
tierConfigs[0].initialSupply = uint32(100);
|
|
86
|
+
tierConfigs[0].category = uint24(1);
|
|
87
|
+
tierConfigs[0].encodedIPFSUri = bytes32(uint256(0xAAAA));
|
|
88
|
+
tierConfigs[0].splitPercent = 500_000_000; // 50%
|
|
89
|
+
|
|
90
|
+
tierConfigs[1].price = 3 ether;
|
|
91
|
+
tierConfigs[1].initialSupply = uint32(100);
|
|
92
|
+
tierConfigs[1].category = uint24(2);
|
|
93
|
+
tierConfigs[1].encodedIPFSUri = bytes32(uint256(0xBBBB));
|
|
94
|
+
tierConfigs[1].splitPercent = 0; // 0%
|
|
95
|
+
|
|
96
|
+
vm.prank(address(testHook));
|
|
97
|
+
uint256[] memory tierIds = hookStore.recordAddTiers(tierConfigs);
|
|
98
|
+
|
|
99
|
+
uint16[] memory mintIds = new uint16[](2);
|
|
100
|
+
mintIds[0] = uint16(tierIds[0]);
|
|
101
|
+
mintIds[1] = uint16(tierIds[1]);
|
|
102
|
+
bytes memory payerMetadata = _buildPayerMetadata(address(testHook), mintIds);
|
|
103
|
+
|
|
104
|
+
JBBeforePayRecordedContext memory context = JBBeforePayRecordedContext({
|
|
105
|
+
terminal: mockTerminalAddress,
|
|
106
|
+
payer: beneficiary,
|
|
107
|
+
amount: JBTokenAmount({
|
|
108
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
109
|
+
value: 4 ether,
|
|
110
|
+
decimals: 18,
|
|
111
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
112
|
+
}),
|
|
113
|
+
projectId: projectId,
|
|
114
|
+
rulesetId: 0,
|
|
115
|
+
beneficiary: beneficiary,
|
|
116
|
+
weight: 10e18,
|
|
117
|
+
reservedPercent: 5000,
|
|
118
|
+
metadata: payerMetadata
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
(, JBPayHookSpecification[] memory specs) = testHook.beforePayRecordedWith(context);
|
|
122
|
+
|
|
123
|
+
// Only tier A contributes: 1 ETH * 50% = 0.5 ETH
|
|
124
|
+
assertEq(specs[0].amount, 0.5 ether, "Only non-zero split tiers should contribute");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// @notice Verify that duplicate tier IDs in metadata produce correct cumulative split amounts.
|
|
128
|
+
/// The cached tier lookup must handle the same tier appearing multiple times.
|
|
129
|
+
function test_calculateSplitAmounts_duplicateTierIds() public {
|
|
130
|
+
ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
|
|
131
|
+
IJB721TiersHookStore hookStore = testHook.STORE();
|
|
132
|
+
|
|
133
|
+
// Single tier: 1 ETH, 30% split
|
|
134
|
+
JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
|
|
135
|
+
tierConfigs[0].price = 1 ether;
|
|
136
|
+
tierConfigs[0].initialSupply = uint32(100);
|
|
137
|
+
tierConfigs[0].category = uint24(1);
|
|
138
|
+
tierConfigs[0].encodedIPFSUri = bytes32(uint256(0xCCCC));
|
|
139
|
+
tierConfigs[0].splitPercent = 300_000_000; // 30%
|
|
140
|
+
|
|
141
|
+
vm.prank(address(testHook));
|
|
142
|
+
uint256[] memory tierIds = hookStore.recordAddTiers(tierConfigs);
|
|
143
|
+
|
|
144
|
+
// Request the same tier twice in metadata.
|
|
145
|
+
uint16[] memory mintIds = new uint16[](2);
|
|
146
|
+
mintIds[0] = uint16(tierIds[0]);
|
|
147
|
+
mintIds[1] = uint16(tierIds[0]);
|
|
148
|
+
bytes memory payerMetadata = _buildPayerMetadata(address(testHook), mintIds);
|
|
149
|
+
|
|
150
|
+
JBBeforePayRecordedContext memory context = JBBeforePayRecordedContext({
|
|
151
|
+
terminal: mockTerminalAddress,
|
|
152
|
+
payer: beneficiary,
|
|
153
|
+
amount: JBTokenAmount({
|
|
154
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
155
|
+
value: 2 ether,
|
|
156
|
+
decimals: 18,
|
|
157
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
158
|
+
}),
|
|
159
|
+
projectId: projectId,
|
|
160
|
+
rulesetId: 0,
|
|
161
|
+
beneficiary: beneficiary,
|
|
162
|
+
weight: 10e18,
|
|
163
|
+
reservedPercent: 5000,
|
|
164
|
+
metadata: payerMetadata
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
(, JBPayHookSpecification[] memory specs) = testHook.beforePayRecordedWith(context);
|
|
168
|
+
|
|
169
|
+
// 2 x (1 ETH * 30%) = 0.6 ETH
|
|
170
|
+
assertEq(specs[0].amount, 0.6 ether, "Duplicate tier IDs should each contribute their split amount");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Helper: build payer metadata for tier IDs.
|
|
174
|
+
function _buildPayerMetadata(
|
|
175
|
+
address hookAddress,
|
|
176
|
+
uint16[] memory tierIdsToMint
|
|
177
|
+
)
|
|
178
|
+
internal
|
|
179
|
+
view
|
|
180
|
+
returns (bytes memory)
|
|
181
|
+
{
|
|
182
|
+
bytes[] memory data = new bytes[](1);
|
|
183
|
+
data[0] = abi.encode(false, tierIdsToMint);
|
|
184
|
+
bytes4[] memory ids = new bytes4[](1);
|
|
185
|
+
ids[0] = metadataHelper.getId("pay", hookAddress);
|
|
186
|
+
return metadataHelper.createMetadata(ids, data);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.26;
|
|
3
|
+
|
|
4
|
+
import "../utils/UnitTestSetup.sol";
|
|
5
|
+
import {IJB721TiersHookStore} from "../../src/interfaces/IJB721TiersHookStore.sol";
|
|
6
|
+
import {JB721TiersHookLib} from "../../src/libraries/JB721TiersHookLib.sol";
|
|
7
|
+
import {JBSplit} from "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
8
|
+
import {IJBSplitHook} from "@bananapus/core-v6/src/interfaces/IJBSplitHook.sol";
|
|
9
|
+
import {IJBSplits} from "@bananapus/core-v6/src/interfaces/IJBSplits.sol";
|
|
10
|
+
import {IJBController} from "@bananapus/core-v6/src/interfaces/IJBController.sol";
|
|
11
|
+
import {IJBTerminal} from "@bananapus/core-v6/src/interfaces/IJBTerminal.sol";
|
|
12
|
+
|
|
13
|
+
/// @notice Regression test for L-36: Split with no beneficiary and no projectId should route funds to the project's
|
|
14
|
+
/// balance instead of silently dropping them.
|
|
15
|
+
contract Test_L36_SplitNoBeneficiary is UnitTestSetup {
|
|
16
|
+
using stdStorage for StdStorage;
|
|
17
|
+
|
|
18
|
+
address mockSplits = makeAddr("mockSplits");
|
|
19
|
+
address mockProjectTerminal = makeAddr("mockProjectTerminal");
|
|
20
|
+
|
|
21
|
+
function setUp() public override {
|
|
22
|
+
super.setUp();
|
|
23
|
+
vm.etch(mockSplits, new bytes(0x69));
|
|
24
|
+
vm.etch(mockProjectTerminal, new bytes(0x69));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// @notice Verify that a split with projectId==0 and beneficiary==address(0) routes funds to the project's
|
|
28
|
+
/// balance.
|
|
29
|
+
function test_splitWithNoBeneficiary_routesToProjectBalance() public {
|
|
30
|
+
ForTest_JB721TiersHook testHook = _initializeForTestHook(0);
|
|
31
|
+
IJB721TiersHookStore hookStore = testHook.STORE();
|
|
32
|
+
|
|
33
|
+
// Add a tier with 50% split.
|
|
34
|
+
JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
|
|
35
|
+
tierConfigs[0].price = 1 ether;
|
|
36
|
+
tierConfigs[0].initialSupply = uint32(100);
|
|
37
|
+
tierConfigs[0].category = uint24(1);
|
|
38
|
+
tierConfigs[0].encodedIPFSUri = bytes32(uint256(0x1234));
|
|
39
|
+
tierConfigs[0].splitPercent = 500_000_000; // 50%
|
|
40
|
+
|
|
41
|
+
vm.prank(address(testHook));
|
|
42
|
+
uint256[] memory tierIds = hookStore.recordAddTiers(tierConfigs);
|
|
43
|
+
|
|
44
|
+
// Mock directory checks.
|
|
45
|
+
mockAndExpect(
|
|
46
|
+
address(mockJBDirectory),
|
|
47
|
+
abi.encodeWithSelector(IJBDirectory.isTerminalOf.selector, projectId, mockTerminalAddress),
|
|
48
|
+
abi.encode(true)
|
|
49
|
+
);
|
|
50
|
+
mockAndExpect(
|
|
51
|
+
address(mockJBDirectory),
|
|
52
|
+
abi.encodeWithSelector(IJBDirectory.controllerOf.selector, projectId),
|
|
53
|
+
abi.encode(mockJBController)
|
|
54
|
+
);
|
|
55
|
+
mockAndExpect(mockJBController, abi.encodeWithSelector(IJBController.SPLITS.selector), abi.encode(mockSplits));
|
|
56
|
+
|
|
57
|
+
// Mock splits: a split with projectId==0 and beneficiary==address(0).
|
|
58
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
59
|
+
splits[0] = JBSplit({
|
|
60
|
+
percent: uint32(JBConstants.SPLITS_TOTAL_PERCENT),
|
|
61
|
+
projectId: 0,
|
|
62
|
+
beneficiary: payable(address(0)),
|
|
63
|
+
preferAddToBalance: false,
|
|
64
|
+
lockedUntil: 0,
|
|
65
|
+
hook: IJBSplitHook(address(0))
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
uint256 groupId = uint256(uint160(address(testHook))) | (uint256(tierIds[0]) << 160);
|
|
69
|
+
mockAndExpect(
|
|
70
|
+
mockSplits, abi.encodeWithSelector(IJBSplits.splitsOf.selector, projectId, 0, groupId), abi.encode(splits)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// Mock the project's primary terminal for addToBalanceOf (this is the fallback for no-recipient splits).
|
|
74
|
+
mockAndExpect(
|
|
75
|
+
address(mockJBDirectory),
|
|
76
|
+
abi.encodeWithSelector(IJBDirectory.primaryTerminalOf.selector, projectId, JBConstants.NATIVE_TOKEN),
|
|
77
|
+
abi.encode(mockProjectTerminal)
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Expect addToBalanceOf to be called on the project's terminal with the split amount (0.5 ether).
|
|
81
|
+
vm.expectCall(
|
|
82
|
+
mockProjectTerminal,
|
|
83
|
+
0.5 ether,
|
|
84
|
+
abi.encodeWithSelector(
|
|
85
|
+
IJBTerminal.addToBalanceOf.selector, projectId, JBConstants.NATIVE_TOKEN, 0.5 ether, false, "", ""
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
// Mock the addToBalanceOf call to succeed.
|
|
89
|
+
vm.mockCall(mockProjectTerminal, abi.encodeWithSelector(IJBTerminal.addToBalanceOf.selector), abi.encode());
|
|
90
|
+
|
|
91
|
+
// Build payer metadata.
|
|
92
|
+
uint16[] memory mintIds = new uint16[](1);
|
|
93
|
+
mintIds[0] = uint16(tierIds[0]);
|
|
94
|
+
bytes memory payerMetadata = _buildPayerMetadata(address(testHook), mintIds);
|
|
95
|
+
|
|
96
|
+
// Build hook metadata (per-tier split breakdown from beforePayRecordedWith).
|
|
97
|
+
uint16[] memory splitTierIds = new uint16[](1);
|
|
98
|
+
splitTierIds[0] = uint16(tierIds[0]);
|
|
99
|
+
uint256[] memory splitAmounts = new uint256[](1);
|
|
100
|
+
splitAmounts[0] = 0.5 ether;
|
|
101
|
+
|
|
102
|
+
JBAfterPayRecordedContext memory payContext = JBAfterPayRecordedContext({
|
|
103
|
+
payer: beneficiary,
|
|
104
|
+
projectId: projectId,
|
|
105
|
+
rulesetId: 0,
|
|
106
|
+
amount: JBTokenAmount({
|
|
107
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
108
|
+
value: 1 ether,
|
|
109
|
+
decimals: 18,
|
|
110
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
111
|
+
}),
|
|
112
|
+
forwardedAmount: JBTokenAmount({
|
|
113
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
114
|
+
value: 0.5 ether,
|
|
115
|
+
decimals: 18,
|
|
116
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
117
|
+
}),
|
|
118
|
+
weight: 10e18,
|
|
119
|
+
newlyIssuedTokenCount: 0,
|
|
120
|
+
beneficiary: beneficiary,
|
|
121
|
+
hookMetadata: abi.encode(splitTierIds, splitAmounts),
|
|
122
|
+
payerMetadata: payerMetadata
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
vm.deal(mockTerminalAddress, 1 ether);
|
|
126
|
+
vm.prank(mockTerminalAddress);
|
|
127
|
+
// Should NOT revert — funds should be routed to the project's balance.
|
|
128
|
+
testHook.afterPayRecordedWith{value: 0.5 ether}(payContext);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Helper: build payer metadata for tier IDs.
|
|
132
|
+
function _buildPayerMetadata(
|
|
133
|
+
address hookAddress,
|
|
134
|
+
uint16[] memory tierIdsToMint
|
|
135
|
+
)
|
|
136
|
+
internal
|
|
137
|
+
view
|
|
138
|
+
returns (bytes memory)
|
|
139
|
+
{
|
|
140
|
+
bytes[] memory data = new bytes[](1);
|
|
141
|
+
data[0] = abi.encode(false, tierIdsToMint);
|
|
142
|
+
bytes4[] memory ids = new bytes4[](1);
|
|
143
|
+
ids[0] = metadataHelper.getId("pay", hookAddress);
|
|
144
|
+
return metadataHelper.createMetadata(ids, data);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -4,7 +4,7 @@ pragma solidity 0.8.26;
|
|
|
4
4
|
import "../utils/UnitTestSetup.sol";
|
|
5
5
|
|
|
6
6
|
/// @title M6_TierSupplyCheck
|
|
7
|
-
/// @notice Tests
|
|
7
|
+
/// @notice Tests that the supply check accounts for pending reserves when minting paid NFTs.
|
|
8
8
|
/// Without the `1 +` in the supply check, the last available slot can be consumed by a paid mint, making
|
|
9
9
|
/// pending reserves unmintable (recordMintReservesFor reverts decrementing remainingSupply past zero).
|
|
10
10
|
contract M6_TierSupplyCheck is UnitTestSetup {
|