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

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

/// @notice Register M1 c* tokens as ledger assets with default GRU vault risk parameters.
contract RegisterGruVaultLedgerAssets is Script {
    uint256 constant DEFAULT_DEBT_CEILING = 1_000_000e18;
    uint256 constant DEFAULT_LIQUIDATION_RATIO = 10_000;
    uint256 constant DEFAULT_CREDIT_MULTIPLIER = 50_000;

    function run() external {
        address ledgerAddr = vm.envAddress("LEDGER_ADDRESS");
        Ledger ledger = Ledger(ledgerAddr);

        vm.startBroadcast(vm.envUint("PRIVATE_KEY"));

        _registerIfSet(ledger, vm.envOr("CUSDC_ADDRESS_138", vm.envOr("COMPLIANT_USDC_ADDRESS", address(0))));
        _registerIfSet(ledger, vm.envOr("CUSDT_ADDRESS_138", vm.envOr("COMPLIANT_USDT_ADDRESS", address(0))));
        _registerIfSet(ledger, vm.envOr("cEURC_ADDRESS_138", address(0)));
        _registerIfSet(ledger, vm.envOr("cEURT_ADDRESS_138", address(0)));
        _registerIfSet(ledger, vm.envOr("cGBPC_ADDRESS_138", address(0)));
        _registerIfSet(ledger, vm.envOr("cGBPT_ADDRESS_138", address(0)));
        _registerIfSet(ledger, vm.envOr("cAUDC_ADDRESS_138", address(0)));
        _registerIfSet(ledger, vm.envOr("cJPYC_ADDRESS_138", address(0)));
        _registerIfSet(ledger, vm.envOr("cCHFC_ADDRESS_138", address(0)));
        _registerIfSet(ledger, vm.envOr("cCADC_ADDRESS_138", address(0)));
        _registerIfSet(ledger, vm.envOr("cXAUC_ADDRESS_138", address(0)));
        _registerIfSet(ledger, vm.envOr("cXAUT_ADDRESS_138", address(0)));

        _registerIfSet(ledger, vm.envOr("CUSDC_ADDRESS_651940", vm.envOr("AUSDC_ADDRESS_651940", address(0))));
        _registerIfSet(ledger, vm.envOr("AUSDT_ADDRESS_651940", vm.envOr("CUSDT_ADDRESS_651940", address(0))));
        _registerIfSet(ledger, vm.envOr("WALL_ADDRESS_651940", address(0)));

        vm.stopBroadcast();
    }

    function _registerIfSet(Ledger ledger, address asset) internal {
        if (asset == address(0)) return;
        ledger.setRiskParameters(asset, DEFAULT_DEBT_CEILING, DEFAULT_LIQUIDATION_RATIO, DEFAULT_CREDIT_MULTIPLIER);
        console2.log("Registered ledger asset", asset);
    }
}
