@rev-net/core-v6 0.0.36 → 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.
- 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 +60 -65
- package/src/REVHiddenTokens.sol +2 -2
- package/src/REVLoans.sol +134 -90
- package/src/REVOwner.sol +124 -17
- package/src/interfaces/IREVDeployer.sol +2 -1
- package/src/interfaces/IREVHiddenTokens.sol +4 -1
- package/src/interfaces/IREVOwner.sol +5 -0
- package/ADMINISTRATION.md +0 -73
- package/ARCHITECTURE.md +0 -116
- package/AUDIT_INSTRUCTIONS.md +0 -90
- package/RISKS.md +0 -97
- 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 -368
- 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/CodexCrossChainBuybackRouteMismatch.t.sol +0 -184
- package/test/audit/CodexPhantomSurplusTerminal.t.sol +0 -367
- package/test/audit/CodexREVOwnerRemoteSurplusCurrencyMismatch.t.sol +0 -142
- package/test/audit/LoanIdOverflowGuard.t.sol +0 -523
- package/test/audit/NemesisOperatorDelegation.t.sol +0 -356
- 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/TestLoanBorrowFork.t.sol +0 -163
- package/test/fork/TestLoanCrossRulesetFork.t.sol +0 -308
- package/test/fork/TestLoanERC20Fork.t.sol +0 -465
- 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,356 +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/libraries/JBConstants.sol";
|
|
22
|
-
import "@bananapus/permission-ids-v6/src/JBPermissionIds.sol";
|
|
23
|
-
import "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
24
|
-
import "@bananapus/core-v6/src/structs/JBPermissionsData.sol";
|
|
25
|
-
import "@bananapus/core-v6/src/structs/JBTerminalConfig.sol";
|
|
26
|
-
import "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
27
|
-
import "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
28
|
-
|
|
29
|
-
import {MockBuybackDataHook} from "../mock/MockBuybackDataHook.sol";
|
|
30
|
-
import {REVEmpty721Config} from "../helpers/REVEmpty721Config.sol";
|
|
31
|
-
import {REVDeployer} from "../../src/REVDeployer.sol";
|
|
32
|
-
import {REVHiddenTokens} from "../../src/REVHiddenTokens.sol";
|
|
33
|
-
import {REVLoans} from "../../src/REVLoans.sol";
|
|
34
|
-
import {REVOwner} from "../../src/REVOwner.sol";
|
|
35
|
-
import {IREVLoans} from "../../src/interfaces/IREVLoans.sol";
|
|
36
|
-
import {IREVHiddenTokens} from "../../src/interfaces/IREVHiddenTokens.sol";
|
|
37
|
-
import {REVConfig} from "../../src/structs/REVConfig.sol";
|
|
38
|
-
import {REVDescription} from "../../src/structs/REVDescription.sol";
|
|
39
|
-
import {REVLoanSource} from "../../src/structs/REVLoanSource.sol";
|
|
40
|
-
import {REVStageConfig} from "../../src/structs/REVStageConfig.sol";
|
|
41
|
-
import {REVAutoIssuance} from "../../src/structs/REVAutoIssuance.sol";
|
|
42
|
-
import {REVSuckerDeploymentConfig} from "../../src/structs/REVSuckerDeploymentConfig.sol";
|
|
43
|
-
import {IREVDeployer} from "../../src/interfaces/IREVDeployer.sol";
|
|
44
|
-
import {MockSuckerRegistry} from "../mock/MockSuckerRegistry.sol";
|
|
45
|
-
|
|
46
|
-
contract NemesisOperatorDelegationTest is TestBaseWorkflow {
|
|
47
|
-
bytes32 internal constant REV_DEPLOYER_SALT = "REVDeployer";
|
|
48
|
-
bytes32 internal constant ERC20_SALT = "REV_TOKEN";
|
|
49
|
-
|
|
50
|
-
address internal constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
51
|
-
|
|
52
|
-
address internal USER = makeAddr("user");
|
|
53
|
-
address internal OPERATOR = makeAddr("operator");
|
|
54
|
-
|
|
55
|
-
REVDeployer internal REV_DEPLOYER;
|
|
56
|
-
REVOwner internal REV_OWNER;
|
|
57
|
-
REVHiddenTokens internal HIDDEN_TOKENS;
|
|
58
|
-
REVLoans internal LOANS;
|
|
59
|
-
JB721TiersHook internal EXAMPLE_HOOK;
|
|
60
|
-
IJB721TiersHookDeployer internal HOOK_DEPLOYER;
|
|
61
|
-
IJB721TiersHookStore internal HOOK_STORE;
|
|
62
|
-
IJBAddressRegistry internal ADDRESS_REGISTRY;
|
|
63
|
-
IJBSuckerRegistry internal SUCKER_REGISTRY;
|
|
64
|
-
CTPublisher internal PUBLISHER;
|
|
65
|
-
MockBuybackDataHook internal MOCK_BUYBACK;
|
|
66
|
-
|
|
67
|
-
uint256 internal FEE_PROJECT_ID;
|
|
68
|
-
uint256 internal REVNET_ID;
|
|
69
|
-
|
|
70
|
-
function setUp() public override {
|
|
71
|
-
super.setUp();
|
|
72
|
-
|
|
73
|
-
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
74
|
-
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
75
|
-
HOOK_STORE = new JB721TiersHookStore();
|
|
76
|
-
EXAMPLE_HOOK = new JB721TiersHook(
|
|
77
|
-
jbDirectory(),
|
|
78
|
-
jbPermissions(),
|
|
79
|
-
jbPrices(),
|
|
80
|
-
jbRulesets(),
|
|
81
|
-
HOOK_STORE,
|
|
82
|
-
jbSplits(),
|
|
83
|
-
IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
|
|
84
|
-
multisig()
|
|
85
|
-
);
|
|
86
|
-
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
87
|
-
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
88
|
-
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
89
|
-
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
90
|
-
|
|
91
|
-
LOANS = new REVLoans({
|
|
92
|
-
controller: jbController(),
|
|
93
|
-
suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
|
|
94
|
-
revId: FEE_PROJECT_ID,
|
|
95
|
-
owner: address(this),
|
|
96
|
-
permit2: permit2(),
|
|
97
|
-
trustedForwarder: TRUSTED_FORWARDER
|
|
98
|
-
});
|
|
99
|
-
HIDDEN_TOKENS = new REVHiddenTokens(jbController(), TRUSTED_FORWARDER);
|
|
100
|
-
REV_OWNER = new REVOwner(
|
|
101
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
102
|
-
jbDirectory(),
|
|
103
|
-
FEE_PROJECT_ID,
|
|
104
|
-
SUCKER_REGISTRY,
|
|
105
|
-
address(LOANS),
|
|
106
|
-
address(HIDDEN_TOKENS)
|
|
107
|
-
);
|
|
108
|
-
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
109
|
-
jbController(),
|
|
110
|
-
SUCKER_REGISTRY,
|
|
111
|
-
FEE_PROJECT_ID,
|
|
112
|
-
HOOK_DEPLOYER,
|
|
113
|
-
PUBLISHER,
|
|
114
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
115
|
-
address(LOANS),
|
|
116
|
-
TRUSTED_FORWARDER,
|
|
117
|
-
address(REV_OWNER)
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
REV_OWNER.setDeployer(IREVDeployer(REV_DEPLOYER));
|
|
121
|
-
|
|
122
|
-
vm.prank(multisig());
|
|
123
|
-
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
124
|
-
|
|
125
|
-
_deployFeeProject();
|
|
126
|
-
REVNET_ID = _deployRevnet();
|
|
127
|
-
|
|
128
|
-
vm.deal(USER, 100e18);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function test_openLoanOperatorCanRedirectBorrowedFunds() public {
|
|
132
|
-
uint256 userTokens = _payUserIntoRevnet(10e18);
|
|
133
|
-
_grantPermission(USER, REVNET_ID, address(LOANS), JBPermissionIds.BURN_TOKENS);
|
|
134
|
-
_grantPermission(USER, REVNET_ID, OPERATOR, JBPermissionIds.OPEN_LOAN);
|
|
135
|
-
|
|
136
|
-
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
137
|
-
uint256 operatorBalanceBefore = OPERATOR.balance;
|
|
138
|
-
|
|
139
|
-
vm.prank(OPERATOR);
|
|
140
|
-
(uint256 loanId,) = LOANS.borrowFrom(REVNET_ID, source, 0, userTokens / 2, payable(OPERATOR), 25, USER);
|
|
141
|
-
|
|
142
|
-
assertEq(LOANS.ownerOf(loanId), USER, "loan NFT stays with the holder");
|
|
143
|
-
assertGt(OPERATOR.balance, operatorBalanceBefore, "operator receives the borrowed funds");
|
|
144
|
-
assertLt(
|
|
145
|
-
jbController().TOKENS().totalBalanceOf(USER, REVNET_ID),
|
|
146
|
-
userTokens,
|
|
147
|
-
"holder lost collateral even though proceeds were redirected"
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function test_hiddenTokensOperatorCanAllowHolderToHideOwnTokens() public {
|
|
152
|
-
uint256 userTokens = _payUserIntoRevnet(10e18);
|
|
153
|
-
uint256 hiddenCount = userTokens / 2;
|
|
154
|
-
|
|
155
|
-
_grantPermission(USER, REVNET_ID, address(HIDDEN_TOKENS), JBPermissionIds.BURN_TOKENS);
|
|
156
|
-
_allowHolderToHide(USER);
|
|
157
|
-
|
|
158
|
-
vm.prank(USER);
|
|
159
|
-
HIDDEN_TOKENS.hideTokensOf(REVNET_ID, hiddenCount, USER);
|
|
160
|
-
|
|
161
|
-
vm.prank(USER);
|
|
162
|
-
HIDDEN_TOKENS.revealTokensOf(REVNET_ID, hiddenCount, USER);
|
|
163
|
-
|
|
164
|
-
assertEq(HIDDEN_TOKENS.hiddenBalanceOf(USER, REVNET_ID), 0, "holder hidden balance was consumed");
|
|
165
|
-
assertEq(
|
|
166
|
-
jbController().TOKENS().totalBalanceOf(USER, REVNET_ID),
|
|
167
|
-
userTokens,
|
|
168
|
-
"holder gets their own revealed tokens back"
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function test_hiddenTokensPermissionedOperatorCanHideOwnTokens() public {
|
|
173
|
-
vm.deal(OPERATOR, 10e18);
|
|
174
|
-
vm.prank(OPERATOR);
|
|
175
|
-
uint256 operatorTokens = jbMultiTerminal().pay{value: 10e18}({
|
|
176
|
-
projectId: REVNET_ID,
|
|
177
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
178
|
-
amount: 10e18,
|
|
179
|
-
beneficiary: OPERATOR,
|
|
180
|
-
minReturnedTokens: 0,
|
|
181
|
-
memo: "",
|
|
182
|
-
metadata: ""
|
|
183
|
-
});
|
|
184
|
-
uint256 hiddenCount = operatorTokens / 2;
|
|
185
|
-
|
|
186
|
-
_grantPermission(OPERATOR, REVNET_ID, address(HIDDEN_TOKENS), JBPermissionIds.BURN_TOKENS);
|
|
187
|
-
_grantOperatorHidePermission(OPERATOR);
|
|
188
|
-
|
|
189
|
-
vm.prank(OPERATOR);
|
|
190
|
-
HIDDEN_TOKENS.hideTokensOf(REVNET_ID, hiddenCount, OPERATOR);
|
|
191
|
-
|
|
192
|
-
assertEq(HIDDEN_TOKENS.hiddenBalanceOf(OPERATOR, REVNET_ID), hiddenCount, "operator hidden balance was updated");
|
|
193
|
-
assertEq(
|
|
194
|
-
jbController().TOKENS().totalBalanceOf(OPERATOR, REVNET_ID),
|
|
195
|
-
operatorTokens - hiddenCount,
|
|
196
|
-
"operator's visible balance was reduced"
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function test_hiddenTokensDelegateCannotHideAnotherHoldersTokens() public {
|
|
201
|
-
uint256 userTokens = _payUserIntoRevnet(10e18);
|
|
202
|
-
|
|
203
|
-
_grantPermission(USER, REVNET_ID, address(HIDDEN_TOKENS), JBPermissionIds.BURN_TOKENS);
|
|
204
|
-
_allowHolderToHide(USER);
|
|
205
|
-
|
|
206
|
-
vm.prank(OPERATOR);
|
|
207
|
-
vm.expectRevert(
|
|
208
|
-
abi.encodeWithSelector(REVHiddenTokens.REVHiddenTokens_Unauthorized.selector, REVNET_ID, OPERATOR)
|
|
209
|
-
);
|
|
210
|
-
HIDDEN_TOKENS.hideTokensOf(REVNET_ID, userTokens / 2, USER);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function test_hiddenTokensOperatorCanDisallowHolder() public {
|
|
214
|
-
uint256 userTokens = _payUserIntoRevnet(10e18);
|
|
215
|
-
|
|
216
|
-
_grantPermission(USER, REVNET_ID, address(HIDDEN_TOKENS), JBPermissionIds.BURN_TOKENS);
|
|
217
|
-
_allowHolderToHide(USER);
|
|
218
|
-
|
|
219
|
-
vm.prank(address(REV_DEPLOYER));
|
|
220
|
-
HIDDEN_TOKENS.setTokenHidingAllowedFor(REVNET_ID, USER, false);
|
|
221
|
-
|
|
222
|
-
vm.prank(USER);
|
|
223
|
-
vm.expectRevert(abi.encodeWithSelector(REVHiddenTokens.REVHiddenTokens_Unauthorized.selector, REVNET_ID, USER));
|
|
224
|
-
HIDDEN_TOKENS.hideTokensOf(REVNET_ID, userTokens / 2, USER);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function _grantPermission(address account, uint256 revnetId, address operator, uint8 permissionId) internal {
|
|
228
|
-
uint8[] memory permissionIds = new uint8[](1);
|
|
229
|
-
permissionIds[0] = permissionId;
|
|
230
|
-
|
|
231
|
-
vm.prank(account);
|
|
232
|
-
jbPermissions()
|
|
233
|
-
.setPermissionsFor(
|
|
234
|
-
account,
|
|
235
|
-
JBPermissionsData({operator: operator, projectId: uint56(revnetId), permissionIds: permissionIds})
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function _payUserIntoRevnet(uint256 amount) internal returns (uint256 tokenCount) {
|
|
240
|
-
vm.prank(USER);
|
|
241
|
-
tokenCount = jbMultiTerminal().pay{value: amount}({
|
|
242
|
-
projectId: REVNET_ID,
|
|
243
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
244
|
-
amount: amount,
|
|
245
|
-
beneficiary: USER,
|
|
246
|
-
minReturnedTokens: 0,
|
|
247
|
-
memo: "",
|
|
248
|
-
metadata: ""
|
|
249
|
-
});
|
|
250
|
-
assertGt(tokenCount, 0, "payment should mint revnet tokens");
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function _allowHolderToHide(address holder) internal {
|
|
254
|
-
vm.prank(address(REV_DEPLOYER));
|
|
255
|
-
HIDDEN_TOKENS.setTokenHidingAllowedFor(REVNET_ID, holder, true);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function _grantOperatorHidePermission(address operator) internal {
|
|
259
|
-
uint8[] memory permissionIds = new uint8[](1);
|
|
260
|
-
permissionIds[0] = JBPermissionIds.HIDE_TOKENS;
|
|
261
|
-
|
|
262
|
-
vm.prank(address(REV_DEPLOYER));
|
|
263
|
-
jbPermissions()
|
|
264
|
-
.setPermissionsFor(
|
|
265
|
-
address(REV_DEPLOYER),
|
|
266
|
-
JBPermissionsData({operator: operator, projectId: uint56(REVNET_ID), permissionIds: permissionIds})
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function _deployFeeProject() internal {
|
|
271
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](1);
|
|
272
|
-
acc[0] = JBAccountingContext({
|
|
273
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
277
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
278
|
-
|
|
279
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
280
|
-
stages[0] = REVStageConfig({
|
|
281
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
282
|
-
autoIssuances: new REVAutoIssuance[](0),
|
|
283
|
-
splitPercent: 0,
|
|
284
|
-
splits: new JBSplit[](0),
|
|
285
|
-
initialIssuance: uint112(1000e18),
|
|
286
|
-
issuanceCutFrequency: 0,
|
|
287
|
-
issuanceCutPercent: 0,
|
|
288
|
-
cashOutTaxRate: 0,
|
|
289
|
-
extraMetadata: 0
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
REVConfig memory feeConfig = REVConfig({
|
|
293
|
-
description: REVDescription("Fee Revnet", "FEE", "", ERC20_SALT),
|
|
294
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
295
|
-
splitOperator: multisig(),
|
|
296
|
-
stageConfigurations: stages
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
vm.prank(multisig());
|
|
300
|
-
REV_DEPLOYER.deployFor({
|
|
301
|
-
revnetId: FEE_PROJECT_ID,
|
|
302
|
-
configuration: feeConfig,
|
|
303
|
-
terminalConfigurations: tc,
|
|
304
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
305
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
|
|
306
|
-
}),
|
|
307
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
308
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function _deployRevnet() internal returns (uint256 revnetId) {
|
|
313
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](1);
|
|
314
|
-
acc[0] = JBAccountingContext({
|
|
315
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
319
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
320
|
-
|
|
321
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
322
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
323
|
-
splits[0].beneficiary = payable(multisig());
|
|
324
|
-
splits[0].percent = 10_000;
|
|
325
|
-
|
|
326
|
-
stages[0] = REVStageConfig({
|
|
327
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
328
|
-
autoIssuances: new REVAutoIssuance[](0),
|
|
329
|
-
splitPercent: 2000,
|
|
330
|
-
splits: splits,
|
|
331
|
-
initialIssuance: uint112(1000e18),
|
|
332
|
-
issuanceCutFrequency: 90 days,
|
|
333
|
-
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
334
|
-
cashOutTaxRate: 6000,
|
|
335
|
-
extraMetadata: 0
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
REVConfig memory config = REVConfig({
|
|
339
|
-
description: REVDescription("Revnet", "REV", "", bytes32("REV_TOKEN_2")),
|
|
340
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
341
|
-
splitOperator: multisig(),
|
|
342
|
-
stageConfigurations: stages
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
(revnetId,) = REV_DEPLOYER.deployFor({
|
|
346
|
-
revnetId: 0,
|
|
347
|
-
configuration: config,
|
|
348
|
-
terminalConfigurations: tc,
|
|
349
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
350
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("REV")
|
|
351
|
-
}),
|
|
352
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
353
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity 0.8.28;
|
|
3
|
-
|
|
4
|
-
import {Test} from "forge-std/Test.sol";
|
|
5
|
-
import {IJBBuybackHookRegistry} from "@bananapus/buyback-hook-v6/src/interfaces/IJBBuybackHookRegistry.sol";
|
|
6
|
-
import {IJBCashOutHook} from "@bananapus/core-v6/src/interfaces/IJBCashOutHook.sol";
|
|
7
|
-
import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
|
|
8
|
-
import {IJBRulesetDataHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetDataHook.sol";
|
|
9
|
-
import {IJBSuckerRegistry} from "@bananapus/suckers-v6/src/interfaces/IJBSuckerRegistry.sol";
|
|
10
|
-
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
11
|
-
|
|
12
|
-
import {REVOwner} from "../../src/REVOwner.sol";
|
|
13
|
-
|
|
14
|
-
/// @notice Regression test for missing IERC165 support: REVOwner.supportsInterface omits IERC165.
|
|
15
|
-
contract AuditFixL17Test is Test {
|
|
16
|
-
REVOwner revOwner;
|
|
17
|
-
|
|
18
|
-
function setUp() public {
|
|
19
|
-
revOwner = new REVOwner(
|
|
20
|
-
IJBBuybackHookRegistry(makeAddr("buybackHook")),
|
|
21
|
-
IJBDirectory(makeAddr("directory")),
|
|
22
|
-
1, // feeRevnetId
|
|
23
|
-
IJBSuckerRegistry(makeAddr("suckerRegistry")),
|
|
24
|
-
makeAddr("loans"),
|
|
25
|
-
makeAddr("hiddenTokens")
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/// @notice supportsInterface returns true for IERC165 (0x01ffc9a7).
|
|
30
|
-
function test_supportsInterface_IERC165() public view {
|
|
31
|
-
assertTrue(revOwner.supportsInterface(type(IERC165).interfaceId), "should support IERC165");
|
|
32
|
-
assertEq(type(IERC165).interfaceId, bytes4(0x01ffc9a7), "IERC165 interface ID should be 0x01ffc9a7");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/// @notice supportsInterface returns true for IJBRulesetDataHook.
|
|
36
|
-
function test_supportsInterface_IJBRulesetDataHook() public view {
|
|
37
|
-
assertTrue(
|
|
38
|
-
revOwner.supportsInterface(type(IJBRulesetDataHook).interfaceId), "should support IJBRulesetDataHook"
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/// @notice supportsInterface returns true for IJBCashOutHook.
|
|
43
|
-
function test_supportsInterface_IJBCashOutHook() public view {
|
|
44
|
-
assertTrue(revOwner.supportsInterface(type(IJBCashOutHook).interfaceId), "should support IJBCashOutHook");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/// @notice supportsInterface returns false for an unsupported interface.
|
|
48
|
-
function test_supportsInterface_unsupported() public view {
|
|
49
|
-
assertFalse(revOwner.supportsInterface(bytes4(0xdeadbeef)), "should not support random interface");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity 0.8.28;
|
|
3
|
-
|
|
4
|
-
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
5
|
-
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
6
|
-
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
7
|
-
import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
|
|
8
|
-
import {IJBTerminal} from "@bananapus/core-v6/src/interfaces/IJBTerminal.sol";
|
|
9
|
-
import {IJBPayoutTerminal} from "@bananapus/core-v6/src/interfaces/IJBPayoutTerminal.sol";
|
|
10
|
-
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
11
|
-
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
12
|
-
import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
13
|
-
import {JBPayHookSpecification} from "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
|
|
14
|
-
import {REVLoanSource} from "../../src/structs/REVLoanSource.sol";
|
|
15
|
-
import {REVLoansFeeRecovery} from "../REVLoansFeeRecovery.t.sol";
|
|
16
|
-
|
|
17
|
-
contract StickyAllowanceFeeTerminal is ERC165, IJBPayoutTerminal {
|
|
18
|
-
IERC20 public immutable token;
|
|
19
|
-
address public immutable loans;
|
|
20
|
-
address public thief;
|
|
21
|
-
uint256 public stealAmount;
|
|
22
|
-
|
|
23
|
-
constructor(IERC20 _token, address _loans) {
|
|
24
|
-
token = _token;
|
|
25
|
-
loans = _loans;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function configureSteal(address _thief, uint256 _stealAmount) external {
|
|
29
|
-
thief = _thief;
|
|
30
|
-
stealAmount = _stealAmount;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function pay(
|
|
34
|
-
uint256,
|
|
35
|
-
address,
|
|
36
|
-
uint256,
|
|
37
|
-
address,
|
|
38
|
-
uint256,
|
|
39
|
-
string calldata,
|
|
40
|
-
bytes calldata
|
|
41
|
-
)
|
|
42
|
-
external
|
|
43
|
-
payable
|
|
44
|
-
override
|
|
45
|
-
returns (uint256)
|
|
46
|
-
{
|
|
47
|
-
uint256 amount = stealAmount;
|
|
48
|
-
if (amount != 0) {
|
|
49
|
-
stealAmount = 0;
|
|
50
|
-
token.transferFrom(loans, thief, amount);
|
|
51
|
-
}
|
|
52
|
-
return 0;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function accountingContextForTokenOf(uint256, address) external view override returns (JBAccountingContext memory) {
|
|
56
|
-
return JBAccountingContext({token: address(token), decimals: 6, currency: uint32(uint160(address(token)))});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function accountingContextsOf(uint256) external pure override returns (JBAccountingContext[] memory) {
|
|
60
|
-
return new JBAccountingContext[](0);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function addAccountingContextsFor(uint256, JBAccountingContext[] calldata) external override {}
|
|
64
|
-
|
|
65
|
-
function addToBalanceOf(
|
|
66
|
-
uint256,
|
|
67
|
-
address,
|
|
68
|
-
uint256,
|
|
69
|
-
bool,
|
|
70
|
-
string calldata,
|
|
71
|
-
bytes calldata
|
|
72
|
-
)
|
|
73
|
-
external
|
|
74
|
-
payable
|
|
75
|
-
override
|
|
76
|
-
{}
|
|
77
|
-
|
|
78
|
-
function currentSurplusOf(uint256, address[] calldata, uint256, uint256) external pure override returns (uint256) {
|
|
79
|
-
return 0;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function migrateBalanceOf(uint256, address, IJBTerminal) external pure override returns (uint256) {
|
|
83
|
-
return 0;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function sendPayoutsOf(uint256, address, uint256, uint256, uint256) external pure override returns (uint256) {
|
|
87
|
-
return 0;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function useAllowanceOf(
|
|
91
|
-
uint256,
|
|
92
|
-
address,
|
|
93
|
-
uint256,
|
|
94
|
-
uint256,
|
|
95
|
-
uint256,
|
|
96
|
-
address payable,
|
|
97
|
-
address payable,
|
|
98
|
-
string calldata
|
|
99
|
-
)
|
|
100
|
-
external
|
|
101
|
-
pure
|
|
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 supportsInterface(bytes4 interfaceId) public view override(ERC165, IERC165) returns (bool) {
|
|
125
|
-
return interfaceId == type(IJBTerminal).interfaceId || interfaceId == type(IJBPayoutTerminal).interfaceId
|
|
126
|
-
|| super.supportsInterface(interfaceId);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
contract TestFeeAllowanceLeak is REVLoansFeeRecovery {
|
|
131
|
-
StickyAllowanceFeeTerminal internal stickyFeeTerminal;
|
|
132
|
-
address internal attacker = makeAddr("attacker");
|
|
133
|
-
|
|
134
|
-
function _stickyFeeTerminal() internal returns (StickyAllowanceFeeTerminal) {
|
|
135
|
-
if (address(stickyFeeTerminal) == address(0)) {
|
|
136
|
-
stickyFeeTerminal = new StickyAllowanceFeeTerminal(TOKEN, address(LOANS_CONTRACT));
|
|
137
|
-
}
|
|
138
|
-
return stickyFeeTerminal;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/// @notice Verifies that stale allowance is cleared — the original exploit no longer works.
|
|
142
|
-
/// @dev Previously, a sticky fee terminal could accumulate reusable allowance across borrows.
|
|
143
|
-
/// After the fix (_afterTransferTo clears allowance on success), the allowance is zero.
|
|
144
|
-
function test_feeTerminalCannotHarvestStaleAllowanceAfterFix() public {
|
|
145
|
-
StickyAllowanceFeeTerminal terminal = _stickyFeeTerminal();
|
|
146
|
-
|
|
147
|
-
vm.mockCall(
|
|
148
|
-
address(jbDirectory()),
|
|
149
|
-
abi.encodeWithSelector(IJBDirectory.primaryTerminalOf.selector, FEE_PROJECT_ID, address(TOKEN)),
|
|
150
|
-
abi.encode(address(terminal))
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
REVLoanSource memory source = REVLoanSource({token: address(TOKEN), terminal: jbMultiTerminal()});
|
|
154
|
-
uint256 payAmount = 1_000_000;
|
|
155
|
-
|
|
156
|
-
deal(address(TOKEN), USER, payAmount * 2);
|
|
157
|
-
|
|
158
|
-
vm.startPrank(USER);
|
|
159
|
-
TOKEN.approve(address(jbMultiTerminal()), payAmount * 2);
|
|
160
|
-
uint256 firstTokenCount = jbMultiTerminal().pay(REVNET_ID, address(TOKEN), payAmount, USER, 0, "", "");
|
|
161
|
-
vm.stopPrank();
|
|
162
|
-
|
|
163
|
-
_mockLoanPermission(USER);
|
|
164
|
-
vm.prank(USER);
|
|
165
|
-
LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, firstTokenCount, payable(USER), 25, USER);
|
|
166
|
-
|
|
167
|
-
// Allowance is now cleared after successful fee payment.
|
|
168
|
-
uint256 allowanceAfterBorrow = TOKEN.allowance(address(LOANS_CONTRACT), address(stickyFeeTerminal));
|
|
169
|
-
assertEq(allowanceAfterBorrow, 0, "no stale allowance after successful borrow");
|
|
170
|
-
|
|
171
|
-
// The uncollected fee is still parked in REVLoans (terminal didn't pull it),
|
|
172
|
-
// but there's no allowance for the terminal to steal it later.
|
|
173
|
-
uint256 loansBalance = TOKEN.balanceOf(address(LOANS_CONTRACT));
|
|
174
|
-
assertGt(loansBalance, 0, "uncollected fee is parked in REVLoans");
|
|
175
|
-
|
|
176
|
-
// Second borrow — terminal tries to steal but can't because allowance is 0.
|
|
177
|
-
vm.prank(USER);
|
|
178
|
-
uint256 secondTokenCount = jbMultiTerminal().pay(REVNET_ID, address(TOKEN), payAmount, USER, 0, "", "");
|
|
179
|
-
|
|
180
|
-
terminal.configureSteal(attacker, loansBalance);
|
|
181
|
-
|
|
182
|
-
_mockLoanPermission(USER);
|
|
183
|
-
vm.prank(USER);
|
|
184
|
-
LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, secondTokenCount, payable(USER), 25, USER);
|
|
185
|
-
|
|
186
|
-
// The attacker gets nothing — the steal attempt fails silently (transferFrom reverts,
|
|
187
|
-
// caught by _tryPayFee's try-catch).
|
|
188
|
-
assertEq(TOKEN.balanceOf(attacker), 0, "attacker cannot drain stale allowance");
|
|
189
|
-
|
|
190
|
-
// And the current borrow also leaves zero allowance.
|
|
191
|
-
assertEq(
|
|
192
|
-
TOKEN.allowance(address(LOANS_CONTRACT), address(terminal)),
|
|
193
|
-
0,
|
|
194
|
-
"no fresh stale allowance after second borrow"
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
}
|