Skip to content

Global Types

prediction_market_agent_tooling.gtypes

PrivateKey module-attribute

PrivateKey = NewType('PrivateKey', SecretStr)

ABI module-attribute

ABI = NewType('ABI', str)

OutcomeStr module-attribute

OutcomeStr = NewType('OutcomeStr', str)

Probability module-attribute

Probability = NewType('Probability', float)

ChainID module-attribute

ChainID = NewType('ChainID', int)

IPFSCIDVersion0 module-attribute

IPFSCIDVersion0 = NewType('IPFSCIDVersion0', str)

_GenericValue

_GenericValue(value: InputValueType)

Bases: Generic[InputValueType, InternalValueType], dict[Literal['value'] | Literal['type'], InternalValueType | str]

A helper class intended for inheritance. Do not instantiate this class directly.

Example:

a = _GenericValue(10)
b = Token(100) # Token is a subclass of _GenericValue
c = xDai(100) # xDai is a subclass of _GenericValue
d = Mana(100) # Mana is a subclass of _GenericValue
e = xDai(50)

# Mypy will complain if we try to work with different currencies (types)
b - c # mypy will report incompatible types
c - d # mypy will report incompatible types
c - e # mypy will be ok
a - b # mypy won't report issues, as others are subclasses of _GenericValue, and that's a problem, so don't use _GenericValue directly

# Resulting types after arithmetic operations are as expected, so we don't need to wrap them as before (e.g. xdai_type(c + c))
x = c - e # x is of type xDai
x = c * e # x if of type xDai
x = c / e # x is of type float (pure value after division with same types)
x = c / 2 # x is of type xDai
x = c // 2 # x is of type xDai
x * x * 2 # x is of type xDai

TODO: There are some type ignores which isn't cool, but it works and type-wise values are also correct. Idk how to explain it to mypy though.

Source code in prediction_market_agent_tooling/tools/_generic_value.py
62
63
64
def __init__(self, value: InputValueType) -> None:
    self.value: InternalValueType = self.parser(value)
    super().__init__({"value": self.value, "type": self.__class__.__name__})

GenericValueType class-attribute instance-attribute

GenericValueType = TypeVar(
    "GenericValueType",
    bound="_GenericValue[InputValueType, InternalValueType]",
)

parser instance-attribute

parser: Callable[[InputValueType], InternalValueType]

value instance-attribute

value: InternalValueType = parser(value)

symbol property

symbol: str

with_fraction

with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248
249
250
251
def with_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 + fraction))  # type: ignore[arg-type]

without_fraction

without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253
254
255
256
def without_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 - fraction))  # type: ignore[arg-type]

zero classmethod

zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258
259
260
@classmethod
def zero(cls: type[GenericValueType]) -> GenericValueType:
    return cls(0)  # type: ignore[arg-type]

DatetimeUTC

Bases: datetime

As a subclass of datetime instead of NewType because otherwise it doesn't work with issubclass command which is required for SQLModel/Pydantic.

from_datetime staticmethod

from_datetime(dt: datetime) -> DatetimeUTC

Converts a datetime object to DatetimeUTC, ensuring it is timezone-aware in UTC.

Source code in prediction_market_agent_tooling/tools/datetime_utc.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@staticmethod
def from_datetime(dt: datetime) -> "DatetimeUTC":
    """
    Converts a datetime object to DatetimeUTC, ensuring it is timezone-aware in UTC.
    """
    if dt.tzinfo is None:
        logger.warning(
            f"tzinfo not provided, assuming the timezone of {dt=} is UTC."
        )
        dt = dt.replace(tzinfo=pytz.UTC)
    else:
        dt = dt.astimezone(pytz.UTC)
    return DatetimeUTC(
        dt.year,
        dt.month,
        dt.day,
        dt.hour,
        dt.minute,
        dt.second,
        dt.microsecond,
        tzinfo=pytz.UTC,
    )

to_datetime_utc staticmethod

