@rev-net/core-v6 0.0.8 → 0.0.10
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 +186 -0
- package/ARCHITECTURE.md +87 -0
- package/README.md +8 -6
- package/RISKS.md +49 -0
- package/SKILLS.md +24 -10
- package/STYLE_GUIDE.md +558 -0
- package/docs/src/README.md +2 -2
- package/foundry.toml +9 -6
- package/package.json +12 -9
- package/remappings.txt +1 -1
- package/script/Deploy.s.sol +4 -3
- package/script/helpers/RevnetCoreDeploymentLib.sol +1 -1
- package/src/REVDeployer.sol +103 -76
- package/src/REVLoans.sol +14 -4
- package/src/interfaces/IREVDeployer.sol +2 -1
- package/src/structs/REV721TiersHookFlags.sol +14 -0
- package/src/structs/REVBaseline721HookConfig.sol +27 -0
- package/src/structs/REVDeploy721TiersHookConfig.sol +2 -2
- package/test/REV.integrations.t.sol +4 -3
- package/test/REVAutoIssuanceFuzz.t.sol +12 -8
- package/test/{REVDeployerAuditRegressions.t.sol → REVDeployerRegressions.t.sol} +4 -3
- package/test/REVInvincibility.t.sol +23 -25
- package/test/REVInvincibilityHandler.sol +1 -0
- package/test/REVLifecycle.t.sol +4 -4
- package/test/REVLoans.invariants.t.sol +5 -3
- package/test/REVLoansAttacks.t.sol +7 -10
- package/test/REVLoansFeeRecovery.t.sol +4 -5
- package/test/REVLoansFindings.t.sol +644 -0
- package/test/{REVLoansAuditRegressions.t.sol → REVLoansRegressions.t.sol} +14 -25
- package/test/REVLoansSourced.t.sol +7 -4
- package/test/REVLoansUnSourced.t.sol +4 -3
- package/test/{TestPR26_BurnHeldTokens.t.sol → TestBurnHeldTokens.t.sol} +4 -3
- package/test/{TestPR27_CEIPattern.t.sol → TestCEIPattern.t.sol} +6 -5
- package/test/{TestPR15_CashOutCallerValidation.t.sol → TestCashOutCallerValidation.t.sol} +4 -5
- package/test/{TestPR09_ConversionDocumentation.t.sol → TestConversionDocumentation.t.sol} +4 -3
- package/test/{TestPR13_CrossSourceReallocation.t.sol → TestCrossSourceReallocation.t.sol} +4 -3
- package/test/TestEmptyBuybackSpecs.t.sol +4 -3
- package/test/{TestPR12_FlashLoanSurplus.t.sol → TestFlashLoanSurplus.t.sol} +4 -3
- package/test/{TestPR22_HookArrayOOB.t.sol → TestHookArrayOOB.t.sol} +4 -3
- package/test/{TestPR10_LiquidationBehavior.t.sol → TestLiquidationBehavior.t.sol} +7 -6
- package/test/{TestPR11_LowFindings.t.sol → TestLowFindings.t.sol} +4 -3
- package/test/{TestPR32_MixedFixes.t.sol → TestMixedFixes.t.sol} +4 -3
- package/test/TestSplitWeightAdjustment.t.sol +445 -0
- package/test/TestSplitWeightE2E.t.sol +528 -0
- package/test/TestSplitWeightFork.t.sol +780 -0
- package/test/TestStageTransitionBorrowable.t.sol +4 -3
- package/test/{TestPR29_SwapTerminalPermission.t.sol → TestSwapTerminalPermission.t.sol} +4 -3
- package/test/{TestPR21_Uint112Overflow.t.sol → TestUint112Overflow.t.sol} +7 -6
- package/test/{TestPR16_ZeroRepayment.t.sol → TestZeroRepayment.t.sol} +7 -8
- package/test/fork/ForkTestBase.sol +649 -0
- package/test/fork/TestCashOutFork.t.sol +246 -0
- package/test/fork/TestLoanBorrowFork.t.sol +161 -0
- package/test/fork/TestLoanCrossRulesetFork.t.sol +300 -0
- package/test/fork/TestLoanLiquidationFork.t.sol +134 -0
- package/test/fork/TestLoanReallocateFork.t.sol +112 -0
- package/test/fork/TestLoanRepayFork.t.sol +187 -0
- package/test/fork/TestSplitWeightFork.t.sol +186 -0
- package/test/mock/MockBuybackDataHook.sol +9 -9
- package/test/mock/MockBuybackDataHookMintPath.sol +10 -9
- package/test/regression/{TestI20_CumulativeLoanCounter.t.sol → TestCumulativeLoanCounter.t.sol} +9 -8
- package/test/regression/{TestL27_LiquidateGapHandling.t.sol → TestLiquidateGapHandling.t.sol} +9 -8
- package/SECURITY.md +0 -68
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.26;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
import /* {*} from */ "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
6
|
+
import /* {*} from */ "./../src/REVDeployer.sol";
|
|
7
|
+
import "@croptop/core-v6/src/CTPublisher.sol";
|
|
8
|
+
import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
9
|
+
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
10
|
+
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
11
|
+
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
12
|
+
import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
|
|
13
|
+
|
|
14
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
15
|
+
import {JBMetadataResolver} from "@bananapus/core-v6/src/libraries/JBMetadataResolver.sol";
|
|
16
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
17
|
+
import {REVLoans} from "../src/REVLoans.sol";
|
|
18
|
+
import {REVStageConfig, REVAutoIssuance} from "../src/structs/REVStageConfig.sol";
|
|
19
|
+
import {REVLoanSource} from "../src/structs/REVLoanSource.sol";
|
|
20
|
+
import {REVDescription} from "../src/structs/REVDescription.sol";
|
|
21
|
+
import {IREVLoans} from "./../src/interfaces/IREVLoans.sol";
|
|
22
|
+
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
23
|
+
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
24
|
+
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
25
|
+
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
26
|
+
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
27
|
+
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
28
|
+
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
29
|
+
import {IJBRulesetDataHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetDataHook.sol";
|
|
30
|
+
import {IJBBuybackHookRegistry} from "@bananapus/buyback-hook-v6/src/interfaces/IJBBuybackHookRegistry.sol";
|
|
31
|
+
import {IJBPayHook} from "@bananapus/core-v6/src/interfaces/IJBPayHook.sol";
|
|
32
|
+
import {REVBaseline721HookConfig} from "../src/structs/REVBaseline721HookConfig.sol";
|
|
33
|
+
import {REV721TiersHookFlags} from "../src/structs/REV721TiersHookFlags.sol";
|
|
34
|
+
import {JB721TierConfig} from "@bananapus/721-hook-v6/src/structs/JB721TierConfig.sol";
|
|
35
|
+
import {JB721InitTiersConfig} from "@bananapus/721-hook-v6/src/structs/JB721InitTiersConfig.sol";
|
|
36
|
+
import {IJB721TokenUriResolver} from "@bananapus/721-hook-v6/src/interfaces/IJB721TokenUriResolver.sol";
|
|
37
|
+
import {REVDeploy721TiersHookConfig} from "../src/structs/REVDeploy721TiersHookConfig.sol";
|
|
38
|
+
import {REVCroptopAllowedPost} from "../src/structs/REVCroptopAllowedPost.sol";
|
|
39
|
+
|
|
40
|
+
// Buyback hook
|
|
41
|
+
import {JBBuybackHook} from "@bananapus/buyback-hook-v6/src/JBBuybackHook.sol";
|
|
42
|
+
import {JBBuybackHookRegistry} from "@bananapus/buyback-hook-v6/src/JBBuybackHookRegistry.sol";
|
|
43
|
+
import {IJBBuybackHook} from "@bananapus/buyback-hook-v6/src/interfaces/IJBBuybackHook.sol";
|
|
44
|
+
import {IGeomeanOracle} from "@bananapus/buyback-hook-v6/src/interfaces/IGeomeanOracle.sol";
|
|
45
|
+
|
|
46
|
+
// Uniswap V4
|
|
47
|
+
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
|
|
48
|
+
import {IUnlockCallback} from "@uniswap/v4-core/src/interfaces/callback/IUnlockCallback.sol";
|
|
49
|
+
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
|
|
50
|
+
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
|
51
|
+
import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol";
|
|
52
|
+
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol";
|
|
53
|
+
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
|
|
54
|
+
import {ModifyLiquidityParams, SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";
|
|
55
|
+
import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol";
|
|
56
|
+
import {StateLibrary} from "@uniswap/v4-core/src/libraries/StateLibrary.sol";
|
|
57
|
+
|
|
58
|
+
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
|
|
59
|
+
|
|
60
|
+
/// @notice Helper that adds liquidity to and swaps on a V4 pool via the unlock/callback pattern.
|
|
61
|
+
contract LiquidityHelper is IUnlockCallback {
|
|
62
|
+
IPoolManager public immutable poolManager;
|
|
63
|
+
|
|
64
|
+
enum Action {
|
|
65
|
+
ADD_LIQUIDITY,
|
|
66
|
+
SWAP
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
struct AddLiqParams {
|
|
70
|
+
PoolKey key;
|
|
71
|
+
int24 tickLower;
|
|
72
|
+
int24 tickUpper;
|
|
73
|
+
int256 liquidityDelta;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
struct DoSwapParams {
|
|
77
|
+
PoolKey key;
|
|
78
|
+
bool zeroForOne;
|
|
79
|
+
int256 amountSpecified;
|
|
80
|
+
uint160 sqrtPriceLimitX96;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
constructor(IPoolManager _poolManager) {
|
|
84
|
+
poolManager = _poolManager;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function addLiquidity(
|
|
88
|
+
PoolKey calldata key,
|
|
89
|
+
int24 tickLower,
|
|
90
|
+
int24 tickUpper,
|
|
91
|
+
int256 liquidityDelta
|
|
92
|
+
)
|
|
93
|
+
external
|
|
94
|
+
payable
|
|
95
|
+
{
|
|
96
|
+
bytes memory data =
|
|
97
|
+
abi.encode(Action.ADD_LIQUIDITY, abi.encode(AddLiqParams(key, tickLower, tickUpper, liquidityDelta)));
|
|
98
|
+
poolManager.unlock(data);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function swap(
|
|
102
|
+
PoolKey calldata key,
|
|
103
|
+
bool zeroForOne,
|
|
104
|
+
int256 amountSpecified,
|
|
105
|
+
uint160 sqrtPriceLimitX96
|
|
106
|
+
)
|
|
107
|
+
external
|
|
108
|
+
payable
|
|
109
|
+
{
|
|
110
|
+
bytes memory data =
|
|
111
|
+
abi.encode(Action.SWAP, abi.encode(DoSwapParams(key, zeroForOne, amountSpecified, sqrtPriceLimitX96)));
|
|
112
|
+
poolManager.unlock(data);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function unlockCallback(bytes calldata data) external override returns (bytes memory) {
|
|
116
|
+
require(msg.sender == address(poolManager), "only PM");
|
|
117
|
+
|
|
118
|
+
(Action action, bytes memory inner) = abi.decode(data, (Action, bytes));
|
|
119
|
+
|
|
120
|
+
if (action == Action.ADD_LIQUIDITY) {
|
|
121
|
+
return _handleAddLiquidity(inner);
|
|
122
|
+
} else {
|
|
123
|
+
return _handleSwap(inner);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function _handleAddLiquidity(bytes memory data) internal returns (bytes memory) {
|
|
128
|
+
AddLiqParams memory params = abi.decode(data, (AddLiqParams));
|
|
129
|
+
|
|
130
|
+
(BalanceDelta callerDelta,) = poolManager.modifyLiquidity(
|
|
131
|
+
params.key,
|
|
132
|
+
ModifyLiquidityParams({
|
|
133
|
+
tickLower: params.tickLower,
|
|
134
|
+
tickUpper: params.tickUpper,
|
|
135
|
+
liquidityDelta: params.liquidityDelta,
|
|
136
|
+
salt: bytes32(0)
|
|
137
|
+
}),
|
|
138
|
+
""
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
_settleIfNegative(params.key.currency0, callerDelta.amount0());
|
|
142
|
+
_settleIfNegative(params.key.currency1, callerDelta.amount1());
|
|
143
|
+
_takeIfPositive(params.key.currency0, callerDelta.amount0());
|
|
144
|
+
_takeIfPositive(params.key.currency1, callerDelta.amount1());
|
|
145
|
+
|
|
146
|
+
return abi.encode(callerDelta);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function _handleSwap(bytes memory data) internal returns (bytes memory) {
|
|
150
|
+
DoSwapParams memory params = abi.decode(data, (DoSwapParams));
|
|
151
|
+
|
|
152
|
+
BalanceDelta delta = poolManager.swap(
|
|
153
|
+
params.key, SwapParams(params.zeroForOne, params.amountSpecified, params.sqrtPriceLimitX96), ""
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
// Settle (pay) what we owe, take what we're owed.
|
|
157
|
+
if (delta.amount0() < 0) {
|
|
158
|
+
_settleIfNegative(params.key.currency0, delta.amount0());
|
|
159
|
+
} else {
|
|
160
|
+
_takeIfPositive(params.key.currency0, delta.amount0());
|
|
161
|
+
}
|
|
162
|
+
if (delta.amount1() < 0) {
|
|
163
|
+
_settleIfNegative(params.key.currency1, delta.amount1());
|
|
164
|
+
} else {
|
|
165
|
+
_takeIfPositive(params.key.currency1, delta.amount1());
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return abi.encode(delta);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function _settleIfNegative(Currency currency, int128 delta) internal {
|
|
172
|
+
if (delta >= 0) return;
|
|
173
|
+
uint256 amount = uint256(uint128(-delta));
|
|
174
|
+
|
|
175
|
+
if (currency.isAddressZero()) {
|
|
176
|
+
poolManager.settle{value: amount}();
|
|
177
|
+
} else {
|
|
178
|
+
poolManager.sync(currency);
|
|
179
|
+
IERC20(Currency.unwrap(currency)).transfer(address(poolManager), amount);
|
|
180
|
+
poolManager.settle();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function _takeIfPositive(Currency currency, int128 delta) internal {
|
|
185
|
+
if (delta <= 0) return;
|
|
186
|
+
uint256 amount = uint256(uint128(delta));
|
|
187
|
+
poolManager.take(currency, address(this), amount);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
receive() external payable {}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/// @notice Fork tests verifying that revnet 721 tier splits + real Uniswap V4 buyback hook produce correct token
|
|
194
|
+
/// issuance in both the swap path (AMM buyback) and the mint path (direct minting).
|
|
195
|
+
///
|
|
196
|
+
/// Requires: RPC_ETHEREUM_MAINNET env var for mainnet fork (real PoolManager).
|
|
197
|
+
///
|
|
198
|
+
/// Run with: FOUNDRY_PROFILE=fork forge test --match-contract TestSplitWeightFork -vvv --skip "script/*"
|
|
199
|
+
contract TestSplitWeightFork is TestBaseWorkflow {
|
|
200
|
+
using JBMetadataResolver for bytes;
|
|
201
|
+
using PoolIdLibrary for PoolKey;
|
|
202
|
+
using CurrencyLibrary for Currency;
|
|
203
|
+
using StateLibrary for IPoolManager;
|
|
204
|
+
|
|
205
|
+
// ───────────────────────── Mainnet constants
|
|
206
|
+
// ─────────────────────────
|
|
207
|
+
|
|
208
|
+
address constant POOL_MANAGER_ADDR = 0x000000000004444c5dc75cB358380D2e3dE08A90;
|
|
209
|
+
|
|
210
|
+
/// @notice Full-range tick bounds for tickSpacing = 200.
|
|
211
|
+
int24 constant TICK_LOWER = -887_200;
|
|
212
|
+
int24 constant TICK_UPPER = 887_200;
|
|
213
|
+
|
|
214
|
+
// ───────────────────────── State
|
|
215
|
+
// ─────────────────────────
|
|
216
|
+
|
|
217
|
+
REVDeployer REV_DEPLOYER;
|
|
218
|
+
JBBuybackHook BUYBACK_HOOK;
|
|
219
|
+
JBBuybackHookRegistry BUYBACK_REGISTRY;
|
|
220
|
+
JB721TiersHook EXAMPLE_HOOK;
|
|
221
|
+
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
222
|
+
IJB721TiersHookStore HOOK_STORE;
|
|
223
|
+
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
224
|
+
IREVLoans LOANS_CONTRACT;
|
|
225
|
+
IJBSuckerRegistry SUCKER_REGISTRY;
|
|
226
|
+
CTPublisher PUBLISHER;
|
|
227
|
+
IPoolManager poolManager;
|
|
228
|
+
LiquidityHelper liqHelper;
|
|
229
|
+
|
|
230
|
+
uint256 FEE_PROJECT_ID;
|
|
231
|
+
|
|
232
|
+
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
233
|
+
address PAYER = makeAddr("payer");
|
|
234
|
+
address SPLIT_BENEFICIARY = makeAddr("splitBeneficiary");
|
|
235
|
+
|
|
236
|
+
// Tier configuration: 1 ETH tier with 30% split.
|
|
237
|
+
uint104 constant TIER_PRICE = 1 ether;
|
|
238
|
+
uint32 constant SPLIT_PERCENT = 300_000_000; // 30% of SPLITS_TOTAL_PERCENT (1_000_000_000)
|
|
239
|
+
uint112 constant INITIAL_ISSUANCE = 1000e18; // 1000 tokens per ETH
|
|
240
|
+
|
|
241
|
+
// ───────────────────────── Setup
|
|
242
|
+
// ─────────────────────────
|
|
243
|
+
|
|
244
|
+
function setUp() public override {
|
|
245
|
+
// Fork mainnet at a stable block — deterministic and post-V4 deployment.
|
|
246
|
+
vm.createSelectFork("ethereum", 21_700_000);
|
|
247
|
+
|
|
248
|
+
// Verify V4 PoolManager is deployed.
|
|
249
|
+
require(POOL_MANAGER_ADDR.code.length > 0, "PoolManager not deployed at expected address");
|
|
250
|
+
|
|
251
|
+
// Deploy fresh JB core on the forked mainnet.
|
|
252
|
+
super.setUp();
|
|
253
|
+
|
|
254
|
+
poolManager = IPoolManager(POOL_MANAGER_ADDR);
|
|
255
|
+
liqHelper = new LiquidityHelper(poolManager);
|
|
256
|
+
|
|
257
|
+
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
258
|
+
|
|
259
|
+
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
260
|
+
HOOK_STORE = new JB721TiersHookStore();
|
|
261
|
+
EXAMPLE_HOOK =
|
|
262
|
+
new JB721TiersHook(jbDirectory(), jbPermissions(), jbRulesets(), HOOK_STORE, jbSplits(), multisig());
|
|
263
|
+
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
264
|
+
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
265
|
+
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
266
|
+
|
|
267
|
+
// Deploy REAL buyback hook with real PoolManager.
|
|
268
|
+
BUYBACK_HOOK = new JBBuybackHook(
|
|
269
|
+
jbDirectory(),
|
|
270
|
+
jbPermissions(),
|
|
271
|
+
jbPrices(),
|
|
272
|
+
jbProjects(),
|
|
273
|
+
jbTokens(),
|
|
274
|
+
poolManager,
|
|
275
|
+
IHooks(address(0)), // oracleHook
|
|
276
|
+
address(0) // trustedForwarder
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
// Deploy the registry and set the buyback hook as the default.
|
|
280
|
+
BUYBACK_REGISTRY = new JBBuybackHookRegistry(
|
|
281
|
+
jbPermissions(),
|
|
282
|
+
jbProjects(),
|
|
283
|
+
address(this), // owner
|
|
284
|
+
address(0) // trustedForwarder
|
|
285
|
+
);
|
|
286
|
+
BUYBACK_REGISTRY.setDefaultHook(IJBRulesetDataHook(address(BUYBACK_HOOK)));
|
|
287
|
+
|
|
288
|
+
LOANS_CONTRACT = new REVLoans({
|
|
289
|
+
controller: jbController(),
|
|
290
|
+
projects: jbProjects(),
|
|
291
|
+
revId: FEE_PROJECT_ID,
|
|
292
|
+
owner: address(this),
|
|
293
|
+
permit2: permit2(),
|
|
294
|
+
trustedForwarder: TRUSTED_FORWARDER
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
REV_DEPLOYER = new REVDeployer{salt: "REVDeployer_Fork"}(
|
|
298
|
+
jbController(),
|
|
299
|
+
SUCKER_REGISTRY,
|
|
300
|
+
FEE_PROJECT_ID,
|
|
301
|
+
HOOK_DEPLOYER,
|
|
302
|
+
PUBLISHER,
|
|
303
|
+
IJBBuybackHookRegistry(address(BUYBACK_REGISTRY)),
|
|
304
|
+
address(LOANS_CONTRACT),
|
|
305
|
+
TRUSTED_FORWARDER
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
vm.prank(multisig());
|
|
309
|
+
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
310
|
+
|
|
311
|
+
// Fund the payer.
|
|
312
|
+
vm.deal(PAYER, 100 ether);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ───────────────────────── Helpers
|
|
316
|
+
// ─────────────────────────
|
|
317
|
+
|
|
318
|
+
function _buildMinimalConfig()
|
|
319
|
+
internal
|
|
320
|
+
view
|
|
321
|
+
returns (REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc)
|
|
322
|
+
{
|
|
323
|
+
JBAccountingContext[] memory acc = new JBAccountingContext[](1);
|
|
324
|
+
acc[0] = JBAccountingContext({
|
|
325
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
326
|
+
});
|
|
327
|
+
tc = new JBTerminalConfig[](1);
|
|
328
|
+
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
329
|
+
|
|
330
|
+
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
331
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
332
|
+
splits[0].beneficiary = payable(multisig());
|
|
333
|
+
splits[0].percent = 10_000;
|
|
334
|
+
stages[0] = REVStageConfig({
|
|
335
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
336
|
+
autoIssuances: new REVAutoIssuance[](0),
|
|
337
|
+
splitPercent: 0,
|
|
338
|
+
splits: splits,
|
|
339
|
+
initialIssuance: INITIAL_ISSUANCE,
|
|
340
|
+
issuanceCutFrequency: 0,
|
|
341
|
+
issuanceCutPercent: 0,
|
|
342
|
+
cashOutTaxRate: 5000,
|
|
343
|
+
extraMetadata: 0
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
cfg = REVConfig({
|
|
347
|
+
description: REVDescription("Fork Test", "FORK", "ipfs://fork", "FORK_SALT"),
|
|
348
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
349
|
+
splitOperator: multisig(),
|
|
350
|
+
stageConfigurations: stages
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
sdc = REVSuckerDeploymentConfig({
|
|
354
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256(abi.encodePacked("FORK_TEST"))
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function _build721Config() internal view returns (REVDeploy721TiersHookConfig memory) {
|
|
359
|
+
JB721TierConfig[] memory tiers = new JB721TierConfig[](1);
|
|
360
|
+
JBSplit[] memory tierSplits = new JBSplit[](1);
|
|
361
|
+
tierSplits[0] = JBSplit({
|
|
362
|
+
preferAddToBalance: false,
|
|
363
|
+
percent: uint32(JBConstants.SPLITS_TOTAL_PERCENT),
|
|
364
|
+
projectId: 0,
|
|
365
|
+
beneficiary: payable(SPLIT_BENEFICIARY),
|
|
366
|
+
lockedUntil: 0,
|
|
367
|
+
hook: IJBSplitHook(address(0))
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
tiers[0] = JB721TierConfig({
|
|
371
|
+
price: TIER_PRICE,
|
|
372
|
+
initialSupply: 100,
|
|
373
|
+
votingUnits: 0,
|
|
374
|
+
reserveFrequency: 0,
|
|
375
|
+
reserveBeneficiary: address(0),
|
|
376
|
+
encodedIPFSUri: bytes32("tier1"),
|
|
377
|
+
category: 1,
|
|
378
|
+
discountPercent: 0,
|
|
379
|
+
allowOwnerMint: false,
|
|
380
|
+
useReserveBeneficiaryAsDefault: false,
|
|
381
|
+
transfersPausable: false,
|
|
382
|
+
useVotingUnits: false,
|
|
383
|
+
cannotBeRemoved: false,
|
|
384
|
+
cannotIncreaseDiscountPercent: false,
|
|
385
|
+
splitPercent: SPLIT_PERCENT,
|
|
386
|
+
splits: tierSplits
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
return REVDeploy721TiersHookConfig({
|
|
390
|
+
baseline721HookConfiguration: REVBaseline721HookConfig({
|
|
391
|
+
name: "Fork NFT",
|
|
392
|
+
symbol: "FNFT",
|
|
393
|
+
baseUri: "ipfs://",
|
|
394
|
+
tokenUriResolver: IJB721TokenUriResolver(address(0)),
|
|
395
|
+
contractUri: "ipfs://contract",
|
|
396
|
+
tiersConfig: JB721InitTiersConfig({
|
|
397
|
+
tiers: tiers,
|
|
398
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
399
|
+
decimals: 18,
|
|
400
|
+
prices: IJBPrices(address(0))
|
|
401
|
+
}),
|
|
402
|
+
reserveBeneficiary: address(0),
|
|
403
|
+
flags: REV721TiersHookFlags({
|
|
404
|
+
noNewTiersWithReserves: false,
|
|
405
|
+
noNewTiersWithVotes: false,
|
|
406
|
+
noNewTiersWithOwnerMinting: false,
|
|
407
|
+
preventOverspending: false
|
|
408
|
+
})
|
|
409
|
+
}),
|
|
410
|
+
salt: bytes32("FORK_721"),
|
|
411
|
+
splitOperatorCanAdjustTiers: false,
|
|
412
|
+
splitOperatorCanUpdateMetadata: false,
|
|
413
|
+
splitOperatorCanMint: false,
|
|
414
|
+
splitOperatorCanIncreaseDiscountPercent: false
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/// @notice Deploy the fee project, then deploy a revnet with 721 tiers.
|
|
419
|
+
function _deployRevnetWith721() internal returns (uint256 revnetId, IJB721TiersHook hook) {
|
|
420
|
+
// Deploy fee project first.
|
|
421
|
+
(REVConfig memory feeCfg, JBTerminalConfig[] memory feeTc, REVSuckerDeploymentConfig memory feeSdc) =
|
|
422
|
+
_buildMinimalConfig();
|
|
423
|
+
feeCfg.description = REVDescription("Fee", "FEE", "ipfs://fee", "FEE_SALT");
|
|
424
|
+
|
|
425
|
+
vm.prank(multisig());
|
|
426
|
+
REV_DEPLOYER.deployFor({
|
|
427
|
+
revnetId: FEE_PROJECT_ID,
|
|
428
|
+
configuration: feeCfg,
|
|
429
|
+
terminalConfigurations: feeTc,
|
|
430
|
+
suckerDeploymentConfiguration: feeSdc
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// Deploy the revnet with 721 hook.
|
|
434
|
+
(REVConfig memory cfg, JBTerminalConfig[] memory tc, REVSuckerDeploymentConfig memory sdc) =
|
|
435
|
+
_buildMinimalConfig();
|
|
436
|
+
REVDeploy721TiersHookConfig memory hookConfig = _build721Config();
|
|
437
|
+
|
|
438
|
+
(revnetId, hook) = REV_DEPLOYER.deployWith721sFor({
|
|
439
|
+
revnetId: 0,
|
|
440
|
+
configuration: cfg,
|
|
441
|
+
terminalConfigurations: tc,
|
|
442
|
+
suckerDeploymentConfiguration: sdc,
|
|
443
|
+
tiered721HookConfiguration: hookConfig,
|
|
444
|
+
allowedPosts: new REVCroptopAllowedPost[](0)
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/// @notice Set up a V4 pool for the revnet's project token / native ETH pair and register it with the buyback hook.
|
|
449
|
+
function _setupPool(uint256 revnetId, uint256 liquidityTokenAmount) internal returns (PoolKey memory key) {
|
|
450
|
+
// Get the project token.
|
|
451
|
+
address projectToken = address(jbTokens().tokenOf(revnetId));
|
|
452
|
+
require(projectToken != address(0), "project token not deployed");
|
|
453
|
+
|
|
454
|
+
// Native ETH is represented as address(0) in V4 pool keys.
|
|
455
|
+
// address(0) is always less than any deployed token address.
|
|
456
|
+
key = PoolKey({
|
|
457
|
+
currency0: Currency.wrap(address(0)),
|
|
458
|
+
currency1: Currency.wrap(projectToken),
|
|
459
|
+
fee: REV_DEPLOYER.DEFAULT_BUYBACK_POOL_FEE(),
|
|
460
|
+
tickSpacing: REV_DEPLOYER.DEFAULT_BUYBACK_TICK_SPACING(),
|
|
461
|
+
hooks: IHooks(address(0))
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// Pool is already initialized at 1:1 price by REVDeployer during deployment.
|
|
465
|
+
// Just add liquidity and mock the oracle.
|
|
466
|
+
|
|
467
|
+
// Fund LiquidityHelper with project tokens via JBTokens.mintFor (not deal).
|
|
468
|
+
// deal() skips ERC20Votes checkpoints, causing underflow when tokens are burned.
|
|
469
|
+
vm.prank(address(jbController()));
|
|
470
|
+
jbTokens().mintFor(address(liqHelper), revnetId, liquidityTokenAmount);
|
|
471
|
+
// Fund with ETH for the native currency side.
|
|
472
|
+
vm.deal(address(liqHelper), liquidityTokenAmount);
|
|
473
|
+
|
|
474
|
+
// Approve PoolManager to spend project tokens from LiquidityHelper.
|
|
475
|
+
vm.startPrank(address(liqHelper));
|
|
476
|
+
IERC20(projectToken).approve(address(poolManager), type(uint256).max);
|
|
477
|
+
vm.stopPrank();
|
|
478
|
+
|
|
479
|
+
// Add full-range liquidity.
|
|
480
|
+
int256 liquidityDelta = int256(liquidityTokenAmount / 2);
|
|
481
|
+
vm.prank(address(liqHelper));
|
|
482
|
+
liqHelper.addLiquidity{value: liquidityTokenAmount}(key, TICK_LOWER, TICK_UPPER, liquidityDelta);
|
|
483
|
+
|
|
484
|
+
// Mock the oracle at address(0) for hookless pools.
|
|
485
|
+
_mockOracle(liquidityDelta, 0, uint32(REV_DEPLOYER.DEFAULT_BUYBACK_TWAP_WINDOW()));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/// @notice Mock the IGeomeanOracle at address(0) for hookless pools.
|
|
489
|
+
/// @param liquidity The liquidity to use for secondsPerLiquidity computation.
|
|
490
|
+
/// @param tick The TWAP tick to report (e.g. 0 for 1:1 price).
|
|
491
|
+
/// @param twapWindow The TWAP window in seconds (must match the buyback hook's configured window).
|
|
492
|
+
function _mockOracle(int256 liquidity, int24 tick, uint32 twapWindow) internal {
|
|
493
|
+
// Etch minimal bytecode at address(0) so it's treated as a contract.
|
|
494
|
+
vm.etch(address(0), hex"00");
|
|
495
|
+
|
|
496
|
+
int56[] memory tickCumulatives = new int56[](2);
|
|
497
|
+
tickCumulatives[0] = 0;
|
|
498
|
+
// arithmeticMeanTick = (tickCumulatives[1] - tickCumulatives[0]) / twapWindow = tick
|
|
499
|
+
tickCumulatives[1] = int56(tick) * int56(int32(twapWindow));
|
|
500
|
+
|
|
501
|
+
uint136[] memory secondsPerLiquidityCumulativeX128s = new uint136[](2);
|
|
502
|
+
secondsPerLiquidityCumulativeX128s[0] = 0;
|
|
503
|
+
uint256 liq = uint256(liquidity > 0 ? liquidity : -liquidity);
|
|
504
|
+
if (liq == 0) liq = 1;
|
|
505
|
+
secondsPerLiquidityCumulativeX128s[1] = uint136((uint256(twapWindow) << 128) / liq);
|
|
506
|
+
|
|
507
|
+
vm.mockCall(
|
|
508
|
+
address(0),
|
|
509
|
+
abi.encodeWithSelector(IGeomeanOracle.observe.selector),
|
|
510
|
+
abi.encode(tickCumulatives, secondsPerLiquidityCumulativeX128s)
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/// @notice Build payment metadata with both 721 tier selection AND buyback quote.
|
|
515
|
+
function _buildPayMetadataWithQuote(
|
|
516
|
+
address hookMetadataTarget,
|
|
517
|
+
uint256 amountToSwapWith,
|
|
518
|
+
uint256 minimumSwapAmountOut
|
|
519
|
+
)
|
|
520
|
+
internal
|
|
521
|
+
view
|
|
522
|
+
returns (bytes memory)
|
|
523
|
+
{
|
|
524
|
+
// 721 tier metadata: mint tier 1.
|
|
525
|
+
uint16[] memory tierIds = new uint16[](1);
|
|
526
|
+
tierIds[0] = 1;
|
|
527
|
+
bytes memory tierData = abi.encode(true, tierIds); // (allowOverspending, tierIdsToMint)
|
|
528
|
+
bytes4 tierMetadataId = JBMetadataResolver.getId("pay", hookMetadataTarget);
|
|
529
|
+
|
|
530
|
+
// Buyback quote metadata.
|
|
531
|
+
bytes memory quoteData = abi.encode(amountToSwapWith, minimumSwapAmountOut);
|
|
532
|
+
bytes4 quoteMetadataId = JBMetadataResolver.getId("quote");
|
|
533
|
+
|
|
534
|
+
// Combine both metadata entries.
|
|
535
|
+
bytes4[] memory ids = new bytes4[](2);
|
|
536
|
+
ids[0] = tierMetadataId;
|
|
537
|
+
ids[1] = quoteMetadataId;
|
|
538
|
+
bytes[] memory datas = new bytes[](2);
|
|
539
|
+
datas[0] = tierData;
|
|
540
|
+
datas[1] = quoteData;
|
|
541
|
+
|
|
542
|
+
return JBMetadataResolver.createMetadata(ids, datas);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/// @notice Build payment metadata with only 721 tier selection (no quote → TWAP/spot fallback).
|
|
546
|
+
function _buildPayMetadataNoQuote(address hookMetadataTarget) internal pure returns (bytes memory) {
|
|
547
|
+
uint16[] memory tierIds = new uint16[](1);
|
|
548
|
+
tierIds[0] = 1;
|
|
549
|
+
bytes memory tierData = abi.encode(true, tierIds);
|
|
550
|
+
bytes4 tierMetadataId = JBMetadataResolver.getId("pay", hookMetadataTarget);
|
|
551
|
+
|
|
552
|
+
bytes4[] memory ids = new bytes4[](1);
|
|
553
|
+
ids[0] = tierMetadataId;
|
|
554
|
+
bytes[] memory datas = new bytes[](1);
|
|
555
|
+
datas[0] = tierData;
|
|
556
|
+
|
|
557
|
+
return JBMetadataResolver.createMetadata(ids, datas);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// ───────────────────────── Tests
|
|
561
|
+
// ─────────────────────────
|
|
562
|
+
|
|
563
|
+
/// @notice SWAP PATH: Pool offers good rate → buyback hook swaps on AMM instead of minting.
|
|
564
|
+
/// With 30% tier split, the buyback should swap with 0.7 ETH worth.
|
|
565
|
+
/// Terminal mints 0 tokens (weight=0), buyback hook mints via controller after swap.
|
|
566
|
+
function test_fork_swapPath_splitWithBuyback() public {
|
|
567
|
+
(uint256 revnetId, IJB721TiersHook hook) = _deployRevnetWith721();
|
|
568
|
+
|
|
569
|
+
// We need to initialize the pool and get the price to favor buying project tokens: > 1000 tokens/ETH.
|
|
570
|
+
// Strategy: initialize pool, add liquidity, then swap project tokens for ETH to move the tick.
|
|
571
|
+
|
|
572
|
+
address projectToken = address(jbTokens().tokenOf(revnetId));
|
|
573
|
+
require(projectToken != address(0), "project token not deployed");
|
|
574
|
+
|
|
575
|
+
// Native ETH is address(0), always less than any deployed token.
|
|
576
|
+
PoolKey memory key = PoolKey({
|
|
577
|
+
currency0: Currency.wrap(address(0)),
|
|
578
|
+
currency1: Currency.wrap(projectToken),
|
|
579
|
+
fee: REV_DEPLOYER.DEFAULT_BUYBACK_POOL_FEE(),
|
|
580
|
+
tickSpacing: REV_DEPLOYER.DEFAULT_BUYBACK_TICK_SPACING(),
|
|
581
|
+
hooks: IHooks(address(0))
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
// Pool is already initialized at 1:1 price by REVDeployer during deployment.
|
|
585
|
+
|
|
586
|
+
// Seed liquidity. We need both tokens.
|
|
587
|
+
// IMPORTANT: Use JBTokens.mintFor (not deal) so ERC20Votes checkpoints are updated.
|
|
588
|
+
uint256 projectLiq = 10_000_000e18;
|
|
589
|
+
uint256 ethLiq = 5000e18;
|
|
590
|
+
|
|
591
|
+
vm.prank(address(jbController()));
|
|
592
|
+
jbTokens().mintFor(address(liqHelper), revnetId, projectLiq);
|
|
593
|
+
vm.deal(address(liqHelper), ethLiq);
|
|
594
|
+
|
|
595
|
+
vm.startPrank(address(liqHelper));
|
|
596
|
+
IERC20(projectToken).approve(address(poolManager), type(uint256).max);
|
|
597
|
+
vm.stopPrank();
|
|
598
|
+
|
|
599
|
+
// Add full-range liquidity at tick 0 (1:1 price).
|
|
600
|
+
int256 liquidityDelta = int256(ethLiq / 4);
|
|
601
|
+
vm.prank(address(liqHelper));
|
|
602
|
+
liqHelper.addLiquidity{value: ethLiq}(key, TICK_LOWER, TICK_UPPER, liquidityDelta);
|
|
603
|
+
|
|
604
|
+
// Swap a large amount of project tokens for ETH to move the price.
|
|
605
|
+
// This makes project tokens cheaper (more tokens per ETH) so the swap path wins.
|
|
606
|
+
uint256 swapAmount = 5_000_000e18;
|
|
607
|
+
vm.prank(address(jbController()));
|
|
608
|
+
jbTokens().mintFor(address(liqHelper), revnetId, swapAmount);
|
|
609
|
+
|
|
610
|
+
// currency0 is native ETH (address(0)), currency1 is projectToken.
|
|
611
|
+
// To sell projectToken for ETH (making project tokens cheaper), swap 1->0 (zeroForOne = false).
|
|
612
|
+
// zeroForOne=false pushes sqrtPrice up (more projectTokens per ETH).
|
|
613
|
+
bool zeroForOne = false;
|
|
614
|
+
uint160 sqrtPriceLimit = TickMath.getSqrtPriceAtTick(76_000);
|
|
615
|
+
|
|
616
|
+
vm.prank(address(liqHelper));
|
|
617
|
+
liqHelper.swap(key, zeroForOne, -int256(swapAmount), sqrtPriceLimit);
|
|
618
|
+
|
|
619
|
+
// Read the post-swap tick for the oracle mock.
|
|
620
|
+
(, int24 postSwapTick,,) = poolManager.getSlot0(key.toId());
|
|
621
|
+
|
|
622
|
+
// Mock the TWAP oracle to report the post-swap tick (so buyback hook sees the real price).
|
|
623
|
+
_mockOracle(liquidityDelta, postSwapTick, uint32(REV_DEPLOYER.DEFAULT_BUYBACK_TWAP_WINDOW()));
|
|
624
|
+
|
|
625
|
+
// Build metadata: mint tier 1 + quote for swap.
|
|
626
|
+
// The quote tells buyback to swap with the full amount, expecting at least 1 token out.
|
|
627
|
+
address metadataTarget = hook.METADATA_ID_TARGET();
|
|
628
|
+
bytes memory metadata = _buildPayMetadataWithQuote({
|
|
629
|
+
hookMetadataTarget: metadataTarget,
|
|
630
|
+
amountToSwapWith: 0.7 ether, // projectAmount after 30% split
|
|
631
|
+
minimumSwapAmountOut: 1 // Accept any amount from swap
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
// Pay 1 ETH through the terminal.
|
|
635
|
+
vm.prank(PAYER);
|
|
636
|
+
uint256 terminalTokensReturned = jbMultiTerminal().pay{value: 1 ether}({
|
|
637
|
+
projectId: revnetId,
|
|
638
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
639
|
+
amount: 1 ether,
|
|
640
|
+
beneficiary: PAYER,
|
|
641
|
+
minReturnedTokens: 0,
|
|
642
|
+
memo: "Fork: swap path with splits",
|
|
643
|
+
metadata: metadata
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
// pay() returns beneficiaryBalanceAfter - beneficiaryBalanceBefore, capturing ALL token sources.
|
|
647
|
+
// In the SWAP path:
|
|
648
|
+
// - Terminal mints 0 tokens (weight=0 from buyback hook)
|
|
649
|
+
// - Buyback hook's afterPay swaps 0.7 ETH on AMM and mints via controller
|
|
650
|
+
// - Pool at ~2000:1 price → 0.7 ETH yields ~1400 tokens (minus pool fee)
|
|
651
|
+
// - pay() returns the total (0 from terminal + ~1400 from buyback swap)
|
|
652
|
+
// - More than the 700 tokens minting would produce → swap was the right call
|
|
653
|
+
assertGt(terminalTokensReturned, 700e18, "swap path: should get more tokens than minting (pool rate better)");
|
|
654
|
+
|
|
655
|
+
console.log(
|
|
656
|
+
" Swap path: buyback swapped for %s tokens (minting would give 700)", terminalTokensReturned / 1e18
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/// @notice MINT PATH: Pool offers bad rate → buyback decides minting is better.
|
|
661
|
+
/// With 30% tier split, REVDeployer scales weight from 1000e18 to 700e18.
|
|
662
|
+
/// Terminal mints 700 tokens.
|
|
663
|
+
function test_fork_mintPath_splitWithBuyback() public {
|
|
664
|
+
(uint256 revnetId, IJB721TiersHook hook) = _deployRevnetWith721();
|
|
665
|
+
|
|
666
|
+
// Set up pool with 1:1 price. At this price:
|
|
667
|
+
// 0.7 ETH → ~0.7 tokens from pool (after fees).
|
|
668
|
+
// Direct minting: 700 tokens.
|
|
669
|
+
// Minting wins by a huge margin → buyback returns context.weight unchanged.
|
|
670
|
+
_setupPool(revnetId, 10_000 ether);
|
|
671
|
+
|
|
672
|
+
// Build metadata: mint tier 1 + quote for "swap" with 0.7 ETH, but expect many tokens (forces mint path).
|
|
673
|
+
// When minimumSwapAmountOut > actual pool output, the buyback hook falls back to minting.
|
|
674
|
+
// Actually the buyback hook uses max(payerQuote, twapQuote). If we set minimumSwapAmountOut=0,
|
|
675
|
+
// it'll use the TWAP/spot quote. At 1:1 pool price, spot says ~0.7 tokens for 0.7 ETH.
|
|
676
|
+
// tokenCountWithoutHook = 700 tokens. 700 > ~0.7 → mint wins.
|
|
677
|
+
// We don't even need quote metadata — the spot fallback handles it.
|
|
678
|
+
address metadataTarget = hook.METADATA_ID_TARGET();
|
|
679
|
+
bytes memory metadata = _buildPayMetadataNoQuote(metadataTarget);
|
|
680
|
+
|
|
681
|
+
// Pay 1 ETH through the terminal.
|
|
682
|
+
vm.prank(PAYER);
|
|
683
|
+
uint256 tokensReceived = jbMultiTerminal().pay{value: 1 ether}({
|
|
684
|
+
projectId: revnetId,
|
|
685
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
686
|
+
amount: 1 ether,
|
|
687
|
+
beneficiary: PAYER,
|
|
688
|
+
minReturnedTokens: 0,
|
|
689
|
+
memo: "Fork: mint path with splits",
|
|
690
|
+
metadata: metadata
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
// Mint path: buyback returns context.weight unchanged.
|
|
694
|
+
// REVDeployer scales: weight = 1000e18 * 0.7e18 / 1e18 = 700e18.
|
|
695
|
+
// Terminal: tokenCount = mulDiv(1e18, 700e18, 1e18) = 700e18.
|
|
696
|
+
uint256 expectedTokens = 700e18;
|
|
697
|
+
|
|
698
|
+
assertEq(tokensReceived, expectedTokens, "mint path: should receive 700 tokens (weight scaled for 30% split)");
|
|
699
|
+
|
|
700
|
+
console.log(" Mint path: terminal minted %s tokens (expected 700)", tokensReceived / 1e18);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/// @notice MINT PATH without splits: baseline confirming 1000 tokens for 1 ETH.
|
|
704
|
+
function test_fork_mintPath_noSplits_fullTokens() public {
|
|
705
|
+
(uint256 revnetId,) = _deployRevnetWith721();
|
|
706
|
+
_setupPool(revnetId, 10_000 ether);
|
|
707
|
+
|
|
708
|
+
// Pay 1 ETH with NO tier metadata (no NFT purchase, no splits).
|
|
709
|
+
vm.prank(PAYER);
|
|
710
|
+
uint256 tokensReceived = jbMultiTerminal().pay{value: 1 ether}({
|
|
711
|
+
projectId: revnetId,
|
|
712
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
713
|
+
amount: 1 ether,
|
|
714
|
+
beneficiary: PAYER,
|
|
715
|
+
minReturnedTokens: 0,
|
|
716
|
+
memo: "Fork: no split baseline",
|
|
717
|
+
metadata: ""
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
// No splits → no weight reduction. Full 1000 tokens.
|
|
721
|
+
uint256 expectedTokens = 1000e18;
|
|
722
|
+
assertEq(tokensReceived, expectedTokens, "no splits: should receive 1000 tokens");
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/// @notice Invariant: tokens / projectAmount rate is identical with and without splits.
|
|
726
|
+
function test_fork_invariant_tokenPerEthConsistent() public {
|
|
727
|
+
// --- Revnet 1: with 721 splits (30%) ---
|
|
728
|
+
(uint256 revnetId1, IJB721TiersHook hook1) = _deployRevnetWith721();
|
|
729
|
+
_setupPool(revnetId1, 10_000 ether);
|
|
730
|
+
|
|
731
|
+
address metadataTarget1 = hook1.METADATA_ID_TARGET();
|
|
732
|
+
bytes memory metadata1 = _buildPayMetadataNoQuote(metadataTarget1);
|
|
733
|
+
|
|
734
|
+
vm.prank(PAYER);
|
|
735
|
+
uint256 tokens1 = jbMultiTerminal().pay{value: 1 ether}({
|
|
736
|
+
projectId: revnetId1,
|
|
737
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
738
|
+
amount: 1 ether,
|
|
739
|
+
beneficiary: PAYER,
|
|
740
|
+
minReturnedTokens: 0,
|
|
741
|
+
memo: "invariant: with splits",
|
|
742
|
+
metadata: metadata1
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
// --- Revnet 2: no splits (plain payment, no tier metadata) ---
|
|
746
|
+
// Deploy a second revnet without 721 hook.
|
|
747
|
+
(REVConfig memory cfg2, JBTerminalConfig[] memory tc2, REVSuckerDeploymentConfig memory sdc2) =
|
|
748
|
+
_buildMinimalConfig();
|
|
749
|
+
cfg2.description = REVDescription("NoSplit Fork", "NSF", "ipfs://nosplit", "NSF_SALT");
|
|
750
|
+
|
|
751
|
+
uint256 revnetId2 = REV_DEPLOYER.deployFor({
|
|
752
|
+
revnetId: 0, configuration: cfg2, terminalConfigurations: tc2, suckerDeploymentConfiguration: sdc2
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
// Set up pool for revnet2 too (so buyback hook has a pool, but will choose mint at 1:1).
|
|
756
|
+
_setupPool(revnetId2, 10_000 ether);
|
|
757
|
+
|
|
758
|
+
vm.prank(PAYER);
|
|
759
|
+
uint256 tokens2 = jbMultiTerminal().pay{value: 1 ether}({
|
|
760
|
+
projectId: revnetId2,
|
|
761
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
762
|
+
amount: 1 ether,
|
|
763
|
+
beneficiary: PAYER,
|
|
764
|
+
minReturnedTokens: 0,
|
|
765
|
+
memo: "invariant: no splits",
|
|
766
|
+
metadata: ""
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
// Rate check: tokens / projectAmount should be the same.
|
|
770
|
+
// Revnet 1: 700 tokens / 0.7 ETH = 1000 tokens/ETH
|
|
771
|
+
// Revnet 2: 1000 tokens / 1.0 ETH = 1000 tokens/ETH
|
|
772
|
+
uint256 projectAmount1 = 0.7 ether;
|
|
773
|
+
uint256 projectAmount2 = 1 ether;
|
|
774
|
+
|
|
775
|
+
uint256 rate1 = (tokens1 * 1e18) / projectAmount1;
|
|
776
|
+
uint256 rate2 = (tokens2 * 1e18) / projectAmount2;
|
|
777
|
+
|
|
778
|
+
assertEq(rate1, rate2, "token-per-ETH rate should be identical with and without splits");
|
|
779
|
+
}
|
|
780
|
+
}
|