Edit on GitHub

communex.types

Common types for the communex module.

  1"""
  2Common types for the communex module.
  3"""
  4
  5from typing import NewType, TypedDict
  6
  7Ss58Address = NewType("Ss58Address", str)
  8"""Substrate SS58 address.
  9
 10The `SS58 encoded address format`_ is based on the Bitcoin Base58Check format,
 11but with a few modification specifically designed to suite Substrate-based
 12chains.
 13
 14.. _SS58 encoded address format:
 15    https://docs.substrate.io/reference/address-formats/
 16"""
 17
 18
 19# TODO: replace with dataclasses
 20
 21# == Burn related
 22MinBurn = NewType("MinBurn", int)
 23MaxBurn = NewType("MaxBurn", int)
 24BurnConfig = NewType("BurnConfig", dict[MinBurn, MaxBurn])
 25
 26
 27class NetworkParams(TypedDict):
 28    max_allowed_modules: int
 29    max_registrations_per_block: int
 30    max_name_length: int
 31    min_name_length: int
 32    min_burn: int
 33    max_burn: int
 34    min_weight_stake: int
 35    max_allowed_subnets: int
 36    curator: Ss58Address
 37    proposal_cost: int
 38    proposal_expiration: int
 39    subnet_stake_threshold: int
 40    general_subnet_application_cost: int
 41    floor_founder_share: int
 42    floor_delegation_fee: int
 43    max_allowed_weights: int
 44
 45
 46class SubnetParamsMaps(TypedDict):
 47    netuid_to_founder: dict[int, Ss58Address]
 48    netuid_to_founder_share: dict[int, int]
 49    netuid_to_immunity_period: dict[int, int]
 50    netuid_to_incentive_ratio: dict[int, int]
 51    netuid_to_max_allowed_uids: dict[int, int]
 52    netuid_to_max_allowed_weights: dict[int, int]
 53    netuid_to_min_allowed_weights: dict[int, int]
 54    netuid_to_max_weight_age: dict[int, int]
 55    netuid_to_min_stake: dict[int, int]
 56    netuid_to_name: dict[int, str]
 57    netuid_to_tempo: dict[int, int]
 58    netuid_to_trust_ratio: dict[int, int]
 59    netuid_to_bonds_ma: dict[int, int]
 60    netuid_to_maximum_set_weight_calls_per_epoch: dict[int, int]
 61    netuid_to_target_registrations_per_interval: dict[int, int]
 62    netuid_to_target_registrations_interval: dict[int, int]
 63    netuid_to_emission: dict[int, int]
 64    netuid_to_max_registrations_per_interval: dict[int, int]
 65    netuid_to_vote_mode: dict[int, dict[str, str]]
 66    netuid_to_adjustment_alpha: dict[int, int]
 67
 68
 69class SubnetParams(TypedDict):
 70    founder: Ss58Address
 71    founder_share: int
 72    immunity_period: int
 73    incentive_ratio: int
 74    max_allowed_uids: int
 75    max_allowed_weights: int
 76    min_allowed_weights: int
 77    max_weight_age: int
 78    min_stake: int
 79    name: str
 80    tempo: int
 81    trust_ratio: int
 82    bonds_ma: int | None
 83    maximum_set_weight_calls_per_epoch: int | None
 84    target_registrations_per_interval: int
 85    target_registrations_interval: int
 86    max_registrations_per_interval: int
 87    vote_mode: str
 88    adjustment_alpha: int
 89
 90
 91# redundant "TypedDict" inheritance because of pdoc warns.
 92# see https://github.com/mitmproxy/pdoc/blob/26d40827ddbe1658e8ac46cd092f17a44cf0287b/pdoc/doc.py#L691-L692
 93class SubnetParamsWithEmission(SubnetParams, TypedDict):
 94    """SubnetParams with emission field."""
 95
 96    emission: int
 97    """Subnet emission percentage (0-100).
 98    """
 99
100
101class ModuleInfo(TypedDict):
102    uid: int
103    key: Ss58Address
104    name: str
105    address: str  # "<ip>:<port>"
106    emission: int
107    incentive: int
108    dividends: int
109    stake_from: list[tuple[str, int]]  # TODO: type key with Ss58Address
110    regblock: int  # block number
111    last_update: int  # block number
112    stake: int
113    delegation_fee: int
114    metadata: str
115
116
117class ModuleInfoWithBalance(ModuleInfo):
118    balance: int
119
120
121class ModuleInfoWithOptionalBalance(ModuleInfo):
122    balance: int | None
Ss58Address = Ss58Address

Substrate SS58 address.

The SS58 encoded address format is based on the Bitcoin Base58Check format, but with a few modification specifically designed to suite Substrate-based chains.