to_datetime_utc(value: datetime | int | str) -> DatetimeUTC
Source code in prediction_market_agent_tooling/tools/datetime_utc.py
63
64
65
66
67
68
69
70
71
72
73
74
@staticmethod
def to_datetime_utc(value: datetime | int | str) -> "DatetimeUTC":
    if isinstance(value, int):
        # Divide by 1000 if the timestamp is assumed to be in milliseconds (if not, 1e11 would be year 5138).
        value = int(value / 1000) if value > 1e11 else value
        # In the past, we had bugged data where timestamp was huge and Python errored out.
        max_timestamp = int((datetime.max - timedelta(days=1)).timestamp())
        value = min(value, max_timestamp)
        value = datetime.fromtimestamp(value, tz=pytz.UTC)
    elif isinstance(value, str):
        value = parser.parse(value)
    return DatetimeUTC.from_datetime(value)

HexBytes

Bases: HexBytes, BaseHex

Use when receiving hexbytes.HexBytes values. Includes a pydantic validator and serializer.

schema_pattern class-attribute

schema_pattern: str = '^0x([0-9a-f][0-9a-f])*$'

schema_examples class-attribute

schema_examples: tuple[str, ...] = (
    "0x",
    "0xd4",
    "0xd4e5",
    "0xd4e56740",
    "0xd4e56740f876aef8",
    "0xd4e56740f876aef8c010b86a40d5f567",
    "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
)

fromhex classmethod

fromhex(hex_str: str) -> HexBytes
Source code in prediction_market_agent_tooling/tools/hexbytes_custom.py
58
59
60
61
@classmethod
def fromhex(cls, hex_str: str) -> "HexBytes":
    value = hex_str[2:] if hex_str.startswith("0x") else hex_str
    return super().fromhex(value)

as_int

as_int() -> int
Source code in prediction_market_agent_tooling/tools/hexbytes_custom.py
69
70
def as_int(self) -> int:
    return int(self.hex(), 16)

CollateralToken

CollateralToken(value: InputValueType)

Bases: _GenericValue[int | float | str | Decimal, float]

Represents any token in its decimal form, it could be 1.1 GNO, WXDAI, XDAI, Mana, whatever. We don't know the currency, just that it's in the decimal form.

Source code in prediction_market_agent_tooling/tools/_generic_value.py
62
63
64
def __init__(self, value: InputValueType) -> None:
    self.value: InternalValueType = self.parser(value)
    super().__init__({"value": self.value, "type": self.__class__.__name__})

as_wei property

as_wei: Wei

GenericValueType class-attribute instance-attribute

GenericValueType = TypeVar(
    "GenericValueType",
    bound="_GenericValue[InputValueType, InternalValueType]",
)

parser instance-attribute

parser: Callable[[InputValueType], InternalValueType]

value instance-attribute

value: InternalValueType = parser(value)

symbol property

symbol: str

with_fraction

with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248
249
250
251
def with_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 + fraction))  # type: ignore[arg-type]

without_fraction

without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253
254
255
256
def without_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 - fraction))  # type: ignore[arg-type]

zero classmethod

zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258
259
260
@classmethod
def zero(cls: type[GenericValueType]) -> GenericValueType:
    return cls(0)  # type: ignore[arg-type]

OutcomeToken

OutcomeToken(value: InputValueType)

Bases: _GenericValue[int | float | str | Decimal, float]

Represents outcome tokens in market in decimal form. After you redeem the outcome tokens, 1 OutcomeToken equals to 1 Token, but before, it's important to distinguish between them. For example, it's a big difference if you are going to sell 1 OutcomeToken, or 1 (collateral) Token. But still, Token and OutcomeToken needs to be handled together in many cases, use available properties to convert between them explicitly.

Source code in prediction_market_agent_tooling/tools/_generic_value.py
62
63
64
def __init__(self, value: InputValueType) -> None:
    self.value: InternalValueType = self.parser(value)
    super().__init__({"value": self.value, "type": self.__class__.__name__})

as_outcome_wei property

as_outcome_wei: OutcomeWei

as_token property

as_token: CollateralToken

OutcomeToken is essentialy Token as well, when you know you really need to convert it, you can convert it explicitly using this.

GenericValueType class-attribute instance-attribute

