@rev-net/core-v6 0.0.37 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/README.md +6 -7
  3. package/foundry.toml +1 -1
  4. package/package.json +23 -16
  5. package/references/operations.md +1 -1
  6. package/references/runtime.md +1 -1
  7. package/script/Deploy.s.sol +12 -9
  8. package/src/REVDeployer.sol +69 -67
  9. package/src/REVHiddenTokens.sol +2 -2
  10. package/src/REVLoans.sol +26 -22
  11. package/src/REVOwner.sol +147 -29
  12. package/src/interfaces/IREVDeployer.sol +2 -1
  13. package/src/interfaces/IREVHiddenTokens.sol +4 -1
  14. package/src/interfaces/IREVOwner.sol +5 -0
  15. package/src/structs/REVAutoIssuance.sol +4 -2
  16. package/src/structs/REVConfig.sol +8 -5
  17. package/src/structs/REVDescription.sol +6 -5
  18. package/src/structs/REVLoan.sol +8 -5
  19. package/src/structs/REVStageConfig.sol +14 -16
  20. package/ADMINISTRATION.md +0 -73
  21. package/ARCHITECTURE.md +0 -116
  22. package/AUDIT_INSTRUCTIONS.md +0 -90
  23. package/RISKS.md +0 -107
  24. package/SKILLS.md +0 -46
  25. package/STYLE_GUIDE.md +0 -610
  26. package/USER_JOURNEYS.md +0 -195
  27. package/foundry.lock +0 -11
  28. package/slither-ci.config.json +0 -10
  29. package/sphinx.lock +0 -507
  30. package/test/REV.integrations.t.sol +0 -573
  31. package/test/REVAutoIssuanceFuzz.t.sol +0 -328
  32. package/test/REVDeployerRegressions.t.sol +0 -396
  33. package/test/REVInvincibility.t.sol +0 -1371
  34. package/test/REVInvincibilityHandler.sol +0 -387
  35. package/test/REVLifecycle.t.sol +0 -420
  36. package/test/REVLoans.invariants.t.sol +0 -724
  37. package/test/REVLoansAttacks.t.sol +0 -816
  38. package/test/REVLoansFeeRecovery.t.sol +0 -783
  39. package/test/REVLoansFindings.t.sol +0 -711
  40. package/test/REVLoansRegressions.t.sol +0 -364
  41. package/test/REVLoansSourceFeeRecovery.t.sol +0 -517
  42. package/test/REVLoansSourced.t.sol +0 -1839
  43. package/test/REVLoansUnSourced.t.sol +0 -409
  44. package/test/TestAuditFixVerification.t.sol +0 -675
  45. package/test/TestBurnHeldTokens.t.sol +0 -394
  46. package/test/TestCEIPattern.t.sol +0 -508
  47. package/test/TestCashOutCallerValidation.t.sol +0 -452
  48. package/test/TestConversionDocumentation.t.sol +0 -365
  49. package/test/TestCrossCurrencyReclaim.t.sol +0 -610
  50. package/test/TestCrossSourceReallocation.t.sol +0 -361
  51. package/test/TestERC2771MetaTx.t.sol +0 -585
  52. package/test/TestEmptyBuybackSpecs.t.sol +0 -300
  53. package/test/TestFlashLoanSurplus.t.sol +0 -365
  54. package/test/TestHiddenTokens.t.sol +0 -474
  55. package/test/TestHookArrayOOB.t.sol +0 -278
  56. package/test/TestLiquidationBehavior.t.sol +0 -398
  57. package/test/TestLoanSourceRotation.t.sol +0 -553
  58. package/test/TestLoansCashOutDelay.t.sol +0 -493
  59. package/test/TestLongTailEconomics.t.sol +0 -677
  60. package/test/TestLowFindings.t.sol +0 -677
  61. package/test/TestMixedFixes.t.sol +0 -593
  62. package/test/TestPermit2Signatures.t.sol +0 -683
  63. package/test/TestReallocationSandwich.t.sol +0 -412
  64. package/test/TestRevnetRegressions.t.sol +0 -350
  65. package/test/TestSplitWeightAdjustment.t.sol +0 -527
  66. package/test/TestSplitWeightE2E.t.sol +0 -605
  67. package/test/TestSplitWeightFork.t.sol +0 -855
  68. package/test/TestStageTransitionBorrowable.t.sol +0 -301
  69. package/test/TestSwapTerminalPermission.t.sol +0 -262
  70. package/test/TestTerminalEncodingInHash.t.sol +0 -326
  71. package/test/TestUint112Overflow.t.sol +0 -311
  72. package/test/TestZeroAmountLoanGuard.t.sol +0 -378
  73. package/test/TestZeroRepayment.t.sol +0 -354
  74. package/test/audit/CrossChainBuybackRouteMismatch.t.sol +0 -184
  75. package/test/audit/HiddenSupplyCashout.t.sol +0 -61
  76. package/test/audit/LoanIdOverflowGuard.t.sol +0 -523
  77. package/test/audit/NemesisVerification.t.sol +0 -97
  78. package/test/audit/OperatorDelegation.t.sol +0 -356
  79. package/test/audit/PhantomSurplusTerminal.t.sol +0 -367
  80. package/test/audit/REVOwnerCurrencyMismatch.t.sol +0 -188
  81. package/test/audit/REVOwnerRemoteSurplusCurrencyMismatch.t.sol +0 -140
  82. package/test/audit/ReallocatePermission.t.sol +0 -363
  83. package/test/audit/RemoteLoanAccountingGap.t.sol +0 -74
  84. package/test/audit/SupportsInterfaceTest.t.sol +0 -51
  85. package/test/audit/TestFeeAllowanceLeak.t.sol +0 -197
  86. package/test/audit/TestLoansAndDeployerFixes.t.sol +0 -576
  87. package/test/fork/ForkTestBase.sol +0 -727
  88. package/test/fork/TestAutoIssuanceFork.t.sol +0 -148
  89. package/test/fork/TestCashOutFork.t.sol +0 -253
  90. package/test/fork/TestIssuanceDecayFork.t.sol +0 -158
  91. package/test/fork/TestLoanAdversarialFork.t.sol +0 -744
  92. package/test/fork/TestLoanBorrowFork.t.sol +0 -163
  93. package/test/fork/TestLoanCrossRulesetFork.t.sol +0 -308
  94. package/test/fork/TestLoanERC20Fork.t.sol +0 -459
  95. package/test/fork/TestLoanLiquidationFork.t.sol +0 -135
  96. package/test/fork/TestLoanReallocateFork.t.sol +0 -113
  97. package/test/fork/TestLoanRepayFork.t.sol +0 -188
  98. package/test/fork/TestLoanTransferFork.t.sol +0 -143
  99. package/test/fork/TestPermit2PaymentFork.t.sol +0 -300
  100. package/test/fork/TestSplitWeightFork.t.sol +0 -189
  101. package/test/helpers/MaliciousContracts.sol +0 -247
  102. package/test/helpers/REVEmpty721Config.sol +0 -45
  103. package/test/mock/MockBuybackCashOutRecorder.sol +0 -84
  104. package/test/mock/MockBuybackDataHook.sol +0 -112
  105. package/test/mock/MockBuybackDataHookMintPath.sol +0 -68
  106. package/test/mock/MockSuckerRegistry.sol +0 -17
  107. package/test/regression/TestBurnPermissionRequired.t.sol +0 -294
  108. package/test/regression/TestCashOutBuybackFeeLeak.t.sol +0 -232
  109. package/test/regression/TestCrossRevnetLiquidation.t.sol +0 -255
  110. package/test/regression/TestCumulativeLoanCounter.t.sol +0 -361
  111. package/test/regression/TestLiquidateGapHandling.t.sol +0 -394
  112. package/test/regression/TestZeroPriceFeed.t.sol +0 -422
