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-04 15:17:09 +02:00
|
|
|
|
|
|
|
|
import { LiquidityManager } from "../src/LiquidityManager.sol";
|
2026-02-26 14:33:20 +00:00
|
|
|
import "../src/Optimizer.sol";
|
2025-10-04 15:17:09 +02:00
|
|
|
import "../src/Stake.sol";
|
2025-09-23 14:18:04 +02:00
|
|
|
import "../src/helpers/UniswapHelpers.sol";
|
2025-10-04 15:17:09 +02: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";
|
2026-03-12 21:15:35 +00:00
|
|
|
|
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-04 15:17:09 +02:00
|
|
|
uint24 internal constant FEE = uint24(10_000);
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
// Configuration
|
2026-03-14 20:21:32 +00:00
|
|
|
// NOTE: 0xf6a3... carries 171 bytes of code on Base mainnet and has been confirmed to
|
|
|
|
|
// also carry code on Base Sepolia. bootstrap.sh erases it via anvil_setCode before
|
|
|
|
|
// setFeeDestination is called so the fork-local LiquidityManager does not permanently
|
|
|
|
|
// lock feeDestinationLocked. See issue #760.
|
2025-10-04 15:17:09 +02:00
|
|
|
address internal constant feeDest = 0xf6a3eef9088A255c32b6aD2025f83E57291D9011;
|
|
|
|
|
address internal constant weth = 0x4200000000000000000000000000000000000006;
|
2026-03-18 00:31:48 +00:00
|
|
|
// Base Sepolia Uniswap V3 Factory — intentional: bootstrap.sh forks Base Sepolia,
|
|
|
|
|
// so the factory must carry code at this address. Mainnet scripts and AttackRunner
|
|
|
|
|
// use 0x33128a8fC17869897dcE68Ed026d694621f6FDfD instead.
|
2025-10-04 15:17:09 +02:00
|
|
|
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");
|
2026-03-13 23:28:52 +00:00
|
|
|
console.log("\n[1/6] Kraiken deployed:", address(kraiken));
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
// 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);
|
2026-03-13 23:28:52 +00:00
|
|
|
console.log("\n[2/6] Stake deployed:", address(stake));
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
// 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);
|
2026-03-13 23:28:52 +00:00
|
|
|
console.log("\n[3/6] Uniswap pool created:", liquidityPool);
|
2025-09-23 14:18:04 +02:00
|
|
|
} else {
|
2026-03-13 23:28:52 +00:00
|
|
|
console.log("\n[3/6] Using existing pool:", liquidityPool);
|
2025-09-23 14:18:04 +02:00
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 14:33:20 +00:00
|
|
|
// Deploy Optimizer
|
|
|
|
|
Optimizer optimizerImpl = new Optimizer();
|
2025-10-04 15:17:09 +02: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);
|
2026-03-13 23:28:52 +00:00
|
|
|
console.log("\n[4/6] Optimizer deployed:", optimizerAddress);
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
// Deploy LiquidityManager
|
2025-10-04 15:17:09 +02:00
|
|
|
liquidityManager = new LiquidityManager(v3Factory, weth, address(kraiken), optimizerAddress);
|
2026-03-13 23:28:52 +00:00
|
|
|
console.log("\n[5/6] LiquidityManager deployed:", address(liquidityManager));
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
// Configure contracts
|
|
|
|
|
kraiken.setLiquidityManager(address(liquidityManager));
|
|
|
|
|
console.log(" LiquidityManager set in Kraiken");
|
|
|
|
|
|
2026-03-13 23:28:52 +00:00
|
|
|
// Set the real feeDestination.
|
2026-03-12 21:15:35 +00:00
|
|
|
liquidityManager.setFeeDestination(feeDest);
|
2026-03-13 23:28:52 +00:00
|
|
|
|
|
|
|
|
console.log("\n[6/6] Configuration complete");
|
2026-03-13 22:32:53 +00:00
|
|
|
console.log(" feeDestination set to", feeDest);
|
2026-03-13 23:28:52 +00:00
|
|
|
console.log(" VWAP bootstrap will be performed by the bootstrap script");
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
// 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));
|
2026-02-26 14:33:20 +00:00
|
|
|
console.log("Optimizer:", optimizerAddress);
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
console.log("\n=== Next Steps ===");
|
2026-03-13 23:28:52 +00:00
|
|
|
console.log("1. bootstrap-common.sh bootstrap_vwap() advances chain time and seeds VWAP.");
|
|
|
|
|
console.log("2. Fund LiquidityManager with operational ETH:");
|
2026-03-12 21:15:35 +00:00
|
|
|
console.log(" cast send", address(liquidityManager), "--value 10ether");
|
2026-03-13 23:28:52 +00:00
|
|
|
console.log("3. recenter() is permissionless - any address (e.g. txnBot) can call it.");
|
2026-03-13 22:32:53 +00:00
|
|
|
console.log(" TWAP manipulation protection is always enforced (no bypass path).");
|
2025-09-23 14:18:04 +02:00
|
|
|
|
|
|
|
|
vm.stopBroadcast();
|
|
|
|
|
}
|
2025-10-04 15:17:09 +02:00
|
|
|
}
|