harb/onchain/script/backtesting/ShadowPoolDeployer.sol
openhands 96b06bd9fe fix: Backtesting #2: Foundry script skeleton + Uniswap V3 shadow pool deployment (#316)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 05:08:27 +00:00

49 lines
1.5 KiB
Solidity

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.19;
import { IUniswapV3Factory } from "@uniswap-v3-core/interfaces/IUniswapV3Factory.sol";
import { IUniswapV3Pool } from "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
import { UniswapHelpers } from "../../src/helpers/UniswapHelpers.sol";
struct ShadowPool {
IUniswapV3Factory factory;
IUniswapV3Pool pool;
address token0;
address token1;
}
/**
* @title ShadowPoolDeployer
* @notice Deploys a fresh UniswapV3Factory and pool for backtesting.
* SHADOW_FEE = 10 000 (1%) matches the AERO/WETH pool on Base.
*/
library ShadowPoolDeployer {
uint24 internal constant SHADOW_FEE = 10_000;
/**
* @notice Deploy a new UniswapV3 factory + pool and initialize it.
* @param tokenA One of the two mock tokens (any order).
* @param tokenB The other mock token.
* @param sqrtPriceX96 Initial sqrt price (Q64.96).
* @return sp ShadowPool struct with factory, pool, token0, token1 addresses.
*/
function deploy(
address tokenA,
address tokenB,
uint160 sqrtPriceX96
)
internal
returns (ShadowPool memory sp)
{
sp.factory = UniswapHelpers.deployUniswapFactory();
address poolAddr = sp.factory.createPool(tokenA, tokenB, SHADOW_FEE);
sp.pool = IUniswapV3Pool(poolAddr);
sp.pool.initialize(sqrtPriceX96);
// Resolve canonical token ordering from the pool.
sp.token0 = sp.pool.token0();
sp.token1 = sp.pool.token1();
}
}