// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {Script, console} from "forge-std/Script.sol";
import {DODOPMMIntegration} from "../../contracts/dex/DODOPMMIntegration.sol";

/**
 * @title CreateCUSDTCUSDCPool
 * @notice Call createCUSDTCUSDCPool on existing DODOPMMIntegration (Chain 138).
 * @dev Requires caller to have POOL_MANAGER_ROLE. Run with --broadcast.
 */
contract CreateCUSDTCUSDCPool is Script {
    uint256 constant LP_FEE_BPS = 3;
    uint256 constant INITIAL_PRICE_1E18 = 1e18;
    uint256 constant K_50PCT = 0.5e18;
    bool constant USE_TWAP = true;

    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address integrationAddr = vm.envAddress("DODO_PMM_INTEGRATION");
        if (integrationAddr == address(0)) {
            integrationAddr = vm.envAddress("DODO_PMM_INTEGRATION_ADDRESS");
        }
        require(integrationAddr != address(0), "DODO_PMM_INTEGRATION not set");

        address deployer = vm.addr(pk);
        uint64 nextNonce = uint64(vm.envOr("NEXT_NONCE", uint256(0)));
        if (nextNonce > 0) {
            vm.setNonce(deployer, nextNonce);
        }

        DODOPMMIntegration integration = DODOPMMIntegration(integrationAddr);
        vm.startBroadcast(pk);
        address pool = integration.createCUSDTCUSDCPool(
            LP_FEE_BPS,
            INITIAL_PRICE_1E18,
            K_50PCT,
            USE_TWAP
        );
        console.log("cUSDT/cUSDC pool created at:", pool);
        vm.stopBroadcast();
    }
}
