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

import {Script, console} from "forge-std/Script.sol";
import {TreasuryVault} from "../../contracts/treasury/TreasuryVault.sol";
import {CcipBridgeAdapter138} from "../../contracts/treasury/CcipBridgeAdapter138.sol";
import {StrategyExecutor138} from "../../contracts/treasury/StrategyExecutor138.sol";

contract DeployTreasuryExecutor138 is Script {
    address constant WETH9_138 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    address constant WETH10_138 = 0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9F;
    address constant CUSDC_138 = 0xf22258f57794CC8E06237084b353Ab30fFfa640b;
    address constant CUSDT_138 = 0x93E66202A11B1772E55407B32B44e5Cd8eda7f22;
    address constant CCIPWETH9_BRIDGE_138 = 0x971cD9D156f193df8051E48043C476e53ECd4693;

    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address admin = vm.addr(pk);
        address receiverMainnet = vm.envAddress("RECEIVER_EXECUTOR_MAINNET");

        vm.startBroadcast(pk);

        TreasuryVault vault = new TreasuryVault(admin);

        CcipBridgeAdapter138 adapter = new CcipBridgeAdapter138(
            WETH9_138,
            CCIPWETH9_BRIDGE_138,
            receiverMainnet,
            admin
        );

        StrategyExecutor138 executor = new StrategyExecutor138(
            address(vault),
            address(adapter),
            admin
        );

        adapter.setStrategyExecutor(address(executor));

        vault.setModule(address(executor), true);
        vault.setModule(address(adapter), true);
        vault.setToken(WETH9_138, true);
        vault.setToken(WETH10_138, true);
        vault.setToken(CUSDC_138, true);
        vault.setToken(CUSDT_138, true);
        executor.setToken(WETH9_138, true);
        // Optional: admin may call executor.setExportPolicy(...) and executor.setCooldownBlocks(...) after deploy.
        // Optional: on ReceiverExecutorMainnet, admin may call setExpectedWeth9Source(bridge) for operator reference.

        vm.stopBroadcast();

        console.log("TREASURY_VAULT_138=", address(vault));
        console.log("CCIP_BRIDGE_ADAPTER_138=", address(adapter));
        console.log("STRATEGY_EXECUTOR_138=", address(executor));
    }
}
