Skip to content

Commit

Permalink
chore: add docstrings to LiquidationEventData class and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykayudo committed Oct 25, 2024
1 parent d1aa5f6 commit 3a2827e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions data_handler/handler_tools/data_parser/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))

0 comments on commit 3a2827e

Please sign in to comment.