// 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";

contract DeployCWTokenMarketRegistry is Script {
    struct TokenSeed {
        address token;
        uint8 decimals;
        uint64 faceUsdE8;
        address uniV3Pool;
        bool cwIsToken0;
        string feedDescription;
    }

    function run() external {
        vm.startBroadcast();
        address admin = msg.sender;

        CWTokenMarketRegistry registry = new CWTokenMarketRegistry(admin);

        TokenSeed[] memory seeds = _seeds();
        for (uint256 i = 0; i < seeds.length; i++) {
            TokenSeed memory s = seeds[i];
            CWTokenUsdFeed feed = new CWTokenUsdFeed(registry, s.token, s.feedDescription);
            registry.registerToken(
                s.token, s.decimals, s.faceUsdE8, s.uniV3Pool, s.cwIsToken0, address(feed)
            );
            console2.log("Registered", s.token);
            console2.log("  feed", address(feed));
        }

        vm.stopBroadcast();
        console2.log("CWTokenMarketRegistry", address(registry));
    }

    function _seeds() internal pure returns (TokenSeed[] memory) {
        TokenSeed[] memory seeds = new TokenSeed[](2);
        seeds[0] = TokenSeed({
            token: 0x2de5F116bFcE3d0f922d9C8351e0c5Fc24b9284a,
            decimals: 6,
            faceUsdE8: 100_000_000,
            uniV3Pool: 0x1Cf2e685682C7F7beF508F0Af15Dfb5CDda01ee3,
            cwIsToken0: true,
            feedDescription: "cWUSDC / USD (GRU market anchor)"
        });
        seeds[1] = TokenSeed({
            token: 0xaF5017d0163ecb99D9B5D94e3b4D7b09Af44D8AE,
            decimals: 6,
            faceUsdE8: 100_000_000,
            uniV3Pool: 0x6eF5A392BcbE42F3D0a855595bEa60CFf9451784,
            cwIsToken0: true,
            feedDescription: "cWUSDT / USD (GRU market anchor)"
        });
        return seeds;
    }
}
