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

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

/**
 * @title DeployStablecoinReserveVault
 * @notice Deploy StablecoinReserveVault contract for 1:1 backing mechanism
 * @dev This contract should be deployed on Ethereum Mainnet where official USDT/USDC exist
 *      For Chain 138 deployment, connect via cross-chain bridge
 */
contract DeployStablecoinReserveVault is Script {
    // Official token addresses on Ethereum Mainnet
    address constant MAINNET_USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
    address constant MAINNET_USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;

    function run() external {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        address deployer = vm.addr(deployerPrivateKey);
        
        // Load environment variables
        address admin = vm.envOr("RESERVE_VAULT_ADMIN", deployer);
        
        // Official token addresses (default to Mainnet, can be overridden)
        address officialUsdt = vm.envOr("OFFICIAL_USDT_ADDRESS", MAINNET_USDT);
        address officialUsdc = vm.envOr("OFFICIAL_USDC_ADDRESS", MAINNET_USDC);
        
        // Compliant token addresses (on Chain 138 or same network)
        address compliantUsdt = vm.envAddress("COMPLIANT_USDT_ADDRESS");
        address compliantUsdc = vm.envAddress("COMPLIANT_USDC_ADDRESS");
        
        console.log("Deploying StablecoinReserveVault with deployer:", vm.toString(deployer));
        console.log("Admin:", vm.toString(admin));
        console.log("Official USDT:", vm.toString(officialUsdt));
        console.log("Official USDC:", vm.toString(officialUsdc));
        console.log("Compliant USDT:", vm.toString(compliantUsdt));
        console.log("Compliant USDC:", vm.toString(compliantUsdc));
        
        vm.startBroadcast(deployerPrivateKey);
        
        StablecoinReserveVault vault = new StablecoinReserveVault(
            admin,
            officialUsdt,
            officialUsdc,
            compliantUsdt,
            compliantUsdc
        );
        
        console.log("StablecoinReserveVault deployed at:", vm.toString(address(vault)));
        
        vm.stopBroadcast();
        
        console.log("\n=== Deployment Summary ===");
        console.log("StablecoinReserveVault:", vm.toString(address(vault)));
        console.log("Admin:", vm.toString(admin));
        console.log("Official USDT:", vm.toString(officialUsdt));
        console.log("Official USDC:", vm.toString(officialUsdc));
        console.log("Compliant USDT:", vm.toString(compliantUsdt));
        console.log("Compliant USDC:", vm.toString(compliantUsdc));
        console.log("\nNext Steps:");
        console.log("1. Transfer ownership of CompliantUSDT/CompliantUSDC to vault (if needed)");
        console.log("2. Fund vault with official USDT/USDC tokens");
        console.log("3. Enable deposit functions by ensuring tokens are approved");
    }
}

