@rev-net/core-v6 0.0.37 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -2
- package/README.md +6 -7
- package/foundry.toml +1 -1
- package/package.json +23 -16
- package/references/operations.md +1 -1
- package/references/runtime.md +1 -1
- package/script/Deploy.s.sol +12 -9
- package/src/REVDeployer.sol +60 -65
- package/src/REVHiddenTokens.sol +2 -2
- package/src/REVLoans.sol +17 -10
- package/src/REVOwner.sol +121 -14
- package/src/interfaces/IREVDeployer.sol +2 -1
- package/src/interfaces/IREVHiddenTokens.sol +4 -1
- package/src/interfaces/IREVOwner.sol +5 -0
- package/ADMINISTRATION.md +0 -73
- package/ARCHITECTURE.md +0 -116
- package/AUDIT_INSTRUCTIONS.md +0 -90
- package/RISKS.md +0 -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,378 +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
|
-
import {REVEmpty721Config} from "./helpers/REVEmpty721Config.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 {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.sol";
|
|
29
|
-
import {REVLoans} from "../src/REVLoans.sol";
|
|
30
|
-
import {REVLoan} from "../src/structs/REVLoan.sol";
|
|
31
|
-
import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
|
|
32
|
-
import {REVLoanSource} from "../src/structs/REVLoanSource.sol";
|
|
33
|
-
import {REVDescription} from "../src/structs/REVDescription.sol";
|
|
34
|
-
import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
|
|
35
|
-
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
36
|
-
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
37
|
-
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
38
|
-
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
39
|
-
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
40
|
-
import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
|
|
41
|
-
import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
|
|
42
|
-
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
43
|
-
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
44
|
-
import {REVOwner} from "../src/REVOwner.sol";
|
|
45
|
-
import {IREVDeployer} from "../src/interfaces/IREVDeployer.sol";
|
|
46
|
-
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|
47
|
-
import {MockSuckerRegistry} from "./mock/MockSuckerRegistry.sol";
|
|
48
|
-
|
|
49
|
-
/// @notice Tests for PR #105: zero-amount loan guard and mint-before-adjust ordering.
|
|
50
|
-
contract TestZeroAmountLoanGuard 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
|
-
IREVLoans 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
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
83
|
-
address USER = makeAddr("user");
|
|
84
|
-
|
|
85
|
-
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
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
|
-
vm.deal(USER, 1000e18);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function _deployFeeProject() internal {
|
|
150
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](2);
|
|
151
|
-
acc[0] = JBAccountingContext({
|
|
152
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
153
|
-
});
|
|
154
|
-
acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
|
|
155
|
-
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
156
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
157
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
158
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
159
|
-
splits[0].beneficiary = payable(multisig());
|
|
160
|
-
splits[0].percent = 10_000;
|
|
161
|
-
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
162
|
-
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
163
|
-
stages[0] = REVStageConfig({
|
|
164
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
165
|
-
autoIssuances: ai,
|
|
166
|
-
splitPercent: 2000,
|
|
167
|
-
splits: splits,
|
|
168
|
-
initialIssuance: uint112(1000e18),
|
|
169
|
-
issuanceCutFrequency: 90 days,
|
|
170
|
-
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
171
|
-
cashOutTaxRate: 6000,
|
|
172
|
-
extraMetadata: 0
|
|
173
|
-
});
|
|
174
|
-
REVConfig memory cfg = REVConfig({
|
|
175
|
-
// forge-lint: disable-next-line(named-struct-fields)
|
|
176
|
-
description: REVDescription("Revnet", "$REV", "ipfs://test", "REV_TOKEN"),
|
|
177
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
178
|
-
splitOperator: multisig(),
|
|
179
|
-
stageConfigurations: stages
|
|
180
|
-
});
|
|
181
|
-
vm.prank(multisig());
|
|
182
|
-
REV_DEPLOYER.deployFor({
|
|
183
|
-
revnetId: FEE_PROJECT_ID,
|
|
184
|
-
configuration: cfg,
|
|
185
|
-
terminalConfigurations: tc,
|
|
186
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
187
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
|
|
188
|
-
}),
|
|
189
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
190
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function _deployRevnet() internal {
|
|
195
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](2);
|
|
196
|
-
acc[0] = JBAccountingContext({
|
|
197
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
198
|
-
});
|
|
199
|
-
acc[1] = JBAccountingContext({token: address(TOKEN), decimals: 6, currency: uint32(uint160(address(TOKEN)))});
|
|
200
|
-
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
201
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
202
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
203
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
204
|
-
splits[0].beneficiary = payable(multisig());
|
|
205
|
-
splits[0].percent = 10_000;
|
|
206
|
-
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
207
|
-
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
208
|
-
stages[0] = REVStageConfig({
|
|
209
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
210
|
-
autoIssuances: ai,
|
|
211
|
-
splitPercent: 2000,
|
|
212
|
-
splits: splits,
|
|
213
|
-
initialIssuance: uint112(1000e18),
|
|
214
|
-
issuanceCutFrequency: 90 days,
|
|
215
|
-
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
216
|
-
cashOutTaxRate: 6000,
|
|
217
|
-
extraMetadata: 0
|
|
218
|
-
});
|
|
219
|
-
REVLoanSource[] memory ls = new REVLoanSource[](1);
|
|
220
|
-
ls[0] = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
221
|
-
REVConfig memory cfg = REVConfig({
|
|
222
|
-
// forge-lint: disable-next-line(named-struct-fields)
|
|
223
|
-
description: REVDescription("NANA", "$NANA", "ipfs://test2", "NANA_TOKEN"),
|
|
224
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
225
|
-
splitOperator: multisig(),
|
|
226
|
-
stageConfigurations: stages
|
|
227
|
-
});
|
|
228
|
-
(REVNET_ID,) = REV_DEPLOYER.deployFor({
|
|
229
|
-
revnetId: 0,
|
|
230
|
-
configuration: cfg,
|
|
231
|
-
terminalConfigurations: tc,
|
|
232
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
233
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("NANA")
|
|
234
|
-
}),
|
|
235
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
236
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function _setupLoan(
|
|
241
|
-
address user,
|
|
242
|
-
uint256 ethAmount,
|
|
243
|
-
uint256 prepaidFee
|
|
244
|
-
)
|
|
245
|
-
internal
|
|
246
|
-
returns (uint256 loanId, uint256 tokenCount, uint256 borrowAmount)
|
|
247
|
-
{
|
|
248
|
-
vm.prank(user);
|
|
249
|
-
tokenCount =
|
|
250
|
-
jbMultiTerminal().pay{value: ethAmount}(REVNET_ID, JBConstants.NATIVE_TOKEN, ethAmount, user, 0, "", "");
|
|
251
|
-
borrowAmount =
|
|
252
|
-
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokenCount, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
253
|
-
if (borrowAmount == 0) return (0, tokenCount, 0);
|
|
254
|
-
mockExpect(
|
|
255
|
-
address(jbPermissions()),
|
|
256
|
-
abi.encodeCall(IJBPermissions.hasPermission, (address(LOANS_CONTRACT), user, REVNET_ID, 11, true, true)),
|
|
257
|
-
abi.encode(true)
|
|
258
|
-
);
|
|
259
|
-
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
260
|
-
vm.prank(user);
|
|
261
|
-
(loanId,) = LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(user), prepaidFee, user);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// -----------------------------------------------------------------------
|
|
265
|
-
// 1. Zero-amount loan guard: partial repay that rounds to zero triggers full repay
|
|
266
|
-
// -----------------------------------------------------------------------
|
|
267
|
-
|
|
268
|
-
/// @notice When a partial repay would create a zero-amount loan (newBorrowAmount rounds to 0),
|
|
269
|
-
/// the guard should automatically return ALL collateral (full repay path).
|
|
270
|
-
/// Without the guard, a zero-amount loan with leftover collateral would be unrepayable.
|
|
271
|
-
function test_zeroAmountGuard_partialRepayBecomesFullRepay() public {
|
|
272
|
-
// Setup: borrow against 10 ETH
|
|
273
|
-
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
274
|
-
require(loanId != 0, "Loan setup failed");
|
|
275
|
-
|
|
276
|
-
REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
|
|
277
|
-
uint256 originalCollateral = loan.collateral;
|
|
278
|
-
|
|
279
|
-
// Drain most surplus so remaining collateral yields ~0 borrow amount.
|
|
280
|
-
// Cash out most of the surplus from other participants to reduce it drastically.
|
|
281
|
-
// Instead, we'll return nearly all collateral, leaving just 1 token.
|
|
282
|
-
// With very low remaining collateral and bonding curve rounding, newBorrowAmount = 0.
|
|
283
|
-
uint256 collateralToReturn = originalCollateral - 1; // Return all but 1 token
|
|
284
|
-
|
|
285
|
-
JBSingleAllowance memory allowance;
|
|
286
|
-
|
|
287
|
-
vm.prank(USER);
|
|
288
|
-
(uint256 paidOffLoanId, REVLoan memory paidOffLoan) = LOANS_CONTRACT.repayLoan{value: loan.amount}(
|
|
289
|
-
loanId,
|
|
290
|
-
loan.amount, // generous max repay
|
|
291
|
-
collateralToReturn,
|
|
292
|
-
payable(USER),
|
|
293
|
-
allowance
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
// Check: if newBorrowAmount was 0, the guard should have triggered full repayment.
|
|
297
|
-
// This means paidOffLoanId == loanId (original ID returned for full repays)
|
|
298
|
-
// AND paidOffLoan.collateral == 0 AND paidOffLoan.amount == 0.
|
|
299
|
-
if (paidOffLoanId == loanId) {
|
|
300
|
-
// Full repay path was taken — guard worked
|
|
301
|
-
assertEq(paidOffLoan.collateral, 0, "Full repay should have zero collateral");
|
|
302
|
-
assertEq(paidOffLoan.amount, 0, "Full repay should have zero amount");
|
|
303
|
-
} else {
|
|
304
|
-
// Partial repay path — newBorrowAmount was nonzero (rounding didn't hit zero)
|
|
305
|
-
// This is also valid, just means the guard wasn't needed in this case.
|
|
306
|
-
assertTrue(paidOffLoan.amount > 0, "Partial repay should have nonzero amount");
|
|
307
|
-
assertTrue(paidOffLoan.collateral > 0, "Partial repay should have nonzero collateral");
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// -----------------------------------------------------------------------
|
|
312
|
-
// 2. Mint-before-adjust: replacement loan NFT exists before external calls
|
|
313
|
-
// -----------------------------------------------------------------------
|
|
314
|
-
|
|
315
|
-
/// @notice A partial repay (not returning all collateral) should produce a valid new loan NFT
|
|
316
|
-
/// with correct ownership established before any external calls from _adjust.
|
|
317
|
-
function test_mintBeforeAdjust_partialRepayCreatesValidLoan() public {
|
|
318
|
-
// Setup: borrow against 10 ETH
|
|
319
|
-
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
320
|
-
require(loanId != 0, "Loan setup failed");
|
|
321
|
-
|
|
322
|
-
REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
|
|
323
|
-
uint256 collateralToReturn = loan.collateral / 2;
|
|
324
|
-
|
|
325
|
-
JBSingleAllowance memory allowance;
|
|
326
|
-
|
|
327
|
-
vm.prank(USER);
|
|
328
|
-
(uint256 paidOffLoanId, REVLoan memory paidOffLoan) = LOANS_CONTRACT.repayLoan{value: loan.amount}(
|
|
329
|
-
loanId, loan.amount, collateralToReturn, payable(USER), allowance
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
// Partial repay should create a new loan (different ID)
|
|
333
|
-
assertTrue(paidOffLoanId != loanId, "Partial repay should create new loan ID");
|
|
334
|
-
|
|
335
|
-
// New loan should be owned by the caller
|
|
336
|
-
assertEq(
|
|
337
|
-
IERC721(address(LOANS_CONTRACT)).ownerOf(paidOffLoanId), USER, "New loan NFT should be owned by caller"
|
|
338
|
-
);
|
|
339
|
-
|
|
340
|
-
// New loan should have reduced collateral and amount
|
|
341
|
-
assertTrue(paidOffLoan.collateral < loan.collateral, "New loan should have less collateral");
|
|
342
|
-
assertTrue(paidOffLoan.amount < loan.amount, "New loan should have less borrow amount");
|
|
343
|
-
assertTrue(paidOffLoan.collateral > 0, "New loan should have nonzero collateral");
|
|
344
|
-
assertTrue(paidOffLoan.amount > 0, "New loan should have nonzero borrow amount");
|
|
345
|
-
|
|
346
|
-
// Original loan NFT should be burned
|
|
347
|
-
vm.expectRevert();
|
|
348
|
-
IERC721(address(LOANS_CONTRACT)).ownerOf(loanId);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// -----------------------------------------------------------------------
|
|
352
|
-
// 3. Full repay still works correctly (returns original loanId)
|
|
353
|
-
// -----------------------------------------------------------------------
|
|
354
|
-
|
|
355
|
-
/// @notice Full repayment (returning all collateral) should return the original loanId
|
|
356
|
-
/// and zero out the loan. This path doesn't create a new NFT.
|
|
357
|
-
function test_fullRepay_returnsOriginalLoanId() public {
|
|
358
|
-
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
359
|
-
require(loanId != 0, "Loan setup failed");
|
|
360
|
-
|
|
361
|
-
REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
|
|
362
|
-
|
|
363
|
-
JBSingleAllowance memory allowance;
|
|
364
|
-
|
|
365
|
-
vm.prank(USER);
|
|
366
|
-
(uint256 paidOffLoanId, REVLoan memory paidOffLoan) = LOANS_CONTRACT.repayLoan{value: loan.amount}(
|
|
367
|
-
loanId,
|
|
368
|
-
loan.amount,
|
|
369
|
-
loan.collateral, // return ALL collateral
|
|
370
|
-
payable(USER),
|
|
371
|
-
allowance
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
assertEq(paidOffLoanId, loanId, "Full repay should return original loan ID");
|
|
375
|
-
assertEq(paidOffLoan.amount, 0, "Full repay should zero out amount");
|
|
376
|
-
assertEq(paidOffLoan.collateral, 0, "Full repay should zero out collateral");
|
|
377
|
-
}
|
|
378
|
-
}
|