@bananapus/distributor-v6 0.0.3
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/.github/pull_request_template.md +33 -0
- package/.github/workflows/lint.yml +19 -0
- package/.github/workflows/publish.yml +19 -0
- package/.github/workflows/slither.yml +23 -0
- package/.github/workflows/test.yml +26 -0
- package/.gitmodules +3 -0
- package/ADMINISTRATION.md +65 -0
- package/ARCHITECTURE.md +89 -0
- package/AUDIT_INSTRUCTIONS.md +52 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/RISKS.md +78 -0
- package/SKILLS.md +36 -0
- package/USER_JOURNEYS.md +120 -0
- package/foundry.toml +22 -0
- package/package.json +29 -0
- package/references/operations.md +25 -0
- package/references/runtime.md +36 -0
- package/remappings.txt +1 -0
- package/script/Deploy.s.sol +23 -0
- package/slither-ci.config.json +10 -0
- package/src/JB721Distributor.sol +180 -0
- package/src/JBDistributor.sol +563 -0
- package/src/JBTokenDistributor.sol +160 -0
- package/src/interfaces/IJB721Distributor.sol +15 -0
- package/src/interfaces/IJBDistributor.sol +138 -0
- package/src/interfaces/IJBTokenDistributor.sol +16 -0
- package/src/structs/JBTokenSnapshotData.sol +9 -0
- package/src/structs/JBVestingData.sol +11 -0
- package/test/JB721Distributor.t.sol +1985 -0
- package/test/JBTokenDistributor.t.sol +424 -0
- package/test/invariant/JB721DistributorInvariant.t.sol +410 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Description
|
|
2
|
+
|
|
3
|
+
What does this PR do, how, and why?
|
|
4
|
+
|
|
5
|
+
## Risk Surface
|
|
6
|
+
|
|
7
|
+
What new trust boundary, failure mode, operational dependency, or integration caveat does this PR introduce or remove?
|
|
8
|
+
|
|
9
|
+
## RISKS.md Impact
|
|
10
|
+
|
|
11
|
+
- [ ] No runtime, admin, deployment, or integration risk surface changed
|
|
12
|
+
- [ ] Updated this repo's `RISKS.md`
|
|
13
|
+
- [ ] Updated `/v6/evm/RISKS.md` because ecosystem behavior changed
|
|
14
|
+
- [ ] If no `RISKS.md` update was needed, I explained why in this PR
|
|
15
|
+
|
|
16
|
+
Reference: [`/v6/evm/docs/RISKS_MAINTENANCE.md`](../docs/RISKS_MAINTENANCE.md)
|
|
17
|
+
|
|
18
|
+
## Checklist
|
|
19
|
+
|
|
20
|
+
- [ ] Tests cover the behavior change
|
|
21
|
+
- [ ] Code is natspec'd where needed
|
|
22
|
+
- [ ] Code is linted and formatted
|
|
23
|
+
- [ ] I ran the relevant tests locally
|
|
24
|
+
- [ ] I checked for stale docs and updated them where needed
|
|
25
|
+
- [ ] `STYLE_GUIDE.md` is adhered to — no lint errors, warnings, or notes
|
|
26
|
+
- [ ] No build errors, warnings, or notes
|
|
27
|
+
|
|
28
|
+
## Interactions
|
|
29
|
+
|
|
30
|
+
These changes impact the following contracts or docs:
|
|
31
|
+
|
|
32
|
+
- Directly:
|
|
33
|
+
- Indirectly:
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: lint
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
push:
|
|
7
|
+
branches:
|
|
8
|
+
- main
|
|
9
|
+
jobs:
|
|
10
|
+
forge-test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
with:
|
|
15
|
+
submodules: recursive
|
|
16
|
+
- name: Install Foundry
|
|
17
|
+
uses: foundry-rs/foundry-toolchain@v1
|
|
18
|
+
- name: Check linting
|
|
19
|
+
run: forge fmt --check
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
jobs:
|
|
7
|
+
publish:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v4
|
|
11
|
+
- uses: actions/setup-node@v4
|
|
12
|
+
with:
|
|
13
|
+
node-version: 22.4.x
|
|
14
|
+
registry-url: https://registry.npmjs.org
|
|
15
|
+
# This will fail if the version in package.json has not increased.
|
|
16
|
+
- name: Publish to npm
|
|
17
|
+
run: npm publish --access public
|
|
18
|
+
env:
|
|
19
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: slither
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
branches: [main]
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
jobs:
|
|
8
|
+
slither:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
with:
|
|
13
|
+
submodules: recursive
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: 22.4.x
|
|
17
|
+
- name: Install npm dependencies
|
|
18
|
+
run: npm install --omit=dev
|
|
19
|
+
- name: Run Slither
|
|
20
|
+
uses: crytic/slither-action@v0.3.1
|
|
21
|
+
with:
|
|
22
|
+
slither-config: slither-ci.config.json
|
|
23
|
+
fail-on: medium
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: test
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
push:
|
|
7
|
+
branches:
|
|
8
|
+
- main
|
|
9
|
+
jobs:
|
|
10
|
+
forge-test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
with:
|
|
15
|
+
submodules: recursive
|
|
16
|
+
- uses: actions/setup-node@v4
|
|
17
|
+
with:
|
|
18
|
+
node-version: 22.4.x
|
|
19
|
+
- name: Install npm dependencies
|
|
20
|
+
run: npm install --omit=dev
|
|
21
|
+
- name: Install Foundry
|
|
22
|
+
uses: foundry-rs/foundry-toolchain@v1
|
|
23
|
+
- name: Run tests
|
|
24
|
+
run: forge test --fail-fast --summary --detailed --skip "*/script/**"
|
|
25
|
+
- name: Check contract sizes
|
|
26
|
+
run: forge build --sizes --skip "*/test/**" --skip "*/script/**" --skip SphinxUtils
|
package/.gitmodules
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Administration
|
|
2
|
+
|
|
3
|
+
## At A Glance
|
|
4
|
+
|
|
5
|
+
| Item | Details |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| Scope | Round-based vesting and distribution configuration |
|
|
8
|
+
| Control posture | Mostly parameter- and caller-driven, with asset-specific authority checks |
|
|
9
|
+
| Highest-risk actions | Bad deployment parameters, wrong funding assumptions, and stale snapshot timing |
|
|
10
|
+
| Recovery posture | Some value can remain for future rounds, but bad parameters can brick an instance |
|
|
11
|
+
|
|
12
|
+
## Purpose
|
|
13
|
+
|
|
14
|
+
`nana-distributor-v6` has less admin complexity than many sibling repos, but deployment parameters and funding assumptions still create real control risk.
|
|
15
|
+
|
|
16
|
+
## Control Model
|
|
17
|
+
|
|
18
|
+
- vesting is mostly driven by deployment parameters and permissionless round starts
|
|
19
|
+
- claim authority differs by distributor type
|
|
20
|
+
- 721 forfeiture handling adds a separate recovery path not present in the token distributor
|
|
21
|
+
|
|
22
|
+
## Roles
|
|
23
|
+
|
|
24
|
+
| Role | How Assigned | Scope | Notes |
|
|
25
|
+
| --- | --- | --- | --- |
|
|
26
|
+
| Round starter | Any caller | Per distributor | Vesting is permissionless |
|
|
27
|
+
| Token claimant | Encoded claimant address | Per token slot | Token distributor authority model |
|
|
28
|
+
| NFT claimant | Current NFT owner | Per token ID | 721 distributor authority model |
|
|
29
|
+
|
|
30
|
+
## Privileged Surfaces
|
|
31
|
+
|
|
32
|
+
- deployment parameters
|
|
33
|
+
- funding flows
|
|
34
|
+
- claim entrypoints with distributor-specific authority checks
|
|
35
|
+
- 721 forfeiture release path
|
|
36
|
+
|
|
37
|
+
## Immutable And One-Way
|
|
38
|
+
|
|
39
|
+
- bad constructor parameters can permanently make an instance unusable
|
|
40
|
+
- snapshots define a round once taken
|
|
41
|
+
- vested or collected value does not rewind
|
|
42
|
+
|
|
43
|
+
## Operational Notes
|
|
44
|
+
|
|
45
|
+
- review round timing and vesting-round count before deployment
|
|
46
|
+
- verify the distributor holds the correct asset before starting rounds
|
|
47
|
+
- do not assume token and 721 variants behave identically
|
|
48
|
+
|
|
49
|
+
## Recovery
|
|
50
|
+
|
|
51
|
+
- unclaimed value can remain for future rounds
|
|
52
|
+
- 721 forfeiture release can recycle some value
|
|
53
|
+
- bad deployment parameters usually require a new distributor instance
|
|
54
|
+
|
|
55
|
+
## Admin Boundaries
|
|
56
|
+
|
|
57
|
+
- this repo does not create upstream entitlement logic
|
|
58
|
+
- permissionless vesting means operators do not fully control snapshot timing
|
|
59
|
+
- the distributor cannot make a missing or wrong stake source correct
|
|
60
|
+
|
|
61
|
+
## Source Map
|
|
62
|
+
|
|
63
|
+
- `src/JBDistributor.sol`
|
|
64
|
+
- `src/JBTokenDistributor.sol`
|
|
65
|
+
- `src/JB721Distributor.sol`
|
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
`nana-distributor-v6` provides round-based vesting and claiming for already-owned assets. It supports both `IVotes`-based ERC-20 distributions and 721-based distributions without becoming a treasury or accounting layer.
|
|
6
|
+
|
|
7
|
+
## System Overview
|
|
8
|
+
|
|
9
|
+
`JBDistributor` is the shared vesting engine. `JBTokenDistributor` changes stake measurement to checkpointed voting power. `JB721Distributor` changes stake measurement to checkpointed voting power from the hook's `CHECKPOINTS()` module, ensuring only NFTs held at round start are eligible.
|
|
10
|
+
|
|
11
|
+
Both variants can be used as `IJBSplitHook` receivers.
|
|
12
|
+
|
|
13
|
+
## Core Invariants
|
|
14
|
+
|
|
15
|
+
- snapshot timing must stay coherent
|
|
16
|
+
- tracked funded balance must cover current vesting obligations
|
|
17
|
+
- claim authority must match the distributor type
|
|
18
|
+
- 721 forfeiture handling must not over-allocate or burn value accidentally
|
|
19
|
+
- token and 721 variants must preserve the same core vesting math
|
|
20
|
+
|
|
21
|
+
## Modules
|
|
22
|
+
|
|
23
|
+
| Module | Responsibility | Notes |
|
|
24
|
+
| --- | --- | --- |
|
|
25
|
+
| `JBDistributor` | Shared rounds, vesting, snapshots, and claims | Economic core |
|
|
26
|
+
| `JBTokenDistributor` | ERC-20 distribution using `IVotes` checkpoints | Token stake source |
|
|
27
|
+
| `JB721Distributor` | NFT distribution using checkpointed voting power | 721 stake source |
|
|
28
|
+
|
|
29
|
+
## Trust Boundaries
|
|
30
|
+
|
|
31
|
+
- split-hook caller authentication depends on `JBDirectory`
|
|
32
|
+
- `JBTokenDistributor` trusts `IVotes` checkpoint history
|
|
33
|
+
- `JB721Distributor` trusts the 721 hook's `CHECKPOINTS()` module for historical voting power and the store for tier metadata
|
|
34
|
+
- upstream entitlement logic still lives outside this repo
|
|
35
|
+
|
|
36
|
+
## Critical Flows
|
|
37
|
+
|
|
38
|
+
### Begin Vesting
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
funded distributor
|
|
42
|
+
-> begin a round
|
|
43
|
+
-> snapshot stake and tracked balance for that round
|
|
44
|
+
-> record vesting entries for the requested token IDs
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Collect
|
|
48
|
+
|
|
49
|
+
```text
|
|
50
|
+
claimant
|
|
51
|
+
-> prove authority for the token ID or encoded claimant slot
|
|
52
|
+
-> compute unlocked share
|
|
53
|
+
-> transfer the vested amount
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Accounting Model
|
|
57
|
+
|
|
58
|
+
This repo owns vesting-round accounting. It does not own upstream treasury accounting or entitlement creation.
|
|
59
|
+
|
|
60
|
+
The main variables are snapshot balance, total vesting amount, and the stake source used to split each round.
|
|
61
|
+
|
|
62
|
+
## Security Model
|
|
63
|
+
|
|
64
|
+
- wrong snapshots can misallocate a whole round
|
|
65
|
+
- bad constructor parameters can brick a distributor instance
|
|
66
|
+
- split-funding caller assumptions matter because `processSplitWith` distinguishes pull and pre-sent flows
|
|
67
|
+
- 721 and token variants intentionally differ in authority and forfeiture behavior
|
|
68
|
+
|
|
69
|
+
## Safe Change Guide
|
|
70
|
+
|
|
71
|
+
- review snapshot timing and vesting math together
|
|
72
|
+
- if claim authority changes, re-check both distributor variants separately
|
|
73
|
+
- if funding semantics change, test terminal-style and controller-style flows explicitly
|
|
74
|
+
|
|
75
|
+
## Canonical Checks
|
|
76
|
+
|
|
77
|
+
- token distribution behavior:
|
|
78
|
+
`test/JBTokenDistributor.t.sol`
|
|
79
|
+
- 721 distribution behavior:
|
|
80
|
+
`test/JB721Distributor.t.sol`
|
|
81
|
+
- 721 invariants:
|
|
82
|
+
`test/invariant/JB721DistributorInvariant.t.sol`
|
|
83
|
+
|
|
84
|
+
## Source Map
|
|
85
|
+
|
|
86
|
+
- `src/JBDistributor.sol`
|
|
87
|
+
- `src/JBTokenDistributor.sol`
|
|
88
|
+
- `src/JB721Distributor.sol`
|
|
89
|
+
- `src/interfaces/IJBDistributor.sol`
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Audit Instructions
|
|
2
|
+
|
|
3
|
+
This repo is a shared vesting engine plus two concrete distributor variants. Audit it as payout logic whose main risks are snapshot timing, stake measurement, and funding assumptions.
|
|
4
|
+
|
|
5
|
+
## Audit Objective
|
|
6
|
+
|
|
7
|
+
Find issues that:
|
|
8
|
+
|
|
9
|
+
- misallocate rewards because the snapshot or stake source is wrong
|
|
10
|
+
- break vesting or claiming because parameters are invalid
|
|
11
|
+
- let caller or claim authority drift from the intended model
|
|
12
|
+
- make split-funding assumptions unsafe
|
|
13
|
+
|
|
14
|
+
## Scope
|
|
15
|
+
|
|
16
|
+
In scope:
|
|
17
|
+
|
|
18
|
+
- `src/JBDistributor.sol`
|
|
19
|
+
- `src/JBTokenDistributor.sol`
|
|
20
|
+
- `src/JB721Distributor.sol`
|
|
21
|
+
- interfaces and structs under `src/`
|
|
22
|
+
|
|
23
|
+
## Start Here
|
|
24
|
+
|
|
25
|
+
1. `src/JBDistributor.sol`
|
|
26
|
+
2. `src/JBTokenDistributor.sol`
|
|
27
|
+
3. `src/JB721Distributor.sol`
|
|
28
|
+
|
|
29
|
+
## Security Model
|
|
30
|
+
|
|
31
|
+
The shared distributor:
|
|
32
|
+
|
|
33
|
+
- snapshots balance and stake for a round
|
|
34
|
+
- tracks vesting obligations
|
|
35
|
+
- lets authorized claimants collect what has unlocked
|
|
36
|
+
|
|
37
|
+
The concrete variants only change how stake and claimant authority are measured.
|
|
38
|
+
|
|
39
|
+
## Critical Invariants
|
|
40
|
+
|
|
41
|
+
1. Snapshot and stake source stay coherent.
|
|
42
|
+
A round should not allocate more or less than the chosen stake source supports.
|
|
43
|
+
2. Tracked balance covers vesting obligations.
|
|
44
|
+
Current and future vesting must reconcile with funded inventory.
|
|
45
|
+
3. Claim authority matches distributor type.
|
|
46
|
+
The token and 721 variants must enforce their distinct authority models correctly.
|
|
47
|
+
|
|
48
|
+
## Verification
|
|
49
|
+
|
|
50
|
+
- `npm install`
|
|
51
|
+
- `forge build`
|
|
52
|
+
- `forge test`
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.0.1
|
|
4
|
+
|
|
5
|
+
Initial release of the Juicebox V6 distributor system.
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- **JBDistributor**: Abstract base contract with round-based distribution and configurable linear vesting.
|
|
10
|
+
- **JBTokenDistributor**: Singleton distributor for IVotes-compatible ERC-20 tokens. Stake weight = delegated voting power at round start.
|
|
11
|
+
- **JB721Distributor**: Singleton distributor for JB 721 NFT holders. Stake weight = tier's `votingUnits`. Burned NFTs excluded from stake; forfeited rewards reclaimable.
|
|
12
|
+
- Both implement `IJBSplitHook` for direct integration with Juicebox payout splits.
|
|
13
|
+
- Linear vesting over configurable number of rounds.
|
|
14
|
+
- Fee-on-transfer token support via balance-delta pattern.
|
|
15
|
+
- Native ETH distribution support.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Bananapus
|
|
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,117 @@
|
|
|
1
|
+
# Juicebox Distributor
|
|
2
|
+
|
|
3
|
+
`@bananapus/distributor-v6` distributes ERC-20 balances or 721 token inventories to many recipients under round-based vesting rules. It is a payout utility package for Juicebox-adjacent flows, not a protocol accounting layer.
|
|
4
|
+
|
|
5
|
+
Architecture: [ARCHITECTURE.md](./ARCHITECTURE.md)
|
|
6
|
+
User journeys: [USER_JOURNEYS.md](./USER_JOURNEYS.md)
|
|
7
|
+
Skills: [SKILLS.md](./SKILLS.md)
|
|
8
|
+
Risks: [RISKS.md](./RISKS.md)
|
|
9
|
+
Administration: [ADMINISTRATION.md](./ADMINISTRATION.md)
|
|
10
|
+
Audit instructions: [AUDIT_INSTRUCTIONS.md](./AUDIT_INSTRUCTIONS.md)
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
This repo provides reusable distributors for teams that need deterministic post-funding or post-mint distribution.
|
|
15
|
+
|
|
16
|
+
The package separates distribution mechanics by asset type:
|
|
17
|
+
|
|
18
|
+
- `JBDistributor` coordinates shared round and vesting logic
|
|
19
|
+
- `JBTokenDistributor` distributes ERC-20 balances using `IVotes` checkpointed voting power
|
|
20
|
+
- `JB721Distributor` distributes value to 721 holders using checkpointed voting power, ensuring only holders at round start are eligible
|
|
21
|
+
|
|
22
|
+
Both concrete distributors implement `IJBSplitHook`, which makes them usable directly from Juicebox payout splits.
|
|
23
|
+
|
|
24
|
+
Use this repo when the problem is "how do we distribute already-owned assets over time?" Do not use it when the problem is project accounting, treasury settlement, or terminal execution.
|
|
25
|
+
|
|
26
|
+
If the issue is "where did the project's value come from?" start in `nana-core-v6`, `nana-721-hook-v6`, or the upstream repo that minted or received the assets first.
|
|
27
|
+
|
|
28
|
+
## Key Contracts
|
|
29
|
+
|
|
30
|
+
| Contract | Role |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| `JBDistributor` | Shared round-based vesting, claiming, and accounting logic. |
|
|
33
|
+
| `JBTokenDistributor` | ERC-20 distributor keyed to `IVotes` checkpointed voting power. |
|
|
34
|
+
| `JB721Distributor` | NFT-aware distributor keyed to checkpointed voting power from the hook's `CHECKPOINTS()` module. Only NFTs held at round start are eligible. |
|
|
35
|
+
|
|
36
|
+
## Mental Model
|
|
37
|
+
|
|
38
|
+
1. a project funds the distributor, often through a payout split
|
|
39
|
+
2. a vesting round begins and snapshots the eligible stake state
|
|
40
|
+
3. recipients collect their pro-rata share as that round vests
|
|
41
|
+
4. some unclaimable value can be reclaimed through explicit recovery paths, depending on the distributor type
|
|
42
|
+
|
|
43
|
+
This repo does not explain why an allocation exists. It only defines how funded inventory is handed out.
|
|
44
|
+
|
|
45
|
+
## Read These Files First
|
|
46
|
+
|
|
47
|
+
1. `src/interfaces/IJBDistributor.sol`
|
|
48
|
+
2. `src/JBDistributor.sol`
|
|
49
|
+
3. `src/JBTokenDistributor.sol`
|
|
50
|
+
4. `src/JB721Distributor.sol`
|
|
51
|
+
|
|
52
|
+
## Integration Traps
|
|
53
|
+
|
|
54
|
+
- distribution correctness depends on the distributor actually holding the assets it is expected to vest
|
|
55
|
+
- ERC-20 and ERC-721 distributions share a mental model, but their edge cases are different
|
|
56
|
+
- `releaseForfeitedRewards` matters for 721 distributions; token-vote distributions do not have the same burned-token path
|
|
57
|
+
- snapshot timing is part of the trusted surface
|
|
58
|
+
- this repo settles distributions, but it does not prove the upstream entitlement math was correct
|
|
59
|
+
|
|
60
|
+
## Where State Lives
|
|
61
|
+
|
|
62
|
+
- round and vesting state: `JBDistributor`
|
|
63
|
+
- token snapshot inputs: `JBTokenSnapshotData`
|
|
64
|
+
- vesting schedule state: `JBVestingData`
|
|
65
|
+
- asset-specific claim behavior: the concrete distributor
|
|
66
|
+
|
|
67
|
+
## High-Signal Tests
|
|
68
|
+
|
|
69
|
+
1. `test/JBTokenDistributor.t.sol`
|
|
70
|
+
2. `test/JB721Distributor.t.sol`
|
|
71
|
+
3. `test/invariant/JB721DistributorInvariant.t.sol`
|
|
72
|
+
|
|
73
|
+
## Install
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm install @bananapus/distributor-v6
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Development
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm install
|
|
83
|
+
forge build
|
|
84
|
+
forge test
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Useful scripts:
|
|
88
|
+
|
|
89
|
+
- `npm run test:fork`
|
|
90
|
+
- `npm run deploy:mainnets`
|
|
91
|
+
- `npm run deploy:testnets`
|
|
92
|
+
|
|
93
|
+
## Repository Layout
|
|
94
|
+
|
|
95
|
+
```text
|
|
96
|
+
src/
|
|
97
|
+
JBDistributor.sol
|
|
98
|
+
JBTokenDistributor.sol
|
|
99
|
+
JB721Distributor.sol
|
|
100
|
+
interfaces/
|
|
101
|
+
structs/
|
|
102
|
+
test/
|
|
103
|
+
token, 721, and invariant coverage
|
|
104
|
+
script/
|
|
105
|
+
Deploy.s.sol
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Risks And Notes
|
|
109
|
+
|
|
110
|
+
- distributors are only as trustworthy as the vesting parameters and funding they receive
|
|
111
|
+
- operational mistakes often come from funding the wrong asset or underfunding the distributor
|
|
112
|
+
- teams should review claim timing and snapshot assumptions with the same care they review the payout source
|
|
113
|
+
|
|
114
|
+
## For AI Agents
|
|
115
|
+
|
|
116
|
+
- Treat this repo as distribution plumbing, not as the source of upstream entitlement math.
|
|
117
|
+
- Read both the ERC-20 and ERC-721 tests before claiming the flows are equivalent.
|
package/RISKS.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Distributor Risk Register
|
|
2
|
+
|
|
3
|
+
This file covers the shared vesting engine in `JBDistributor` and the two concrete payout-split receivers, `JB721Distributor` and `JBTokenDistributor`.
|
|
4
|
+
|
|
5
|
+
## How To Use This File
|
|
6
|
+
|
|
7
|
+
- Read `Priority risks` first. Those are the failure modes with the highest payout-integrity impact.
|
|
8
|
+
- Treat the shared `JBDistributor` logic as the economic core.
|
|
9
|
+
- Use `Invariants to verify` as the minimum test envelope before routing live splits through a distributor.
|
|
10
|
+
|
|
11
|
+
## Priority Risks
|
|
12
|
+
|
|
13
|
+
| Priority | Risk | Why it matters | Primary controls |
|
|
14
|
+
|----------|------|----------------|------------------|
|
|
15
|
+
| P0 | Wrong stake snapshot or stale stake source | A bad stake reading misallocates rewards for an entire round. | Snapshot review, invariants, and careful integration with the chosen hook or `IVotes` token. |
|
|
16
|
+
| P1 | Zero-stake or bad-parameter deployment | Bad constructor inputs or zero total stake can make core flows revert. | Deployment-time validation and operator runbooks. |
|
|
17
|
+
| P1 | Split funding trust mismatch | `processSplitWith` distinguishes terminal-style pull flows from controller-style pre-sent flows. | Restrict callers and test both paths. |
|
|
18
|
+
|
|
19
|
+
## 1. Trust Assumptions
|
|
20
|
+
|
|
21
|
+
- **`JBDirectory` is trusted.**
|
|
22
|
+
- **Stake sources are trusted.**
|
|
23
|
+
- **Deployment parameters must be sane.**
|
|
24
|
+
|
|
25
|
+
## 2. Economic Risks
|
|
26
|
+
|
|
27
|
+
- **Round snapshot timing has a zero-balance edge case.**
|
|
28
|
+
- **Unclaimed value stays in the pool.**
|
|
29
|
+
- **Partial-round claims are linear, not cliff-based.**
|
|
30
|
+
- **Forfeited 721 rewards are recycled, not burned.**
|
|
31
|
+
- **Undelegated `IVotes` balances can dilute participation.**
|
|
32
|
+
|
|
33
|
+
## 3. Access Control And Caller Risks
|
|
34
|
+
|
|
35
|
+
- **Vesting is permissionless.**
|
|
36
|
+
- **Claim authority differs by distributor type.**
|
|
37
|
+
- **721 claim batches are brittle to invalid token IDs.**
|
|
38
|
+
- **Forfeiture release is effectively 721-only.**
|
|
39
|
+
- **Split-hook entry is tightly gated.**
|
|
40
|
+
|
|
41
|
+
## 4. DoS And Liveness Risks
|
|
42
|
+
|
|
43
|
+
- **Zero stake reverts vesting.**
|
|
44
|
+
- **Zero distributable balance reverts vesting.** The `beginVesting` call reverts with `JBDistributor_NothingToDistribute` if the distributable balance for a token is zero.
|
|
45
|
+
- **Bad constructor parameters can brick the instance.**
|
|
46
|
+
- **Resolver or token callback failures can block collection.**
|
|
47
|
+
|
|
48
|
+
## 5. Integration Risks
|
|
49
|
+
|
|
50
|
+
- **Controller-vs-terminal split funding heuristic matters.**
|
|
51
|
+
- **Fee-on-transfer handling uses balance-delta accounting.** Both terminal-pull and controller-pre-send paths measure `balanceAfter - balanceBefore` to credit the actual received amount.
|
|
52
|
+
- **721 stake weights depend on checkpointed voting power at round start.** The `CHECKPOINTS()` module must be deployed and delegates must be set before the round snapshot block, or stakers receive zero weight.
|
|
53
|
+
- **721 vesting and claiming treat burned tokens differently.**
|
|
54
|
+
- **Checkpoint availability matters for both `IVotes` token distributors and 721 distributors.**
|
|
55
|
+
- **Token distributor rejects token IDs with non-zero upper bits** (above 160) to prevent aliasing to the same staker address.
|
|
56
|
+
|
|
57
|
+
## 6. Invariants To Verify
|
|
58
|
+
|
|
59
|
+
- `totalVestingAmountOf <= _balanceOf`
|
|
60
|
+
- collections plus remaining vesting plus future distributable balance never exceed tracked funded balance
|
|
61
|
+
- non-zero round snapshots stay stable within a round
|
|
62
|
+
- `latestVestedIndexOf` advances contiguously
|
|
63
|
+
- burned NFTs are excluded from 721 stake (via zero checkpointed votes) and only recycled through the explicit forfeiture path
|
|
64
|
+
- only the encoded address can collect from the token distributor
|
|
65
|
+
|
|
66
|
+
## 7. Accepted Behaviors
|
|
67
|
+
|
|
68
|
+
### 7.1 Anyone can trigger a round snapshot
|
|
69
|
+
|
|
70
|
+
This improves liveness, but it also means operators do not fully control the exact block when a round is crystallized.
|
|
71
|
+
|
|
72
|
+
### 7.2 Rewards can remain undistributed when stake is missing
|
|
73
|
+
|
|
74
|
+
If some potential participants have zero effective stake for a round, the corresponding value stays in the distributor for future rounds.
|
|
75
|
+
|
|
76
|
+
### 7.3 721 and `IVotes` variants intentionally differ
|
|
77
|
+
|
|
78
|
+
They share the vesting engine but not the same ownership model.
|
package/SKILLS.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Juicebox Distributor
|
|
2
|
+
|
|
3
|
+
## Use This File For
|
|
4
|
+
|
|
5
|
+
- Use this file when the task involves round-based vesting, split-hook distribution, or snapshot-based payout allocation.
|
|
6
|
+
- Start here, then decide whether the issue is in shared vesting logic, `IVotes`-based stake measurement, or 721-based stake measurement.
|
|
7
|
+
|
|
8
|
+
## Read This Next
|
|
9
|
+
|
|
10
|
+
| If you need... | Open this next |
|
|
11
|
+
|---|---|
|
|
12
|
+
| Repo overview and architecture | [`README.md`](./README.md), [`ARCHITECTURE.md`](./ARCHITECTURE.md) |
|
|
13
|
+
| Shared vesting engine | [`src/JBDistributor.sol`](./src/JBDistributor.sol), [`src/interfaces/IJBDistributor.sol`](./src/interfaces/IJBDistributor.sol) |
|
|
14
|
+
| Token distributor behavior | [`src/JBTokenDistributor.sol`](./src/JBTokenDistributor.sol) |
|
|
15
|
+
| 721 distributor behavior | [`src/JB721Distributor.sol`](./src/JB721Distributor.sol) |
|
|
16
|
+
| Types and structs | [`src/structs/`](./src/structs/) |
|
|
17
|
+
| Main tests | [`test/JBTokenDistributor.t.sol`](./test/JBTokenDistributor.t.sol), [`test/JB721Distributor.t.sol`](./test/JB721Distributor.t.sol), [`test/invariant/JB721DistributorInvariant.t.sol`](./test/invariant/JB721DistributorInvariant.t.sol) |
|
|
18
|
+
|
|
19
|
+
## Repo Map
|
|
20
|
+
|
|
21
|
+
| Area | Where to look |
|
|
22
|
+
|---|---|
|
|
23
|
+
| Main contracts | [`src/`](./src/) |
|
|
24
|
+
| Structs and interfaces | [`src/structs/`](./src/structs/), [`src/interfaces/`](./src/interfaces/) |
|
|
25
|
+
| Tests | [`test/`](./test/) |
|
|
26
|
+
|
|
27
|
+
## Purpose
|
|
28
|
+
|
|
29
|
+
Shared vesting and distribution engine for ERC-20 and 721-based payout flows.
|
|
30
|
+
|
|
31
|
+
## Working Rules
|
|
32
|
+
|
|
33
|
+
- Start in [`src/JBDistributor.sol`](./src/JBDistributor.sol) for shared round logic.
|
|
34
|
+
- Treat snapshot timing as part of correctness.
|
|
35
|
+
- `JBTokenDistributor` and `JB721Distributor` share a vesting engine but not the same ownership model.
|
|
36
|
+
- Verify the distributor actually holds the asset it is meant to vest before reasoning about payout correctness.
|