@rev-net/core-v6 0.0.37 → 0.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -2
- package/README.md +6 -7
- package/foundry.toml +1 -1
- package/package.json +23 -16
- package/references/operations.md +1 -1
- package/references/runtime.md +1 -1
- package/script/Deploy.s.sol +12 -9
- package/src/REVDeployer.sol +69 -67
- package/src/REVHiddenTokens.sol +2 -2
- package/src/REVLoans.sol +26 -22
- package/src/REVOwner.sol +147 -29
- package/src/interfaces/IREVDeployer.sol +2 -1
- package/src/interfaces/IREVHiddenTokens.sol +4 -1
- package/src/interfaces/IREVOwner.sol +5 -0
- package/src/structs/REVAutoIssuance.sol +4 -2
- package/src/structs/REVConfig.sol +8 -5
- package/src/structs/REVDescription.sol +6 -5
- package/src/structs/REVLoan.sol +8 -5
- package/src/structs/REVStageConfig.sol +14 -16
- package/ADMINISTRATION.md +0 -73
- package/ARCHITECTURE.md +0 -116
- package/AUDIT_INSTRUCTIONS.md +0 -90
- package/RISKS.md +0 -107
- package/SKILLS.md +0 -46
- package/STYLE_GUIDE.md +0 -610
- package/USER_JOURNEYS.md +0 -195
- package/foundry.lock +0 -11
- package/slither-ci.config.json +0 -10
- package/sphinx.lock +0 -507
- package/test/REV.integrations.t.sol +0 -573
- package/test/REVAutoIssuanceFuzz.t.sol +0 -328
- package/test/REVDeployerRegressions.t.sol +0 -396
- package/test/REVInvincibility.t.sol +0 -1371
- package/test/REVInvincibilityHandler.sol +0 -387
- package/test/REVLifecycle.t.sol +0 -420
- package/test/REVLoans.invariants.t.sol +0 -724
- package/test/REVLoansAttacks.t.sol +0 -816
- package/test/REVLoansFeeRecovery.t.sol +0 -783
- package/test/REVLoansFindings.t.sol +0 -711
- package/test/REVLoansRegressions.t.sol +0 -364
- package/test/REVLoansSourceFeeRecovery.t.sol +0 -517
- package/test/REVLoansSourced.t.sol +0 -1839
- package/test/REVLoansUnSourced.t.sol +0 -409
- package/test/TestAuditFixVerification.t.sol +0 -675
- package/test/TestBurnHeldTokens.t.sol +0 -394
- package/test/TestCEIPattern.t.sol +0 -508
- package/test/TestCashOutCallerValidation.t.sol +0 -452
- package/test/TestConversionDocumentation.t.sol +0 -365
- package/test/TestCrossCurrencyReclaim.t.sol +0 -610
- package/test/TestCrossSourceReallocation.t.sol +0 -361
- package/test/TestERC2771MetaTx.t.sol +0 -585
- package/test/TestEmptyBuybackSpecs.t.sol +0 -300
- package/test/TestFlashLoanSurplus.t.sol +0 -365
- package/test/TestHiddenTokens.t.sol +0 -474
- package/test/TestHookArrayOOB.t.sol +0 -278
- package/test/TestLiquidationBehavior.t.sol +0 -398
- package/test/TestLoanSourceRotation.t.sol +0 -553
- package/test/TestLoansCashOutDelay.t.sol +0 -493
- package/test/TestLongTailEconomics.t.sol +0 -677
- package/test/TestLowFindings.t.sol +0 -677
- package/test/TestMixedFixes.t.sol +0 -593
- package/test/TestPermit2Signatures.t.sol +0 -683
- package/test/TestReallocationSandwich.t.sol +0 -412
- package/test/TestRevnetRegressions.t.sol +0 -350
- package/test/TestSplitWeightAdjustment.t.sol +0 -527
- package/test/TestSplitWeightE2E.t.sol +0 -605
- package/test/TestSplitWeightFork.t.sol +0 -855
- package/test/TestStageTransitionBorrowable.t.sol +0 -301
- package/test/TestSwapTerminalPermission.t.sol +0 -262
- package/test/TestTerminalEncodingInHash.t.sol +0 -326
- package/test/TestUint112Overflow.t.sol +0 -311
- package/test/TestZeroAmountLoanGuard.t.sol +0 -378
- package/test/TestZeroRepayment.t.sol +0 -354
- package/test/audit/CrossChainBuybackRouteMismatch.t.sol +0 -184
- package/test/audit/HiddenSupplyCashout.t.sol +0 -61
- package/test/audit/LoanIdOverflowGuard.t.sol +0 -523
- package/test/audit/NemesisVerification.t.sol +0 -97
- package/test/audit/OperatorDelegation.t.sol +0 -356
- package/test/audit/PhantomSurplusTerminal.t.sol +0 -367
- package/test/audit/REVOwnerCurrencyMismatch.t.sol +0 -188
- package/test/audit/REVOwnerRemoteSurplusCurrencyMismatch.t.sol +0 -140
- package/test/audit/ReallocatePermission.t.sol +0 -363
- package/test/audit/RemoteLoanAccountingGap.t.sol +0 -74
- package/test/audit/SupportsInterfaceTest.t.sol +0 -51
- package/test/audit/TestFeeAllowanceLeak.t.sol +0 -197
- package/test/audit/TestLoansAndDeployerFixes.t.sol +0 -576
- package/test/fork/ForkTestBase.sol +0 -727
- package/test/fork/TestAutoIssuanceFork.t.sol +0 -148
- package/test/fork/TestCashOutFork.t.sol +0 -253
- package/test/fork/TestIssuanceDecayFork.t.sol +0 -158
- package/test/fork/TestLoanAdversarialFork.t.sol +0 -744
- package/test/fork/TestLoanBorrowFork.t.sol +0 -163
- package/test/fork/TestLoanCrossRulesetFork.t.sol +0 -308
- package/test/fork/TestLoanERC20Fork.t.sol +0 -459
- package/test/fork/TestLoanLiquidationFork.t.sol +0 -135
- package/test/fork/TestLoanReallocateFork.t.sol +0 -113
- package/test/fork/TestLoanRepayFork.t.sol +0 -188
- package/test/fork/TestLoanTransferFork.t.sol +0 -143
- package/test/fork/TestPermit2PaymentFork.t.sol +0 -300
- package/test/fork/TestSplitWeightFork.t.sol +0 -189
- package/test/helpers/MaliciousContracts.sol +0 -247
- package/test/helpers/REVEmpty721Config.sol +0 -45
- package/test/mock/MockBuybackCashOutRecorder.sol +0 -84
- package/test/mock/MockBuybackDataHook.sol +0 -112
- package/test/mock/MockBuybackDataHookMintPath.sol +0 -68
- package/test/mock/MockSuckerRegistry.sol +0 -17
- package/test/regression/TestBurnPermissionRequired.t.sol +0 -294
- package/test/regression/TestCashOutBuybackFeeLeak.t.sol +0 -232
- package/test/regression/TestCrossRevnetLiquidation.t.sol +0 -255
- package/test/regression/TestCumulativeLoanCounter.t.sol +0 -361
- package/test/regression/TestLiquidateGapHandling.t.sol +0 -394
- package/test/regression/TestZeroPriceFeed.t.sol +0 -422
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity 0.8.28;
|
|
3
|
-
|
|
4
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
5
|
-
import "forge-std/Test.sol";
|
|
6
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
7
|
-
import /* {*} from */ "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
8
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
9
|
-
import /* {*} from */ "./../../src/REVDeployer.sol";
|
|
10
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
11
|
-
import "@croptop/core-v6/src/CTPublisher.sol";
|
|
12
|
-
import {MockBuybackDataHook} from "./../mock/MockBuybackDataHook.sol";
|
|
13
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
14
|
-
import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
15
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
16
|
-
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
17
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
18
|
-
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
19
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
20
|
-
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
21
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
22
|
-
import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
|
|
23
|
-
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
24
|
-
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
25
|
-
import {MockPriceFeed} from "@bananapus/core-v6/test/mock/MockPriceFeed.sol";
|
|
26
|
-
import {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.sol";
|
|
27
|
-
import {REVLoans} from "../../src/REVLoans.sol";
|
|
28
|
-
import {REVLoan} from "../../src/structs/REVLoan.sol";
|
|
29
|
-
import {REVStageConfig, REVAutoIssuance} from "../../src/structs/REVStageConfig.sol";
|
|
30
|
-
import {REVLoanSource} from "../../src/structs/REVLoanSource.sol";
|
|
31
|
-
import {REVDescription} from "../../src/structs/REVDescription.sol";
|
|
32
|
-
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
33
|
-
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
34
|
-
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
35
|
-
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
36
|
-
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
37
|
-
import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
|
|
38
|
-
import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
|
|
39
|
-
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
40
|
-
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
41
|
-
import {REVEmpty721Config} from "../helpers/REVEmpty721Config.sol";
|
|
42
|
-
import {REVOwner} from "../../src/REVOwner.sol";
|
|
43
|
-
import {IREVDeployer} from "../../src/interfaces/IREVDeployer.sol";
|
|
44
|
-
import {MockSuckerRegistry} from "../mock/MockSuckerRegistry.sol";
|
|
45
|
-
|
|
46
|
-
/// @notice Validates that liquidateExpiredLoansFrom rejects loan number ranges that would overflow into another
|
|
47
|
-
/// revnet's namespace.
|
|
48
|
-
/// @dev _generateLoanId computes: (revnetId * _ONE_TRILLION) + loanNumber. If startingLoanId + count > _ONE_TRILLION,
|
|
49
|
-
/// the generated loanId would collide with a different revnet's loans.
|
|
50
|
-
contract TestCrossRevnetLiquidation is TestBaseWorkflow {
|
|
51
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
52
|
-
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
53
|
-
|
|
54
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
55
|
-
REVDeployer REV_DEPLOYER;
|
|
56
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
57
|
-
REVOwner REV_OWNER;
|
|
58
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
59
|
-
JB721TiersHook EXAMPLE_HOOK;
|
|
60
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
61
|
-
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
62
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
63
|
-
IJB721TiersHookStore HOOK_STORE;
|
|
64
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
65
|
-
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
66
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
67
|
-
REVLoans LOANS_CONTRACT;
|
|
68
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
69
|
-
MockERC20 TOKEN;
|
|
70
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
71
|
-
IJBSuckerRegistry SUCKER_REGISTRY;
|
|
72
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
73
|
-
CTPublisher PUBLISHER;
|
|
74
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
75
|
-
MockBuybackDataHook MOCK_BUYBACK;
|
|
76
|
-
|
|
77
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
78
|
-
uint256 FEE_PROJECT_ID;
|
|
79
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
80
|
-
uint256 REVNET_ID;
|
|
81
|
-
|
|
82
|
-
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
83
|
-
|
|
84
|
-
/// @dev _ONE_TRILLION mirrors the private constant in REVLoans.sol.
|
|
85
|
-
uint256 private constant _ONE_TRILLION = 1_000_000_000_000;
|
|
86
|
-
|
|
87
|
-
function setUp() public override {
|
|
88
|
-
super.setUp();
|
|
89
|
-
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
90
|
-
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
91
|
-
HOOK_STORE = new JB721TiersHookStore();
|
|
92
|
-
EXAMPLE_HOOK = new JB721TiersHook(
|
|
93
|
-
jbDirectory(),
|
|
94
|
-
jbPermissions(),
|
|
95
|
-
jbPrices(),
|
|
96
|
-
jbRulesets(),
|
|
97
|
-
HOOK_STORE,
|
|
98
|
-
jbSplits(),
|
|
99
|
-
IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
|
|
100
|
-
multisig()
|
|
101
|
-
);
|
|
102
|
-
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
103
|
-
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
104
|
-
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
105
|
-
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
106
|
-
TOKEN = new MockERC20("1/2 ETH", "1/2");
|
|
107
|
-
MockPriceFeed priceFeed = new MockPriceFeed(1e21, 6);
|
|
108
|
-
vm.prank(multisig());
|
|
109
|
-
jbPrices()
|
|
110
|
-
.addPriceFeedFor(0, uint32(uint160(address(TOKEN))), uint32(uint160(JBConstants.NATIVE_TOKEN)), priceFeed);
|
|
111
|
-
LOANS_CONTRACT = new REVLoans({
|
|
112
|
-
controller: jbController(),
|
|
113
|
-
suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
|
|
114
|
-
revId: FEE_PROJECT_ID,
|
|
115
|
-
owner: address(this),
|
|
116
|
-
permit2: permit2(),
|
|
117
|
-
trustedForwarder: TRUSTED_FORWARDER
|
|
118
|
-
});
|
|
119
|
-
REV_OWNER = new REVOwner(
|
|
120
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
121
|
-
jbDirectory(),
|
|
122
|
-
FEE_PROJECT_ID,
|
|
123
|
-
SUCKER_REGISTRY,
|
|
124
|
-
address(LOANS_CONTRACT),
|
|
125
|
-
address(0)
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
129
|
-
jbController(),
|
|
130
|
-
SUCKER_REGISTRY,
|
|
131
|
-
FEE_PROJECT_ID,
|
|
132
|
-
HOOK_DEPLOYER,
|
|
133
|
-
PUBLISHER,
|
|
134
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
135
|
-
address(LOANS_CONTRACT),
|
|
136
|
-
TRUSTED_FORWARDER,
|
|
137
|
-
address(REV_OWNER)
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
REV_OWNER.setDeployer(REV_DEPLOYER);
|
|
141
|
-
|
|
142
|
-
vm.prank(multisig());
|
|
143
|
-
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
144
|
-
_deployFeeProject();
|
|
145
|
-
_deployRevnet();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function _deployFeeProject() internal {
|
|
149
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](2);
|
|
150
|
-
acc[0] = JBAccountingContext({
|
|
151
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
152
|
-
});
|
|
153
|
-
acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
|
|
154
|
-
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
155
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
156
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
157
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
158
|
-
splits[0].beneficiary = payable(multisig());
|
|
159
|
-
splits[0].percent = 10_000;
|
|
160
|
-
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
161
|
-
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
162
|
-
stages[0] = REVStageConfig({
|
|
163
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
164
|
-
autoIssuances: ai,
|
|
165
|
-
splitPercent: 2000,
|
|
166
|
-
splits: splits,
|
|
167
|
-
initialIssuance: uint112(1000e18),
|
|
168
|
-
issuanceCutFrequency: 90 days,
|
|
169
|
-
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
170
|
-
cashOutTaxRate: 6000,
|
|
171
|
-
extraMetadata: 0
|
|
172
|
-
});
|
|
173
|
-
REVConfig memory cfg = REVConfig({
|
|
174
|
-
// forge-lint: disable-next-line(named-struct-fields)
|
|
175
|
-
description: REVDescription("Revnet", "$REV", "ipfs://test", "REV_TOKEN"),
|
|
176
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
177
|
-
splitOperator: multisig(),
|
|
178
|
-
stageConfigurations: stages
|
|
179
|
-
});
|
|
180
|
-
vm.prank(multisig());
|
|
181
|
-
REV_DEPLOYER.deployFor({
|
|
182
|
-
revnetId: FEE_PROJECT_ID,
|
|
183
|
-
configuration: cfg,
|
|
184
|
-
terminalConfigurations: tc,
|
|
185
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
186
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
|
|
187
|
-
}),
|
|
188
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
189
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function _deployRevnet() internal {
|
|
194
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](2);
|
|
195
|
-
acc[0] = JBAccountingContext({
|
|
196
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
197
|
-
});
|
|
198
|
-
acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
|
|
199
|
-
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
200
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
201
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
202
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
203
|
-
splits[0].beneficiary = payable(multisig());
|
|
204
|
-
splits[0].percent = 10_000;
|
|
205
|
-
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
206
|
-
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
207
|
-
stages[0] = REVStageConfig({
|
|
208
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
209
|
-
autoIssuances: ai,
|
|
210
|
-
splitPercent: 2000,
|
|
211
|
-
splits: splits,
|
|
212
|
-
initialIssuance: uint112(1000e18),
|
|
213
|
-
issuanceCutFrequency: 90 days,
|
|
214
|
-
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
215
|
-
cashOutTaxRate: 6000,
|
|
216
|
-
extraMetadata: 0
|
|
217
|
-
});
|
|
218
|
-
REVConfig memory cfg = REVConfig({
|
|
219
|
-
// forge-lint: disable-next-line(named-struct-fields)
|
|
220
|
-
description: REVDescription("NANA", "$NANA", "ipfs://test2", "NANA_TOKEN"),
|
|
221
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
222
|
-
splitOperator: multisig(),
|
|
223
|
-
stageConfigurations: stages
|
|
224
|
-
});
|
|
225
|
-
(REVNET_ID,) = REV_DEPLOYER.deployFor({
|
|
226
|
-
revnetId: 0,
|
|
227
|
-
configuration: cfg,
|
|
228
|
-
terminalConfigurations: tc,
|
|
229
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
230
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("NANA")
|
|
231
|
-
}),
|
|
232
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
233
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/// @notice liquidateExpiredLoansFrom should revert when startingLoanId would overflow into another revnet's
|
|
238
|
-
/// namespace.
|
|
239
|
-
function test_liquidateExpiredLoans_revertsOnCrossRevnetOverflow() public {
|
|
240
|
-
vm.expectRevert(REVLoans.REVLoans_LoanIdOverflow.selector);
|
|
241
|
-
LOANS_CONTRACT.liquidateExpiredLoansFrom(REVNET_ID, _ONE_TRILLION, 1);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/// @notice liquidateExpiredLoansFrom should work for valid ranges within the revnet's namespace.
|
|
245
|
-
function test_liquidateExpiredLoans_normalRangeStillWorks() public {
|
|
246
|
-
// Calling with a valid range on a revnet with no loans should simply do nothing (no revert).
|
|
247
|
-
LOANS_CONTRACT.liquidateExpiredLoansFrom(REVNET_ID, 1, 5);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/// @notice The boundary case where startingLoanId + count == _ONE_TRILLION should succeed.
|
|
251
|
-
function test_liquidateExpiredLoans_boundaryExactlyAtLimit() public {
|
|
252
|
-
// Exactly at the boundary (not over) should not revert.
|
|
253
|
-
LOANS_CONTRACT.liquidateExpiredLoansFrom(REVNET_ID, _ONE_TRILLION - 1, 1);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity 0.8.28;
|
|
3
|
-
|
|
4
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
5
|
-
import "forge-std/Test.sol";
|
|
6
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
7
|
-
import /* {*} from */ "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
8
|
-
// import /* {*} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
9
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
10
|
-
import /* {*} from */ "./../../src/REVDeployer.sol";
|
|
11
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
12
|
-
import "@croptop/core-v6/src/CTPublisher.sol";
|
|
13
|
-
import {MockBuybackDataHook} from "./../mock/MockBuybackDataHook.sol";
|
|
14
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
15
|
-
import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
16
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
17
|
-
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
18
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
19
|
-
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
20
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
21
|
-
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
22
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
23
|
-
import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
|
|
24
|
-
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
25
|
-
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
26
|
-
import {JBSingleAllowance} from "@bananapus/core-v6/src/structs/JBSingleAllowance.sol";
|
|
27
|
-
import {MockPriceFeed} from "@bananapus/core-v6/test/mock/MockPriceFeed.sol";
|
|
28
|
-
import {REVLoans} from "../../src/REVLoans.sol";
|
|
29
|
-
import {REVLoan} from "../../src/structs/REVLoan.sol";
|
|
30
|
-
import {REVStageConfig, REVAutoIssuance} from "../../src/structs/REVStageConfig.sol";
|
|
31
|
-
import {REVLoanSource} from "../../src/structs/REVLoanSource.sol";
|
|
32
|
-
import {REVDescription} from "../../src/structs/REVDescription.sol";
|
|
33
|
-
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
34
|
-
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
35
|
-
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
36
|
-
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
37
|
-
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
38
|
-
import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
|
|
39
|
-
import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
|
|
40
|
-
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
41
|
-
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
42
|
-
import {REVEmpty721Config} from "../helpers/REVEmpty721Config.sol";
|
|
43
|
-
import {REVOwner} from "../../src/REVOwner.sol";
|
|
44
|
-
import {IREVDeployer} from "../../src/interfaces/IREVDeployer.sol";
|
|
45
|
-
import {MockSuckerRegistry} from "../mock/MockSuckerRegistry.sol";
|
|
46
|
-
|
|
47
|
-
/// @notice totalLoansBorrowedFor is a cumulative counter, not an active loan count.
|
|
48
|
-
/// @dev The rename from numberOfLoansFor to totalLoansBorrowedFor clarifies that the counter only increments
|
|
49
|
-
/// and never decrements. Repaying or liquidating a loan does NOT reduce the counter. This test verifies that
|
|
50
|
-
/// the counter remains at its high-water mark after loans are fully repaid and after loans are liquidated.
|
|
51
|
-
contract TestCumulativeLoanCounter is TestBaseWorkflow {
|
|
52
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
53
|
-
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
54
|
-
|
|
55
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
56
|
-
REVDeployer REV_DEPLOYER;
|
|
57
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
58
|
-
REVOwner REV_OWNER;
|
|
59
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
60
|
-
JB721TiersHook EXAMPLE_HOOK;
|
|
61
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
62
|
-
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
63
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
64
|
-
IJB721TiersHookStore HOOK_STORE;
|
|
65
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
66
|
-
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
67
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
68
|
-
REVLoans LOANS_CONTRACT;
|
|
69
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
70
|
-
IJBSuckerRegistry SUCKER_REGISTRY;
|
|
71
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
72
|
-
CTPublisher PUBLISHER;
|
|
73
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
74
|
-
MockBuybackDataHook MOCK_BUYBACK;
|
|
75
|
-
|
|
76
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
77
|
-
uint256 FEE_PROJECT_ID;
|
|
78
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
79
|
-
uint256 REVNET_ID;
|
|
80
|
-
|
|
81
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
82
|
-
address USER1 = makeAddr("user1");
|
|
83
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
84
|
-
address USER2 = makeAddr("user2");
|
|
85
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
86
|
-
address USER3 = makeAddr("user3");
|
|
87
|
-
|
|
88
|
-
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
89
|
-
|
|
90
|
-
function setUp() public override {
|
|
91
|
-
super.setUp();
|
|
92
|
-
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
93
|
-
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
94
|
-
HOOK_STORE = new JB721TiersHookStore();
|
|
95
|
-
EXAMPLE_HOOK = new JB721TiersHook(
|
|
96
|
-
jbDirectory(),
|
|
97
|
-
jbPermissions(),
|
|
98
|
-
jbPrices(),
|
|
99
|
-
jbRulesets(),
|
|
100
|
-
HOOK_STORE,
|
|
101
|
-
jbSplits(),
|
|
102
|
-
IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
|
|
103
|
-
multisig()
|
|
104
|
-
);
|
|
105
|
-
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
106
|
-
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
107
|
-
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
108
|
-
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
109
|
-
MockPriceFeed priceFeed = new MockPriceFeed(1e18, 18);
|
|
110
|
-
vm.prank(multisig());
|
|
111
|
-
jbPrices()
|
|
112
|
-
.addPriceFeedFor(
|
|
113
|
-
0, uint32(uint160(JBConstants.NATIVE_TOKEN)), uint32(uint160(JBConstants.NATIVE_TOKEN)), priceFeed
|
|
114
|
-
);
|
|
115
|
-
LOANS_CONTRACT = new REVLoans({
|
|
116
|
-
controller: jbController(),
|
|
117
|
-
suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
|
|
118
|
-
revId: FEE_PROJECT_ID,
|
|
119
|
-
owner: address(this),
|
|
120
|
-
permit2: permit2(),
|
|
121
|
-
trustedForwarder: TRUSTED_FORWARDER
|
|
122
|
-
});
|
|
123
|
-
REV_OWNER = new REVOwner(
|
|
124
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
125
|
-
jbDirectory(),
|
|
126
|
-
FEE_PROJECT_ID,
|
|
127
|
-
SUCKER_REGISTRY,
|
|
128
|
-
address(LOANS_CONTRACT),
|
|
129
|
-
address(0)
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
133
|
-
jbController(),
|
|
134
|
-
SUCKER_REGISTRY,
|
|
135
|
-
FEE_PROJECT_ID,
|
|
136
|
-
HOOK_DEPLOYER,
|
|
137
|
-
PUBLISHER,
|
|
138
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
139
|
-
address(LOANS_CONTRACT),
|
|
140
|
-
TRUSTED_FORWARDER,
|
|
141
|
-
address(REV_OWNER)
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
REV_OWNER.setDeployer(REV_DEPLOYER);
|
|
145
|
-
|
|
146
|
-
vm.prank(multisig());
|
|
147
|
-
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
148
|
-
_deployFeeProject();
|
|
149
|
-
_deployRevnet();
|
|
150
|
-
vm.deal(USER1, 100e18);
|
|
151
|
-
vm.deal(USER2, 100e18);
|
|
152
|
-
vm.deal(USER3, 100e18);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function _deployFeeProject() internal {
|
|
156
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](1);
|
|
157
|
-
acc[0] = JBAccountingContext({
|
|
158
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
159
|
-
});
|
|
160
|
-
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
161
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
162
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
163
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
164
|
-
splits[0].beneficiary = payable(multisig());
|
|
165
|
-
splits[0].percent = 10_000;
|
|
166
|
-
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
167
|
-
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
168
|
-
stages[0] = REVStageConfig({
|
|
169
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
170
|
-
autoIssuances: ai,
|
|
171
|
-
splitPercent: 2000,
|
|
172
|
-
splits: splits,
|
|
173
|
-
initialIssuance: uint112(1000e18),
|
|
174
|
-
issuanceCutFrequency: 90 days,
|
|
175
|
-
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
176
|
-
cashOutTaxRate: 6000,
|
|
177
|
-
extraMetadata: 0
|
|
178
|
-
});
|
|
179
|
-
REVConfig memory cfg = REVConfig({
|
|
180
|
-
// forge-lint: disable-next-line(named-struct-fields)
|
|
181
|
-
description: REVDescription("Revnet", "$REV", "ipfs://test", "REV_TOKEN"),
|
|
182
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
183
|
-
splitOperator: multisig(),
|
|
184
|
-
stageConfigurations: stages
|
|
185
|
-
});
|
|
186
|
-
vm.prank(multisig());
|
|
187
|
-
REV_DEPLOYER.deployFor({
|
|
188
|
-
revnetId: FEE_PROJECT_ID,
|
|
189
|
-
configuration: cfg,
|
|
190
|
-
terminalConfigurations: tc,
|
|
191
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
192
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
|
|
193
|
-
}),
|
|
194
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
195
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function _deployRevnet() internal {
|
|
200
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](1);
|
|
201
|
-
acc[0] = JBAccountingContext({
|
|
202
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
203
|
-
});
|
|
204
|
-
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
205
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
206
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
207
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
208
|
-
splits[0].beneficiary = payable(multisig());
|
|
209
|
-
splits[0].percent = 10_000;
|
|
210
|
-
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
211
|
-
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
212
|
-
stages[0] = REVStageConfig({
|
|
213
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
214
|
-
autoIssuances: ai,
|
|
215
|
-
splitPercent: 2000,
|
|
216
|
-
splits: splits,
|
|
217
|
-
initialIssuance: uint112(1000e18),
|
|
218
|
-
issuanceCutFrequency: 90 days,
|
|
219
|
-
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
220
|
-
cashOutTaxRate: 6000,
|
|
221
|
-
extraMetadata: 0
|
|
222
|
-
});
|
|
223
|
-
REVConfig memory cfg = REVConfig({
|
|
224
|
-
// forge-lint: disable-next-line(named-struct-fields)
|
|
225
|
-
description: REVDescription("NANA", "$NANA", "ipfs://test2", "NANA_TOKEN"),
|
|
226
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
227
|
-
splitOperator: multisig(),
|
|
228
|
-
stageConfigurations: stages
|
|
229
|
-
});
|
|
230
|
-
(REVNET_ID,) = REV_DEPLOYER.deployFor({
|
|
231
|
-
revnetId: 0,
|
|
232
|
-
configuration: cfg,
|
|
233
|
-
terminalConfigurations: tc,
|
|
234
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
235
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("NANA")
|
|
236
|
-
}),
|
|
237
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
238
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function _setupLoan(address user, uint256 ethAmount) internal returns (uint256 loanId, uint256 tokenCount) {
|
|
243
|
-
vm.prank(user);
|
|
244
|
-
tokenCount =
|
|
245
|
-
jbMultiTerminal().pay{value: ethAmount}(REVNET_ID, JBConstants.NATIVE_TOKEN, ethAmount, user, 0, "", "");
|
|
246
|
-
uint256 borrowAmount =
|
|
247
|
-
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokenCount, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
248
|
-
require(borrowAmount > 0, "Borrow amount should be > 0");
|
|
249
|
-
mockExpect(
|
|
250
|
-
address(jbPermissions()),
|
|
251
|
-
abi.encodeCall(IJBPermissions.hasPermission, (address(LOANS_CONTRACT), user, REVNET_ID, 11, true, true)),
|
|
252
|
-
abi.encode(true)
|
|
253
|
-
);
|
|
254
|
-
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
255
|
-
vm.prank(user);
|
|
256
|
-
(loanId,) = LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(user), 25, user);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/// @notice Verifies totalLoansBorrowedFor never decrements after loan repayment.
|
|
260
|
-
/// @dev Creates 3 loans, fully repays 2, then verifies the counter stays at 3 (not 1).
|
|
261
|
-
/// This confirms that the rename correctly reflects cumulative semantics.
|
|
262
|
-
function test_counterNeverDecrementsAfterRepayment() public {
|
|
263
|
-
// Counter starts at 0
|
|
264
|
-
assertEq(LOANS_CONTRACT.totalLoansBorrowedFor(REVNET_ID), 0, "Counter should start at 0");
|
|
265
|
-
|
|
266
|
-
// Create 3 loans
|
|
267
|
-
(uint256 loanId1,) = _setupLoan(USER1, 3e18);
|
|
268
|
-
(uint256 loanId2,) = _setupLoan(USER2, 3e18);
|
|
269
|
-
(uint256 loanId3,) = _setupLoan(USER3, 3e18);
|
|
270
|
-
|
|
271
|
-
// Counter should be 3
|
|
272
|
-
assertEq(LOANS_CONTRACT.totalLoansBorrowedFor(REVNET_ID), 3, "Counter should be 3 after 3 loans");
|
|
273
|
-
|
|
274
|
-
// Fully repay loan 1
|
|
275
|
-
REVLoan memory loan1 = LOANS_CONTRACT.loanOf(loanId1);
|
|
276
|
-
JBSingleAllowance memory allowance;
|
|
277
|
-
vm.prank(USER1);
|
|
278
|
-
LOANS_CONTRACT.repayLoan{value: loan1.amount}(
|
|
279
|
-
loanId1, loan1.amount, loan1.collateral, payable(USER1), allowance
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
// Counter should still be 3 (NOT 2) -- repayment does not decrement
|
|
283
|
-
assertEq(
|
|
284
|
-
LOANS_CONTRACT.totalLoansBorrowedFor(REVNET_ID),
|
|
285
|
-
3,
|
|
286
|
-
"Counter should remain 3 after repaying loan 1 -- cumulative, never decrements"
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
// Fully repay loan 2
|
|
290
|
-
REVLoan memory loan2 = LOANS_CONTRACT.loanOf(loanId2);
|
|
291
|
-
vm.prank(USER2);
|
|
292
|
-
LOANS_CONTRACT.repayLoan{value: loan2.amount}(
|
|
293
|
-
loanId2, loan2.amount, loan2.collateral, payable(USER2), allowance
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
// Counter should still be 3 (NOT 1)
|
|
297
|
-
assertEq(
|
|
298
|
-
LOANS_CONTRACT.totalLoansBorrowedFor(REVNET_ID),
|
|
299
|
-
3,
|
|
300
|
-
"Counter should remain 3 after repaying loan 2 -- cumulative, never decrements"
|
|
301
|
-
);
|
|
302
|
-
|
|
303
|
-
// Verify the loans are actually deleted (createdAt == 0)
|
|
304
|
-
assertEq(LOANS_CONTRACT.loanOf(loanId1).createdAt, 0, "Loan 1 should be deleted");
|
|
305
|
-
assertEq(LOANS_CONTRACT.loanOf(loanId2).createdAt, 0, "Loan 2 should be deleted");
|
|
306
|
-
assertTrue(LOANS_CONTRACT.loanOf(loanId3).createdAt > 0, "Loan 3 should still exist");
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/// @notice Verifies totalLoansBorrowedFor never decrements after loan liquidation.
|
|
310
|
-
/// @dev Creates 2 loans, liquidates both, then verifies the counter stays at 2.
|
|
311
|
-
function test_counterNeverDecrementsAfterLiquidation() public {
|
|
312
|
-
// Create 2 loans
|
|
313
|
-
(uint256 loanId1,) = _setupLoan(USER1, 5e18);
|
|
314
|
-
(uint256 loanId2,) = _setupLoan(USER2, 5e18);
|
|
315
|
-
|
|
316
|
-
assertEq(LOANS_CONTRACT.totalLoansBorrowedFor(REVNET_ID), 2, "Counter should be 2 after 2 loans");
|
|
317
|
-
|
|
318
|
-
// Warp past liquidation duration
|
|
319
|
-
vm.warp(block.timestamp + LOANS_CONTRACT.LOAN_LIQUIDATION_DURATION() + 1);
|
|
320
|
-
|
|
321
|
-
// Liquidate both loans
|
|
322
|
-
LOANS_CONTRACT.liquidateExpiredLoansFrom(REVNET_ID, 1, 2);
|
|
323
|
-
|
|
324
|
-
// Both loans should be deleted
|
|
325
|
-
assertEq(LOANS_CONTRACT.loanOf(loanId1).createdAt, 0, "Loan 1 should be liquidated");
|
|
326
|
-
assertEq(LOANS_CONTRACT.loanOf(loanId2).createdAt, 0, "Loan 2 should be liquidated");
|
|
327
|
-
|
|
328
|
-
// Counter should still be 2 -- liquidation does not decrement
|
|
329
|
-
assertEq(
|
|
330
|
-
LOANS_CONTRACT.totalLoansBorrowedFor(REVNET_ID),
|
|
331
|
-
2,
|
|
332
|
-
"Counter should remain 2 after liquidating both loans -- cumulative, never decrements"
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/// @notice Verifies that partial repayment (which creates a new loan) increments the counter.
|
|
337
|
-
/// @dev When partially repaying, the old loan is burned and a new loan is minted for the remainder.
|
|
338
|
-
/// This should increment the counter by 1 since a new loan ID is generated.
|
|
339
|
-
function test_partialRepaymentIncrementsCounter() public {
|
|
340
|
-
// Create 1 loan
|
|
341
|
-
(uint256 loanId1,) = _setupLoan(USER1, 5e18);
|
|
342
|
-
assertEq(LOANS_CONTRACT.totalLoansBorrowedFor(REVNET_ID), 1, "Counter should be 1 after 1 loan");
|
|
343
|
-
|
|
344
|
-
// Partially repay (repay half the borrow amount, return no collateral)
|
|
345
|
-
REVLoan memory loan1 = LOANS_CONTRACT.loanOf(loanId1);
|
|
346
|
-
uint256 halfAmount = loan1.amount / 2;
|
|
347
|
-
JBSingleAllowance memory allowance;
|
|
348
|
-
vm.prank(USER1);
|
|
349
|
-
LOANS_CONTRACT.repayLoan{value: halfAmount}(loanId1, halfAmount, 0, payable(USER1), allowance);
|
|
350
|
-
|
|
351
|
-
// Counter should be 2: original loan (burned) + replacement loan (new ID)
|
|
352
|
-
assertEq(
|
|
353
|
-
LOANS_CONTRACT.totalLoansBorrowedFor(REVNET_ID),
|
|
354
|
-
2,
|
|
355
|
-
"Counter should be 2 after partial repayment creates a replacement loan"
|
|
356
|
-
);
|
|
357
|
-
|
|
358
|
-
// Original loan should be deleted
|
|
359
|
-
assertEq(LOANS_CONTRACT.loanOf(loanId1).createdAt, 0, "Original loan should be deleted after partial repay");
|
|
360
|
-
}
|
|
361
|
-
}
|