@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.
- package/CHANGELOG.md +2 -2
- package/README.md +6 -7
- package/foundry.toml +1 -1
- package/package.json +23 -16
- package/references/operations.md +1 -1
- package/references/runtime.md +1 -1
- package/script/Deploy.s.sol +12 -9
- package/src/REVDeployer.sol +69 -67
- package/src/REVHiddenTokens.sol +2 -2
- package/src/REVLoans.sol +26 -22
- package/src/REVOwner.sol +147 -29
- package/src/interfaces/IREVDeployer.sol +2 -1
- package/src/interfaces/IREVHiddenTokens.sol +4 -1
- package/src/interfaces/IREVOwner.sol +5 -0
- package/src/structs/REVAutoIssuance.sol +4 -2
- package/src/structs/REVConfig.sol +8 -5
- package/src/structs/REVDescription.sol +6 -5
- package/src/structs/REVLoan.sol +8 -5
- package/src/structs/REVStageConfig.sol +14 -16
- package/ADMINISTRATION.md +0 -73
- package/ARCHITECTURE.md +0 -116
- package/AUDIT_INSTRUCTIONS.md +0 -90
- package/RISKS.md +0 -107
- package/SKILLS.md +0 -46
- package/STYLE_GUIDE.md +0 -610
- package/USER_JOURNEYS.md +0 -195
- package/foundry.lock +0 -11
- package/slither-ci.config.json +0 -10
- package/sphinx.lock +0 -507
- package/test/REV.integrations.t.sol +0 -573
- package/test/REVAutoIssuanceFuzz.t.sol +0 -328
- package/test/REVDeployerRegressions.t.sol +0 -396
- package/test/REVInvincibility.t.sol +0 -1371
- package/test/REVInvincibilityHandler.sol +0 -387
- package/test/REVLifecycle.t.sol +0 -420
- package/test/REVLoans.invariants.t.sol +0 -724
- package/test/REVLoansAttacks.t.sol +0 -816
- package/test/REVLoansFeeRecovery.t.sol +0 -783
- package/test/REVLoansFindings.t.sol +0 -711
- package/test/REVLoansRegressions.t.sol +0 -364
- package/test/REVLoansSourceFeeRecovery.t.sol +0 -517
- package/test/REVLoansSourced.t.sol +0 -1839
- package/test/REVLoansUnSourced.t.sol +0 -409
- package/test/TestAuditFixVerification.t.sol +0 -675
- package/test/TestBurnHeldTokens.t.sol +0 -394
- package/test/TestCEIPattern.t.sol +0 -508
- package/test/TestCashOutCallerValidation.t.sol +0 -452
- package/test/TestConversionDocumentation.t.sol +0 -365
- package/test/TestCrossCurrencyReclaim.t.sol +0 -610
- package/test/TestCrossSourceReallocation.t.sol +0 -361
- package/test/TestERC2771MetaTx.t.sol +0 -585
- package/test/TestEmptyBuybackSpecs.t.sol +0 -300
- package/test/TestFlashLoanSurplus.t.sol +0 -365
- package/test/TestHiddenTokens.t.sol +0 -474
- package/test/TestHookArrayOOB.t.sol +0 -278
- package/test/TestLiquidationBehavior.t.sol +0 -398
- package/test/TestLoanSourceRotation.t.sol +0 -553
- package/test/TestLoansCashOutDelay.t.sol +0 -493
- package/test/TestLongTailEconomics.t.sol +0 -677
- package/test/TestLowFindings.t.sol +0 -677
- package/test/TestMixedFixes.t.sol +0 -593
- package/test/TestPermit2Signatures.t.sol +0 -683
- package/test/TestReallocationSandwich.t.sol +0 -412
- package/test/TestRevnetRegressions.t.sol +0 -350
- package/test/TestSplitWeightAdjustment.t.sol +0 -527
- package/test/TestSplitWeightE2E.t.sol +0 -605
- package/test/TestSplitWeightFork.t.sol +0 -855
- package/test/TestStageTransitionBorrowable.t.sol +0 -301
- package/test/TestSwapTerminalPermission.t.sol +0 -262
- package/test/TestTerminalEncodingInHash.t.sol +0 -326
- package/test/TestUint112Overflow.t.sol +0 -311
- package/test/TestZeroAmountLoanGuard.t.sol +0 -378
- package/test/TestZeroRepayment.t.sol +0 -354
- package/test/audit/CrossChainBuybackRouteMismatch.t.sol +0 -184
- package/test/audit/HiddenSupplyCashout.t.sol +0 -61
- package/test/audit/LoanIdOverflowGuard.t.sol +0 -523
- package/test/audit/NemesisVerification.t.sol +0 -97
- package/test/audit/OperatorDelegation.t.sol +0 -356
- package/test/audit/PhantomSurplusTerminal.t.sol +0 -367
- package/test/audit/REVOwnerCurrencyMismatch.t.sol +0 -188
- package/test/audit/REVOwnerRemoteSurplusCurrencyMismatch.t.sol +0 -140
- package/test/audit/ReallocatePermission.t.sol +0 -363
- package/test/audit/RemoteLoanAccountingGap.t.sol +0 -74
- package/test/audit/SupportsInterfaceTest.t.sol +0 -51
- package/test/audit/TestFeeAllowanceLeak.t.sol +0 -197
- package/test/audit/TestLoansAndDeployerFixes.t.sol +0 -576
- package/test/fork/ForkTestBase.sol +0 -727
- package/test/fork/TestAutoIssuanceFork.t.sol +0 -148
- package/test/fork/TestCashOutFork.t.sol +0 -253
- package/test/fork/TestIssuanceDecayFork.t.sol +0 -158
- package/test/fork/TestLoanAdversarialFork.t.sol +0 -744
- package/test/fork/TestLoanBorrowFork.t.sol +0 -163
- package/test/fork/TestLoanCrossRulesetFork.t.sol +0 -308
- package/test/fork/TestLoanERC20Fork.t.sol +0 -459
- package/test/fork/TestLoanLiquidationFork.t.sol +0 -135
- package/test/fork/TestLoanReallocateFork.t.sol +0 -113
- package/test/fork/TestLoanRepayFork.t.sol +0 -188
- package/test/fork/TestLoanTransferFork.t.sol +0 -143
- package/test/fork/TestPermit2PaymentFork.t.sol +0 -300
- package/test/fork/TestSplitWeightFork.t.sol +0 -189
- package/test/helpers/MaliciousContracts.sol +0 -247
- package/test/helpers/REVEmpty721Config.sol +0 -45
- package/test/mock/MockBuybackCashOutRecorder.sol +0 -84
- package/test/mock/MockBuybackDataHook.sol +0 -112
- package/test/mock/MockBuybackDataHookMintPath.sol +0 -68
- package/test/mock/MockSuckerRegistry.sol +0 -17
- package/test/regression/TestBurnPermissionRequired.t.sol +0 -294
- package/test/regression/TestCashOutBuybackFeeLeak.t.sol +0 -232
- package/test/regression/TestCrossRevnetLiquidation.t.sol +0 -255
- package/test/regression/TestCumulativeLoanCounter.t.sol +0 -361
- package/test/regression/TestLiquidateGapHandling.t.sol +0 -394
- package/test/regression/TestZeroPriceFeed.t.sol +0 -422
|
@@ -1,367 +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 "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
7
|
-
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
8
|
-
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
9
|
-
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
10
|
-
import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
|
|
11
|
-
import "@croptop/core-v6/src/CTPublisher.sol";
|
|
12
|
-
import "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
13
|
-
import "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
14
|
-
import "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
15
|
-
import "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
16
|
-
import "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
|
|
17
|
-
import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
|
|
18
|
-
import "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
19
|
-
import "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
20
|
-
import "@bananapus/buyback-hook-v6/src/interfaces/IJBBuybackHookRegistry.sol";
|
|
21
|
-
import "@bananapus/core-v6/src/interfaces/IJBPermissions.sol";
|
|
22
|
-
import "@bananapus/core-v6/src/interfaces/IJBTerminal.sol";
|
|
23
|
-
import "@bananapus/core-v6/src/interfaces/IJBPayoutTerminal.sol";
|
|
24
|
-
import "@bananapus/core-v6/src/libraries/JBCashOuts.sol";
|
|
25
|
-
import "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
26
|
-
import "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
27
|
-
import "@bananapus/core-v6/src/structs/JBPermissionsData.sol";
|
|
28
|
-
import "@bananapus/core-v6/src/structs/JBTerminalConfig.sol";
|
|
29
|
-
import "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
30
|
-
import "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
31
|
-
import "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
|
|
32
|
-
import "@bananapus/permission-ids-v6/src/JBPermissionIds.sol";
|
|
33
|
-
import "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
34
|
-
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
35
|
-
|
|
36
|
-
import {MockBuybackDataHook} from "../mock/MockBuybackDataHook.sol";
|
|
37
|
-
import {REVEmpty721Config} from "../helpers/REVEmpty721Config.sol";
|
|
38
|
-
import {REVDeployer} from "../../src/REVDeployer.sol";
|
|
39
|
-
import {REVLoans} from "../../src/REVLoans.sol";
|
|
40
|
-
import {REVOwner} from "../../src/REVOwner.sol";
|
|
41
|
-
import {IREVLoans} from "../../src/interfaces/IREVLoans.sol";
|
|
42
|
-
import {IREVDeployer} from "../../src/interfaces/IREVDeployer.sol";
|
|
43
|
-
import {REVConfig} from "../../src/structs/REVConfig.sol";
|
|
44
|
-
import {REVDescription} from "../../src/structs/REVDescription.sol";
|
|
45
|
-
import {REVLoanSource} from "../../src/structs/REVLoanSource.sol";
|
|
46
|
-
import {REVStageConfig} from "../../src/structs/REVStageConfig.sol";
|
|
47
|
-
import {REVAutoIssuance} from "../../src/structs/REVStageConfig.sol";
|
|
48
|
-
import {REVSuckerDeploymentConfig} from "../../src/structs/REVSuckerDeploymentConfig.sol";
|
|
49
|
-
import {MockSuckerRegistry} from "../mock/MockSuckerRegistry.sol";
|
|
50
|
-
|
|
51
|
-
contract PhantomSurplusTerminal is ERC165, IJBPayoutTerminal {
|
|
52
|
-
uint256 public fakeSurplus;
|
|
53
|
-
|
|
54
|
-
function setFakeSurplus(uint256 newFakeSurplus) external {
|
|
55
|
-
fakeSurplus = newFakeSurplus;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function currentSurplusOf(uint256, address[] calldata, uint256, uint256) external view override returns (uint256) {
|
|
59
|
-
return fakeSurplus;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function accountingContextForTokenOf(uint256, address) external pure override returns (JBAccountingContext memory) {
|
|
63
|
-
return JBAccountingContext({
|
|
64
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function accountingContextsOf(uint256) external pure override returns (JBAccountingContext[] memory) {
|
|
69
|
-
return new JBAccountingContext[](0);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function addAccountingContextsFor(uint256, JBAccountingContext[] calldata) external override {}
|
|
73
|
-
|
|
74
|
-
function addToBalanceOf(
|
|
75
|
-
uint256,
|
|
76
|
-
address,
|
|
77
|
-
uint256,
|
|
78
|
-
bool,
|
|
79
|
-
string calldata,
|
|
80
|
-
bytes calldata
|
|
81
|
-
)
|
|
82
|
-
external
|
|
83
|
-
payable
|
|
84
|
-
override
|
|
85
|
-
{}
|
|
86
|
-
|
|
87
|
-
function migrateBalanceOf(uint256, address, IJBTerminal) external pure override returns (uint256) {
|
|
88
|
-
return 0;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function pay(
|
|
92
|
-
uint256,
|
|
93
|
-
address,
|
|
94
|
-
uint256,
|
|
95
|
-
address,
|
|
96
|
-
uint256,
|
|
97
|
-
string calldata,
|
|
98
|
-
bytes calldata
|
|
99
|
-
)
|
|
100
|
-
external
|
|
101
|
-
payable
|
|
102
|
-
override
|
|
103
|
-
returns (uint256)
|
|
104
|
-
{
|
|
105
|
-
return 0;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function previewPayFor(
|
|
109
|
-
uint256,
|
|
110
|
-
address,
|
|
111
|
-
uint256,
|
|
112
|
-
address,
|
|
113
|
-
bytes calldata
|
|
114
|
-
)
|
|
115
|
-
external
|
|
116
|
-
pure
|
|
117
|
-
override
|
|
118
|
-
returns (JBRuleset memory, uint256, uint256, JBPayHookSpecification[] memory)
|
|
119
|
-
{
|
|
120
|
-
JBRuleset memory ruleset;
|
|
121
|
-
return (ruleset, 0, 0, new JBPayHookSpecification[](0));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function sendPayoutsOf(uint256, address, uint256, uint256, uint256) external pure override returns (uint256) {
|
|
125
|
-
return 0;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function supportsInterface(bytes4 interfaceId) public view override(ERC165, IERC165) returns (bool) {
|
|
129
|
-
return interfaceId == type(IJBTerminal).interfaceId || interfaceId == type(IJBPayoutTerminal).interfaceId
|
|
130
|
-
|| super.supportsInterface(interfaceId);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function useAllowanceOf(
|
|
134
|
-
uint256,
|
|
135
|
-
address,
|
|
136
|
-
uint256,
|
|
137
|
-
uint256,
|
|
138
|
-
uint256,
|
|
139
|
-
address payable,
|
|
140
|
-
address payable,
|
|
141
|
-
string calldata
|
|
142
|
-
)
|
|
143
|
-
external
|
|
144
|
-
pure
|
|
145
|
-
override
|
|
146
|
-
returns (uint256)
|
|
147
|
-
{
|
|
148
|
-
return 0;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
contract CodexPhantomSurplusTerminalTest is TestBaseWorkflow {
|
|
153
|
-
bytes32 internal constant REV_DEPLOYER_SALT = "REVDeployer";
|
|
154
|
-
address internal constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
155
|
-
|
|
156
|
-
address internal USER = makeAddr("user");
|
|
157
|
-
|
|
158
|
-
REVDeployer internal REV_DEPLOYER;
|
|
159
|
-
REVOwner internal REV_OWNER;
|
|
160
|
-
REVLoans internal LOANS;
|
|
161
|
-
JB721TiersHook internal EXAMPLE_HOOK;
|
|
162
|
-
IJB721TiersHookDeployer internal HOOK_DEPLOYER;
|
|
163
|
-
IJB721TiersHookStore internal HOOK_STORE;
|
|
164
|
-
IJBAddressRegistry internal ADDRESS_REGISTRY;
|
|
165
|
-
IJBSuckerRegistry internal SUCKER_REGISTRY;
|
|
166
|
-
CTPublisher internal PUBLISHER;
|
|
167
|
-
MockBuybackDataHook internal MOCK_BUYBACK;
|
|
168
|
-
PhantomSurplusTerminal internal PHANTOM_TERMINAL;
|
|
169
|
-
|
|
170
|
-
uint256 internal FEE_PROJECT_ID;
|
|
171
|
-
uint256 internal REVNET_ID;
|
|
172
|
-
|
|
173
|
-
function setUp() public override {
|
|
174
|
-
super.setUp();
|
|
175
|
-
|
|
176
|
-
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
177
|
-
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
178
|
-
HOOK_STORE = new JB721TiersHookStore();
|
|
179
|
-
EXAMPLE_HOOK = new JB721TiersHook(
|
|
180
|
-
jbDirectory(),
|
|
181
|
-
jbPermissions(),
|
|
182
|
-
jbPrices(),
|
|
183
|
-
jbRulesets(),
|
|
184
|
-
HOOK_STORE,
|
|
185
|
-
jbSplits(),
|
|
186
|
-
IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
|
|
187
|
-
multisig()
|
|
188
|
-
);
|
|
189
|
-
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
190
|
-
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
191
|
-
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
192
|
-
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
193
|
-
LOANS = new REVLoans({
|
|
194
|
-
controller: jbController(),
|
|
195
|
-
suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
|
|
196
|
-
revId: FEE_PROJECT_ID,
|
|
197
|
-
owner: address(this),
|
|
198
|
-
permit2: permit2(),
|
|
199
|
-
trustedForwarder: TRUSTED_FORWARDER
|
|
200
|
-
});
|
|
201
|
-
REV_OWNER = new REVOwner(
|
|
202
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
203
|
-
jbDirectory(),
|
|
204
|
-
FEE_PROJECT_ID,
|
|
205
|
-
SUCKER_REGISTRY,
|
|
206
|
-
address(LOANS),
|
|
207
|
-
address(0)
|
|
208
|
-
);
|
|
209
|
-
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
210
|
-
jbController(),
|
|
211
|
-
SUCKER_REGISTRY,
|
|
212
|
-
FEE_PROJECT_ID,
|
|
213
|
-
HOOK_DEPLOYER,
|
|
214
|
-
PUBLISHER,
|
|
215
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
216
|
-
address(LOANS),
|
|
217
|
-
TRUSTED_FORWARDER,
|
|
218
|
-
address(REV_OWNER)
|
|
219
|
-
);
|
|
220
|
-
REV_OWNER.setDeployer(IREVDeployer(REV_DEPLOYER));
|
|
221
|
-
PHANTOM_TERMINAL = new PhantomSurplusTerminal();
|
|
222
|
-
|
|
223
|
-
vm.prank(multisig());
|
|
224
|
-
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
225
|
-
|
|
226
|
-
_deployFeeProject();
|
|
227
|
-
REVNET_ID = _deployRevnetWithPhantomTerminal();
|
|
228
|
-
vm.deal(USER, 200 ether);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function test_registeredPhantomTerminalInflatesBorrowAgainstRealTreasury() public {
|
|
232
|
-
uint256 realSurplus = 100 ether;
|
|
233
|
-
uint256 phantomSurplus = 100 ether;
|
|
234
|
-
|
|
235
|
-
PHANTOM_TERMINAL.setFakeSurplus(phantomSurplus);
|
|
236
|
-
|
|
237
|
-
vm.prank(USER);
|
|
238
|
-
uint256 userTokens = jbMultiTerminal().pay{value: realSurplus}(
|
|
239
|
-
REVNET_ID, JBConstants.NATIVE_TOKEN, realSurplus, USER, 0, "", ""
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
uint256 collateral = userTokens / 10;
|
|
243
|
-
uint256 taxRate = 5000;
|
|
244
|
-
|
|
245
|
-
uint256 honestBorrowable = JBCashOuts.cashOutFrom({
|
|
246
|
-
surplus: realSurplus, cashOutCount: collateral, totalSupply: userTokens, cashOutTaxRate: taxRate
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
uint256 inflatedBorrowable =
|
|
250
|
-
LOANS.borrowableAmountFrom(REVNET_ID, collateral, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
251
|
-
|
|
252
|
-
assertGt(inflatedBorrowable, honestBorrowable, "phantom terminal should inflate borrow quote");
|
|
253
|
-
assertLe(inflatedBorrowable, realSurplus, "PoC should remain payable by the honest terminal");
|
|
254
|
-
|
|
255
|
-
_grantBurnPermission(USER, REVNET_ID, address(LOANS));
|
|
256
|
-
|
|
257
|
-
uint256 balanceBefore = USER.balance;
|
|
258
|
-
vm.prank(USER);
|
|
259
|
-
LOANS.borrowFrom(
|
|
260
|
-
REVNET_ID,
|
|
261
|
-
REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()}),
|
|
262
|
-
inflatedBorrowable,
|
|
263
|
-
collateral,
|
|
264
|
-
payable(USER),
|
|
265
|
-
25,
|
|
266
|
-
USER
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
uint256 balanceDelta = USER.balance - balanceBefore;
|
|
270
|
-
assertGt(balanceDelta, honestBorrowable, "borrower extracts more ETH than real treasury surplus supports");
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function _deployFeeProject() internal {
|
|
274
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](1);
|
|
275
|
-
acc[0] = JBAccountingContext({
|
|
276
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
277
|
-
});
|
|
278
|
-
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
279
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
280
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
281
|
-
stages[0] = REVStageConfig({
|
|
282
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
283
|
-
autoIssuances: new REVAutoIssuance[](0),
|
|
284
|
-
splitPercent: 0,
|
|
285
|
-
splits: new JBSplit[](0),
|
|
286
|
-
initialIssuance: uint112(1000e18),
|
|
287
|
-
issuanceCutFrequency: 0,
|
|
288
|
-
issuanceCutPercent: 0,
|
|
289
|
-
cashOutTaxRate: 0,
|
|
290
|
-
extraMetadata: 0
|
|
291
|
-
});
|
|
292
|
-
REVConfig memory feeConfig = REVConfig({
|
|
293
|
-
description: REVDescription("Fee Revnet", "FEE", "", "FEE_TOKEN"),
|
|
294
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
295
|
-
splitOperator: multisig(),
|
|
296
|
-
stageConfigurations: stages
|
|
297
|
-
});
|
|
298
|
-
vm.prank(multisig());
|
|
299
|
-
REV_DEPLOYER.deployFor({
|
|
300
|
-
revnetId: FEE_PROJECT_ID,
|
|
301
|
-
configuration: feeConfig,
|
|
302
|
-
terminalConfigurations: tc,
|
|
303
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
304
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
|
|
305
|
-
}),
|
|
306
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
307
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function _deployRevnetWithPhantomTerminal() internal returns (uint256 revnetId) {
|
|
312
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](1);
|
|
313
|
-
acc[0] = JBAccountingContext({
|
|
314
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
315
|
-
});
|
|
316
|
-
JBTerminalConfig[] memory tc = new JBTerminalConfig[](2);
|
|
317
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
318
|
-
tc[1] = JBTerminalConfig({terminal: PHANTOM_TERMINAL, accountingContextsToAccept: acc});
|
|
319
|
-
|
|
320
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
321
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
322
|
-
splits[0].beneficiary = payable(multisig());
|
|
323
|
-
splits[0].percent = 10_000;
|
|
324
|
-
stages[0] = REVStageConfig({
|
|
325
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
326
|
-
autoIssuances: new REVAutoIssuance[](0),
|
|
327
|
-
splitPercent: 0,
|
|
328
|
-
splits: splits,
|
|
329
|
-
initialIssuance: uint112(1000e18),
|
|
330
|
-
issuanceCutFrequency: 0,
|
|
331
|
-
issuanceCutPercent: 0,
|
|
332
|
-
cashOutTaxRate: 5000,
|
|
333
|
-
extraMetadata: 0
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
REVConfig memory config = REVConfig({
|
|
337
|
-
description: REVDescription("Phantom", "PHM", "", "PHM_TOKEN"),
|
|
338
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
339
|
-
splitOperator: multisig(),
|
|
340
|
-
stageConfigurations: stages
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
vm.prank(multisig());
|
|
344
|
-
(revnetId,) = REV_DEPLOYER.deployFor({
|
|
345
|
-
revnetId: 0,
|
|
346
|
-
configuration: config,
|
|
347
|
-
terminalConfigurations: tc,
|
|
348
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
349
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("PHANTOM")
|
|
350
|
-
}),
|
|
351
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
352
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function _grantBurnPermission(address account, uint256 revnetId, address operator) internal {
|
|
357
|
-
uint8[] memory permissionIds = new uint8[](1);
|
|
358
|
-
permissionIds[0] = JBPermissionIds.BURN_TOKENS;
|
|
359
|
-
|
|
360
|
-
vm.prank(account);
|
|
361
|
-
jbPermissions()
|
|
362
|
-
.setPermissionsFor(
|
|
363
|
-
account,
|
|
364
|
-
JBPermissionsData({operator: operator, projectId: uint56(revnetId), permissionIds: permissionIds})
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
@@ -1,188 +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 {IJBRulesetDataHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetDataHook.sol";
|
|
8
|
-
import {JBBeforeCashOutRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforeCashOutRecordedContext.sol";
|
|
9
|
-
import {JBBeforePayRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforePayRecordedContext.sol";
|
|
10
|
-
import {JBCashOutHookSpecification} from "@bananapus/core-v6/src/structs/JBCashOutHookSpecification.sol";
|
|
11
|
-
import {JBPayHookSpecification} from "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
|
|
12
|
-
import {JBTokenAmount} from "@bananapus/core-v6/src/structs/JBTokenAmount.sol";
|
|
13
|
-
import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
14
|
-
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
15
|
-
import {IJBSuckerRegistry} from "@bananapus/suckers-v6/src/interfaces/IJBSuckerRegistry.sol";
|
|
16
|
-
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
17
|
-
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
|
18
|
-
|
|
19
|
-
import {REVOwner} from "../../src/REVOwner.sol";
|
|
20
|
-
|
|
21
|
-
/// @notice Mock sucker registry that returns configurable remote values.
|
|
22
|
-
/// @dev All functions are view/pure to avoid StateChangeDuringStaticCall when called from
|
|
23
|
-
/// REVOwner.beforeCashOutRecordedWith (which is a view function).
|
|
24
|
-
contract MockSuckerRegistry {
|
|
25
|
-
uint256 public remoteSurplusToReturn;
|
|
26
|
-
uint256 public remoteSupplyToReturn;
|
|
27
|
-
|
|
28
|
-
function setRemoteValues(uint256 supply, uint256 surplus) external {
|
|
29
|
-
remoteSupplyToReturn = supply;
|
|
30
|
-
remoteSurplusToReturn = surplus;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function isSuckerOf(uint256, address) external pure returns (bool) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function remoteTotalSupplyOf(uint256) external view returns (uint256) {
|
|
38
|
-
return remoteSupplyToReturn;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function remoteSurplusOf(uint256, uint256, uint256) external view returns (uint256) {
|
|
42
|
-
return remoteSurplusToReturn;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/// @notice Minimal echo buyback registry that passes through cash out context unchanged.
|
|
47
|
-
contract EchoBuybackRegistry is IJBRulesetDataHook {
|
|
48
|
-
function beforeCashOutRecordedWith(JBBeforeCashOutRecordedContext calldata context)
|
|
49
|
-
external
|
|
50
|
-
pure
|
|
51
|
-
returns (
|
|
52
|
-
uint256 cashOutTaxRate,
|
|
53
|
-
uint256 cashOutCount,
|
|
54
|
-
uint256 totalSupply,
|
|
55
|
-
uint256 effectiveSurplusValue,
|
|
56
|
-
JBCashOutHookSpecification[] memory hookSpecifications
|
|
57
|
-
)
|
|
58
|
-
{
|
|
59
|
-
cashOutTaxRate = context.cashOutTaxRate;
|
|
60
|
-
cashOutCount = context.cashOutCount;
|
|
61
|
-
totalSupply = context.totalSupply;
|
|
62
|
-
effectiveSurplusValue = context.surplus.value;
|
|
63
|
-
hookSpecifications = new JBCashOutHookSpecification[](0);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function beforePayRecordedWith(JBBeforePayRecordedContext calldata context)
|
|
67
|
-
external
|
|
68
|
-
pure
|
|
69
|
-
returns (uint256 weight, JBPayHookSpecification[] memory hookSpecifications)
|
|
70
|
-
{
|
|
71
|
-
weight = context.weight;
|
|
72
|
-
hookSpecifications = new JBPayHookSpecification[](0);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function hasMintPermissionFor(uint256, JBRuleset calldata, address) external pure returns (bool) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function setPoolFor(uint256, PoolKey calldata, uint256, address) external pure {}
|
|
80
|
-
function setPoolFor(uint256, uint24, int24, uint256, address) external pure {}
|
|
81
|
-
function initializePoolFor(uint256, uint24, int24, uint256, address, uint160) external pure {}
|
|
82
|
-
|
|
83
|
-
function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
|
|
84
|
-
return interfaceId == type(IJBRulesetDataHook).interfaceId || interfaceId == type(IERC165).interfaceId;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/// @notice REVOwner.beforeCashOutRecordedWith should pass the surplus currency (not the token address) to
|
|
89
|
-
/// remoteSurplusOf. @dev `currency: uint256(context.surplus.currency)` passes the correct currency value,
|
|
90
|
-
/// not `uint256(uint160(context.surplus.token))` which would pass the token address (e.g. 61166 for NATIVE_TOKEN).
|
|
91
|
-
contract REVOwnerCurrencyMismatchTest is TestBaseWorkflow {
|
|
92
|
-
REVOwner internal ownerHook;
|
|
93
|
-
MockSuckerRegistry internal suckerRegistry;
|
|
94
|
-
EchoBuybackRegistry internal buybackRegistry;
|
|
95
|
-
|
|
96
|
-
function setUp() public override {
|
|
97
|
-
super.setUp();
|
|
98
|
-
|
|
99
|
-
suckerRegistry = new MockSuckerRegistry();
|
|
100
|
-
buybackRegistry = new EchoBuybackRegistry();
|
|
101
|
-
|
|
102
|
-
ownerHook = new REVOwner(
|
|
103
|
-
IJBBuybackHookRegistry(address(buybackRegistry)),
|
|
104
|
-
jbDirectory(),
|
|
105
|
-
999_999, // fee revnet ID (won't be used in this test path)
|
|
106
|
-
IJBSuckerRegistry(address(suckerRegistry)),
|
|
107
|
-
address(0), // loans
|
|
108
|
-
address(0) // hidden tokens
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/// @notice Verify that remoteSurplusOf is called with the context's currency, not the token address.
|
|
113
|
-
/// @dev NATIVE_TOKEN = 0x000000000000000000000000000000000000EEEe
|
|
114
|
-
/// uint160(NATIVE_TOKEN) = 61166
|
|
115
|
-
/// The correct currency for ETH is 1 (baseCurrency).
|
|
116
|
-
/// Before the fix, 61166 was passed. After the fix, 1 is passed.
|
|
117
|
-
function test_remoteSurplusOf_receives_currency_not_token_address() public {
|
|
118
|
-
// Set up remote values so the registry returns something.
|
|
119
|
-
suckerRegistry.setRemoteValues(500 ether, 900 ether);
|
|
120
|
-
|
|
121
|
-
uint32 ethCurrency = 1; // ETH baseCurrency identifier
|
|
122
|
-
|
|
123
|
-
// Build a context where surplus.token = NATIVE_TOKEN and surplus.currency = 1 (ETH).
|
|
124
|
-
// These are intentionally different values to detect the bug.
|
|
125
|
-
JBBeforeCashOutRecordedContext memory context = JBBeforeCashOutRecordedContext({
|
|
126
|
-
terminal: address(jbMultiTerminal()),
|
|
127
|
-
holder: address(0xCAFE),
|
|
128
|
-
projectId: 1,
|
|
129
|
-
rulesetId: 0,
|
|
130
|
-
cashOutCount: 100 ether,
|
|
131
|
-
totalSupply: 1000 ether,
|
|
132
|
-
surplus: JBTokenAmount({
|
|
133
|
-
token: JBConstants.NATIVE_TOKEN, // 0xEEEe
|
|
134
|
-
value: 100 ether,
|
|
135
|
-
decimals: 18,
|
|
136
|
-
currency: ethCurrency // 1
|
|
137
|
-
}),
|
|
138
|
-
useTotalSurplus: true,
|
|
139
|
-
cashOutTaxRate: 0, // zero tax = feeless path (simpler, avoids needing fee terminal)
|
|
140
|
-
beneficiaryIsFeeless: false,
|
|
141
|
-
metadata: ""
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Use vm.expectCall to verify the exact parameters passed to remoteSurplusOf.
|
|
145
|
-
// After fix: currency should be 1 (ethCurrency), NOT 61166 (uint160(NATIVE_TOKEN)).
|
|
146
|
-
// This assertion will fail if the buggy code passes uint256(uint160(NATIVE_TOKEN)) = 61166.
|
|
147
|
-
vm.expectCall(
|
|
148
|
-
address(suckerRegistry), abi.encodeCall(suckerRegistry.remoteSurplusOf, (1, 18, uint256(ethCurrency)))
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
ownerHook.beforeCashOutRecordedWith(context);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/// @notice Verify that the remote surplus is actually included in the returned effectiveSurplusValue.
|
|
155
|
-
/// @dev This is a regression test: if the wrong currency is passed, the registry might return 0
|
|
156
|
-
/// and the remote surplus would be silently dropped.
|
|
157
|
-
function test_remoteSurplus_included_in_effectiveSurplus() public {
|
|
158
|
-
suckerRegistry.setRemoteValues(500 ether, 900 ether);
|
|
159
|
-
|
|
160
|
-
uint32 ethCurrency = 1;
|
|
161
|
-
|
|
162
|
-
JBBeforeCashOutRecordedContext memory context = JBBeforeCashOutRecordedContext({
|
|
163
|
-
terminal: address(jbMultiTerminal()),
|
|
164
|
-
holder: address(0xCAFE),
|
|
165
|
-
projectId: 1,
|
|
166
|
-
rulesetId: 0,
|
|
167
|
-
cashOutCount: 100 ether,
|
|
168
|
-
totalSupply: 1000 ether,
|
|
169
|
-
surplus: JBTokenAmount({
|
|
170
|
-
token: JBConstants.NATIVE_TOKEN, value: 100 ether, decimals: 18, currency: ethCurrency
|
|
171
|
-
}),
|
|
172
|
-
useTotalSurplus: true,
|
|
173
|
-
cashOutTaxRate: 0,
|
|
174
|
-
beneficiaryIsFeeless: false,
|
|
175
|
-
metadata: ""
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
(,, uint256 returnedSupply, uint256 returnedSurplus,) = ownerHook.beforeCashOutRecordedWith(context);
|
|
179
|
-
|
|
180
|
-
// Remote supply should be added.
|
|
181
|
-
assertEq(returnedSupply, 1500 ether, "totalSupply should include remote supply");
|
|
182
|
-
|
|
183
|
-
// Remote surplus should be added (100 local + 900 remote = 1000).
|
|
184
|
-
assertEq(
|
|
185
|
-
returnedSurplus, 1000 ether, "effectiveSurplusValue should include remote surplus (100 local + 900 remote)"
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
}
|