@rev-net/core-v6 0.0.37 → 0.0.40

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 (112) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/README.md +6 -7
  3. package/foundry.toml +1 -1
  4. package/package.json +23 -16
  5. package/references/operations.md +1 -1
  6. package/references/runtime.md +1 -1
  7. package/script/Deploy.s.sol +12 -9
  8. package/src/REVDeployer.sol +69 -67
  9. package/src/REVHiddenTokens.sol +2 -2
  10. package/src/REVLoans.sol +26 -22
  11. package/src/REVOwner.sol +147 -29
  12. package/src/interfaces/IREVDeployer.sol +2 -1
  13. package/src/interfaces/IREVHiddenTokens.sol +4 -1
  14. package/src/interfaces/IREVOwner.sol +5 -0
  15. package/src/structs/REVAutoIssuance.sol +4 -2
  16. package/src/structs/REVConfig.sol +8 -5
  17. package/src/structs/REVDescription.sol +6 -5
  18. package/src/structs/REVLoan.sol +8 -5
  19. package/src/structs/REVStageConfig.sol +14 -16
  20. package/ADMINISTRATION.md +0 -73
  21. package/ARCHITECTURE.md +0 -116
  22. package/AUDIT_INSTRUCTIONS.md +0 -90
  23. package/RISKS.md +0 -107
  24. package/SKILLS.md +0 -46
  25. package/STYLE_GUIDE.md +0 -610
  26. package/USER_JOURNEYS.md +0 -195
  27. package/foundry.lock +0 -11
  28. package/slither-ci.config.json +0 -10
  29. package/sphinx.lock +0 -507
  30. package/test/REV.integrations.t.sol +0 -573
  31. package/test/REVAutoIssuanceFuzz.t.sol +0 -328
  32. package/test/REVDeployerRegressions.t.sol +0 -396
  33. package/test/REVInvincibility.t.sol +0 -1371
  34. package/test/REVInvincibilityHandler.sol +0 -387
  35. package/test/REVLifecycle.t.sol +0 -420
  36. package/test/REVLoans.invariants.t.sol +0 -724
  37. package/test/REVLoansAttacks.t.sol +0 -816
  38. package/test/REVLoansFeeRecovery.t.sol +0 -783
  39. package/test/REVLoansFindings.t.sol +0 -711
  40. package/test/REVLoansRegressions.t.sol +0 -364
  41. package/test/REVLoansSourceFeeRecovery.t.sol +0 -517
  42. package/test/REVLoansSourced.t.sol +0 -1839
  43. package/test/REVLoansUnSourced.t.sol +0 -409
  44. package/test/TestAuditFixVerification.t.sol +0 -675
  45. package/test/TestBurnHeldTokens.t.sol +0 -394
  46. package/test/TestCEIPattern.t.sol +0 -508
  47. package/test/TestCashOutCallerValidation.t.sol +0 -452
  48. package/test/TestConversionDocumentation.t.sol +0 -365
  49. package/test/TestCrossCurrencyReclaim.t.sol +0 -610
  50. package/test/TestCrossSourceReallocation.t.sol +0 -361
  51. package/test/TestERC2771MetaTx.t.sol +0 -585
  52. package/test/TestEmptyBuybackSpecs.t.sol +0 -300
  53. package/test/TestFlashLoanSurplus.t.sol +0 -365
  54. package/test/TestHiddenTokens.t.sol +0 -474
  55. package/test/TestHookArrayOOB.t.sol +0 -278
  56. package/test/TestLiquidationBehavior.t.sol +0 -398
  57. package/test/TestLoanSourceRotation.t.sol +0 -553
  58. package/test/TestLoansCashOutDelay.t.sol +0 -493
  59. package/test/TestLongTailEconomics.t.sol +0 -677
  60. package/test/TestLowFindings.t.sol +0 -677
  61. package/test/TestMixedFixes.t.sol +0 -593
  62. package/test/TestPermit2Signatures.t.sol +0 -683
  63. package/test/TestReallocationSandwich.t.sol +0 -412
  64. package/test/TestRevnetRegressions.t.sol +0 -350
  65. package/test/TestSplitWeightAdjustment.t.sol +0 -527
  66. package/test/TestSplitWeightE2E.t.sol +0 -605
  67. package/test/TestSplitWeightFork.t.sol +0 -855
  68. package/test/TestStageTransitionBorrowable.t.sol +0 -301
  69. package/test/TestSwapTerminalPermission.t.sol +0 -262
  70. package/test/TestTerminalEncodingInHash.t.sol +0 -326
  71. package/test/TestUint112Overflow.t.sol +0 -311
  72. package/test/TestZeroAmountLoanGuard.t.sol +0 -378
  73. package/test/TestZeroRepayment.t.sol +0 -354
  74. package/test/audit/CrossChainBuybackRouteMismatch.t.sol +0 -184
  75. package/test/audit/HiddenSupplyCashout.t.sol +0 -61
  76. package/test/audit/LoanIdOverflowGuard.t.sol +0 -523
  77. package/test/audit/NemesisVerification.t.sol +0 -97
  78. package/test/audit/OperatorDelegation.t.sol +0 -356
  79. package/test/audit/PhantomSurplusTerminal.t.sol +0 -367
  80. package/test/audit/REVOwnerCurrencyMismatch.t.sol +0 -188
  81. package/test/audit/REVOwnerRemoteSurplusCurrencyMismatch.t.sol +0 -140
  82. package/test/audit/ReallocatePermission.t.sol +0 -363
  83. package/test/audit/RemoteLoanAccountingGap.t.sol +0 -74
  84. package/test/audit/SupportsInterfaceTest.t.sol +0 -51
  85. package/test/audit/TestFeeAllowanceLeak.t.sol +0 -197
  86. package/test/audit/TestLoansAndDeployerFixes.t.sol +0 -576
  87. package/test/fork/ForkTestBase.sol +0 -727
  88. package/test/fork/TestAutoIssuanceFork.t.sol +0 -148
  89. package/test/fork/TestCashOutFork.t.sol +0 -253
  90. package/test/fork/TestIssuanceDecayFork.t.sol +0 -158
  91. package/test/fork/TestLoanAdversarialFork.t.sol +0 -744
  92. package/test/fork/TestLoanBorrowFork.t.sol +0 -163
  93. package/test/fork/TestLoanCrossRulesetFork.t.sol +0 -308
  94. package/test/fork/TestLoanERC20Fork.t.sol +0 -459
  95. package/test/fork/TestLoanLiquidationFork.t.sol +0 -135
  96. package/test/fork/TestLoanReallocateFork.t.sol +0 -113
  97. package/test/fork/TestLoanRepayFork.t.sol +0 -188
  98. package/test/fork/TestLoanTransferFork.t.sol +0 -143
  99. package/test/fork/TestPermit2PaymentFork.t.sol +0 -300
  100. package/test/fork/TestSplitWeightFork.t.sol +0 -189
  101. package/test/helpers/MaliciousContracts.sol +0 -247
  102. package/test/helpers/REVEmpty721Config.sol +0 -45
  103. package/test/mock/MockBuybackCashOutRecorder.sol +0 -84
  104. package/test/mock/MockBuybackDataHook.sol +0 -112
  105. package/test/mock/MockBuybackDataHookMintPath.sol +0 -68
  106. package/test/mock/MockSuckerRegistry.sol +0 -17
  107. package/test/regression/TestBurnPermissionRequired.t.sol +0 -294
  108. package/test/regression/TestCashOutBuybackFeeLeak.t.sol +0 -232
  109. package/test/regression/TestCrossRevnetLiquidation.t.sol +0 -255
  110. package/test/regression/TestCumulativeLoanCounter.t.sol +0 -361
  111. package/test/regression/TestLiquidateGapHandling.t.sol +0 -394
  112. package/test/regression/TestZeroPriceFeed.t.sol +0 -422
