@rev-net/core-v6 0.0.37 → 0.0.39

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 (107) 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 +60 -65
  9. package/src/REVHiddenTokens.sol +2 -2
  10. package/src/REVLoans.sol +17 -10
  11. package/src/REVOwner.sol +121 -14
  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/ADMINISTRATION.md +0 -73
  16. package/ARCHITECTURE.md +0 -116
  17. package/AUDIT_INSTRUCTIONS.md +0 -90
  18. package/RISKS.md +0 -107
  19. package/SKILLS.md +0 -46
  20. package/STYLE_GUIDE.md +0 -610
  21. package/USER_JOURNEYS.md +0 -195
  22. package/foundry.lock +0 -11
  23. package/slither-ci.config.json +0 -10
  24. package/sphinx.lock +0 -507
  25. package/test/REV.integrations.t.sol +0 -573
  26. package/test/REVAutoIssuanceFuzz.t.sol +0 -328
  27. package/test/REVDeployerRegressions.t.sol +0 -396
  28. package/test/REVInvincibility.t.sol +0 -1371
  29. package/test/REVInvincibilityHandler.sol +0 -387
  30. package/test/REVLifecycle.t.sol +0 -420
  31. package/test/REVLoans.invariants.t.sol +0 -724
  32. package/test/REVLoansAttacks.t.sol +0 -816
  33. package/test/REVLoansFeeRecovery.t.sol +0 -783
  34. package/test/REVLoansFindings.t.sol +0 -711
  35. package/test/REVLoansRegressions.t.sol +0 -364
  36. package/test/REVLoansSourceFeeRecovery.t.sol +0 -517
  37. package/test/REVLoansSourced.t.sol +0 -1839
  38. package/test/REVLoansUnSourced.t.sol +0 -409
  39. package/test/TestAuditFixVerification.t.sol +0 -675
  40. package/test/TestBurnHeldTokens.t.sol +0 -394
  41. package/test/TestCEIPattern.t.sol +0 -508
  42. package/test/TestCashOutCallerValidation.t.sol +0 -452
  43. package/test/TestConversionDocumentation.t.sol +0 -365
  44. package/test/TestCrossCurrencyReclaim.t.sol +0 -610
  45. package/test/TestCrossSourceReallocation.t.sol +0 -361
  46. package/test/TestERC2771MetaTx.t.sol +0 -585
  47. package/test/TestEmptyBuybackSpecs.t.sol +0 -300
  48. package/test/TestFlashLoanSurplus.t.sol +0 -365
  49. package/test/TestHiddenTokens.t.sol +0 -474
  50. package/test/TestHookArrayOOB.t.sol +0 -278
  51. package/test/TestLiquidationBehavior.t.sol +0 -398
  52. package/test/TestLoanSourceRotation.t.sol +0 -553
  53. package/test/TestLoansCashOutDelay.t.sol +0 -493
  54. package/test/TestLongTailEconomics.t.sol +0 -677
  55. package/test/TestLowFindings.t.sol +0 -677
  56. package/test/TestMixedFixes.t.sol +0 -593
  57. package/test/TestPermit2Signatures.t.sol +0 -683
  58. package/test/TestReallocationSandwich.t.sol +0 -412
  59. package/test/TestRevnetRegressions.t.sol +0 -350
  60. package/test/TestSplitWeightAdjustment.t.sol +0 -527
  61. package/test/TestSplitWeightE2E.t.sol +0 -605
  62. package/test/TestSplitWeightFork.t.sol +0 -855
  63. package/test/TestStageTransitionBorrowable.t.sol +0 -301
  64. package/test/TestSwapTerminalPermission.t.sol +0 -262
  65. package/test/TestTerminalEncodingInHash.t.sol +0 -326
  66. package/test/TestUint112Overflow.t.sol +0 -311
  67. package/test/TestZeroAmountLoanGuard.t.sol +0 -378
  68. package/test/TestZeroRepayment.t.sol +0 -354
  69. package/test/audit/CrossChainBuybackRouteMismatch.t.sol +0 -184
  70. package/test/audit/HiddenSupplyCashout.t.sol +0 -61
  71. package/test/audit/LoanIdOverflowGuard.t.sol +0 -523
  72. package/test/audit/NemesisVerification.t.sol +0 -97
  73. package/test/audit/OperatorDelegation.t.sol +0 -356
  74. package/test/audit/PhantomSurplusTerminal.t.sol +0 -367
  75. package/test/audit/REVOwnerCurrencyMismatch.t.sol +0 -188
  76. package/test/audit/REVOwnerRemoteSurplusCurrencyMismatch.t.sol +0 -140
  77. package/test/audit/ReallocatePermission.t.sol +0 -363
  78. package/test/audit/RemoteLoanAccountingGap.t.sol +0 -74
  79. package/test/audit/SupportsInterfaceTest.t.sol +0 -51
  80. package/test/audit/TestFeeAllowanceLeak.t.sol +0 -197
  81. package/test/audit/TestLoansAndDeployerFixes.t.sol +0 -576
  82. package/test/fork/ForkTestBase.sol +0 -727
  83. package/test/fork/TestAutoIssuanceFork.t.sol +0 -148
  84. package/test/fork/TestCashOutFork.t.sol +0 -253
  85. package/test/fork/TestIssuanceDecayFork.t.sol +0 -158
  86. package/test/fork/TestLoanAdversarialFork.t.sol +0 -744
  87. package/test/fork/TestLoanBorrowFork.t.sol +0 -163
  88. package/test/fork/TestLoanCrossRulesetFork.t.sol +0 -308
  89. package/test/fork/TestLoanERC20Fork.t.sol +0 -459
  90. package/test/fork/TestLoanLiquidationFork.t.sol +0 -135
  91. package/test/fork/TestLoanReallocateFork.t.sol +0 -113
  92. package/test/fork/TestLoanRepayFork.t.sol +0 -188
  93. package/test/fork/TestLoanTransferFork.t.sol +0 -143
  94. package/test/fork/TestPermit2PaymentFork.t.sol +0 -300
  95. package/test/fork/TestSplitWeightFork.t.sol +0 -189
  96. package/test/helpers/MaliciousContracts.sol +0 -247
  97. package/test/helpers/REVEmpty721Config.sol +0 -45
  98. package/test/mock/MockBuybackCashOutRecorder.sol +0 -84
  99. package/test/mock/MockBuybackDataHook.sol +0 -112
  100. package/test/mock/MockBuybackDataHookMintPath.sol +0 -68
  101. package/test/mock/MockSuckerRegistry.sol +0 -17
  102. package/test/regression/TestBurnPermissionRequired.t.sol +0 -294
  103. package/test/regression/TestCashOutBuybackFeeLeak.t.sol +0 -232
  104. package/test/regression/TestCrossRevnetLiquidation.t.sol +0 -255
  105. package/test/regression/TestCumulativeLoanCounter.t.sol +0 -361
  106. package/test/regression/TestLiquidateGapHandling.t.sol +0 -394
  107. package/test/regression/TestZeroPriceFeed.t.sol +0 -422
