diff --git a/data_handler/handler_tools/data_parser/serializers.py b/data_handler/handler_tools/data_parser/serializers.py index 41416021..e8fc085c 100644 --- a/data_handler/handler_tools/data_parser/serializers.py +++ b/data_handler/handler_tools/data_parser/serializers.py @@ -6,6 +6,19 @@ class LiquidationEventData(BaseModel): + """ + Class for converting liquadation event to an object model. + + Attributes: + liquidator: The address of the liquidator. + user: The address of the user. + debt_token: The address of the debt token. + debt_raw_amount: A numeric string of the debt_raw_amount converted to decimal. + debt_face_amount: A numeric string of the debt_face_amount converted to decimal. + collateral_token: The address of collateral token. + collateral_amount: A numeric string of the collateral_amount converted to decimal. + """ + liquidator: str user: str debt_token: str @@ -16,12 +29,30 @@ class LiquidationEventData(BaseModel): @field_validator("liquidator", "user", "debt_token", "collateral_token") def validate_valid_addresses(cls, value: str, info: ValidationInfo): + """ + Check if the value is an address and format it to having leading zeros. + + Raises: + ValueError + + Returns: + str + """ if not value.startswith("0x"): raise ValueError("Invalid address provided for %s" % info.field_name) return add_leading_zeros(value) @field_validator("debt_raw_amount", "debt_face_amount", "collateral_amount") def validate_valid_numbers(cls, value: str, info: ValidationInfo): + """ + Check if the value is a digit and convert it to a decimal from base 16 int conversion. + + Raises: + ValueError + + Returns: + Decimal + """ if not value.isdigit(): raise ValueError("%s field is not numeric" % info.field_name) return Decimal(str(int(value, base=16)))