@bananapus/core-v6 0.0.35 → 0.0.37
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/ADMINISTRATION.md +29 -29
- package/ARCHITECTURE.md +41 -34
- package/AUDIT_INSTRUCTIONS.md +44 -42
- package/README.md +37 -37
- package/RISKS.md +115 -154
- package/SKILLS.md +17 -18
- package/USER_JOURNEYS.md +49 -51
- package/package.json +2 -2
- package/src/JBController.sol +7 -4
- package/src/JBMultiTerminal.sol +17 -13
- package/test/TestAccessToFunds.sol +24 -0
- package/test/audit/CodexMigrationFeeFailure.t.sol +163 -0
package/USER_JOURNEYS.md
CHANGED
|
@@ -2,32 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
## Repo Purpose
|
|
4
4
|
|
|
5
|
-
This repo is the
|
|
6
|
-
It owns project identity, rulesets, terminal execution, treasury accounting, permissions, price feeds, and migration
|
|
7
|
-
paths. Most other V6 repos wrap or extend this behavior rather than replacing it.
|
|
5
|
+
This repo is the main runtime surface for Juicebox V6. It owns project identity, rulesets, terminal execution, treasury accounting, permissions, price feeds, and migration paths. Most other V6 repos build on this behavior instead of replacing it.
|
|
8
6
|
|
|
9
7
|
## Primary Actors
|
|
10
8
|
|
|
11
|
-
- founders launching and
|
|
12
|
-
- supporters paying projects in
|
|
9
|
+
- founders launching and updating Juicebox projects
|
|
10
|
+
- supporters paying projects in assets that a terminal accepts
|
|
13
11
|
- token holders cashing out against project surplus
|
|
14
12
|
- operators managing permissions, splits, fund access limits, and rulesets
|
|
15
|
-
- integrators wiring hooks, terminals, price feeds, and migrations into
|
|
13
|
+
- integrators wiring hooks, terminals, price feeds, and migrations into core
|
|
16
14
|
|
|
17
15
|
## Key Surfaces
|
|
18
16
|
|
|
19
17
|
- `JBController`: project launch, ruleset queueing, token setup, splits, and controller migration
|
|
20
|
-
- `JBMultiTerminal`: pay, payout, allowance, preview, and cash-out
|
|
18
|
+
- `JBMultiTerminal`: pay, payout, allowance, preview, and cash-out entrypoints
|
|
21
19
|
- `JBTerminalStore`: balance, surplus, fee, and reclaim accounting
|
|
22
20
|
- `JBDirectory`: controller and terminal routing
|
|
23
21
|
- `JBPermissions`: packed operator-permission registry
|
|
24
22
|
- `JBProjects`, `JBRulesets`, `JBPrices`, `JBFundAccessLimits`, `JBSplits`, `JBTokens`: core state and helper surfaces
|
|
25
23
|
|
|
26
|
-
## Journey 1: Launch A Project With The Right Initial
|
|
24
|
+
## Journey 1: Launch A Project With The Right Initial Setup
|
|
27
25
|
|
|
28
26
|
**Actor:** founder, deployer, or protocol integrator.
|
|
29
27
|
|
|
30
|
-
**Intent:** create a project with the right owner, terminal, ruleset, and hook assumptions from
|
|
28
|
+
**Intent:** create a project with the right owner, terminal, ruleset, and hook assumptions from the start.
|
|
31
29
|
|
|
32
30
|
**Preconditions**
|
|
33
31
|
- the team knows who should own the project, which terminals it should use, and what the first ruleset should allow
|
|
@@ -35,20 +33,20 @@ paths. Most other V6 repos wrap or extend this behavior rather than replacing it
|
|
|
35
33
|
**Main Flow**
|
|
36
34
|
1. Call `JBController.launchProjectFor(...)` with the owner, URI, ruleset config, terminal configs, and any split or hook metadata.
|
|
37
35
|
2. `JBProjects` mints the project NFT, `JBDirectory` records controller and terminal routing, and `JBRulesets` stores the first ruleset.
|
|
38
|
-
3. If the project wants ERC-20 tokens, reserved-rate behavior, or hook-driven behavior, that configuration is
|
|
36
|
+
3. If the project wants ERC-20 tokens, reserved-rate behavior, or hook-driven behavior, that configuration is set at launch.
|
|
39
37
|
4. The project can now accept payments and queue future rulesets without changing project identity.
|
|
40
38
|
|
|
41
39
|
**Failure Modes**
|
|
42
40
|
- accounting contexts do not match the intended terminal asset
|
|
43
41
|
- hook metadata or split assumptions are invalid at launch
|
|
44
|
-
- ownership or permission assumptions are wrong and expensive to
|
|
42
|
+
- ownership or permission assumptions are wrong and expensive to fix later
|
|
45
43
|
|
|
46
44
|
**Postconditions**
|
|
47
|
-
- the project NFT exists, the
|
|
45
|
+
- the project NFT exists, the first ruleset is active, accepted terminals are installed, and hooks or splits can start immediately
|
|
48
46
|
|
|
49
47
|
## Journey 2: Accept A Payment And Issue The Right Token Exposure
|
|
50
48
|
|
|
51
|
-
**Actor:** payer or integration paying
|
|
49
|
+
**Actor:** payer or integration paying for a user.
|
|
52
50
|
|
|
53
51
|
**Intent:** settle a payment through the canonical terminal path and issue the correct token exposure.
|
|
54
52
|
|
|
@@ -58,18 +56,18 @@ paths. Most other V6 repos wrap or extend this behavior rather than replacing it
|
|
|
58
56
|
**Main Flow**
|
|
59
57
|
1. A payer calls `pay(...)` on `JBMultiTerminal`.
|
|
60
58
|
2. The terminal validates the accounting context, records funds, and asks `JBTerminalStore` to derive issuance from the active ruleset.
|
|
61
|
-
3. `JBController` and `JBTokens` decide whether the beneficiary gets project
|
|
59
|
+
3. `JBController` and `JBTokens` decide whether the beneficiary gets project credits, ERC-20s, or no issuance because weight is zero.
|
|
62
60
|
4. Any configured pay hooks or data hooks run around the accounting path.
|
|
63
61
|
|
|
64
62
|
**Failure Modes**
|
|
65
63
|
- payments are paused or the token is unsupported for the target accounting context
|
|
66
64
|
- fee-on-transfer behavior or price-feed assumptions break the intended issuance path
|
|
67
|
-
- hooks add side effects the payer or integrator did not account for
|
|
65
|
+
- hooks add side effects that the payer or integrator did not account for
|
|
68
66
|
|
|
69
67
|
**Postconditions**
|
|
70
|
-
- treasury balances increase, hooks run in the right order, and the beneficiary receives credits or ERC-20 tokens
|
|
68
|
+
- treasury balances increase, hooks run in the right order, and the beneficiary receives credits or ERC-20 tokens that match the ruleset
|
|
71
69
|
|
|
72
|
-
## Journey 3: Turn Credits Into ERC-20 Tokens
|
|
70
|
+
## Journey 3: Turn Credits Into ERC-20 Tokens
|
|
73
71
|
|
|
74
72
|
**Actor:** holder or operator acting for a holder.
|
|
75
73
|
|
|
@@ -82,30 +80,30 @@ paths. Most other V6 repos wrap or extend this behavior rather than replacing it
|
|
|
82
80
|
**Main Flow**
|
|
83
81
|
1. Deploy or set the project's ERC-20 token through `JBController`.
|
|
84
82
|
2. Holders or operators call `claimTokensFor(...)` to convert credits into ERC-20 balances for a beneficiary.
|
|
85
|
-
3. Future issuance can continue
|
|
83
|
+
3. Future issuance can continue under the same project identity while users now interact with a standard token surface.
|
|
86
84
|
|
|
87
85
|
**Failure Modes**
|
|
88
86
|
- the wrong token is installed for the project
|
|
89
|
-
- integrations assume credits
|
|
87
|
+
- integrations assume credits automatically become ERC-20 balances after token installation
|
|
90
88
|
|
|
91
89
|
**Postconditions**
|
|
92
|
-
- the project
|
|
90
|
+
- the project has an ERC-20 token and holders can claim credits into transferable balances
|
|
93
91
|
|
|
94
92
|
## Journey 4: Distribute Treasury Funds Through Governed Paths
|
|
95
93
|
|
|
96
94
|
**Actor:** owner or authorized operator.
|
|
97
95
|
|
|
98
|
-
**Intent:** move value out of the treasury through configured
|
|
96
|
+
**Intent:** move value out of the treasury through configured payout or allowance paths.
|
|
99
97
|
|
|
100
98
|
**Preconditions**
|
|
101
99
|
- the project has terminal balances
|
|
102
100
|
- the caller is allowed to use payout or allowance paths
|
|
103
101
|
|
|
104
102
|
**Main Flow**
|
|
105
|
-
1.
|
|
103
|
+
1. An authorized caller uses payout or allowance entrypoints on the terminal.
|
|
106
104
|
2. `JBFundAccessLimits` bounds how much may leave for the current ruleset cycle.
|
|
107
|
-
3. `JBSplits`
|
|
108
|
-
4. `JBTerminalStore` updates balances and fee accounting so later previews and cash outs
|
|
105
|
+
3. `JBSplits` routes value to beneficiaries, projects, hooks, or fee recipients as configured.
|
|
106
|
+
4. `JBTerminalStore` updates balances and fee accounting so later previews and cash outs stay consistent.
|
|
109
107
|
|
|
110
108
|
**Failure Modes**
|
|
111
109
|
- splits or access limits no longer match operator expectations
|
|
@@ -113,7 +111,7 @@ paths. Most other V6 repos wrap or extend this behavior rather than replacing it
|
|
|
113
111
|
- operators assume allowance withdrawals behave exactly like payouts when fee treatment differs
|
|
114
112
|
|
|
115
113
|
**Postconditions**
|
|
116
|
-
-
|
|
114
|
+
- value leaves the treasury only through configured limits, recipients, and fee logic
|
|
117
115
|
|
|
118
116
|
## Journey 5: Let Holders Cash Out Against Surplus
|
|
119
117
|
|
|
@@ -127,42 +125,42 @@ paths. Most other V6 repos wrap or extend this behavior rather than replacing it
|
|
|
127
125
|
|
|
128
126
|
**Main Flow**
|
|
129
127
|
1. The holder calls `cashOutTokensOf(...)` on the relevant terminal.
|
|
130
|
-
2. `JBTerminalStore` calculates reclaim value using surplus,
|
|
131
|
-
3. Cash-out hooks can
|
|
132
|
-
4. Tokens burn and value exits the treasury through the terminal that
|
|
128
|
+
2. `JBTerminalStore` calculates reclaim value using surplus, total supply, cash-out tax rate, and any pending reserved-token effects.
|
|
129
|
+
3. Cash-out hooks can change behavior or side effects, but core accounting still comes from the terminal store.
|
|
130
|
+
4. Tokens burn and value exits the treasury through the terminal that held the asset.
|
|
133
131
|
|
|
134
132
|
**Failure Modes**
|
|
135
133
|
- fee-free or custom hook paths produce different outcomes than the holder expected
|
|
136
|
-
- preview
|
|
137
|
-
- users
|
|
134
|
+
- preview and execution drift under changing routing or multi-terminal liquidity
|
|
135
|
+
- users treat multi-terminal surplus like one simple pool when it is not
|
|
138
136
|
|
|
139
137
|
**Postconditions**
|
|
140
|
-
- the holder burns the intended
|
|
138
|
+
- the holder burns the intended token exposure and receives the reclaim amount allowed by the current ruleset
|
|
141
139
|
|
|
142
140
|
## Journey 6: Queue New Rulesets Without Migrating The Project
|
|
143
141
|
|
|
144
142
|
**Actor:** owner or authorized operator.
|
|
145
143
|
|
|
146
|
-
**Intent:** change future project economics without changing
|
|
144
|
+
**Intent:** change future project economics without changing identity or existing balances.
|
|
147
145
|
|
|
148
146
|
**Preconditions**
|
|
149
147
|
- the project is live and future economics need to change
|
|
150
148
|
|
|
151
149
|
**Main Flow**
|
|
152
|
-
1. The owner or an operator
|
|
153
|
-
2. `JBRulesets` stores the
|
|
154
|
-
3. When the active duration
|
|
155
|
-
4. Existing balances and token history
|
|
150
|
+
1. The owner or an allowed operator queues one or more new rulesets through `JBController`.
|
|
151
|
+
2. `JBRulesets` stores the future configuration and any approval-hook requirements.
|
|
152
|
+
3. When the active duration ends, the next approved ruleset becomes live and later pays, payouts, and cash outs follow the new terms.
|
|
153
|
+
4. Existing balances and token history stay intact because only future behavior changed.
|
|
156
154
|
|
|
157
155
|
**Failure Modes**
|
|
158
156
|
- approval-hook requirements are forgotten or misunderstood
|
|
159
157
|
- queued metadata is incompatible with installed hooks
|
|
160
|
-
- teams assume a ruleset change can
|
|
158
|
+
- teams assume a ruleset change can fix past accounting
|
|
161
159
|
|
|
162
160
|
**Postconditions**
|
|
163
|
-
- the next ruleset activates on schedule while the project keeps the same identity, treasury, and
|
|
161
|
+
- the next ruleset activates on schedule while the project keeps the same identity, treasury, and integrations
|
|
164
162
|
|
|
165
|
-
## Journey 7: Migrate
|
|
163
|
+
## Journey 7: Migrate To New Terminal Or Controller Surfaces
|
|
166
164
|
|
|
167
165
|
**Actor:** owner or migration operator.
|
|
168
166
|
|
|
@@ -173,13 +171,13 @@ paths. Most other V6 repos wrap or extend this behavior rather than replacing it
|
|
|
173
171
|
- the destination surface is understood and intended
|
|
174
172
|
|
|
175
173
|
**Main Flow**
|
|
176
|
-
1. Confirm the active ruleset
|
|
174
|
+
1. Confirm the active ruleset allows migration and the destination is the intended successor.
|
|
177
175
|
2. Use `JBController.migrate(...)` and the terminal-store migration paths instead of manually repointing addresses.
|
|
178
|
-
3. Recheck directory routing and accepted accounting contexts after migration
|
|
176
|
+
3. Recheck directory routing and accepted accounting contexts after migration.
|
|
179
177
|
|
|
180
178
|
**Failure Modes**
|
|
181
|
-
- migration targets are wrong or only
|
|
182
|
-
- operators manually repoint routing without using
|
|
179
|
+
- migration targets are wrong or only partly configured
|
|
180
|
+
- operators manually repoint routing without using protocol migration paths
|
|
183
181
|
|
|
184
182
|
**Postconditions**
|
|
185
183
|
- balances, permissions, and future routing stay coherent after migration
|
|
@@ -188,7 +186,7 @@ paths. Most other V6 repos wrap or extend this behavior rather than replacing it
|
|
|
188
186
|
|
|
189
187
|
**Actor:** project owner.
|
|
190
188
|
|
|
191
|
-
**Intent:** delegate project operations
|
|
189
|
+
**Intent:** delegate narrow project operations instead of blanket control.
|
|
192
190
|
|
|
193
191
|
**Preconditions**
|
|
194
192
|
- the owner wants operators, delegates, or automation to manage only specific surfaces
|
|
@@ -196,10 +194,10 @@ paths. Most other V6 repos wrap or extend this behavior rather than replacing it
|
|
|
196
194
|
**Main Flow**
|
|
197
195
|
1. The owner configures operator permissions in `JBPermissions`.
|
|
198
196
|
2. Downstream calls check those packed permission bits instead of assuming project ownership.
|
|
199
|
-
3.
|
|
197
|
+
3. Ownable wrappers, hook deployers, and router registries can respect project-scoped delegation without custom ACL logic.
|
|
200
198
|
|
|
201
199
|
**Failure Modes**
|
|
202
|
-
- operators receive permissions
|
|
200
|
+
- operators receive broader permissions than they need
|
|
203
201
|
- auditors assume downstream access still depends only on project ownership
|
|
204
202
|
|
|
205
203
|
**Postconditions**
|
|
@@ -207,11 +205,11 @@ paths. Most other V6 repos wrap or extend this behavior rather than replacing it
|
|
|
207
205
|
|
|
208
206
|
## Trust Boundaries
|
|
209
207
|
|
|
210
|
-
- `JBTerminalStore` is the accounting truth for balances, surplus, fees, and reclaim behavior
|
|
211
|
-
- hooks, approval hooks, pay hooks, and cash-out hooks are trusted extension surfaces
|
|
212
|
-
- price feeds and directory routing are critical
|
|
208
|
+
- `JBTerminalStore` is the accounting source of truth for balances, surplus, fees, and reclaim behavior
|
|
209
|
+
- hooks, approval hooks, pay hooks, and cash-out hooks are trusted extension surfaces
|
|
210
|
+
- price feeds and directory routing are critical shared-context surfaces
|
|
213
211
|
|
|
214
212
|
## Hand-Offs
|
|
215
213
|
|
|
216
|
-
- Use [nana-permission-ids-v6](../nana-permission-ids-v6/USER_JOURNEYS.md) for the shared permission vocabulary
|
|
217
|
-
- Use [nana-721-hook-v6](../nana-721-hook-v6/USER_JOURNEYS.md), [nana-router-terminal-v6](../nana-router-terminal-v6/USER_JOURNEYS.md), and [nana-buyback-hook-v6](../nana-buyback-hook-v6/USER_JOURNEYS.md) for opinionated layers on
|
|
214
|
+
- Use [nana-permission-ids-v6](../nana-permission-ids-v6/USER_JOURNEYS.md) for the shared permission vocabulary used by downstream repos.
|
|
215
|
+
- Use [nana-721-hook-v6](../nana-721-hook-v6/USER_JOURNEYS.md), [nana-router-terminal-v6](../nana-router-terminal-v6/USER_JOURNEYS.md), and [nana-buyback-hook-v6](../nana-buyback-hook-v6/USER_JOURNEYS.md) for opinionated layers built on the core terminal and ruleset surfaces.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bananapus/core-v6",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"artifacts": "source ./.env && npx sphinx artifacts --org-id 'ea165b21-7cdc-4d7b-be59-ecdd4c26bee4' --project-name 'nana-core-v6'"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@bananapus/permission-ids-v6": "^0.0.
|
|
29
|
+
"@bananapus/permission-ids-v6": "^0.0.19",
|
|
30
30
|
"@chainlink/contracts": "^1.5.0",
|
|
31
31
|
"@openzeppelin/contracts": "^5.6.1",
|
|
32
32
|
"@prb/math": "^4.1.1",
|
package/src/JBController.sol
CHANGED
|
@@ -525,6 +525,10 @@ contract JBController is JBPermissioned, ERC2771Context, IJBController, IJBMigra
|
|
|
525
525
|
// Cache common values used in both permission checks.
|
|
526
526
|
address sender = _msgSender();
|
|
527
527
|
bool senderIsTerminal = _isTerminalOf(projectId, sender);
|
|
528
|
+
bool senderIsTerminalOrDataHook = senderIsTerminal || sender == ruleset.dataHook();
|
|
529
|
+
// Only query the data hook if the sender isn't already a terminal or the data hook itself.
|
|
530
|
+
bool senderHasDataHookMintPermission =
|
|
531
|
+
!senderIsTerminalOrDataHook && _hasDataHookMintPermissionFor(projectId, ruleset, sender);
|
|
528
532
|
|
|
529
533
|
// Minting is restricted to: the project's owner, addresses with permission to `MINT_TOKENS`, the project's
|
|
530
534
|
// terminals, and the project's data hook.
|
|
@@ -532,15 +536,14 @@ contract JBController is JBPermissioned, ERC2771Context, IJBController, IJBMigra
|
|
|
532
536
|
account: PROJECTS.ownerOf(projectId),
|
|
533
537
|
projectId: projectId,
|
|
534
538
|
permissionId: JBPermissionIds.MINT_TOKENS,
|
|
535
|
-
alsoGrantAccessIf:
|
|
536
|
-
|| _hasDataHookMintPermissionFor(projectId, ruleset, sender)
|
|
539
|
+
alsoGrantAccessIf: senderIsTerminalOrDataHook || senderHasDataHookMintPermission
|
|
537
540
|
});
|
|
538
541
|
|
|
539
542
|
// If the message sender is not the project's terminal or data hook, the ruleset must have `allowOwnerMinting`
|
|
540
543
|
// set to `true`.
|
|
541
544
|
if (
|
|
542
|
-
ruleset.id != 0 && !ruleset.allowOwnerMinting() && !
|
|
543
|
-
&& !
|
|
545
|
+
ruleset.id != 0 && !ruleset.allowOwnerMinting() && !senderIsTerminalOrDataHook
|
|
546
|
+
&& !senderHasDataHookMintPermission
|
|
544
547
|
) {
|
|
545
548
|
revert JBController_MintNotAllowedAndNotTerminalOrHook(sender);
|
|
546
549
|
}
|
package/src/JBMultiTerminal.sol
CHANGED
|
@@ -1150,20 +1150,24 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal {
|
|
|
1150
1150
|
// Cache whether the beneficiary is feeless.
|
|
1151
1151
|
bool beneficiaryIsFeeless = _isFeeless(beneficiary);
|
|
1152
1152
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1153
|
+
{
|
|
1154
|
+
// Cache the controller to avoid a redundant external call (also used inside STORE.recordCashOutFor).
|
|
1155
|
+
IJBController controller = _controllerOf(projectId);
|
|
1156
|
+
|
|
1157
|
+
// Record the cash out.
|
|
1158
|
+
(ruleset, reclaimAmount, cashOutTaxRate, hookSpecifications) = STORE.recordCashOutFor({
|
|
1159
|
+
holder: holder,
|
|
1160
|
+
projectId: projectId,
|
|
1161
|
+
cashOutCount: cashOutCount,
|
|
1162
|
+
tokenToReclaim: tokenToReclaim,
|
|
1163
|
+
beneficiaryIsFeeless: beneficiaryIsFeeless,
|
|
1164
|
+
metadata: metadata
|
|
1165
|
+
});
|
|
1162
1166
|
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
+
// Burn the project tokens.
|
|
1168
|
+
if (cashOutCount != 0) {
|
|
1169
|
+
controller.burnTokensOf({holder: holder, projectId: projectId, tokenCount: cashOutCount, memo: ""});
|
|
1170
|
+
}
|
|
1167
1171
|
}
|
|
1168
1172
|
|
|
1169
1173
|
// Keep a reference to the amount being reclaimed that is subject to fees.
|
|
@@ -1146,6 +1146,20 @@ contract TestAccessToFunds_Local is TestBaseWorkflow {
|
|
|
1146
1146
|
: _nativePayAmount - _nativeCurrencyPayoutLimit > 1
|
|
1147
1147
|
);
|
|
1148
1148
|
|
|
1149
|
+
// Skip inputs where cross-currency payout limit rounding could flip the revert/succeed outcome.
|
|
1150
|
+
// The test's `_toNative` helper may round differently than the contract's multi-step conversion
|
|
1151
|
+
// (which uses 18-decimal intermediate fidelity). A 1 wei difference at the boundary is enough
|
|
1152
|
+
// to cause the test to expect a revert that doesn't happen, or vice versa.
|
|
1153
|
+
{
|
|
1154
|
+
uint256 _nativePLTotal = uint256(_nativeCurrencyPayoutLimit) + _toNative(_usdCurrencyPayoutLimit);
|
|
1155
|
+
uint256 _predicted = uint256(_nativeCurrencySurplusAllowance) + _nativePLTotal;
|
|
1156
|
+
// If the predicted total is within 2 of the pay amount, rounding can go either way.
|
|
1157
|
+
if (_predicted > _nativePayAmount ? _predicted - _nativePayAmount <= 2 : _nativePayAmount - _predicted <= 2)
|
|
1158
|
+
{
|
|
1159
|
+
vm.assume(false);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1149
1163
|
{
|
|
1150
1164
|
// Package up the limits for the given terminal.
|
|
1151
1165
|
JBFundAccessLimitGroup[] memory _fundAccessLimitGroup = new JBFundAccessLimitGroup[](1);
|
|
@@ -1371,6 +1385,16 @@ contract TestAccessToFunds_Local is TestBaseWorkflow {
|
|
|
1371
1385
|
&& _toNative(_usdCurrencySurplusAllowance + _usdCurrencyPayoutLimit) + _nativeCurrencyPayoutLimit
|
|
1372
1386
|
+ _nativeCurrencySurplusAllowance > _nativePayAmount
|
|
1373
1387
|
) {
|
|
1388
|
+
// Skip inputs near the rounding boundary for the second allowance call too.
|
|
1389
|
+
{
|
|
1390
|
+
uint256 _predicted2 = _toNative(_usdCurrencySurplusAllowance + _usdCurrencyPayoutLimit)
|
|
1391
|
+
+ _nativeCurrencyPayoutLimit + _nativeCurrencySurplusAllowance;
|
|
1392
|
+
if (_predicted2 > _nativePayAmount
|
|
1393
|
+
? _predicted2 - _nativePayAmount <= 2
|
|
1394
|
+
: _nativePayAmount - _predicted2 <= 2) {
|
|
1395
|
+
return; // Too close to boundary — rounding may differ between test helper and contract.
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1374
1398
|
vm.expectRevert(
|
|
1375
1399
|
abi.encodeWithSelector(
|
|
1376
1400
|
JBTerminalStore.JBTerminalStore_InadequateTerminalStoreBalance.selector,
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.6;
|
|
3
|
+
|
|
4
|
+
import {TestBaseWorkflow} from "../helpers/TestBaseWorkflow.sol";
|
|
5
|
+
import {JBMultiTerminal} from "../../src/JBMultiTerminal.sol";
|
|
6
|
+
import {JBDirectory} from "../../src/JBDirectory.sol";
|
|
7
|
+
import {JBTerminalStore} from "../../src/JBTerminalStore.sol";
|
|
8
|
+
import {IJBController} from "../../src/interfaces/IJBController.sol";
|
|
9
|
+
import {IJBTerminal} from "../../src/interfaces/IJBTerminal.sol";
|
|
10
|
+
import {IJBRulesetApprovalHook} from "../../src/interfaces/IJBRulesetApprovalHook.sol";
|
|
11
|
+
import {JBConstants} from "../../src/libraries/JBConstants.sol";
|
|
12
|
+
import {JBFees} from "../../src/libraries/JBFees.sol";
|
|
13
|
+
import {JBAccountingContext} from "../../src/structs/JBAccountingContext.sol";
|
|
14
|
+
import {JBCurrencyAmount} from "../../src/structs/JBCurrencyAmount.sol";
|
|
15
|
+
import {JBFundAccessLimitGroup} from "../../src/structs/JBFundAccessLimitGroup.sol";
|
|
16
|
+
import {JBRulesetConfig} from "../../src/structs/JBRulesetConfig.sol";
|
|
17
|
+
import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
|
|
18
|
+
import {JBSplitGroup} from "../../src/structs/JBSplitGroup.sol";
|
|
19
|
+
import {JBTerminalConfig} from "../../src/structs/JBTerminalConfig.sol";
|
|
20
|
+
|
|
21
|
+
contract CodexMigrationFeeFailure is TestBaseWorkflow {
|
|
22
|
+
IJBController private _controller;
|
|
23
|
+
JBDirectory private _directory;
|
|
24
|
+
JBTerminalStore private _store;
|
|
25
|
+
JBMultiTerminal private _terminalA;
|
|
26
|
+
JBMultiTerminal private _terminalB;
|
|
27
|
+
|
|
28
|
+
address private _feeProjectOwner = address(420);
|
|
29
|
+
address private _projectOwner;
|
|
30
|
+
address private _payer;
|
|
31
|
+
uint256 private _projectId;
|
|
32
|
+
|
|
33
|
+
function setUp() public override {
|
|
34
|
+
super.setUp();
|
|
35
|
+
|
|
36
|
+
_controller = jbController();
|
|
37
|
+
_directory = jbDirectory();
|
|
38
|
+
_store = jbTerminalStore();
|
|
39
|
+
_terminalA = jbMultiTerminal();
|
|
40
|
+
_terminalB = jbMultiTerminal2();
|
|
41
|
+
_projectOwner = multisig();
|
|
42
|
+
_payer = beneficiary();
|
|
43
|
+
|
|
44
|
+
JBRulesetMetadata memory metadata = JBRulesetMetadata({
|
|
45
|
+
reservedPercent: 0,
|
|
46
|
+
cashOutTaxRate: 0,
|
|
47
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
48
|
+
pausePay: false,
|
|
49
|
+
pauseCreditTransfers: false,
|
|
50
|
+
allowOwnerMinting: false,
|
|
51
|
+
allowSetCustomToken: false,
|
|
52
|
+
allowTerminalMigration: true,
|
|
53
|
+
allowSetTerminals: true,
|
|
54
|
+
allowSetController: false,
|
|
55
|
+
allowAddAccountingContext: false,
|
|
56
|
+
allowAddPriceFeed: false,
|
|
57
|
+
ownerMustSendPayouts: false,
|
|
58
|
+
holdFees: false,
|
|
59
|
+
useTotalSurplusForCashOuts: false,
|
|
60
|
+
useDataHookForPay: false,
|
|
61
|
+
useDataHookForCashOut: false,
|
|
62
|
+
dataHook: address(0),
|
|
63
|
+
metadata: 0
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
|
|
67
|
+
rulesetConfig[0].mustStartAtOrAfter = 0;
|
|
68
|
+
rulesetConfig[0].duration = 0;
|
|
69
|
+
rulesetConfig[0].weight = 1000 * 10 ** 18;
|
|
70
|
+
rulesetConfig[0].weightCutPercent = 0;
|
|
71
|
+
rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
|
|
72
|
+
rulesetConfig[0].metadata = metadata;
|
|
73
|
+
rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
|
|
74
|
+
rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
|
|
75
|
+
|
|
76
|
+
JBAccountingContext[] memory contexts = new JBAccountingContext[](1);
|
|
77
|
+
contexts[0] = JBAccountingContext({
|
|
78
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
JBTerminalConfig[] memory feeTerminalConfigs = new JBTerminalConfig[](1);
|
|
82
|
+
feeTerminalConfigs[0] = JBTerminalConfig({terminal: _terminalA, accountingContextsToAccept: contexts});
|
|
83
|
+
|
|
84
|
+
JBTerminalConfig[] memory projectTerminalConfigs = new JBTerminalConfig[](2);
|
|
85
|
+
projectTerminalConfigs[0] = JBTerminalConfig({terminal: _terminalA, accountingContextsToAccept: contexts});
|
|
86
|
+
projectTerminalConfigs[1] = JBTerminalConfig({terminal: _terminalB, accountingContextsToAccept: contexts});
|
|
87
|
+
|
|
88
|
+
_controller.launchProjectFor({
|
|
89
|
+
owner: _feeProjectOwner,
|
|
90
|
+
projectUri: "fee-project",
|
|
91
|
+
rulesetConfigurations: rulesetConfig,
|
|
92
|
+
terminalConfigurations: feeTerminalConfigs,
|
|
93
|
+
memo: ""
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
_projectId = _controller.launchProjectFor({
|
|
97
|
+
owner: _projectOwner,
|
|
98
|
+
projectUri: "migrating-project",
|
|
99
|
+
rulesetConfigurations: rulesetConfig,
|
|
100
|
+
terminalConfigurations: projectTerminalConfigs,
|
|
101
|
+
memo: ""
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function test_migrationFeeFailure_strandsForgivenFeeAndChargesItAgainOnCleanup() external {
|
|
106
|
+
uint256 payAmount = 10 ether;
|
|
107
|
+
uint256 expectedFee = JBFees.feeAmountFrom({amountBeforeFee: payAmount, feePercent: _terminalA.FEE()});
|
|
108
|
+
|
|
109
|
+
vm.deal(_payer, payAmount);
|
|
110
|
+
vm.prank(_payer);
|
|
111
|
+
_terminalA.pay{value: payAmount}(_projectId, JBConstants.NATIVE_TOKEN, payAmount, _payer, 0, "", "");
|
|
112
|
+
|
|
113
|
+
// Break fee routing by removing every terminal from fee project #1.
|
|
114
|
+
vm.prank(_feeProjectOwner);
|
|
115
|
+
_directory.setTerminalsOf(1, new IJBTerminal[](0));
|
|
116
|
+
|
|
117
|
+
vm.prank(_projectOwner);
|
|
118
|
+
_terminalA.migrateBalanceOf(_projectId, JBConstants.NATIVE_TOKEN, _terminalB);
|
|
119
|
+
|
|
120
|
+
// The failed fee is credited back on terminal A instead of migrating with the project.
|
|
121
|
+
assertEq(
|
|
122
|
+
_store.balanceOf(address(_terminalA), _projectId, JBConstants.NATIVE_TOKEN),
|
|
123
|
+
expectedFee,
|
|
124
|
+
"failed migration fee remains on the source terminal"
|
|
125
|
+
);
|
|
126
|
+
assertEq(
|
|
127
|
+
_store.balanceOf(address(_terminalB), _projectId, JBConstants.NATIVE_TOKEN),
|
|
128
|
+
payAmount - expectedFee,
|
|
129
|
+
"only the post-fee amount reaches the destination terminal"
|
|
130
|
+
);
|
|
131
|
+
assertEq(
|
|
132
|
+
_store.balanceOf(address(_terminalA), 1, JBConstants.NATIVE_TOKEN),
|
|
133
|
+
0,
|
|
134
|
+
"fee project did not receive the forgiven migration fee"
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// Restore fee routing and sweep the residual balance.
|
|
138
|
+
IJBTerminal[] memory feeTerminals = new IJBTerminal[](1);
|
|
139
|
+
feeTerminals[0] = IJBTerminal(address(_terminalA));
|
|
140
|
+
vm.prank(_feeProjectOwner);
|
|
141
|
+
_directory.setTerminalsOf(1, feeTerminals);
|
|
142
|
+
|
|
143
|
+
vm.prank(_projectOwner);
|
|
144
|
+
_terminalA.migrateBalanceOf(_projectId, JBConstants.NATIVE_TOKEN, _terminalB);
|
|
145
|
+
|
|
146
|
+
uint256 secondFee = JBFees.feeAmountFrom({amountBeforeFee: expectedFee, feePercent: _terminalA.FEE()});
|
|
147
|
+
assertEq(
|
|
148
|
+
_store.balanceOf(address(_terminalA), _projectId, JBConstants.NATIVE_TOKEN),
|
|
149
|
+
0,
|
|
150
|
+
"cleanup migration clears the stranded source balance"
|
|
151
|
+
);
|
|
152
|
+
assertEq(
|
|
153
|
+
_store.balanceOf(address(_terminalB), _projectId, JBConstants.NATIVE_TOKEN),
|
|
154
|
+
payAmount - secondFee,
|
|
155
|
+
"the previously forgiven fee is charged again during cleanup"
|
|
156
|
+
);
|
|
157
|
+
assertEq(
|
|
158
|
+
_store.balanceOf(address(_terminalA), 1, JBConstants.NATIVE_TOKEN),
|
|
159
|
+
secondFee,
|
|
160
|
+
"fee project only receives the second migration fee"
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|