@@ -1,452 +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
-
15
- // forge-lint: disable-next-line(unaliased-plain-import)
16
- import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
17
- // forge-lint: disable-next-line(unaliased-plain-import)
18
- import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
19
- // forge-lint: disable-next-line(unaliased-plain-import)
20
- import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
21
- // forge-lint: disable-next-line(unaliased-plain-import)
22
- import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
23
- // forge-lint: disable-next-line(unaliased-plain-import)
24
- import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
25
- import {JBCashOuts} from "@bananapus/core-v6/src/libraries/JBCashOuts.sol";
26
- import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
27
- import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
28
- import {JBBeforeCashOutRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforeCashOutRecordedContext.sol";
29
- import {JBCashOutHookSpecification} from "@bananapus/core-v6/src/structs/JBCashOutHookSpecification.sol";
30
- import {JBTokenAmount} from "@bananapus/core-v6/src/structs/JBTokenAmount.sol";
31
- import {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.sol";
32
- import {REVLoans} from "../src/REVLoans.sol";
33
- import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
34
- import {REVLoanSource} from "../src/structs/REVLoanSource.sol";
35
- import {REVDescription} from "../src/structs/REVDescription.sol";
36
- import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
37
- import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
38
- import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
39
- import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
40
- import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
41
- import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
42
- import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
43
- import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
44
- import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
45
- import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
46
- import {REVEmpty721Config} from "./helpers/REVEmpty721Config.sol";
47
- import {REVOwner} from "../src/REVOwner.sol";
48
- import {IREVDeployer} from "../src/interfaces/IREVDeployer.sol";
49
- import {MockSuckerRegistry} from "./mock/MockSuckerRegistry.sol";
50
-
51
- struct FeeProjectConfig {
52
- REVConfig configuration;
53
- JBTerminalConfig[] terminalConfigurations;
54
- REVSuckerDeploymentConfig suckerDeploymentConfiguration;
55
- }
56
-
57
- contract TestCashOutCallerValidation is TestBaseWorkflow {
58
- // forge-lint: disable-next-line(mixed-case-variable)
59
- bytes32 REV_DEPLOYER_SALT = "REVDeployer";
60
- // forge-lint: disable-next-line(mixed-case-variable)
61
- bytes32 ERC20_SALT = "REV_TOKEN";
62
-
63
- // forge-lint: disable-next-line(mixed-case-variable)
64
- REVDeployer REV_DEPLOYER;
65
- // forge-lint: disable-next-line(mixed-case-variable)
66
- REVOwner REV_OWNER;
67
- // forge-lint: disable-next-line(mixed-case-variable)
68
- JB721TiersHook EXAMPLE_HOOK;
69
- // forge-lint: disable-next-line(mixed-case-variable)
70
- IJB721TiersHookDeployer HOOK_DEPLOYER;
71
- // forge-lint: disable-next-line(mixed-case-variable)
72
- IJB721TiersHookStore HOOK_STORE;
73
- // forge-lint: disable-next-line(mixed-case-variable)
74
- IJBAddressRegistry ADDRESS_REGISTRY;
75
- // forge-lint: disable-next-line(mixed-case-variable)
76
- IREVLoans LOANS_CONTRACT;
77
- // forge-lint: disable-next-line(mixed-case-variable)
78
- MockERC20 TOKEN;
79
- // forge-lint: disable-next-line(mixed-case-variable)
80
- IJBSuckerRegistry SUCKER_REGISTRY;
81
- // forge-lint: disable-next-line(mixed-case-variable)
82
- CTPublisher PUBLISHER;
83
- // forge-lint: disable-next-line(mixed-case-variable)
84
- MockBuybackDataHook MOCK_BUYBACK;
85
-
86
- // forge-lint: disable-next-line(mixed-case-variable)
87
- uint256 FEE_PROJECT_ID;
88
- // forge-lint: disable-next-line(mixed-case-variable)
89
- uint256 REVNET_ID;
90
-
91
- // forge-lint: disable-next-line(mixed-case-variable)
92
- address USER = makeAddr("user");
93
- // forge-lint: disable-next-line(mixed-case-variable)
94
- address RANDOM_CALLER = makeAddr("randomCaller");
95
-
96
- address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
97
-
98
- function getFeeProjectConfig() internal view returns (FeeProjectConfig memory) {
99
- string memory name = "Revnet";
100
- string memory symbol = "$REV";
101
- string memory projectUri = "ipfs://QmNRHT91HcDgMcenebYX7rJigt77cgNcosvuhX21wkF3tx";
102
- uint8 decimals = 18;
103
- uint256 decimalMultiplier = 10 ** decimals;
104
-
105
- JBAccountingContext[] memory accountingContextsToAccept = new JBAccountingContext[](1);
106
- accountingContextsToAccept[0] = JBAccountingContext({
107
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
108
- });
109
-
110
- JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
111
- terminalConfigurations[0] =
112
- JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: accountingContextsToAccept});
113
-
114
- REVStageConfig[] memory stageConfigurations = new REVStageConfig[](1);
115
- JBSplit[] memory splits = new JBSplit[](1);
116
- splits[0].beneficiary = payable(multisig());
117
- splits[0].percent = 10_000;
118
-
119
- {
120
- REVAutoIssuance[] memory issuanceConfs = new REVAutoIssuance[](0);
121
- stageConfigurations[0] = REVStageConfig({
122
- startsAtOrAfter: uint40(block.timestamp),
123
- autoIssuances: issuanceConfs,
124
- splitPercent: 2000,
125
- splits: splits,
126
- // forge-lint: disable-next-line(unsafe-typecast)
127
- initialIssuance: uint112(1000 * decimalMultiplier),
128
- issuanceCutFrequency: 90 days,
129
- issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
130
- cashOutTaxRate: 6000,
131
- extraMetadata: 0
132
- });
133
- }
134
-
135
- REVConfig memory revnetConfiguration = REVConfig({
136
- // forge-lint: disable-next-line(named-struct-fields)
137
- description: REVDescription(name, symbol, projectUri, ERC20_SALT),
138
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
139
- splitOperator: multisig(),
140
- stageConfigurations: stageConfigurations
141
- });
142
-
143
- return FeeProjectConfig({
144
- configuration: revnetConfiguration,
145
- terminalConfigurations: terminalConfigurations,
146
- suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
147
- deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("REV"))
148
- })
149
- });
150
- }
151
-
152
- function getRevnetConfig() internal view returns (FeeProjectConfig memory) {
153
- string memory name = "NANA";
154
- string memory symbol = "$NANA";
155
- string memory projectUri = "ipfs://QmNRHT91HcDgMcenebYX7rJigt77cgNxosvuhX21wkF3tx";
156
- uint8 decimals = 18;
157
- uint256 decimalMultiplier = 10 ** decimals;
158
-
159
- JBAccountingContext[] memory accountingContextsToAccept = new JBAccountingContext[](1);
160
- accountingContextsToAccept[0] = JBAccountingContext({
161
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
162
- });
163
-
164
- JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
165
- terminalConfigurations[0] =
166
- JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: accountingContextsToAccept});
167
-
168
- REVStageConfig[] memory stageConfigurations = new REVStageConfig[](1);
169
- JBSplit[] memory splits = new JBSplit[](1);
170
- splits[0].beneficiary = payable(multisig());
171
- splits[0].percent = 10_000;
172
-
173
- {
174
- REVAutoIssuance[] memory issuanceConfs = new REVAutoIssuance[](0);
175
- stageConfigurations[0] = REVStageConfig({
176
- startsAtOrAfter: uint40(block.timestamp),
177
- autoIssuances: issuanceConfs,
178
- splitPercent: 2000,
179
- splits: splits,
180
- // forge-lint: disable-next-line(unsafe-typecast)
181
- initialIssuance: uint112(1000 * decimalMultiplier),
182
- issuanceCutFrequency: 90 days,
183
- issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
184
- cashOutTaxRate: 3000,
185
- extraMetadata: 0
186
- });
187
- }
188
-
189
- REVLoanSource[] memory loanSources = new REVLoanSource[](1);
190
- loanSources[0] = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
191
-
192
- REVConfig memory revnetConfiguration = REVConfig({
193
- // forge-lint: disable-next-line(named-struct-fields)
194
- description: REVDescription(name, symbol, projectUri, "NANA_TOKEN"),
195
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
196
- splitOperator: multisig(),
197
- stageConfigurations: stageConfigurations
198
- });
199
-
200
- return FeeProjectConfig({
201
- configuration: revnetConfiguration,
202
- terminalConfigurations: terminalConfigurations,
203
- suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
204
- deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("NANA"))
205
- })
206
- });
207
- }
208
-
209
- function setUp() public override {
210
- super.setUp();
211
-
212
- FEE_PROJECT_ID = jbProjects().createFor(multisig());
213
- SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
214
- HOOK_STORE = new JB721TiersHookStore();
215
- EXAMPLE_HOOK = new JB721TiersHook(
216
- jbDirectory(),
217
- jbPermissions(),
218
- jbPrices(),
219
- jbRulesets(),
220
- HOOK_STORE,
221
- jbSplits(),
222
- IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
223
- multisig()
224
- );
225
- ADDRESS_REGISTRY = new JBAddressRegistry();
226
- HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
227
- PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
228
- MOCK_BUYBACK = new MockBuybackDataHook();
229
- TOKEN = new MockERC20("1/2 ETH", "1/2");
230
-
231
- LOANS_CONTRACT = new REVLoans({
232
- controller: jbController(),
233
- suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
234
- revId: FEE_PROJECT_ID,
235
- owner: address(this),
236
- permit2: permit2(),
237
- trustedForwarder: TRUSTED_FORWARDER
238
- });
239
-
240
- REV_OWNER = new REVOwner(
241
- IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
242
- jbDirectory(),
243
- FEE_PROJECT_ID,
244
- SUCKER_REGISTRY,
245
- address(LOANS_CONTRACT),
246
- address(0)
247
- );
248
-
249
- REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
250
- jbController(),
251
- SUCKER_REGISTRY,
252
- FEE_PROJECT_ID,
253
- HOOK_DEPLOYER,
254
- PUBLISHER,
255
- IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
256
- address(LOANS_CONTRACT),
257
- TRUSTED_FORWARDER,
258
- address(REV_OWNER)
259
- );
260
-
261
- REV_OWNER.setDeployer(REV_DEPLOYER);
262
-
263
- // Approve the deployer to configure the fee project.
264
- vm.prank(multisig());
265
- jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
266
-
267
- // Deploy the fee project.
268
- FeeProjectConfig memory feeProjectConfig = getFeeProjectConfig();
269
- vm.prank(multisig());
270
- REV_DEPLOYER.deployFor({
271
- revnetId: FEE_PROJECT_ID,
272
- configuration: feeProjectConfig.configuration,
273
- terminalConfigurations: feeProjectConfig.terminalConfigurations,
274
- suckerDeploymentConfiguration: feeProjectConfig.suckerDeploymentConfiguration,
275
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
276
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
277
- });
278
-
279
- // Deploy the revnet.
280
- FeeProjectConfig memory revnetConfig = getRevnetConfig();
281
- (REVNET_ID,) = REV_DEPLOYER.deployFor({
282
- revnetId: 0,
283
- configuration: revnetConfig.configuration,
284
- terminalConfigurations: revnetConfig.terminalConfigurations,
285
- suckerDeploymentConfiguration: revnetConfig.suckerDeploymentConfiguration,
286
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
287
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
288
- });
289
-
290
- vm.deal(USER, 100 ether);
291
- }
292
-
293
- /// @notice Test that a normal cash out flow processes fees correctly to the fee project.
294
- function test_normalCashOutFlow_feeProcessedCorrectly() public {
295
- // Pay ETH into revnet to get tokens.
296
- vm.prank(USER);
297
- uint256 tokenCount =
298
- jbMultiTerminal().pay{value: 10 ether}(REVNET_ID, JBConstants.NATIVE_TOKEN, 10 ether, USER, 0, "", "");
299
- assertGt(tokenCount, 0, "Should have received tokens");
300
-
301
- // Record fee project balance before cash out.
302
- uint256 feeProjectBalanceBefore =
303
- jbTerminalStore().balanceOf(address(jbMultiTerminal()), REVNET_ID, JBConstants.NATIVE_TOKEN);
304
- assertGt(feeProjectBalanceBefore, 0, "Revnet should have balance");
305
-
306
- // Warp past CASH_OUT_DELAY.
307
- uint256 delay = REV_DEPLOYER.CASH_OUT_DELAY();
308
- vm.warp(block.timestamp + delay + 1);
309
-
310
- // Record fee project terminal balance before.
311
- uint256 feeBalanceBefore =
312
- jbTerminalStore().balanceOf(address(jbMultiTerminal()), FEE_PROJECT_ID, JBConstants.NATIVE_TOKEN);
313
-
314
- // Cash out tokens.
315
- vm.prank(USER);
316
- uint256 reclaimed = jbMultiTerminal()
317
- .cashOutTokensOf({
318
- holder: USER,
319
- projectId: REVNET_ID,
320
- cashOutCount: tokenCount,
321
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
322
- minTokensReclaimed: 0,
323
- beneficiary: payable(USER),
324
- metadata: ""
325
- });
326
-
327
- assertGt(reclaimed, 0, "Should have reclaimed some ETH");
328
-
329
- // Verify fee project balance increased (it received the fee).
330
- uint256 feeBalanceAfter =
331
- jbTerminalStore().balanceOf(address(jbMultiTerminal()), FEE_PROJECT_ID, JBConstants.NATIVE_TOKEN);
332
- assertGt(feeBalanceAfter, feeBalanceBefore, "Fee project balance should increase from cash out fee");
333
- }
334
-
335
- /// @notice Revnet cash-out fees and buyback sell-side specs are composed together.
336
- function test_beforeCashOutRecordedWith_proxiesIntoBuybackAndAppendsFeeSpec() public {
337
- bytes memory buybackMetadata = abi.encode(uint256(123));
338
- MOCK_BUYBACK.configureCashOutResult({
339
- cashOutTaxRate: JBConstants.MAX_CASH_OUT_TAX_RATE,
340
- cashOutCount: 0,
341
- totalSupply: 0,
342
- hookAmount: 0,
343
- hookMetadata: buybackMetadata
344
- });
345
-
346
- JBBeforeCashOutRecordedContext memory context = JBBeforeCashOutRecordedContext({
347
- terminal: address(jbMultiTerminal()),
348
- holder: USER,
349
- projectId: REVNET_ID,
350
- rulesetId: 0,
351
- cashOutCount: 1000,
352
- totalSupply: 10_000,
353
- surplus: JBTokenAmount({
354
- token: JBConstants.NATIVE_TOKEN,
355
- value: 100 ether,
356
- decimals: 18,
357
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
358
- }),
359
- useTotalSurplus: true,
360
- cashOutTaxRate: 3000,
361
- beneficiaryIsFeeless: false,
362
- metadata: ""
363
- });
364
-
365
- (
366
- uint256 cashOutTaxRate,
367
- uint256 cashOutCount,
368
- uint256 totalSupply,,
369
- JBCashOutHookSpecification[] memory hookSpecifications
370
- ) = REV_OWNER.beforeCashOutRecordedWith(context);
371
-
372
- uint256 feeCashOutCount = context.cashOutCount * REV_DEPLOYER.FEE() / JBConstants.MAX_FEE;
373
- uint256 nonFeeCashOutCount = context.cashOutCount - feeCashOutCount;
374
- uint256 postFeeReclaimedAmount = JBCashOuts.cashOutFrom({
375
- surplus: context.surplus.value,
376
- cashOutCount: nonFeeCashOutCount,
377
- totalSupply: context.totalSupply,
378
- cashOutTaxRate: context.cashOutTaxRate
379
- });
380
- uint256 feeAmount = JBCashOuts.cashOutFrom({
381
- surplus: context.surplus.value - postFeeReclaimedAmount,
382
- cashOutCount: feeCashOutCount,
383
- totalSupply: context.totalSupply - nonFeeCashOutCount,
384
- cashOutTaxRate: context.cashOutTaxRate
385
- });
386
-
387
- assertEq(cashOutTaxRate, JBConstants.MAX_CASH_OUT_TAX_RATE, "Buyback cash out tax rate should be forwarded");
388
- assertEq(cashOutCount, nonFeeCashOutCount, "Buyback should receive the non-fee cash out count");
389
- assertEq(totalSupply, context.totalSupply, "Total supply should pass through");
390
- assertEq(hookSpecifications.length, 2, "Buyback spec and revnet fee spec should both be returned");
391
-
392
- assertEq(address(hookSpecifications[0].hook), address(MOCK_BUYBACK), "First hook spec should come from buyback");
393
- assertEq(hookSpecifications[0].amount, 0, "Buyback sell-side spec should preserve its forwarded amount");
394
- assertEq(hookSpecifications[0].metadata, buybackMetadata, "Buyback metadata should be preserved");
395
-
396
- assertEq(address(hookSpecifications[1].hook), address(REV_OWNER), "Second hook spec should charge fee");
397
- assertEq(hookSpecifications[1].amount, feeAmount, "Fee spec amount should match the revnet fee math");
398
- assertEq(
399
- hookSpecifications[1].metadata,
400
- abi.encode(jbMultiTerminal()),
401
- "Fee spec metadata should encode the fee terminal"
402
- );
403
- }
404
-
405
- /// @notice Test that afterCashOutRecordedWith has no access control — anyone can call it.
406
- /// A non-terminal caller would just be donating their own funds as fees.
407
- function test_nonTerminalCaller_justDonatesOwnFunds() public {
408
- // Fund the random caller with ETH.
409
- vm.deal(RANDOM_CALLER, 10 ether);
410
-
411
- // Build a minimal JBAfterCashOutRecordedContext.
412
- // The key point: afterCashOutRecordedWith does NOT check msg.sender against any terminal registry.
413
- // If a non-terminal calls it with native ETH, the ETH just goes to the fee project as a donation.
414
- JBAfterCashOutRecordedContext memory context = JBAfterCashOutRecordedContext({
415
- holder: RANDOM_CALLER,
416
- projectId: REVNET_ID,
417
- rulesetId: 0,
418
- cashOutCount: 0,
419
- reclaimedAmount: JBTokenAmount({
420
- token: JBConstants.NATIVE_TOKEN,
421
- decimals: 18,
422
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
423
- value: 0
424
- }),
425
- forwardedAmount: JBTokenAmount({
426
- token: JBConstants.NATIVE_TOKEN,
427
- decimals: 18,
428
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
429
- value: 1 ether
430
- }),
431
- cashOutTaxRate: 0,
432
- beneficiary: payable(RANDOM_CALLER),
433
- hookMetadata: abi.encode(jbMultiTerminal()),
434
- cashOutMetadata: ""
435
- });
436
-
437
- // Record fee project balance before.
438
- uint256 feeBalanceBefore =
439
- jbTerminalStore().balanceOf(address(jbMultiTerminal()), FEE_PROJECT_ID, JBConstants.NATIVE_TOKEN);
440
-
441
- // Call afterCashOutRecordedWith from a random (non-terminal) address.
442
- // This should NOT revert with any authorization error.
443
- // The caller sends ETH which gets paid as a fee to the fee project.
444
- vm.prank(RANDOM_CALLER);
445
- REV_OWNER.afterCashOutRecordedWith{value: 1 ether}(context);
446
-
447
- // Verify the fee project received the ETH (donation).
448
- uint256 feeBalanceAfter =
449
- jbTerminalStore().balanceOf(address(jbMultiTerminal()), FEE_PROJECT_ID, JBConstants.NATIVE_TOKEN);
450
- assertGt(feeBalanceAfter, feeBalanceBefore, "Fee project should receive the donated ETH");
451
- }
452
- }