@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,675 +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 {IJBRulesetDataHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetDataHook.sol";
13
- import {IJBPayHook} from "@bananapus/core-v6/src/interfaces/IJBPayHook.sol";
14
- import {JBBeforePayRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforePayRecordedContext.sol";
15
- import {JBPayHookSpecification} from "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
16
- import {JBAfterPayRecordedContext} from "@bananapus/core-v6/src/structs/JBAfterPayRecordedContext.sol";
17
- import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
18
- import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
19
- import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
20
- import {REVEmpty721Config} from "./helpers/REVEmpty721Config.sol";
21
- // forge-lint: disable-next-line(unaliased-plain-import)
22
- import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
23
- // forge-lint: disable-next-line(unaliased-plain-import)
24
- import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
25
- // forge-lint: disable-next-line(unaliased-plain-import)
26
- import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
27
- // forge-lint: disable-next-line(unaliased-plain-import)
28
- import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
29
- // forge-lint: disable-next-line(unaliased-plain-import)
30
- import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
31
- import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
32
- import {JBPermissionIds} from "@bananapus/permission-ids-v6/src/JBPermissionIds.sol";
33
- import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
34
- import {JBPermissionsData} from "@bananapus/core-v6/src/structs/JBPermissionsData.sol";
35
- import {JBBeforeCashOutRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforeCashOutRecordedContext.sol";
36
- import {JBCashOutHookSpecification} from "@bananapus/core-v6/src/structs/JBCashOutHookSpecification.sol";
37
- import {JBTokenAmount} from "@bananapus/core-v6/src/structs/JBTokenAmount.sol";
38
- import {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.sol";
39
- import {MockPriceFeed} from "@bananapus/core-v6/test/mock/MockPriceFeed.sol";
40
- import {REVLoans} from "../src/REVLoans.sol";
41
- import {REVHiddenTokens} from "../src/REVHiddenTokens.sol";
42
- import {IREVHiddenTokens} from "../src/interfaces/IREVHiddenTokens.sol";
43
- import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
44
- import {REVDescription} from "../src/structs/REVDescription.sol";
45
- import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
46
- import {REVLoanSource} from "../src/structs/REVLoanSource.sol";
47
- import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
48
- import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
49
- import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
50
- import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
51
- import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
52
- import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
53
- import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
54
- import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
55
- import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
56
- import {JBSuckersPair} from "@bananapus/suckers-v6/src/structs/JBSuckersPair.sol";
57
- import {REVOwner} from "../src/REVOwner.sol";
58
- import {IREVDeployer} from "../src/interfaces/IREVDeployer.sol";
59
- import {MockSuckerRegistry} from "./mock/MockSuckerRegistry.sol";
60
-
61
- /// @notice A mock buyback hook that records the context passed to `beforeCashOutRecordedWith`
62
- /// so that tests can verify the cross-chain-adjusted values (H-3 fix).
63
- contract MockBuybackContextRecorder is IJBRulesetDataHook, IJBPayHook {
64
- function beforePayRecordedWith(JBBeforePayRecordedContext calldata context)
65
- external
66
- view
67
- override
68
- returns (uint256 weight, JBPayHookSpecification[] memory hookSpecifications)
69
- {
70
- weight = context.weight;
71
- hookSpecifications = new JBPayHookSpecification[](1);
72
- hookSpecifications[0] =
73
- JBPayHookSpecification({hook: IJBPayHook(address(this)), noop: false, amount: 0, metadata: ""});
74
- }
75
-
76
- function beforeCashOutRecordedWith(JBBeforeCashOutRecordedContext calldata context)
77
- external
78
- pure
79
- override
80
- returns (
81
- uint256 cashOutTaxRate,
82
- uint256 cashOutCount,
83
- uint256 totalSupply,
84
- uint256 effectiveSurplusValue,
85
- JBCashOutHookSpecification[] memory hookSpecifications
86
- )
87
- {
88
- // Echo selected context values back through the return data so the caller can assert
89
- // which values were forwarded into the hook without mutating state in a `view` function.
90
- cashOutTaxRate = context.totalSupply;
91
- cashOutCount = context.surplus.value;
92
- totalSupply = context.totalSupply;
93
- effectiveSurplusValue = 0;
94
- hookSpecifications = new JBCashOutHookSpecification[](0);
95
- }
96
-
97
- function hasMintPermissionFor(uint256, JBRuleset calldata, address) external pure override returns (bool) {
98
- return false;
99
- }
100
-
101
- function afterPayRecordedWith(JBAfterPayRecordedContext calldata) external payable override {}
102
-
103
- /// @notice No-op pool configuration for tests.
104
- function setPoolFor(uint256, PoolKey calldata, uint256, address) external pure {}
105
-
106
- /// @notice No-op pool configuration for tests (simplified overload).
107
- function setPoolFor(uint256, uint24, int24, uint256, address) external pure {}
108
-
109
- /// @notice No-op pool initialization for tests.
110
- function initializePoolFor(uint256, uint24, int24, uint256, address, uint160) external pure {}
111
-
112
- function supportsInterface(bytes4 interfaceId) external pure override returns (bool) {
113
- return interfaceId == type(IJBRulesetDataHook).interfaceId || interfaceId == type(IJBPayHook).interfaceId
114
- || interfaceId == type(IERC165).interfaceId;
115
- }
116
- }
117
-
118
- /// @notice A mock sucker registry that returns configurable non-zero remote supply and surplus.
119
- /// Used to verify that cross-chain values flow correctly to the buyback hook (H-3).
120
- contract MockSuckerRegistryWithRemote {
121
- uint256 public remoteSupply;
122
- uint256 public remoteSurplus;
123
-
124
- function DIRECTORY() external pure returns (IJBDirectory) {
125
- return IJBDirectory(address(0));
126
- }
127
-
128
- function MAX_TO_REMOTE_FEE() external pure returns (uint256) {
129
- return 0;
130
- }
131
-
132
- function PROJECTS() external pure returns (IJBProjects) {
133
- return IJBProjects(address(0));
134
- }
135
-
136
- function setRemoteValues(uint256 supply, uint256 surplus) external {
137
- remoteSupply = supply;
138
- remoteSurplus = surplus;
139
- }
140
-
141
- function isSuckerOf(uint256, address) external pure returns (bool) {
142
- return false;
143
- }
144
-
145
- function remoteTotalSupplyOf(uint256) external view returns (uint256) {
146
- return remoteSupply;
147
- }
148
-
149
- function remoteSurplusOf(uint256, uint256, uint256) external view returns (uint256) {
150
- return remoteSurplus;
151
- }
152
-
153
- function suckerDeployerIsAllowed(address) external pure returns (bool) {
154
- return false;
155
- }
156
-
157
- function suckerPairsOf(uint256) external pure returns (JBSuckersPair[] memory pairs) {
158
- return new JBSuckersPair[](0);
159
- }
160
-
161
- function suckersOf(uint256) external pure returns (address[] memory suckers) {
162
- return new address[](0);
163
- }
164
-
165
- function remoteBalanceOf(uint256, uint256, uint256) external pure returns (uint256) {
166
- return 0;
167
- }
168
-
169
- function toRemoteFee() external pure returns (uint256) {
170
- return 0;
171
- }
172
-
173
- function allowSuckerDeployer(address) external pure {}
174
-
175
- function allowSuckerDeployers(address[] calldata) external pure {}
176
-
177
- function deploySuckersFor(
178
- uint256,
179
- bytes32,
180
- JBSuckerDeployerConfig[] calldata
181
- )
182
- external
183
- pure
184
- returns (address[] memory suckers)
185
- {
186
- return new address[](0);
187
- }
188
-
189
- function removeDeprecatedSucker(uint256, address) external pure {}
190
-
191
- function removeSuckerDeployer(address) external pure {}
192
-
193
- function setToRemoteFee(uint256) external pure {}
194
- }
195
-
196
- /// @notice Tests verifying audit fix correctness for C-1, H-3, and C-5/A14.
197
- /// C-1: `_borrowableAmountFrom` passes `decimals` parameter (not hardcoded 18) to `remoteSurplusOf`.
198
- /// H-3: `REVOwner.beforeCashOutRecordedWith` forwards cross-chain-adjusted context to buyback hook.
199
- /// A14: `REVHiddenTokens` has operator gating and hidden tokens reduce economic supply until revealed.
200
- contract TestAuditFixVerification is TestBaseWorkflow {
201
- // forge-lint: disable-next-line(mixed-case-variable)
202
- bytes32 REV_DEPLOYER_SALT = "REVDeployer";
203
- // forge-lint: disable-next-line(mixed-case-variable)
204
- bytes32 ERC20_SALT = "REV_TOKEN";
205
-
206
- // forge-lint: disable-next-line(mixed-case-variable)
207
- REVDeployer REV_DEPLOYER;
208
- // forge-lint: disable-next-line(mixed-case-variable)
209
- REVOwner REV_OWNER;
210
- // forge-lint: disable-next-line(mixed-case-variable)
211
- JB721TiersHook EXAMPLE_HOOK;
212
- // forge-lint: disable-next-line(mixed-case-variable)
213
- IJB721TiersHookDeployer HOOK_DEPLOYER;
214
- // forge-lint: disable-next-line(mixed-case-variable)
215
- IJB721TiersHookStore HOOK_STORE;
216
- // forge-lint: disable-next-line(mixed-case-variable)
217
- IJBAddressRegistry ADDRESS_REGISTRY;
218
- // forge-lint: disable-next-line(mixed-case-variable)
219
- IREVLoans LOANS_CONTRACT;
220
- // forge-lint: disable-next-line(mixed-case-variable)
221
- REVHiddenTokens HIDDEN_TOKENS;
222
- // forge-lint: disable-next-line(mixed-case-variable)
223
- IJBSuckerRegistry SUCKER_REGISTRY;
224
- // forge-lint: disable-next-line(mixed-case-variable)
225
- CTPublisher PUBLISHER;
226
- // forge-lint: disable-next-line(mixed-case-variable)
227
- MockBuybackContextRecorder MOCK_BUYBACK;
228
- // forge-lint: disable-next-line(mixed-case-variable)
229
- MockSuckerRegistryWithRemote MOCK_SUCKER_REGISTRY;
230
- // forge-lint: disable-next-line(mixed-case-variable)
231
- MockERC20 USDC_TOKEN;
232
-
233
- // forge-lint: disable-next-line(mixed-case-variable)
234
- uint256 FEE_PROJECT_ID;
235
- // forge-lint: disable-next-line(mixed-case-variable)
236
- uint256 REVNET_ID;
237
-
238
- // forge-lint: disable-next-line(mixed-case-variable)
239
- address USER = makeAddr("user");
240
- // forge-lint: disable-next-line(mixed-case-variable)
241
- address UNAUTHORIZED = makeAddr("unauthorized");
242
-
243
- address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
244
-
245
- function setUp() public override {
246
- super.setUp();
247
- FEE_PROJECT_ID = jbProjects().createFor(multisig());
248
- MOCK_SUCKER_REGISTRY = new MockSuckerRegistryWithRemote();
249
- SUCKER_REGISTRY = IJBSuckerRegistry(address(MOCK_SUCKER_REGISTRY));
250
- HOOK_STORE = new JB721TiersHookStore();
251
- EXAMPLE_HOOK = new JB721TiersHook(
252
- jbDirectory(),
253
- jbPermissions(),
254
- jbPrices(),
255
- jbRulesets(),
256
- HOOK_STORE,
257
- jbSplits(),
258
- IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
259
- multisig()
260
- );
261
- ADDRESS_REGISTRY = new JBAddressRegistry();
262
- HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
263
- PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
264
- MOCK_BUYBACK = new MockBuybackContextRecorder();
265
-
266
- // Deploy a 6-decimal ERC20 token (simulates USDC).
267
- USDC_TOKEN = new MockERC20("USD Coin", "USDC");
268
-
269
- // Add a price feed: USDC/ETH at 1 USDC = 0.0005 ETH (i.e. 2000 USDC per ETH).
270
- // Feed returns price in 6 decimals.
271
- MockPriceFeed priceFeed = new MockPriceFeed(5e14, 18);
272
- vm.prank(multisig());
273
- jbPrices()
274
- .addPriceFeedFor(
275
- 0, uint32(uint160(address(USDC_TOKEN))), uint32(uint160(JBConstants.NATIVE_TOKEN)), priceFeed
276
- );
277
-
278
- LOANS_CONTRACT = new REVLoans({
279
- controller: jbController(),
280
- suckerRegistry: SUCKER_REGISTRY,
281
- revId: FEE_PROJECT_ID,
282
- owner: address(this),
283
- permit2: permit2(),
284
- trustedForwarder: TRUSTED_FORWARDER
285
- });
286
-
287
- HIDDEN_TOKENS = new REVHiddenTokens(jbController(), TRUSTED_FORWARDER);
288
-
289
- REV_OWNER = new REVOwner(
290
- IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
291
- jbDirectory(),
292
- FEE_PROJECT_ID,
293
- SUCKER_REGISTRY,
294
- address(LOANS_CONTRACT),
295
- address(HIDDEN_TOKENS)
296
- );
297
-
298
- REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
299
- jbController(),
300
- SUCKER_REGISTRY,
301
- FEE_PROJECT_ID,
302
- HOOK_DEPLOYER,
303
- PUBLISHER,
304
- IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
305
- address(LOANS_CONTRACT),
306
- TRUSTED_FORWARDER,
307
- address(REV_OWNER)
308
- );
309
-
310
- REV_OWNER.setDeployer(REV_DEPLOYER);
311
-
312
- vm.prank(multisig());
313
- jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
314
- _deployFeeProject();
315
- REVNET_ID = _deployRevnet();
316
- vm.deal(USER, 100e18);
317
- _grantBurnPermission(USER, REVNET_ID);
318
- }
319
-
320
- //*********************************************************************//
321
- // ────────── C-1: _borrowableAmountFrom decimal correctness ────────── //
322
- //*********************************************************************//
323
-
324
- /// @notice C-1 fix: `borrowableAmountFrom` with 6-decimal token produces
325
- /// a correctly scaled (non-inflated) result.
326
- function test_C1_borrowableAmount_6decimals_notInflated() public {
327
- // Pay into the revnet to create surplus and get tokens.
328
- uint256 payAmount = 10e18;
329
- vm.prank(USER);
330
- uint256 tokens = jbMultiTerminal().pay{value: payAmount}({
331
- projectId: REVNET_ID,
332
- token: JBConstants.NATIVE_TOKEN,
333
- amount: payAmount,
334
- beneficiary: USER,
335
- minReturnedTokens: 0,
336
- memo: "",
337
- metadata: ""
338
- });
339
- assertGt(tokens, 0, "User should have tokens");
340
-
341
- // Query borrowable amount in 6 decimals (USDC-like).
342
- uint256 borrowable6 =
343
- LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokens, 6, uint32(uint160(address(USDC_TOKEN))));
344
-
345
- // Query borrowable amount in 18 decimals (ETH).
346
- uint256 borrowable18 =
347
- LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
348
-
349
- // The 6-decimal result must be scaled to 6 decimals, NOT 18.
350
- // If the bug existed (hardcoded 18), borrowable6 would be inflated by 1e12.
351
- // A 6-decimal result for 10 ETH worth of collateral at 2000 USDC/ETH with 50% tax
352
- // should be on the order of thousands of USDC (millions in 6-decimal units).
353
- // The 18-decimal ETH result should be on the order of 10e18 (with bonding curve tax).
354
- assertLt(borrowable6, 1e18, "6-decimal borrowable must not be inflated to 18-decimal scale");
355
- assertGt(borrowable6, 0, "6-decimal borrowable should be positive");
356
- assertGt(borrowable18, 0, "18-decimal borrowable should be positive");
357
-
358
- // Sanity: the 6-decimal result should be much smaller numerically than 18-decimal.
359
- // With correct scaling, borrowable6 (USDC units) should be less than borrowable18 (ETH wei)
360
- // because USDC uses 6 decimals and ETH uses 18 decimals.
361
- assertLt(borrowable6, borrowable18, "6-decimal result should be smaller in magnitude than 18-decimal");
362
- }
363
-
364
- /// @notice C-1 fix: `borrowableAmountFrom` with 18-decimal token still works correctly.
365
- function test_C1_borrowableAmount_18decimals_stillCorrect() public {
366
- // Pay into the revnet.
367
- uint256 payAmount = 5e18;
368
- vm.prank(USER);
369
- uint256 tokens = jbMultiTerminal().pay{value: payAmount}({
370
- projectId: REVNET_ID,
371
- token: JBConstants.NATIVE_TOKEN,
372
- amount: payAmount,
373
- beneficiary: USER,
374
- minReturnedTokens: 0,
375
- memo: "",
376
- metadata: ""
377
- });
378
- assertGt(tokens, 0, "User should have tokens");
379
-
380
- // Query borrowable amount in 18 decimals.
381
- uint256 borrowable =
382
- LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
383
-
384
- // Should be positive and less than or equal to the total surplus.
385
- assertGt(borrowable, 0, "18-decimal borrowable should be positive");
386
- // With 50% cash out tax rate, borrowable should be less than the full pay amount.
387
- assertLe(borrowable, payAmount, "Borrowable should not exceed surplus");
388
- }
389
-
390
- //*********************************************************************//
391
- // ──── H-3: Buyback hook receives cross-chain-adjusted context ──── //
392
- //*********************************************************************//
393
-
394
- /// @notice H-3 fix: The buyback hook receives cross-chain-adjusted `totalSupply` and
395
- /// `surplus.value` in the context passed by `REVOwner.beforeCashOutRecordedWith`.
396
- function test_H3_buybackHook_receivesCrossChainAdjustedContext() public {
397
- // Pay into the revnet to get tokens and create surplus.
398
- uint256 payAmount = 10e18;
399
- vm.prank(USER);
400
- uint256 tokens = jbMultiTerminal().pay{value: payAmount}({
401
- projectId: REVNET_ID,
402
- token: JBConstants.NATIVE_TOKEN,
403
- amount: payAmount,
404
- beneficiary: USER,
405
- minReturnedTokens: 0,
406
- memo: "",
407
- metadata: ""
408
- });
409
- assertGt(tokens, 0, "User should have tokens");
410
-
411
- // Set non-zero remote supply and surplus to simulate cross-chain state.
412
- uint256 remoteSupply = 5000e18;
413
- uint256 remoteSurplus = 3e18;
414
- MOCK_SUCKER_REGISTRY.setRemoteValues(remoteSupply, remoteSurplus);
415
-
416
- // Get the local supply and surplus for comparison.
417
- uint256 localSupply = jbController().totalTokenSupplyWithReservedTokensOf(REVNET_ID);
418
- // The local surplus can be queried via the terminal.
419
- uint256 localSurplus = jbMultiTerminal()
420
- .currentSurplusOf(REVNET_ID, new address[](0), 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
421
-
422
- // Build a context simulating a cash out call (as the terminal would).
423
- JBBeforeCashOutRecordedContext memory context = JBBeforeCashOutRecordedContext({
424
- terminal: address(jbMultiTerminal()),
425
- holder: USER,
426
- projectId: REVNET_ID,
427
- rulesetId: 0,
428
- cashOutCount: tokens / 2,
429
- totalSupply: localSupply,
430
- surplus: JBTokenAmount({
431
- token: JBConstants.NATIVE_TOKEN,
432
- decimals: 18,
433
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
434
- value: localSurplus
435
- }),
436
- useTotalSurplus: true,
437
- cashOutTaxRate: 5000, // 50% tax
438
- beneficiaryIsFeeless: false,
439
- metadata: ""
440
- });
441
-
442
- // Call beforeCashOutRecordedWith on the REV_OWNER (data hook).
443
- // Note: REVOwner.beforeCashOutRecordedWith is `view` but our mock records state via SSTORE,
444
- // so we need to use a staticcall-breaking trick. We use low-level call to bypass the view restriction.
445
- (bool success, bytes memory retdata) =
446
- address(REV_OWNER).call(abi.encodeWithSelector(REV_OWNER.beforeCashOutRecordedWith.selector, context));
447
- assertTrue(success, "beforeCashOutRecordedWith should succeed");
448
-
449
- // Decode the return to verify it does not revert and to inspect what the buyback hook saw.
450
- (
451
- uint256 cashOutTaxRate,
452
- uint256 cashOutCount,
453
- uint256 totalSupply,
454
- uint256 effectiveSurplusValue,
455
- JBCashOutHookSpecification[] memory hookSpecifications
456
- ) = abi.decode(retdata, (uint256, uint256, uint256, uint256, JBCashOutHookSpecification[]));
457
-
458
- uint256 expectedTotalSupply = localSupply + remoteSupply;
459
- uint256 expectedSurplus = localSurplus + remoteSurplus;
460
-
461
- // The mocked buyback hook echoes the context it receives through the first two return values.
462
- assertEq(cashOutTaxRate, expectedTotalSupply, "Buyback hook should receive cross-chain totalSupply");
463
- assertEq(cashOutCount, expectedSurplus, "Buyback hook should receive cross-chain surplus value");
464
-
465
- // REVOwner should also return the same cross-chain-adjusted values to the terminal.
466
- assertEq(totalSupply, expectedTotalSupply, "REVOwner should return cross-chain totalSupply");
467
- assertEq(effectiveSurplusValue, expectedSurplus, "REVOwner should return cross-chain surplus value");
468
- assertEq(hookSpecifications.length, 1, "Expected REVOwner to append its fee hook spec");
469
- }
470
-
471
- //*********************************************************************//
472
- // ──────── A14: REVHiddenTokens operator gating & views ──────── //
473
- //*********************************************************************//
474
-
475
- /// @notice A14: Only the project owner or authorized operator can call `hideTokensOf`.
476
- /// Unauthorized callers should revert.
477
- function test_A14_hideTokensOf_revertsForUnauthorized() public {
478
- // Pay to get tokens.
479
- uint256 payAmount = 10e18;
480
- vm.prank(USER);
481
- jbMultiTerminal().pay{value: payAmount}({
482
- projectId: REVNET_ID,
483
- token: JBConstants.NATIVE_TOKEN,
484
- amount: payAmount,
485
- beneficiary: USER,
486
- minReturnedTokens: 0,
487
- memo: "",
488
- metadata: ""
489
- });
490
-
491
- uint256 userTokens = jbController().TOKENS().totalBalanceOf(USER, REVNET_ID);
492
- assertGt(userTokens, 0, "User should have tokens");
493
-
494
- // An unauthorized address (not project owner, not operator) should revert.
495
- vm.prank(UNAUTHORIZED);
496
- vm.expectRevert();
497
- HIDDEN_TOKENS.hideTokensOf(REVNET_ID, userTokens / 2, USER);
498
-
499
- // Even the token holder themselves cannot hide without operator permission.
500
- vm.prank(USER);
501
- vm.expectRevert();
502
- HIDDEN_TOKENS.hideTokensOf(REVNET_ID, userTokens / 2, USER);
503
- }
504
-
505
- /// @notice A14: Hiding tokens reduces the live token supply used for economic calculations.
506
- function test_A14_hidingTokens_reducesLiveSupply() public {
507
- // Pay to get tokens.
508
- uint256 payAmount = 10e18;
509
- vm.prank(USER);
510
- jbMultiTerminal().pay{value: payAmount}({
511
- projectId: REVNET_ID,
512
- token: JBConstants.NATIVE_TOKEN,
513
- amount: payAmount,
514
- beneficiary: USER,
515
- minReturnedTokens: 0,
516
- memo: "",
517
- metadata: ""
518
- });
519
-
520
- uint256 userTokens = jbController().TOKENS().totalBalanceOf(USER, REVNET_ID);
521
- uint256 totalSupplyBefore = jbController().totalTokenSupplyWithReservedTokensOf(REVNET_ID);
522
-
523
- _allowHolderToHide(USER, REVNET_ID);
524
-
525
- // Hide half the tokens via a split-operator delegate.
526
- uint256 hideCount = userTokens / 2;
527
- vm.prank(USER);
528
- HIDDEN_TOKENS.hideTokensOf(REVNET_ID, hideCount, USER);
529
-
530
- // After hiding: raw totalSupply should be reduced.
531
- uint256 totalSupplyAfter = jbController().totalTokenSupplyWithReservedTokensOf(REVNET_ID);
532
- assertEq(totalSupplyAfter, totalSupplyBefore - hideCount, "Raw total supply should decrease");
533
-
534
- assertEq(HIDDEN_TOKENS.hiddenBalanceOf(USER, REVNET_ID), hideCount, "Hidden balance should be tracked");
535
- assertEq(HIDDEN_TOKENS.totalHiddenOf(REVNET_ID), hideCount, "Total hidden should be tracked");
536
- }
537
-
538
- /// @notice A14: After hiding, economic supply is reduced until tokens are revealed.
539
- function test_A14_hiddenTokens_reduceEconomicSupply() public {
540
- // Pay to get tokens for the user.
541
- uint256 payAmount = 10e18;
542
- vm.prank(USER);
543
- jbMultiTerminal().pay{value: payAmount}({
544
- projectId: REVNET_ID,
545
- token: JBConstants.NATIVE_TOKEN,
546
- amount: payAmount,
547
- beneficiary: USER,
548
- minReturnedTokens: 0,
549
- memo: "",
550
- metadata: ""
551
- });
552
-
553
- uint256 userTokens = jbController().TOKENS().totalBalanceOf(USER, REVNET_ID);
554
- uint256 totalSupplyBefore = jbController().totalTokenSupplyWithReservedTokensOf(REVNET_ID);
555
-
556
- _allowHolderToHide(USER, REVNET_ID);
557
-
558
- // Hide 80% of the user's tokens.
559
- uint256 hideCount = (userTokens * 80) / 100;
560
- vm.prank(USER);
561
- HIDDEN_TOKENS.hideTokensOf(REVNET_ID, hideCount, USER);
562
-
563
- // The live totalSupply should be reduced, which also reduces economic supply.
564
- uint256 rawSupply = jbController().totalTokenSupplyWithReservedTokensOf(REVNET_ID);
565
- assertEq(rawSupply, totalSupplyBefore - hideCount, "Economic supply should decrease after hiding");
566
-
567
- // The hidden balance should be correctly tracked.
568
- assertEq(HIDDEN_TOKENS.hiddenBalanceOf(USER, REVNET_ID), hideCount, "Hidden balance tracked");
569
- assertEq(HIDDEN_TOKENS.totalHiddenOf(REVNET_ID), hideCount, "Total hidden tracked");
570
- }
571
-
572
- //*********************************************************************//
573
- // ──────────────── Internal helpers
574
- // ──────────────── //
575
- //*********************************************************************//
576
-
577
- function _grantBurnPermission(address account, uint256 revnetId) internal {
578
- uint8[] memory permissionIds = new uint8[](1);
579
- permissionIds[0] = JBPermissionIds.BURN_TOKENS;
580
- JBPermissionsData memory permissionsData = JBPermissionsData({
581
- operator: address(HIDDEN_TOKENS),
582
- // forge-lint: disable-next-line(unsafe-typecast)
583
- projectId: uint56(revnetId),
584
- permissionIds: permissionIds
585
- });
586
- vm.prank(account);
587
- jbPermissions().setPermissionsFor(account, permissionsData);
588
- }
589
-
590
- function _allowHolderToHide(address holder, uint256 revnetId) internal {
591
- vm.prank(address(REV_DEPLOYER));
592
- HIDDEN_TOKENS.setTokenHidingAllowedFor(revnetId, holder, true);
593
- }
594
-
595
- function _deployFeeProject() internal {
596
- JBAccountingContext[] memory acc = new JBAccountingContext[](1);
597
- acc[0] = JBAccountingContext({
598
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
599
- });
600
- JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
601
- tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
602
- REVStageConfig[] memory stages = new REVStageConfig[](1);
603
- stages[0] = REVStageConfig({
604
- startsAtOrAfter: uint48(block.timestamp),
605
- autoIssuances: new REVAutoIssuance[](0),
606
- splitPercent: 0,
607
- splits: new JBSplit[](0),
608
- initialIssuance: uint112(1000e18),
609
- issuanceCutFrequency: 0,
610
- issuanceCutPercent: 0,
611
- cashOutTaxRate: 0,
612
- extraMetadata: 0
613
- });
614
- // forge-lint: disable-next-line(named-struct-fields)
615
- REVConfig memory feeConfig = REVConfig({
616
- description: REVDescription("Fee Revnet", "FEE", "", ERC20_SALT),
617
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
618
- splitOperator: multisig(),
619
- stageConfigurations: stages
620
- });
621
- vm.prank(multisig());
622
- REV_DEPLOYER.deployFor({
623
- revnetId: FEE_PROJECT_ID,
624
- configuration: feeConfig,
625
- terminalConfigurations: tc,
626
- suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
627
- deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
628
- }),
629
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
630
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
631
- });
632
- }
633
-
634
- function _deployRevnet() internal returns (uint256) {
635
- JBAccountingContext[] memory acc = new JBAccountingContext[](2);
636
- acc[0] = JBAccountingContext({
637
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
638
- });
639
- acc[1] = JBAccountingContext({
640
- token: address(USDC_TOKEN), decimals: 6, currency: uint32(uint160(address(USDC_TOKEN)))
641
- });
642
- JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
643
- tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
644
- REVStageConfig[] memory stages = new REVStageConfig[](1);
645
- stages[0] = REVStageConfig({
646
- startsAtOrAfter: uint48(block.timestamp),
647
- autoIssuances: new REVAutoIssuance[](0),
648
- splitPercent: 0,
649
- splits: new JBSplit[](0),
650
- initialIssuance: uint112(1000e18),
651
- issuanceCutFrequency: 0,
652
- issuanceCutPercent: 0,
653
- cashOutTaxRate: 5000, // 50% cash out tax rate
654
- extraMetadata: 0
655
- });
656
- // forge-lint: disable-next-line(named-struct-fields)
657
- REVConfig memory revConfig = REVConfig({
658
- description: REVDescription("Test Revnet", "TEST", "", bytes32("TEST_TOKEN")),
659
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
660
- splitOperator: multisig(),
661
- stageConfigurations: stages
662
- });
663
- (uint256 revnetId,) = REV_DEPLOYER.deployFor({
664
- revnetId: 0,
665
- configuration: revConfig,
666
- terminalConfigurations: tc,
667
- suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
668
- deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("NANA")
669
- }),
670
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
671
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
672
- });
673
- return revnetId;
674
- }
675
- }