@bananapus/721-hook-v6 0.0.13 → 0.0.14
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/ARCHITECTURE.md +7 -2
- package/RISKS.md +6 -6
- package/SKILLS.md +3 -2
- package/STYLE_GUIDE.md +131 -43
- package/foundry.toml +3 -3
- package/package.json +5 -5
- package/remappings.txt +1 -1
- package/script/Deploy.s.sol +1 -1
- package/script/helpers/Hook721DeploymentLib.sol +1 -1
- package/src/JB721TiersHook.sol +23 -0
- package/src/libraries/JB721TiersHookLib.sol +44 -0
- package/test/Fork.t.sol +13 -18
- package/test/fork/ERC20TierSplitFork.t.sol +537 -0
- package/test/invariants/TierLifecycleInvariant.t.sol +0 -2
- package/test/unit/pay_CrossCurrency_Unit.t.sol +498 -0
- package/test/unit/tierSplitRouting_Unit.t.sol +257 -0
- /package/test/regression/{L35_CacheTierLookup.t.sol → CacheTierLookup.t.sol} +0 -0
- /package/test/regression/{L34_ReserveBeneficiaryOverwrite.t.sol → ReserveBeneficiaryOverwrite.t.sol} +0 -0
- /package/test/regression/{L36_SplitNoBeneficiary.t.sol → SplitNoBeneficiary.t.sol} +0 -0
- /package/test/unit/{M6_TierSupplyCheck.t.sol → TierSupplyReserveCheck.t.sol} +0 -0
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.26;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
|
|
6
|
+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
|
7
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
8
|
+
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|
9
|
+
|
|
10
|
+
import "@bananapus/core-v6/src/JBController.sol";
|
|
11
|
+
import "@bananapus/core-v6/src/JBDirectory.sol";
|
|
12
|
+
import "@bananapus/core-v6/src/JBMultiTerminal.sol";
|
|
13
|
+
import "@bananapus/core-v6/src/JBFundAccessLimits.sol";
|
|
14
|
+
import "@bananapus/core-v6/src/JBFeelessAddresses.sol";
|
|
15
|
+
import "@bananapus/core-v6/src/JBTerminalStore.sol";
|
|
16
|
+
import "@bananapus/core-v6/src/JBRulesets.sol";
|
|
17
|
+
import "@bananapus/core-v6/src/JBPermissions.sol";
|
|
18
|
+
import "@bananapus/core-v6/src/JBPrices.sol";
|
|
19
|
+
import {JBProjects} from "@bananapus/core-v6/src/JBProjects.sol";
|
|
20
|
+
import "@bananapus/core-v6/src/JBSplits.sol";
|
|
21
|
+
import "@bananapus/core-v6/src/JBERC20.sol";
|
|
22
|
+
import "@bananapus/core-v6/src/JBTokens.sol";
|
|
23
|
+
import "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
24
|
+
import "@bananapus/core-v6/src/libraries/JBRulesetMetadataResolver.sol";
|
|
25
|
+
import "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
26
|
+
import "@bananapus/core-v6/src/structs/JBTerminalConfig.sol";
|
|
27
|
+
import "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
28
|
+
import "@bananapus/core-v6/src/structs/JBFundAccessLimitGroup.sol";
|
|
29
|
+
import "@bananapus/core-v6/src/interfaces/IJBRulesetApprovalHook.sol";
|
|
30
|
+
import "@bananapus/core-v6/src/interfaces/IJBTerminal.sol";
|
|
31
|
+
import "@bananapus/core-v6/src/interfaces/IJBSplitHook.sol";
|
|
32
|
+
import "@bananapus/permission-ids-v6/src/JBPermissionIds.sol";
|
|
33
|
+
import {MetadataResolverHelper} from "@bananapus/core-v6/test/helpers/MetadataResolverHelper.sol";
|
|
34
|
+
import {JBMetadataResolver} from "@bananapus/core-v6/src/libraries/JBMetadataResolver.sol";
|
|
35
|
+
|
|
36
|
+
import "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
37
|
+
|
|
38
|
+
import "../../src/JB721TiersHook.sol";
|
|
39
|
+
import "../../src/JB721TiersHookDeployer.sol";
|
|
40
|
+
import "../../src/JB721TiersHookProjectDeployer.sol";
|
|
41
|
+
import "../../src/JB721TiersHookStore.sol";
|
|
42
|
+
import "../../src/interfaces/IJB721TiersHook.sol";
|
|
43
|
+
import "../../src/structs/JBDeploy721TiersHookConfig.sol";
|
|
44
|
+
import "../../src/structs/JBLaunchProjectConfig.sol";
|
|
45
|
+
import "../../src/structs/JBPayDataHookRulesetConfig.sol";
|
|
46
|
+
import "../../src/structs/JBPayDataHookRulesetMetadata.sol";
|
|
47
|
+
|
|
48
|
+
/// @notice Mock ERC20 with 6 decimals (USDC-like).
|
|
49
|
+
contract MockUSDC6 is ERC20 {
|
|
50
|
+
constructor() ERC20("Mock USDC", "USDC") {}
|
|
51
|
+
|
|
52
|
+
function decimals() public pure override returns (uint8) {
|
|
53
|
+
return 6;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function mint(address to, uint256 amount) external {
|
|
57
|
+
_mint(to, amount);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// @title ERC20TierSplitFork
|
|
62
|
+
/// @notice Fork tests for ERC20 tier split distribution in JB721TiersHook.
|
|
63
|
+
/// @dev Run with: forge test --match-contract ERC20TierSplitFork -vvv --fork-url $RPC
|
|
64
|
+
contract ERC20TierSplitFork is Test {
|
|
65
|
+
using JBRulesetMetadataResolver for JBRuleset;
|
|
66
|
+
|
|
67
|
+
// Actors
|
|
68
|
+
address multisig = address(0xBEEF);
|
|
69
|
+
address payer = makeAddr("payer");
|
|
70
|
+
address beneficiary = makeAddr("beneficiary");
|
|
71
|
+
address splitBeneficiary = makeAddr("splitBeneficiary");
|
|
72
|
+
address reserveBeneficiary = makeAddr("reserveBeneficiary");
|
|
73
|
+
|
|
74
|
+
// JB Core
|
|
75
|
+
JBPermissions jbPermissions;
|
|
76
|
+
JBProjects jbProjects;
|
|
77
|
+
JBDirectory jbDirectory;
|
|
78
|
+
JBRulesets jbRulesets;
|
|
79
|
+
JBTokens jbTokens;
|
|
80
|
+
JBSplits jbSplits;
|
|
81
|
+
JBFundAccessLimits jbFundAccessLimits;
|
|
82
|
+
JBFeelessAddresses jbFeelessAddresses;
|
|
83
|
+
JBPrices jbPrices;
|
|
84
|
+
JBController jbController;
|
|
85
|
+
JBTerminalStore jbTerminalStore;
|
|
86
|
+
JBMultiTerminal jbMultiTerminal;
|
|
87
|
+
|
|
88
|
+
// 721 Hook
|
|
89
|
+
JB721TiersHookStore store;
|
|
90
|
+
JB721TiersHook hookImpl;
|
|
91
|
+
JB721TiersHookDeployer hookDeployer;
|
|
92
|
+
JB721TiersHookProjectDeployer projectDeployer;
|
|
93
|
+
MetadataResolverHelper metadataHelper;
|
|
94
|
+
JBAddressRegistry addressRegistry;
|
|
95
|
+
|
|
96
|
+
// Token
|
|
97
|
+
MockUSDC6 usdc;
|
|
98
|
+
|
|
99
|
+
receive() external payable {}
|
|
100
|
+
|
|
101
|
+
function setUp() public {
|
|
102
|
+
vm.createSelectFork("ethereum");
|
|
103
|
+
|
|
104
|
+
_deployJBCore();
|
|
105
|
+
_deploy721Hook();
|
|
106
|
+
|
|
107
|
+
usdc = new MockUSDC6();
|
|
108
|
+
usdc.mint(payer, 100_000e6);
|
|
109
|
+
|
|
110
|
+
vm.deal(payer, 10 ether);
|
|
111
|
+
vm.deal(multisig, 10 ether);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function _deployJBCore() internal {
|
|
115
|
+
jbPermissions = new JBPermissions(address(0));
|
|
116
|
+
jbProjects = new JBProjects(multisig, address(0), address(0));
|
|
117
|
+
jbDirectory = new JBDirectory(jbPermissions, jbProjects, multisig);
|
|
118
|
+
JBERC20 jbErc20 = new JBERC20();
|
|
119
|
+
jbTokens = new JBTokens(jbDirectory, jbErc20);
|
|
120
|
+
jbRulesets = new JBRulesets(jbDirectory);
|
|
121
|
+
jbPrices = new JBPrices(jbDirectory, jbPermissions, jbProjects, multisig, address(0));
|
|
122
|
+
jbSplits = new JBSplits(jbDirectory);
|
|
123
|
+
jbFundAccessLimits = new JBFundAccessLimits(jbDirectory);
|
|
124
|
+
jbFeelessAddresses = new JBFeelessAddresses(multisig);
|
|
125
|
+
|
|
126
|
+
jbController = new JBController(
|
|
127
|
+
jbDirectory,
|
|
128
|
+
jbFundAccessLimits,
|
|
129
|
+
jbPermissions,
|
|
130
|
+
jbPrices,
|
|
131
|
+
jbProjects,
|
|
132
|
+
jbRulesets,
|
|
133
|
+
jbSplits,
|
|
134
|
+
jbTokens,
|
|
135
|
+
address(0),
|
|
136
|
+
address(0)
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
vm.prank(multisig);
|
|
140
|
+
jbDirectory.setIsAllowedToSetFirstController(address(jbController), true);
|
|
141
|
+
|
|
142
|
+
jbTerminalStore = new JBTerminalStore(jbDirectory, jbPrices, jbRulesets);
|
|
143
|
+
|
|
144
|
+
jbMultiTerminal = new JBMultiTerminal(
|
|
145
|
+
jbFeelessAddresses,
|
|
146
|
+
jbPermissions,
|
|
147
|
+
jbProjects,
|
|
148
|
+
jbSplits,
|
|
149
|
+
jbTerminalStore,
|
|
150
|
+
jbTokens,
|
|
151
|
+
IPermit2(address(0)),
|
|
152
|
+
address(0)
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function _deploy721Hook() internal {
|
|
157
|
+
store = new JB721TiersHookStore();
|
|
158
|
+
hookImpl =
|
|
159
|
+
new JB721TiersHook(jbDirectory, jbPermissions, jbRulesets, store, IJBSplits(address(jbSplits)), address(0));
|
|
160
|
+
addressRegistry = new JBAddressRegistry();
|
|
161
|
+
hookDeployer = new JB721TiersHookDeployer(hookImpl, store, addressRegistry, address(0));
|
|
162
|
+
projectDeployer = new JB721TiersHookProjectDeployer(
|
|
163
|
+
IJBDirectory(jbDirectory), IJBPermissions(jbPermissions), hookDeployer, address(0)
|
|
164
|
+
);
|
|
165
|
+
metadataHelper = new MetadataResolverHelper();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// =========================================================================
|
|
169
|
+
// Launch Helper
|
|
170
|
+
// =========================================================================
|
|
171
|
+
|
|
172
|
+
function _launchERC20Project(
|
|
173
|
+
JB721TierConfig[] memory tierConfigs,
|
|
174
|
+
address token,
|
|
175
|
+
uint8 tokenDecimals
|
|
176
|
+
)
|
|
177
|
+
internal
|
|
178
|
+
returns (uint256 projectId, address dataHook)
|
|
179
|
+
{
|
|
180
|
+
uint32 currency = uint32(uint160(token));
|
|
181
|
+
|
|
182
|
+
JBDeploy721TiersHookConfig memory hookConfig = JBDeploy721TiersHookConfig({
|
|
183
|
+
name: "TestNFT",
|
|
184
|
+
symbol: "TNFT",
|
|
185
|
+
baseUri: "ipfs://base/",
|
|
186
|
+
tokenUriResolver: IJB721TokenUriResolver(address(0)),
|
|
187
|
+
contractUri: "ipfs://contract",
|
|
188
|
+
tiersConfig: JB721InitTiersConfig({
|
|
189
|
+
tiers: tierConfigs, currency: currency, decimals: tokenDecimals, prices: IJBPrices(address(0))
|
|
190
|
+
}),
|
|
191
|
+
reserveBeneficiary: reserveBeneficiary,
|
|
192
|
+
flags: JB721TiersHookFlags({
|
|
193
|
+
preventOverspending: false,
|
|
194
|
+
issueTokensForSplits: false,
|
|
195
|
+
noNewTiersWithReserves: false,
|
|
196
|
+
noNewTiersWithVotes: false,
|
|
197
|
+
noNewTiersWithOwnerMinting: false
|
|
198
|
+
})
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
JBPayDataHookRulesetMetadata memory rulesetMetadata = JBPayDataHookRulesetMetadata({
|
|
202
|
+
reservedPercent: 0,
|
|
203
|
+
cashOutTaxRate: 0,
|
|
204
|
+
baseCurrency: currency,
|
|
205
|
+
pausePay: false,
|
|
206
|
+
pauseCreditTransfers: false,
|
|
207
|
+
allowOwnerMinting: true,
|
|
208
|
+
allowTerminalMigration: false,
|
|
209
|
+
allowSetTerminals: false,
|
|
210
|
+
allowSetController: false,
|
|
211
|
+
allowAddAccountingContext: false,
|
|
212
|
+
allowAddPriceFeed: false,
|
|
213
|
+
ownerMustSendPayouts: false,
|
|
214
|
+
holdFees: false,
|
|
215
|
+
useTotalSurplusForCashOuts: false,
|
|
216
|
+
useDataHookForCashOut: false,
|
|
217
|
+
metadata: 0x00
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
JBPayDataHookRulesetConfig[] memory rulesetConfigs = new JBPayDataHookRulesetConfig[](1);
|
|
221
|
+
rulesetConfigs[0].mustStartAtOrAfter = 0;
|
|
222
|
+
rulesetConfigs[0].duration = 0;
|
|
223
|
+
rulesetConfigs[0].weight = 1_000_000e18;
|
|
224
|
+
rulesetConfigs[0].weightCutPercent = 0;
|
|
225
|
+
rulesetConfigs[0].approvalHook = IJBRulesetApprovalHook(address(0));
|
|
226
|
+
rulesetConfigs[0].metadata = rulesetMetadata;
|
|
227
|
+
|
|
228
|
+
JBAccountingContext[] memory accountingContexts = new JBAccountingContext[](1);
|
|
229
|
+
accountingContexts[0] = JBAccountingContext({token: token, currency: currency, decimals: tokenDecimals});
|
|
230
|
+
|
|
231
|
+
JBTerminalConfig[] memory terminalConfigs = new JBTerminalConfig[](1);
|
|
232
|
+
terminalConfigs[0] =
|
|
233
|
+
JBTerminalConfig({terminal: jbMultiTerminal, accountingContextsToAccept: accountingContexts});
|
|
234
|
+
|
|
235
|
+
JBLaunchProjectConfig memory launchConfig = JBLaunchProjectConfig({
|
|
236
|
+
projectUri: "test-erc20-project",
|
|
237
|
+
rulesetConfigurations: rulesetConfigs,
|
|
238
|
+
terminalConfigurations: terminalConfigs,
|
|
239
|
+
memo: ""
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
IJB721TiersHook hookInstance;
|
|
243
|
+
(projectId, hookInstance) =
|
|
244
|
+
projectDeployer.launchProjectFor(multisig, hookConfig, launchConfig, jbController, bytes32(0));
|
|
245
|
+
|
|
246
|
+
dataHook = address(hookInstance);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/// @dev Launch with ETH accounting (for regression test).
|
|
250
|
+
function _launchETHProject(JB721TierConfig[] memory tierConfigs)
|
|
251
|
+
internal
|
|
252
|
+
returns (uint256 projectId, address dataHook)
|
|
253
|
+
{
|
|
254
|
+
JBDeploy721TiersHookConfig memory hookConfig = JBDeploy721TiersHookConfig({
|
|
255
|
+
name: "TestNFT",
|
|
256
|
+
symbol: "TNFT",
|
|
257
|
+
baseUri: "ipfs://base/",
|
|
258
|
+
tokenUriResolver: IJB721TokenUriResolver(address(0)),
|
|
259
|
+
contractUri: "ipfs://contract",
|
|
260
|
+
tiersConfig: JB721InitTiersConfig({
|
|
261
|
+
tiers: tierConfigs,
|
|
262
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
263
|
+
decimals: 18,
|
|
264
|
+
prices: IJBPrices(address(0))
|
|
265
|
+
}),
|
|
266
|
+
reserveBeneficiary: reserveBeneficiary,
|
|
267
|
+
flags: JB721TiersHookFlags({
|
|
268
|
+
preventOverspending: false,
|
|
269
|
+
issueTokensForSplits: false,
|
|
270
|
+
noNewTiersWithReserves: false,
|
|
271
|
+
noNewTiersWithVotes: false,
|
|
272
|
+
noNewTiersWithOwnerMinting: false
|
|
273
|
+
})
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
JBPayDataHookRulesetMetadata memory rulesetMetadata = JBPayDataHookRulesetMetadata({
|
|
277
|
+
reservedPercent: 0,
|
|
278
|
+
cashOutTaxRate: 0,
|
|
279
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
280
|
+
pausePay: false,
|
|
281
|
+
pauseCreditTransfers: false,
|
|
282
|
+
allowOwnerMinting: true,
|
|
283
|
+
allowTerminalMigration: false,
|
|
284
|
+
allowSetTerminals: false,
|
|
285
|
+
allowSetController: false,
|
|
286
|
+
allowAddAccountingContext: false,
|
|
287
|
+
allowAddPriceFeed: false,
|
|
288
|
+
ownerMustSendPayouts: false,
|
|
289
|
+
holdFees: false,
|
|
290
|
+
useTotalSurplusForCashOuts: false,
|
|
291
|
+
useDataHookForCashOut: false,
|
|
292
|
+
metadata: 0x00
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
JBPayDataHookRulesetConfig[] memory rulesetConfigs = new JBPayDataHookRulesetConfig[](1);
|
|
296
|
+
rulesetConfigs[0].mustStartAtOrAfter = 0;
|
|
297
|
+
rulesetConfigs[0].duration = 0;
|
|
298
|
+
rulesetConfigs[0].weight = 1_000_000e18;
|
|
299
|
+
rulesetConfigs[0].weightCutPercent = 0;
|
|
300
|
+
rulesetConfigs[0].approvalHook = IJBRulesetApprovalHook(address(0));
|
|
301
|
+
rulesetConfigs[0].metadata = rulesetMetadata;
|
|
302
|
+
|
|
303
|
+
JBAccountingContext[] memory accountingContexts = new JBAccountingContext[](1);
|
|
304
|
+
accountingContexts[0] = JBAccountingContext({
|
|
305
|
+
token: JBConstants.NATIVE_TOKEN, currency: uint32(uint160(JBConstants.NATIVE_TOKEN)), decimals: 18
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
JBTerminalConfig[] memory terminalConfigs = new JBTerminalConfig[](1);
|
|
309
|
+
terminalConfigs[0] =
|
|
310
|
+
JBTerminalConfig({terminal: jbMultiTerminal, accountingContextsToAccept: accountingContexts});
|
|
311
|
+
|
|
312
|
+
JBLaunchProjectConfig memory launchConfig = JBLaunchProjectConfig({
|
|
313
|
+
projectUri: "test-eth-project",
|
|
314
|
+
rulesetConfigurations: rulesetConfigs,
|
|
315
|
+
terminalConfigurations: terminalConfigs,
|
|
316
|
+
memo: ""
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
IJB721TiersHook hookInstance;
|
|
320
|
+
(projectId, hookInstance) =
|
|
321
|
+
projectDeployer.launchProjectFor(multisig, hookConfig, launchConfig, jbController, bytes32(0));
|
|
322
|
+
|
|
323
|
+
dataHook = address(hookInstance);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// =========================================================================
|
|
327
|
+
// Metadata Helper
|
|
328
|
+
// =========================================================================
|
|
329
|
+
|
|
330
|
+
function _buildPayMetadata(uint16[] memory tierIds, bool allowOverspending) internal view returns (bytes memory) {
|
|
331
|
+
bytes[] memory data = new bytes[](1);
|
|
332
|
+
data[0] = abi.encode(allowOverspending, tierIds);
|
|
333
|
+
bytes4[] memory ids = new bytes4[](1);
|
|
334
|
+
ids[0] = JBMetadataResolver.getId("pay", address(hookImpl));
|
|
335
|
+
return metadataHelper.createMetadata(ids, data);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function _tokenId(uint256 tierId, uint256 mintNumber) internal pure returns (uint256) {
|
|
339
|
+
return tierId * 1_000_000_000 + mintNumber;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// =========================================================================
|
|
343
|
+
// Test 1: USDC payment with tier split to beneficiary
|
|
344
|
+
// =========================================================================
|
|
345
|
+
|
|
346
|
+
function test_fork_usdcPayment_tierSplitToBeneficiary() public {
|
|
347
|
+
// Create a tier: 100 USDC, 30% split to splitBeneficiary.
|
|
348
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
349
|
+
splits[0] = JBSplit({
|
|
350
|
+
percent: uint32(JBConstants.SPLITS_TOTAL_PERCENT),
|
|
351
|
+
projectId: 0,
|
|
352
|
+
beneficiary: payable(splitBeneficiary),
|
|
353
|
+
preferAddToBalance: false,
|
|
354
|
+
lockedUntil: 0,
|
|
355
|
+
hook: IJBSplitHook(address(0))
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
|
|
359
|
+
tierConfigs[0] = JB721TierConfig({
|
|
360
|
+
price: 100e6,
|
|
361
|
+
initialSupply: 100,
|
|
362
|
+
votingUnits: 0,
|
|
363
|
+
reserveFrequency: 0,
|
|
364
|
+
reserveBeneficiary: address(0),
|
|
365
|
+
encodedIPFSUri: bytes32("tier1"),
|
|
366
|
+
category: 1,
|
|
367
|
+
discountPercent: 0,
|
|
368
|
+
allowOwnerMint: false,
|
|
369
|
+
useReserveBeneficiaryAsDefault: false,
|
|
370
|
+
transfersPausable: false,
|
|
371
|
+
useVotingUnits: false,
|
|
372
|
+
cannotBeRemoved: false,
|
|
373
|
+
cannotIncreaseDiscountPercent: false,
|
|
374
|
+
splitPercent: 300_000_000, // 30%
|
|
375
|
+
splits: splits
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
(uint256 projectId, address hook) = _launchERC20Project(tierConfigs, address(usdc), 6);
|
|
379
|
+
|
|
380
|
+
// Pay 100 USDC to mint tier 1 NFT.
|
|
381
|
+
uint16[] memory tierIds = new uint16[](1);
|
|
382
|
+
tierIds[0] = 1;
|
|
383
|
+
bytes memory meta = _buildPayMetadata(tierIds, true);
|
|
384
|
+
|
|
385
|
+
vm.startPrank(payer);
|
|
386
|
+
usdc.approve(address(jbMultiTerminal), 100e6);
|
|
387
|
+
jbMultiTerminal.pay({
|
|
388
|
+
projectId: projectId,
|
|
389
|
+
amount: 100e6,
|
|
390
|
+
token: address(usdc),
|
|
391
|
+
beneficiary: beneficiary,
|
|
392
|
+
minReturnedTokens: 0,
|
|
393
|
+
memo: "",
|
|
394
|
+
metadata: meta
|
|
395
|
+
});
|
|
396
|
+
vm.stopPrank();
|
|
397
|
+
|
|
398
|
+
// Split beneficiary should have received 30% of 100 USDC = 30 USDC.
|
|
399
|
+
assertEq(usdc.balanceOf(splitBeneficiary), 30e6, "split beneficiary should have 30 USDC");
|
|
400
|
+
// NFT minted to beneficiary.
|
|
401
|
+
assertEq(IERC721(hook).balanceOf(beneficiary), 1, "beneficiary should own 1 NFT");
|
|
402
|
+
assertEq(IERC721(hook).ownerOf(_tokenId(1, 1)), beneficiary, "beneficiary owns tier 1 NFT");
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// =========================================================================
|
|
406
|
+
// Test 2: USDC payment with tier split to project
|
|
407
|
+
// =========================================================================
|
|
408
|
+
|
|
409
|
+
function test_fork_usdcPayment_tierSplitToProject() public {
|
|
410
|
+
// First launch a target project that accepts USDC.
|
|
411
|
+
JB721TierConfig[] memory emptyTiers = new JB721TierConfig[](0);
|
|
412
|
+
(uint256 targetProjectId,) = _launchERC20Project(emptyTiers, address(usdc), 6);
|
|
413
|
+
|
|
414
|
+
// Now create the main project with tier split pointing to target project.
|
|
415
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
416
|
+
splits[0] = JBSplit({
|
|
417
|
+
percent: uint32(JBConstants.SPLITS_TOTAL_PERCENT),
|
|
418
|
+
projectId: uint56(targetProjectId),
|
|
419
|
+
beneficiary: payable(address(0)),
|
|
420
|
+
preferAddToBalance: true,
|
|
421
|
+
lockedUntil: 0,
|
|
422
|
+
hook: IJBSplitHook(address(0))
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
|
|
426
|
+
tierConfigs[0] = JB721TierConfig({
|
|
427
|
+
price: 100e6,
|
|
428
|
+
initialSupply: 100,
|
|
429
|
+
votingUnits: 0,
|
|
430
|
+
reserveFrequency: 0,
|
|
431
|
+
reserveBeneficiary: address(0),
|
|
432
|
+
encodedIPFSUri: bytes32("tier1"),
|
|
433
|
+
category: 1,
|
|
434
|
+
discountPercent: 0,
|
|
435
|
+
allowOwnerMint: false,
|
|
436
|
+
useReserveBeneficiaryAsDefault: false,
|
|
437
|
+
transfersPausable: false,
|
|
438
|
+
useVotingUnits: false,
|
|
439
|
+
cannotBeRemoved: false,
|
|
440
|
+
cannotIncreaseDiscountPercent: false,
|
|
441
|
+
splitPercent: 300_000_000, // 30%
|
|
442
|
+
splits: splits
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
(uint256 projectId, address hook) = _launchERC20Project(tierConfigs, address(usdc), 6);
|
|
446
|
+
|
|
447
|
+
// Record target project's terminal USDC balance before.
|
|
448
|
+
uint256 targetBalanceBefore =
|
|
449
|
+
jbTerminalStore.balanceOf(address(jbMultiTerminal), targetProjectId, address(usdc));
|
|
450
|
+
|
|
451
|
+
// Pay 100 USDC.
|
|
452
|
+
uint16[] memory tierIds = new uint16[](1);
|
|
453
|
+
tierIds[0] = 1;
|
|
454
|
+
bytes memory meta = _buildPayMetadata(tierIds, true);
|
|
455
|
+
|
|
456
|
+
vm.startPrank(payer);
|
|
457
|
+
usdc.approve(address(jbMultiTerminal), 100e6);
|
|
458
|
+
jbMultiTerminal.pay({
|
|
459
|
+
projectId: projectId,
|
|
460
|
+
amount: 100e6,
|
|
461
|
+
token: address(usdc),
|
|
462
|
+
beneficiary: beneficiary,
|
|
463
|
+
minReturnedTokens: 0,
|
|
464
|
+
memo: "",
|
|
465
|
+
metadata: meta
|
|
466
|
+
});
|
|
467
|
+
vm.stopPrank();
|
|
468
|
+
|
|
469
|
+
// Target project should have received 30 USDC via addToBalance.
|
|
470
|
+
uint256 targetBalanceAfter = jbTerminalStore.balanceOf(address(jbMultiTerminal), targetProjectId, address(usdc));
|
|
471
|
+
assertEq(targetBalanceAfter - targetBalanceBefore, 30e6, "target project should have 30 USDC more");
|
|
472
|
+
// NFT minted.
|
|
473
|
+
assertEq(IERC721(hook).balanceOf(beneficiary), 1, "beneficiary should own 1 NFT");
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// =========================================================================
|
|
477
|
+
// Test 3: ETH payment with tier split still works (regression)
|
|
478
|
+
// =========================================================================
|
|
479
|
+
|
|
480
|
+
function test_fork_ethPayment_tierSplitStillWorks() public {
|
|
481
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
482
|
+
splits[0] = JBSplit({
|
|
483
|
+
percent: uint32(JBConstants.SPLITS_TOTAL_PERCENT),
|
|
484
|
+
projectId: 0,
|
|
485
|
+
beneficiary: payable(splitBeneficiary),
|
|
486
|
+
preferAddToBalance: false,
|
|
487
|
+
lockedUntil: 0,
|
|
488
|
+
hook: IJBSplitHook(address(0))
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
JB721TierConfig[] memory tierConfigs = new JB721TierConfig[](1);
|
|
492
|
+
tierConfigs[0] = JB721TierConfig({
|
|
493
|
+
price: 1 ether,
|
|
494
|
+
initialSupply: 100,
|
|
495
|
+
votingUnits: 0,
|
|
496
|
+
reserveFrequency: 0,
|
|
497
|
+
reserveBeneficiary: address(0),
|
|
498
|
+
encodedIPFSUri: bytes32("tier1"),
|
|
499
|
+
category: 1,
|
|
500
|
+
discountPercent: 0,
|
|
501
|
+
allowOwnerMint: false,
|
|
502
|
+
useReserveBeneficiaryAsDefault: false,
|
|
503
|
+
transfersPausable: false,
|
|
504
|
+
useVotingUnits: false,
|
|
505
|
+
cannotBeRemoved: false,
|
|
506
|
+
cannotIncreaseDiscountPercent: false,
|
|
507
|
+
splitPercent: 500_000_000, // 50%
|
|
508
|
+
splits: splits
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
(uint256 projectId, address hook) = _launchETHProject(tierConfigs);
|
|
512
|
+
|
|
513
|
+
uint256 splitBalanceBefore = splitBeneficiary.balance;
|
|
514
|
+
|
|
515
|
+
// Pay 1 ETH.
|
|
516
|
+
uint16[] memory tierIds = new uint16[](1);
|
|
517
|
+
tierIds[0] = 1;
|
|
518
|
+
bytes memory meta = _buildPayMetadata(tierIds, true);
|
|
519
|
+
|
|
520
|
+
vm.prank(payer);
|
|
521
|
+
jbMultiTerminal.pay{value: 1 ether}({
|
|
522
|
+
projectId: projectId,
|
|
523
|
+
amount: 1 ether,
|
|
524
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
525
|
+
beneficiary: beneficiary,
|
|
526
|
+
minReturnedTokens: 0,
|
|
527
|
+
memo: "",
|
|
528
|
+
metadata: meta
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
// Split beneficiary should have received 50% of 1 ETH = 0.5 ETH.
|
|
532
|
+
assertEq(splitBeneficiary.balance - splitBalanceBefore, 0.5 ether, "split beneficiary should have 0.5 ETH");
|
|
533
|
+
// NFT minted.
|
|
534
|
+
assertEq(IERC721(hook).balanceOf(beneficiary), 1, "beneficiary should own 1 NFT");
|
|
535
|
+
assertEq(IERC721(hook).ownerOf(_tokenId(1, 1)), beneficiary, "beneficiary owns tier 1 NFT");
|
|
536
|
+
}
|
|
537
|
+
}
|
|
@@ -76,7 +76,6 @@ contract TierLifecycleInvariant_Local is StdInvariant, UnitTestSetup {
|
|
|
76
76
|
function invariant_721_2_totalCashOutWeightConsistency() public {
|
|
77
77
|
uint256 totalWeight = store.totalCashOutWeight(address(hook));
|
|
78
78
|
|
|
79
|
-
uint256 maxTierId = store.maxTierIdOf(address(hook));
|
|
80
79
|
uint256 computedWeight = 0;
|
|
81
80
|
|
|
82
81
|
uint256[] memory categories = new uint256[](0);
|
|
@@ -175,7 +174,6 @@ contract TierLifecycleInvariant_Local is StdInvariant, UnitTestSetup {
|
|
|
175
174
|
JB721Tier[] memory allTiers = store.tiersOf(address(hook), categories, false, 0, 100);
|
|
176
175
|
|
|
177
176
|
for (uint256 i = 0; i < allTiers.length; i++) {
|
|
178
|
-
uint256 tierId = allTiers[i].id;
|
|
179
177
|
uint256 price = allTiers[i].price;
|
|
180
178
|
|
|
181
179
|
// Cash out weight per token for this tier is just `price` (from the store)
|