@bananapus/core-v6 0.0.30 → 0.0.32
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 +43 -13
- package/ARCHITECTURE.md +62 -137
- package/AUDIT_INSTRUCTIONS.md +149 -428
- package/CHANGELOG.md +73 -0
- package/README.md +90 -201
- package/RISKS.md +27 -12
- package/SKILLS.md +31 -441
- package/STYLE_GUIDE.md +52 -19
- package/USER_JOURNEYS.md +76 -627
- package/package.json +1 -2
- package/references/entrypoints.md +160 -0
- package/references/types-errors-events.md +297 -0
- package/script/Deploy.s.sol +7 -2
- package/script/DeployPeriphery.s.sol +51 -4
- package/src/JBController.sol +45 -17
- package/src/JBDirectory.sol +26 -13
- package/src/JBFundAccessLimits.sol +28 -7
- package/src/JBMultiTerminal.sol +180 -86
- package/src/JBPermissions.sol +17 -17
- package/src/JBRulesets.sol +82 -23
- package/src/JBSplits.sol +31 -12
- package/src/JBTerminalStore.sol +137 -53
- package/src/JBTokens.sol +5 -2
- package/src/abstract/JBControlled.sol +10 -3
- package/src/abstract/JBPermissioned.sol +1 -1
- package/src/interfaces/IJBRulesetDataHook.sol +5 -4
- package/src/libraries/JBCashOuts.sol +1 -1
- package/src/libraries/JBConstants.sol +1 -1
- package/src/libraries/JBCurrencyIds.sol +1 -1
- package/src/libraries/JBFees.sol +1 -1
- package/src/libraries/JBFixedPointNumber.sol +1 -1
- package/src/libraries/JBMetadataResolver.sol +5 -2
- package/src/libraries/JBPayoutSplitGroupLib.sol +7 -2
- package/src/libraries/JBRulesetMetadataResolver.sol +1 -1
- package/src/libraries/JBSplitGroupIds.sol +1 -1
- package/src/libraries/JBSurplus.sol +5 -2
- package/src/structs/JBSplit.sol +4 -1
- package/test/TestForwardedTokenConsumption.sol +419 -0
- package/test/audit/CrossTerminalSurplusSpoof.t.sol +140 -0
- package/test/audit/CycledSurplusAllowanceReset.t.sol +184 -0
- package/test/units/static/JBController/TestPreviewMintOf.sol +5 -4
- package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +15 -12
- package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +6 -0
- package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +3 -0
- package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +3 -0
- package/test/units/static/JBMultiTerminal/TestPay.sol +7 -15
- package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +1 -1
- package/CHANGE_LOG.md +0 -479
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity
|
|
2
|
+
pragma solidity 0.8.28;
|
|
3
3
|
|
|
4
4
|
import {IJBTerminal} from "../interfaces/IJBTerminal.sol";
|
|
5
5
|
|
|
@@ -30,10 +30,13 @@ library JBSurplus {
|
|
|
30
30
|
uint256 numberOfTerminals = terminals.length;
|
|
31
31
|
|
|
32
32
|
// Add the current surplus for each terminal.
|
|
33
|
-
for (uint256 i; i < numberOfTerminals;
|
|
33
|
+
for (uint256 i; i < numberOfTerminals;) {
|
|
34
34
|
surplus += terminals[i].currentSurplusOf({
|
|
35
35
|
projectId: projectId, tokens: tokens, decimals: decimals, currency: currency
|
|
36
36
|
});
|
|
37
|
+
unchecked {
|
|
38
|
+
++i;
|
|
39
|
+
}
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
}
|
package/src/structs/JBSplit.sol
CHANGED
|
@@ -24,7 +24,10 @@ import {IJBSplitHook} from "./../interfaces/IJBSplitHook.sol";
|
|
|
24
24
|
/// @custom:member preferAddToBalance If this split were to `pay` a project through its terminal, this flag indicates
|
|
25
25
|
/// whether it should prefer using the terminal's `addToBalance` function instead.
|
|
26
26
|
/// @custom:member lockedUntil The split cannot be changed until this timestamp. The `lockedUntil` timestamp can be
|
|
27
|
-
/// increased while a split is locked. If `lockedUntil` is zero, this split can be changed at any time.
|
|
27
|
+
/// increased while a split is locked. If `lockedUntil` is zero, this split can be changed at any time. This lock is
|
|
28
|
+
/// enforced only when rewriting the same split table. Queueing a successor ruleset with a different `rulesetId` can
|
|
29
|
+
/// still replace future payout behavior before `lockedUntil`, so applications that need cross-ruleset continuity must
|
|
30
|
+
/// preserve those splits at the governance/configuration layer.
|
|
28
31
|
/// @custom:member hook A contract which will receive this split's tokens and properties, and can define custom
|
|
29
32
|
/// behavior.
|
|
30
33
|
// forge-lint: disable-next-line(pascal-case-struct)
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.6;
|
|
3
|
+
|
|
4
|
+
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
5
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
6
|
+
|
|
7
|
+
import {TestBaseWorkflow} from "./helpers/TestBaseWorkflow.sol";
|
|
8
|
+
import {JBMultiTerminal} from "../src/JBMultiTerminal.sol";
|
|
9
|
+
import {IJBController} from "../src/interfaces/IJBController.sol";
|
|
10
|
+
import {IJBCashOutHook} from "../src/interfaces/IJBCashOutHook.sol";
|
|
11
|
+
import {IJBMultiTerminal} from "../src/interfaces/IJBMultiTerminal.sol";
|
|
12
|
+
import {IJBPayHook} from "../src/interfaces/IJBPayHook.sol";
|
|
13
|
+
import {IJBRulesetApprovalHook} from "../src/interfaces/IJBRulesetApprovalHook.sol";
|
|
14
|
+
import {IJBRulesetDataHook} from "../src/interfaces/IJBRulesetDataHook.sol";
|
|
15
|
+
import {IJBSplitHook} from "../src/interfaces/IJBSplitHook.sol";
|
|
16
|
+
import {IJBTokens} from "../src/interfaces/IJBTokens.sol";
|
|
17
|
+
import {JBConstants} from "../src/libraries/JBConstants.sol";
|
|
18
|
+
import {JBAccountingContext} from "../src/structs/JBAccountingContext.sol";
|
|
19
|
+
import {JBAfterCashOutRecordedContext} from "../src/structs/JBAfterCashOutRecordedContext.sol";
|
|
20
|
+
import {JBAfterPayRecordedContext} from "../src/structs/JBAfterPayRecordedContext.sol";
|
|
21
|
+
import {JBCashOutHookSpecification} from "../src/structs/JBCashOutHookSpecification.sol";
|
|
22
|
+
import {JBCurrencyAmount} from "../src/structs/JBCurrencyAmount.sol";
|
|
23
|
+
import {JBFundAccessLimitGroup} from "../src/structs/JBFundAccessLimitGroup.sol";
|
|
24
|
+
import {JBPayHookSpecification} from "../src/structs/JBPayHookSpecification.sol";
|
|
25
|
+
import {JBRulesetConfig} from "../src/structs/JBRulesetConfig.sol";
|
|
26
|
+
import {JBRulesetMetadata} from "../src/structs/JBRulesetMetadata.sol";
|
|
27
|
+
import {JBSplit} from "../src/structs/JBSplit.sol";
|
|
28
|
+
import {JBSplitGroup} from "../src/structs/JBSplitGroup.sol";
|
|
29
|
+
import {JBTerminalConfig} from "../src/structs/JBTerminalConfig.sol";
|
|
30
|
+
|
|
31
|
+
contract TestForwardedTokenConsumption_Local is TestBaseWorkflow {
|
|
32
|
+
uint112 private constant _WEIGHT = 1000 * 10 ** 18;
|
|
33
|
+
uint256 private constant _PAY_AMOUNT = 10 * 10 ** 6;
|
|
34
|
+
uint256 private constant _HOOK_FORWARD_AMOUNT = 1 * 10 ** 6;
|
|
35
|
+
uint256 private constant _PAYOUT_AMOUNT = 4 * 10 ** 6;
|
|
36
|
+
address private constant _DATA_HOOK = address(bytes20(keccak256("datahook")));
|
|
37
|
+
|
|
38
|
+
IJBController private _controller;
|
|
39
|
+
IJBMultiTerminal private _terminal;
|
|
40
|
+
IJBMultiTerminal private _terminal2;
|
|
41
|
+
IJBTokens private _tokens;
|
|
42
|
+
address private _projectOwner;
|
|
43
|
+
|
|
44
|
+
uint64 private _projectId;
|
|
45
|
+
|
|
46
|
+
function setUp() public override {
|
|
47
|
+
super.setUp();
|
|
48
|
+
|
|
49
|
+
_controller = jbController();
|
|
50
|
+
_terminal = jbMultiTerminal();
|
|
51
|
+
_terminal2 = jbMultiTerminal2();
|
|
52
|
+
_tokens = jbTokens();
|
|
53
|
+
_projectOwner = multisig();
|
|
54
|
+
|
|
55
|
+
// Launch the fee beneficiary project first so project ID 1 has a terminal and accounting context.
|
|
56
|
+
_launchProject({
|
|
57
|
+
terminal: _terminal,
|
|
58
|
+
projectUri: "fee-project",
|
|
59
|
+
metadata: _metadataWithHooks({useDataHookForPay: true, useDataHookForCashOut: true, dataHook: _DATA_HOOK}),
|
|
60
|
+
splitGroups: new JBSplitGroup[](0),
|
|
61
|
+
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
_projectId = uint64(
|
|
65
|
+
_launchProject({
|
|
66
|
+
terminal: _terminal,
|
|
67
|
+
projectUri: "hook-project",
|
|
68
|
+
metadata: _metadataWithHooks({
|
|
69
|
+
useDataHookForPay: true, useDataHookForCashOut: true, dataHook: _DATA_HOOK
|
|
70
|
+
}),
|
|
71
|
+
splitGroups: new JBSplitGroup[](0),
|
|
72
|
+
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function test_RevertIfERC20PayHookDoesNotConsumeForwardedTokens() external {
|
|
78
|
+
NonConsumingPayHook hook = new NonConsumingPayHook();
|
|
79
|
+
JBPayHookSpecification[] memory specifications = new JBPayHookSpecification[](1);
|
|
80
|
+
specifications[0] =
|
|
81
|
+
JBPayHookSpecification({hook: hook, noop: false, amount: _HOOK_FORWARD_AMOUNT, metadata: ""});
|
|
82
|
+
|
|
83
|
+
vm.mockCall(
|
|
84
|
+
_DATA_HOOK,
|
|
85
|
+
abi.encodeWithSelector(IJBRulesetDataHook.beforePayRecordedWith.selector),
|
|
86
|
+
abi.encode(_WEIGHT, specifications)
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
vm.prank(multisig());
|
|
90
|
+
jbFeelessAddresses().setFeelessAddress(address(hook), true);
|
|
91
|
+
|
|
92
|
+
address payer = makeAddr("payer");
|
|
93
|
+
usdcToken().mint(payer, _PAY_AMOUNT);
|
|
94
|
+
vm.prank(payer);
|
|
95
|
+
usdcToken().approve(address(_terminal), _PAY_AMOUNT);
|
|
96
|
+
|
|
97
|
+
vm.expectRevert(
|
|
98
|
+
abi.encodeWithSelector(
|
|
99
|
+
JBMultiTerminal.JBMultiTerminal_TemporaryAllowanceNotConsumed.selector,
|
|
100
|
+
address(usdcToken()),
|
|
101
|
+
address(hook),
|
|
102
|
+
_HOOK_FORWARD_AMOUNT
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
vm.prank(payer);
|
|
106
|
+
_terminal.pay({
|
|
107
|
+
projectId: _projectId,
|
|
108
|
+
token: address(usdcToken()),
|
|
109
|
+
amount: _PAY_AMOUNT,
|
|
110
|
+
beneficiary: payer,
|
|
111
|
+
minReturnedTokens: 0,
|
|
112
|
+
memo: "",
|
|
113
|
+
metadata: ""
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function test_RevertIfERC20CashOutHookDoesNotConsumeForwardedTokens() external {
|
|
118
|
+
JBPayHookSpecification[] memory emptyPaySpecifications = new JBPayHookSpecification[](0);
|
|
119
|
+
vm.mockCall(
|
|
120
|
+
_DATA_HOOK,
|
|
121
|
+
abi.encodeWithSelector(IJBRulesetDataHook.beforePayRecordedWith.selector),
|
|
122
|
+
abi.encode(_WEIGHT, emptyPaySpecifications)
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
usdcToken().mint(address(this), _PAY_AMOUNT);
|
|
126
|
+
usdcToken().approve(address(_terminal), _PAY_AMOUNT);
|
|
127
|
+
|
|
128
|
+
_terminal.pay({
|
|
129
|
+
projectId: _projectId,
|
|
130
|
+
token: address(usdcToken()),
|
|
131
|
+
amount: _PAY_AMOUNT,
|
|
132
|
+
beneficiary: address(this),
|
|
133
|
+
minReturnedTokens: 0,
|
|
134
|
+
memo: "",
|
|
135
|
+
metadata: ""
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
uint256 cashOutCount = _tokens.totalBalanceOf(address(this), _projectId) / 2;
|
|
139
|
+
|
|
140
|
+
NonConsumingCashOutHook hook = new NonConsumingCashOutHook();
|
|
141
|
+
JBCashOutHookSpecification[] memory specifications = new JBCashOutHookSpecification[](1);
|
|
142
|
+
specifications[0] =
|
|
143
|
+
JBCashOutHookSpecification({hook: hook, noop: false, amount: _HOOK_FORWARD_AMOUNT, metadata: ""});
|
|
144
|
+
|
|
145
|
+
vm.mockCall(
|
|
146
|
+
_DATA_HOOK,
|
|
147
|
+
abi.encodeWithSelector(IJBRulesetDataHook.beforeCashOutRecordedWith.selector),
|
|
148
|
+
abi.encode(0, cashOutCount, _controller.totalTokenSupplyWithReservedTokensOf(_projectId), specifications)
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
vm.prank(multisig());
|
|
152
|
+
jbFeelessAddresses().setFeelessAddress(address(hook), true);
|
|
153
|
+
|
|
154
|
+
vm.expectRevert(
|
|
155
|
+
abi.encodeWithSelector(
|
|
156
|
+
JBMultiTerminal.JBMultiTerminal_TemporaryAllowanceNotConsumed.selector,
|
|
157
|
+
address(usdcToken()),
|
|
158
|
+
address(hook),
|
|
159
|
+
_HOOK_FORWARD_AMOUNT
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
_terminal.cashOutTokensOf({
|
|
163
|
+
holder: address(this),
|
|
164
|
+
projectId: _projectId,
|
|
165
|
+
cashOutCount: cashOutCount,
|
|
166
|
+
tokenToReclaim: address(usdcToken()),
|
|
167
|
+
minTokensReclaimed: 0,
|
|
168
|
+
beneficiary: payable(address(this)),
|
|
169
|
+
metadata: ""
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function test_SendPayoutsToMultiTerminalAddToBalanceConsumesForwardedAllowance() external {
|
|
174
|
+
uint256 recipientProjectId = _launchProject({
|
|
175
|
+
terminal: _terminal2,
|
|
176
|
+
projectUri: "recipient-add-to-balance",
|
|
177
|
+
metadata: _metadataWithHooks({
|
|
178
|
+
useDataHookForPay: false, useDataHookForCashOut: false, dataHook: address(0)
|
|
179
|
+
}),
|
|
180
|
+
splitGroups: new JBSplitGroup[](0),
|
|
181
|
+
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
uint256 sourceProjectId = _launchProject({
|
|
185
|
+
terminal: _terminal,
|
|
186
|
+
projectUri: "source-add-to-balance",
|
|
187
|
+
metadata: _metadataWithHooks({
|
|
188
|
+
useDataHookForPay: false, useDataHookForCashOut: false, dataHook: address(0)
|
|
189
|
+
}),
|
|
190
|
+
splitGroups: _splitGroupsToProject({targetProjectId: recipientProjectId, preferAddToBalance: true}),
|
|
191
|
+
fundAccessLimitGroups: _usdcPayoutLimitGroups({terminal: _terminal, payoutAmount: _PAYOUT_AMOUNT})
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
usdcToken().mint(address(this), _PAYOUT_AMOUNT);
|
|
195
|
+
usdcToken().approve(address(_terminal), _PAYOUT_AMOUNT);
|
|
196
|
+
|
|
197
|
+
_terminal.pay({
|
|
198
|
+
projectId: sourceProjectId,
|
|
199
|
+
token: address(usdcToken()),
|
|
200
|
+
amount: _PAYOUT_AMOUNT,
|
|
201
|
+
beneficiary: address(this),
|
|
202
|
+
minReturnedTokens: 0,
|
|
203
|
+
memo: "",
|
|
204
|
+
metadata: ""
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
uint256 fee = _PAYOUT_AMOUNT * _terminal.FEE() / JBConstants.MAX_FEE;
|
|
208
|
+
uint256 expectedNetPayout = _PAYOUT_AMOUNT - fee;
|
|
209
|
+
|
|
210
|
+
_terminal.sendPayoutsOf({
|
|
211
|
+
projectId: sourceProjectId,
|
|
212
|
+
amount: _PAYOUT_AMOUNT,
|
|
213
|
+
currency: uint32(uint160(address(usdcToken()))),
|
|
214
|
+
token: address(usdcToken()),
|
|
215
|
+
minTokensPaidOut: 0
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
assertEq(usdcToken().allowance(address(_terminal), address(_terminal2)), 0);
|
|
219
|
+
assertEq(jbTerminalStore().balanceOf(address(_terminal), sourceProjectId, address(usdcToken())), fee);
|
|
220
|
+
assertEq(
|
|
221
|
+
jbTerminalStore().balanceOf(address(_terminal2), recipientProjectId, address(usdcToken())),
|
|
222
|
+
expectedNetPayout
|
|
223
|
+
);
|
|
224
|
+
assertEq(usdcToken().balanceOf(address(_terminal2)), expectedNetPayout);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function test_SendPayoutsToMultiTerminalPayConsumesForwardedAllowance() external {
|
|
228
|
+
uint256 recipientProjectId = _launchProject({
|
|
229
|
+
terminal: _terminal2,
|
|
230
|
+
projectUri: "recipient-pay",
|
|
231
|
+
metadata: _metadataWithHooks({
|
|
232
|
+
useDataHookForPay: false, useDataHookForCashOut: false, dataHook: address(0)
|
|
233
|
+
}),
|
|
234
|
+
splitGroups: new JBSplitGroup[](0),
|
|
235
|
+
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
uint256 sourceProjectId = _launchProject({
|
|
239
|
+
terminal: _terminal,
|
|
240
|
+
projectUri: "source-pay",
|
|
241
|
+
metadata: _metadataWithHooks({
|
|
242
|
+
useDataHookForPay: false, useDataHookForCashOut: false, dataHook: address(0)
|
|
243
|
+
}),
|
|
244
|
+
splitGroups: _splitGroupsToProject({targetProjectId: recipientProjectId, preferAddToBalance: false}),
|
|
245
|
+
fundAccessLimitGroups: _usdcPayoutLimitGroups({terminal: _terminal, payoutAmount: _PAYOUT_AMOUNT})
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
usdcToken().mint(address(this), _PAYOUT_AMOUNT);
|
|
249
|
+
usdcToken().approve(address(_terminal), _PAYOUT_AMOUNT);
|
|
250
|
+
|
|
251
|
+
_terminal.pay({
|
|
252
|
+
projectId: sourceProjectId,
|
|
253
|
+
token: address(usdcToken()),
|
|
254
|
+
amount: _PAYOUT_AMOUNT,
|
|
255
|
+
beneficiary: address(this),
|
|
256
|
+
minReturnedTokens: 0,
|
|
257
|
+
memo: "",
|
|
258
|
+
metadata: ""
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
uint256 fee = _PAYOUT_AMOUNT * _terminal.FEE() / JBConstants.MAX_FEE;
|
|
262
|
+
uint256 expectedNetPayout = _PAYOUT_AMOUNT - fee;
|
|
263
|
+
|
|
264
|
+
_terminal.sendPayoutsOf({
|
|
265
|
+
projectId: sourceProjectId,
|
|
266
|
+
amount: _PAYOUT_AMOUNT,
|
|
267
|
+
currency: uint32(uint160(address(usdcToken()))),
|
|
268
|
+
token: address(usdcToken()),
|
|
269
|
+
minTokensPaidOut: 0
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
assertEq(usdcToken().allowance(address(_terminal), address(_terminal2)), 0);
|
|
273
|
+
assertEq(jbTerminalStore().balanceOf(address(_terminal), sourceProjectId, address(usdcToken())), fee);
|
|
274
|
+
assertEq(
|
|
275
|
+
jbTerminalStore().balanceOf(address(_terminal2), recipientProjectId, address(usdcToken())),
|
|
276
|
+
expectedNetPayout
|
|
277
|
+
);
|
|
278
|
+
assertEq(usdcToken().balanceOf(address(_terminal2)), expectedNetPayout);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function _launchProject(
|
|
282
|
+
IJBMultiTerminal terminal,
|
|
283
|
+
string memory projectUri,
|
|
284
|
+
JBRulesetMetadata memory metadata,
|
|
285
|
+
JBSplitGroup[] memory splitGroups,
|
|
286
|
+
JBFundAccessLimitGroup[] memory fundAccessLimitGroups
|
|
287
|
+
)
|
|
288
|
+
internal
|
|
289
|
+
returns (uint256)
|
|
290
|
+
{
|
|
291
|
+
JBRulesetConfig[] memory rulesetConfigurations = new JBRulesetConfig[](1);
|
|
292
|
+
rulesetConfigurations[0].mustStartAtOrAfter = 0;
|
|
293
|
+
rulesetConfigurations[0].duration = 0;
|
|
294
|
+
rulesetConfigurations[0].weight = _WEIGHT;
|
|
295
|
+
rulesetConfigurations[0].weightCutPercent = 0;
|
|
296
|
+
rulesetConfigurations[0].approvalHook = IJBRulesetApprovalHook(address(0));
|
|
297
|
+
rulesetConfigurations[0].metadata = metadata;
|
|
298
|
+
rulesetConfigurations[0].splitGroups = splitGroups;
|
|
299
|
+
rulesetConfigurations[0].fundAccessLimitGroups = fundAccessLimitGroups;
|
|
300
|
+
|
|
301
|
+
JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
|
|
302
|
+
terminalConfigurations[0] =
|
|
303
|
+
JBTerminalConfig({terminal: terminal, accountingContextsToAccept: _usdcAccountingContexts()});
|
|
304
|
+
|
|
305
|
+
return _controller.launchProjectFor({
|
|
306
|
+
owner: _projectOwner,
|
|
307
|
+
projectUri: projectUri,
|
|
308
|
+
rulesetConfigurations: rulesetConfigurations,
|
|
309
|
+
terminalConfigurations: terminalConfigurations,
|
|
310
|
+
memo: ""
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function _metadataWithHooks(
|
|
315
|
+
bool useDataHookForPay,
|
|
316
|
+
bool useDataHookForCashOut,
|
|
317
|
+
address dataHook
|
|
318
|
+
)
|
|
319
|
+
internal
|
|
320
|
+
view
|
|
321
|
+
returns (JBRulesetMetadata memory)
|
|
322
|
+
{
|
|
323
|
+
return JBRulesetMetadata({
|
|
324
|
+
reservedPercent: 0,
|
|
325
|
+
cashOutTaxRate: 0,
|
|
326
|
+
baseCurrency: uint32(uint160(address(usdcToken()))),
|
|
327
|
+
pausePay: false,
|
|
328
|
+
pauseCreditTransfers: false,
|
|
329
|
+
allowOwnerMinting: false,
|
|
330
|
+
allowSetCustomToken: false,
|
|
331
|
+
allowTerminalMigration: false,
|
|
332
|
+
allowSetTerminals: false,
|
|
333
|
+
ownerMustSendPayouts: false,
|
|
334
|
+
allowSetController: false,
|
|
335
|
+
allowAddAccountingContext: true,
|
|
336
|
+
allowAddPriceFeed: false,
|
|
337
|
+
holdFees: false,
|
|
338
|
+
useTotalSurplusForCashOuts: false,
|
|
339
|
+
useDataHookForPay: useDataHookForPay,
|
|
340
|
+
useDataHookForCashOut: useDataHookForCashOut,
|
|
341
|
+
dataHook: dataHook,
|
|
342
|
+
metadata: 0
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function _splitGroupsToProject(
|
|
347
|
+
uint256 targetProjectId,
|
|
348
|
+
bool preferAddToBalance
|
|
349
|
+
)
|
|
350
|
+
internal
|
|
351
|
+
view
|
|
352
|
+
returns (JBSplitGroup[] memory)
|
|
353
|
+
{
|
|
354
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
355
|
+
splits[0].percent = uint32(JBConstants.SPLITS_TOTAL_PERCENT);
|
|
356
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
357
|
+
splits[0].projectId = uint64(targetProjectId);
|
|
358
|
+
splits[0].beneficiary = payable(address(0));
|
|
359
|
+
splits[0].preferAddToBalance = preferAddToBalance;
|
|
360
|
+
splits[0].lockedUntil = 0;
|
|
361
|
+
splits[0].hook = IJBSplitHook(address(0));
|
|
362
|
+
|
|
363
|
+
JBSplitGroup[] memory splitGroups = new JBSplitGroup[](1);
|
|
364
|
+
splitGroups[0] = JBSplitGroup({groupId: uint256(uint160(address(usdcToken()))), splits: splits});
|
|
365
|
+
|
|
366
|
+
return splitGroups;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function _usdcAccountingContexts() internal view returns (JBAccountingContext[] memory) {
|
|
370
|
+
JBAccountingContext[] memory accountingContexts = new JBAccountingContext[](1);
|
|
371
|
+
accountingContexts[0] = JBAccountingContext({
|
|
372
|
+
token: address(usdcToken()),
|
|
373
|
+
decimals: usdcToken().decimals(),
|
|
374
|
+
currency: uint32(uint160(address(usdcToken())))
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
return accountingContexts;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function _usdcPayoutLimitGroups(
|
|
381
|
+
IJBMultiTerminal terminal,
|
|
382
|
+
uint256 payoutAmount
|
|
383
|
+
)
|
|
384
|
+
internal
|
|
385
|
+
view
|
|
386
|
+
returns (JBFundAccessLimitGroup[] memory)
|
|
387
|
+
{
|
|
388
|
+
JBCurrencyAmount[] memory payoutLimits = new JBCurrencyAmount[](1);
|
|
389
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
390
|
+
payoutLimits[0] =
|
|
391
|
+
JBCurrencyAmount({amount: uint224(payoutAmount), currency: uint32(uint160(address(usdcToken())))});
|
|
392
|
+
|
|
393
|
+
JBFundAccessLimitGroup[] memory fundAccessLimitGroups = new JBFundAccessLimitGroup[](1);
|
|
394
|
+
fundAccessLimitGroups[0] = JBFundAccessLimitGroup({
|
|
395
|
+
terminal: address(terminal),
|
|
396
|
+
token: address(usdcToken()),
|
|
397
|
+
payoutLimits: payoutLimits,
|
|
398
|
+
surplusAllowances: new JBCurrencyAmount[](0)
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
return fundAccessLimitGroups;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
contract NonConsumingPayHook is ERC165, IJBPayHook {
|
|
406
|
+
function afterPayRecordedWith(JBAfterPayRecordedContext calldata) external payable override {}
|
|
407
|
+
|
|
408
|
+
function supportsInterface(bytes4 interfaceId) public view override(ERC165, IERC165) returns (bool) {
|
|
409
|
+
return interfaceId == type(IJBPayHook).interfaceId || super.supportsInterface(interfaceId);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
contract NonConsumingCashOutHook is ERC165, IJBCashOutHook {
|
|
414
|
+
function afterCashOutRecordedWith(JBAfterCashOutRecordedContext calldata) external payable override {}
|
|
415
|
+
|
|
416
|
+
function supportsInterface(bytes4 interfaceId) public view override(ERC165, IERC165) returns (bool) {
|
|
417
|
+
return interfaceId == type(IJBCashOutHook).interfaceId || super.supportsInterface(interfaceId);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.6;
|
|
3
|
+
|
|
4
|
+
import {TestBaseWorkflow} from "../helpers/TestBaseWorkflow.sol";
|
|
5
|
+
import {IJBController} from "../../src/interfaces/IJBController.sol";
|
|
6
|
+
import {IJBDirectory} from "../../src/interfaces/IJBDirectory.sol";
|
|
7
|
+
import {IJBTerminal} from "../../src/interfaces/IJBTerminal.sol";
|
|
8
|
+
import {JBMultiTerminal} from "../../src/JBMultiTerminal.sol";
|
|
9
|
+
import {JBConstants} from "../../src/libraries/JBConstants.sol";
|
|
10
|
+
import {JBAccountingContext} from "../../src/structs/JBAccountingContext.sol";
|
|
11
|
+
import {JBFundAccessLimitGroup} from "../../src/structs/JBFundAccessLimitGroup.sol";
|
|
12
|
+
import {JBRulesetConfig} from "../../src/structs/JBRulesetConfig.sol";
|
|
13
|
+
import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
|
|
14
|
+
import {JBSplitGroup} from "../../src/structs/JBSplitGroup.sol";
|
|
15
|
+
import {JBTerminalConfig} from "../../src/structs/JBTerminalConfig.sol";
|
|
16
|
+
import {IJBRulesetApprovalHook} from "../../src/interfaces/IJBRulesetApprovalHook.sol";
|
|
17
|
+
|
|
18
|
+
/// @notice Verifies that `useTotalSurplusForCashOuts` trusts every terminal in the directory,
|
|
19
|
+
/// even though settlement still comes from the specific terminal the holder cashes out through.
|
|
20
|
+
contract CrossTerminalSurplusSpoof_Local is TestBaseWorkflow {
|
|
21
|
+
IJBController private _controller;
|
|
22
|
+
IJBDirectory private _directory;
|
|
23
|
+
JBMultiTerminal private _terminal;
|
|
24
|
+
address private _projectOwner;
|
|
25
|
+
address private _holder;
|
|
26
|
+
uint32 private _nativeCurrency;
|
|
27
|
+
uint256 private _projectId;
|
|
28
|
+
|
|
29
|
+
function setUp() public override {
|
|
30
|
+
super.setUp();
|
|
31
|
+
|
|
32
|
+
_controller = jbController();
|
|
33
|
+
_directory = jbDirectory();
|
|
34
|
+
_terminal = jbMultiTerminal();
|
|
35
|
+
_projectOwner = multisig();
|
|
36
|
+
_holder = beneficiary();
|
|
37
|
+
_nativeCurrency = uint32(uint160(JBConstants.NATIVE_TOKEN));
|
|
38
|
+
|
|
39
|
+
JBRulesetMetadata memory metadata = JBRulesetMetadata({
|
|
40
|
+
reservedPercent: 0,
|
|
41
|
+
cashOutTaxRate: 0,
|
|
42
|
+
baseCurrency: _nativeCurrency,
|
|
43
|
+
pausePay: false,
|
|
44
|
+
pauseCreditTransfers: false,
|
|
45
|
+
allowOwnerMinting: true,
|
|
46
|
+
allowSetCustomToken: true,
|
|
47
|
+
allowTerminalMigration: false,
|
|
48
|
+
allowSetTerminals: true,
|
|
49
|
+
allowSetController: false,
|
|
50
|
+
allowAddAccountingContext: true,
|
|
51
|
+
allowAddPriceFeed: false,
|
|
52
|
+
ownerMustSendPayouts: false,
|
|
53
|
+
holdFees: false,
|
|
54
|
+
useTotalSurplusForCashOuts: true,
|
|
55
|
+
useDataHookForPay: false,
|
|
56
|
+
useDataHookForCashOut: false,
|
|
57
|
+
dataHook: address(0),
|
|
58
|
+
metadata: 0
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
JBRulesetConfig[] memory rulesetConfigs = new JBRulesetConfig[](1);
|
|
62
|
+
rulesetConfigs[0] = JBRulesetConfig({
|
|
63
|
+
mustStartAtOrAfter: 0,
|
|
64
|
+
duration: 0,
|
|
65
|
+
weight: 1000e18,
|
|
66
|
+
weightCutPercent: 0,
|
|
67
|
+
approvalHook: IJBRulesetApprovalHook(address(0)),
|
|
68
|
+
metadata: metadata,
|
|
69
|
+
splitGroups: new JBSplitGroup[](0),
|
|
70
|
+
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
JBAccountingContext[] memory contexts = new JBAccountingContext[](1);
|
|
74
|
+
contexts[0] = JBAccountingContext({token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: _nativeCurrency});
|
|
75
|
+
|
|
76
|
+
JBTerminalConfig[] memory terminalConfigs = new JBTerminalConfig[](1);
|
|
77
|
+
terminalConfigs[0] = JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: contexts});
|
|
78
|
+
|
|
79
|
+
_projectId = _controller.launchProjectFor({
|
|
80
|
+
owner: _projectOwner,
|
|
81
|
+
projectUri: "spoofed-surplus",
|
|
82
|
+
rulesetConfigurations: rulesetConfigs,
|
|
83
|
+
terminalConfigurations: terminalConfigs,
|
|
84
|
+
memo: ""
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function test_partialCashOutCanDrainLocalTerminalUsingSpoofedSiblingSurplus() external {
|
|
89
|
+
vm.deal(_holder, 1 ether);
|
|
90
|
+
|
|
91
|
+
vm.prank(_holder);
|
|
92
|
+
uint256 minted = _terminal.pay{value: 1 ether}({
|
|
93
|
+
projectId: _projectId,
|
|
94
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
95
|
+
amount: 1 ether,
|
|
96
|
+
beneficiary: _holder,
|
|
97
|
+
minReturnedTokens: 0,
|
|
98
|
+
memo: "",
|
|
99
|
+
metadata: ""
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
assertEq(address(_terminal).balance, 1 ether, "terminal should hold the paid ETH");
|
|
103
|
+
|
|
104
|
+
address spoofedTerminal = makeAddr("spoofedTerminal");
|
|
105
|
+
IJBTerminal[] memory terminals = new IJBTerminal[](2);
|
|
106
|
+
terminals[0] = IJBTerminal(address(_terminal));
|
|
107
|
+
terminals[1] = IJBTerminal(spoofedTerminal);
|
|
108
|
+
|
|
109
|
+
vm.prank(_projectOwner);
|
|
110
|
+
_directory.setTerminalsOf(_projectId, terminals);
|
|
111
|
+
|
|
112
|
+
vm.mockCall(
|
|
113
|
+
spoofedTerminal,
|
|
114
|
+
abi.encodeCall(IJBTerminal.currentSurplusOf, (_projectId, new address[](0), 18, _nativeCurrency)),
|
|
115
|
+
abi.encode(1 ether)
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
uint256 holderBalanceBefore = _holder.balance;
|
|
119
|
+
|
|
120
|
+
vm.prank(_holder);
|
|
121
|
+
uint256 reclaimed = _terminal.cashOutTokensOf({
|
|
122
|
+
holder: _holder,
|
|
123
|
+
projectId: _projectId,
|
|
124
|
+
cashOutCount: minted / 2,
|
|
125
|
+
tokenToReclaim: JBConstants.NATIVE_TOKEN,
|
|
126
|
+
minTokensReclaimed: 0,
|
|
127
|
+
beneficiary: payable(_holder),
|
|
128
|
+
metadata: new bytes(0)
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
assertEq(reclaimed, 1 ether, "spoofed global surplus should let a half burn reclaim the full local balance");
|
|
132
|
+
assertEq(_holder.balance - holderBalanceBefore, 1 ether, "holder should receive the full terminal balance");
|
|
133
|
+
assertEq(address(_terminal).balance, 0, "the honest terminal should be fully drained");
|
|
134
|
+
assertEq(
|
|
135
|
+
jbTokens().totalBalanceOf(_holder, _projectId),
|
|
136
|
+
minted / 2,
|
|
137
|
+
"the holder should keep half their project tokens after draining the terminal"
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|