# AUTOGENERATED! DO NOT EDIT! File to edit: ../src/token.ipynb.

# %% auto 0
__all__ = ['Token']

# %% ../src/token.ipynb 2
from typing import Tuple
from dataclasses import dataclass
from .helpers import normalize_address

# %% ../src/token.ipynb 4
@dataclass(frozen=True)
class Token:
    """Data class for Token
    based on: https://github.com/velodrome-finance/sugar/blob/v2/contracts/LpSugar.vy#L17
    """

    token_address: str
    symbol: str
    decimals: int
    listed: bool
    wrapped_token_address: str = None

    @property
    def is_native(self) -> bool: return self.wrapped_token_address is not None

    def value_from_bigint(self, value: float) -> float: return value / 10**self.decimals

    @classmethod
    def make_native_token(cls, symbol: str, wrapped_address: str, decimals: int) -> "Token":
        return Token(token_address=symbol, symbol=symbol, decimals=decimals, listed=True, wrapped_token_address=wrapped_address)

    @classmethod
    def from_tuple(cls, t: Tuple) -> "Token":
        (token_address, symbol, decimals, _, listed) = t
        return Token(
            token_address=normalize_address(token_address),
            symbol=symbol,
            decimals=decimals,
            listed=listed,
        )
