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 | |
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 | |
without_fraction
without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253 254 255 256 | |
zero
classmethod
zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258 259 260 | |
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 | |
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 | |
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 | |
as_int
as_int() -> int
Source code in prediction_market_agent_tooling/tools/hexbytes_custom.py
69 70 | |
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 | |
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 | |
without_fraction
without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253 254 255 256 | |
zero
classmethod
zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258 259 260 | |
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 | |
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 | |
with_fraction
with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248 249 250 251 | |
without_fraction
without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253 254 255 256 | |
zero
classmethod
zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258 259 260 | |
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 | |
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 | |
without_fraction
without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253 254 255 256 | |
zero
classmethod
zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258 259 260 | |
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 | |
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 | |
without_fraction
without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253 254 255 256 | |
zero
classmethod
zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258 259 260 | |
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 | |
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 | |
without_fraction
without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253 254 255 256 | |
zero
classmethod
zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258 259 260 | |
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 | |
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 | |
without_fraction
without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253 254 255 256 | |
zero
classmethod
zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258 259 260 | |
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 | |
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 | |
without_fraction
without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253 254 255 256 | |
zero
classmethod
zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258 259 260 | |
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 | |
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 | |
with_fraction
with_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
248 249 250 251 | |
without_fraction
without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253 254 255 256 | |
zero
classmethod
zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258 259 260 | |
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 | |
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 | |
without_fraction
without_fraction(fraction: float) -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
253 254 255 256 | |
zero
classmethod
zero() -> GenericValueType
Source code in prediction_market_agent_tooling/tools/_generic_value.py
258 259 260 | |
private_key_type
private_key_type(k: str) -> PrivateKey
Source code in prediction_market_agent_tooling/gtypes.py
143 144 | |
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 | |
int_to_hexbytes
int_to_hexbytes(v: int) -> HexBytes
Source code in prediction_market_agent_tooling/gtypes.py
162 163 164 | |
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 | |
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 | |