GenericValueType = TypeVar(
    "GenericValueType",
    bound="_GenericValue[InputValueType, InternalValueType]",
)

parser instance-attribute

parser: Callable[[InputValueType], InternalValueType]

value instance-attribute

value: InternalValueType = parser(value)

symbol property

symbol: str

from_token staticmethod

from_token(token: CollateralToken) -> OutcomeToken
Source code in prediction_market_agent_tooling/gtypes.py
48
49
50
@staticmethod
def from_token(token: CollateralToken) -> "OutcomeToken":
    return OutcomeToken(token.value)

with_fraction

with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248
249
250
251
def with_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 + fraction))  # type: ignore[arg-type]

without_fraction

without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253
254
255
256
def without_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 - fraction))  # type: ignore[arg-type]

zero classmethod

zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258
259
260
@classmethod
def zero(cls: type[GenericValueType]) -> GenericValueType:
    return cls(0)  # type: ignore[arg-type]

USD

USD(value: InputValueType)

Bases: _GenericValue[int | float | str | Decimal, float]

Represents values in USD.

Source code in prediction_market_agent_tooling/tools/_generic_value.py
62
63
64
def __init__(self, value: InputValueType) -> None:
    self.value: InternalValueType = self.parser(value)
    super().__init__({"value": self.value, "type": self.__class__.__name__})

GenericValueType class-attribute instance-attribute

GenericValueType = TypeVar(
    "GenericValueType",
    bound="_GenericValue[InputValueType, InternalValueType]",
)

parser instance-attribute

parser: Callable[[InputValueType], InternalValueType]

value instance-attribute

value: InternalValueType = parser(value)

symbol property

symbol: str

with_fraction

with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248
249
250
251
def with_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 + fraction))  # type: ignore[arg-type]

without_fraction

without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253
254
255
256
def without_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 - fraction))  # type: ignore[arg-type]

zero classmethod

zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258
259
260
@classmethod
def zero(cls: type[GenericValueType]) -> GenericValueType:
    return cls(0)  # type: ignore[arg-type]

xDai

xDai(value: InputValueType)

Bases: _GenericValue[int | float | str | Decimal, float]

Represents values in xDai.

Source code in prediction_market_agent_tooling/tools/_generic_value.py
62
63
64
def __init__(self, value: InputValueType) -> None:
    self.value: InternalValueType = self.parser(value)
    super().__init__({"value": self.value, "type": self.__class__.__name__})

as_token property

as_token: CollateralToken

xDai is essentialy Token as well, when you know you need to pass it, you can convert it using this.

as_xdai_wei property

as_xdai_wei: xDaiWei

GenericValueType class-attribute instance-attribute

GenericValueType = TypeVar(
    "GenericValueType",
    bound="_GenericValue[InputValueType, InternalValueType]",
)

parser instance-attribute

parser: Callable[[InputValueType], InternalValueType]

value instance-attribute

value: InternalValueType = parser(value)

symbol property

symbol: str

with_fraction

with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248
249
250
251
def with_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 + fraction))  # type: ignore[arg-type]

without_fraction

without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253
254
255
256
def without_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 - fraction))  # type: ignore[arg-type]

zero classmethod

zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258
259
260
@classmethod
def zero(cls: type[GenericValueType]) -> GenericValueType:
    return cls(0)  # type: ignore[arg-type]

Mana

Mana(value: InputValueType)

Bases: _GenericValue[int | float | str | Decimal, float]

Represents values in Manifold's Mana.

Source code in prediction_market_agent_tooling/tools/_generic_value.py
62
63
64
def __init__(self, value: InputValueType) -> None:
    self.value: InternalValueType = self.parser(value)
    super().__init__({"value": self.value, "type": self.__class__.__name__})

GenericValueType class-attribute instance-attribute

GenericValueType = TypeVar(
    "GenericValueType",
    bound="_GenericValue[InputValueType, InternalValueType]",
)

parser instance-attribute

parser: Callable[[InputValueType], InternalValueType]

value instance-attribute

value: InternalValueType = parser(value)

symbol property

symbol: str

with_fraction

with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248
249
250
251
def with_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 + fraction))  # type: ignore[arg-type]

