<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def genesis(chain_class: BaseChain, db: BaseAtomicDB=None, params: Dict[str, HeaderParams]=None, state: GeneralState=None) -> BaseChain: """ Initialize the given chain class with the given genesis header parameters and chain state. """

    if state is None:
        genesis_state = {}  # type: AccountState
    else:
        genesis_state = _fill_and_normalize_state(state)

    genesis_params_defaults = _get_default_genesis_params(genesis_state)

    if params is None:
        genesis_params = genesis_params_defaults
    else:
        genesis_params = merge(genesis_params_defaults, params)

    if db is None:
        base_db = AtomicDB()  # type: BaseAtomicDB
    else:
        base_db = db

    return chain_class.from_genesis(base_db, genesis_params, genesis_state)