2025-09-23 14:18:04 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
pragma solidity ^0.8.19;
|
|
|
|
|
|
|
|
|
|
import "../src/Kraiken.sol";
|
2025-10-02 15:14:50 +00:00
|
|
|
|
|
|
|
|
import { LiquidityManager } from "../src/LiquidityManager.sol";
|
2025-09-23 14:18:04 +02:00
|
|
|
import "../src/Optimizer.sol";
|
2025-10-02 15:14:50 +00:00
|
|
|
import "../src/Stake.sol";
|
2025-09-23 14:18:04 +02:00
|
|
|
import "../src/helpers/UniswapHelpers.sol";
|
2025-10-02 15:14:50 +00:00
|
|
|
import { ERC1967Proxy } from "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
|
|
|
|
|
import "@uniswap-v3-core/interfaces/IUniswapV3Factory.sol";
|
|
|
|
|
import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
|
|
|
|
|
import "forge-std/Script.sol";
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @title DeployLocal
|
|
|
|
|
* @notice Deployment script for local Anvil fork
|
|
|
|
|
* @dev Run with: forge script script/DeployLocal.sol --rpc-url http://localhost:8545 --broadcast
|
|
|
|
|
*/
|
|
|
|
|
contract DeployLocal is Script {
|
|
|
|
|
using UniswapHelpers for IUniswapV3Pool;
|
|
|
|
|
|
2025-10-02 15:14:50 +00:00
|
|
|
uint24 internal constant FEE = uint24(10_000);
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
// Configuration
|
2025-10-02 15:14:50 +00:00
|
|
|
address internal constant feeDest = 0xf6a3eef9088A255c32b6aD2025f83E57291D9011;
|
|
|
|
|
address internal constant weth = 0x4200000000000000000000000000000000000006;
|
|
|
|
|
address internal constant v3Factory = 0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24;
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
// Deployed contracts
|
|
|
|
|
Kraiken public kraiken;
|
|
|
|
|
Stake public stake;
|
|
|
|
|
LiquidityManager public liquidityManager;
|
|
|
|
|
IUniswapV3Pool public pool;
|
|
|
|
|
bool public token0isWeth;
|
|
|
|
|
|
|
|
|
|
function run() public {
|
|
|
|
|
// Use local mnemonic file for consistent deployment
|
|
|
|
|
string memory seedPhrase = vm.readFile(".secret.local");
|
|
|
|
|
uint256 privateKey = vm.deriveKey(seedPhrase, 0);
|
|
|
|
|
vm.startBroadcast(privateKey);
|
|
|
|
|
address sender = vm.addr(privateKey);
|
|
|
|
|
|
|
|
|
|
console.log("\n=== Starting Local Deployment ===");
|
|
|
|
|
console.log("Deployer:", sender);
|
|
|
|
|
console.log("Using mnemonic from .secret.local");
|
|
|
|
|
console.log("Chain ID: 31337 (Local Anvil)");
|
|
|
|
|
|
|
|
|
|
// Deploy Kraiken token
|
|
|
|
|
kraiken = new Kraiken("Kraiken", "KRK");
|
|
|
|
|
console.log("\n[1/6] Kraiken deployed:", address(kraiken));
|
|
|
|
|
|
|
|
|
|
// Determine token ordering
|
|
|
|
|
token0isWeth = address(weth) < address(kraiken);
|
|
|
|
|
console.log(" Token ordering - WETH is token0:", token0isWeth);
|
|
|
|
|
|
|
|
|
|
// Deploy Stake contract
|
|
|
|
|
stake = new Stake(address(kraiken), feeDest);
|
|
|
|
|
console.log("\n[2/6] Stake deployed:", address(stake));
|
|
|
|
|
|
|
|
|
|
// Set staking pool in Kraiken
|
|
|
|
|
kraiken.setStakingPool(address(stake));
|
|
|
|
|
console.log(" Staking pool set in Kraiken");
|
|
|
|
|
|
|
|
|
|
// Get or create Uniswap V3 pool
|
|
|
|
|
IUniswapV3Factory factory = IUniswapV3Factory(v3Factory);
|
|
|
|
|
address liquidityPool = factory.getPool(weth, address(kraiken), FEE);
|
|
|
|
|
if (liquidityPool == address(0)) {
|
|
|
|
|
liquidityPool = factory.createPool(weth, address(kraiken), FEE);
|
|
|
|
|
console.log("\n[3/6] Uniswap pool created:", liquidityPool);
|
|
|
|
|
} else {
|
|
|
|
|
console.log("\n[3/6] Using existing pool:", liquidityPool);
|
|
|
|
|
}
|
|
|
|
|
pool = IUniswapV3Pool(liquidityPool);
|
|
|
|
|
|
|
|
|
|
// Initialize pool at 1 cent price if not already initialized
|
|
|
|
|
try pool.slot0() returns (uint160 sqrtPriceX96, int24, uint16, uint16, uint16, uint8, bool) {
|
|
|
|
|
if (sqrtPriceX96 == 0) {
|
|
|
|
|
pool.initializePoolFor1Cent(token0isWeth);
|
|
|
|
|
console.log(" Pool initialized at 1 cent price");
|
|
|
|
|
} else {
|
|
|
|
|
console.log(" Pool already initialized");
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
pool.initializePoolFor1Cent(token0isWeth);
|
|
|
|
|
console.log(" Pool initialized at 1 cent price");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Deploy Optimizer
|
|
|
|
|
Optimizer optimizerImpl = new Optimizer();
|
2025-10-02 15:14:50 +00:00
|
|
|
bytes memory params = abi.encodeWithSignature("initialize(address,address)", address(kraiken), address(stake));
|
2025-09-23 14:18:04 +02:00
|
|
|
ERC1967Proxy proxy = new ERC1967Proxy(address(optimizerImpl), params);
|
|
|
|
|
address optimizerAddress = address(proxy);
|
|
|
|
|
console.log("\n[4/6] Optimizer deployed:", optimizerAddress);
|
|
|
|
|
|
|
|
|
|
// Deploy LiquidityManager
|
2025-10-02 15:14:50 +00:00
|
|
|
liquidityManager = new LiquidityManager(v3Factory, weth, address(kraiken), optimizerAddress);
|
2025-09-23 14:18:04 +02:00
|
|
|
console.log("\n[5/6] LiquidityManager deployed:", address(liquidityManager));
|
|
|
|
|
|
|
|
|
|
// Configure contracts
|
|
|
|
|
liquidityManager.setFeeDestination(feeDest);
|
|
|
|
|
console.log(" Fee destination set");
|
|
|
|
|
|
|
|
|
|
kraiken.setLiquidityManager(address(liquidityManager));
|
|
|
|
|
console.log(" LiquidityManager set in Kraiken");
|
|
|
|
|
|
|
|
|
|
console.log("\n[6/6] Configuration complete");
|
|
|
|
|
|
|
|
|
|
// Print deployment summary
|
|
|
|
|
console.log("\n=== Deployment Summary ===");
|
|
|
|
|
console.log("Kraiken (KRK):", address(kraiken));
|
|
|
|
|
console.log("Stake:", address(stake));
|
|
|
|
|
console.log("Pool:", address(pool));
|
|
|
|
|
console.log("LiquidityManager:", address(liquidityManager));
|
|
|
|
|
console.log("Optimizer:", optimizerAddress);
|
|
|
|
|
|
|
|
|
|
console.log("\n=== Next Steps ===");
|
|
|
|
|
console.log("1. Fund LiquidityManager with ETH:");
|
|
|
|
|
console.log(" cast send", address(liquidityManager), "--value 0.1ether");
|
|
|
|
|
console.log("2. Call recenter to initialize positions:");
|
2025-10-02 15:14:50 +00:00
|
|
|
console.log(" cast send", address(liquidityManager), "\"recenter()\"");
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
vm.stopBroadcast();
|
|
|
|
|
}
|
2025-10-02 15:14:50 +00:00
|
|
|
}
|