@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,278 +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 {REVLoans} from "../src/REVLoans.sol";
|
|
27
|
-
import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
|
|
28
|
-
import {REVDescription} from "../src/structs/REVDescription.sol";
|
|
29
|
-
import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
|
|
30
|
-
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
31
|
-
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
32
|
-
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
33
|
-
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
34
|
-
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
35
|
-
import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
|
|
36
|
-
import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
|
|
37
|
-
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
38
|
-
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
39
|
-
import {JBBeforePayRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforePayRecordedContext.sol";
|
|
40
|
-
import {JBPayHookSpecification} from "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
|
|
41
|
-
import {JBTokenAmount} from "@bananapus/core-v6/src/structs/JBTokenAmount.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 Tests for PR #22: fix/c2-hook-array-oob
|
|
48
|
-
/// Verifies that the fix for the hook array out-of-bounds bug works correctly.
|
|
49
|
-
/// The bug: `hookSpecifications[1] = buybackHookSpecifications[0]` would revert with OOB
|
|
50
|
-
/// when there is no tiered 721 hook (array size is 1, not 2).
|
|
51
|
-
/// The fix: `hookSpecifications[usesTiered721Hook ? 1 : 0] = buybackHookSpecifications[0]`.
|
|
52
|
-
contract TestHookArrayOOB is TestBaseWorkflow {
|
|
53
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
54
|
-
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
55
|
-
|
|
56
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
57
|
-
REVDeployer REV_DEPLOYER;
|
|
58
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
59
|
-
REVOwner REV_OWNER;
|
|
60
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
61
|
-
JB721TiersHook EXAMPLE_HOOK;
|
|
62
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
63
|
-
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
64
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
65
|
-
IJB721TiersHookStore HOOK_STORE;
|
|
66
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
67
|
-
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
68
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
69
|
-
IREVLoans LOANS_CONTRACT;
|
|
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
|
-
|
|
80
|
-
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
81
|
-
// forge-lint: disable-next-line(mixed-case-variable)
|
|
82
|
-
address USER = makeAddr("user");
|
|
83
|
-
|
|
84
|
-
function setUp() public override {
|
|
85
|
-
super.setUp();
|
|
86
|
-
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
87
|
-
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
88
|
-
HOOK_STORE = new JB721TiersHookStore();
|
|
89
|
-
EXAMPLE_HOOK = new JB721TiersHook(
|
|
90
|
-
jbDirectory(),
|
|
91
|
-
jbPermissions(),
|
|
92
|
-
jbPrices(),
|
|
93
|
-
jbRulesets(),
|
|
94
|
-
HOOK_STORE,
|
|
95
|
-
jbSplits(),
|
|
96
|
-
IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
|
|
97
|
-
multisig()
|
|
98
|
-
);
|
|
99
|
-
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
100
|
-
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
101
|
-
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
102
|
-
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
103
|
-
LOANS_CONTRACT = new REVLoans({
|
|
104
|
-
controller: jbController(),
|
|
105
|
-
suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
|
|
106
|
-
revId: FEE_PROJECT_ID,
|
|
107
|
-
owner: address(this),
|
|
108
|
-
permit2: permit2(),
|
|
109
|
-
trustedForwarder: TRUSTED_FORWARDER
|
|
110
|
-
});
|
|
111
|
-
REV_OWNER = new REVOwner(
|
|
112
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
113
|
-
jbDirectory(),
|
|
114
|
-
FEE_PROJECT_ID,
|
|
115
|
-
SUCKER_REGISTRY,
|
|
116
|
-
address(LOANS_CONTRACT),
|
|
117
|
-
address(0)
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
121
|
-
jbController(),
|
|
122
|
-
SUCKER_REGISTRY,
|
|
123
|
-
FEE_PROJECT_ID,
|
|
124
|
-
HOOK_DEPLOYER,
|
|
125
|
-
PUBLISHER,
|
|
126
|
-
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
127
|
-
address(LOANS_CONTRACT),
|
|
128
|
-
TRUSTED_FORWARDER,
|
|
129
|
-
address(REV_OWNER)
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
REV_OWNER.setDeployer(REV_DEPLOYER);
|
|
133
|
-
|
|
134
|
-
vm.prank(multisig());
|
|
135
|
-
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/// @notice Helper to build a minimal revnet config with no hooks.
|
|
139
|
-
function _buildMinimalConfig()
|
|
140
|
-
internal
|
|
141
|
-
view
|
|
142
|
-
returns (REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc)
|
|
143
|
-
{
|
|
144
|
-
JBAccountingContext[] memory acc = new JBAccountingContext[](1);
|
|
145
|
-
acc[0] = JBAccountingContext({
|
|
146
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
147
|
-
});
|
|
148
|
-
tc = new JBTerminalConfig[](1);
|
|
149
|
-
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
150
|
-
|
|
151
|
-
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
152
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
153
|
-
splits[0].beneficiary = payable(multisig());
|
|
154
|
-
splits[0].percent = 10_000;
|
|
155
|
-
stages[0] = REVStageConfig({
|
|
156
|
-
startsAtOrAfter: uint40(block.timestamp),
|
|
157
|
-
autoIssuances: new REVAutoIssuance[](0),
|
|
158
|
-
splitPercent: 0,
|
|
159
|
-
splits: splits,
|
|
160
|
-
initialIssuance: uint112(1000e18),
|
|
161
|
-
issuanceCutFrequency: 0,
|
|
162
|
-
issuanceCutPercent: 0,
|
|
163
|
-
cashOutTaxRate: 5000,
|
|
164
|
-
extraMetadata: 0
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
cfg = REVConfig({
|
|
168
|
-
// forge-lint: disable-next-line(named-struct-fields)
|
|
169
|
-
description: REVDescription("Test", "TST", "ipfs://test", "TEST_SALT"),
|
|
170
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
171
|
-
splitOperator: multisig(),
|
|
172
|
-
stageConfigurations: stages
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
sdc = REVSuckerDeploymentConfig({
|
|
176
|
-
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("TEST"))
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/// @notice Helper to deploy the fee project first and then deploy a test revnet.
|
|
181
|
-
function _deployFeeAndRevnet() internal returns (uint256 revnetId) {
|
|
182
|
-
(REVConfig memory feeCfg, JBTerminalConfig[] memory feeTc, REVSuckerDeploymentConfig memory feeSdc) =
|
|
183
|
-
_buildMinimalConfig();
|
|
184
|
-
|
|
185
|
-
// Deploy the fee project
|
|
186
|
-
vm.prank(multisig());
|
|
187
|
-
REV_DEPLOYER.deployFor({
|
|
188
|
-
revnetId: FEE_PROJECT_ID,
|
|
189
|
-
configuration: feeCfg,
|
|
190
|
-
terminalConfigurations: feeTc,
|
|
191
|
-
suckerDeploymentConfiguration: feeSdc,
|
|
192
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
193
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
// Deploy a new test revnet (revnetId: 0 = create new)
|
|
197
|
-
(REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc) =
|
|
198
|
-
_buildMinimalConfig();
|
|
199
|
-
// Use a different salt so the ERC20 deploy doesn't clash
|
|
200
|
-
// forge-lint: disable-next-line(named-struct-fields)
|
|
201
|
-
cfg.description = REVDescription("Test2", "TS2", "ipfs://test2", "TEST_SALT_2");
|
|
202
|
-
|
|
203
|
-
(revnetId,) = REV_DEPLOYER.deployFor({
|
|
204
|
-
revnetId: 0,
|
|
205
|
-
configuration: cfg,
|
|
206
|
-
terminalConfigurations: tc,
|
|
207
|
-
suckerDeploymentConfiguration: sdc,
|
|
208
|
-
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
209
|
-
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/// @notice Test that paying a revnet with no hooks (no 721, no buyback) works fine.
|
|
214
|
-
/// This exercises beforePayRecordedWith where both usesTiered721Hook and usesBuybackHook are false.
|
|
215
|
-
function test_payRevnet_noHooks_works() public {
|
|
216
|
-
uint256 revnetId = _deployFeeAndRevnet();
|
|
217
|
-
|
|
218
|
-
// Pay into the revnet
|
|
219
|
-
vm.deal(USER, 1 ether);
|
|
220
|
-
vm.prank(USER);
|
|
221
|
-
jbMultiTerminal().pay{value: 1 ether}({
|
|
222
|
-
projectId: revnetId,
|
|
223
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
224
|
-
amount: 1 ether,
|
|
225
|
-
beneficiary: USER,
|
|
226
|
-
minReturnedTokens: 0,
|
|
227
|
-
memo: "test payment",
|
|
228
|
-
metadata: ""
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// Verify tokens were minted
|
|
232
|
-
uint256 balance = jbTokens().totalBalanceOf(USER, revnetId);
|
|
233
|
-
assertGt(balance, 0, "Should have received tokens from payment");
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/// @notice Test the array index logic directly: `usesTiered721Hook ? 1 : 0` gives index 0 for buyback-only.
|
|
237
|
-
function test_arrayIndexLogic_unitTest() public pure {
|
|
238
|
-
// When no tiered 721 hook is present, the buyback hook should be at index 0
|
|
239
|
-
bool usesTiered721Hook = false;
|
|
240
|
-
uint256 buybackIndex = usesTiered721Hook ? 1 : 0;
|
|
241
|
-
assertEq(buybackIndex, 0, "Buyback hook index should be 0 when no 721 hook");
|
|
242
|
-
|
|
243
|
-
// When tiered 721 hook IS present, the buyback hook should be at index 1
|
|
244
|
-
usesTiered721Hook = true;
|
|
245
|
-
buybackIndex = usesTiered721Hook ? 1 : 0;
|
|
246
|
-
assertEq(buybackIndex, 1, "Buyback hook index should be 1 when 721 hook present");
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/// @notice Test that beforePayRecordedWith returns correct hook specification counts.
|
|
250
|
-
/// Every revnet now has both a buyback hook and a 721 hook.
|
|
251
|
-
function test_beforePayRecordedWith_returnsHookSpecs() public {
|
|
252
|
-
uint256 revnetId = _deployFeeAndRevnet();
|
|
253
|
-
|
|
254
|
-
// Build a mock context for beforePayRecordedWith
|
|
255
|
-
JBBeforePayRecordedContext memory context = JBBeforePayRecordedContext({
|
|
256
|
-
terminal: address(jbMultiTerminal()),
|
|
257
|
-
payer: USER,
|
|
258
|
-
amount: JBTokenAmount({
|
|
259
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
260
|
-
value: 1 ether,
|
|
261
|
-
decimals: 18,
|
|
262
|
-
currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
263
|
-
}),
|
|
264
|
-
projectId: revnetId,
|
|
265
|
-
rulesetId: 0,
|
|
266
|
-
beneficiary: USER,
|
|
267
|
-
weight: 1000e18,
|
|
268
|
-
reservedPercent: 0,
|
|
269
|
-
metadata: ""
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
(uint256 weight, JBPayHookSpecification[] memory specs) = REV_OWNER.beforePayRecordedWith(context);
|
|
273
|
-
|
|
274
|
-
// Every revnet has both the buyback hook and the 721 hook.
|
|
275
|
-
assertEq(weight, context.weight, "Weight should be the default context weight");
|
|
276
|
-
assertEq(specs.length, 2, "Should have buyback hook and 721 hook specifications");
|
|
277
|
-
}
|
|
278
|
-
}
|
|
@@ -1,398 +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
|
-
import {REVEmpty721Config} from "./helpers/REVEmpty721Config.sol";
|
|
15
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
16
|
-
import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
17
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
18
|
-
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
19
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
20
|
-
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
21
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
22
|
-
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
23
|
-
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
24
|
-
import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
|
|
25
|
-
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
26
|
-
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
27
|
-
import {JBSingleAllowance} from "@bananapus/core-v6/src/structs/JBSingleAllowance.sol";
|
|
28
|
-
import {MockPriceFeed} from "@bananapus/core-v6/test/mock/MockPriceFeed.sol";
|
|
29
|
-
import {MockERC20} from "@bananapus/core-v6/test/mock/MockERC20.sol";
|
|
30
|
-
import {REVLoans} from "../src/REVLoans.sol";
|
|
31
|
-
import {REVLoan} from "../src/structs/REVLoan.sol";
|
|
32
|
-
import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
|
|
33
|
-
import {REVLoanSource} from "../src/structs/REVLoanSource.sol";
|
|
34
|
-
import {REVDescription} from "../src/structs/REVDescription.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 {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|
45
|
-
import {REVOwner} from "../src/REVOwner.sol";
|
|
46
|
-
import {IREVDeployer} from "../src/interfaces/IREVDeployer.sol";
|
|
47
|
-
import {MockSuckerRegistry} from "./mock/MockSuckerRegistry.sol";
|
|
48
|
-
|
|
49
|
-
/// @notice Tests for PR #10: liquidation behavior documentation and collateral burn mechanics.
|
|
50
|
-
contract TestLiquidationBehavior 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
|
-
// 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
|
-
/// @notice Verify that collateral is burned (not escrowed) — totalCollateralOf increases and loans contract holds
|
|
265
|
-
/// no tokens.
|
|
266
|
-
function test_collateralBurnedNotEscrowed() public {
|
|
267
|
-
uint256 totalCollateralBefore = LOANS_CONTRACT.totalCollateralOf(REVNET_ID);
|
|
268
|
-
assertEq(totalCollateralBefore, 0, "No collateral before any loans");
|
|
269
|
-
|
|
270
|
-
// User pays to get tokens
|
|
271
|
-
vm.prank(USER);
|
|
272
|
-
uint256 tokenCount =
|
|
273
|
-
jbMultiTerminal().pay{value: 10e18}(REVNET_ID, JBConstants.NATIVE_TOKEN, 10e18, USER, 0, "", "");
|
|
274
|
-
|
|
275
|
-
// Now borrow (which burns collateral tokens)
|
|
276
|
-
uint256 borrowAmount =
|
|
277
|
-
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, tokenCount, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
278
|
-
require(borrowAmount > 0, "Borrow amount should be > 0");
|
|
279
|
-
|
|
280
|
-
mockExpect(
|
|
281
|
-
address(jbPermissions()),
|
|
282
|
-
abi.encodeCall(IJBPermissions.hasPermission, (address(LOANS_CONTRACT), USER, REVNET_ID, 11, true, true)),
|
|
283
|
-
abi.encode(true)
|
|
284
|
-
);
|
|
285
|
-
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
286
|
-
vm.prank(USER);
|
|
287
|
-
LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(USER), 25, USER);
|
|
288
|
-
|
|
289
|
-
uint256 totalCollateralAfterBorrow = LOANS_CONTRACT.totalCollateralOf(REVNET_ID);
|
|
290
|
-
|
|
291
|
-
// totalCollateralOf should have increased by tokenCount (bookkeeping for burned collateral)
|
|
292
|
-
assertEq(
|
|
293
|
-
totalCollateralAfterBorrow,
|
|
294
|
-
totalCollateralBefore + tokenCount,
|
|
295
|
-
"Total collateral tracking should increase by the collateral amount"
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
// The loans contract should NOT hold any project tokens — they are burned, not escrowed.
|
|
299
|
-
// Check that the REVLoans contract has zero balance of the project's ERC20 token.
|
|
300
|
-
uint256 loansTokenBalance = jbTokens().totalBalanceOf(address(LOANS_CONTRACT), REVNET_ID);
|
|
301
|
-
assertEq(loansTokenBalance, 0, "Loans contract should hold zero project tokens (burned, not escrowed)");
|
|
302
|
-
|
|
303
|
-
// Note: The user may hold some project tokens received as fee payment beneficiary during borrowing.
|
|
304
|
-
// The key point is that the LOANS CONTRACT holds zero — collateral is burned, not escrowed.
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/// @notice Verify borrower receives ETH from borrowing.
|
|
308
|
-
function test_borrowerKeepsBorrowedFunds() public {
|
|
309
|
-
uint256 userBalanceBefore = USER.balance;
|
|
310
|
-
|
|
311
|
-
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
312
|
-
require(loanId != 0, "Loan setup failed");
|
|
313
|
-
|
|
314
|
-
uint256 userBalanceAfter = USER.balance;
|
|
315
|
-
|
|
316
|
-
// User spent 10 ETH paying in, then received borrowAmount minus fees.
|
|
317
|
-
// The net balance change: -10 ETH (payment) + borrowed funds received
|
|
318
|
-
// Borrowed funds = borrowAmount minus protocol fee (2.5%) minus REV fee (1%) minus prepaid source fee (2.5%)
|
|
319
|
-
// The user's balance should have increased relative to the post-payment balance.
|
|
320
|
-
// Since _setupLoan sends ETH to pay AND receives borrow, let's just check:
|
|
321
|
-
// userBalanceAfter should be > (userBalanceBefore - 10e18) because they received borrowed funds
|
|
322
|
-
assertTrue(userBalanceAfter > userBalanceBefore - 10e18, "Borrower should have received ETH from the loan");
|
|
323
|
-
|
|
324
|
-
// Furthermore, the amount received should be meaningful (not zero)
|
|
325
|
-
// The borrow amount minus all fees should still be positive
|
|
326
|
-
assertTrue(userBalanceAfter > userBalanceBefore - 10e18, "Borrower keeps borrowed funds");
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/// @notice Repay before expiry returns collateral (re-mints tokens).
|
|
330
|
-
function test_repayBeforeExpiry_collateralReminted() public {
|
|
331
|
-
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
332
|
-
require(loanId != 0, "Loan setup failed");
|
|
333
|
-
|
|
334
|
-
REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
|
|
335
|
-
uint256 totalCollateralAfterBorrow = LOANS_CONTRACT.totalCollateralOf(REVNET_ID);
|
|
336
|
-
assertTrue(totalCollateralAfterBorrow > 0, "Should have collateral tracking after borrow");
|
|
337
|
-
|
|
338
|
-
// Repay the full loan (returning all collateral)
|
|
339
|
-
JBSingleAllowance memory allowance;
|
|
340
|
-
vm.prank(USER);
|
|
341
|
-
LOANS_CONTRACT.repayLoan{value: loan.amount}(
|
|
342
|
-
loanId,
|
|
343
|
-
loan.amount,
|
|
344
|
-
loan.collateral, // return all collateral
|
|
345
|
-
payable(USER),
|
|
346
|
-
allowance
|
|
347
|
-
);
|
|
348
|
-
|
|
349
|
-
// After full repayment, totalCollateralOf should return to 0
|
|
350
|
-
uint256 totalCollateralAfterRepay = LOANS_CONTRACT.totalCollateralOf(REVNET_ID);
|
|
351
|
-
assertEq(totalCollateralAfterRepay, 0, "Total collateral should be 0 after full repay (collateral re-minted)");
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/// @notice After liquidation, the loan NFT is burned and collateral/borrow tracking is decremented.
|
|
355
|
-
function test_loanDataDeletedAfterLiquidation() public {
|
|
356
|
-
(uint256 loanId,,) = _setupLoan(USER, 10e18, 25);
|
|
357
|
-
require(loanId != 0, "Loan setup failed");
|
|
358
|
-
|
|
359
|
-
REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
|
|
360
|
-
uint256 totalCollateralBefore = LOANS_CONTRACT.totalCollateralOf(REVNET_ID);
|
|
361
|
-
uint256 totalBorrowedBefore =
|
|
362
|
-
LOANS_CONTRACT.totalBorrowedFrom(REVNET_ID, jbMultiTerminal(), JBConstants.NATIVE_TOKEN);
|
|
363
|
-
|
|
364
|
-
assertTrue(totalCollateralBefore > 0, "Should have collateral before liquidation");
|
|
365
|
-
assertTrue(totalBorrowedBefore > 0, "Should have borrowed amount before liquidation");
|
|
366
|
-
|
|
367
|
-
// Warp past the liquidation duration
|
|
368
|
-
vm.warp(loan.createdAt + LOANS_CONTRACT.LOAN_LIQUIDATION_DURATION() + 1);
|
|
369
|
-
|
|
370
|
-
// Get the loan number (loanId = revnetId * 1_000_000_000_000 + loanNumber)
|
|
371
|
-
uint256 loanNumber = loanId - (REVNET_ID * 1_000_000_000_000);
|
|
372
|
-
|
|
373
|
-
// Liquidate the loan
|
|
374
|
-
LOANS_CONTRACT.liquidateExpiredLoansFrom(REVNET_ID, loanNumber, 1);
|
|
375
|
-
|
|
376
|
-
// After liquidation:
|
|
377
|
-
// 1. The NFT should be burned (ownerOf should revert)
|
|
378
|
-
vm.expectRevert();
|
|
379
|
-
IERC721(address(LOANS_CONTRACT)).ownerOf(loanId);
|
|
380
|
-
|
|
381
|
-
// 2. totalCollateralOf should be decremented
|
|
382
|
-
uint256 totalCollateralAfter = LOANS_CONTRACT.totalCollateralOf(REVNET_ID);
|
|
383
|
-
assertEq(totalCollateralAfter, 0, "Collateral tracking should be 0 after liquidation");
|
|
384
|
-
|
|
385
|
-
// 3. totalBorrowedFrom should be decremented
|
|
386
|
-
uint256 totalBorrowedAfter =
|
|
387
|
-
LOANS_CONTRACT.totalBorrowedFrom(REVNET_ID, jbMultiTerminal(), JBConstants.NATIVE_TOKEN);
|
|
388
|
-
assertEq(totalBorrowedAfter, 0, "Borrowed tracking should be 0 after liquidation");
|
|
389
|
-
|
|
390
|
-
// 4. The loan data in _loanOf[loanId] is NOT deleted (no `delete` statement),
|
|
391
|
-
// but the loan is effectively dead since the NFT is burned and tracking is zeroed.
|
|
392
|
-
REVLoan memory loanAfter = LOANS_CONTRACT.loanOf(loanId);
|
|
393
|
-
// The loan struct data is deleted for a gas refund (delete _loanOf[loanId]).
|
|
394
|
-
assertEq(loanAfter.amount, 0, "Loan data should be cleared after liquidation");
|
|
395
|
-
assertEq(loanAfter.collateral, 0, "Loan collateral should be cleared after liquidation");
|
|
396
|
-
assertEq(loanAfter.createdAt, 0, "Loan createdAt should be cleared after liquidation");
|
|
397
|
-
}
|
|
398
|
-
}
|