@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,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 {MockPriceFeed} from "@bananapus/core-v6/test/mock/MockPriceFeed.sol";
|
|
27
|
-
import {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.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 {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
|
|
34
|
-
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
35
|
-
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
36
|
-
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
37
|
-
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
38
|
-
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
39
|
-
import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
|
|
40
|
-
import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
|
|
41
|
-
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
42
|
-
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
43
|
-
import {REVEmpty721Config} from "./helpers/REVEmpty721Config.sol";
|
|
44
|
-
import {REVOwner} from "../src/REVOwner.sol";
|
|
45
|
-
import {IREVDeployer} from "../src/interfaces/IREVDeployer.sol";
|
|
46
|
-
import {MockSuckerRegistry} from "./mock/MockSuckerRegistry.sol";
|
|
47
|
-
|
|
48
|
-
/// @notice Tests for PR #13: cross-source reallocation prevention.
|
|
49
|
-
contract TestCrossSourceReallocation is TestBaseWorkflow {
|
|
50
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
51
|
-
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
52
|
-
|
|
53
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
54
|
-
REVDeployer REV_DEPLOYER;
|
|
55
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
56
|
-
REVOwner REV_OWNER;
|
|
57
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
58
|
-
JB721TiersHook EXAMPLE_HOOK;
|
|
59
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
60
|
-
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
61
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
62
|
-
IJB721TiersHookStore HOOK_STORE;
|
|
63
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
64
|
-
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
65
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
66
|
-
IREVLoans LOANS_CONTRACT;
|
|
67
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
68
|
-
MockERC20 TOKEN;
|
|
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 USER = makeAddr("user");
|
|
83
|
-
|
|
84
|
-
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
85
|
-
|
|
86
|
-
function setUp() public override {
|
|
87
|
-
super.setUp();
|
|
88
|
-
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
89
|
-
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
90
|
-
HOOK_STORE = new JB721TiersHookStore();
|
|
91
|
-
EXAMPLE_HOOK = new JB721TiersHook(
|
|
92
|
-
jbDirectory(),
|
|
93
|
-
jbPermissions(),
|
|
94
|
-
jbPrices(),
|
|
95
|
-
jbRulesets(),
|
|
96
|
-
HOOK_STORE,
|
|
97
|
-
jbSplits(),
|
|
98
|
-
IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
|
|
99
|
-
multisig()
|
|
100
|
-
);
|
|
101
|
-
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
102
|
-
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
103
|
-
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
104
|
-
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
105
|
-
TOKEN = new MockERC20("1/2 ETH", "1/2");
|
|
106
|
-
MockPriceFeed priceFeed = new MockPriceFeed(1e21, 6);
|
|
107
|
-
vm.prank(multisig());
|
|
108
|
-
jbPrices()
|
|
109
|
-
.addPriceFeedFor(0, uint32(uint160(address(TOKEN))), uint32(uint160(JBConstants.NATIVE_TOKEN)), priceFeed);
|
|
110
|
-
LOANS_CONTRACT = new REVLoans({
|
|
111
|
-
controller: jbController(),
|
|
112
|
-
suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
|
|
113
|
-
revId: FEE_PROJECT_ID,
|
|
114
|
-
owner: address(this),
|
|
115
|
-
permit2: permit2(),
|
|
116
|
-
trustedForwarder: TRUSTED_FORWARDER
|
|
117
|
-
});
|
|
118
|
-
REV_OWNER = new REVOwner(
|
|
119
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
120
|
-
jbDirectory(),
|
|
121
|
-
FEE_PROJECT_ID,
|
|
122
|
-
SUCKER_REGISTRY,
|
|
123
|
-
address(LOANS_CONTRACT),
|
|
124
|
-
address(0)
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
128
|
-
jbController(),
|
|
129
|
-
SUCKER_REGISTRY,
|
|
130
|
-
FEE_PROJECT_ID,
|
|
131
|
-
HOOK_DEPLOYER,
|
|
132
|
-
PUBLISHER,
|
|
133
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
134
|
-
address(LOANS_CONTRACT),
|
|
135
|
-
TRUSTED_FORWARDER,
|
|
136
|
-
address(REV_OWNER)
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
REV_OWNER.setDeployer(REV_DEPLOYER);
|
|
140
|
-
|
|
141
|
-
vm.prank(multisig());
|
|
142
|
-
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
143
|
-
_deployFeeProject();
|
|
144
|
-
_deployRevnet();
|
|
145
|
-
vm.deal(USER, 1000e18);
|
|
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
|
-
REVLoanSource[] memory ls = new REVLoanSource[](1);
|
|
219
|
-
ls[0] = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
220
|
-
REVConfig memory cfg = REVConfig({
|
|
221
|
-
// forge-lint: disable-next-line(named-struct-fields)
|
|
222
|
-
description: REVDescription("NANA", "$NANA", "ipfs://test2", "NANA_TOKEN"),
|
|
223
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
224
|
-
splitOperator: multisig(),
|
|
225
|
-
stageConfigurations: stages
|
|
226
|
-
});
|
|
227
|
-
(REVNET_ID,) = REV_DEPLOYER.deployFor({
|
|
228
|
-
revnetId: 0,
|
|
229
|
-
configuration: cfg,
|
|
230
|
-
terminalConfigurations: tc,
|
|
231
|
-
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
232
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("NANA")
|
|
233
|
-
}),
|
|
234
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
235
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function _setupLoan(
|
|
240
|
-
address user,
|
|
241
|
-
uint256 ethAmount,
|
|
242
|
-
uint256 prepaidFee
|
|
243
|
-
)
|
|
244
|
-
internal
|
|
245
|
-
returns (uint256 loanId, uint256 tokenCount, uint256 borrowAmount)
|
|
246
|
-
{
|
|
247
|
-
vm.prank(user);
|
|
248
|
-
tokenCount =
|
|
249
|
-
jbMultiTerminal().pay{value: ethAmount}(REVNET_ID, JBConstants.NATIVE_TOKEN, ethAmount, user, 0, "", "");
|
|
250
|
-
borrowAmount =
|
|
251
|
-
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokenCount, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
252
|
-
if (borrowAmount == 0) return (0, tokenCount, 0);
|
|
253
|
-
mockExpect(
|
|
254
|
-
address(jbPermissions()),
|
|
255
|
-
abi.encodeCall(IJBPermissions.hasPermission, (address(LOANS_CONTRACT), user, REVNET_ID, 11, true, true)),
|
|
256
|
-
abi.encode(true)
|
|
257
|
-
);
|
|
258
|
-
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
259
|
-
vm.prank(user);
|
|
260
|
-
(loanId,) = LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(user), prepaidFee, user);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/// @notice Reallocating with the same source (token + terminal) should succeed.
|
|
264
|
-
function test_reallocateWithSameSource_succeeds() public {
|
|
265
|
-
// Setup: user pays and borrows
|
|
266
|
-
(uint256 loanId, uint256 tokenCount,) = _setupLoan(USER, 10e18, 25);
|
|
267
|
-
require(loanId != 0, "Loan setup failed");
|
|
268
|
-
|
|
269
|
-
// Donate a large amount to inflate surplus, making each collateral token worth significantly more.
|
|
270
|
-
// This ensures that after removing some collateral, the remaining collateral still supports the loan amount.
|
|
271
|
-
address donor = makeAddr("donor");
|
|
272
|
-
vm.deal(donor, 500e18);
|
|
273
|
-
vm.prank(donor);
|
|
274
|
-
jbMultiTerminal().addToBalanceOf{value: 500e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 500e18, false, "", "");
|
|
275
|
-
|
|
276
|
-
// User pays more to get additional tokens for the new loan's extra collateral
|
|
277
|
-
vm.prank(USER);
|
|
278
|
-
uint256 extraTokens =
|
|
279
|
-
jbMultiTerminal().pay{value: 50e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 50e18, USER, 0, "", "");
|
|
280
|
-
|
|
281
|
-
// Transfer a small portion of collateral so the remaining collateral (now worth much more) supports the loan
|
|
282
|
-
uint256 collateralToTransfer = tokenCount / 10; // Transfer 10% of collateral
|
|
283
|
-
|
|
284
|
-
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
285
|
-
|
|
286
|
-
// Mock burn permission for the new loan's borrowFrom call
|
|
287
|
-
mockExpect(
|
|
288
|
-
address(jbPermissions()),
|
|
289
|
-
abi.encodeCall(IJBPermissions.hasPermission, (address(LOANS_CONTRACT), USER, REVNET_ID, 11, true, true)),
|
|
290
|
-
abi.encode(true)
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
vm.prank(USER);
|
|
294
|
-
(uint256 reallocatedLoanId, uint256 newLoanId,,) = LOANS_CONTRACT.reallocateCollateralFromLoan(
|
|
295
|
-
loanId,
|
|
296
|
-
collateralToTransfer,
|
|
297
|
-
source,
|
|
298
|
-
0, // minBorrowAmount
|
|
299
|
-
extraTokens, // collateralCountToAdd
|
|
300
|
-
payable(USER),
|
|
301
|
-
25 // prepaidFeePercent
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
// Verify both loans exist
|
|
305
|
-
assertTrue(reallocatedLoanId != 0, "Reallocated loan should exist");
|
|
306
|
-
assertTrue(newLoanId != 0, "New loan should exist");
|
|
307
|
-
|
|
308
|
-
// Verify new loan has correct source
|
|
309
|
-
REVLoan memory newLoan = LOANS_CONTRACT.loanOf(newLoanId);
|
|
310
|
-
assertEq(newLoan.source.token, JBConstants.NATIVE_TOKEN, "New loan source token should match");
|
|
311
|
-
assertEq(address(newLoan.source.terminal), address(jbMultiTerminal()), "New loan source terminal should match");
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/// @notice Reallocating with a different token should revert with SourceMismatch.
|
|
315
|
-
function test_reallocateWithDifferentToken_reverts() public {
|
|
316
|
-
// Setup: user pays and borrows with NATIVE_TOKEN source
|
|
317
|
-
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
318
|
-
require(loanId != 0, "Loan setup failed");
|
|
319
|
-
|
|
320
|
-
// Try to reallocate with a different token (TOKEN instead of NATIVE_TOKEN)
|
|
321
|
-
REVLoanSource memory wrongSource = REVLoanSource({token: address(TOKEN), terminal: jbMultiTerminal()});
|
|
322
|
-
|
|
323
|
-
vm.prank(USER);
|
|
324
|
-
vm.expectRevert(REVLoans.REVLoans_SourceMismatch.selector);
|
|
325
|
-
LOANS_CONTRACT.reallocateCollateralFromLoan(
|
|
326
|
-
loanId,
|
|
327
|
-
1, // collateralCountToTransfer (any nonzero value)
|
|
328
|
-
wrongSource,
|
|
329
|
-
0, // minBorrowAmount
|
|
330
|
-
0, // collateralCountToAdd
|
|
331
|
-
payable(USER),
|
|
332
|
-
25 // prepaidFeePercent
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/// @notice Reallocating with a different terminal should revert with SourceMismatch.
|
|
337
|
-
function test_reallocateWithDifferentTerminal_reverts() public {
|
|
338
|
-
// Setup: user pays and borrows with jbMultiTerminal
|
|
339
|
-
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
340
|
-
require(loanId != 0, "Loan setup failed");
|
|
341
|
-
|
|
342
|
-
// Create a fake terminal address
|
|
343
|
-
address fakeTerminal = makeAddr("fakeTerminal");
|
|
344
|
-
|
|
345
|
-
// Try to reallocate with a different terminal
|
|
346
|
-
REVLoanSource memory wrongSource =
|
|
347
|
-
REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: IJBPayoutTerminal(fakeTerminal)});
|
|
348
|
-
|
|
349
|
-
vm.prank(USER);
|
|
350
|
-
vm.expectRevert(REVLoans.REVLoans_SourceMismatch.selector);
|
|
351
|
-
LOANS_CONTRACT.reallocateCollateralFromLoan(
|
|
352
|
-
loanId,
|
|
353
|
-
1, // collateralCountToTransfer
|
|
354
|
-
wrongSource,
|
|
355
|
-
0, // minBorrowAmount
|
|
356
|
-
0, // collateralCountToAdd
|
|
357
|
-
payable(USER),
|
|
358
|
-
25 // prepaidFeePercent
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
}
|