@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,605 +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 {MockBuybackDataHookMintPath} from "./mock/MockBuybackDataHookMintPath.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
-
25
- import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
26
- import {JBMetadataResolver} from "@bananapus/core-v6/src/libraries/JBMetadataResolver.sol";
27
- import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
28
- import {REVLoans} from "../src/REVLoans.sol";
29
- import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
30
- import {REVDescription} from "../src/structs/REVDescription.sol";
31
- import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
32
- import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
33
- import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
34
- import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
35
- import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
36
- import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
37
- import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
38
- import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
39
- import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
40
- import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
41
- import {IJBRulesetDataHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetDataHook.sol";
42
- import {IJBBuybackHookRegistry} from "@bananapus/buyback-hook-v6/src/interfaces/IJBBuybackHookRegistry.sol";
43
- import {JB721TierConfig} from "@bananapus/721-hook-v6/src/structs/JB721TierConfig.sol";
44
- import {JB721TierConfigFlags} from "@bananapus/721-hook-v6/src/structs/JB721TierConfigFlags.sol";
45
- import {JB721InitTiersConfig} from "@bananapus/721-hook-v6/src/structs/JB721InitTiersConfig.sol";
46
- import {IJB721TokenUriResolver} from "@bananapus/721-hook-v6/src/interfaces/IJB721TokenUriResolver.sol";
47
- import "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
48
- import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
49
- import {REVDeploy721TiersHookConfig} from "../src/structs/REVDeploy721TiersHookConfig.sol";
50
- import {REVBaseline721HookConfig} from "../src/structs/REVBaseline721HookConfig.sol";
51
- import {REV721TiersHookFlags} from "../src/structs/REV721TiersHookFlags.sol";
52
- import {REVCroptopAllowedPost} from "../src/structs/REVCroptopAllowedPost.sol";
53
- import {REVEmpty721Config} from "./helpers/REVEmpty721Config.sol";
54
- import {REVOwner} from "../src/REVOwner.sol";
55
- import {IREVDeployer} from "../src/interfaces/IREVDeployer.sol";
56
- import {MockSuckerRegistry} from "./mock/MockSuckerRegistry.sol";
57
-
58
- /// @notice E2E tests verifying that the split weight adjustment in REVDeployer produces correct token counts
59
- /// when payments flow through the full terminal → store → dataHook → mint pipeline.
60
- /// Tests both mint path (buyback decides to mint) and AMM path (buyback decides to swap).
61
- contract TestSplitWeightE2E is TestBaseWorkflow {
62
- using JBMetadataResolver for bytes;
63
-
64
- // forge-lint: disable-next-line(mixed-case-variable)
65
- bytes32 REV_DEPLOYER_SALT = "REVDeployer_E2E";
66
-
67
- // forge-lint: disable-next-line(mixed-case-variable)
68
- REVDeployer REV_DEPLOYER;
69
- // forge-lint: disable-next-line(mixed-case-variable)
70
- REVOwner REV_OWNER;
71
- // forge-lint: disable-next-line(mixed-case-variable)
72
- JB721TiersHook EXAMPLE_HOOK;
73
- // forge-lint: disable-next-line(mixed-case-variable)
74
- IJB721TiersHookDeployer HOOK_DEPLOYER;
75
- // forge-lint: disable-next-line(mixed-case-variable)
76
- IJB721TiersHookStore HOOK_STORE;
77
- // forge-lint: disable-next-line(mixed-case-variable)
78
- IJBAddressRegistry ADDRESS_REGISTRY;
79
- // forge-lint: disable-next-line(mixed-case-variable)
80
- IREVLoans LOANS_CONTRACT;
81
- // forge-lint: disable-next-line(mixed-case-variable)
82
- IJBSuckerRegistry SUCKER_REGISTRY;
83
- // forge-lint: disable-next-line(mixed-case-variable)
84
- CTPublisher PUBLISHER;
85
- // forge-lint: disable-next-line(mixed-case-variable)
86
- MockBuybackDataHookMintPath MOCK_BUYBACK_MINT;
87
-
88
- // forge-lint: disable-next-line(mixed-case-variable)
89
- uint256 FEE_PROJECT_ID;
90
-
91
- address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
92
- // forge-lint: disable-next-line(mixed-case-variable)
93
- address PAYER = makeAddr("payer");
94
- // forge-lint: disable-next-line(mixed-case-variable)
95
- address SPLIT_BENEFICIARY = makeAddr("splitBeneficiary");
96
-
97
- // Tier configuration: 1 ETH tier with 30% split.
98
- uint104 constant TIER_PRICE = 1 ether;
99
- uint32 constant SPLIT_PERCENT = 300_000_000; // 30% of SPLITS_TOTAL_PERCENT (1_000_000_000)
100
- uint112 constant INITIAL_ISSUANCE = 1000e18; // 1000 tokens per ETH
101
-
102
- function setUp() public override {
103
- super.setUp();
104
-
105
- FEE_PROJECT_ID = jbProjects().createFor(multisig());
106
-
107
- SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
108
- HOOK_STORE = new JB721TiersHookStore();
109
- EXAMPLE_HOOK = new JB721TiersHook(
110
- jbDirectory(),
111
- jbPermissions(),
112
- jbPrices(),
113
- jbRulesets(),
114
- HOOK_STORE,
115
- jbSplits(),
116
- IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
117
- multisig()
118
- );
119
- ADDRESS_REGISTRY = new JBAddressRegistry();
120
- HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
121
- PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
122
- MOCK_BUYBACK_MINT = new MockBuybackDataHookMintPath();
123
-
124
- LOANS_CONTRACT = new REVLoans({
125
- controller: jbController(),
126
- suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
127
- revId: FEE_PROJECT_ID,
128
- owner: address(this),
129
- permit2: permit2(),
130
- trustedForwarder: TRUSTED_FORWARDER
131
- });
132
-
133
- REV_OWNER = new REVOwner(
134
- IJBBuybackHookRegistry(address(MOCK_BUYBACK_MINT)),
135
- jbDirectory(),
136
- FEE_PROJECT_ID,
137
- SUCKER_REGISTRY,
138
- address(LOANS_CONTRACT),
139
- address(0)
140
- );
141
-
142
- REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
143
- jbController(),
144
- SUCKER_REGISTRY,
145
- FEE_PROJECT_ID,
146
- HOOK_DEPLOYER,
147
- PUBLISHER,
148
- IJBBuybackHookRegistry(address(MOCK_BUYBACK_MINT)),
149
- address(LOANS_CONTRACT),
150
- TRUSTED_FORWARDER,
151
- address(REV_OWNER)
152
- );
153
-
154
- REV_OWNER.setDeployer(REV_DEPLOYER);
155
-
156
- vm.prank(multisig());
157
- jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
158
-
159
- // Fund the payer.
160
- vm.deal(PAYER, 100 ether);
161
- }
162
-
163
- // ───────────────────────── Helpers
164
- // ─────────────────────────
165
-
166
- function _buildMinimalConfig()
167
- internal
168
- view
169
- returns (REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc)
170
- {
171
- JBAccountingContext[] memory acc = new JBAccountingContext[](1);
172
- acc[0] = JBAccountingContext({
173
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
174
- });
175
- tc = new JBTerminalConfig[](1);
176
- tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
177
-
178
- REVStageConfig[] memory stages = new REVStageConfig[](1);
179
- JBSplit[] memory splits = new JBSplit[](1);
180
- splits[0].beneficiary = payable(multisig());
181
- splits[0].percent = 10_000;
182
- stages[0] = REVStageConfig({
183
- startsAtOrAfter: uint40(block.timestamp),
184
- autoIssuances: new REVAutoIssuance[](0),
185
- splitPercent: 0,
186
- splits: splits,
187
- initialIssuance: INITIAL_ISSUANCE,
188
- issuanceCutFrequency: 0,
189
- issuanceCutPercent: 0,
190
- cashOutTaxRate: 5000,
191
- extraMetadata: 0
192
- });
193
-
194
- cfg = REVConfig({
195
- // forge-lint: disable-next-line(named-struct-fields)
196
- description: REVDescription("E2E Test", "E2E", "ipfs://e2e", "E2E_SALT"),
197
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
198
- splitOperator: multisig(),
199
- stageConfigurations: stages
200
- });
201
-
202
- sdc = REVSuckerDeploymentConfig({
203
- deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("E2E_TEST"))
204
- });
205
- }
206
-
207
- function _build721Config() internal view returns (REVDeploy721TiersHookConfig memory) {
208
- // Create a tier: 1 ETH, 30% split to SPLIT_BENEFICIARY.
209
- JB721TierConfig[] memory tiers = new JB721TierConfig[](1);
210
- JBSplit[] memory tierSplits = new JBSplit[](1);
211
- tierSplits[0] = JBSplit({
212
- preferAddToBalance: false,
213
- percent: uint32(JBConstants.SPLITS_TOTAL_PERCENT), // 100% of the split portion goes to this beneficiary
214
- projectId: 0,
215
- beneficiary: payable(SPLIT_BENEFICIARY),
216
- lockedUntil: 0,
217
- hook: IJBSplitHook(address(0))
218
- });
219
-
220
- tiers[0] = JB721TierConfig({
221
- price: TIER_PRICE,
222
- initialSupply: 100,
223
- votingUnits: 0,
224
- reserveFrequency: 0,
225
- reserveBeneficiary: address(0),
226
- // forge-lint: disable-next-line(unsafe-typecast)
227
- encodedIPFSUri: bytes32("tier1"),
228
- category: 1,
229
- discountPercent: 0,
230
- flags: JB721TierConfigFlags({
231
- allowOwnerMint: false,
232
- useReserveBeneficiaryAsDefault: false,
233
- transfersPausable: false,
234
- useVotingUnits: false,
235
- cantBeRemoved: false,
236
- cantIncreaseDiscountPercent: false,
237
- cantBuyWithCredits: false
238
- }),
239
- splitPercent: SPLIT_PERCENT,
240
- splits: tierSplits
241
- });
242
-
243
- return REVDeploy721TiersHookConfig({
244
- baseline721HookConfiguration: REVBaseline721HookConfig({
245
- name: "E2E NFT",
246
- symbol: "E2ENFT",
247
- baseUri: "ipfs://",
248
- tokenUriResolver: IJB721TokenUriResolver(address(0)),
249
- contractUri: "ipfs://contract",
250
- tiersConfig: JB721InitTiersConfig({
251
- tiers: tiers, currency: uint32(uint160(JBConstants.NATIVE_TOKEN)), decimals: 18
252
- }),
253
- flags: REV721TiersHookFlags({
254
- noNewTiersWithReserves: false,
255
- noNewTiersWithVotes: false,
256
- noNewTiersWithOwnerMinting: false,
257
- preventOverspending: false
258
- })
259
- }),
260
- // forge-lint: disable-next-line(unsafe-typecast)
261
- salt: bytes32("E2E_721"),
262
- preventSplitOperatorAdjustingTiers: false,
263
- preventSplitOperatorUpdatingMetadata: false,
264
- preventSplitOperatorMinting: false,
265
- preventSplitOperatorIncreasingDiscountPercent: false
266
- });
267
- }
268
-
269
- /// @notice Deploy the fee project, then deploy a revnet with 721 tiers.
270
- function _deployRevnetWith721() internal returns (uint256 revnetId, IJB721TiersHook hook) {
271
- // Deploy fee project first.
272
- (REVConfig memory feeCfg, JBTerminalConfig[] memory feeTc, REVSuckerDeploymentConfig memory feeSdc) =
273
- _buildMinimalConfig();
274
- // forge-lint: disable-next-line(named-struct-fields)
275
- feeCfg.description = REVDescription("Fee", "FEE", "ipfs://fee", "FEE_SALT");
276
-
277
- vm.prank(multisig());
278
- REV_DEPLOYER.deployFor({
279
- revnetId: FEE_PROJECT_ID,
280
- configuration: feeCfg,
281
- terminalConfigurations: feeTc,
282
- suckerDeploymentConfiguration: feeSdc,
283
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
284
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
285
- });
286
-
287
- // Deploy the revnet with 721 hook.
288
- (REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc) =
289
- _buildMinimalConfig();
290
- REVDeploy721TiersHookConfig memory hookConfig = _build721Config();
291
-
292
- (revnetId, hook) = REV_DEPLOYER.deployFor({
293
- revnetId: 0,
294
- configuration: cfg,
295
- terminalConfigurations: tc,
296
- suckerDeploymentConfiguration: sdc,
297
- tiered721HookConfiguration: hookConfig,
298
- allowedPosts: new REVCroptopAllowedPost[](0)
299
- });
300
- }
301
-
302
- /// @notice Build payment metadata that tells the 721 hook to mint from tier 1.
303
- function _buildPayMetadata(address hookAddress) internal pure returns (bytes memory) {
304
- // The 721 hook uses getId("pay", METADATA_ID_TARGET).
305
- // For clones, METADATA_ID_TARGET = address(implementation), but for our test the hook
306
- // is deployed via deployer and METADATA_ID_TARGET is set in the constructor.
307
- // We'll use the hook address as target since that's what `address(this)` resolves to
308
- // in a clone's delegatecall context... Actually for the JB721TiersHookDeployer,
309
- // METADATA_ID_TARGET is the implementation address. Let's compute it directly.
310
-
311
- // Actually, we need to read METADATA_ID_TARGET from the deployed hook.
312
- // For now, let's compute the metadata ID using the hook's METADATA_ID_TARGET.
313
- // We'll handle this in the test function where we have access to the hook instance.
314
-
315
- // Tier IDs to mint: [1] (first tier is ID 1)
316
- uint16[] memory tierIds = new uint16[](1);
317
- tierIds[0] = 1;
318
-
319
- // Encode: (allowOverspending, tierIdsToMint)
320
- bytes memory tierData = abi.encode(true, tierIds);
321
-
322
- // Build the metadata ID.
323
- bytes4 metadataId = JBMetadataResolver.getId("pay", hookAddress);
324
-
325
- // Build full metadata using createMetadata.
326
- bytes4[] memory ids = new bytes4[](1);
327
- ids[0] = metadataId;
328
- bytes[] memory datas = new bytes[](1);
329
- datas[0] = tierData;
330
-
331
- return JBMetadataResolver.createMetadata(ids, datas);
332
- }
333
-
334
- // ───────────────────────── Tests
335
- // ─────────────────────────
336
-
337
- /// @notice Mint path: pay 1 ETH for tier with 30% split.
338
- /// Verifies tokens minted == 700 (not 1000), confirming the weight scaling is correct.
339
- ///
340
- /// The core question this settles: does the terminal mint tokens based on the FULL payment amount?
341
- /// YES — JBTerminalStore.recordPaymentFrom line 410: tokenCount = mulDiv(amount.value, weight, weightRatio)
342
- /// where amount.value is the full 1 ETH, NOT the reduced 0.7 ETH.
343
- ///
344
- /// So the weight MUST be scaled down. Without scaling:
345
- /// tokenCount = mulDiv(1e18, 1000e18, 1e18) = 1000e18 → 1000 tokens for 0.7 ETH of actual value = WRONG
346
- /// With scaling:
347
- /// tokenCount = mulDiv(1e18, 700e18, 1e18) = 700e18 → 700 tokens for 0.7 ETH of actual value = CORRECT
348
- function test_e2e_mintPath_splitReducesTokens() public {
349
- (uint256 revnetId, IJB721TiersHook hook) = _deployRevnetWith721();
350
-
351
- // Build metadata targeting the hook's METADATA_ID_TARGET.
352
- address metadataTarget = hook.METADATA_ID_TARGET();
353
- bytes memory metadata = _buildPayMetadata(metadataTarget);
354
-
355
- // Pay 1 ETH through the terminal.
356
- vm.prank(PAYER);
357
- uint256 tokensReceived = jbMultiTerminal().pay{value: 1 ether}({
358
- projectId: revnetId,
359
- token: JBConstants.NATIVE_TOKEN,
360
- amount: 1 ether,
361
- beneficiary: PAYER,
362
- minReturnedTokens: 0,
363
- memo: "E2E split weight test",
364
- metadata: metadata
365
- });
366
-
367
- // Expected: 1 ETH payment, 0.3 ETH split (30% of 1 ETH tier price).
368
- // projectAmount = 0.7 ETH.
369
- // Buyback hook (mint path) returns context.weight unchanged.
370
- // REVDeployer scales: weight = 1000e18 * 0.7e18 / 1e18 = 700e18.
371
- // Terminal mints: mulDiv(1e18, 700e18, 1e18) = 700e18 = 700 tokens.
372
- uint256 expectedTokens = 700e18;
373
-
374
- assertEq(tokensReceived, expectedTokens, "tokens should be 700 (weight scaled for 30% split)");
375
-
376
- // Confirm payer's actual token balance matches.
377
- uint256 payerBalance = jbTokens().totalBalanceOf(PAYER, revnetId);
378
- assertEq(payerBalance, expectedTokens, "payer balance matches expected tokens");
379
- }
380
-
381
- /// @notice Mint path without splits: pay 1 ETH with no tier metadata.
382
- /// Baseline: all tokens should be minted at full weight.
383
- function test_e2e_mintPath_noSplits_fullTokens() public {
384
- (uint256 revnetId,) = _deployRevnetWith721();
385
-
386
- // Pay 1 ETH with NO tier metadata (no NFT purchase, no splits).
387
- vm.prank(PAYER);
388
- uint256 tokensReceived = jbMultiTerminal().pay{value: 1 ether}({
389
- projectId: revnetId,
390
- token: JBConstants.NATIVE_TOKEN,
391
- amount: 1 ether,
392
- beneficiary: PAYER,
393
- minReturnedTokens: 0,
394
- memo: "E2E no split test",
395
- metadata: ""
396
- });
397
-
398
- // No splits → no weight reduction. Full 1000 tokens.
399
- uint256 expectedTokens = 1000e18;
400
- assertEq(tokensReceived, expectedTokens, "tokens should be 1000 (no splits, full weight)");
401
- }
402
-
403
- /// @notice Mint path: pay 2 ETH for 1 ETH tier with 30% split.
404
- /// 0.3 ETH goes to split, 1.7 ETH enters project.
405
- /// Weight should be scaled to 1.7/2.0 of the original.
406
- function test_e2e_mintPath_overpay_splitReducesTokens() public {
407
- (uint256 revnetId, IJB721TiersHook hook) = _deployRevnetWith721();
408
-
409
- address metadataTarget = hook.METADATA_ID_TARGET();
410
- bytes memory metadata = _buildPayMetadata(metadataTarget);
411
-
412
- vm.prank(PAYER);
413
- uint256 tokensReceived = jbMultiTerminal().pay{value: 2 ether}({
414
- projectId: revnetId,
415
- token: JBConstants.NATIVE_TOKEN,
416
- amount: 2 ether,
417
- beneficiary: PAYER,
418
- minReturnedTokens: 0,
419
- memo: "E2E overpay split test",
420
- metadata: metadata
421
- });
422
-
423
- // 2 ETH payment, 1 tier at 1 ETH with 30% split → 0.3 ETH split.
424
- // projectAmount = 2 - 0.3 = 1.7 ETH.
425
- // weight = 1000e18 * 1.7 / 2.0 = 850e18.
426
- // tokenCount = mulDiv(2e18, 850e18, 1e18) = 1700e18 = 1700 tokens.
427
- uint256 expectedTokens = 1700e18;
428
- assertEq(tokensReceived, expectedTokens, "tokens should be 1700 (weight scaled for 0.3 ETH split on 2 ETH)");
429
- }
430
-
431
- /// @notice AMM path: buyback hook returns weight=0 (swapping).
432
- /// With splits, weight should still be 0 (no tokens minted by terminal).
433
- function test_e2e_ammPath_splitWithBuyback_zeroWeight() public {
434
- // Deploy a separate REVDeployer with the AMM buyback mock.
435
- MockBuybackDataHook ammBuyback = new MockBuybackDataHook();
436
-
437
- vm.prank(multisig());
438
- jbProjects().approve(address(0), FEE_PROJECT_ID); // Clear old approval.
439
-
440
- REVOwner ammOwner = new REVOwner(
441
- IJBBuybackHookRegistry(address(ammBuyback)),
442
- jbDirectory(),
443
- FEE_PROJECT_ID,
444
- SUCKER_REGISTRY,
445
- address(LOANS_CONTRACT),
446
- address(0)
447
- );
448
- REVDeployer ammDeployer = new REVDeployer{salt: "REVDeployer_AMM_E2E"}(
449
- jbController(),
450
- SUCKER_REGISTRY,
451
- FEE_PROJECT_ID,
452
- HOOK_DEPLOYER,
453
- PUBLISHER,
454
- IJBBuybackHookRegistry(address(ammBuyback)),
455
- address(LOANS_CONTRACT),
456
- TRUSTED_FORWARDER,
457
- address(ammOwner)
458
- );
459
-
460
- ammOwner.setDeployer(ammDeployer);
461
-
462
- vm.prank(multisig());
463
- jbProjects().approve(address(ammDeployer), FEE_PROJECT_ID);
464
-
465
- // Deploy fee project.
466
- (REVConfig memory feeCfg, JBTerminalConfig[] memory feeTc, REVSuckerDeploymentConfig memory feeSdc) =
467
- _buildMinimalConfig();
468
- // forge-lint: disable-next-line(named-struct-fields)
469
- feeCfg.description = REVDescription("Fee AMM", "FEEA", "ipfs://feeamm", "FEEA_SALT");
470
-
471
- vm.prank(multisig());
472
- ammDeployer.deployFor({
473
- revnetId: FEE_PROJECT_ID,
474
- configuration: feeCfg,
475
- terminalConfigurations: feeTc,
476
- suckerDeploymentConfiguration: feeSdc,
477
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
478
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
479
- });
480
-
481
- // Deploy revnet with 721 hook.
482
- (REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc) =
483
- _buildMinimalConfig();
484
- // forge-lint: disable-next-line(named-struct-fields)
485
- cfg.description = REVDescription("AMM E2E", "AMME", "ipfs://amme2e", "AMME_SALT");
486
- REVDeploy721TiersHookConfig memory hookConfig = _build721Config();
487
-
488
- (uint256 revnetId, IJB721TiersHook hook) = ammDeployer.deployFor({
489
- revnetId: 0,
490
- configuration: cfg,
491
- terminalConfigurations: tc,
492
- suckerDeploymentConfiguration: sdc,
493
- tiered721HookConfiguration: hookConfig,
494
- allowedPosts: new REVCroptopAllowedPost[](0)
495
- });
496
-
497
- // Build metadata.
498
- address metadataTarget = hook.METADATA_ID_TARGET();
499
- bytes memory metadata = _buildPayMetadata(metadataTarget);
500
-
501
- // The AMM mock buyback returns weight=context.weight + a hook spec (simulates swap decision).
502
- // But wait — when projectAmount < context.amount.value, REVDeployer scales the weight.
503
- // The AMM mock doesn't return weight=0 like the real buyback would for a swap.
504
- // It returns context.weight with a hook spec.
505
- //
506
- // For the real buyback in swap mode:
507
- // - Returns weight=0 (line 279 of JBBuybackHook.sol)
508
- // - Returns hookSpec with amountToSwapWith
509
- // - Terminal mints 0 tokens (weight=0)
510
- // - Buyback hook's afterPay handles the swap and mints tokens directly via controller
511
- //
512
- // The mock doesn't replicate this behavior exactly.
513
- // Let's verify the mock's behavior: it returns context.weight + a spec with amount=0.
514
- // So this test really shows the mint path with an extra hook spec, not true AMM.
515
- //
516
- // For a true AMM test we'd need a real Uniswap pool. For now, verify that
517
- // when the buyback hook returns weight=0 (which we can mock), tokens = 0.
518
-
519
- // Mock the buyback to return weight=0 (swap mode) for any call.
520
- vm.mockCall(
521
- address(ammBuyback),
522
- abi.encodeWithSelector(IJBRulesetDataHook.beforePayRecordedWith.selector),
523
- abi.encode(
524
- uint256(0), // weight = 0 (buying back from AMM)
525
- new JBPayHookSpecification[](0)
526
- )
527
- );
528
-
529
- vm.prank(PAYER);
530
- uint256 tokensReceived = jbMultiTerminal().pay{value: 1 ether}({
531
- projectId: revnetId,
532
- token: JBConstants.NATIVE_TOKEN,
533
- amount: 1 ether,
534
- beneficiary: PAYER,
535
- minReturnedTokens: 0,
536
- memo: "E2E AMM + split test",
537
- metadata: metadata
538
- });
539
-
540
- // Buyback returns weight=0 → REVDeployer preserves 0 (both branches: projectAmount==0 → 0, else
541
- // mulDiv(0,...) → 0). Terminal: tokenCount = mulDiv(1e18, 0, 1e18) = 0.
542
- // No tokens minted by terminal. In production, the buyback hook's afterPay would handle the swap.
543
- assertEq(tokensReceived, 0, "AMM path: terminal should mint 0 tokens (buyback handles swap)");
544
- }
545
-
546
- /// @notice Verify the invariant: tokens / projectAmount is the same rate regardless of split percentage.
547
- /// This proves the weight scaling keeps the token-per-ETH rate consistent.
548
- ///
549
- /// With splits: 700 tokens for 0.7 ETH entering project = 1000 tokens/ETH
550
- /// Without splits: 1000 tokens for 1.0 ETH entering project = 1000 tokens/ETH
551
- function test_e2e_invariant_tokenPerEthConsistent() public {
552
- // --- Revnet 1: with 721 splits (30%) ---
553
- (uint256 revnetId1, IJB721TiersHook hook1) = _deployRevnetWith721();
554
- address metadataTarget1 = hook1.METADATA_ID_TARGET();
555
- bytes memory metadata1 = _buildPayMetadata(metadataTarget1);
556
-
557
- vm.prank(PAYER);
558
- uint256 tokens1 = jbMultiTerminal().pay{value: 1 ether}({
559
- projectId: revnetId1,
560
- token: JBConstants.NATIVE_TOKEN,
561
- amount: 1 ether,
562
- beneficiary: PAYER,
563
- minReturnedTokens: 0,
564
- memo: "invariant test: with splits",
565
- metadata: metadata1
566
- });
567
-
568
- // --- Revnet 2: no splits (plain payment, no tier metadata) ---
569
- (REVConfig memory cfg2, JBTerminalConfig[] memory tc2, REVSuckerDeploymentConfig memory sdc2) =
570
- _buildMinimalConfig();
571
- // forge-lint: disable-next-line(named-struct-fields)
572
- cfg2.description = REVDescription("NoSplit", "NS", "ipfs://nosplit", "NOSPLIT_SALT");
573
-
574
- (uint256 revnetId2,) = REV_DEPLOYER.deployFor({
575
- revnetId: 0,
576
- configuration: cfg2,
577
- terminalConfigurations: tc2,
578
- suckerDeploymentConfiguration: sdc2,
579
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
580
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
581
- });
582
-
583
- vm.prank(PAYER);
584
- uint256 tokens2 = jbMultiTerminal().pay{value: 1 ether}({
585
- projectId: revnetId2,
586
- token: JBConstants.NATIVE_TOKEN,
587
- amount: 1 ether,
588
- beneficiary: PAYER,
589
- minReturnedTokens: 0,
590
- memo: "invariant test: no splits",
591
- metadata: ""
592
- });
593
-
594
- // Invariant: tokens / projectAmount should produce the same rate.
595
- // Revnet 1: 700e18 tokens / 0.7 ETH = 1000 tokens/ETH
596
- // Revnet 2: 1000e18 tokens / 1.0 ETH = 1000 tokens/ETH
597
- uint256 projectAmount1 = 0.7 ether; // 1 ETH - 30% split
598
- uint256 projectAmount2 = 1 ether; // no splits
599
-
600
- uint256 rate1 = (tokens1 * 1e18) / projectAmount1;
601
- uint256 rate2 = (tokens2 * 1e18) / projectAmount2;
602
-
603
- assertEq(rate1, rate2, "token-per-ETH rate should be identical with and without splits");
604
- }
605
- }