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

import {Script, console2} from "forge-std/Script.sol";
import {VaultFactory} from "../../../contracts/vault/VaultFactory.sol";
import {GRUVaultIndex} from "../../../contracts/vault/GRUVaultIndex.sol";

/// @notice Wire an existing VaultFactory to an existing GRUVaultIndex (post-deploy on any chain).
contract WireGRUVaultFactoryToIndex is Script {
    function run() external {
        address factoryAddr = vm.envAddress("VAULT_FACTORY_ADDRESS");
        address indexAddr = vm.envAddress("GRU_VAULT_INDEX");

        vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
        VaultFactory(factoryAddr).setGruVaultIndex(indexAddr);
        GRUVaultIndex(indexAddr).grantFactoryRole(factoryAddr);
        vm.stopBroadcast();

        console2.log("Wired VaultFactory", factoryAddr);
        console2.log("GRUVaultIndex", indexAddr);
    }
}
