@croptop/core-v6 0.0.1

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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -0
  3. package/SKILLS.md +88 -0
  4. package/deployments/croptop-core-v5/arbitrum/CTDeployer.json +1896 -0
  5. package/deployments/croptop-core-v5/arbitrum/CTProjectOwner.json +186 -0
  6. package/deployments/croptop-core-v5/arbitrum/CTPublisher.json +738 -0
  7. package/deployments/croptop-core-v5/arbitrum_sepolia/CTDeployer.json +1883 -0
  8. package/deployments/croptop-core-v5/arbitrum_sepolia/CTProjectOwner.json +186 -0
  9. package/deployments/croptop-core-v5/arbitrum_sepolia/CTPublisher.json +738 -0
  10. package/deployments/croptop-core-v5/base/CTDeployer.json +1908 -0
  11. package/deployments/croptop-core-v5/base/CTProjectOwner.json +190 -0
  12. package/deployments/croptop-core-v5/base/CTPublisher.json +741 -0
  13. package/deployments/croptop-core-v5/base_sepolia/CTDeployer.json +1894 -0
  14. package/deployments/croptop-core-v5/base_sepolia/CTProjectOwner.json +190 -0
  15. package/deployments/croptop-core-v5/base_sepolia/CTPublisher.json +741 -0
  16. package/deployments/croptop-core-v5/ethereum/CTDeployer.json +1894 -0
  17. package/deployments/croptop-core-v5/ethereum/CTProjectOwner.json +190 -0
  18. package/deployments/croptop-core-v5/ethereum/CTPublisher.json +741 -0
  19. package/deployments/croptop-core-v5/optimism/CTDeployer.json +1894 -0
  20. package/deployments/croptop-core-v5/optimism/CTProjectOwner.json +190 -0
  21. package/deployments/croptop-core-v5/optimism/CTPublisher.json +741 -0
  22. package/deployments/croptop-core-v5/optimism_sepolia/CTDeployer.json +1894 -0
  23. package/deployments/croptop-core-v5/optimism_sepolia/CTProjectOwner.json +190 -0
  24. package/deployments/croptop-core-v5/optimism_sepolia/CTPublisher.json +741 -0
  25. package/deployments/croptop-core-v5/sepolia/CTDeployer.json +1894 -0
  26. package/deployments/croptop-core-v5/sepolia/CTProjectOwner.json +190 -0
  27. package/deployments/croptop-core-v5/sepolia/CTPublisher.json +741 -0
  28. package/foundry.toml +25 -0
  29. package/package.json +31 -0
  30. package/remappings.txt +2 -0
  31. package/script/ConfigureFeeProject.s.sol +386 -0
  32. package/script/Deploy.s.sol +138 -0
  33. package/script/helpers/CroptopDeploymentLib.sol +75 -0
  34. package/slither-ci.config.json +10 -0
  35. package/sphinx.lock +507 -0
  36. package/src/CTDeployer.sol +425 -0
  37. package/src/CTProjectOwner.sol +78 -0
  38. package/src/CTPublisher.sol +540 -0
  39. package/src/interfaces/ICTDeployer.sol +56 -0
  40. package/src/interfaces/ICTProjectOwner.sol +24 -0
  41. package/src/interfaces/ICTPublisher.sol +91 -0
  42. package/src/structs/CTAllowedPost.sol +22 -0
  43. package/src/structs/CTDeployerAllowedPost.sol +20 -0
  44. package/src/structs/CTPost.sol +22 -0
  45. package/src/structs/CTProjectConfig.sol +22 -0
  46. package/src/structs/CTSuckerDeploymentConfig.sol +11 -0
  47. package/test/CTPublisher.t.sol +672 -0
  48. package/test/CroptopAttacks.t.sol +439 -0
  49. package/test/Fork.t.sol +114 -0
  50. package/test/Test_MetadataGeneration.t.sol +70 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Croptop Publishing Network
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # croptop-core-v5
2
+
3
+ Permissioned NFT publishing for Juicebox projects -- anyone can post content as NFT tiers to a project's 721 hook, provided the posts meet criteria set by the project owner.
4
+
5
+ ## Architecture
6
+
7
+ | Contract | Description |
8
+ |----------|-------------|
9
+ | `CTPublisher` | Core publishing engine. Validates posts against owner-configured allowances (min price, supply bounds, address allowlists), creates new 721 tiers on the hook, mints the first copy to the poster, and routes a 5% fee to a designated fee project. |
10
+ | `CTDeployer` | One-click project factory. Deploys a Juicebox project with a 721 tiers hook pre-wired, configures posting criteria via `CTPublisher`, optionally deploys cross-chain suckers, and acts as a `IJBRulesetDataHook` proxy that forwards pay/cash-out calls to the underlying hook while granting fee-free cash outs to suckers. |
11
+ | `CTProjectOwner` | Burn-lock ownership helper. Receives a project's ERC-721 ownership token and automatically grants `CTPublisher` the `ADJUST_721_TIERS` permission, effectively making the project's tier configuration immutable except through Croptop posts. |
12
+
13
+ ### Structs
14
+
15
+ | Struct | Purpose |
16
+ |--------|---------|
17
+ | `CTAllowedPost` | Full posting criteria including hook address, category, price/supply bounds, and address allowlist. |
18
+ | `CTDeployerAllowedPost` | Same as `CTAllowedPost` but without the hook address (inferred during deployment). |
19
+ | `CTPost` | A post to publish: encoded IPFS URI, total supply, price, and category. |
20
+ | `CTProjectConfig` | Project deployment configuration: terminals, metadata URIs, allowed posts, collection name/symbol, and salt. |
21
+ | `CTSuckerDeploymentConfig` | Cross-chain sucker deployment: deployer configurations and deterministic salt. |
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ npm install @croptop/core-v5
27
+ ```
28
+
29
+ ## Develop
30
+
31
+ `croptop-core-v5` uses [npm](https://www.npmjs.com/) for package management and [Foundry](https://github.com/foundry-rs/foundry) for builds, tests, and deployments.
32
+
33
+ ```bash
34
+ curl -L https://foundry.paradigm.xyz | sh
35
+ npm install && forge install
36
+ ```
37
+
38
+ | Command | Description |
39
+ |---------|-------------|
40
+ | `forge build` | Compile contracts and write artifacts to `out`. |
41
+ | `forge test` | Run the test suite. |
42
+ | `forge fmt` | Lint Solidity files. |
43
+ | `forge build --sizes` | Get contract sizes. |
44
+ | `forge coverage` | Generate a test coverage report. |
45
+ | `forge clean` | Remove build artifacts and cache. |
package/SKILLS.md ADDED
@@ -0,0 +1,88 @@
1
+ # croptop-core-v5
2
+
3
+ ## Purpose
4
+
5
+ Permissioned NFT publishing system that lets anyone post content as 721 tiers to a Juicebox project, subject to owner-defined criteria for price, supply, and poster identity.
6
+
7
+ ## Contracts
8
+
9
+ | Contract | Role |
10
+ |----------|------|
11
+ | `CTPublisher` | Validates posts against allowances, creates 721 tiers, mints first copies, and routes fees. |
12
+ | `CTDeployer` | Factory that deploys a Juicebox project + 721 hook + posting criteria in one transaction. Also acts as a data hook proxy. |
13
+ | `CTProjectOwner` | Receives project ownership and grants the publisher tier-adjustment permissions permanently. |
14
+
15
+ ## Key Functions
16
+
17
+ | Function | Contract | What it does |
18
+ |----------|----------|--------------|
19
+ | `mintFrom` | `CTPublisher` | Publishes posts as new 721 tiers, mints first copies to `nftBeneficiary`, deducts a 5% fee (1/`FEE_DIVISOR`) routed to `FEE_PROJECT_ID`, and pays the remainder into the project terminal. |
20
+ | `configurePostingCriteriaFor` | `CTPublisher` | Sets per-category posting rules (min price, min/max supply, address allowlist) for a given hook. Requires `ADJUST_721_TIERS` permission from the hook owner. |
21
+ | `allowanceFor` | `CTPublisher` | Reads the packed allowance for a hook+category: minimum price (104 bits), min supply (32 bits), max supply (32 bits), plus the address allowlist. |
22
+ | `tiersFor` | `CTPublisher` | Resolves an array of encoded IPFS URIs to their corresponding `JB721Tier` structs via the stored `tierIdForEncodedIPFSUriOf` mapping. |
23
+ | `deployProjectFor` | `CTDeployer` | Deploys a new Juicebox project with a 721 tiers hook, configures posting criteria, optionally deploys suckers, and transfers project ownership to the specified owner. |
24
+ | `claimCollectionOwnershipOf` | `CTDeployer` | Transfers hook ownership to the project (via `JBOwnable.transferOwnershipToProject`). Only callable by the project owner. |
25
+ | `deploySuckersFor` | `CTDeployer` | Deploys new cross-chain suckers for an existing project. Requires `DEPLOY_SUCKERS` permission. |
26
+ | `beforePayRecordedWith` | `CTDeployer` | Data hook proxy: forwards pay context to the stored `dataHookOf[projectId]`. |
27
+ | `beforeCashOutRecordedWith` | `CTDeployer` | Data hook proxy: returns zero tax rate for sucker addresses (fee-free cross-chain cash outs), otherwise forwards to the stored data hook. |
28
+ | `onERC721Received` | `CTProjectOwner` | On receiving the project NFT, grants `CTPublisher` the `ADJUST_721_TIERS` permission for that project. |
29
+
30
+ ## Integration Points
31
+
32
+ | Dependency | Import | Used For |
33
+ |------------|--------|----------|
34
+ | `@bananapus/core-v6` | `IJBDirectory`, `IJBPermissions`, `IJBTerminal`, `IJBProjects`, `IJBController` | Project lookup, permission enforcement, payment routing, project creation. |
35
+ | `@bananapus/721-hook-v6` | `IJB721TiersHook`, `IJB721TiersHookDeployer`, `JB721TierConfig`, `JB721Tier` | Tier creation/adjustment, hook deployment, tier data resolution. |
36
+ | `@bananapus/ownable-v6` | `JBOwnable` | Ownership checks and transfers for hooks. |
37
+ | `@bananapus/suckers-v6` | `IJBSuckerRegistry`, `JBSuckerDeployerConfig` | Cross-chain sucker deployment and fee-free cash-out detection. |
38
+ | `@bananapus/permission-ids-v6` | `JBPermissionIds` | Permission ID constants (`ADJUST_721_TIERS`, `DEPLOY_SUCKERS`, `MAP_SUCKER_TOKEN`, etc.). |
39
+ | `@openzeppelin/contracts` | `ERC2771Context`, `IERC721Receiver` | Meta-transaction support, safe project NFT receipt. |
40
+
41
+ ## Key Types
42
+
43
+ | Struct/Enum | Key Fields | Used In |
44
+ |-------------|------------|---------|
45
+ | `CTAllowedPost` | `hook`, `category`, `minimumPrice` (uint104), `minimumTotalSupply` (uint32), `maximumTotalSupply` (uint32), `allowedAddresses` | `CTPublisher.configurePostingCriteriaFor` |
46
+ | `CTPost` | `encodedIPFSUri` (bytes32), `totalSupply` (uint32), `price` (uint104), `category` (uint24) | `CTPublisher.mintFrom` |
47
+ | `CTProjectConfig` | `terminalConfigurations`, `projectUri`, `allowedPosts`, `contractUri`, `name`, `symbol`, `salt` | `CTDeployer.deployProjectFor` |
48
+ | `CTDeployerAllowedPost` | `category`, `minimumPrice`, `minimumTotalSupply`, `maximumTotalSupply`, `allowedAddresses` | `CTProjectConfig.allowedPosts` |
49
+ | `CTSuckerDeploymentConfig` | `deployerConfigurations`, `salt` | `CTDeployer.deployProjectFor`, `CTDeployer.deploySuckersFor` |
50
+
51
+ ## Gotchas
52
+
53
+ - The `FEE_DIVISOR` is 20 (5% fee), not a percentage. Fee = `totalPrice / 20`. The fee is skipped when `projectId == FEE_PROJECT_ID`.
54
+ - Allowances are bit-packed into a single `uint256`: price in bits 0-103, min supply in 104-135, max supply in 136-167. Reading with wrong bit widths will silently return wrong values.
55
+ - `CTDeployer` owns the project NFT temporarily during deployment (to configure permissions and hooks) then transfers it to the specified `owner`. If the transfer reverts, the entire deployment fails.
56
+ - `CTDeployer.beforeCashOutRecordedWith` checks `SUCKER_REGISTRY.isSuckerOf` to grant fee-free cash outs. If the sucker registry is compromised, any address could cash out without tax.
57
+ - `CTProjectOwner.onERC721Received` only accepts tokens from `PROJECTS` and only from `address(0)` (mints). In `CTDeployer`, it accepts mints only. Sending a project NFT via transfer to `CTProjectOwner` works, but to `CTDeployer` it does not (reverts if `from != address(0)`).
58
+ - `_setupPosts` resizes `tiersToAdd` via inline assembly if some posts reuse existing tiers. The `tierIdsToMint` array is NOT resized and may contain zeros for pre-existing tiers that were already minted in prior calls.
59
+ - The `mintFrom` function sends `address(this).balance` as the fee payment after the main payment. If no ETH remains (e.g., exact payment), the fee transfer is skipped entirely.
60
+
61
+ ## Example Integration
62
+
63
+ ```solidity
64
+ import {ICTPublisher} from "@croptop/core-v6/src/interfaces/ICTPublisher.sol";
65
+ import {CTPost} from "@croptop/core-v6/src/structs/CTPost.sol";
66
+ import {IJB721TiersHook} from "@bananapus/721-hook-v6/src/interfaces/IJB721TiersHook.sol";
67
+
68
+ // Mint a post from a Croptop-enabled project
69
+ CTPost[] memory posts = new CTPost[](1);
70
+ posts[0] = CTPost({
71
+ encodedIPFSUri: 0x1234..., // encoded IPFS CID
72
+ totalSupply: 100,
73
+ price: 0.01 ether,
74
+ category: 1
75
+ });
76
+
77
+ // Price + 5% fee
78
+ uint256 totalCost = 0.01 ether + (0.01 ether / 20);
79
+
80
+ publisher.mintFrom{value: totalCost}(
81
+ IJB721TiersHook(hookAddress),
82
+ posts,
83
+ msg.sender, // NFT beneficiary
84
+ msg.sender, // fee beneficiary
85
+ "", // additional pay metadata
86
+ "" // fee metadata
87
+ );
88
+ ```