MinBurn = MinBurn
MaxBurn = MaxBurn
BurnConfig = BurnConfig
class NetworkParams(typing.TypedDict):
28class NetworkParams(TypedDict):
29    max_allowed_modules: int
30    max_registrations_per_block: int
31    max_name_length: int
32    min_name_length: int
33    min_burn: int
34    max_burn: int
35    min_weight_stake: int
36    max_allowed_subnets: int
37    curator: Ss58Address
38    proposal_cost: int
39    proposal_expiration: int
40    subnet_stake_threshold: int
41    general_subnet_application_cost: int
42    floor_founder_share: int
43    floor_delegation_fee: int
44    max_allowed_weights: int
max_allowed_modules: int
max_registrations_per_block: int
max_name_length: int
min_name_length: int
min_burn: int
max_burn: int
min_weight_stake: int
max_allowed_subnets: int
curator: Ss58Address
proposal_cost: int
proposal_expiration: int
subnet_stake_threshold: int
general_subnet_application_cost: int
floor_founder_share: int
floor_delegation_fee: int
max_allowed_weights: int
class SubnetParamsMaps(typing.TypedDict):
47class SubnetParamsMaps(TypedDict):
48    netuid_to_founder: dict[int, Ss58Address]
49    netuid_to_founder_share: dict[int, int]
50    netuid_to_immunity_period: dict[int, int]
51    netuid_to_incentive_ratio: dict[int, int]
52    netuid_to_max_allowed_uids: dict[int, int]
53    netuid_to_max_allowed_weights: dict[int, int]
54    netuid_to_min_allowed_weights: dict[int, int]
55    netuid_to_max_weight_age: dict[int, int]
56    netuid_to_min_stake: dict[int, int]
57    netuid_to_name: dict[int, str]
58    netuid_to_tempo: dict[int, int]
59    netuid_to_trust_ratio: dict[int, int]
60    netuid_to_bonds_ma: dict[int, int]
61    netuid_to_maximum_set_weight_calls_per_epoch: dict[int, int]
62    netuid_to_target_registrations_per_interval: dict[int, int]
63    netuid_to_target_registrations_interval: dict[int, int]
64    netuid_to_emission: dict[int, int]
65    netuid_to_max_registrations_per_interval: dict[int, int]
66    netuid_to_vote_mode: dict[int, dict[str, str]]
67    netuid_to_adjustment_alpha: dict[int, int]
netuid_to_founder: dict[int, Ss58Address]
netuid_to_founder_share: dict[int, int]
netuid_to_immunity_period: dict[int, int]
netuid_to_incentive_ratio: dict[int, int]
netuid_to_max_allowed_uids: dict[int, int]
netuid_to_max_allowed_weights: dict[int, int]
netuid_to_min_allowed_weights: dict[int, int]
netuid_to_max_weight_age: dict[int, int]
netuid_to_min_stake: dict[int, int]
netuid_to_name: dict[int, str]
netuid_to_tempo: dict[int, int]
netuid_to_trust_ratio: dict[int, int]
netuid_to_bonds_ma: dict[int, int]
netuid_to_maximum_set_weight_calls_per_epoch: dict[int, int]
netuid_to_target_registrations_per_interval: dict[int, int]
netuid_to_target_registrations_interval: dict[int, int]
netuid_to_emission: dict[int, int]
netuid_to_max_registrations_per_interval: dict[int, int]
netuid_to_vote_mode: dict[int, dict[str, str]]
netuid_to_adjustment_alpha: dict[int, int]
class SubnetParams(typing.TypedDict):
70class SubnetParams(TypedDict):
71    founder: Ss58Address
72    founder_share: int
73    immunity_period: int
74    incentive_ratio: int
75    max_allowed_uids: int
76    max_allowed_weights: int
77    min_allowed_weights: int
78    max_weight_age: int
79    min_stake: int
80    name: str
81    tempo: int
82    trust_ratio: int
83    bonds_ma: int | None
84    maximum_set_weight_calls_per_epoch: int | None
85    target_registrations_per_interval: int
86    target_registrations_interval: int
87    max_registrations_per_interval: int
88    vote_mode: str
89    adjustment_alpha: int
founder: Ss58Address
founder_share: int
immunity_period: int
incentive_ratio: int
max_allowed_uids: int
max_allowed_weights: int
min_allowed_weights: int
max_weight_age: int
min_stake: int
name: str
tempo: int
trust_ratio: int
bonds_ma: int | None
maximum_set_weight_calls_per_epoch: int | None
target_registrations_per_interval: int
target_registrations_interval: int
max_registrations_per_interval: int
vote_mode: str
adjustment_alpha: int
class SubnetParamsWithEmission(SubnetParams, typing.TypedDict):
94class SubnetParamsWithEmission(SubnetParams, TypedDict):
95    """SubnetParams with emission field."""
96
97    emission: int
98    """Subnet emission percentage (0-100).
99    """

SubnetParams with emission field.

emission: int

Subnet emission percentage (0-100).

class ModuleInfo(typing.TypedDict):
102class ModuleInfo(TypedDict):
103    uid: int
104    key: Ss58Address
105    name: str
106    address: str  # "<ip>:<port>"
107    emission: int
108    incentive: int
109    dividends: int
110    stake_from: list[tuple[str, int]]  # TODO: type key with Ss58Address
111    regblock: int  # block number
112    last_update: int  # block number
113    stake: int
114    delegation_fee: int
115    metadata: str
uid: int
name: str
address: str
emission: int
incentive: int
dividends: int
stake_from: list[tuple[str, int]]
regblock: int
last_update: int
stake: int
delegation_fee: int
metadata: str
class ModuleInfoWithBalance(builtins.dict):
118class ModuleInfoWithBalance(ModuleInfo):
119    balance: int
balance: int
uid: int
name: str
address: str
emission: int
incentive: int
dividends: int
stake_from: list[tuple[str, int]]
regblock: int
last_update: int
stake: int
delegation_fee: int
metadata: str
Inherited Members
builtins.dict
get
setdefault
pop
popitem
keys
items
values
update
fromkeys
clear
copy
class ModuleInfoWithOptionalBalance(builtins.dict):
122class ModuleInfoWithOptionalBalance(ModuleInfo):
123    balance: int | None
balance: int | None
uid: int
name: str
address: str
emission: int
incentive: int
dividends: int
stake_from: list[tuple[str, int]]
regblock: int
last_update: int
stake: int
delegation_fee: int
metadata: str
Inherited Members
builtins.dict
get
setdefault
pop
popitem
keys
items
values
update
fromkeys
clear
copy