@rev-net/core-v6 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -0
  3. package/REVNET_SECURITY_CHECKLIST.md +164 -0
  4. package/SECURITY.md +68 -0
  5. package/SKILLS.md +166 -0
  6. package/deployments/revnet-core-v5/arbitrum/REVDeployer.json +2821 -0
  7. package/deployments/revnet-core-v5/arbitrum/REVLoans.json +2260 -0
  8. package/deployments/revnet-core-v5/arbitrum_sepolia/REVDeployer.json +2821 -0
  9. package/deployments/revnet-core-v5/arbitrum_sepolia/REVLoans.json +2260 -0
  10. package/deployments/revnet-core-v5/base/REVDeployer.json +2825 -0
  11. package/deployments/revnet-core-v5/base/REVLoans.json +2264 -0
  12. package/deployments/revnet-core-v5/base_sepolia/REVDeployer.json +2825 -0
  13. package/deployments/revnet-core-v5/base_sepolia/REVLoans.json +2264 -0
  14. package/deployments/revnet-core-v5/ethereum/REVDeployer.json +2825 -0
  15. package/deployments/revnet-core-v5/ethereum/REVLoans.json +2264 -0
  16. package/deployments/revnet-core-v5/optimism/REVDeployer.json +2821 -0
  17. package/deployments/revnet-core-v5/optimism/REVLoans.json +2260 -0
  18. package/deployments/revnet-core-v5/optimism_sepolia/REVDeployer.json +2825 -0
  19. package/deployments/revnet-core-v5/optimism_sepolia/REVLoans.json +2264 -0
  20. package/deployments/revnet-core-v5/sepolia/REVDeployer.json +2825 -0
  21. package/deployments/revnet-core-v5/sepolia/REVLoans.json +2264 -0
  22. package/docs/book.css +13 -0
  23. package/docs/book.toml +13 -0
  24. package/docs/solidity.min.js +74 -0
  25. package/docs/src/README.md +88 -0
  26. package/docs/src/SUMMARY.md +20 -0
  27. package/docs/src/src/README.md +7 -0
  28. package/docs/src/src/REVDeployer.sol/contract.REVDeployer.md +968 -0
  29. package/docs/src/src/REVLoans.sol/contract.REVLoans.md +1047 -0
  30. package/docs/src/src/interfaces/IREVDeployer.sol/interface.IREVDeployer.md +243 -0
  31. package/docs/src/src/interfaces/IREVLoans.sol/interface.IREVLoans.md +296 -0
  32. package/docs/src/src/interfaces/README.md +5 -0
  33. package/docs/src/src/structs/README.md +14 -0
  34. package/docs/src/src/structs/REVAutoIssuance.sol/struct.REVAutoIssuance.md +19 -0
  35. package/docs/src/src/structs/REVBuybackHookConfig.sol/struct.REVBuybackHookConfig.md +19 -0
  36. package/docs/src/src/structs/REVBuybackPoolConfig.sol/struct.REVBuybackPoolConfig.md +21 -0
  37. package/docs/src/src/structs/REVConfig.sol/struct.REVConfig.md +35 -0
  38. package/docs/src/src/structs/REVCroptopAllowedPost.sol/struct.REVCroptopAllowedPost.md +28 -0
  39. package/docs/src/src/structs/REVDeploy721TiersHookConfig.sol/struct.REVDeploy721TiersHookConfig.md +34 -0
  40. package/docs/src/src/structs/REVDescription.sol/struct.REVDescription.md +23 -0
  41. package/docs/src/src/structs/REVLoan.sol/struct.REVLoan.md +28 -0
  42. package/docs/src/src/structs/REVLoanSource.sol/struct.REVLoanSource.md +16 -0
  43. package/docs/src/src/structs/REVStageConfig.sol/struct.REVStageConfig.md +44 -0
  44. package/docs/src/src/structs/REVSuckerDeploymentConfig.sol/struct.REVSuckerDeploymentConfig.md +16 -0
  45. package/foundry.lock +11 -0
  46. package/foundry.toml +23 -0
  47. package/package.json +31 -0
  48. package/remappings.txt +1 -0
  49. package/script/Deploy.s.sol +350 -0
  50. package/script/helpers/RevnetCoreDeploymentLib.sol +72 -0
  51. package/slither-ci.config.json +10 -0
  52. package/sphinx.lock +507 -0
  53. package/src/REVDeployer.sol +1257 -0
  54. package/src/REVLoans.sol +1333 -0
  55. package/src/interfaces/IREVDeployer.sol +198 -0
  56. package/src/interfaces/IREVLoans.sol +241 -0
  57. package/src/structs/REVAutoIssuance.sol +11 -0
  58. package/src/structs/REVConfig.sol +17 -0
  59. package/src/structs/REVCroptopAllowedPost.sol +20 -0
  60. package/src/structs/REVDeploy721TiersHookConfig.sol +25 -0
  61. package/src/structs/REVDescription.sol +14 -0
  62. package/src/structs/REVLoan.sol +19 -0
  63. package/src/structs/REVLoanSource.sol +11 -0
  64. package/src/structs/REVStageConfig.sol +34 -0
  65. package/src/structs/REVSuckerDeploymentConfig.sol +11 -0
  66. package/test/REV.integrations.t.sol +420 -0
  67. package/test/REVAutoIssuanceFuzz.t.sol +276 -0
  68. package/test/REVDeployerAuditRegressions.t.sol +328 -0
  69. package/test/REVInvincibility.t.sol +1275 -0
  70. package/test/REVInvincibilityHandler.sol +357 -0
  71. package/test/REVLifecycle.t.sol +364 -0
  72. package/test/REVLoans.invariants.t.sol +642 -0
  73. package/test/REVLoansAttacks.t.sol +739 -0
  74. package/test/REVLoansAuditRegressions.t.sol +314 -0
  75. package/test/REVLoansFeeRecovery.t.sol +704 -0
  76. package/test/REVLoansSourced.t.sol +1732 -0
  77. package/test/REVLoansUnSourced.t.sol +331 -0
  78. package/test/TestPR09_ConversionDocumentation.t.sol +304 -0
  79. package/test/TestPR10_LiquidationBehavior.t.sol +340 -0
  80. package/test/TestPR11_LowFindings.t.sol +571 -0
  81. package/test/TestPR12_FlashLoanSurplus.t.sol +305 -0
  82. package/test/TestPR13_CrossSourceReallocation.t.sol +302 -0
  83. package/test/TestPR15_CashOutCallerValidation.t.sol +320 -0
  84. package/test/TestPR16_ZeroRepayment.t.sol +297 -0
  85. package/test/TestPR21_Uint112Overflow.t.sol +251 -0
  86. package/test/TestPR22_HookArrayOOB.t.sol +221 -0
  87. package/test/TestPR26_BurnHeldTokens.t.sol +331 -0
  88. package/test/TestPR27_CEIPattern.t.sol +448 -0
  89. package/test/TestPR29_SwapTerminalPermission.t.sol +206 -0
  90. package/test/TestPR32_MixedFixes.t.sol +529 -0
  91. package/test/helpers/MaliciousContracts.sol +233 -0
  92. package/test/mock/MockBuybackDataHook.sol +61 -0
