@bananapus/721-hook-v6 0.0.9 → 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 +3 -3
- package/SKILLS.md +7 -4
- package/docs/src/src/JB721TiersHookStore.sol/contract.JB721TiersHookStore.md +5 -5
- package/docs/src/src/structs/JB721InitTiersConfig.sol/struct.JB721InitTiersConfig.md +1 -1
- package/foundry.toml +1 -1
- package/package.json +4 -4
- package/src/JB721TiersHook.sol +25 -12
- package/src/JB721TiersHookDeployer.sol +2 -2
- package/src/JB721TiersHookProjectDeployer.sol +24 -20
- package/src/JB721TiersHookStore.sol +18 -18
- 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 +4 -0
- package/src/interfaces/IJB721TokenUriResolver.sol +1 -0
- package/src/structs/JB721InitTiersConfig.sol +1 -1
- package/src/structs/JB721TiersHookFlags.sol +3 -0
- package/test/E2E/Pay_Mint_Redeem_E2E.t.sol +2 -0
- package/test/regression/L34_ReserveBeneficiaryOverwrite.t.sol +1 -1
- package/test/regression/L35_CacheTierLookup.t.sol +2 -2
- package/test/regression/L36_SplitNoBeneficiary.t.sol +1 -1
- package/test/unit/adjustTier_Unit.t.sol +11 -0
- package/test/unit/getters_constructor_Unit.t.sol +2 -0
- package/test/unit/tierSplitRouting_Unit.t.sol +224 -2
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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/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.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@bananapus/address-registry-v6": "^0.0.4",
|
|
21
|
-
"@bananapus/core-v6": "^0.0.
|
|
22
|
-
"@bananapus/ownable-v6": "^0.0.
|
|
23
|
-
"@bananapus/permission-ids-v6": "^0.0.
|
|
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
|
@@ -22,13 +22,14 @@ 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";
|
|
27
|
+
import {JB721InitTiersConfig} from "./structs/JB721InitTiersConfig.sol";
|
|
26
28
|
import {JB721Tier} from "./structs/JB721Tier.sol";
|
|
27
29
|
import {JB721TierConfig} from "./structs/JB721TierConfig.sol";
|
|
28
|
-
import {JB721TiersSetDiscountPercentConfig} from "./structs/JB721TiersSetDiscountPercentConfig.sol";
|
|
29
|
-
import {JB721InitTiersConfig} from "./structs/JB721InitTiersConfig.sol";
|
|
30
30
|
import {JB721TiersHookFlags} from "./structs/JB721TiersHookFlags.sol";
|
|
31
31
|
import {JB721TiersMintReservesConfig} from "./structs/JB721TiersMintReservesConfig.sol";
|
|
32
|
+
import {JB721TiersSetDiscountPercentConfig} from "./structs/JB721TiersSetDiscountPercentConfig.sol";
|
|
32
33
|
|
|
33
34
|
/// @title JB721TiersHook
|
|
34
35
|
/// @notice A Juicebox project can use this hook to sell tiered ERC-721 NFTs with different prices and metadata. When
|
|
@@ -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
|
|
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
|
|
|
@@ -190,13 +203,6 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
|
|
|
190
203
|
return STORE.cashOutWeightOf({hook: address(this), tokenIds: tokenIds});
|
|
191
204
|
}
|
|
192
205
|
|
|
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
206
|
/// @notice Initializes a cloned copy of the original hook contract.
|
|
201
207
|
/// @param projectId The ID of the project this this hook is associated with.
|
|
202
208
|
/// @param name The name of the NFT collection.
|
|
@@ -262,13 +268,20 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
|
|
|
262
268
|
// Set the flags if needed.
|
|
263
269
|
if (
|
|
264
270
|
flags.noNewTiersWithReserves || flags.noNewTiersWithVotes || flags.noNewTiersWithOwnerMinting
|
|
265
|
-
|| flags.preventOverspending
|
|
271
|
+
|| flags.preventOverspending || flags.issueTokensForSplits
|
|
266
272
|
) STORE.recordFlags(flags);
|
|
267
273
|
|
|
268
274
|
// Transfer ownership to the initializer.
|
|
269
275
|
_transferOwnership(_msgSender());
|
|
270
276
|
}
|
|
271
277
|
|
|
278
|
+
/// @notice Indicates if this contract adheres to the specified interface.
|
|
279
|
+
/// @dev See {IERC165-supportsInterface}.
|
|
280
|
+
/// @param interfaceId The ID of the interface to check for adherence to.
|
|
281
|
+
function supportsInterface(bytes4 interfaceId) public view override(IERC165, JB721Hook) returns (bool) {
|
|
282
|
+
return interfaceId == type(IJB721TiersHook).interfaceId || JB721Hook.supportsInterface(interfaceId);
|
|
283
|
+
}
|
|
284
|
+
|
|
272
285
|
/// @notice The metadata URI of the NFT with the specified token ID.
|
|
273
286
|
/// @dev Defers to the `tokenUriResolver` if it is set. Otherwise, use the `tokenUri` corresponding with the NFT's
|
|
274
287
|
/// 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
|
}
|
|
@@ -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
|
|
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
|
|
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(
|
|
@@ -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.
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
@@ -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,7 +6,11 @@ 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
|
|
|
12
16
|
/// @notice Emitted when the default reserve beneficiary is changed.
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
95
|
-
assertEq(weight,
|
|
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
|
}
|