@@ -1,354 +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
- import {REVEmpty721Config} from "./helpers/REVEmpty721Config.sol";
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 {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
26
- import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
27
- import {JBSingleAllowance} from "@bananapus/core-v6/src/structs/JBSingleAllowance.sol";
28
- import {MockPriceFeed} from "@bananapus/core-v6/test/mock/MockPriceFeed.sol";
29
- import {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.sol";
30
- import {REVLoans} from "../src/REVLoans.sol";
31
- import {REVLoan} from "../src/structs/REVLoan.sol";
32
- import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
33
- import {REVLoanSource} from "../src/structs/REVLoanSource.sol";
34
- import {REVDescription} from "../src/structs/REVDescription.sol";
35
- import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
36
- import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
37
- import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
38
- import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
39
- import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
40
- import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
41
- import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
42
- import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
43
- import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
44
- import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
45
- import {REVOwner} from "../src/REVOwner.sol";
46
- import {IREVDeployer} from "../src/interfaces/IREVDeployer.sol";
47
- import {MockSuckerRegistry} from "./mock/MockSuckerRegistry.sol";
48
-
49
- /// @notice Tests for PR #16: zero repayment prevention.
50
- contract TestZeroRepayment is TestBaseWorkflow {
51
- // forge-lint: disable-next-line(mixed-case-variable)
52
- bytes32 REV_DEPLOYER_SALT = "REVDeployer";
53
-
54
- // forge-lint: disable-next-line(mixed-case-variable)
55
- REVDeployer REV_DEPLOYER;
56
- // forge-lint: disable-next-line(mixed-case-variable)
57
- REVOwner REV_OWNER;
58
- // forge-lint: disable-next-line(mixed-case-variable)
59
- JB721TiersHook EXAMPLE_HOOK;
60
- // forge-lint: disable-next-line(mixed-case-variable)
61
- IJB721TiersHookDeployer HOOK_DEPLOYER;
62
- // forge-lint: disable-next-line(mixed-case-variable)
63
- IJB721TiersHookStore HOOK_STORE;
64
- // forge-lint: disable-next-line(mixed-case-variable)
65
- IJBAddressRegistry ADDRESS_REGISTRY;
66
- // forge-lint: disable-next-line(mixed-case-variable)
67
- IREVLoans LOANS_CONTRACT;
68
- // forge-lint: disable-next-line(mixed-case-variable)
69
- MockERC20 TOKEN;
70
- // forge-lint: disable-next-line(mixed-case-variable)
71
- IJBSuckerRegistry SUCKER_REGISTRY;
72
- // forge-lint: disable-next-line(mixed-case-variable)
73
- CTPublisher PUBLISHER;
74
- // forge-lint: disable-next-line(mixed-case-variable)
75
- MockBuybackDataHook MOCK_BUYBACK;
76
-
77
- // forge-lint: disable-next-line(mixed-case-variable)
78
- uint256 FEE_PROJECT_ID;
79
- // forge-lint: disable-next-line(mixed-case-variable)
80
- uint256 REVNET_ID;
81
-
82
- // forge-lint: disable-next-line(mixed-case-variable)
83
- address USER = makeAddr("user");
84
-
85
- address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
86
-
87
- function setUp() public override {
88
- super.setUp();
89
- FEE_PROJECT_ID = jbProjects().createFor(multisig());
90
- SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
91
- HOOK_STORE = new JB721TiersHookStore();
92
- EXAMPLE_HOOK = new JB721TiersHook(
93
- jbDirectory(),
94
- jbPermissions(),
95
- jbPrices(),
96
- jbRulesets(),
97
- HOOK_STORE,
98
- jbSplits(),
99
- IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
100
- multisig()
101
- );
102
- ADDRESS_REGISTRY = new JBAddressRegistry();
103
- HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
104
- PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
105
- MOCK_BUYBACK = new MockBuybackDataHook();
106
- TOKEN = new MockERC20("1/2 ETH", "1/2");
107
- MockPriceFeed priceFeed = new MockPriceFeed(1e21, 6);
108
- vm.prank(multisig());
109
- jbPrices()
110
- .addPriceFeedFor(0, uint32(uint160(address(TOKEN))), uint32(uint160(JBConstants.NATIVE_TOKEN)), priceFeed);
111
- LOANS_CONTRACT = new REVLoans({
112
- controller: jbController(),
113
- suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
114
- revId: FEE_PROJECT_ID,
115
- owner: address(this),
116
- permit2: permit2(),
117
- trustedForwarder: TRUSTED_FORWARDER
118
- });
119
- REV_OWNER = new REVOwner(
120
- IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
121
- jbDirectory(),
122
- FEE_PROJECT_ID,
123
- SUCKER_REGISTRY,
124
- address(LOANS_CONTRACT),
125
- address(0)
126
- );
127
-
128
- REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
129
- jbController(),
130
- SUCKER_REGISTRY,
131
- FEE_PROJECT_ID,
132
- HOOK_DEPLOYER,
133
- PUBLISHER,
134
- IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
135
- address(LOANS_CONTRACT),
136
- TRUSTED_FORWARDER,
137
- address(REV_OWNER)
138
- );
139
-
140
- REV_OWNER.setDeployer(REV_DEPLOYER);
141
-
142
- vm.prank(multisig());
143
- jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
144
- _deployFeeProject();
145
- _deployRevnet();
146
- vm.deal(USER, 1000e18);
147
- }
148
-
149
- function _deployFeeProject() internal {
150
- JBAccountingContext[] memory acc = new JBAccountingContext[](2);
151
- acc[0] = JBAccountingContext({
152
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
153
- });
154
- acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
155
- JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
156
- tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
157
- REVStageConfig[] memory stages = new REVStageConfig[](1);
158
- JBSplit[] memory splits = new JBSplit[](1);
159
- splits[0].beneficiary = payable(multisig());
160
- splits[0].percent = 10_000;
161
- REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
162
- ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
163
- stages[0] = REVStageConfig({
164
- startsAtOrAfter: uint40(block.timestamp),
165
- autoIssuances: ai,
166
- splitPercent: 2000,
167
- splits: splits,
168
- initialIssuance: uint112(1000e18),
169
- issuanceCutFrequency: 90 days,
170
- issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
171
- cashOutTaxRate: 6000,
172
- extraMetadata: 0
173
- });
174
- REVConfig memory cfg = REVConfig({
175
- // forge-lint: disable-next-line(named-struct-fields)
176
- description: REVDescription("Revnet", "$REV", "ipfs://test", "REV_TOKEN"),
177
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
178
- splitOperator: multisig(),
179
- stageConfigurations: stages
180
- });
181
- vm.prank(multisig());
182
- REV_DEPLOYER.deployFor({
183
- revnetId: FEE_PROJECT_ID,
184
- configuration: cfg,
185
- terminalConfigurations: tc,
186
- suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
187
- deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
188
- }),
189
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
190
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
191
- });
192
- }
193
-
194
- function _deployRevnet() internal {
195
- JBAccountingContext[] memory acc = new JBAccountingContext[](2);
196
- acc[0] = JBAccountingContext({
197
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
198
- });
199
- acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
200
- JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
201
- tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
202
- REVStageConfig[] memory stages = new REVStageConfig[](1);
203
- JBSplit[] memory splits = new JBSplit[](1);
204
- splits[0].beneficiary = payable(multisig());
205
- splits[0].percent = 10_000;
206
- REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
207
- ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
208
- stages[0] = REVStageConfig({
209
- startsAtOrAfter: uint40(block.timestamp),
210
- autoIssuances: ai,
211
- splitPercent: 2000,
212
- splits: splits,
213
- initialIssuance: uint112(1000e18),
214
- issuanceCutFrequency: 90 days,
215
- issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
216
- cashOutTaxRate: 6000,
217
- extraMetadata: 0
218
- });
219
- REVLoanSource[] memory ls = new REVLoanSource[](1);
220
- ls[0] = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
221
- REVConfig memory cfg = REVConfig({
222
- // forge-lint: disable-next-line(named-struct-fields)
223
- description: REVDescription("NANA", "$NANA", "ipfs://test2", "NANA_TOKEN"),
224
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
225
- splitOperator: multisig(),
226
- stageConfigurations: stages
227
- });
228
- (REVNET_ID,) = REV_DEPLOYER.deployFor({
229
- revnetId: 0,
230
- configuration: cfg,
231
- terminalConfigurations: tc,
232
- suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
233
- deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("NANA")
234
- }),
235
- tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
236
- allowedPosts: REVEmpty721Config.emptyAllowedPosts()
237
- });
238
- }
239
-
240
- function _setupLoan(
241
- address user,
242
- uint256 ethAmount,
243
- uint256 prepaidFee
244
- )
245
- internal
246
- returns (uint256 loanId, uint256 tokenCount, uint256 borrowAmount)
247
- {
248
- vm.prank(user);
249
- tokenCount =
250
- jbMultiTerminal().pay{value: ethAmount}(REVNET_ID, JBConstants.NATIVE_TOKEN, ethAmount, user, 0, "", "");
251
- borrowAmount =
252
- LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokenCount, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
253
- if (borrowAmount == 0) return (0, tokenCount, 0);
254
- mockExpect(
255
- address(jbPermissions()),
256
- abi.encodeCall(IJBPermissions.hasPermission, (address(LOANS_CONTRACT), user, REVNET_ID, 11, true, true)),
257
- abi.encode(true)
258
- );
259
- REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
260
- vm.prank(user);
261
- (loanId,) = LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(user), prepaidFee, user);
262
- }
263
-
264
- /// @notice Repaying with zero borrow amount and zero collateral return should revert.
265
- /// @dev After borrowing, we inflate surplus back so newBorrowAmount >= loan.amount, then
266
- /// repayBorrowAmount = loan.amount - newBorrowAmount = 0 with collateralCountToReturn = 0.
267
- /// This should revert with NothingToRepay (or NewBorrowAmountGreaterThanLoanAmount if surplus overshot).
268
- function test_repayZeroBoth_reverts() public {
269
- // Setup: borrow against 10 ETH
270
- (uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
271
- require(loanId != 0, "Loan setup failed");
272
-
273
- // After borrowing, fees reduced surplus. We need to restore it so newBorrowAmount >= loan.amount.
274
- // Donate enough surplus to compensate for all fees extracted during borrowing.
275
- // A large donation ensures newBorrowAmount > loan.amount, hitting
276
- // REVLoans_NewBorrowAmountGreaterThanLoanAmount, OR at exact match, hitting REVLoans_NothingToRepay.
277
- // Either way, the "zero repayment" is prevented.
278
- address donor = makeAddr("donor");
279
- vm.deal(donor, 500e18);
280
- vm.prank(donor);
281
- jbMultiTerminal().addToBalanceOf{value: 500e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 500e18, false, "", "");
282
-
283
- JBSingleAllowance memory allowance;
284
-
285
- // Try to repay with collateralCountToReturn = 0 and some maxRepayBorrowAmount.
286
- // Since surplus was inflated, newBorrowAmount > loan.amount, which reverts with
287
- // REVLoans_NewBorrowAmountGreaterThanLoanAmount. This shows zero-repayment is blocked.
288
- vm.prank(USER);
289
- vm.expectRevert(); // Will revert with either NothingToRepay or NewBorrowAmountGreaterThanLoanAmount
290
- LOANS_CONTRACT.repayLoan{value: 0}(
291
- loanId,
292
- 0, // maxRepayBorrowAmount
293
- 0, // collateralCountToReturn = 0
294
- payable(USER),
295
- allowance
296
- );
297
- }
298
-
299
- /// @notice Repaying full borrow amount should succeed (returning all collateral).
300
- function test_repayNonZeroAmount_succeeds() public {
301
- // Setup: borrow against 10 ETH
302
- (uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
303
- require(loanId != 0, "Loan setup failed");
304
-
305
- REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
306
-
307
- // Repay the full loan by returning all collateral.
308
- // collateralCountToReturn == loan.collateral means full repayment path (newBorrowAmount = 0).
309
- // Need to send enough ETH to cover loan.amount (the repayBorrowAmount) + any source fee.
310
- JBSingleAllowance memory allowance;
311
-
312
- vm.prank(USER);
313
- (uint256 paidOffLoanId,) = LOANS_CONTRACT.repayLoan{value: loan.amount}(
314
- loanId,
315
- loan.amount, // maxRepayBorrowAmount — covers full repayment
316
- loan.collateral, // return all collateral
317
- payable(USER),
318
- allowance
319
- );
320
-
321
- // Verify loan was fully repaid
322
- // After full repayment with all collateral returned, the original loan is burned.
323
- // The paidOffLoanId should match the loanId since all collateral was returned.
324
- assertEq(paidOffLoanId, loanId, "Full repay should return original loan ID");
325
- }
326
-
327
- /// @notice Repaying some collateral (non-zero) should succeed.
328
- function test_repayNonZeroCollateral_succeeds() public {
329
- // Setup: borrow against 10 ETH
330
- (uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
331
- require(loanId != 0, "Loan setup failed");
332
-
333
- REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
334
- uint256 collateralToReturn = loan.collateral / 2; // Return half the collateral
335
-
336
- // When returning half the collateral, the new borrow amount covers the remaining half.
337
- // The repay amount = loan.amount - newBorrowAmount (which is > 0).
338
- // We need to send enough ETH to cover it.
339
- JBSingleAllowance memory allowance;
340
-
341
- vm.prank(USER);
342
- (, REVLoan memory paidOffLoan) = LOANS_CONTRACT.repayLoan{value: loan.amount}(
343
- loanId,
344
- loan.amount, // maxRepayBorrowAmount — generous cap
345
- collateralToReturn,
346
- payable(USER),
347
- allowance
348
- );
349
-
350
- // Verify some collateral was returned and loan still exists with reduced collateral
351
- assertTrue(paidOffLoan.collateral < loan.collateral, "Collateral should have decreased");
352
- assertTrue(paidOffLoan.amount < loan.amount, "Borrow amount should have decreased");
353
- }
354
- }
@@ -1,184 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import "forge-std/Test.sol";
5
- import "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
6
- import {IJBBuybackHookRegistry} from "@bananapus/buyback-hook-v6/src/interfaces/IJBBuybackHookRegistry.sol";
7
- import {IJBCashOutHook} from "@bananapus/core-v6/src/interfaces/IJBCashOutHook.sol";
8
- import {IJBRulesetDataHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetDataHook.sol";
9
- import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
10
- import {JBCashOuts} from "@bananapus/core-v6/src/libraries/JBCashOuts.sol";
11
- import {JBBeforeCashOutRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforeCashOutRecordedContext.sol";
12
- import {JBCashOutHookSpecification} from "@bananapus/core-v6/src/structs/JBCashOutHookSpecification.sol";
13
- import {JBBeforePayRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforePayRecordedContext.sol";
14
- import {JBPayHookSpecification} from "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
15
- import {JBTokenAmount} from "@bananapus/core-v6/src/structs/JBTokenAmount.sol";
16
- import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
17
- import {IJBSuckerRegistry} from "@bananapus/suckers-v6/src/interfaces/IJBSuckerRegistry.sol";
18
- import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
19
- import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
20
-
21
- import {REVOwner} from "../../src/REVOwner.sol";
22
-
23
- contract ConfigurableSuckerRegistry {
24
- uint256 public remoteSupply;
25
- uint256 public remoteSurplus;
26
-
27
- function setRemoteTotals(uint256 supply, uint256 surplus) external {
28
- remoteSupply = supply;
29
- remoteSurplus = surplus;
30
- }
31
-
32
- function isSuckerOf(uint256, address) external pure returns (bool) {
33
- return false;
34
- }
35
-
36
- function remoteTotalSupplyOf(uint256) external view returns (uint256) {
37
- return remoteSupply;
38
- }
39
-
40
- function remoteSurplusOf(uint256, uint256, uint256) external view returns (uint256) {
41
- return remoteSurplus;
42
- }
43
- }
44
-
45
- contract ThresholdBuybackRegistry is IJBRulesetDataHook {
46
- uint256 public immutable minimumSwapAmountOut;
47
-
48
- constructor(uint256 minAmountOut) {
49
- minimumSwapAmountOut = minAmountOut;
50
- }
51
-
52
- function beforeCashOutRecordedWith(JBBeforeCashOutRecordedContext calldata context)
53
- external
54
- view
55
- returns (
56
- uint256 cashOutTaxRate,
57
- uint256 cashOutCount,
58
- uint256 totalSupply,
59
- uint256 effectiveSurplusValue,
60
- JBCashOutHookSpecification[] memory hookSpecifications
61
- )
62
- {
63
- uint256 directCashOutAmount = JBCashOuts.cashOutFrom({
64
- surplus: context.surplus.value,
65
- cashOutCount: context.cashOutCount,
66
- totalSupply: context.totalSupply,
67
- cashOutTaxRate: context.cashOutTaxRate
68
- });
69
-
70
- hookSpecifications = new JBCashOutHookSpecification[](1);
71
- hookSpecifications[0] = JBCashOutHookSpecification({
72
- hook: IJBCashOutHook(address(this)),
73
- noop: directCashOutAmount >= minimumSwapAmountOut,
74
- amount: 0,
75
- metadata: ""
76
- });
77
-
78
- cashOutTaxRate =
79
- directCashOutAmount >= minimumSwapAmountOut ? context.cashOutTaxRate : JBConstants.MAX_CASH_OUT_TAX_RATE;
80
- cashOutCount = context.cashOutCount;
81
- totalSupply = context.totalSupply;
82
- effectiveSurplusValue = 0;
83
- }
84
-
85
- function beforePayRecordedWith(JBBeforePayRecordedContext calldata context)
86
- external
87
- pure
88
- returns (uint256 weight, JBPayHookSpecification[] memory hookSpecifications)
89
- {
90
- weight = context.weight;
91
- hookSpecifications = new JBPayHookSpecification[](0);
92
- }
93
-
94
- function hasMintPermissionFor(uint256, JBRuleset calldata, address) external pure returns (bool) {
95
- return false;
96
- }
97
-
98
- function setPoolFor(uint256, PoolKey calldata, uint256, address) external pure {}
99
-
100
- function setPoolFor(uint256, uint24, int24, uint256, address) external pure {}
101
-
102
- function initializePoolFor(uint256, uint24, int24, uint256, address, uint160) external pure {}
103
-
104
- function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
105
- return interfaceId == type(IJBRulesetDataHook).interfaceId || interfaceId == type(IERC165).interfaceId;
106
- }
107
- }
108
-
109
- contract CodexCrossChainBuybackRouteMismatchTest is TestBaseWorkflow {
110
- REVOwner internal ownerHook;
111
- ConfigurableSuckerRegistry internal suckerRegistry;
112
- ThresholdBuybackRegistry internal buybackRegistry;
113
-
114
- function setUp() public override {
115
- super.setUp();
116
-
117
- suckerRegistry = new ConfigurableSuckerRegistry();
118
- buybackRegistry = new ThresholdBuybackRegistry(50 ether);
119
-
120
- ownerHook = new REVOwner(
121
- IJBBuybackHookRegistry(address(buybackRegistry)),
122
- jbDirectory(),
123
- 999_999,
124
- IJBSuckerRegistry(address(suckerRegistry)),
125
- address(0),
126
- address(0)
127
- );
128
- }
129
-
130
- function test_buybackRouteUsesOmnichainContextForRouting() public {
131
- suckerRegistry.setRemoteTotals(0, 900 ether);
132
-
133
- JBBeforeCashOutRecordedContext memory context = JBBeforeCashOutRecordedContext({
134
- terminal: address(jbMultiTerminal()),
135
- holder: address(0xBEEF),
136
- projectId: 1,
137
- rulesetId: 0,
138
- cashOutCount: 100,
139
- totalSupply: 1000,
140
- surplus: JBTokenAmount({
141
- token: JBConstants.NATIVE_TOKEN,
142
- value: 100 ether,
143
- decimals: 18,
144
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
145
- }),
146
- useTotalSurplus: true,
147
- cashOutTaxRate: 0,
148
- beneficiaryIsFeeless: false,
149
- metadata: ""
150
- });
151
-
152
- uint256 localDirectCashOut = JBCashOuts.cashOutFrom({
153
- surplus: context.surplus.value,
154
- cashOutCount: context.cashOutCount,
155
- totalSupply: context.totalSupply,
156
- cashOutTaxRate: context.cashOutTaxRate
157
- });
158
- uint256 omnichainDirectCashOut = JBCashOuts.cashOutFrom({
159
- surplus: context.surplus.value + 900 ether,
160
- cashOutCount: context.cashOutCount,
161
- totalSupply: context.totalSupply,
162
- cashOutTaxRate: context.cashOutTaxRate
163
- });
164
-
165
- assertLt(localDirectCashOut, 50 ether, "local route should prefer swap in the mock");
166
- assertGe(omnichainDirectCashOut, 50 ether, "omnichain route should prefer direct reclaim");
167
-
168
- (uint256 returnedTaxRate,, uint256 returnedSupply, uint256 returnedSurplus,) =
169
- ownerHook.beforeCashOutRecordedWith(context);
170
-
171
- // After the fix, REVOwner forwards the cross-chain-adjusted context to the buyback hook.
172
- // The buyback hook now sees the full omnichain surplus (1000 ether) and correctly routes
173
- // to direct reclaim (passthrough) instead of swap.
174
- assertEq(returnedSupply, context.totalSupply, "owner returns cross-chain total supply");
175
- assertEq(returnedSurplus, context.surplus.value + 900 ether, "owner returns cross-chain effective surplus");
176
- // With omnichain context, the direct reclaim (100 ether) exceeds the threshold (50 ether),
177
- // so the buyback hook chooses passthrough (returns the original cashOutTaxRate of 0).
178
- assertEq(
179
- returnedTaxRate,
180
- context.cashOutTaxRate,
181
- "routing correctly uses omnichain context - direct reclaim beats threshold"
182
- );
183
- }
184
- }
@@ -1,61 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
5
-
6
- import {TestHiddenTokens} from "../TestHiddenTokens.t.sol";
7
-
8
- contract CodexNemesisHiddenSupplyCashoutTest is TestHiddenTokens {
9
- function test_hiddenSupplyCanDrainCashoutAndThenBeRevealed() public {
10
- uint256 payAmount = 10 ether;
11
-
12
- vm.prank(USER);
13
- uint256 minted = jbMultiTerminal().pay{value: payAmount}({
14
- projectId: REVNET_ID,
15
- token: JBConstants.NATIVE_TOKEN,
16
- amount: payAmount,
17
- beneficiary: USER,
18
- minReturnedTokens: 0,
19
- memo: "",
20
- metadata: ""
21
- });
22
-
23
- uint256 terminalBalanceBefore =
24
- jbTerminalStore().balanceOf(address(jbMultiTerminal()), REVNET_ID, JBConstants.NATIVE_TOKEN);
25
- assertEq(terminalBalanceBefore, payAmount, "setup: revnet terminal balance");
26
-
27
- _allowHolderToHide(USER, REVNET_ID);
28
-
29
- uint256 hiddenCount = minted / 2;
30
- vm.prank(USER);
31
- HIDDEN_TOKENS.hideTokensOf(REVNET_ID, hiddenCount, USER);
32
-
33
- uint256 visibleSupply = jbController().TOKENS().totalSupplyOf(REVNET_ID);
34
- assertEq(visibleSupply, minted - hiddenCount, "hidden tokens left the cash-out denominator");
35
-
36
- vm.prank(USER);
37
- jbMultiTerminal()
38
- .cashOutTokensOf({
39
- holder: USER,
40
- projectId: REVNET_ID,
41
- cashOutCount: visibleSupply,
42
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
43
- minTokensReclaimed: 0,
44
- beneficiary: payable(USER),
45
- metadata: ""
46
- });
47
-
48
- uint256 terminalBalanceAfter =
49
- jbTerminalStore().balanceOf(address(jbMultiTerminal()), REVNET_ID, JBConstants.NATIVE_TOKEN);
50
- assertEq(terminalBalanceAfter, 0, "visible tranche drained the revnet balance");
51
-
52
- vm.prank(USER);
53
- HIDDEN_TOKENS.revealTokensOf(REVNET_ID, hiddenCount, USER);
54
-
55
- assertEq(
56
- jbController().TOKENS().totalBalanceOf(USER, REVNET_ID),
57
- hiddenCount,
58
- "hidden tranche was restored after the cash out"
59
- );
60
- }
61
- }