@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,305 @@
|
|
|
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
|
+
import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
11
|
+
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
12
|
+
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
13
|
+
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
14
|
+
import "@bananapus/swap-terminal-v6/script/helpers/SwapTerminalDeploymentLib.sol";
|
|
15
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
16
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
17
|
+
import {MockPriceFeed} from "@bananapus/core-v6/test/mock/MockPriceFeed.sol";
|
|
18
|
+
import {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.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
|
+
|
|
33
|
+
/// @notice Tests proving that flash loan surplus manipulation is economically unprofitable (PR #12).
|
|
34
|
+
contract TestPR12_FlashLoanSurplus is TestBaseWorkflow, JBTest {
|
|
35
|
+
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
36
|
+
bytes32 ERC20_SALT = "REV_TOKEN";
|
|
37
|
+
|
|
38
|
+
REVDeployer REV_DEPLOYER;
|
|
39
|
+
JB721TiersHook EXAMPLE_HOOK;
|
|
40
|
+
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
41
|
+
IJB721TiersHookStore HOOK_STORE;
|
|
42
|
+
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
43
|
+
IREVLoans LOANS_CONTRACT;
|
|
44
|
+
MockERC20 TOKEN;
|
|
45
|
+
IJBSuckerRegistry SUCKER_REGISTRY;
|
|
46
|
+
CTPublisher PUBLISHER;
|
|
47
|
+
MockBuybackDataHook MOCK_BUYBACK;
|
|
48
|
+
|
|
49
|
+
uint256 FEE_PROJECT_ID;
|
|
50
|
+
uint256 REVNET_ID;
|
|
51
|
+
|
|
52
|
+
address USER = makeAddr("user");
|
|
53
|
+
address ATTACKER = makeAddr("attacker");
|
|
54
|
+
|
|
55
|
+
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
56
|
+
|
|
57
|
+
function setUp() public override {
|
|
58
|
+
super.setUp();
|
|
59
|
+
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
60
|
+
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
61
|
+
HOOK_STORE = new JB721TiersHookStore();
|
|
62
|
+
EXAMPLE_HOOK = new JB721TiersHook(jbDirectory(), jbPermissions(), jbRulesets(), HOOK_STORE, multisig());
|
|
63
|
+
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
64
|
+
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
65
|
+
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
66
|
+
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
67
|
+
TOKEN = new MockERC20("1/2 ETH", "1/2");
|
|
68
|
+
MockPriceFeed priceFeed = new MockPriceFeed(1e21, 6);
|
|
69
|
+
vm.prank(multisig());
|
|
70
|
+
jbPrices()
|
|
71
|
+
.addPriceFeedFor(0, uint32(uint160(address(TOKEN))), uint32(uint160(JBConstants.NATIVE_TOKEN)), priceFeed);
|
|
72
|
+
LOANS_CONTRACT = new REVLoans({
|
|
73
|
+
controller: jbController(),
|
|
74
|
+
projects: jbProjects(),
|
|
75
|
+
revId: FEE_PROJECT_ID,
|
|
76
|
+
owner: address(this),
|
|
77
|
+
permit2: permit2(),
|
|
78
|
+
trustedForwarder: TRUSTED_FORWARDER
|
|
79
|
+
});
|
|
80
|
+
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
81
|
+
jbController(),
|
|
82
|
+
SUCKER_REGISTRY,
|
|
83
|
+
FEE_PROJECT_ID,
|
|
84
|
+
HOOK_DEPLOYER,
|
|
85
|
+
PUBLISHER,
|
|
86
|
+
IJBRulesetDataHook(address(MOCK_BUYBACK)),
|
|
87
|
+
address(LOANS_CONTRACT),
|
|
88
|
+
TRUSTED_FORWARDER
|
|
89
|
+
);
|
|
90
|
+
vm.prank(multisig());
|
|
91
|
+
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
92
|
+
_deployFeeProject();
|
|
93
|
+
_deployRevnet();
|
|
94
|
+
vm.deal(USER, 1000e18);
|
|
95
|
+
vm.deal(ATTACKER, 1000e18);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function _deployFeeProject() internal {
|
|
99
|
+
JBAccountingContext[] memory acc = new JBAccountingContext[](2);
|
|
100
|
+
acc[0] = JBAccountingContext({
|
|
101
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
102
|
+
});
|
|
103
|
+
acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
|
|
104
|
+
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
105
|
+
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
106
|
+
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
107
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
108
|
+
splits[0].beneficiary = payable(multisig());
|
|
109
|
+
splits[0].percent = 10_000;
|
|
110
|
+
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
111
|
+
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
112
|
+
stages[0] = REVStageConfig({
|
|
113
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
114
|
+
autoIssuances: ai,
|
|
115
|
+
splitPercent: 2000,
|
|
116
|
+
splits: splits,
|
|
117
|
+
initialIssuance: uint112(1000e18),
|
|
118
|
+
issuanceCutFrequency: 90 days,
|
|
119
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
120
|
+
cashOutTaxRate: 6000,
|
|
121
|
+
extraMetadata: 0
|
|
122
|
+
});
|
|
123
|
+
REVConfig memory cfg = REVConfig({
|
|
124
|
+
description: REVDescription("Revnet", "$REV", "ipfs://test", "REV_TOKEN"),
|
|
125
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
126
|
+
splitOperator: multisig(),
|
|
127
|
+
stageConfigurations: stages
|
|
128
|
+
});
|
|
129
|
+
vm.prank(multisig());
|
|
130
|
+
REV_DEPLOYER.deployFor({
|
|
131
|
+
revnetId: FEE_PROJECT_ID,
|
|
132
|
+
configuration: cfg,
|
|
133
|
+
terminalConfigurations: tc,
|
|
134
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
135
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function _deployRevnet() internal {
|
|
141
|
+
JBAccountingContext[] memory acc = new JBAccountingContext[](2);
|
|
142
|
+
acc[0] = JBAccountingContext({
|
|
143
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
144
|
+
});
|
|
145
|
+
acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
|
|
146
|
+
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
147
|
+
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
148
|
+
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
149
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
150
|
+
splits[0].beneficiary = payable(multisig());
|
|
151
|
+
splits[0].percent = 10_000;
|
|
152
|
+
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
153
|
+
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
154
|
+
stages[0] = REVStageConfig({
|
|
155
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
156
|
+
autoIssuances: ai,
|
|
157
|
+
splitPercent: 2000,
|
|
158
|
+
splits: splits,
|
|
159
|
+
initialIssuance: uint112(1000e18),
|
|
160
|
+
issuanceCutFrequency: 90 days,
|
|
161
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
162
|
+
cashOutTaxRate: 6000,
|
|
163
|
+
extraMetadata: 0
|
|
164
|
+
});
|
|
165
|
+
REVLoanSource[] memory ls = new REVLoanSource[](1);
|
|
166
|
+
ls[0] = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
167
|
+
REVConfig memory cfg = REVConfig({
|
|
168
|
+
description: REVDescription("NANA", "$NANA", "ipfs://test2", "NANA_TOKEN"),
|
|
169
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
170
|
+
splitOperator: multisig(),
|
|
171
|
+
stageConfigurations: stages
|
|
172
|
+
});
|
|
173
|
+
REVNET_ID = REV_DEPLOYER.deployFor({
|
|
174
|
+
revnetId: 0,
|
|
175
|
+
configuration: cfg,
|
|
176
|
+
terminalConfigurations: tc,
|
|
177
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
178
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("NANA")
|
|
179
|
+
})
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function _setupLoan(
|
|
184
|
+
address user,
|
|
185
|
+
uint256 ethAmount,
|
|
186
|
+
uint256 prepaidFee
|
|
187
|
+
)
|
|
188
|
+
internal
|
|
189
|
+
returns (uint256 loanId, uint256 tokenCount, uint256 borrowAmount)
|
|
190
|
+
{
|
|
191
|
+
vm.prank(user);
|
|
192
|
+
tokenCount =
|
|
193
|
+
jbMultiTerminal().pay{value: ethAmount}(REVNET_ID, JBConstants.NATIVE_TOKEN, ethAmount, user, 0, "", "");
|
|
194
|
+
borrowAmount =
|
|
195
|
+
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokenCount, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
196
|
+
if (borrowAmount == 0) return (0, tokenCount, 0);
|
|
197
|
+
mockExpect(
|
|
198
|
+
address(jbPermissions()),
|
|
199
|
+
abi.encodeCall(IJBPermissions.hasPermission, (address(LOANS_CONTRACT), user, REVNET_ID, 11, true, true)),
|
|
200
|
+
abi.encode(true)
|
|
201
|
+
);
|
|
202
|
+
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
203
|
+
vm.prank(user);
|
|
204
|
+
(loanId,) = LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(user), prepaidFee);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/// @notice Donate ETH via addToBalanceOf, then borrow. The donation costs more than the extra borrowable amount.
|
|
208
|
+
function test_addToBalance_surplusInflation_unprofitable() public {
|
|
209
|
+
// First, user pays to establish baseline tokens
|
|
210
|
+
vm.prank(USER);
|
|
211
|
+
uint256 userTokens =
|
|
212
|
+
jbMultiTerminal().pay{value: 10e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 10e18, USER, 0, "", "");
|
|
213
|
+
|
|
214
|
+
// Check borrowable amount before donation
|
|
215
|
+
uint256 borrowableBefore =
|
|
216
|
+
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, userTokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
217
|
+
|
|
218
|
+
// Attacker donates 100 ETH to inflate surplus
|
|
219
|
+
uint256 donationAmount = 100e18;
|
|
220
|
+
vm.prank(ATTACKER);
|
|
221
|
+
jbMultiTerminal().addToBalanceOf{value: donationAmount}(
|
|
222
|
+
REVNET_ID, JBConstants.NATIVE_TOKEN, donationAmount, false, "", ""
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
// Check borrowable amount after donation
|
|
226
|
+
uint256 borrowableAfter =
|
|
227
|
+
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, userTokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
228
|
+
|
|
229
|
+
// The gain in borrowable amount
|
|
230
|
+
uint256 borrowableGain = borrowableAfter - borrowableBefore;
|
|
231
|
+
|
|
232
|
+
// The donation cost (100 ETH) is always more than the extra borrowable amount gained.
|
|
233
|
+
// Because borrowable = surplus * (collateralCount / totalSupply) * bonding_curve_factor,
|
|
234
|
+
// and collateralCount < totalSupply, so gain < donation.
|
|
235
|
+
assertGt(donationAmount, borrowableGain, "Donation should cost more than the extra borrowable amount gained");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/// @notice Pay into revnet (minting tokens). borrowable-per-existing-token should not increase because supply
|
|
239
|
+
/// dilution offsets surplus increase.
|
|
240
|
+
function test_pay_surplusInflation_neutral() public {
|
|
241
|
+
// User pays to get tokens
|
|
242
|
+
vm.prank(USER);
|
|
243
|
+
uint256 userTokens =
|
|
244
|
+
jbMultiTerminal().pay{value: 10e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 10e18, USER, 0, "", "");
|
|
245
|
+
|
|
246
|
+
// Check borrowable-per-token for existing user's tokens
|
|
247
|
+
uint256 borrowableBefore =
|
|
248
|
+
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, userTokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
249
|
+
|
|
250
|
+
// Someone else pays 100 ETH (this mints new tokens AND increases surplus)
|
|
251
|
+
address payer = makeAddr("payer");
|
|
252
|
+
vm.deal(payer, 100e18);
|
|
253
|
+
vm.prank(payer);
|
|
254
|
+
jbMultiTerminal().pay{value: 100e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 100e18, payer, 0, "", "");
|
|
255
|
+
|
|
256
|
+
// Check borrowable for the SAME user tokens after the payment
|
|
257
|
+
uint256 borrowableAfter =
|
|
258
|
+
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, userTokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
259
|
+
|
|
260
|
+
// With a non-zero cashOutTaxRate (concave bonding curve), paying in actually DECREASES
|
|
261
|
+
// the per-token borrowable amount for existing holders due to dilution.
|
|
262
|
+
// At minimum, it should not increase the per-token borrowable amount.
|
|
263
|
+
assertLe(borrowableAfter, borrowableBefore, "Paying in should not increase per-token borrowable amount");
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/// @notice Full attack simulation: donate, borrow max, verify net negative.
|
|
267
|
+
function test_flashLoanSimulation_netNegative() public {
|
|
268
|
+
// Attacker first buys tokens to have something to borrow against
|
|
269
|
+
vm.prank(ATTACKER);
|
|
270
|
+
uint256 attackerTokens =
|
|
271
|
+
jbMultiTerminal().pay{value: 10e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 10e18, ATTACKER, 0, "", "");
|
|
272
|
+
|
|
273
|
+
// Check borrowable before donation
|
|
274
|
+
uint256 borrowableBefore = LOANS_CONTRACT.borrowableAmountFrom(
|
|
275
|
+
REVNET_ID, attackerTokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
// Attacker donates 100 ETH to inflate surplus (simulating flash loan injection)
|
|
279
|
+
uint256 donationAmount = 100e18;
|
|
280
|
+
vm.prank(ATTACKER);
|
|
281
|
+
jbMultiTerminal().addToBalanceOf{value: donationAmount}(
|
|
282
|
+
REVNET_ID, JBConstants.NATIVE_TOKEN, donationAmount, false, "", ""
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Check borrowable after donation
|
|
286
|
+
uint256 borrowableAfter = LOANS_CONTRACT.borrowableAmountFrom(
|
|
287
|
+
REVNET_ID, attackerTokens, 18, uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
// Extra borrowable gained by the attacker through the donation
|
|
291
|
+
uint256 extraBorrowable = borrowableAfter - borrowableBefore;
|
|
292
|
+
|
|
293
|
+
// The attacker's net position:
|
|
294
|
+
// - Lost: donationAmount (100 ETH, permanently donated — no recovery mechanism)
|
|
295
|
+
// - Gained: extraBorrowable (the additional amount they can borrow)
|
|
296
|
+
// Net = extraBorrowable - donationAmount, which should be negative
|
|
297
|
+
assertGt(donationAmount, extraBorrowable, "Attack should be net negative: donation > extra borrowable");
|
|
298
|
+
|
|
299
|
+
// Furthermore, the extra borrowable is strictly less than donation because
|
|
300
|
+
// gain = donation * (collateral / totalSupply) * cashOutTaxRate_factor
|
|
301
|
+
// and collateral < totalSupply, so the multiplier is always < 1
|
|
302
|
+
// This means the attacker loses a significant fraction of their flash loan
|
|
303
|
+
assertTrue(extraBorrowable < donationAmount, "Extra borrowable must be strictly less than donation");
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -0,0 +1,302 @@
|
|
|
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
|
+
import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
11
|
+
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
12
|
+
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
13
|
+
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
14
|
+
import "@bananapus/swap-terminal-v6/script/helpers/SwapTerminalDeploymentLib.sol";
|
|
15
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
16
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
17
|
+
import {MockPriceFeed} from "@bananapus/core-v6/test/mock/MockPriceFeed.sol";
|
|
18
|
+
import {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.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
|
+
|
|
33
|
+
/// @notice Tests for PR #13: cross-source reallocation prevention.
|
|
34
|
+
contract TestPR13_CrossSourceReallocation is TestBaseWorkflow, JBTest {
|
|
35
|
+
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
36
|
+
|
|
37
|
+
REVDeployer REV_DEPLOYER;
|
|
38
|
+
JB721TiersHook EXAMPLE_HOOK;
|
|
39
|
+
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
40
|
+
IJB721TiersHookStore HOOK_STORE;
|
|
41
|
+
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
42
|
+
IREVLoans LOANS_CONTRACT;
|
|
43
|
+
MockERC20 TOKEN;
|
|
44
|
+
IJBSuckerRegistry SUCKER_REGISTRY;
|
|
45
|
+
CTPublisher PUBLISHER;
|
|
46
|
+
MockBuybackDataHook MOCK_BUYBACK;
|
|
47
|
+
|
|
48
|
+
uint256 FEE_PROJECT_ID;
|
|
49
|
+
uint256 REVNET_ID;
|
|
50
|
+
|
|
51
|
+
address USER = makeAddr("user");
|
|
52
|
+
|
|
53
|
+
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
54
|
+
|
|
55
|
+
function setUp() public override {
|
|
56
|
+
super.setUp();
|
|
57
|
+
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
58
|
+
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
59
|
+
HOOK_STORE = new JB721TiersHookStore();
|
|
60
|
+
EXAMPLE_HOOK = new JB721TiersHook(jbDirectory(), jbPermissions(), jbRulesets(), HOOK_STORE, multisig());
|
|
61
|
+
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
62
|
+
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
63
|
+
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
64
|
+
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
65
|
+
TOKEN = new MockERC20("1/2 ETH", "1/2");
|
|
66
|
+
MockPriceFeed priceFeed = new MockPriceFeed(1e21, 6);
|
|
67
|
+
vm.prank(multisig());
|
|
68
|
+
jbPrices()
|
|
69
|
+
.addPriceFeedFor(0, uint32(uint160(address(TOKEN))), uint32(uint160(JBConstants.NATIVE_TOKEN)), priceFeed);
|
|
70
|
+
LOANS_CONTRACT = new REVLoans({
|
|
71
|
+
controller: jbController(),
|
|
72
|
+
projects: jbProjects(),
|
|
73
|
+
revId: FEE_PROJECT_ID,
|
|
74
|
+
owner: address(this),
|
|
75
|
+
permit2: permit2(),
|
|
76
|
+
trustedForwarder: TRUSTED_FORWARDER
|
|
77
|
+
});
|
|
78
|
+
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
79
|
+
jbController(),
|
|
80
|
+
SUCKER_REGISTRY,
|
|
81
|
+
FEE_PROJECT_ID,
|
|
82
|
+
HOOK_DEPLOYER,
|
|
83
|
+
PUBLISHER,
|
|
84
|
+
IJBRulesetDataHook(address(MOCK_BUYBACK)),
|
|
85
|
+
address(LOANS_CONTRACT),
|
|
86
|
+
TRUSTED_FORWARDER
|
|
87
|
+
);
|
|
88
|
+
vm.prank(multisig());
|
|
89
|
+
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
90
|
+
_deployFeeProject();
|
|
91
|
+
_deployRevnet();
|
|
92
|
+
vm.deal(USER, 1000e18);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function _deployFeeProject() internal {
|
|
96
|
+
JBAccountingContext[] memory acc = new JBAccountingContext[](2);
|
|
97
|
+
acc[0] = JBAccountingContext({
|
|
98
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
99
|
+
});
|
|
100
|
+
acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
|
|
101
|
+
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
102
|
+
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
103
|
+
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
104
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
105
|
+
splits[0].beneficiary = payable(multisig());
|
|
106
|
+
splits[0].percent = 10_000;
|
|
107
|
+
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
108
|
+
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
109
|
+
stages[0] = REVStageConfig({
|
|
110
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
111
|
+
autoIssuances: ai,
|
|
112
|
+
splitPercent: 2000,
|
|
113
|
+
splits: splits,
|
|
114
|
+
initialIssuance: uint112(1000e18),
|
|
115
|
+
issuanceCutFrequency: 90 days,
|
|
116
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
117
|
+
cashOutTaxRate: 6000,
|
|
118
|
+
extraMetadata: 0
|
|
119
|
+
});
|
|
120
|
+
REVConfig memory cfg = REVConfig({
|
|
121
|
+
description: REVDescription("Revnet", "$REV", "ipfs://test", "REV_TOKEN"),
|
|
122
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
123
|
+
splitOperator: multisig(),
|
|
124
|
+
stageConfigurations: stages
|
|
125
|
+
});
|
|
126
|
+
vm.prank(multisig());
|
|
127
|
+
REV_DEPLOYER.deployFor({
|
|
128
|
+
revnetId: FEE_PROJECT_ID,
|
|
129
|
+
configuration: cfg,
|
|
130
|
+
terminalConfigurations: tc,
|
|
131
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
132
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function _deployRevnet() internal {
|
|
138
|
+
JBAccountingContext[] memory acc = new JBAccountingContext[](2);
|
|
139
|
+
acc[0] = JBAccountingContext({
|
|
140
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
141
|
+
});
|
|
142
|
+
acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
|
|
143
|
+
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
144
|
+
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
145
|
+
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
146
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
147
|
+
splits[0].beneficiary = payable(multisig());
|
|
148
|
+
splits[0].percent = 10_000;
|
|
149
|
+
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
150
|
+
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
151
|
+
stages[0] = REVStageConfig({
|
|
152
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
153
|
+
autoIssuances: ai,
|
|
154
|
+
splitPercent: 2000,
|
|
155
|
+
splits: splits,
|
|
156
|
+
initialIssuance: uint112(1000e18),
|
|
157
|
+
issuanceCutFrequency: 90 days,
|
|
158
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
159
|
+
cashOutTaxRate: 6000,
|
|
160
|
+
extraMetadata: 0
|
|
161
|
+
});
|
|
162
|
+
REVLoanSource[] memory ls = new REVLoanSource[](1);
|
|
163
|
+
ls[0] = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
164
|
+
REVConfig memory cfg = REVConfig({
|
|
165
|
+
description: REVDescription("NANA", "$NANA", "ipfs://test2", "NANA_TOKEN"),
|
|
166
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
167
|
+
splitOperator: multisig(),
|
|
168
|
+
stageConfigurations: stages
|
|
169
|
+
});
|
|
170
|
+
REVNET_ID = REV_DEPLOYER.deployFor({
|
|
171
|
+
revnetId: 0,
|
|
172
|
+
configuration: cfg,
|
|
173
|
+
terminalConfigurations: tc,
|
|
174
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
175
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("NANA")
|
|
176
|
+
})
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function _setupLoan(
|
|
181
|
+
address user,
|
|
182
|
+
uint256 ethAmount,
|
|
183
|
+
uint256 prepaidFee
|
|
184
|
+
)
|
|
185
|
+
internal
|
|
186
|
+
returns (uint256 loanId, uint256 tokenCount, uint256 borrowAmount)
|
|
187
|
+
{
|
|
188
|
+
vm.prank(user);
|
|
189
|
+
tokenCount =
|
|
190
|
+
jbMultiTerminal().pay{value: ethAmount}(REVNET_ID, JBConstants.NATIVE_TOKEN, ethAmount, user, 0, "", "");
|
|
191
|
+
borrowAmount =
|
|
192
|
+
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokenCount, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
193
|
+
if (borrowAmount == 0) return (0, tokenCount, 0);
|
|
194
|
+
mockExpect(
|
|
195
|
+
address(jbPermissions()),
|
|
196
|
+
abi.encodeCall(IJBPermissions.hasPermission, (address(LOANS_CONTRACT), user, REVNET_ID, 11, true, true)),
|
|
197
|
+
abi.encode(true)
|
|
198
|
+
);
|
|
199
|
+
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
200
|
+
vm.prank(user);
|
|
201
|
+
(loanId,) = LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(user), prepaidFee);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/// @notice Reallocating with the same source (token + terminal) should succeed.
|
|
205
|
+
function test_reallocateWithSameSource_succeeds() public {
|
|
206
|
+
// Setup: user pays and borrows
|
|
207
|
+
(uint256 loanId, uint256 tokenCount,) = _setupLoan(USER, 10e18, 25);
|
|
208
|
+
require(loanId != 0, "Loan setup failed");
|
|
209
|
+
|
|
210
|
+
// Donate a large amount to inflate surplus, making each collateral token worth significantly more.
|
|
211
|
+
// This ensures that after removing some collateral, the remaining collateral still supports the loan amount.
|
|
212
|
+
address donor = makeAddr("donor");
|
|
213
|
+
vm.deal(donor, 500e18);
|
|
214
|
+
vm.prank(donor);
|
|
215
|
+
jbMultiTerminal().addToBalanceOf{value: 500e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 500e18, false, "", "");
|
|
216
|
+
|
|
217
|
+
// User pays more to get additional tokens for the new loan's extra collateral
|
|
218
|
+
vm.prank(USER);
|
|
219
|
+
uint256 extraTokens =
|
|
220
|
+
jbMultiTerminal().pay{value: 50e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 50e18, USER, 0, "", "");
|
|
221
|
+
|
|
222
|
+
// Transfer a small portion of collateral so the remaining collateral (now worth much more) supports the loan
|
|
223
|
+
uint256 collateralToTransfer = tokenCount / 10; // Transfer 10% of collateral
|
|
224
|
+
|
|
225
|
+
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
226
|
+
|
|
227
|
+
// Mock burn permission for the new loan's borrowFrom call
|
|
228
|
+
mockExpect(
|
|
229
|
+
address(jbPermissions()),
|
|
230
|
+
abi.encodeCall(IJBPermissions.hasPermission, (address(LOANS_CONTRACT), USER, REVNET_ID, 11, true, true)),
|
|
231
|
+
abi.encode(true)
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
vm.prank(USER);
|
|
235
|
+
(uint256 reallocatedLoanId, uint256 newLoanId,,) = LOANS_CONTRACT.reallocateCollateralFromLoan(
|
|
236
|
+
loanId,
|
|
237
|
+
collateralToTransfer,
|
|
238
|
+
source,
|
|
239
|
+
0, // minBorrowAmount
|
|
240
|
+
extraTokens, // collateralCountToAdd
|
|
241
|
+
payable(USER),
|
|
242
|
+
25 // prepaidFeePercent
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
// Verify both loans exist
|
|
246
|
+
assertTrue(reallocatedLoanId != 0, "Reallocated loan should exist");
|
|
247
|
+
assertTrue(newLoanId != 0, "New loan should exist");
|
|
248
|
+
|
|
249
|
+
// Verify new loan has correct source
|
|
250
|
+
REVLoan memory newLoan = LOANS_CONTRACT.loanOf(newLoanId);
|
|
251
|
+
assertEq(newLoan.source.token, JBConstants.NATIVE_TOKEN, "New loan source token should match");
|
|
252
|
+
assertEq(address(newLoan.source.terminal), address(jbMultiTerminal()), "New loan source terminal should match");
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/// @notice Reallocating with a different token should revert with SourceMismatch.
|
|
256
|
+
function test_reallocateWithDifferentToken_reverts() public {
|
|
257
|
+
// Setup: user pays and borrows with NATIVE_TOKEN source
|
|
258
|
+
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
259
|
+
require(loanId != 0, "Loan setup failed");
|
|
260
|
+
|
|
261
|
+
// Try to reallocate with a different token (TOKEN instead of NATIVE_TOKEN)
|
|
262
|
+
REVLoanSource memory wrongSource = REVLoanSource({token: address(TOKEN), terminal: jbMultiTerminal()});
|
|
263
|
+
|
|
264
|
+
vm.prank(USER);
|
|
265
|
+
vm.expectRevert(REVLoans.REVLoans_SourceMismatch.selector);
|
|
266
|
+
LOANS_CONTRACT.reallocateCollateralFromLoan(
|
|
267
|
+
loanId,
|
|
268
|
+
1, // collateralCountToTransfer (any nonzero value)
|
|
269
|
+
wrongSource,
|
|
270
|
+
0, // minBorrowAmount
|
|
271
|
+
0, // collateralCountToAdd
|
|
272
|
+
payable(USER),
|
|
273
|
+
25 // prepaidFeePercent
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/// @notice Reallocating with a different terminal should revert with SourceMismatch.
|
|
278
|
+
function test_reallocateWithDifferentTerminal_reverts() public {
|
|
279
|
+
// Setup: user pays and borrows with jbMultiTerminal
|
|
280
|
+
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
281
|
+
require(loanId != 0, "Loan setup failed");
|
|
282
|
+
|
|
283
|
+
// Create a fake terminal address
|
|
284
|
+
address fakeTerminal = makeAddr("fakeTerminal");
|
|
285
|
+
|
|
286
|
+
// Try to reallocate with a different terminal
|
|
287
|
+
REVLoanSource memory wrongSource =
|
|
288
|
+
REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: IJBPayoutTerminal(fakeTerminal)});
|
|
289
|
+
|
|
290
|
+
vm.prank(USER);
|
|
291
|
+
vm.expectRevert(REVLoans.REVLoans_SourceMismatch.selector);
|
|
292
|
+
LOANS_CONTRACT.reallocateCollateralFromLoan(
|
|
293
|
+
loanId,
|
|
294
|
+
1, // collateralCountToTransfer
|
|
295
|
+
wrongSource,
|
|
296
|
+
0, // minBorrowAmount
|
|
297
|
+
0, // collateralCountToAdd
|
|
298
|
+
payable(USER),
|
|
299
|
+
25 // prepaidFeePercent
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
}
|