@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,320 @@
|
|
|
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
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
17
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
18
|
+
import {MockPriceFeed} from "@bananapus/core-v6/test/mock/MockPriceFeed.sol";
|
|
19
|
+
import {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.sol";
|
|
20
|
+
import {REVLoans} from "../src/REVLoans.sol";
|
|
21
|
+
import {REVLoan} from "../src/structs/REVLoan.sol";
|
|
22
|
+
import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
|
|
23
|
+
import {REVLoanSource} from "../src/structs/REVLoanSource.sol";
|
|
24
|
+
import {REVDescription} from "../src/structs/REVDescription.sol";
|
|
25
|
+
import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
|
|
26
|
+
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
27
|
+
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
28
|
+
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
29
|
+
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
30
|
+
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
31
|
+
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
32
|
+
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
33
|
+
|
|
34
|
+
struct FeeProjectConfig {
|
|
35
|
+
REVConfig configuration;
|
|
36
|
+
JBTerminalConfig[] terminalConfigurations;
|
|
37
|
+
REVSuckerDeploymentConfig suckerDeploymentConfiguration;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
contract TestPR15_CashOutCallerValidation is TestBaseWorkflow, JBTest {
|
|
41
|
+
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
42
|
+
bytes32 ERC20_SALT = "REV_TOKEN";
|
|
43
|
+
|
|
44
|
+
REVDeployer REV_DEPLOYER;
|
|
45
|
+
JB721TiersHook EXAMPLE_HOOK;
|
|
46
|
+
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
47
|
+
IJB721TiersHookStore HOOK_STORE;
|
|
48
|
+
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
49
|
+
IREVLoans LOANS_CONTRACT;
|
|
50
|
+
MockERC20 TOKEN;
|
|
51
|
+
IJBSuckerRegistry SUCKER_REGISTRY;
|
|
52
|
+
CTPublisher PUBLISHER;
|
|
53
|
+
MockBuybackDataHook MOCK_BUYBACK;
|
|
54
|
+
|
|
55
|
+
uint256 FEE_PROJECT_ID;
|
|
56
|
+
uint256 REVNET_ID;
|
|
57
|
+
|
|
58
|
+
address USER = makeAddr("user");
|
|
59
|
+
address RANDOM_CALLER = makeAddr("randomCaller");
|
|
60
|
+
|
|
61
|
+
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
62
|
+
|
|
63
|
+
function getFeeProjectConfig() internal view returns (FeeProjectConfig memory) {
|
|
64
|
+
string memory name = "Revnet";
|
|
65
|
+
string memory symbol = "$REV";
|
|
66
|
+
string memory projectUri = "ipfs://QmNRHT91HcDgMcenebYX7rJigt77cgNcosvuhX21wkF3tx";
|
|
67
|
+
uint8 decimals = 18;
|
|
68
|
+
uint256 decimalMultiplier = 10 ** decimals;
|
|
69
|
+
|
|
70
|
+
JBAccountingContext[] memory accountingContextsToAccept = new JBAccountingContext[](1);
|
|
71
|
+
accountingContextsToAccept[0] = JBAccountingContext({
|
|
72
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
|
|
76
|
+
terminalConfigurations[0] =
|
|
77
|
+
JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: accountingContextsToAccept});
|
|
78
|
+
|
|
79
|
+
REVStageConfig[] memory stageConfigurations = new REVStageConfig[](1);
|
|
80
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
81
|
+
splits[0].beneficiary = payable(multisig());
|
|
82
|
+
splits[0].percent = 10_000;
|
|
83
|
+
|
|
84
|
+
{
|
|
85
|
+
REVAutoIssuance[] memory issuanceConfs = new REVAutoIssuance[](0);
|
|
86
|
+
stageConfigurations[0] = REVStageConfig({
|
|
87
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
88
|
+
autoIssuances: issuanceConfs,
|
|
89
|
+
splitPercent: 2000,
|
|
90
|
+
splits: splits,
|
|
91
|
+
initialIssuance: uint112(1000 * decimalMultiplier),
|
|
92
|
+
issuanceCutFrequency: 90 days,
|
|
93
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
94
|
+
cashOutTaxRate: 6000,
|
|
95
|
+
extraMetadata: 0
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
REVLoanSource[] memory loanSources = new REVLoanSource[](0);
|
|
100
|
+
|
|
101
|
+
REVConfig memory revnetConfiguration = REVConfig({
|
|
102
|
+
description: REVDescription(name, symbol, projectUri, ERC20_SALT),
|
|
103
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
104
|
+
splitOperator: multisig(),
|
|
105
|
+
stageConfigurations: stageConfigurations
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return FeeProjectConfig({
|
|
109
|
+
configuration: revnetConfiguration,
|
|
110
|
+
terminalConfigurations: terminalConfigurations,
|
|
111
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
112
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("REV"))
|
|
113
|
+
})
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function getRevnetConfig() internal view returns (FeeProjectConfig memory) {
|
|
118
|
+
string memory name = "NANA";
|
|
119
|
+
string memory symbol = "$NANA";
|
|
120
|
+
string memory projectUri = "ipfs://QmNRHT91HcDgMcenebYX7rJigt77cgNxosvuhX21wkF3tx";
|
|
121
|
+
uint8 decimals = 18;
|
|
122
|
+
uint256 decimalMultiplier = 10 ** decimals;
|
|
123
|
+
|
|
124
|
+
JBAccountingContext[] memory accountingContextsToAccept = new JBAccountingContext[](1);
|
|
125
|
+
accountingContextsToAccept[0] = JBAccountingContext({
|
|
126
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
|
|
130
|
+
terminalConfigurations[0] =
|
|
131
|
+
JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: accountingContextsToAccept});
|
|
132
|
+
|
|
133
|
+
REVStageConfig[] memory stageConfigurations = new REVStageConfig[](1);
|
|
134
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
135
|
+
splits[0].beneficiary = payable(multisig());
|
|
136
|
+
splits[0].percent = 10_000;
|
|
137
|
+
|
|
138
|
+
{
|
|
139
|
+
REVAutoIssuance[] memory issuanceConfs = new REVAutoIssuance[](0);
|
|
140
|
+
stageConfigurations[0] = REVStageConfig({
|
|
141
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
142
|
+
autoIssuances: issuanceConfs,
|
|
143
|
+
splitPercent: 2000,
|
|
144
|
+
splits: splits,
|
|
145
|
+
initialIssuance: uint112(1000 * decimalMultiplier),
|
|
146
|
+
issuanceCutFrequency: 90 days,
|
|
147
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
148
|
+
cashOutTaxRate: 3000,
|
|
149
|
+
extraMetadata: 0
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
REVLoanSource[] memory loanSources = new REVLoanSource[](1);
|
|
154
|
+
loanSources[0] = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
155
|
+
|
|
156
|
+
REVConfig memory revnetConfiguration = REVConfig({
|
|
157
|
+
description: REVDescription(name, symbol, projectUri, "NANA_TOKEN"),
|
|
158
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
159
|
+
splitOperator: multisig(),
|
|
160
|
+
stageConfigurations: stageConfigurations
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return FeeProjectConfig({
|
|
164
|
+
configuration: revnetConfiguration,
|
|
165
|
+
terminalConfigurations: terminalConfigurations,
|
|
166
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
167
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("NANA"))
|
|
168
|
+
})
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function setUp() public override {
|
|
173
|
+
super.setUp();
|
|
174
|
+
|
|
175
|
+
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
176
|
+
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
177
|
+
HOOK_STORE = new JB721TiersHookStore();
|
|
178
|
+
EXAMPLE_HOOK = new JB721TiersHook(jbDirectory(), jbPermissions(), jbRulesets(), HOOK_STORE, multisig());
|
|
179
|
+
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
180
|
+
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
181
|
+
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
182
|
+
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
183
|
+
TOKEN = new MockERC20("1/2 ETH", "1/2");
|
|
184
|
+
|
|
185
|
+
LOANS_CONTRACT = new REVLoans({
|
|
186
|
+
controller: jbController(),
|
|
187
|
+
projects: jbProjects(),
|
|
188
|
+
revId: FEE_PROJECT_ID,
|
|
189
|
+
owner: address(this),
|
|
190
|
+
permit2: permit2(),
|
|
191
|
+
trustedForwarder: TRUSTED_FORWARDER
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
195
|
+
jbController(),
|
|
196
|
+
SUCKER_REGISTRY,
|
|
197
|
+
FEE_PROJECT_ID,
|
|
198
|
+
HOOK_DEPLOYER,
|
|
199
|
+
PUBLISHER,
|
|
200
|
+
IJBRulesetDataHook(address(MOCK_BUYBACK)),
|
|
201
|
+
address(LOANS_CONTRACT),
|
|
202
|
+
TRUSTED_FORWARDER
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
// Approve the deployer to configure the fee project.
|
|
206
|
+
vm.prank(multisig());
|
|
207
|
+
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
208
|
+
|
|
209
|
+
// Deploy the fee project.
|
|
210
|
+
FeeProjectConfig memory feeProjectConfig = getFeeProjectConfig();
|
|
211
|
+
vm.prank(multisig());
|
|
212
|
+
REV_DEPLOYER.deployFor({
|
|
213
|
+
revnetId: FEE_PROJECT_ID,
|
|
214
|
+
configuration: feeProjectConfig.configuration,
|
|
215
|
+
terminalConfigurations: feeProjectConfig.terminalConfigurations,
|
|
216
|
+
suckerDeploymentConfiguration: feeProjectConfig.suckerDeploymentConfiguration
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Deploy the revnet.
|
|
220
|
+
FeeProjectConfig memory revnetConfig = getRevnetConfig();
|
|
221
|
+
REVNET_ID = REV_DEPLOYER.deployFor({
|
|
222
|
+
revnetId: 0,
|
|
223
|
+
configuration: revnetConfig.configuration,
|
|
224
|
+
terminalConfigurations: revnetConfig.terminalConfigurations,
|
|
225
|
+
suckerDeploymentConfiguration: revnetConfig.suckerDeploymentConfiguration
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
vm.deal(USER, 100 ether);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/// @notice Test that a normal cash out flow processes fees correctly to the fee project.
|
|
232
|
+
function test_normalCashOutFlow_feeProcessedCorrectly() public {
|
|
233
|
+
// Pay ETH into revnet to get tokens.
|
|
234
|
+
vm.prank(USER);
|
|
235
|
+
uint256 tokenCount =
|
|
236
|
+
jbMultiTerminal().pay{value: 10 ether}(REVNET_ID, JBConstants.NATIVE_TOKEN, 10 ether, USER, 0, "", "");
|
|
237
|
+
assertGt(tokenCount, 0, "Should have received tokens");
|
|
238
|
+
|
|
239
|
+
// Record fee project balance before cash out.
|
|
240
|
+
uint256 feeProjectBalanceBefore =
|
|
241
|
+
jbTerminalStore().balanceOf(address(jbMultiTerminal()), REVNET_ID, JBConstants.NATIVE_TOKEN);
|
|
242
|
+
assertGt(feeProjectBalanceBefore, 0, "Revnet should have balance");
|
|
243
|
+
|
|
244
|
+
// Warp past CASH_OUT_DELAY.
|
|
245
|
+
uint256 delay = REV_DEPLOYER.CASH_OUT_DELAY();
|
|
246
|
+
vm.warp(block.timestamp + delay + 1);
|
|
247
|
+
|
|
248
|
+
// Record fee project terminal balance before.
|
|
249
|
+
uint256 feeBalanceBefore =
|
|
250
|
+
jbTerminalStore().balanceOf(address(jbMultiTerminal()), FEE_PROJECT_ID, JBConstants.NATIVE_TOKEN);
|
|
251
|
+
|
|
252
|
+
// Cash out tokens.
|
|
253
|
+
vm.prank(USER);
|
|
254
|
+
uint256 reclaimed = jbMultiTerminal()
|
|
255
|
+
.cashOutTokensOf({
|
|
256
|
+
holder: USER,
|
|
257
|
+
projectId: REVNET_ID,
|
|
258
|
+
cashOutCount: tokenCount,
|
|
259
|
+
tokenToReclaim: JBConstants.NATIVE_TOKEN,
|
|
260
|
+
minTokensReclaimed: 0,
|
|
261
|
+
beneficiary: payable(USER),
|
|
262
|
+
metadata: ""
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
assertGt(reclaimed, 0, "Should have reclaimed some ETH");
|
|
266
|
+
|
|
267
|
+
// Verify fee project balance increased (it received the fee).
|
|
268
|
+
uint256 feeBalanceAfter =
|
|
269
|
+
jbTerminalStore().balanceOf(address(jbMultiTerminal()), FEE_PROJECT_ID, JBConstants.NATIVE_TOKEN);
|
|
270
|
+
assertGt(feeBalanceAfter, feeBalanceBefore, "Fee project balance should increase from cash out fee");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/// @notice Test that afterCashOutRecordedWith has no access control — anyone can call it.
|
|
274
|
+
/// A non-terminal caller would just be donating their own funds as fees.
|
|
275
|
+
function test_nonTerminalCaller_justDonatesOwnFunds() public {
|
|
276
|
+
// Fund the random caller with ETH.
|
|
277
|
+
vm.deal(RANDOM_CALLER, 10 ether);
|
|
278
|
+
|
|
279
|
+
// Build a minimal JBAfterCashOutRecordedContext.
|
|
280
|
+
// The key point: afterCashOutRecordedWith does NOT check msg.sender against any terminal registry.
|
|
281
|
+
// If a non-terminal calls it with native ETH, the ETH just goes to the fee project as a donation.
|
|
282
|
+
JBAfterCashOutRecordedContext memory context = JBAfterCashOutRecordedContext({
|
|
283
|
+
holder: RANDOM_CALLER,
|
|
284
|
+
projectId: REVNET_ID,
|
|
285
|
+
rulesetId: 0,
|
|
286
|
+
cashOutCount: 0,
|
|
287
|
+
reclaimedAmount: JBTokenAmount({
|
|
288
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
289
|
+
decimals: 18,
|
|
290
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
291
|
+
value: 0
|
|
292
|
+
}),
|
|
293
|
+
forwardedAmount: JBTokenAmount({
|
|
294
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
295
|
+
decimals: 18,
|
|
296
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
297
|
+
value: 1 ether
|
|
298
|
+
}),
|
|
299
|
+
cashOutTaxRate: 0,
|
|
300
|
+
beneficiary: payable(RANDOM_CALLER),
|
|
301
|
+
hookMetadata: abi.encode(jbMultiTerminal()),
|
|
302
|
+
cashOutMetadata: ""
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
// Record fee project balance before.
|
|
306
|
+
uint256 feeBalanceBefore =
|
|
307
|
+
jbTerminalStore().balanceOf(address(jbMultiTerminal()), FEE_PROJECT_ID, JBConstants.NATIVE_TOKEN);
|
|
308
|
+
|
|
309
|
+
// Call afterCashOutRecordedWith from a random (non-terminal) address.
|
|
310
|
+
// This should NOT revert with any authorization error.
|
|
311
|
+
// The caller sends ETH which gets paid as a fee to the fee project.
|
|
312
|
+
vm.prank(RANDOM_CALLER);
|
|
313
|
+
REV_DEPLOYER.afterCashOutRecordedWith{value: 1 ether}(context);
|
|
314
|
+
|
|
315
|
+
// Verify the fee project received the ETH (donation).
|
|
316
|
+
uint256 feeBalanceAfter =
|
|
317
|
+
jbTerminalStore().balanceOf(address(jbMultiTerminal()), FEE_PROJECT_ID, JBConstants.NATIVE_TOKEN);
|
|
318
|
+
assertGt(feeBalanceAfter, feeBalanceBefore, "Fee project should receive the donated ETH");
|
|
319
|
+
}
|
|
320
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
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 {JBSingleAllowance} from "@bananapus/core-v6/src/structs/JBSingleAllowance.sol";
|
|
18
|
+
import {MockPriceFeed} from "@bananapus/core-v6/test/mock/MockPriceFeed.sol";
|
|
19
|
+
import {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.sol";
|
|
20
|
+
import {REVLoans} from "../src/REVLoans.sol";
|
|
21
|
+
import {REVLoan} from "../src/structs/REVLoan.sol";
|
|
22
|
+
import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
|
|
23
|
+
import {REVLoanSource} from "../src/structs/REVLoanSource.sol";
|
|
24
|
+
import {REVDescription} from "../src/structs/REVDescription.sol";
|
|
25
|
+
import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
|
|
26
|
+
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
27
|
+
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
28
|
+
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
29
|
+
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
30
|
+
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
31
|
+
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
32
|
+
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
33
|
+
|
|
34
|
+
/// @notice Tests for PR #16: zero repayment prevention.
|
|
35
|
+
contract TestPR16_ZeroRepayment is TestBaseWorkflow, JBTest {
|
|
36
|
+
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
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
|
+
|
|
54
|
+
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
55
|
+
|
|
56
|
+
function setUp() public override {
|
|
57
|
+
super.setUp();
|
|
58
|
+
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
59
|
+
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
60
|
+
HOOK_STORE = new JB721TiersHookStore();
|
|
61
|
+
EXAMPLE_HOOK = new JB721TiersHook(jbDirectory(), jbPermissions(), jbRulesets(), HOOK_STORE, multisig());
|
|
62
|
+
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
63
|
+
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
64
|
+
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
65
|
+
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
66
|
+
TOKEN = new MockERC20("1/2 ETH", "1/2");
|
|
67
|
+
MockPriceFeed priceFeed = new MockPriceFeed(1e21, 6);
|
|
68
|
+
vm.prank(multisig());
|
|
69
|
+
jbPrices()
|
|
70
|
+
.addPriceFeedFor(0, uint32(uint160(address(TOKEN))), uint32(uint160(JBConstants.NATIVE_TOKEN)), priceFeed);
|
|
71
|
+
LOANS_CONTRACT = new REVLoans({
|
|
72
|
+
controller: jbController(),
|
|
73
|
+
projects: jbProjects(),
|
|
74
|
+
revId: FEE_PROJECT_ID,
|
|
75
|
+
owner: address(this),
|
|
76
|
+
permit2: permit2(),
|
|
77
|
+
trustedForwarder: TRUSTED_FORWARDER
|
|
78
|
+
});
|
|
79
|
+
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
80
|
+
jbController(),
|
|
81
|
+
SUCKER_REGISTRY,
|
|
82
|
+
FEE_PROJECT_ID,
|
|
83
|
+
HOOK_DEPLOYER,
|
|
84
|
+
PUBLISHER,
|
|
85
|
+
IJBRulesetDataHook(address(MOCK_BUYBACK)),
|
|
86
|
+
address(LOANS_CONTRACT),
|
|
87
|
+
TRUSTED_FORWARDER
|
|
88
|
+
);
|
|
89
|
+
vm.prank(multisig());
|
|
90
|
+
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
91
|
+
_deployFeeProject();
|
|
92
|
+
_deployRevnet();
|
|
93
|
+
vm.deal(USER, 1000e18);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function _deployFeeProject() internal {
|
|
97
|
+
JBAccountingContext[] memory acc = new JBAccountingContext[](2);
|
|
98
|
+
acc[0] = JBAccountingContext({
|
|
99
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
100
|
+
});
|
|
101
|
+
acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
|
|
102
|
+
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
103
|
+
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
104
|
+
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
105
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
106
|
+
splits[0].beneficiary = payable(multisig());
|
|
107
|
+
splits[0].percent = 10_000;
|
|
108
|
+
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
109
|
+
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
110
|
+
stages[0] = REVStageConfig({
|
|
111
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
112
|
+
autoIssuances: ai,
|
|
113
|
+
splitPercent: 2000,
|
|
114
|
+
splits: splits,
|
|
115
|
+
initialIssuance: uint112(1000e18),
|
|
116
|
+
issuanceCutFrequency: 90 days,
|
|
117
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
118
|
+
cashOutTaxRate: 6000,
|
|
119
|
+
extraMetadata: 0
|
|
120
|
+
});
|
|
121
|
+
REVConfig memory cfg = REVConfig({
|
|
122
|
+
description: REVDescription("Revnet", "$REV", "ipfs://test", "REV_TOKEN"),
|
|
123
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
124
|
+
splitOperator: multisig(),
|
|
125
|
+
stageConfigurations: stages
|
|
126
|
+
});
|
|
127
|
+
vm.prank(multisig());
|
|
128
|
+
REV_DEPLOYER.deployFor({
|
|
129
|
+
revnetId: FEE_PROJECT_ID,
|
|
130
|
+
configuration: cfg,
|
|
131
|
+
terminalConfigurations: tc,
|
|
132
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
133
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function _deployRevnet() internal {
|
|
139
|
+
JBAccountingContext[] memory acc = new JBAccountingContext[](2);
|
|
140
|
+
acc[0] = JBAccountingContext({
|
|
141
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
142
|
+
});
|
|
143
|
+
acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
|
|
144
|
+
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
145
|
+
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
146
|
+
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
147
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
148
|
+
splits[0].beneficiary = payable(multisig());
|
|
149
|
+
splits[0].percent = 10_000;
|
|
150
|
+
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
151
|
+
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
152
|
+
stages[0] = REVStageConfig({
|
|
153
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
154
|
+
autoIssuances: ai,
|
|
155
|
+
splitPercent: 2000,
|
|
156
|
+
splits: splits,
|
|
157
|
+
initialIssuance: uint112(1000e18),
|
|
158
|
+
issuanceCutFrequency: 90 days,
|
|
159
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
160
|
+
cashOutTaxRate: 6000,
|
|
161
|
+
extraMetadata: 0
|
|
162
|
+
});
|
|
163
|
+
REVLoanSource[] memory ls = new REVLoanSource[](1);
|
|
164
|
+
ls[0] = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
165
|
+
REVConfig memory cfg = REVConfig({
|
|
166
|
+
description: REVDescription("NANA", "$NANA", "ipfs://test2", "NANA_TOKEN"),
|
|
167
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
168
|
+
splitOperator: multisig(),
|
|
169
|
+
stageConfigurations: stages
|
|
170
|
+
});
|
|
171
|
+
REVNET_ID = REV_DEPLOYER.deployFor({
|
|
172
|
+
revnetId: 0,
|
|
173
|
+
configuration: cfg,
|
|
174
|
+
terminalConfigurations: tc,
|
|
175
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
176
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("NANA")
|
|
177
|
+
})
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function _setupLoan(
|
|
182
|
+
address user,
|
|
183
|
+
uint256 ethAmount,
|
|
184
|
+
uint256 prepaidFee
|
|
185
|
+
)
|
|
186
|
+
internal
|
|
187
|
+
returns (uint256 loanId, uint256 tokenCount, uint256 borrowAmount)
|
|
188
|
+
{
|
|
189
|
+
vm.prank(user);
|
|
190
|
+
tokenCount =
|
|
191
|
+
jbMultiTerminal().pay{value: ethAmount}(REVNET_ID, JBConstants.NATIVE_TOKEN, ethAmount, user, 0, "", "");
|
|
192
|
+
borrowAmount =
|
|
193
|
+
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokenCount, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
194
|
+
if (borrowAmount == 0) return (0, tokenCount, 0);
|
|
195
|
+
mockExpect(
|
|
196
|
+
address(jbPermissions()),
|
|
197
|
+
abi.encodeCall(IJBPermissions.hasPermission, (address(LOANS_CONTRACT), user, REVNET_ID, 11, true, true)),
|
|
198
|
+
abi.encode(true)
|
|
199
|
+
);
|
|
200
|
+
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
201
|
+
vm.prank(user);
|
|
202
|
+
(loanId,) = LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(user), prepaidFee);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/// @notice Repaying with zero borrow amount and zero collateral return should revert.
|
|
206
|
+
/// @dev After borrowing, we inflate surplus back so newBorrowAmount >= loan.amount, then
|
|
207
|
+
/// repayBorrowAmount = loan.amount - newBorrowAmount = 0 with collateralCountToReturn = 0.
|
|
208
|
+
/// This should revert with NothingToRepay (or NewBorrowAmountGreaterThanLoanAmount if surplus overshot).
|
|
209
|
+
function test_repayZeroBoth_reverts() public {
|
|
210
|
+
// Setup: borrow against 10 ETH
|
|
211
|
+
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
212
|
+
require(loanId != 0, "Loan setup failed");
|
|
213
|
+
|
|
214
|
+
REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
|
|
215
|
+
|
|
216
|
+
// After borrowing, fees reduced surplus. We need to restore it so newBorrowAmount >= loan.amount.
|
|
217
|
+
// Donate enough surplus to compensate for all fees extracted during borrowing.
|
|
218
|
+
// A large donation ensures newBorrowAmount > loan.amount, hitting
|
|
219
|
+
// REVLoans_NewBorrowAmountGreaterThanLoanAmount, OR at exact match, hitting REVLoans_NothingToRepay.
|
|
220
|
+
// Either way, the "zero repayment" is prevented.
|
|
221
|
+
address donor = makeAddr("donor");
|
|
222
|
+
vm.deal(donor, 500e18);
|
|
223
|
+
vm.prank(donor);
|
|
224
|
+
jbMultiTerminal().addToBalanceOf{value: 500e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 500e18, false, "", "");
|
|
225
|
+
|
|
226
|
+
JBSingleAllowance memory allowance;
|
|
227
|
+
|
|
228
|
+
// Try to repay with collateralCountToReturn = 0 and some maxRepayBorrowAmount.
|
|
229
|
+
// Since surplus was inflated, newBorrowAmount > loan.amount, which reverts with
|
|
230
|
+
// REVLoans_NewBorrowAmountGreaterThanLoanAmount. This proves zero-repayment is blocked.
|
|
231
|
+
vm.prank(USER);
|
|
232
|
+
vm.expectRevert(); // Will revert with either NothingToRepay or NewBorrowAmountGreaterThanLoanAmount
|
|
233
|
+
LOANS_CONTRACT.repayLoan{value: 0}(
|
|
234
|
+
loanId,
|
|
235
|
+
0, // maxRepayBorrowAmount
|
|
236
|
+
0, // collateralCountToReturn = 0
|
|
237
|
+
payable(USER),
|
|
238
|
+
allowance
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/// @notice Repaying full borrow amount should succeed (returning all collateral).
|
|
243
|
+
function test_repayNonZeroAmount_succeeds() public {
|
|
244
|
+
// Setup: borrow against 10 ETH
|
|
245
|
+
(uint256 loanId,, uint256 borrowAmount) = _setupLoan(USER, 10e18, 25);
|
|
246
|
+
require(loanId != 0, "Loan setup failed");
|
|
247
|
+
|
|
248
|
+
REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
|
|
249
|
+
|
|
250
|
+
// Repay the full loan by returning all collateral.
|
|
251
|
+
// collateralCountToReturn == loan.collateral means full repayment path (newBorrowAmount = 0).
|
|
252
|
+
// Need to send enough ETH to cover loan.amount (the repayBorrowAmount) + any source fee.
|
|
253
|
+
JBSingleAllowance memory allowance;
|
|
254
|
+
|
|
255
|
+
vm.prank(USER);
|
|
256
|
+
(uint256 paidOffLoanId,) = LOANS_CONTRACT.repayLoan{value: loan.amount}(
|
|
257
|
+
loanId,
|
|
258
|
+
loan.amount, // maxRepayBorrowAmount — covers full repayment
|
|
259
|
+
loan.collateral, // return all collateral
|
|
260
|
+
payable(USER),
|
|
261
|
+
allowance
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
// Verify loan was fully repaid
|
|
265
|
+
// After full repayment with all collateral returned, the original loan is burned.
|
|
266
|
+
// The paidOffLoanId should match the loanId since all collateral was returned.
|
|
267
|
+
assertEq(paidOffLoanId, loanId, "Full repay should return original loan ID");
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/// @notice Repaying some collateral (non-zero) should succeed.
|
|
271
|
+
function test_repayNonZeroCollateral_succeeds() public {
|
|
272
|
+
// Setup: borrow against 10 ETH
|
|
273
|
+
(uint256 loanId,, uint256 borrowAmount) = _setupLoan(USER, 10e18, 25);
|
|
274
|
+
require(loanId != 0, "Loan setup failed");
|
|
275
|
+
|
|
276
|
+
REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
|
|
277
|
+
uint256 collateralToReturn = loan.collateral / 2; // Return half the collateral
|
|
278
|
+
|
|
279
|
+
// When returning half the collateral, the new borrow amount covers the remaining half.
|
|
280
|
+
// The repay amount = loan.amount - newBorrowAmount (which is > 0).
|
|
281
|
+
// We need to send enough ETH to cover it.
|
|
282
|
+
JBSingleAllowance memory allowance;
|
|
283
|
+
|
|
284
|
+
vm.prank(USER);
|
|
285
|
+
(uint256 paidOffLoanId, REVLoan memory paidOffLoan) = LOANS_CONTRACT.repayLoan{value: loan.amount}(
|
|
286
|
+
loanId,
|
|
287
|
+
loan.amount, // maxRepayBorrowAmount — generous cap
|
|
288
|
+
collateralToReturn,
|
|
289
|
+
payable(USER),
|
|
290
|
+
allowance
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
// Verify some collateral was returned and loan still exists with reduced collateral
|
|
294
|
+
assertTrue(paidOffLoan.collateral < loan.collateral, "Collateral should have decreased");
|
|
295
|
+
assertTrue(paidOffLoan.amount < loan.amount, "Borrow amount should have decreased");
|
|
296
|
+
}
|
|
297
|
+
}
|