def to_wei(number: int, unit: str) -> int:
if unit.lower() not in units:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>".format("<STR_LIT:/>".join(units.keys()))<EOL>)<EOL><DEDENT>if is_integer(number) or is_string(number):<EOL><INDENT>d_number = decimal.Decimal(value=number)<EOL><DEDENT>elif isinstance(number, float):<EOL><INDENT>d_number = decimal.Decimal(value=str(number))<EOL><DEDENT>elif isinstance(number, decimal.Decimal):<EOL><INDENT>d_number = number<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>s_number = str(number)<EOL>unit_value = units[unit.lower()]<EOL>if d_number == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if d_number < <NUM_LIT:1> and "<STR_LIT:.>" in s_number:<EOL><INDENT>with localcontext() as ctx:<EOL><INDENT>multiplier = len(s_number) - s_number.index("<STR_LIT:.>") - <NUM_LIT:1><EOL>ctx.prec = multiplier<EOL>d_number = decimal.Decimal(value=number, context=ctx) * <NUM_LIT:10> ** multiplier<EOL><DEDENT>unit_value /= <NUM_LIT:10> ** multiplier<EOL><DEDENT>with localcontext() as ctx:<EOL><INDENT>ctx.prec = <NUM_LIT><EOL>result_value = decimal.Decimal(value=d_number, context=ctx) * unit_value<EOL><DEDENT>if result_value < MIN_WEI or result_value > MAX_WEI:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return int(result_value)<EOL>
Takes a number of a unit and converts it to wei.