@@ -1,301 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- // forge-lint: disable-next-line(unaliased-plain-import)
5
- import "forge-std/Test.sol";
6
- // forge-lint: disable-next-line(unaliased-plain-import)
7
- import /* {*} from */ "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
8
- // forge-lint: disable-next-line(unaliased-plain-import)
9
- import /* {*} from */ "./../src/REVDeployer.sol";
10
- // forge-lint: disable-next-line(unaliased-plain-import)
11
- import "@croptop/core-v6/src/CTPublisher.sol";
12
- import {MockBuybackDataHook} from "./mock/MockBuybackDataHook.sol";
13
- // forge-lint: disable-next-line(unaliased-plain-import)
14
- import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
15
- // forge-lint: disable-next-line(unaliased-plain-import)
16
- import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
17
- // forge-lint: disable-next-line(unaliased-plain-import)
18
- import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
19
- // forge-lint: disable-next-line(unaliased-plain-import)
20
- import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
21
- // forge-lint: disable-next-line(unaliased-plain-import)
22
- import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
23
- import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
24
- import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
25
- import {REVLoans} from "../src/REVLoans.sol";
26
- import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
27
- import {REVDescription} from "../src/structs/REVDescription.sol";
28
- import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
29
- import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
30
- import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
31
- import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
32
- import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
33
- import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
34
- import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
35
- import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
36
- import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
37
- import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
38
- import {REVEmpty721Config} from "./helpers/REVEmpty721Config.sol";
39
- import {REVOwner} from "../src/REVOwner.sol";
40
- import {IREVDeployer} from "../src/interfaces/IREVDeployer.sol";
41
- import {MockSuckerRegistry} from "./mock/MockSuckerRegistry.sol";
42
-
43
- /// @notice Documents and verifies that stage transitions change the borrowable amount for the same collateral.
44
- /// This is by design: loan value tracks the current bonding curve parameters (cashOutTaxRate),
45
- /// just as cash-out value does.
46
- contract TestStageTransitionBorrowable is TestBaseWorkflow {
47
- // forge-lint: disable-next-line(mixed-case-variable)
48
- bytes32 REV_DEPLOYER_SALT = "REVDeployer";
49
-
50
- // forge-lint: disable-next-line(mixed-case-variable)
51
- REVDeployer REV_DEPLOYER;
52
- // forge-lint: disable-next-line(mixed-case-variable)
53
- REVOwner REV_OWNER;
54
- // forge-lint: disable-next-line(mixed-case-variable)
55
- JB721TiersHook EXAMPLE_HOOK;
56
- // forge-lint: disable-next-line(mixed-case-variable)
57
- IJB721TiersHookDeployer HOOK_DEPLOYER;
58
- // forge-lint: disable-next-line(mixed-case-variable)
59
- IJB721TiersHookStore HOOK_STORE;
60
- // forge-lint: disable-next-line(mixed-case-variable)
61
- IJBAddressRegistry ADDRESS_REGISTRY;
62
- // forge-lint: disable-next-line(mixed-case-variable)
63
- IREVLoans LOANS_CONTRACT;
64
- // forge-lint: disable-next-line(mixed-case-variable)
65
- IJBSuckerRegistry SUCKER_REGISTRY;
66
- // forge-lint: disable-next-line(mixed-case-variable)
67
- CTPublisher PUBLISHER;
68
- // forge-lint: disable-next-line(mixed-case-variable)
69
- MockBuybackDataHook MOCK_BUYBACK;
70
-
71
- // forge-lint: disable-next-line(mixed-case-variable)
72
- uint256 FEE_PROJECT_ID;
73
- // forge-lint: disable-next-line(mixed-case-variable)
74
- uint256 REVNET_ID;
75
-
76
- // forge-lint: disable-next-line(mixed-case-variable)
77
- address USER = makeAddr("user");
78
-
79
- address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
80
-
81
- /// @notice Stage 1 starts now with 60% cashOutTaxRate, stage 2 starts after 30 days with 20% cashOutTaxRate.
82
- function _buildConfig()
83
- internal
84
- view
85
- returns (REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc)
86
- {
87
- JBAccountingContext[] memory acc = new JBAccountingContext[](1);
88
- acc[0] = JBAccountingContext({
89
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
90
- });
91
- tc = new JBTerminalConfig[](1);
92
- tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
93
-
94
- REVStageConfig[] memory stages = new REVStageConfig[](2);
95
- JBSplit[] memory splits = new JBSplit[](1);
96
- splits[0].beneficiary = payable(multisig());
97
- splits[0].percent = 10_000;
98
-
99
- // Stage 1: high cashOutTaxRate (60%)
100
- stages[0] = REVStageConfig({
101
- startsAtOrAfter: uint40(block.timestamp),
102
- autoIssuances: new REVAutoIssuance[](0),
103
- splitPercent: 0,
104
- splits: splits,
105
- initialIssuance: uint112(1000e18),
106
- issuanceCutFrequency: 0,
107
- issuanceCutPercent: 0,
108
- cashOutTaxRate: 6000, // 60%
109
- extraMetadata: 0
110
- });
111
-
112
- // Stage 2: low cashOutTaxRate (20%) — starts after 30 days
113
- stages[1] = REVStageConfig({
114
- startsAtOrAfter: uint40(block.timestamp + 30 days),
115
- autoIssuances: new REVAutoIssuance[](0),
116
- splitPercent: 0,
117
- splits: splits,
118
- initialIssuance: uint112(1000e18),
119
- issuanceCutFrequency: 0,
120
- issuanceCutPercent: 0,
121
- cashOutTaxRate: 2000, // 20%
122
- extraMetadata: 0
123
- });
124
-
125
- cfg = REVConfig({
126
- // forge-lint: disable-next-line(named-struct-fields)
127
- description: REVDescription("StageTest", "STG", "ipfs://test", "STG_SALT"),
128
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
129
- splitOperator: multisig(),
130
- stageConfigurations: stages
131
- });
132
-
133
- sdc = REVSuckerDeploymentConfig({
134
- deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("STG"))
135
- });
136
- }
137
-
138
- function setUp() public override {
139
- super.setUp();
140
- FEE_PROJECT_ID = jbProjects().createFor(multisig());
141
- SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
142
- HOOK_STORE = new JB721TiersHookStore();
143
- EXAMPLE_HOOK = new JB721TiersHook(
144
- jbDirectory(),
145
- jbPermissions(),
146
- jbPrices(),
147
- jbRulesets(),
148
- HOOK_STORE,
149
- jbSplits(),
150
- IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
151
- multisig()
152
- );
153
- ADDRESS_REGISTRY = new JBAddressRegistry();
154
- HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
155
- PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
156
- MOCK_BUYBACK = new MockBuybackDataHook();
157
- LOANS_CONTRACT = new REVLoans({
158
- controller: jbController(),
159
- suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
160
- revId: FEE_PROJECT_ID,
161
- owner: address(this),
162
- permit2: permit2(),
163
- trustedForwarder: TRUSTED_FORWARDER
164
- });
165
- REV_OWNER = new REVOwner(
166
- IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
167
- jbDirectory(),
168
- FEE_PROJECT_ID,
169
- SUCKER_REGISTRY,
170
- address(LOANS_CONTRACT),
171
- address(0)
172
- );
173
-
174
- REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
175
- jbController(),
176
- SUCKER_REGISTRY,
177
- FEE_PROJECT_ID,
178
- HOOK_DEPLOYER,
179
- PUBLISHER,
180
- IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
181
- address(LOANS_CONTRACT),
182
- TRUSTED_FORWARDER,
183
- address(REV_OWNER)
184
- );
185
-
186
- REV_OWNER.setDeployer(REV_DEPLOYER);
187
-
188
- vm.prank(multisig());
189
- jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
190
-
191
- // Deploy the fee project first.
192
- (REVConfig memory feeCfg, JBTerminalConfig[] memory feeTc, REVSuckerDeploymentConfig memory feeSdc) =
193
- _buildConfig();
194
- vm.prank(multisig());
195
- REV_DEPLOYER.deployFor({
196
- revnetId: FEE_PROJECT_ID,
197
- configuration: feeCfg,
198
- terminalConfigurations: feeTc,
199
- suckerDeploymentConfiguration: feeSdc,
200
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
201
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
202
- });
203
-
204
- // Deploy the test revnet.
205
- (REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc) = _buildConfig();
206
- // forge-lint: disable-next-line(named-struct-fields)
207
- cfg.description = REVDescription("StageTest2", "ST2", "ipfs://test2", "STG_SALT_2");
208
- (REVNET_ID,) = REV_DEPLOYER.deployFor({
209
- revnetId: 0,
210
- configuration: cfg,
211
- terminalConfigurations: tc,
212
- suckerDeploymentConfiguration: sdc,
213
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
214
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
215
- });
216
-
217
- vm.deal(USER, 100 ether);
218
- }
219
-
220
- /// @notice BY DESIGN: Borrowable amount increases when transitioning to a stage with lower cashOutTaxRate.
221
- /// This documents that loan value tracks the current bonding curve, just as cash-out value does.
222
- /// @dev The bonding curve only applies a tax discount when cashOutCount < totalSupply,
223
- /// so we need multiple payers to see the effect.
224
- function test_borrowableAmount_increasesWhenCashOutTaxRateDecreases() public {
225
- // Two payers so the bonding curve tax rate has a visible effect (count < supply).
226
- address otherPayer = makeAddr("otherPayer");
227
- vm.deal(otherPayer, 10 ether);
228
- vm.prank(otherPayer);
229
- jbMultiTerminal().pay{value: 10 ether}({
230
- projectId: REVNET_ID,
231
- token: JBConstants.NATIVE_TOKEN,
232
- amount: 10 ether,
233
- beneficiary: otherPayer,
234
- minReturnedTokens: 0,
235
- memo: "",
236
- metadata: ""
237
- });
238
-
239
- vm.prank(USER);
240
- uint256 tokens = jbMultiTerminal().pay{value: 10 ether}({
241
- projectId: REVNET_ID,
242
- token: JBConstants.NATIVE_TOKEN,
243
- amount: 10 ether,
244
- beneficiary: USER,
245
- minReturnedTokens: 0,
246
- memo: "",
247
- metadata: ""
248
- });
249
- assertGt(tokens, 0, "Should receive tokens");
250
-
251
- // Check borrowable amount during stage 1 (60% cashOutTaxRate).
252
- uint256 borrowableStage1 =
253
- LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
254
- assertGt(borrowableStage1, 0, "Borrowable amount should be positive in stage 1");
255
-
256
- // Warp to stage 2 (20% cashOutTaxRate).
257
- vm.warp(block.timestamp + 31 days);
258
-
259
- // Check borrowable amount during stage 2.
260
- uint256 borrowableStage2 =
261
- LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
262
-
263
- // Borrowable amount should be HIGHER with a lower cashOutTaxRate — by design.
264
- assertGt(borrowableStage2, borrowableStage1, "Borrowable amount should increase with lower cashOutTaxRate");
265
- }
266
-
267
- /// @notice Verifies that the bonding curve formula applies the tax rate correctly when count < supply.
268
- function test_borrowableAmount_taxRateReducesPartialCashOut() public {
269
- // Two payers so USER holds a fraction of total supply.
270
- address otherPayer = makeAddr("otherPayer");
271
- vm.deal(otherPayer, 10 ether);
272
- vm.prank(otherPayer);
273
- jbMultiTerminal().pay{value: 10 ether}({
274
- projectId: REVNET_ID,
275
- token: JBConstants.NATIVE_TOKEN,
276
- amount: 10 ether,
277
- beneficiary: otherPayer,
278
- minReturnedTokens: 0,
279
- memo: "",
280
- metadata: ""
281
- });
282
-
283
- vm.prank(USER);
284
- uint256 tokens = jbMultiTerminal().pay{value: 10 ether}({
285
- projectId: REVNET_ID,
286
- token: JBConstants.NATIVE_TOKEN,
287
- amount: 10 ether,
288
- beneficiary: USER,
289
- minReturnedTokens: 0,
290
- memo: "",
291
- metadata: ""
292
- });
293
-
294
- // With 60% tax rate and ~50% of supply, borrowable should be meaningfully less than pro-rata share.
295
- uint256 borrowable =
296
- LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
297
- assertGt(borrowable, 0, "Borrowable amount should be positive");
298
- // Pro-rata share would be ~10 ether (half of 20 ether surplus). With 60% tax, it should be less.
299
- assertLt(borrowable, 10 ether, "Borrowable should be less than pro-rata share due to tax rate");
300
- }
301
- }
@@ -1,262 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- // forge-lint: disable-next-line(unaliased-plain-import)
5
- import "forge-std/Test.sol";
6
- // forge-lint: disable-next-line(unaliased-plain-import)
7
- import /* {*} from */ "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
8
- // import /* {*} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
9
- // forge-lint: disable-next-line(unaliased-plain-import)
10
- import /* {*} from */ "./../src/REVDeployer.sol";
11
- // forge-lint: disable-next-line(unaliased-plain-import)
12
- import "@croptop/core-v6/src/CTPublisher.sol";
13
- import {MockBuybackDataHook} from "./mock/MockBuybackDataHook.sol";
14
- // forge-lint: disable-next-line(unaliased-plain-import)
15
- import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
16
- // forge-lint: disable-next-line(unaliased-plain-import)
17
- import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
18
- // forge-lint: disable-next-line(unaliased-plain-import)
19
- import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
20
- // forge-lint: disable-next-line(unaliased-plain-import)
21
- import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
22
- // forge-lint: disable-next-line(unaliased-plain-import)
23
- import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
24
- import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
25
- import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
26
- import {JBPermissionIds} from "@bananapus/permission-ids-v6/src/JBPermissionIds.sol";
27
- import {REVLoans} from "../src/REVLoans.sol";
28
- import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
29
- import {REVDescription} from "../src/structs/REVDescription.sol";
30
- import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
31
- import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
32
- import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
33
- import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
34
- import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
35
- import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
36
- import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
37
- import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
38
- import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
39
- import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
40
- import {REVEmpty721Config} from "./helpers/REVEmpty721Config.sol";
41
- import {REVOwner} from "../src/REVOwner.sol";
42
- import {IREVDeployer} from "../src/interfaces/IREVDeployer.sol";
43
- import {MockSuckerRegistry} from "./mock/MockSuckerRegistry.sol";
44
-
45
- /// @notice Tests for default operator permissions including SET_ROUTER_TERMINAL.
46
- /// Verifies that all default split operator permissions are granted correctly.
47
- contract TestSwapTerminalPermission is TestBaseWorkflow {
48
- // forge-lint: disable-next-line(mixed-case-variable)
49
- bytes32 REV_DEPLOYER_SALT = "REVDeployer";
50
-
51
- // forge-lint: disable-next-line(mixed-case-variable)
52
- REVDeployer REV_DEPLOYER;
53
- // forge-lint: disable-next-line(mixed-case-variable)
54
- REVOwner REV_OWNER;
55
- // forge-lint: disable-next-line(mixed-case-variable)
56
- JB721TiersHook EXAMPLE_HOOK;
57
- // forge-lint: disable-next-line(mixed-case-variable)
58
- IJB721TiersHookDeployer HOOK_DEPLOYER;
59
- // forge-lint: disable-next-line(mixed-case-variable)
60
- IJB721TiersHookStore HOOK_STORE;
61
- // forge-lint: disable-next-line(mixed-case-variable)
62
- IJBAddressRegistry ADDRESS_REGISTRY;
63
- // forge-lint: disable-next-line(mixed-case-variable)
64
- IREVLoans LOANS_CONTRACT;
65
- // forge-lint: disable-next-line(mixed-case-variable)
66
- IJBSuckerRegistry SUCKER_REGISTRY;
67
- // forge-lint: disable-next-line(mixed-case-variable)
68
- CTPublisher PUBLISHER;
69
- // forge-lint: disable-next-line(mixed-case-variable)
70
- MockBuybackDataHook MOCK_BUYBACK;
71
-
72
- // forge-lint: disable-next-line(mixed-case-variable)
73
- uint256 FEE_PROJECT_ID;
74
- // forge-lint: disable-next-line(mixed-case-variable)
75
- uint256 TEST_REVNET_ID;
76
-
77
- address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
78
-
79
- function setUp() public override {
80
- super.setUp();
81
- FEE_PROJECT_ID = jbProjects().createFor(multisig());
82
- SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
83
- HOOK_STORE = new JB721TiersHookStore();
84
- EXAMPLE_HOOK = new JB721TiersHook(
85
- jbDirectory(),
86
- jbPermissions(),
87
- jbPrices(),
88
- jbRulesets(),
89
- HOOK_STORE,
90
- jbSplits(),
91
- IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
92
- multisig()
93
- );
94
- ADDRESS_REGISTRY = new JBAddressRegistry();
95
- HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
96
- PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
97
- MOCK_BUYBACK = new MockBuybackDataHook();
98
- LOANS_CONTRACT = new REVLoans({
99
- controller: jbController(),
100
- suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
101
- revId: FEE_PROJECT_ID,
102
- owner: address(this),
103
- permit2: permit2(),
104
- trustedForwarder: TRUSTED_FORWARDER
105
- });
106
- REV_OWNER = new REVOwner(
107
- IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
108
- jbDirectory(),
109
- FEE_PROJECT_ID,
110
- SUCKER_REGISTRY,
111
- address(LOANS_CONTRACT),
112
- address(0)
113
- );
114
-
115
- REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
116
- jbController(),
117
- SUCKER_REGISTRY,
118
- FEE_PROJECT_ID,
119
- HOOK_DEPLOYER,
120
- PUBLISHER,
121
- IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
122
- address(LOANS_CONTRACT),
123
- TRUSTED_FORWARDER,
124
- address(REV_OWNER)
125
- );
126
-
127
- REV_OWNER.setDeployer(REV_DEPLOYER);
128
-
129
- vm.prank(multisig());
130
- jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
131
-
132
- // Deploy the fee project as a revnet
133
- (REVConfig memory feeCfg, JBTerminalConfig[] memory feeTc, REVSuckerDeploymentConfig memory feeSdc) =
134
- _buildConfig("FeeProject", "FEE", "FEE_SALT");
135
-
136
- vm.prank(multisig());
137
- REV_DEPLOYER.deployFor({
138
- revnetId: FEE_PROJECT_ID,
139
- configuration: feeCfg,
140
- terminalConfigurations: feeTc,
141
- suckerDeploymentConfiguration: feeSdc,
142
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
143
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
144
- });
145
-
146
- // Deploy the test revnet
147
- (REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc) =
148
- _buildConfig("TestRevnet", "TST", "TST_SALT");
149
-
150
- (TEST_REVNET_ID,) = REV_DEPLOYER.deployFor({
151
- revnetId: 0,
152
- configuration: cfg,
153
- terminalConfigurations: tc,
154
- suckerDeploymentConfiguration: sdc,
155
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
156
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
157
- });
158
- }
159
-
160
- function _buildConfig(
161
- string memory name,
162
- string memory ticker,
163
- bytes32 salt
164
- )
165
- internal
166
- view
167
- returns (REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc)
168
- {
169
- JBAccountingContext[] memory acc = new JBAccountingContext[](1);
170
- acc[0] = JBAccountingContext({
171
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
172
- });
173
- tc = new JBTerminalConfig[](1);
174
- tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
175
-
176
- REVStageConfig[] memory stages = new REVStageConfig[](1);
177
- JBSplit[] memory splits = new JBSplit[](1);
178
- splits[0].beneficiary = payable(multisig());
179
- splits[0].percent = 10_000;
180
- stages[0] = REVStageConfig({
181
- startsAtOrAfter: uint40(block.timestamp),
182
- autoIssuances: new REVAutoIssuance[](0),
183
- splitPercent: 0,
184
- splits: splits,
185
- initialIssuance: uint112(1000e18),
186
- issuanceCutFrequency: 0,
187
- issuanceCutPercent: 0,
188
- cashOutTaxRate: 5000,
189
- extraMetadata: 0
190
- });
191
-
192
- cfg = REVConfig({
193
- // forge-lint: disable-next-line(named-struct-fields)
194
- description: REVDescription(name, ticker, "ipfs://test", salt),
195
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
196
- splitOperator: multisig(),
197
- stageConfigurations: stages
198
- });
199
-
200
- sdc = REVSuckerDeploymentConfig({
201
- deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("TEST"))
202
- });
203
- }
204
-
205
- /// @notice Verify the split operator has SET_BUYBACK_HOOK and SET_ROUTER_TERMINAL permissions.
206
- function test_splitOperator_hasRegistryPermissions() public view {
207
- bool hasBuybackHook = jbPermissions()
208
- .hasPermission({
209
- operator: multisig(),
210
- account: address(REV_DEPLOYER),
211
- projectId: TEST_REVNET_ID,
212
- permissionId: JBPermissionIds.SET_BUYBACK_HOOK,
213
- includeRoot: false,
214
- includeWildcardProjectId: false
215
- });
216
- assertTrue(hasBuybackHook, "Split operator should have SET_BUYBACK_HOOK permission");
217
-
218
- bool hasRouterTerminal = jbPermissions()
219
- .hasPermission({
220
- operator: multisig(),
221
- account: address(REV_DEPLOYER),
222
- projectId: TEST_REVNET_ID,
223
- permissionId: JBPermissionIds.SET_ROUTER_TERMINAL,
224
- includeRoot: false,
225
- includeWildcardProjectId: false
226
- });
227
- assertTrue(hasRouterTerminal, "Split operator should have SET_ROUTER_TERMINAL permission");
228
- }
229
-
230
- /// @notice Verify all 8 default permissions are present for the split operator.
231
- function test_allDefaultPermissionsPresent() public view {
232
- // All 8 default permissions that should be granted
233
- uint256[8] memory expectedPermissions = [
234
- uint256(JBPermissionIds.SET_SPLIT_GROUPS),
235
- uint256(JBPermissionIds.SET_BUYBACK_POOL),
236
- uint256(JBPermissionIds.SET_BUYBACK_TWAP),
237
- uint256(JBPermissionIds.SET_PROJECT_URI),
238
- uint256(JBPermissionIds.ADD_PRICE_FEED),
239
- uint256(JBPermissionIds.SUCKER_SAFETY),
240
- uint256(JBPermissionIds.SET_BUYBACK_HOOK),
241
- uint256(JBPermissionIds.SET_ROUTER_TERMINAL)
242
- ];
243
-
244
- for (uint256 i = 0; i < expectedPermissions.length; i++) {
245
- bool hasPermission = jbPermissions()
246
- .hasPermission({
247
- operator: multisig(),
248
- account: address(REV_DEPLOYER),
249
- projectId: TEST_REVNET_ID,
250
- permissionId: expectedPermissions[i],
251
- includeRoot: false,
252
- includeWildcardProjectId: false
253
- });
254
- assertTrue(
255
- hasPermission,
256
- string.concat(
257
- "Missing permission at index ", vm.toString(i), " (ID ", vm.toString(expectedPermissions[i]), ")"
258
- )
259
- );
260
- }
261
- }
262
- }