without_fraction

without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253
254
255
256
def without_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 - fraction))  # type: ignore[arg-type]

zero classmethod

zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258
259
260
@classmethod
def zero(cls: type[GenericValueType]) -> GenericValueType:
    return cls(0)  # type: ignore[arg-type]

USDC

USDC(value: InputValueType)

Bases: _GenericValue[int | float | str | Decimal, float]

Represents values in USDC.

Source code in prediction_market_agent_tooling/tools/_generic_value.py
62
63
64
def __init__(self, value: InputValueType) -> None:
    self.value: InternalValueType = self.parser(value)
    super().__init__({"value": self.value, "type": self.__class__.__name__})

GenericValueType class-attribute instance-attribute

GenericValueType = TypeVar(
    "GenericValueType",
    bound="_GenericValue[InputValueType, InternalValueType]",
)

parser instance-attribute

parser: Callable[[InputValueType], InternalValueType]

value instance-attribute

value: InternalValueType = parser(value)

symbol property

symbol: str

with_fraction

with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248
249
250
251
def with_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 + fraction))  # type: ignore[arg-type]

without_fraction

without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253
254
255
256
def without_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 - fraction))  # type: ignore[arg-type]

zero classmethod

zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258
259
260
@classmethod
def zero(cls: type[GenericValueType]) -> GenericValueType:
    return cls(0)  # type: ignore[arg-type]

Wei

Wei(value: InputValueType)

Bases: _GenericValue[Wei | int | str, Wei]

Represents values in Wei. We don't know what currency, but in its integer form called Wei.

Source code in prediction_market_agent_tooling/tools/_generic_value.py
62
63
64
def __init__(self, value: InputValueType) -> None:
    self.value: InternalValueType = self.parser(value)
    super().__init__({"value": self.value, "type": self.__class__.__name__})

as_token property

as_token: CollateralToken

GenericValueType class-attribute instance-attribute

GenericValueType = TypeVar(
    "GenericValueType",
    bound="_GenericValue[InputValueType, InternalValueType]",
)

parser instance-attribute

parser: Callable[[InputValueType], InternalValueType]

value instance-attribute

value: InternalValueType = parser(value)

symbol property

symbol: str

with_fraction

with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248
249
250
251
def with_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 + fraction))  # type: ignore[arg-type]

without_fraction

without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253
254
255
256
def without_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 - fraction))  # type: ignore[arg-type]

zero classmethod

zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258
259
260
@classmethod
def zero(cls: type[GenericValueType]) -> GenericValueType:
    return cls(0)  # type: ignore[arg-type]

OutcomeWei

OutcomeWei(value: InputValueType)

Bases: _GenericValue[Wei | int | str, Wei]

Similar to OutcomeToken, but in Wei units.

Source code in prediction_market_agent_tooling/tools/_generic_value.py
62
63
64
def __init__(self, value: InputValueType) -> None:
    self.value: InternalValueType = self.parser(value)
    super().__init__({"value": self.value, "type": self.__class__.__name__})

as_outcome_token property

as_outcome_token: OutcomeToken

as_wei property

as_wei: Wei

OutcomeWei is essentialy Wei as well, when you know you need to pass it, you can convert it using this.

GenericValueType class-attribute instance-attribute

GenericValueType = TypeVar(
    "GenericValueType",
    bound="_GenericValue[InputValueType, InternalValueType]",
)

parser instance-attribute

parser: Callable[[InputValueType], InternalValueType]

value instance-attribute

value: InternalValueType = parser(value)

symbol property

symbol: str

from_wei staticmethod

from_wei(wei: Wei) -> OutcomeWei
Source code in prediction_market_agent_tooling/gtypes.py
104
105
106
@staticmethod
def from_wei(wei: Wei) -> "OutcomeWei":
    return OutcomeWei(wei.value)

with_fraction

with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248
249
250
251
def with_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 + fraction))  # type: ignore[arg-type]

without_fraction

without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253
254
255
256
def without_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 - fraction))  # type: ignore[arg-type]

zero classmethod

zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258
259
260
@classmethod
def zero(cls: type[GenericValueType]) -> GenericValueType:
    return cls(0)  # type: ignore[arg-type]

xDaiWei

xDaiWei(value: InputValueType)

Bases: _GenericValue[Wei | int | str, Wei]

Represents xDai in Wei, like 1.9 xDai is 1.9 * 10**18 Wei. In contrast to just Wei, we don't know what unit Wei is (Wei of GNO, sDai, or whatever), but xDaiWei is xDai converted to Wei.

Source code in prediction_market_agent_tooling/tools/_generic_value.py
62
63
64
def __init__(self, value: InputValueType) -> None:
    self.value: InternalValueType = self.parser(value)
    super().__init__({"value": self.value, "type": self.__class__.__name__})

as_xdai property

as_xdai: xDai

as_wei property

as_wei: Wei

xDaiWei is essentialy Wei as well, when you know you need to pass it, you can convert it using this.

GenericValueType class-attribute instance-attribute

GenericValueType = TypeVar(
    "GenericValueType",
    bound="_GenericValue[InputValueType, InternalValueType]",
)

parser instance-attribute

parser: Callable[[InputValueType], InternalValueType]

value instance-attribute

value: InternalValueType = parser(value)

symbol property

symbol: str

with_fraction

with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248
249
250
251
def with_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 + fraction))  # type: ignore[arg-type]

without_fraction

without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253
254
255
256
def without_fraction(self: GenericValueType, fraction: float) -> GenericValueType:
    if not 0 <= fraction <= 1:
        raise ValueError(f"Given fraction {fraction} is not in the range [0,1].")
    return self.__class__(self.value * (1 - fraction))  # type: ignore[arg-type]

zero classmethod

zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258
259
260
@classmethod
def zero(cls: type[GenericValueType]) -> GenericValueType:
    return cls(0)  # type: ignore[arg-type]

private_key_type

private_key_type(k: str) -> PrivateKey
Source code in prediction_market_agent_tooling/gtypes.py
143
144
def private_key_type(k: str) -> PrivateKey:
    return PrivateKey(SecretStr(k))

secretstr_to_v1_secretstr

secretstr_to_v1_secretstr(s: SecretStr) -> SecretStrV1
secretstr_to_v1_secretstr(s: None) -> None
secretstr_to_v1_secretstr(
    s: SecretStr | None,
) -> SecretStrV1 | None
Source code in prediction_market_agent_tooling/gtypes.py
157
158
159
def secretstr_to_v1_secretstr(s: SecretStr | None) -> SecretStrV1 | None:
    # Another library can be typed with v1, and then we need this ugly conversion.
    return SecretStrV1(s.get_secret_value()) if s is not None else None

int_to_hexbytes

int_to_hexbytes(v: int) -> HexBytes
Source code in prediction_market_agent_tooling/gtypes.py
162
163
164
def int_to_hexbytes(v: int) -> HexBytes:
    # Example: 1 -> HexBytes("0x0000000000000000000000000000000000000000000000000000000000000001"). # web3-private-key-ok
    return HexBytes.fromhex(format(v, "064x"))

to_wei_inc_negative

to_wei_inc_negative(
    value: int | float | str | Decimal,
) -> Web3Wei

Handles conversion of a value to Wei, taking into account negative values.

Source code in prediction_market_agent_tooling/gtypes.py
167
168
169
170
171
172
173
def to_wei_inc_negative(value: int | float | str | Decimal) -> Web3Wei:
    """
    Handles conversion of a value to Wei, taking into account negative values.
    """
    return Web3Wei(
        Web3.to_wei(abs(Decimal(value)), "ether") * (-1 if Decimal(value) < 0 else 1)
    )

from_wei_inc_negative

from_wei_inc_negative(value: int) -> int | Decimal

Handles conversion from Wei to a float value, taking into account negative values.

Source code in prediction_market_agent_tooling/gtypes.py
176
177
178
179
180
def from_wei_inc_negative(value: int) -> int | Decimal:
    """
    Handles conversion from Wei to a float value, taking into account negative values.
    """
    return Web3.from_wei(abs(value), "ether") * (-1 if value < 0 else 1)