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

import {Script, console2} from "forge-std/Script.sol";
import {CWTokenMarketRegistry} from "../../contracts/mainnet-market/CWTokenMarketRegistry.sol";
import {CWTokenUsdFeed} from "../../contracts/mainnet-market/CWTokenUsdFeed.sol";

/// @notice Register remaining mainnet CompliantWrappedToken assets on deployed registry.
contract RegisterAdditionalCWMarketTokens is Script {
    struct Seed {
        address token;
        uint8 decimals;
        uint64 faceUsdE8;
        address uniV3Pool;
        bool cwIsToken0;
        string symbol;
    }

    function run() external {
        address registryAddr = vm.envAddress("CW_MARKET_REGISTRY_MAINNET");
        CWTokenMarketRegistry registry = CWTokenMarketRegistry(registryAddr);

        Seed[] memory seeds = _seeds();
        vm.startBroadcast();
        for (uint256 i = 0; i < seeds.length; i++) {
            Seed memory s = seeds[i];
            if (registry.tokenFeed(s.token) != address(0)) {
                console2.log("skip already registered", s.symbol, s.token);
                continue;
            }
            CWTokenUsdFeed feed = new CWTokenUsdFeed(
                registry, s.token, string.concat(s.symbol, " / USD (GRU market anchor)")
            );
            registry.registerToken(
                s.token, s.decimals, s.faceUsdE8, s.uniV3Pool, s.cwIsToken0, address(feed)
            );
            console2.log("Registered", s.symbol, s.token);
            console2.log("  feed", address(feed));
        }
        vm.stopBroadcast();
        console2.log("CWTokenMarketRegistry", registryAddr);
    }

    function _seeds() internal pure returns (Seed[] memory) {
        // face $1.00 e8 for ISO fiat stables; pool=0 when no live UniV3 peg pool (DODO/UniV2 only)
        Seed[] memory seeds = new Seed[](10);
        seeds[0] = Seed(0xD4aEAa8cD3fB41Dc8437FaC7639B6d91B60A5e8d, 6, 100_000_000, address(0), true, "cWEURC");
        seeds[1] = Seed(0x855d74FFB6CF75721a9bAbc8B2ed35c8119241dC, 6, 100_000_000, address(0), true, "cWEURT");
        seeds[2] = Seed(0xc074007dc0Bfb384B1cf6426a56287Ed23FE4D52, 6, 100_000_000, address(0), true, "cWGBPC");
        seeds[3] = Seed(0x1dDF9970F01c76A692Fdba2706203E6f16e0C46F, 6, 100_000_000, address(0), true, "cWGBPT");
        seeds[4] = Seed(0x5020Db641B3Fc0dAbBc0c688C845bc4E3699f35F, 6, 100_000_000, address(0), true, "cWAUDC");
        seeds[5] = Seed(0x07EEd0D7dD40984e47B9D3a3bdded1c536435582, 6, 100_000_000, address(0), true, "cWJPYC");
        seeds[6] = Seed(0x0F91C5E6Ddd46403746aAC970D05d70FFe404780, 6, 100_000_000, address(0), true, "cWCHFC");
        seeds[7] = Seed(0x209FE32fe7B541751D190ae4e50cd005DcF8EDb4, 6, 100_000_000, address(0), true, "cWCADC");
        seeds[8] = Seed(0x572Be0fa8CA0534d642A567CEDb398B771D8a715, 6, 3_300_000_000_00, address(0), true, "cWXAUC");
        seeds[9] = Seed(0xACE1DBF857549a11aF1322e1f91F2F64b029c906, 6, 3_300_000_000_00, address(0), true, "cWXAUT");
        // cWBTC: register separately with live BTC/USD face (volatile)
        return seeds;
    }
}
