@rev-net/core-v6 0.0.1
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/LICENSE +21 -0
- package/README.md +65 -0
- package/REVNET_SECURITY_CHECKLIST.md +164 -0
- package/SECURITY.md +68 -0
- package/SKILLS.md +166 -0
- package/deployments/revnet-core-v5/arbitrum/REVDeployer.json +2821 -0
- package/deployments/revnet-core-v5/arbitrum/REVLoans.json +2260 -0
- package/deployments/revnet-core-v5/arbitrum_sepolia/REVDeployer.json +2821 -0
- package/deployments/revnet-core-v5/arbitrum_sepolia/REVLoans.json +2260 -0
- package/deployments/revnet-core-v5/base/REVDeployer.json +2825 -0
- package/deployments/revnet-core-v5/base/REVLoans.json +2264 -0
- package/deployments/revnet-core-v5/base_sepolia/REVDeployer.json +2825 -0
- package/deployments/revnet-core-v5/base_sepolia/REVLoans.json +2264 -0
- package/deployments/revnet-core-v5/ethereum/REVDeployer.json +2825 -0
- package/deployments/revnet-core-v5/ethereum/REVLoans.json +2264 -0
- package/deployments/revnet-core-v5/optimism/REVDeployer.json +2821 -0
- package/deployments/revnet-core-v5/optimism/REVLoans.json +2260 -0
- package/deployments/revnet-core-v5/optimism_sepolia/REVDeployer.json +2825 -0
- package/deployments/revnet-core-v5/optimism_sepolia/REVLoans.json +2264 -0
- package/deployments/revnet-core-v5/sepolia/REVDeployer.json +2825 -0
- package/deployments/revnet-core-v5/sepolia/REVLoans.json +2264 -0
- package/docs/book.css +13 -0
- package/docs/book.toml +13 -0
- package/docs/solidity.min.js +74 -0
- package/docs/src/README.md +88 -0
- package/docs/src/SUMMARY.md +20 -0
- package/docs/src/src/README.md +7 -0
- package/docs/src/src/REVDeployer.sol/contract.REVDeployer.md +968 -0
- package/docs/src/src/REVLoans.sol/contract.REVLoans.md +1047 -0
- package/docs/src/src/interfaces/IREVDeployer.sol/interface.IREVDeployer.md +243 -0
- package/docs/src/src/interfaces/IREVLoans.sol/interface.IREVLoans.md +296 -0
- package/docs/src/src/interfaces/README.md +5 -0
- package/docs/src/src/structs/README.md +14 -0
- package/docs/src/src/structs/REVAutoIssuance.sol/struct.REVAutoIssuance.md +19 -0
- package/docs/src/src/structs/REVBuybackHookConfig.sol/struct.REVBuybackHookConfig.md +19 -0
- package/docs/src/src/structs/REVBuybackPoolConfig.sol/struct.REVBuybackPoolConfig.md +21 -0
- package/docs/src/src/structs/REVConfig.sol/struct.REVConfig.md +35 -0
- package/docs/src/src/structs/REVCroptopAllowedPost.sol/struct.REVCroptopAllowedPost.md +28 -0
- package/docs/src/src/structs/REVDeploy721TiersHookConfig.sol/struct.REVDeploy721TiersHookConfig.md +34 -0
- package/docs/src/src/structs/REVDescription.sol/struct.REVDescription.md +23 -0
- package/docs/src/src/structs/REVLoan.sol/struct.REVLoan.md +28 -0
- package/docs/src/src/structs/REVLoanSource.sol/struct.REVLoanSource.md +16 -0
- package/docs/src/src/structs/REVStageConfig.sol/struct.REVStageConfig.md +44 -0
- package/docs/src/src/structs/REVSuckerDeploymentConfig.sol/struct.REVSuckerDeploymentConfig.md +16 -0
- package/foundry.lock +11 -0
- package/foundry.toml +23 -0
- package/package.json +31 -0
- package/remappings.txt +1 -0
- package/script/Deploy.s.sol +350 -0
- package/script/helpers/RevnetCoreDeploymentLib.sol +72 -0
- package/slither-ci.config.json +10 -0
- package/sphinx.lock +507 -0
- package/src/REVDeployer.sol +1257 -0
- package/src/REVLoans.sol +1333 -0
- package/src/interfaces/IREVDeployer.sol +198 -0
- package/src/interfaces/IREVLoans.sol +241 -0
- package/src/structs/REVAutoIssuance.sol +11 -0
- package/src/structs/REVConfig.sol +17 -0
- package/src/structs/REVCroptopAllowedPost.sol +20 -0
- package/src/structs/REVDeploy721TiersHookConfig.sol +25 -0
- package/src/structs/REVDescription.sol +14 -0
- package/src/structs/REVLoan.sol +19 -0
- package/src/structs/REVLoanSource.sol +11 -0
- package/src/structs/REVStageConfig.sol +34 -0
- package/src/structs/REVSuckerDeploymentConfig.sol +11 -0
- package/test/REV.integrations.t.sol +420 -0
- package/test/REVAutoIssuanceFuzz.t.sol +276 -0
- package/test/REVDeployerAuditRegressions.t.sol +328 -0
- package/test/REVInvincibility.t.sol +1275 -0
- package/test/REVInvincibilityHandler.sol +357 -0
- package/test/REVLifecycle.t.sol +364 -0
- package/test/REVLoans.invariants.t.sol +642 -0
- package/test/REVLoansAttacks.t.sol +739 -0
- package/test/REVLoansAuditRegressions.t.sol +314 -0
- package/test/REVLoansFeeRecovery.t.sol +704 -0
- package/test/REVLoansSourced.t.sol +1732 -0
- package/test/REVLoansUnSourced.t.sol +331 -0
- package/test/TestPR09_ConversionDocumentation.t.sol +304 -0
- package/test/TestPR10_LiquidationBehavior.t.sol +340 -0
- package/test/TestPR11_LowFindings.t.sol +571 -0
- package/test/TestPR12_FlashLoanSurplus.t.sol +305 -0
- package/test/TestPR13_CrossSourceReallocation.t.sol +302 -0
- package/test/TestPR15_CashOutCallerValidation.t.sol +320 -0
- package/test/TestPR16_ZeroRepayment.t.sol +297 -0
- package/test/TestPR21_Uint112Overflow.t.sol +251 -0
- package/test/TestPR22_HookArrayOOB.t.sol +221 -0
- package/test/TestPR26_BurnHeldTokens.t.sol +331 -0
- package/test/TestPR27_CEIPattern.t.sol +448 -0
- package/test/TestPR29_SwapTerminalPermission.t.sol +206 -0
- package/test/TestPR32_MixedFixes.t.sol +529 -0
- package/test/helpers/MaliciousContracts.sol +233 -0
- package/test/mock/MockBuybackDataHook.sol +61 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.23;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
import /* {*} from */ "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
6
|
+
import /* {*} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
7
|
+
import /* {*} from */ "./../src/REVDeployer.sol";
|
|
8
|
+
import "@croptop/core-v6/src/CTPublisher.sol";
|
|
9
|
+
import {MockBuybackDataHook} from "./mock/MockBuybackDataHook.sol";
|
|
10
|
+
|
|
11
|
+
import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
12
|
+
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
13
|
+
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
14
|
+
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
15
|
+
import "@bananapus/swap-terminal-v6/script/helpers/SwapTerminalDeploymentLib.sol";
|
|
16
|
+
|
|
17
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
18
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
19
|
+
import {REVLoans} from "../src/REVLoans.sol";
|
|
20
|
+
import {REVLoan} from "../src/structs/REVLoan.sol";
|
|
21
|
+
import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
|
|
22
|
+
import {REVLoanSource} from "../src/structs/REVLoanSource.sol";
|
|
23
|
+
import {REVDescription} from "../src/structs/REVDescription.sol";
|
|
24
|
+
import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
|
|
25
|
+
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
26
|
+
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
27
|
+
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
28
|
+
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
29
|
+
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
30
|
+
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
31
|
+
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
32
|
+
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
33
|
+
|
|
34
|
+
/// @notice A fake terminal that tracks whether useAllowanceOf was called.
|
|
35
|
+
/// @dev Used to prove H-6: REVLoans.borrowFrom does not validate source terminal registration.
|
|
36
|
+
contract FakeTerminal is ERC165, IJBPayoutTerminal {
|
|
37
|
+
bool public useAllowanceCalled;
|
|
38
|
+
uint256 public lastProjectId;
|
|
39
|
+
|
|
40
|
+
function useAllowanceOf(
|
|
41
|
+
uint256 projectId,
|
|
42
|
+
address,
|
|
43
|
+
uint256,
|
|
44
|
+
uint256,
|
|
45
|
+
uint256,
|
|
46
|
+
address payable,
|
|
47
|
+
address payable,
|
|
48
|
+
string calldata
|
|
49
|
+
)
|
|
50
|
+
external
|
|
51
|
+
override
|
|
52
|
+
returns (uint256)
|
|
53
|
+
{
|
|
54
|
+
useAllowanceCalled = true;
|
|
55
|
+
lastProjectId = projectId;
|
|
56
|
+
// Return 0 - no actual funds sent
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function accountingContextForTokenOf(uint256, address) external pure override returns (JBAccountingContext memory) {
|
|
61
|
+
return JBAccountingContext({
|
|
62
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Stub implementations for IJBTerminal
|
|
67
|
+
function accountingContextsOf(uint256) external pure override returns (JBAccountingContext[] memory) {
|
|
68
|
+
return new JBAccountingContext[](0);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function addAccountingContextsFor(uint256, JBAccountingContext[] calldata) external override {}
|
|
72
|
+
|
|
73
|
+
function addToBalanceOf(
|
|
74
|
+
uint256,
|
|
75
|
+
address,
|
|
76
|
+
uint256,
|
|
77
|
+
bool,
|
|
78
|
+
string calldata,
|
|
79
|
+
bytes calldata
|
|
80
|
+
)
|
|
81
|
+
external
|
|
82
|
+
payable
|
|
83
|
+
override
|
|
84
|
+
{}
|
|
85
|
+
|
|
86
|
+
function currentSurplusOf(
|
|
87
|
+
uint256,
|
|
88
|
+
JBAccountingContext[] memory,
|
|
89
|
+
uint256,
|
|
90
|
+
uint256
|
|
91
|
+
)
|
|
92
|
+
external
|
|
93
|
+
pure
|
|
94
|
+
override
|
|
95
|
+
returns (uint256)
|
|
96
|
+
{
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function migrateBalanceOf(uint256, address, IJBTerminal) external pure override returns (uint256) {
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function pay(
|
|
105
|
+
uint256,
|
|
106
|
+
address,
|
|
107
|
+
uint256,
|
|
108
|
+
address,
|
|
109
|
+
uint256,
|
|
110
|
+
string calldata,
|
|
111
|
+
bytes calldata
|
|
112
|
+
)
|
|
113
|
+
external
|
|
114
|
+
payable
|
|
115
|
+
override
|
|
116
|
+
returns (uint256)
|
|
117
|
+
{
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function sendPayoutsOf(uint256, address, uint256, uint256, uint256) external pure override returns (uint256) {
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function supportsInterface(bytes4 interfaceId) public view override(ERC165, IERC165) returns (bool) {
|
|
126
|
+
return interfaceId == type(IJBTerminal).interfaceId || interfaceId == type(IJBPayoutTerminal).interfaceId
|
|
127
|
+
|| super.supportsInterface(interfaceId);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// @notice Audit regression tests for REVLoans finding H-6: Unvalidated Source Terminal.
|
|
132
|
+
contract REVLoansAuditRegressions_Local is TestBaseWorkflow, JBTest {
|
|
133
|
+
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
134
|
+
bytes32 ERC20_SALT = "REV_TOKEN";
|
|
135
|
+
|
|
136
|
+
REVDeployer REV_DEPLOYER;
|
|
137
|
+
JB721TiersHook EXAMPLE_HOOK;
|
|
138
|
+
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
139
|
+
IJB721TiersHookStore HOOK_STORE;
|
|
140
|
+
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
141
|
+
IREVLoans LOANS_CONTRACT;
|
|
142
|
+
IJBSuckerRegistry SUCKER_REGISTRY;
|
|
143
|
+
CTPublisher PUBLISHER;
|
|
144
|
+
MockBuybackDataHook MOCK_BUYBACK;
|
|
145
|
+
|
|
146
|
+
uint256 FEE_PROJECT_ID;
|
|
147
|
+
uint256 REVNET_ID;
|
|
148
|
+
|
|
149
|
+
address USER = makeAddr("user");
|
|
150
|
+
|
|
151
|
+
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
152
|
+
|
|
153
|
+
function setUp() public override {
|
|
154
|
+
super.setUp();
|
|
155
|
+
|
|
156
|
+
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
157
|
+
|
|
158
|
+
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
159
|
+
HOOK_STORE = new JB721TiersHookStore();
|
|
160
|
+
EXAMPLE_HOOK = new JB721TiersHook(jbDirectory(), jbPermissions(), jbRulesets(), HOOK_STORE, multisig());
|
|
161
|
+
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
162
|
+
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
163
|
+
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
164
|
+
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
165
|
+
|
|
166
|
+
LOANS_CONTRACT = new REVLoans({
|
|
167
|
+
controller: jbController(),
|
|
168
|
+
projects: jbProjects(),
|
|
169
|
+
revId: FEE_PROJECT_ID,
|
|
170
|
+
owner: address(this),
|
|
171
|
+
permit2: permit2(),
|
|
172
|
+
trustedForwarder: TRUSTED_FORWARDER
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
176
|
+
jbController(),
|
|
177
|
+
SUCKER_REGISTRY,
|
|
178
|
+
FEE_PROJECT_ID,
|
|
179
|
+
HOOK_DEPLOYER,
|
|
180
|
+
PUBLISHER,
|
|
181
|
+
IJBRulesetDataHook(address(MOCK_BUYBACK)),
|
|
182
|
+
address(LOANS_CONTRACT),
|
|
183
|
+
TRUSTED_FORWARDER
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
vm.prank(multisig());
|
|
187
|
+
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
188
|
+
|
|
189
|
+
// Deploy a revnet with loans enabled
|
|
190
|
+
_deployRevnet();
|
|
191
|
+
|
|
192
|
+
// Give user ETH
|
|
193
|
+
vm.deal(USER, 100e18);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function _deployRevnet() internal {
|
|
197
|
+
JBAccountingContext[] memory accountingContextsToAccept = new JBAccountingContext[](1);
|
|
198
|
+
accountingContextsToAccept[0] = JBAccountingContext({
|
|
199
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
|
|
203
|
+
terminalConfigurations[0] =
|
|
204
|
+
JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: accountingContextsToAccept});
|
|
205
|
+
|
|
206
|
+
REVStageConfig[] memory stageConfigurations = new REVStageConfig[](1);
|
|
207
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
208
|
+
splits[0].beneficiary = payable(multisig());
|
|
209
|
+
splits[0].percent = 10_000;
|
|
210
|
+
|
|
211
|
+
stageConfigurations[0] = REVStageConfig({
|
|
212
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
213
|
+
autoIssuances: new REVAutoIssuance[](0),
|
|
214
|
+
splitPercent: 0,
|
|
215
|
+
splits: splits,
|
|
216
|
+
initialIssuance: uint112(1000e18),
|
|
217
|
+
issuanceCutFrequency: 0,
|
|
218
|
+
issuanceCutPercent: 0,
|
|
219
|
+
cashOutTaxRate: 5000,
|
|
220
|
+
extraMetadata: 0
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
REVConfig memory revnetConfiguration = REVConfig({
|
|
224
|
+
description: REVDescription("H6Test", "H6T", "ipfs://h6test", "H6_TOKEN"),
|
|
225
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
226
|
+
splitOperator: multisig(),
|
|
227
|
+
stageConfigurations: stageConfigurations
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
vm.prank(multisig());
|
|
231
|
+
REVNET_ID = REV_DEPLOYER.deployFor({
|
|
232
|
+
revnetId: FEE_PROJECT_ID,
|
|
233
|
+
configuration: revnetConfiguration,
|
|
234
|
+
terminalConfigurations: terminalConfigurations,
|
|
235
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
236
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("H6_TEST")
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
//*********************************************************************//
|
|
242
|
+
// --- [H-6] Unvalidated Source Terminal in REVLoans ---------------- //
|
|
243
|
+
//*********************************************************************//
|
|
244
|
+
|
|
245
|
+
/// @notice Demonstrates H-6: borrowFrom accepts any terminal without validating
|
|
246
|
+
/// it is registered in the JBDirectory for the project.
|
|
247
|
+
/// @dev The fake terminal's useAllowanceOf is called, proving no directory check occurs.
|
|
248
|
+
/// In production, a malicious terminal could return fake amounts or misroute funds.
|
|
249
|
+
function test_H6_unvalidatedSourceTerminal() public {
|
|
250
|
+
// Step 1: User pays into the revnet to get tokens (collateral)
|
|
251
|
+
vm.prank(USER);
|
|
252
|
+
uint256 tokens = jbMultiTerminal().pay{value: 1e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 1e18, USER, 0, "", "");
|
|
253
|
+
assertGt(tokens, 0, "user should receive tokens");
|
|
254
|
+
|
|
255
|
+
// Step 2: Create a fake terminal NOT registered in the directory
|
|
256
|
+
FakeTerminal fakeTerminal = new FakeTerminal();
|
|
257
|
+
|
|
258
|
+
// Verify the fake terminal is NOT in the directory
|
|
259
|
+
IJBTerminal[] memory registeredTerminals = jbDirectory().terminalsOf(REVNET_ID);
|
|
260
|
+
bool found = false;
|
|
261
|
+
for (uint256 i = 0; i < registeredTerminals.length; i++) {
|
|
262
|
+
if (address(registeredTerminals[i]) == address(fakeTerminal)) {
|
|
263
|
+
found = true;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
assertFalse(found, "fake terminal should NOT be in the directory");
|
|
267
|
+
|
|
268
|
+
// Step 3: Try to borrow using the fake terminal as the source
|
|
269
|
+
// H-6 vulnerability: REVLoans.borrowFrom does NOT check if the terminal
|
|
270
|
+
// is registered in the directory before calling useAllowanceOf on it.
|
|
271
|
+
REVLoanSource memory fakeSource =
|
|
272
|
+
REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: IJBPayoutTerminal(address(fakeTerminal))});
|
|
273
|
+
|
|
274
|
+
uint256 borrowable =
|
|
275
|
+
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
276
|
+
assertGt(borrowable, 0, "should have borrowable amount");
|
|
277
|
+
|
|
278
|
+
// H-6 PROOF: Use vm.expectCall to prove the fake terminal's useAllowanceOf
|
|
279
|
+
// is called. This works even if the outer call reverts, because expectCall
|
|
280
|
+
// records the call was made regardless.
|
|
281
|
+
// The code calls accountingContextForTokenOf first, then useAllowanceOf.
|
|
282
|
+
vm.expectCall(
|
|
283
|
+
address(fakeTerminal),
|
|
284
|
+
abi.encodeWithSelector(
|
|
285
|
+
IJBTerminal.accountingContextForTokenOf.selector, REVNET_ID, JBConstants.NATIVE_TOKEN
|
|
286
|
+
)
|
|
287
|
+
);
|
|
288
|
+
vm.expectCall(address(fakeTerminal), abi.encodeWithSelector(IJBPayoutTerminal.useAllowanceOf.selector));
|
|
289
|
+
|
|
290
|
+
// The borrow will reach the fake terminal (proving no validation),
|
|
291
|
+
// but will revert downstream when trying to transfer 0 - fees (underflow).
|
|
292
|
+
vm.prank(USER);
|
|
293
|
+
vm.expectRevert();
|
|
294
|
+
LOANS_CONTRACT.borrowFrom(REVNET_ID, fakeSource, borrowable, tokens, payable(USER), 500);
|
|
295
|
+
|
|
296
|
+
// If we reach here, both vm.expectCall checks passed:
|
|
297
|
+
// 1. accountingContextForTokenOf was called on the fake terminal
|
|
298
|
+
// 2. useAllowanceOf was called on the fake terminal
|
|
299
|
+
// This proves H-6: no directory validation before calling the source terminal
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/// @notice Verify that the configured loan source (real terminal) is properly registered.
|
|
303
|
+
function test_H6_configuredSourceIsRegistered() public {
|
|
304
|
+
// The real terminal should be in the directory
|
|
305
|
+
IJBTerminal[] memory terminals = jbDirectory().terminalsOf(REVNET_ID);
|
|
306
|
+
bool found = false;
|
|
307
|
+
for (uint256 i = 0; i < terminals.length; i++) {
|
|
308
|
+
if (address(terminals[i]) == address(jbMultiTerminal())) {
|
|
309
|
+
found = true;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
assertTrue(found, "real terminal should be in the directory");
|
|
313
|
+
}
|
|
314
|
+
}
|