@rev-net/core-v6 0.0.11 → 0.0.13
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/ADMINISTRATION.md +7 -7
- package/ARCHITECTURE.md +11 -11
- package/AUDIT_INSTRUCTIONS.md +295 -0
- package/CHANGE_LOG.md +316 -0
- package/README.md +9 -6
- package/RISKS.md +180 -35
- package/SKILLS.md +9 -11
- package/STYLE_GUIDE.md +14 -1
- package/USER_JOURNEYS.md +489 -0
- package/package.json +9 -9
- package/script/Deploy.s.sol +124 -40
- package/script/helpers/RevnetCoreDeploymentLib.sol +19 -6
- package/src/REVDeployer.sol +183 -175
- package/src/REVLoans.sol +65 -28
- package/src/interfaces/IREVDeployer.sol +25 -23
- package/src/structs/REV721TiersHookFlags.sol +1 -0
- package/src/structs/REVAutoIssuance.sol +1 -0
- package/src/structs/REVBaseline721HookConfig.sol +1 -0
- package/src/structs/REVConfig.sol +1 -0
- package/src/structs/REVCroptopAllowedPost.sol +1 -0
- package/src/structs/REVDeploy721TiersHookConfig.sol +13 -14
- package/src/structs/REVDescription.sol +1 -0
- package/src/structs/REVLoan.sol +1 -0
- package/src/structs/REVLoanSource.sol +1 -0
- package/src/structs/REVStageConfig.sol +1 -0
- package/src/structs/REVSuckerDeploymentConfig.sol +1 -0
- package/test/REV.integrations.t.sol +148 -19
- package/test/REVAutoIssuanceFuzz.t.sol +31 -6
- package/test/REVDeployerRegressions.t.sol +47 -9
- package/test/REVInvincibility.t.sol +83 -19
- package/test/REVInvincibilityHandler.sol +29 -0
- package/test/REVLifecycle.t.sol +36 -6
- package/test/REVLoans.invariants.t.sol +64 -10
- package/test/REVLoansAttacks.t.sol +54 -9
- package/test/REVLoansFeeRecovery.t.sol +61 -15
- package/test/REVLoansFindings.t.sol +42 -9
- package/test/REVLoansRegressions.t.sol +33 -6
- package/test/REVLoansSourceFeeRecovery.t.sol +491 -0
- package/test/REVLoansSourced.t.sol +79 -17
- package/test/REVLoansUnSourced.t.sol +61 -10
- package/test/TestBurnHeldTokens.t.sol +47 -11
- package/test/TestCEIPattern.t.sol +37 -6
- package/test/TestCashOutCallerValidation.t.sol +41 -8
- package/test/TestConversionDocumentation.t.sol +50 -13
- package/test/TestCrossCurrencyReclaim.t.sol +584 -0
- package/test/TestCrossSourceReallocation.t.sol +37 -6
- package/test/TestERC2771MetaTx.t.sol +557 -0
- package/test/TestEmptyBuybackSpecs.t.sol +45 -10
- package/test/TestFlashLoanSurplus.t.sol +39 -7
- package/test/TestHookArrayOOB.t.sol +42 -13
- package/test/TestLiquidationBehavior.t.sol +37 -7
- package/test/TestLoanSourceRotation.t.sol +525 -0
- package/test/TestLongTailEconomics.t.sol +651 -0
- package/test/TestLowFindings.t.sol +80 -8
- package/test/TestMixedFixes.t.sol +43 -9
- package/test/TestPermit2Signatures.t.sol +657 -0
- package/test/TestReallocationSandwich.t.sol +384 -0
- package/test/TestRevnetRegressions.t.sol +324 -0
- package/test/TestSplitWeightAdjustment.t.sol +52 -13
- package/test/TestSplitWeightE2E.t.sol +53 -18
- package/test/TestSplitWeightFork.t.sol +66 -21
- package/test/TestStageTransitionBorrowable.t.sol +38 -6
- package/test/TestSwapTerminalPermission.t.sol +37 -7
- package/test/TestUint112Overflow.t.sol +39 -6
- package/test/TestZeroRepayment.t.sol +37 -6
- package/test/fork/ForkTestBase.sol +66 -17
- package/test/fork/TestCashOutFork.t.sol +9 -3
- package/test/fork/TestLoanBorrowFork.t.sol +1 -0
- package/test/fork/TestLoanCrossRulesetFork.t.sol +11 -3
- package/test/fork/TestLoanLiquidationFork.t.sol +1 -0
- package/test/fork/TestLoanReallocateFork.t.sol +1 -0
- package/test/fork/TestLoanRepayFork.t.sol +1 -0
- package/test/fork/TestLoanTransferFork.t.sol +133 -0
- package/test/fork/TestSplitWeightFork.t.sol +3 -0
- package/test/helpers/REVEmpty721Config.sol +46 -0
- package/test/mock/MockBuybackDataHook.sol +1 -0
- package/test/regression/TestBurnPermissionRequired.t.sol +267 -0
- package/test/regression/TestCrossRevnetLiquidation.t.sol +228 -0
- package/test/regression/TestCumulativeLoanCounter.t.sol +38 -8
- package/test/regression/TestLiquidateGapHandling.t.sol +40 -8
- package/test/regression/TestZeroPriceFeed.t.sol +396 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.26;
|
|
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
|
+
|
|
16
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
17
|
+
import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
18
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
19
|
+
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
20
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
21
|
+
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
22
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
23
|
+
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
24
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
25
|
+
import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
|
|
26
|
+
|
|
27
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
28
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
29
|
+
import {JBSingleAllowance} from "@bananapus/core-v6/src/structs/JBSingleAllowance.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 {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
|
|
36
|
+
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
37
|
+
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
38
|
+
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
39
|
+
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
40
|
+
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.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
|
+
|
|
44
|
+
/// @notice A test harness that exposes REVLoans internal functions for direct testing.
|
|
45
|
+
/// Used to test _totalBorrowedFrom without needing to set up a full borrow flow.
|
|
46
|
+
contract REVLoansHarness is REVLoans {
|
|
47
|
+
constructor(
|
|
48
|
+
IJBController controller,
|
|
49
|
+
IJBProjects projects,
|
|
50
|
+
uint256 revId,
|
|
51
|
+
address owner,
|
|
52
|
+
IPermit2 permit2,
|
|
53
|
+
address trustedForwarder
|
|
54
|
+
)
|
|
55
|
+
REVLoans(controller, projects, revId, owner, permit2, trustedForwarder)
|
|
56
|
+
{}
|
|
57
|
+
|
|
58
|
+
/// @notice Expose _totalBorrowedFrom for testing.
|
|
59
|
+
function exposed_totalBorrowedFrom(
|
|
60
|
+
uint256 revnetId,
|
|
61
|
+
uint256 decimals,
|
|
62
|
+
uint256 currency
|
|
63
|
+
)
|
|
64
|
+
external
|
|
65
|
+
view
|
|
66
|
+
returns (uint256)
|
|
67
|
+
{
|
|
68
|
+
return _totalBorrowedFrom(revnetId, decimals, currency);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// @notice Set totalBorrowedFrom for testing.
|
|
72
|
+
function setTotalBorrowedFrom(
|
|
73
|
+
uint256 revnetId,
|
|
74
|
+
IJBPayoutTerminal terminal,
|
|
75
|
+
address token,
|
|
76
|
+
uint256 amount
|
|
77
|
+
)
|
|
78
|
+
external
|
|
79
|
+
{
|
|
80
|
+
totalBorrowedFrom[revnetId][terminal][token] = amount;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/// @notice Register a loan source for testing.
|
|
84
|
+
function addLoanSource(uint256 revnetId, REVLoanSource memory source) external {
|
|
85
|
+
_loanSourcesOf[revnetId].push(source);
|
|
86
|
+
isLoanSourceOf[revnetId][source.terminal][source.token] = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// @notice Regression tests for zero price feed DoS in REVLoans._totalBorrowedFrom.
|
|
91
|
+
contract TestRevnetRegressions is TestBaseWorkflow {
|
|
92
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
93
|
+
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
94
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
95
|
+
bytes32 ERC20_SALT = "REV_TOKEN";
|
|
96
|
+
|
|
97
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
98
|
+
REVDeployer REV_DEPLOYER;
|
|
99
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
100
|
+
JB721TiersHook EXAMPLE_HOOK;
|
|
101
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
102
|
+
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
103
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
104
|
+
IJB721TiersHookStore HOOK_STORE;
|
|
105
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
106
|
+
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
107
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
108
|
+
REVLoansHarness LOANS_CONTRACT;
|
|
109
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
110
|
+
IJBSuckerRegistry SUCKER_REGISTRY;
|
|
111
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
112
|
+
CTPublisher PUBLISHER;
|
|
113
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
114
|
+
MockBuybackDataHook MOCK_BUYBACK;
|
|
115
|
+
|
|
116
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
117
|
+
uint256 FEE_PROJECT_ID;
|
|
118
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
119
|
+
address USER = makeAddr("user");
|
|
120
|
+
|
|
121
|
+
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
122
|
+
|
|
123
|
+
function setUp() public override {
|
|
124
|
+
super.setUp();
|
|
125
|
+
|
|
126
|
+
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
127
|
+
|
|
128
|
+
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
129
|
+
HOOK_STORE = new JB721TiersHookStore();
|
|
130
|
+
EXAMPLE_HOOK = new JB721TiersHook(
|
|
131
|
+
jbDirectory(), jbPermissions(), jbPrices(), jbRulesets(), HOOK_STORE, jbSplits(), multisig()
|
|
132
|
+
);
|
|
133
|
+
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
134
|
+
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
135
|
+
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
136
|
+
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
137
|
+
|
|
138
|
+
LOANS_CONTRACT = new REVLoansHarness({
|
|
139
|
+
controller: jbController(),
|
|
140
|
+
projects: jbProjects(),
|
|
141
|
+
revId: FEE_PROJECT_ID,
|
|
142
|
+
owner: address(this),
|
|
143
|
+
permit2: permit2(),
|
|
144
|
+
trustedForwarder: TRUSTED_FORWARDER
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
148
|
+
jbController(),
|
|
149
|
+
SUCKER_REGISTRY,
|
|
150
|
+
FEE_PROJECT_ID,
|
|
151
|
+
HOOK_DEPLOYER,
|
|
152
|
+
PUBLISHER,
|
|
153
|
+
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
154
|
+
address(LOANS_CONTRACT),
|
|
155
|
+
TRUSTED_FORWARDER
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
vm.prank(multisig());
|
|
159
|
+
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//*********************************************************************//
|
|
163
|
+
// ---- Zero price feed return causes DoS in _totalBorrowedFrom ----- //
|
|
164
|
+
//*********************************************************************//
|
|
165
|
+
|
|
166
|
+
/// @notice Demonstrates that `_totalBorrowedFrom` does not revert when
|
|
167
|
+
/// `pricePerUnitOf` returns 0 for a cross-currency loan source.
|
|
168
|
+
/// Before the fix, `mulDiv(x, y, 0)` would panic with a division-by-zero,
|
|
169
|
+
/// blocking all loan operations that aggregate cross-currency borrowed amounts.
|
|
170
|
+
function test_zeroPriceFeedSkippedInTotalBorrowed() public {
|
|
171
|
+
// Deploy the fee revnet (required by the system).
|
|
172
|
+
_deployFeeRevnet();
|
|
173
|
+
|
|
174
|
+
// Deploy a borrowable revnet.
|
|
175
|
+
uint256 revnetId = _deployBorrowableRevnet();
|
|
176
|
+
|
|
177
|
+
// Manually register a loan source with a DIFFERENT currency (fakeCurrency = 999).
|
|
178
|
+
// This simulates having an outstanding loan in a token with a different accounting currency.
|
|
179
|
+
uint32 fakeCurrency = 999;
|
|
180
|
+
address fakeToken = address(0xDEAD);
|
|
181
|
+
|
|
182
|
+
// Create a mock terminal that reports the fake accounting context.
|
|
183
|
+
// We use vm.mockCall to make the terminal report the fake currency.
|
|
184
|
+
address mockTerminal = makeAddr("mockTerminal");
|
|
185
|
+
vm.mockCall(
|
|
186
|
+
mockTerminal,
|
|
187
|
+
abi.encodeWithSelector(IJBTerminal.accountingContextForTokenOf.selector, revnetId, fakeToken),
|
|
188
|
+
abi.encode(JBAccountingContext({token: fakeToken, decimals: 18, currency: fakeCurrency}))
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
// Register the loan source and set a non-zero borrowed amount via the harness.
|
|
192
|
+
LOANS_CONTRACT.addLoanSource(
|
|
193
|
+
revnetId, REVLoanSource({token: fakeToken, terminal: IJBPayoutTerminal(mockTerminal)})
|
|
194
|
+
);
|
|
195
|
+
LOANS_CONTRACT.setTotalBorrowedFrom(revnetId, IJBPayoutTerminal(mockTerminal), fakeToken, 1e18);
|
|
196
|
+
|
|
197
|
+
// Mock PRICES.pricePerUnitOf to return 0 for the cross-currency conversion.
|
|
198
|
+
// This simulates a broken, stale, or uninitialized price feed.
|
|
199
|
+
vm.mockCall(
|
|
200
|
+
address(jbPrices()),
|
|
201
|
+
abi.encodeWithSelector(
|
|
202
|
+
IJBPrices.pricePerUnitOf.selector,
|
|
203
|
+
revnetId,
|
|
204
|
+
uint256(fakeCurrency),
|
|
205
|
+
uint256(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
206
|
+
uint256(18)
|
|
207
|
+
),
|
|
208
|
+
abi.encode(uint256(0))
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
// Call _totalBorrowedFrom via the harness.
|
|
212
|
+
// Before the fix: this would panic with division-by-zero in mulDiv.
|
|
213
|
+
// After the fix: the zero-price source is skipped with `continue`.
|
|
214
|
+
uint256 totalBorrowed =
|
|
215
|
+
LOANS_CONTRACT.exposed_totalBorrowedFrom(revnetId, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
216
|
+
|
|
217
|
+
// The source with zero price should be skipped, so the total is 0
|
|
218
|
+
// (the fake source is not counted because its price feed returned 0).
|
|
219
|
+
assertEq(totalBorrowed, 0, "_totalBorrowedFrom should return 0 when price feed returns 0, not panic");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
//*********************************************************************//
|
|
223
|
+
// ---- Helpers ------------------------------------------------------ //
|
|
224
|
+
//*********************************************************************//
|
|
225
|
+
|
|
226
|
+
function _deployFeeRevnet() internal {
|
|
227
|
+
JBAccountingContext[] memory accountingContextsToAccept = new JBAccountingContext[](1);
|
|
228
|
+
accountingContextsToAccept[0] = JBAccountingContext({
|
|
229
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
|
|
233
|
+
terminalConfigurations[0] =
|
|
234
|
+
JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: accountingContextsToAccept});
|
|
235
|
+
|
|
236
|
+
REVStageConfig[] memory stageConfigurations = new REVStageConfig[](1);
|
|
237
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
238
|
+
splits[0].beneficiary = payable(multisig());
|
|
239
|
+
splits[0].percent = 10_000;
|
|
240
|
+
|
|
241
|
+
REVAutoIssuance[] memory issuanceConfs = new REVAutoIssuance[](1);
|
|
242
|
+
issuanceConfs[0] =
|
|
243
|
+
REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
244
|
+
|
|
245
|
+
stageConfigurations[0] = REVStageConfig({
|
|
246
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
247
|
+
autoIssuances: issuanceConfs,
|
|
248
|
+
splitPercent: 2000,
|
|
249
|
+
splits: splits,
|
|
250
|
+
initialIssuance: uint112(1000e18),
|
|
251
|
+
issuanceCutFrequency: 90 days,
|
|
252
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
253
|
+
cashOutTaxRate: 6000,
|
|
254
|
+
extraMetadata: 0
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
REVConfig memory revnetConfiguration = REVConfig({
|
|
258
|
+
// forge-lint: disable-next-line(named-struct-fields)
|
|
259
|
+
description: REVDescription("Revnet", "$REV", "ipfs://test", ERC20_SALT),
|
|
260
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
261
|
+
splitOperator: multisig(),
|
|
262
|
+
stageConfigurations: stageConfigurations
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
vm.prank(multisig());
|
|
266
|
+
REV_DEPLOYER.deployFor({
|
|
267
|
+
revnetId: FEE_PROJECT_ID,
|
|
268
|
+
configuration: revnetConfiguration,
|
|
269
|
+
terminalConfigurations: terminalConfigurations,
|
|
270
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
271
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("REV"))
|
|
272
|
+
}),
|
|
273
|
+
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
274
|
+
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function _deployBorrowableRevnet() internal returns (uint256 revnetId) {
|
|
279
|
+
JBAccountingContext[] memory accountingContextsToAccept = new JBAccountingContext[](1);
|
|
280
|
+
accountingContextsToAccept[0] = JBAccountingContext({
|
|
281
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
|
|
285
|
+
terminalConfigurations[0] =
|
|
286
|
+
JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: accountingContextsToAccept});
|
|
287
|
+
|
|
288
|
+
REVStageConfig[] memory stageConfigurations = new REVStageConfig[](1);
|
|
289
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
290
|
+
splits[0].beneficiary = payable(multisig());
|
|
291
|
+
splits[0].percent = 10_000;
|
|
292
|
+
|
|
293
|
+
stageConfigurations[0] = REVStageConfig({
|
|
294
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
295
|
+
autoIssuances: new REVAutoIssuance[](0),
|
|
296
|
+
splitPercent: 0,
|
|
297
|
+
splits: splits,
|
|
298
|
+
initialIssuance: uint112(1000e18),
|
|
299
|
+
issuanceCutFrequency: 0,
|
|
300
|
+
issuanceCutPercent: 0,
|
|
301
|
+
cashOutTaxRate: 5000,
|
|
302
|
+
extraMetadata: 0
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
REVConfig memory revnetConfiguration = REVConfig({
|
|
306
|
+
// forge-lint: disable-next-line(named-struct-fields)
|
|
307
|
+
description: REVDescription("Borrowable", "BRW", "ipfs://brw", "BRW_TOKEN"),
|
|
308
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
309
|
+
splitOperator: multisig(),
|
|
310
|
+
stageConfigurations: stageConfigurations
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
(revnetId,) = REV_DEPLOYER.deployFor({
|
|
314
|
+
revnetId: 0,
|
|
315
|
+
configuration: revnetConfiguration,
|
|
316
|
+
terminalConfigurations: terminalConfigurations,
|
|
317
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
318
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("BRW"))
|
|
319
|
+
}),
|
|
320
|
+
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
321
|
+
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity 0.8.26;
|
|
3
3
|
|
|
4
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
4
5
|
import "forge-std/Test.sol";
|
|
6
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
5
7
|
import /* {*} from */ "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
8
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
6
9
|
import /* {*} from */ "./../src/REVDeployer.sol";
|
|
10
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
7
11
|
import "@croptop/core-v6/src/CTPublisher.sol";
|
|
8
12
|
import {MockBuybackDataHookMintPath} from "./mock/MockBuybackDataHookMintPath.sol";
|
|
9
13
|
import {MockBuybackDataHook} from "./mock/MockBuybackDataHook.sol";
|
|
14
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
10
15
|
import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
16
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
11
17
|
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
18
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
12
19
|
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
20
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
13
21
|
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
22
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
14
23
|
import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
|
|
15
24
|
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
16
25
|
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
17
26
|
import {REVLoans} from "../src/REVLoans.sol";
|
|
18
27
|
import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
|
|
19
|
-
import {REVLoanSource} from "../src/structs/REVLoanSource.sol";
|
|
20
28
|
import {REVDescription} from "../src/structs/REVDescription.sol";
|
|
21
29
|
import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
|
|
22
30
|
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
@@ -32,24 +40,37 @@ import {IJBPayHook} from "@bananapus/core-v6/src/interfaces/IJBPayHook.sol";
|
|
|
32
40
|
import {JBBeforePayRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforePayRecordedContext.sol";
|
|
33
41
|
import {JBPayHookSpecification} from "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
|
|
34
42
|
import {JBTokenAmount} from "@bananapus/core-v6/src/structs/JBTokenAmount.sol";
|
|
43
|
+
import {REVEmpty721Config} from "./helpers/REVEmpty721Config.sol";
|
|
35
44
|
|
|
36
45
|
/// @notice Tests for the split weight adjustment in REVDeployer.beforePayRecordedWith.
|
|
37
46
|
contract TestSplitWeightAdjustment is TestBaseWorkflow {
|
|
47
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
38
48
|
bytes32 REV_DEPLOYER_SALT = "REVDeployer_SWA";
|
|
39
49
|
|
|
50
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
40
51
|
REVDeployer REV_DEPLOYER;
|
|
52
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
41
53
|
JB721TiersHook EXAMPLE_HOOK;
|
|
54
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
42
55
|
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
56
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
43
57
|
IJB721TiersHookStore HOOK_STORE;
|
|
58
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
44
59
|
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
60
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
45
61
|
IREVLoans LOANS_CONTRACT;
|
|
62
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
46
63
|
IJBSuckerRegistry SUCKER_REGISTRY;
|
|
64
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
47
65
|
CTPublisher PUBLISHER;
|
|
66
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
48
67
|
MockBuybackDataHookMintPath MOCK_BUYBACK;
|
|
49
68
|
|
|
69
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
50
70
|
uint256 FEE_PROJECT_ID;
|
|
51
71
|
|
|
52
72
|
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
73
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
53
74
|
address USER = makeAddr("user");
|
|
54
75
|
|
|
55
76
|
function setUp() public override {
|
|
@@ -57,8 +78,9 @@ contract TestSplitWeightAdjustment is TestBaseWorkflow {
|
|
|
57
78
|
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
58
79
|
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
59
80
|
HOOK_STORE = new JB721TiersHookStore();
|
|
60
|
-
EXAMPLE_HOOK =
|
|
61
|
-
|
|
81
|
+
EXAMPLE_HOOK = new JB721TiersHook(
|
|
82
|
+
jbDirectory(), jbPermissions(), jbPrices(), jbRulesets(), HOOK_STORE, jbSplits(), multisig()
|
|
83
|
+
);
|
|
62
84
|
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
63
85
|
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
64
86
|
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
@@ -114,6 +136,7 @@ contract TestSplitWeightAdjustment is TestBaseWorkflow {
|
|
|
114
136
|
});
|
|
115
137
|
|
|
116
138
|
cfg = REVConfig({
|
|
139
|
+
// forge-lint: disable-next-line(named-struct-fields)
|
|
117
140
|
description: REVDescription("Test", "TST", "ipfs://test", "TEST_SALT"),
|
|
118
141
|
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
119
142
|
splitOperator: multisig(),
|
|
@@ -134,20 +157,28 @@ contract TestSplitWeightAdjustment is TestBaseWorkflow {
|
|
|
134
157
|
revnetId: FEE_PROJECT_ID,
|
|
135
158
|
configuration: feeCfg,
|
|
136
159
|
terminalConfigurations: feeTc,
|
|
137
|
-
suckerDeploymentConfiguration: feeSdc
|
|
160
|
+
suckerDeploymentConfiguration: feeSdc,
|
|
161
|
+
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
162
|
+
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
138
163
|
});
|
|
139
164
|
|
|
140
165
|
// Deploy the revnet.
|
|
141
166
|
(REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc) =
|
|
142
167
|
_buildMinimalConfig();
|
|
168
|
+
// forge-lint: disable-next-line(named-struct-fields)
|
|
143
169
|
cfg.description = REVDescription("Test2", "TS2", "ipfs://test2", "TEST_SALT_2");
|
|
144
|
-
revnetId = REV_DEPLOYER.deployFor({
|
|
145
|
-
revnetId: 0,
|
|
170
|
+
(revnetId,) = REV_DEPLOYER.deployFor({
|
|
171
|
+
revnetId: 0,
|
|
172
|
+
configuration: cfg,
|
|
173
|
+
terminalConfigurations: tc,
|
|
174
|
+
suckerDeploymentConfiguration: sdc,
|
|
175
|
+
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
176
|
+
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
146
177
|
});
|
|
147
178
|
}
|
|
148
179
|
|
|
149
|
-
/// @notice
|
|
150
|
-
function
|
|
180
|
+
/// @notice Empty 721 hook (no tiers) = no split adjustment, weight passes through.
|
|
181
|
+
function test_beforePay_empty721_noAdjustment() public {
|
|
151
182
|
uint256 revnetId = _deployRevnet();
|
|
152
183
|
|
|
153
184
|
JBBeforePayRecordedContext memory context = JBBeforePayRecordedContext({
|
|
@@ -167,11 +198,11 @@ contract TestSplitWeightAdjustment is TestBaseWorkflow {
|
|
|
167
198
|
metadata: ""
|
|
168
199
|
});
|
|
169
200
|
|
|
170
|
-
//
|
|
201
|
+
// 721 hook is deployed but has no tiers, buyback returns context.weight.
|
|
171
202
|
(uint256 weight, JBPayHookSpecification[] memory specs) = REV_DEPLOYER.beforePayRecordedWith(context);
|
|
172
203
|
|
|
173
204
|
assertEq(weight, context.weight, "weight should pass through unchanged");
|
|
174
|
-
assertEq(specs.length,
|
|
205
|
+
assertEq(specs.length, 1, "should have 721 hook spec even with no tiers");
|
|
175
206
|
}
|
|
176
207
|
|
|
177
208
|
/// @notice When 721 hook returns splits, weight is adjusted proportionally.
|
|
@@ -294,14 +325,22 @@ contract TestSplitWeightAdjustment is TestBaseWorkflow {
|
|
|
294
325
|
revnetId: FEE_PROJECT_ID,
|
|
295
326
|
configuration: feeCfg,
|
|
296
327
|
terminalConfigurations: feeTc,
|
|
297
|
-
suckerDeploymentConfiguration: feeSdc
|
|
328
|
+
suckerDeploymentConfiguration: feeSdc,
|
|
329
|
+
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
330
|
+
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
298
331
|
});
|
|
299
332
|
|
|
300
333
|
(REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc) =
|
|
301
334
|
_buildMinimalConfig();
|
|
335
|
+
// forge-lint: disable-next-line(named-struct-fields)
|
|
302
336
|
cfg.description = REVDescription("AMM", "AMM", "ipfs://amm", "AMM_SALT");
|
|
303
|
-
uint256 revnetId = ammDeployer.deployFor({
|
|
304
|
-
revnetId: 0,
|
|
337
|
+
(uint256 revnetId,) = ammDeployer.deployFor({
|
|
338
|
+
revnetId: 0,
|
|
339
|
+
configuration: cfg,
|
|
340
|
+
terminalConfigurations: tc,
|
|
341
|
+
suckerDeploymentConfiguration: sdc,
|
|
342
|
+
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
343
|
+
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
305
344
|
});
|
|
306
345
|
|
|
307
346
|
// Mock a 721 hook for this project.
|