2025-07-18 20:30:50 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
pragma solidity ^0.8.19;
|
|
|
|
|
|
2025-10-04 15:17:09 +02:00
|
|
|
import { Kraiken } from "../../src/Kraiken.sol";
|
|
|
|
|
|
|
|
|
|
import { LiquidityManager } from "../../src/LiquidityManager.sol";
|
|
|
|
|
|
|
|
|
|
import "../../src/Optimizer.sol";
|
|
|
|
|
import { Stake } from "../../src/Stake.sol";
|
2025-07-18 20:30:50 +02:00
|
|
|
import "../../src/abstracts/ThreePositionStrategy.sol";
|
2025-10-04 15:17:09 +02:00
|
|
|
|
|
|
|
|
import "../../src/helpers/UniswapHelpers.sol";
|
|
|
|
|
import "../../src/interfaces/IWETH9.sol";
|
|
|
|
|
|
|
|
|
|
import "../../test/mocks/MockOptimizer.sol";
|
2025-07-25 18:49:34 +02:00
|
|
|
import "@aperture/uni-v3-lib/TickMath.sol";
|
|
|
|
|
import "@uniswap-v3-core/interfaces/IUniswapV3Factory.sol";
|
|
|
|
|
import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
|
2025-10-04 15:17:09 +02:00
|
|
|
import "forge-std/Test.sol";
|
|
|
|
|
import { WETH } from "solmate/tokens/WETH.sol";
|
2025-07-25 18:49:34 +02:00
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
|
uint24 constant FEE = uint24(10_000); // 1% fee
|
|
|
|
|
uint256 constant INITIAL_LM_ETH_BALANCE = 50 ether;
|
|
|
|
|
uint256 constant ORACLE_UPDATE_INTERVAL = 5 hours;
|
2025-07-18 20:30:50 +02:00
|
|
|
|
|
|
|
|
/**
|
2025-07-25 19:09:11 +02:00
|
|
|
* @title TestConstants
|
|
|
|
|
* @notice Base contract providing shared constants and default parameters for tests
|
|
|
|
|
* @dev Consolidates common test constants to reduce code duplication
|
2025-07-18 20:30:50 +02:00
|
|
|
*/
|
2025-07-25 19:09:11 +02:00
|
|
|
abstract contract TestConstants is Test {
|
2025-07-18 20:30:50 +02:00
|
|
|
/**
|
|
|
|
|
* @notice Returns default parameters for ThreePositionStrategy testing
|
|
|
|
|
* @return Default PositionParams structure with standard values
|
|
|
|
|
* @dev Used across multiple test files to ensure consistency
|
|
|
|
|
*/
|
|
|
|
|
function getDefaultParams() internal pure returns (ThreePositionStrategy.PositionParams memory) {
|
|
|
|
|
return ThreePositionStrategy.PositionParams({
|
2025-10-04 15:17:09 +02:00
|
|
|
capitalInefficiency: 5 * 10 ** 17, // 50%
|
|
|
|
|
anchorShare: 5 * 10 ** 17, // 50%
|
|
|
|
|
anchorWidth: 50, // 50%
|
|
|
|
|
discoveryDepth: 5 * 10 ** 17 // 50%
|
2026-03-22 19:45:35 +00:00
|
|
|
});
|
2025-07-18 20:30:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notice Helper function to convert value to basis points
|
|
|
|
|
* @param val Value to convert
|
|
|
|
|
* @return Value in basis points
|
|
|
|
|
*/
|
|
|
|
|
function bp(uint256 val) internal pure returns (uint256) {
|
|
|
|
|
return val / 1e15;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notice Helper function to denormalize tax rate
|
|
|
|
|
* @param normalizedTaxRate Normalized tax rate
|
|
|
|
|
* @return Denormalized tax rate
|
|
|
|
|
*/
|
|
|
|
|
function denormTR(uint256 normalizedTaxRate) internal pure returns (uint256) {
|
|
|
|
|
return normalizedTaxRate * 97;
|
|
|
|
|
}
|
2025-07-25 18:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-25 19:09:11 +02:00
|
|
|
* @title TestEnvironment
|
|
|
|
|
* @notice Helper contract that provides test environment setup for LiquidityManager tests and scripts
|
2025-07-25 18:49:34 +02:00
|
|
|
* @dev Extracted from LiquidityManager.t.sol to enable reuse without inheritance
|
|
|
|
|
*/
|
2025-07-25 19:09:11 +02:00
|
|
|
contract TestEnvironment is TestConstants {
|
2025-07-25 18:49:34 +02:00
|
|
|
using UniswapHelpers for IUniswapV3Pool;
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
// Core contracts
|
2026-02-02 19:24:57 +01:00
|
|
|
IUniswapV3Factory internal factory;
|
|
|
|
|
IUniswapV3Pool internal pool;
|
|
|
|
|
IWETH9 internal weth;
|
|
|
|
|
Kraiken internal harberg;
|
|
|
|
|
Stake internal stake;
|
|
|
|
|
LiquidityManager internal lm;
|
|
|
|
|
Optimizer internal optimizer;
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
// State variables
|
2026-02-02 19:24:57 +01:00
|
|
|
bool internal token0isWeth;
|
|
|
|
|
address internal feeDestination;
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
constructor(address _feeDestination) {
|
|
|
|
|
feeDestination = _feeDestination;
|
|
|
|
|
}
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
/**
|
|
|
|
|
* @notice Deploy all contracts and set up the environment
|
|
|
|
|
* @param token0shouldBeWeth Whether WETH should be token0
|
|
|
|
|
* @return _factory The deployed Uniswap factory
|
|
|
|
|
* @return _pool The created Uniswap pool
|
|
|
|
|
* @return _weth The WETH token contract
|
|
|
|
|
* @return _harberg The Kraiken token contract
|
|
|
|
|
* @return _stake The staking contract
|
|
|
|
|
* @return _lm The liquidity manager contract
|
|
|
|
|
* @return _optimizer The optimizer contract
|
|
|
|
|
* @return _token0isWeth Whether token0 is WETH
|
|
|
|
|
*/
|
2026-03-14 09:15:48 +00:00
|
|
|
function setupEnvironment(bool token0shouldBeWeth)
|
2025-10-04 15:17:09 +02:00
|
|
|
external
|
|
|
|
|
returns (
|
|
|
|
|
IUniswapV3Factory _factory,
|
|
|
|
|
IUniswapV3Pool _pool,
|
|
|
|
|
IWETH9 _weth,
|
|
|
|
|
Kraiken _harberg,
|
|
|
|
|
Stake _stake,
|
|
|
|
|
LiquidityManager _lm,
|
|
|
|
|
Optimizer _optimizer,
|
|
|
|
|
bool _token0isWeth
|
|
|
|
|
)
|
|
|
|
|
{
|
2025-07-25 18:49:34 +02:00
|
|
|
// Deploy factory
|
|
|
|
|
factory = UniswapHelpers.deployUniswapFactory();
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
// Deploy tokens in correct order
|
|
|
|
|
_deployTokensWithOrder(token0shouldBeWeth);
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
// Create and initialize pool
|
|
|
|
|
_createAndInitializePool();
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
// Deploy protocol contracts
|
|
|
|
|
_deployProtocolContracts();
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
// Configure permissions
|
|
|
|
|
_configurePermissions();
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
return (factory, pool, weth, harberg, stake, lm, optimizer, token0isWeth);
|
|
|
|
|
}
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
/**
|
|
|
|
|
* @notice Deploy tokens ensuring the desired ordering
|
|
|
|
|
* @param token0shouldBeWeth Whether WETH should be token0
|
|
|
|
|
*/
|
|
|
|
|
function _deployTokensWithOrder(bool token0shouldBeWeth) internal {
|
|
|
|
|
bool setupComplete = false;
|
|
|
|
|
uint256 retryCount = 0;
|
|
|
|
|
|
feat: OptimizerV3 with direct 2D staking-to-LP parameter mapping
Core protocol changes for launch readiness:
- OptimizerV3: binary bear/bull mapping from (staking%, avgTax) — avoids
exploitable AW 30-90 kill zone. Bear: AS=30%, AW=100, CI=0, DD=0.3e18.
Bull: AS=100%, AW=20, CI=0, DD=1e18. UUPS upgradeable with __gap[48].
- Directional VWAP: only records prices on ETH inflow (buys), preventing
sell-side dilution of price memory
- Floor formula: unified max(scarcity, mirror, clamp) — VWAP mirror uses
distance from adjusted VWAP as floor distance, no branching
- PriceOracle (M-1 fix): correct fallback TWAP divisor (60000s, not 300s)
- Access control (M-2 fix): deployer-only guard on one-time setters
- Recenter rate limit (M-3 fix): 60-second cooldown for open recenters
- Safe fallback params: recenter() optimizer-failure defaults changed from
exploitable CI=50%/AW=50 to safe bear-mode CI=0/AW=100
- Recentered event for monitoring and indexing
- VERSION bump to 2, kraiken-lib COMPATIBLE_CONTRACT_VERSIONS updated
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:21:18 +00:00
|
|
|
while (!setupComplete && retryCount < 20) {
|
2025-07-25 18:49:34 +02:00
|
|
|
// Clean slate if retrying
|
|
|
|
|
if (retryCount > 0) {
|
|
|
|
|
// Deploy a dummy contract to shift addresses
|
|
|
|
|
new WETH(); // Use WETH as dummy to avoid declaring new contract
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
weth = IWETH9(address(new WETH()));
|
2025-08-19 11:05:08 +02:00
|
|
|
harberg = new Kraiken("KRAIKEN", "KRAIKEN");
|
2025-07-25 18:49:34 +02:00
|
|
|
|
|
|
|
|
// Check if the setup meets the required condition
|
|
|
|
|
if (token0shouldBeWeth == (address(weth) < address(harberg))) {
|
|
|
|
|
setupComplete = true;
|
|
|
|
|
} else {
|
|
|
|
|
// Clear current instances for re-deployment
|
|
|
|
|
delete weth;
|
|
|
|
|
delete harberg;
|
|
|
|
|
retryCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
require(setupComplete, "Setup failed to meet the condition after several retries");
|
|
|
|
|
}
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
/**
|
|
|
|
|
* @notice Create and initialize the Uniswap pool
|
2026-03-22 19:45:35 +00:00
|
|
|
* @dev Warp 61 seconds after pool init so _isPriceStable()'s 30-second TWAP window
|
|
|
|
|
* has sufficient history AND the 60-second recenter cooldown is satisfied
|
|
|
|
|
* for any subsequent recenter() call.
|
2025-07-25 18:49:34 +02:00
|
|
|
*/
|
|
|
|
|
function _createAndInitializePool() internal {
|
|
|
|
|
pool = IUniswapV3Pool(factory.createPool(address(weth), address(harberg), FEE));
|
|
|
|
|
token0isWeth = address(weth) < address(harberg);
|
|
|
|
|
pool.initializePoolFor1Cent(token0isWeth);
|
2026-03-22 19:45:35 +00:00
|
|
|
vm.warp(block.timestamp + 61);
|
2025-07-25 18:49:34 +02:00
|
|
|
}
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
/**
|
|
|
|
|
* @notice Deploy protocol contracts (Stake, Optimizer, LiquidityManager)
|
|
|
|
|
*/
|
|
|
|
|
function _deployProtocolContracts() internal {
|
|
|
|
|
stake = new Stake(address(harberg), feeDestination);
|
|
|
|
|
optimizer = Optimizer(address(new MockOptimizer()));
|
|
|
|
|
optimizer.initialize(address(harberg), address(stake));
|
|
|
|
|
lm = new LiquidityManager(address(factory), address(weth), address(harberg), address(optimizer));
|
|
|
|
|
lm.setFeeDestination(feeDestination);
|
|
|
|
|
}
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
/**
|
|
|
|
|
* @notice Configure permissions and initial funding
|
|
|
|
|
*/
|
|
|
|
|
function _configurePermissions() internal {
|
|
|
|
|
harberg.setStakingPool(address(stake));
|
|
|
|
|
harberg.setLiquidityManager(address(lm));
|
|
|
|
|
vm.deal(address(lm), INITIAL_LM_ETH_BALANCE);
|
|
|
|
|
}
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
/**
|
|
|
|
|
* @notice Setup environment with specific optimizer
|
|
|
|
|
* @param token0shouldBeWeth Whether WETH should be token0
|
|
|
|
|
* @param optimizerAddress Address of the optimizer to use
|
|
|
|
|
* @return _factory The deployed Uniswap factory
|
|
|
|
|
* @return _pool The created Uniswap pool
|
|
|
|
|
* @return _weth The WETH token contract
|
|
|
|
|
* @return _harberg The Kraiken token contract
|
|
|
|
|
* @return _stake The staking contract
|
|
|
|
|
* @return _lm The liquidity manager contract
|
|
|
|
|
* @return _optimizer The optimizer contract
|
|
|
|
|
* @return _token0isWeth Whether token0 is WETH
|
|
|
|
|
*/
|
2026-03-22 19:45:35 +00:00
|
|
|
function setupEnvironmentWithOptimizer(
|
|
|
|
|
bool token0shouldBeWeth,
|
|
|
|
|
address optimizerAddress
|
|
|
|
|
)
|
2025-10-04 15:17:09 +02:00
|
|
|
external
|
|
|
|
|
returns (
|
|
|
|
|
IUniswapV3Factory _factory,
|
|
|
|
|
IUniswapV3Pool _pool,
|
|
|
|
|
IWETH9 _weth,
|
|
|
|
|
Kraiken _harberg,
|
|
|
|
|
Stake _stake,
|
|
|
|
|
LiquidityManager _lm,
|
|
|
|
|
Optimizer _optimizer,
|
|
|
|
|
bool _token0isWeth
|
|
|
|
|
)
|
|
|
|
|
{
|
2025-07-25 18:49:34 +02:00
|
|
|
// Deploy factory
|
|
|
|
|
factory = UniswapHelpers.deployUniswapFactory();
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
// Deploy tokens in correct order
|
|
|
|
|
_deployTokensWithOrder(token0shouldBeWeth);
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
// Create and initialize pool
|
|
|
|
|
_createAndInitializePool();
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
// Deploy protocol contracts with custom optimizer
|
|
|
|
|
stake = new Stake(address(harberg), feeDestination);
|
|
|
|
|
optimizer = Optimizer(optimizerAddress);
|
2025-08-09 18:03:31 +02:00
|
|
|
lm = new LiquidityManager(address(factory), address(weth), address(harberg), optimizerAddress);
|
|
|
|
|
lm.setFeeDestination(feeDestination);
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-08-09 18:03:31 +02:00
|
|
|
// Configure permissions
|
|
|
|
|
_configurePermissions();
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-08-09 18:03:31 +02:00
|
|
|
return (factory, pool, weth, harberg, stake, lm, optimizer, token0isWeth);
|
|
|
|
|
}
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2026-03-10 10:11:41 +00:00
|
|
|
/**
|
|
|
|
|
* @notice Deploy all contracts with feeDestination set to the LiquidityManager itself.
|
|
|
|
|
* @dev Useful for testing the "fees accrue as liquidity" path introduced in issue #533.
|
|
|
|
|
* When feeDestination == address(lm), _scrapePositions skips fee transfers and
|
|
|
|
|
* _getOutstandingSupply skips the feeDestination KRK subtraction (already excluded
|
|
|
|
|
* by outstandingSupply()).
|
|
|
|
|
* @param token0shouldBeWeth Whether WETH should be token0
|
|
|
|
|
*/
|
2026-03-14 09:15:48 +00:00
|
|
|
function setupEnvironmentWithSelfFeeDestination(bool token0shouldBeWeth)
|
2026-03-10 10:11:41 +00:00
|
|
|
external
|
|
|
|
|
returns (
|
|
|
|
|
IUniswapV3Factory _factory,
|
|
|
|
|
IUniswapV3Pool _pool,
|
|
|
|
|
IWETH9 _weth,
|
|
|
|
|
Kraiken _harberg,
|
|
|
|
|
Stake _stake,
|
|
|
|
|
LiquidityManager _lm,
|
|
|
|
|
Optimizer _optimizer,
|
|
|
|
|
bool _token0isWeth
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
// Deploy factory and tokens
|
|
|
|
|
factory = UniswapHelpers.deployUniswapFactory();
|
|
|
|
|
_deployTokensWithOrder(token0shouldBeWeth);
|
|
|
|
|
_createAndInitializePool();
|
|
|
|
|
|
|
|
|
|
// Deploy protocol contracts; Stake gets a throwaway feeDestination address
|
|
|
|
|
address stakeFee = makeAddr("stakeFeeDestination");
|
|
|
|
|
stake = new Stake(address(harberg), stakeFee);
|
|
|
|
|
optimizer = Optimizer(address(new MockOptimizer()));
|
|
|
|
|
optimizer.initialize(address(harberg), address(stake));
|
|
|
|
|
lm = new LiquidityManager(address(factory), address(weth), address(harberg), address(optimizer));
|
|
|
|
|
|
|
|
|
|
// Set feeDestination to the LM itself — this is the self-referencing mode under test
|
|
|
|
|
lm.setFeeDestination(address(lm));
|
|
|
|
|
|
|
|
|
|
harberg.setStakingPool(address(stake));
|
|
|
|
|
harberg.setLiquidityManager(address(lm));
|
2026-03-20 01:05:05 +00:00
|
|
|
vm.deal(address(lm), INITIAL_LM_ETH_BALANCE);
|
|
|
|
|
|
|
|
|
|
return (factory, pool, weth, harberg, stake, lm, optimizer, token0isWeth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notice Deploy all contracts WITHOUT calling setFeeDestination — feeDestination stays address(0).
|
|
|
|
|
* @dev Regression helper for issue #624: verifies that _scrapePositions gracefully handles
|
|
|
|
|
* an uninitialized feeDestination instead of attempting safeTransfer to address(0).
|
|
|
|
|
* @param token0shouldBeWeth Whether WETH should be token0
|
|
|
|
|
*/
|
|
|
|
|
function setupEnvironmentWithUnsetFeeDestination(bool token0shouldBeWeth)
|
|
|
|
|
external
|
|
|
|
|
returns (
|
|
|
|
|
IUniswapV3Factory _factory,
|
|
|
|
|
IUniswapV3Pool _pool,
|
|
|
|
|
IWETH9 _weth,
|
|
|
|
|
Kraiken _harberg,
|
|
|
|
|
Stake _stake,
|
|
|
|
|
LiquidityManager _lm,
|
|
|
|
|
Optimizer _optimizer,
|
|
|
|
|
bool _token0isWeth
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
// Deploy factory and tokens
|
|
|
|
|
factory = UniswapHelpers.deployUniswapFactory();
|
|
|
|
|
_deployTokensWithOrder(token0shouldBeWeth);
|
|
|
|
|
_createAndInitializePool();
|
|
|
|
|
|
|
|
|
|
// Deploy protocol contracts; Stake gets a throwaway feeDestination address
|
|
|
|
|
address stakeFee = makeAddr("stakeFeeDestination");
|
|
|
|
|
stake = new Stake(address(harberg), stakeFee);
|
|
|
|
|
optimizer = Optimizer(address(new MockOptimizer()));
|
|
|
|
|
optimizer.initialize(address(harberg), address(stake));
|
|
|
|
|
lm = new LiquidityManager(address(factory), address(weth), address(harberg), address(optimizer));
|
|
|
|
|
|
|
|
|
|
// Intentionally do NOT call lm.setFeeDestination() — feeDestination stays address(0)
|
|
|
|
|
|
|
|
|
|
harberg.setStakingPool(address(stake));
|
|
|
|
|
harberg.setLiquidityManager(address(lm));
|
2026-03-10 10:11:41 +00:00
|
|
|
vm.deal(address(lm), INITIAL_LM_ETH_BALANCE);
|
|
|
|
|
|
|
|
|
|
return (factory, pool, weth, harberg, stake, lm, optimizer, token0isWeth);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-09 18:03:31 +02:00
|
|
|
/**
|
|
|
|
|
* @notice Setup environment with existing factory and specific optimizer
|
|
|
|
|
* @param existingFactory The existing Uniswap factory to use
|
|
|
|
|
* @param token0shouldBeWeth Whether WETH should be token0
|
|
|
|
|
* @param optimizerAddress Address of the optimizer to use
|
|
|
|
|
* @return _factory The existing Uniswap factory
|
|
|
|
|
* @return _pool The created Uniswap pool
|
|
|
|
|
* @return _weth The WETH token contract
|
|
|
|
|
* @return _harberg The Kraiken token contract
|
|
|
|
|
* @return _stake The staking contract
|
|
|
|
|
* @return _lm The liquidity manager contract
|
|
|
|
|
* @return _optimizer The optimizer contract
|
|
|
|
|
* @return _token0isWeth Whether token0 is WETH
|
|
|
|
|
*/
|
|
|
|
|
function setupEnvironmentWithExistingFactory(
|
|
|
|
|
IUniswapV3Factory existingFactory,
|
2025-10-04 15:17:09 +02:00
|
|
|
bool token0shouldBeWeth,
|
2025-08-09 18:03:31 +02:00
|
|
|
address optimizerAddress
|
2025-10-04 15:17:09 +02:00
|
|
|
)
|
|
|
|
|
external
|
|
|
|
|
returns (
|
|
|
|
|
IUniswapV3Factory _factory,
|
|
|
|
|
IUniswapV3Pool _pool,
|
|
|
|
|
IWETH9 _weth,
|
|
|
|
|
Kraiken _harberg,
|
|
|
|
|
Stake _stake,
|
|
|
|
|
LiquidityManager _lm,
|
|
|
|
|
Optimizer _optimizer,
|
|
|
|
|
bool _token0isWeth
|
|
|
|
|
)
|
|
|
|
|
{
|
2025-08-09 18:03:31 +02:00
|
|
|
// Use existing factory
|
|
|
|
|
factory = existingFactory;
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-08-09 18:03:31 +02:00
|
|
|
// Deploy tokens in correct order
|
|
|
|
|
_deployTokensWithOrder(token0shouldBeWeth);
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-08-09 18:03:31 +02:00
|
|
|
// Create and initialize pool
|
|
|
|
|
_createAndInitializePool();
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-08-09 18:03:31 +02:00
|
|
|
// Deploy protocol contracts with custom optimizer
|
|
|
|
|
stake = new Stake(address(harberg), feeDestination);
|
|
|
|
|
optimizer = Optimizer(optimizerAddress);
|
2025-07-25 18:49:34 +02:00
|
|
|
lm = new LiquidityManager(address(factory), address(weth), address(harberg), optimizerAddress);
|
|
|
|
|
lm.setFeeDestination(feeDestination);
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
// Configure permissions
|
|
|
|
|
_configurePermissions();
|
2025-10-04 15:17:09 +02:00
|
|
|
|
2025-07-25 18:49:34 +02:00
|
|
|
return (factory, pool, weth, harberg, stake, lm, optimizer, token0isWeth);
|
|
|
|
|
}
|
2025-10-04 15:17:09 +02:00
|
|
|
}
|