@@ -0,0 +1,420 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.23;
3
+
4
+ import "forge-std/Test.sol";
5
+ import /* {*} from */ "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
6
+ import /* {*} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
7
+ import /* {*} from */ "./../src/REVDeployer.sol";
8
+ import "@croptop/core-v6/src/CTPublisher.sol";
9
+ import {MockBuybackDataHook} from "./mock/MockBuybackDataHook.sol";
10
+
11
+ import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
12
+ import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
13
+ import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
14
+ import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
15
+ import "@bananapus/swap-terminal-v6/script/helpers/SwapTerminalDeploymentLib.sol";
16
+
17
+ import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
18
+ import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
19
+ import {REVLoans} from "../src/REVLoans.sol";
20
+ import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
21
+ import {REVDescription} from "../src/structs/REVDescription.sol";
22
+ import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
23
+ import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
24
+ import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
25
+ import {JBTokenMapping} from "@bananapus/suckers-v6/src/structs/JBTokenMapping.sol";
26
+ import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
27
+ import {JBArbitrumSuckerDeployer} from "@bananapus/suckers-v6/src/deployers/JBArbitrumSuckerDeployer.sol";
28
+ import {JBArbitrumSucker, JBLayer, IArbGatewayRouter, IInbox} from "@bananapus/suckers-v6/src/JBArbitrumSucker.sol";
29
+ import {JBAddToBalanceMode} from "@bananapus/suckers-v6/src/enums/JBAddToBalanceMode.sol";
30
+ import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
31
+ import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
32
+ import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
33
+ import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
34
+
35
+ struct FeeProjectConfig {
36
+ REVConfig configuration;
37
+ JBTerminalConfig[] terminalConfigurations;
38
+ REVSuckerDeploymentConfig suckerDeploymentConfiguration;
39
+ }
40
+
41
+ contract REVnet_Integrations is TestBaseWorkflow, JBTest {
42
+ /// @notice the salts that are used to deploy the contracts.
43
+ bytes32 REV_DEPLOYER_SALT = "REVDeployer";
44
+ bytes32 ERC20_SALT = "REV_TOKEN";
45
+
46
+ REVDeployer REV_DEPLOYER;
47
+ JB721TiersHook EXAMPLE_HOOK;
48
+
49
+ /// @notice Deploys tiered ERC-721 hooks for revnets.
50
+ IJB721TiersHookDeployer HOOK_DEPLOYER;
51
+ IJB721TiersHookStore HOOK_STORE;
52
+ IJBAddressRegistry ADDRESS_REGISTRY;
53
+
54
+ IREVLoans LOANS_CONTRACT;
55
+
56
+ /// @notice Deploys and tracks suckers for revnets.
57
+ IJBSuckerRegistry SUCKER_REGISTRY;
58
+ IJBSuckerDeployer ARB_SUCKER_DEPLOYER;
59
+ bytes ENCODED_CONFIG;
60
+
61
+ CTPublisher PUBLISHER;
62
+ MockBuybackDataHook MOCK_BUYBACK;
63
+
64
+ uint256 FEE_PROJECT_ID;
65
+ uint256 REVNET_ID;
66
+ uint256 decimals = 18;
67
+ uint256 decimalMultiplier = 10 ** decimals;
68
+
69
+ /// @notice The address that is allowed to forward calls.
70
+ address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
71
+
72
+ uint256 firstStageId;
73
+
74
+ address USER = makeAddr("user");
75
+
76
+ function getFeeProjectConfig() internal returns (FeeProjectConfig memory) {
77
+ // Define constants
78
+ string memory name = "Revnet";
79
+ string memory symbol = "$REV";
80
+ string memory projectUri = "ipfs://QmNRHT91HcDgMcenebYX7rJigt77cgNcosvuhX21wkF3tx";
81
+
82
+ // The tokens that the project accepts and stores.
83
+ JBAccountingContext[] memory accountingContextsToAccept = new JBAccountingContext[](1);
84
+
85
+ // Accept the chain's native currency through the multi terminal.
86
+ accountingContextsToAccept[0] = JBAccountingContext({
87
+ token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
88
+ });
89
+
90
+ // The terminals that the project will accept funds through.
91
+ JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
92
+ terminalConfigurations[0] =
93
+ JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: accountingContextsToAccept});
94
+
95
+ // The project's revnet stage configurations.
96
+ REVStageConfig[] memory stageConfigurations = new REVStageConfig[](3);
97
+
98
+ REVAutoIssuance[] memory issuanceConfs = new REVAutoIssuance[](1);
99
+ issuanceConfs[0] = REVAutoIssuance({
100
+ chainId: uint32(block.chainid), count: uint104(70_000 * decimalMultiplier), beneficiary: multisig()
101
+ });
102
+
103
+ JBSplit[] memory splits = new JBSplit[](1);
104
+ splits[0].beneficiary = payable(multisig());
105
+ splits[0].percent = 10_000;
106
+
107
+ {
108
+ firstStageId = block.timestamp;
109
+
110
+ stageConfigurations[0] = REVStageConfig({
111
+ startsAtOrAfter: uint40(block.timestamp),
112
+ autoIssuances: issuanceConfs,
113
+ splitPercent: 2000, // 20%
114
+ splits: splits,
115
+ initialIssuance: uint112(1000 * decimalMultiplier),
116
+ issuanceCutFrequency: 90 days,
117
+ issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
118
+ cashOutTaxRate: 6000, // 0.6
119
+ extraMetadata: (1 << 2) // Enable adding new suckers.
120
+ });
121
+ }
122
+
123
+ stageConfigurations[1] = REVStageConfig({
124
+ startsAtOrAfter: uint40(stageConfigurations[0].startsAtOrAfter + 720 days),
125
+ autoIssuances: issuanceConfs,
126
+ splitPercent: 2000, // 20%
127
+ splits: splits,
128
+ initialIssuance: 0, // inherit from previous cycle.
129
+ issuanceCutFrequency: 180 days,
130
+ issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
131
+ cashOutTaxRate: 6000, // 0.6
132
+ extraMetadata: (1 << 2) // Enable adding new suckers.
133
+ });
134
+
135
+ stageConfigurations[2] = REVStageConfig({
136
+ startsAtOrAfter: uint40(stageConfigurations[1].startsAtOrAfter + (20 * 365 days)),
137
+ autoIssuances: new REVAutoIssuance[](0),
138
+ splitPercent: 0,
139
+ splits: splits,
140
+ initialIssuance: 1,
141
+ issuanceCutFrequency: 0,
142
+ issuanceCutPercent: 0,
143
+ cashOutTaxRate: 6000, // 0.6
144
+ extraMetadata: (1 << 2) // Enable adding new suckers.
145
+ });
146
+
147
+ // The project's revnet configuration
148
+ REVConfig memory revnetConfiguration = REVConfig({
149
+ description: REVDescription(name, symbol, projectUri, ERC20_SALT),
150
+ baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
151
+ splitOperator: multisig(),
152
+ stageConfigurations: stageConfigurations
153
+ });
154
+
155
+ ENCODED_CONFIG = abi.encode(
156
+ revnetConfiguration.baseCurrency,
157
+ revnetConfiguration.description.name,
158
+ revnetConfiguration.description.ticker,
159
+ revnetConfiguration.description.salt
160
+ );
161
+
162
+ return FeeProjectConfig({
163
+ configuration: revnetConfiguration,
164
+ terminalConfigurations: terminalConfigurations,
165
+ suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
166
+ deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("REV"))
167
+ })
168
+ });
169
+ }
170
+
171
+ function setUp() public override {
172
+ super.setUp();
173
+
174
+ FEE_PROJECT_ID = jbProjects().createFor(multisig());
175
+
176
+ SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
177
+
178
+ HOOK_STORE = new JB721TiersHookStore();
179
+
180
+ EXAMPLE_HOOK = new JB721TiersHook(jbDirectory(), jbPermissions(), jbRulesets(), HOOK_STORE, multisig());
181
+
182
+ ADDRESS_REGISTRY = new JBAddressRegistry();
183
+
184
+ HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
185
+
186
+ PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
187
+ MOCK_BUYBACK = new MockBuybackDataHook();
188
+
189
+ REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
190
+ jbController(),
191
+ SUCKER_REGISTRY,
192
+ FEE_PROJECT_ID,
193
+ HOOK_DEPLOYER,
194
+ PUBLISHER,
195
+ IJBRulesetDataHook(address(MOCK_BUYBACK)),
196
+ makeAddr("loans"),
197
+ TRUSTED_FORWARDER
198
+ );
199
+
200
+ // Deploy the ARB sucker deployer.
201
+ JBArbitrumSuckerDeployer _deployer =
202
+ new JBArbitrumSuckerDeployer(jbDirectory(), jbPermissions(), jbTokens(), address(this), address(0));
203
+ ARB_SUCKER_DEPLOYER = IJBSuckerDeployer(address(_deployer));
204
+
205
+ // Deploy the ARB sucker singleton.
206
+ JBArbitrumSucker _singleton = new JBArbitrumSucker(
207
+ _deployer, jbDirectory(), jbPermissions(), jbTokens(), JBAddToBalanceMode.MANUAL, address(0)
208
+ );
209
+
210
+ // Set the layer specific confguration.
211
+ _deployer.setChainSpecificConstants(JBLayer.L1, IInbox(address(1)), IArbGatewayRouter(address(1)));
212
+
213
+ // Set the singleton for the deployer.
214
+ _deployer.configureSingleton(_singleton);
215
+
216
+ // Approve the basic deployer to configure the project.
217
+ vm.startPrank(address(multisig()));
218
+ jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
219
+ SUCKER_REGISTRY.allowSuckerDeployer(address(ARB_SUCKER_DEPLOYER));
220
+
221
+ vm.stopPrank();
222
+
223
+ // Build the config.
224
+ FeeProjectConfig memory feeProjectConfig = getFeeProjectConfig();
225
+
226
+ // Configure the project.
227
+ vm.prank(address(multisig()));
228
+ REVNET_ID = REV_DEPLOYER.deployFor({
229
+ revnetId: FEE_PROJECT_ID, // Zero to deploy a new revnet
230
+ configuration: feeProjectConfig.configuration,
231
+ terminalConfigurations: feeProjectConfig.terminalConfigurations,
232
+ suckerDeploymentConfiguration: feeProjectConfig.suckerDeploymentConfiguration
233
+ });
234
+ }
235
+
236
+ function test_Is_Setup() public view {
237
+ assertGt(uint160(address(jbDirectory())), uint160(0));
238
+ assertGt(FEE_PROJECT_ID, 0);
239
+ assertGt(jbProjects().count(), 0);
240
+ assertGt(REVNET_ID, 0);
241
+ }
242
+
243
+ function test_preMint() public {
244
+ uint256 perStageMintAmount = 70_000 * decimalMultiplier;
245
+ vm.expectEmit();
246
+ emit IREVDeployer.AutoIssue(REVNET_ID, firstStageId, multisig(), perStageMintAmount, address(this));
247
+ REV_DEPLOYER.autoIssueFor(REVNET_ID, firstStageId, multisig());
248
+
249
+ assertEq(70_000 * decimalMultiplier, IJBToken(jbTokens().tokenOf(REVNET_ID)).balanceOf(multisig()));
250
+ }
251
+
252
+ function test_realize_autoissuance() public {
253
+ uint256 perStageMintAmount = 70_000 * decimalMultiplier;
254
+
255
+ vm.expectEmit();
256
+ emit IREVDeployer.AutoIssue(REVNET_ID, firstStageId, multisig(), perStageMintAmount, address(this));
257
+ REV_DEPLOYER.autoIssueFor(REVNET_ID, firstStageId, multisig());
258
+ assertEq(REV_DEPLOYER.amountToAutoIssue(REVNET_ID, firstStageId, multisig()), 0);
259
+
260
+ assertEq(perStageMintAmount, IJBToken(jbTokens().tokenOf(REVNET_ID)).balanceOf(multisig()));
261
+
262
+ vm.warp(firstStageId + 720 days);
263
+ assertEq(perStageMintAmount, REV_DEPLOYER.amountToAutoIssue(REVNET_ID, firstStageId + 1, multisig()));
264
+
265
+ vm.expectEmit();
266
+ emit IREVDeployer.AutoIssue(REVNET_ID, firstStageId + 1, multisig(), perStageMintAmount, address(this));
267
+ REV_DEPLOYER.autoIssueFor(REVNET_ID, firstStageId + 1, multisig());
268
+
269
+ assertEq(perStageMintAmount * 2, IJBToken(jbTokens().tokenOf(REVNET_ID)).balanceOf(multisig()));
270
+ }
271
+
272
+ function test_change_split_operator() public {
273
+ vm.prank(multisig());
274
+ REV_DEPLOYER.setSplitOperatorOf(REVNET_ID, address(this));
275
+
276
+ bool isNewOperator = REV_DEPLOYER.isSplitOperatorOf(REVNET_ID, address(this));
277
+
278
+ assertEq(isNewOperator, true);
279
+ }
280
+
281
+ function test_sucker_deploy() public {
282
+ JBSuckerDeployerConfig[] memory suckerDeployerConfig = new JBSuckerDeployerConfig[](1);
283
+
284
+ JBTokenMapping[] memory tokenMapping = new JBTokenMapping[](1);
285
+
286
+ address token = makeAddr("someToken");
287
+ tokenMapping[0] = JBTokenMapping({
288
+ localToken: token,
289
+ minGas: 200_000,
290
+ remoteToken: bytes32(uint256(uint160(makeAddr("someOtherToken")))),
291
+ minBridgeAmount: 100 // emoji
292
+ });
293
+
294
+ suckerDeployerConfig[0] = JBSuckerDeployerConfig({deployer: ARB_SUCKER_DEPLOYER, mappings: tokenMapping});
295
+
296
+ REVSuckerDeploymentConfig memory revConfig =
297
+ REVSuckerDeploymentConfig({deployerConfigurations: suckerDeployerConfig, salt: "SALTY"});
298
+
299
+ // Arbitrum chainid so the deployer works
300
+ vm.chainId(42_161);
301
+ vm.prank(multisig());
302
+
303
+ // As a safety measure the newly created sucker will check that it has not missed a crosschain call.
304
+ // which wil call the balanceOf to check its own balance.
305
+ vm.mockCall(address(token), abi.encodeWithSelector(IERC20.balanceOf.selector), abi.encode(0));
306
+
307
+ address[] memory suckers = REV_DEPLOYER.deploySuckersFor(REVNET_ID, revConfig);
308
+
309
+ // Ensure it's registered
310
+ bool isSucker = SUCKER_REGISTRY.isSuckerOf(REVNET_ID, suckers[0]);
311
+ assertEq(isSucker, true);
312
+ }
313
+
314
+ /// Test that ensures that the splits are being configured for the new project.
315
+ function test_configure_split(address payable beneficiaryA, address payable beneficiaryB) public {
316
+ JBSplit[] memory splitsA = new JBSplit[](1);
317
+ splitsA[0].beneficiary = beneficiaryA;
318
+ splitsA[0].percent = 10_000;
319
+
320
+ JBSplit[] memory splitsB = new JBSplit[](1);
321
+ splitsB[0].beneficiary = beneficiaryB;
322
+ splitsB[0].percent = 10_000;
323
+
324
+ // Deploy a new REVNET, it has two configurations, we give each its own split and then check if the splits were
325
+ // set correctly for each of the stages.
326
+ FeeProjectConfig memory projectConfig = getFeeProjectConfig();
327
+
328
+ REVStageConfig[] memory stageConfigurations = new REVStageConfig[](2);
329
+ stageConfigurations[0] = REVStageConfig({
330
+ startsAtOrAfter: uint40(block.timestamp),
331
+ autoIssuances: new REVAutoIssuance[](0),
332
+ splitPercent: 2000, // 20%
333
+ splits: splitsA,
334
+ initialIssuance: 1000e18,
335
+ issuanceCutFrequency: 180 days,
336
+ issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
337
+ cashOutTaxRate: 2000, // 20%
338
+ extraMetadata: 0
339
+ });
340
+
341
+ stageConfigurations[1] = REVStageConfig({
342
+ startsAtOrAfter: uint40(block.timestamp + 720 days),
343
+ autoIssuances: new REVAutoIssuance[](0),
344
+ splitPercent: 2000, // 20%
345
+ splits: splitsB,
346
+ initialIssuance: 0, // inherit from previous cycle.
347
+ issuanceCutFrequency: 180 days,
348
+ issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
349
+ cashOutTaxRate: 0, // 40%
350
+ extraMetadata: 0
351
+ });
352
+
353
+ // Replace the configuration.
354
+ projectConfig.configuration.stageConfigurations = stageConfigurations;
355
+ projectConfig.configuration.description.salt = "FeeChange";
356
+
357
+ uint256 revnetProjectId = REV_DEPLOYER.deployFor({
358
+ revnetId: 0, // Zero to deploy a new revnet
359
+ configuration: projectConfig.configuration,
360
+ terminalConfigurations: projectConfig.terminalConfigurations,
361
+ suckerDeploymentConfiguration: projectConfig.suckerDeploymentConfiguration
362
+ });
363
+
364
+ {
365
+ JBSplit[] memory configuredSplits = jbSplits()
366
+ .splitsOf(revnetProjectId, jbRulesets().currentOf(revnetProjectId).id, JBSplitGroupIds.RESERVED_TOKENS);
367
+ assertEq(keccak256(abi.encode(configuredSplits)), keccak256(abi.encode(splitsA)));
368
+ }
369
+
370
+ {
371
+ JBSplit[] memory configuredSplits = jbSplits()
372
+ .splitsOf(
373
+ revnetProjectId, jbRulesets().latestRulesetIdOf(revnetProjectId), JBSplitGroupIds.RESERVED_TOKENS
374
+ );
375
+ assertEq(keccak256(abi.encode(configuredSplits)), keccak256(abi.encode(splitsB)));
376
+ }
377
+ }
378
+
379
+ function test_loans_has_use_allowance_permission() public view {
380
+ // The loans contract should have USE_ALLOWANCE permission for any revnet via the wildcard grant.
381
+ bool hasPermission = jbPermissions()
382
+ .hasPermission({
383
+ operator: address(REV_DEPLOYER.LOANS()),
384
+ account: address(REV_DEPLOYER),
385
+ projectId: REVNET_ID,
386
+ permissionId: JBPermissionIds.USE_ALLOWANCE,
387
+ includeRoot: false,
388
+ includeWildcardProjectId: true
389
+ });
390
+ assertTrue(hasPermission, "LOANS should have USE_ALLOWANCE for deployed revnet");
391
+
392
+ // Also holds for a revnet that doesn't exist yet — the wildcard covers all projects.
393
+ bool hasPermissionForFuture = jbPermissions()
394
+ .hasPermission({
395
+ operator: address(REV_DEPLOYER.LOANS()),
396
+ account: address(REV_DEPLOYER),
397
+ projectId: 999,
398
+ permissionId: JBPermissionIds.USE_ALLOWANCE,
399
+ includeRoot: false,
400
+ includeWildcardProjectId: true
401
+ });
402
+ assertTrue(hasPermissionForFuture, "LOANS should have USE_ALLOWANCE for any project via wildcard");
403
+ }
404
+
405
+ function test_deployer_not_owner() public {
406
+ // Build the config.
407
+ FeeProjectConfig memory feeProjectConfig = getFeeProjectConfig();
408
+
409
+ vm.expectRevert(
410
+ abi.encodeWithSelector(REVDeployer.REVDeployer_Unauthorized.selector, FEE_PROJECT_ID, address(this))
411
+ );
412
+ // Configure the project.
413
+ REVNET_ID = REV_DEPLOYER.deployFor({
414
+ revnetId: FEE_PROJECT_ID, // Zero to deploy a new revnet
415
+ configuration: feeProjectConfig.configuration,
416
+ terminalConfigurations: feeProjectConfig.terminalConfigurations,
417
+ suckerDeploymentConfiguration: feeProjectConfig.suckerDeploymentConfiguration
418
+ });
419
+ }
420
+ }