Edit on GitHub

communex.types

Common types for the communex module.

  1"""
  2Common types for the communex module.
  3"""
  4
  5from enum import Enum
  6from typing import NewType, TypedDict
  7
  8from pydantic import BaseModel
  9
 10Ss58Address = NewType("Ss58Address", str)
 11"""Substrate SS58 address.
 12
 13The `SS58 encoded address format`_ is based on the Bitcoin Base58Check format,
 14but with a few modification specifically designed to suite Substrate-based
 15chains.
 16
 17.. _SS58 encoded address format:
 18    https://docs.substrate.io/reference/address-formats/
 19"""
 20
 21
 22# TODO: replace with dataclasses
 23
 24# == Burn related
 25MinBurn = NewType("MinBurn", int)
 26MaxBurn = NewType("MaxBurn", int)
 27BurnConfig = NewType("BurnConfig", dict[MinBurn, MaxBurn])
 28
 29
 30class VoteMode(Enum):
 31    authority = "Authority"
 32    vote = "Vote"
 33
 34
 35class subnetDecryptionInfo(BaseModel):
 36    node_id: Ss58Address
 37    node_public_key: bytes
 38    block_assigned: int
 39
 40
 41class DisplayGovernanceConfiguration(TypedDict):
 42    proposal_cost: float
 43    proposal_expiration: float
 44    vote_mode: VoteMode
 45    proposal_reward_treasury_allocation: float
 46    max_proposal_reward_treasury_allocation: float
 47    proposal_reward_interval: int
 48
 49
 50class GovernanceConfiguration(TypedDict):
 51    proposal_cost: int
 52    proposal_expiration: int
 53    vote_mode: int  # 0: Authority, 1: Vote
 54    proposal_reward_treasury_allocation: float
 55    max_proposal_reward_treasury_allocation: int
 56    proposal_reward_interval: int
 57
 58
 59class DisplayBurnConfiguration(TypedDict):
 60    min_burn: float
 61    max_burn: float
 62    adjustment_alpha: int
 63    target_registrations_interval: int
 64    target_registrations_per_interval: int
 65    max_registrations_per_interval: int
 66
 67
 68class BurnConfiguration(TypedDict):
 69    min_burn: int
 70    max_burn: int
 71    adjustment_alpha: int
 72    target_registrations_interval: int
 73    target_registrations_per_interval: int
 74    max_registrations_per_interval: int
 75
 76
 77class NetworkParams(TypedDict):
 78    # max
 79    max_name_length: int
 80    min_name_length: int  # dont change the position
 81    max_allowed_subnets: int
 82    max_allowed_modules: int
 83    max_registrations_per_block: int
 84    max_allowed_weights: int
 85
 86    # mins
 87    floor_delegation_fee: int
 88    floor_founder_share: int
 89    min_weight_stake: int
 90
 91    # S0 governance
 92    curator: Ss58Address
 93    general_subnet_application_cost: int
 94
 95    # Other
 96    subnet_immunity_period: int
 97    governance_config: GovernanceConfiguration
 98
 99    kappa: int
100    rho: int
101
102    subnet_registration_cost: int
103
104
105class SubnetParamsMaps(TypedDict):
106    netuid_to_founder: dict[int, Ss58Address]
107    netuid_to_founder_share: dict[int, int]
108    netuid_to_incentive_ratio: dict[int, int]
109    netuid_to_max_allowed_uids: dict[int, int]
110    netuid_to_max_allowed_weights: dict[int, int]
111    netuid_to_min_allowed_weights: dict[int, int]
112    netuid_to_max_weight_age: dict[int, int]
113    netuid_to_name: dict[int, str]
114    netuid_to_tempo: dict[int, int]
115    netuid_to_bonds_ma: dict[int, int]
116    netuid_to_maximum_set_weight_calls_per_epoch: dict[int, int]
117    netuid_to_emission: dict[int, int]
118    netuid_to_immunity_period: dict[int, int]
119    netuid_to_governance_configuration: dict[int, GovernanceConfiguration]
120    netuid_to_min_validator_stake: dict[int, int]
121    netuid_to_max_allowed_validators: dict[int, int]
122    netuid_to_module_burn_config: dict[int, BurnConfiguration]
123    netuid_to_subnet_metadata: dict[int, str]
124    netuid_to_max_encryption_period: dict[int, int]
125    netuid_to_copier_margin: dict[int, int]
126    netuid_to_use_weights_encryption: dict[int, int]
127
128
129# WIP
130class UpdatableSubnetParams(TypedDict):
131    tempo: int
132
133
134class SubnetParams(UpdatableSubnetParams, TypedDict):
135    name: str
136    min_allowed_weights: int
137    max_allowed_weights: int
138    max_allowed_uids: int
139    max_weight_age: int
140    founder_share: int
141    incentive_ratio: int
142    founder: Ss58Address
143    maximum_set_weight_calls_per_epoch: int | None
144    bonds_ma: int | None
145    immunity_period: int
146    governance_config: GovernanceConfiguration
147    min_validator_stake: int | None
148    max_allowed_validators: int | None
149    module_burn_config: BurnConfiguration
150    subnet_metadata: str | None
151    max_encryption_period: int
152    copier_margin: int
153    use_weights_encryption: int
154
155
156class DisplaySubnetParams(TypedDict):
157    name: str
158    tempo: int
159    min_allowed_weights: int
160    max_allowed_weights: int
161    max_allowed_uids: int
162    max_weight_age: int
163    trust_ratio: int
164    founder_share: int
165    incentive_ratio: int
166    founder: Ss58Address
167    maximum_set_weight_calls_per_epoch: int | None
168    bonds_ma: int
169    immunity_period: int
170    governance_config: DisplayGovernanceConfiguration
171    min_validator_stake: float
172    max_allowed_validators: int | None
173    module_burn_config: DisplayBurnConfiguration
174    subnet_metadata: str | None
175    emission: float
176    max_encryption_period: int
177    copier_margin: int
178    use_weights_encryption: int
179
180
181# redundant "TypedDict" inheritance because of pdoc warns.
182# see https://github.com/mitmproxy/pdoc/blob/26d40827ddbe1658e8ac46cd092f17a44cf0287b/pdoc/doc.py#L691-L692
183
184
185class SubnetParamsWithEmission(SubnetParams, TypedDict):
186    """SubnetParams with emission field."""
187
188    emission: int
189    """Subnet emission percentage (0-100).
190    """
191
192
193class ModuleInfo(TypedDict):
194    uid: int
195    key: Ss58Address
196    name: str
197    address: str  # "<ip>:<port>"
198    emission: int
199    incentive: int
200    dividends: int
201    stake_from: list[tuple[Ss58Address, int]]
202    regblock: int  # block number
203    last_update: int  # block number
204    stake: int
205    stake_delegation_fee: int
206    validator_weight_fee: int
207    metadata: str | None
208
209
210class ModuleInfoWithBalance(ModuleInfo):
211    balance: int
212
213
214class ModuleInfoWithOptionalBalance(ModuleInfo):
215    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 VoteMode(enum.Enum):
31class VoteMode(Enum):
32    authority = "Authority"
33    vote = "Vote"
authority = <VoteMode.authority: 'Authority'>
vote = <VoteMode.vote: 'Vote'>
Inherited Members
enum.Enum
name
value
class subnetDecryptionInfo(pydantic.main.BaseModel):
36class subnetDecryptionInfo(BaseModel):
37    node_id: Ss58Address
38    node_public_key: bytes
39    block_assigned: int

Usage docs: https://docs.pydantic.dev/2.10/concepts/models/

A base class for creating Pydantic models.

Attributes:
  • __class_vars__: The names of the class variables defined on the model.
  • __private_attributes__: Metadata about the private attributes of the model.
  • __signature__: The synthesized __init__ [Signature][inspect.Signature] of the model.
  • __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
  • __pydantic_core_schema__: The core schema of the model.
  • __pydantic_custom_init__: Whether the model has a custom __init__ function.
  • __pydantic_decorators__: Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
  • __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
  • __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
  • __pydantic_post_init__: The name of the post-init method for the model, if defined.
  • __pydantic_root_model__: Whether the model is a [RootModel][pydantic.root_model.RootModel].
  • __pydantic_serializer__: The pydantic-core SchemaSerializer used to dump instances of the model.
  • __pydantic_validator__: The pydantic-core SchemaValidator used to validate instances of the model.
  • __pydantic_fields__: A dictionary of field names and their corresponding [FieldInfo][pydantic.fields.FieldInfo] objects.
  • __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects.
  • __pydantic_extra__: A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to 'allow'.
  • __pydantic_fields_set__: The names of fields explicitly set during instantiation.
  • __pydantic_private__: Values of private attributes set on the model instance.
node_id: Ss58Address
node_public_key: bytes
block_assigned: int
model_config: ClassVar[pydantic.config.ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Inherited Members
pydantic.main.BaseModel
BaseModel
model_extra
model_fields_set
model_construct
model_copy
model_dump
model_dump_json
model_json_schema
model_parametrized_name
model_post_init
model_rebuild
model_validate
model_validate_json
model_validate_strings
dict
json
parse_obj
parse_raw
parse_file
from_orm
construct
copy
schema
schema_json
validate
update_forward_refs
model_fields
model_computed_fields
class DisplayGovernanceConfiguration(typing.TypedDict):
42class DisplayGovernanceConfiguration(TypedDict):
43    proposal_cost: float
44    proposal_expiration: float
45    vote_mode: VoteMode
46    proposal_reward_treasury_allocation: float
47    max_proposal_reward_treasury_allocation: float
48    proposal_reward_interval: int
proposal_cost: float
proposal_expiration: float
vote_mode: VoteMode
proposal_reward_treasury_allocation: float
max_proposal_reward_treasury_allocation: float
proposal_reward_interval: int
class GovernanceConfiguration(typing.TypedDict):
51class GovernanceConfiguration(TypedDict):
52    proposal_cost: int
53    proposal_expiration: int
54    vote_mode: int  # 0: Authority, 1: Vote
55    proposal_reward_treasury_allocation: float
56    max_proposal_reward_treasury_allocation: int
57    proposal_reward_interval: int
proposal_cost: int
proposal_expiration: int
vote_mode: int
proposal_reward_treasury_allocation: float
max_proposal_reward_treasury_allocation: int
proposal_reward_interval: int
class DisplayBurnConfiguration(typing.TypedDict):
60class DisplayBurnConfiguration(TypedDict):
61    min_burn: float
62    max_burn: float
63    adjustment_alpha: int
64    target_registrations_interval: int
65    target_registrations_per_interval: int
66    max_registrations_per_interval: int
min_burn: float
max_burn: float
adjustment_alpha: int
target_registrations_interval: int
target_registrations_per_interval: int
max_registrations_per_interval: int
class BurnConfiguration(typing.TypedDict):
69class BurnConfiguration(TypedDict):
70    min_burn: int
71    max_burn: int
72    adjustment_alpha: int
73    target_registrations_interval: int
74    target_registrations_per_interval: int
75    max_registrations_per_interval: int
min_burn: int
max_burn: int
adjustment_alpha: int
target_registrations_interval: int
target_registrations_per_interval: int
max_registrations_per_interval: int
class NetworkParams(typing.TypedDict):
 78class NetworkParams(TypedDict):
 79    # max
 80    max_name_length: int
 81    min_name_length: int  # dont change the position
 82    max_allowed_subnets: int
 83    max_allowed_modules: int
 84    max_registrations_per_block: int
 85    max_allowed_weights: int
 86
 87    # mins
 88    floor_delegation_fee: int
 89    floor_founder_share: int
 90    min_weight_stake: int
 91
 92    # S0 governance
 93    curator: Ss58Address
 94    general_subnet_application_cost: int
 95
 96    # Other
 97    subnet_immunity_period: int
 98    governance_config: GovernanceConfiguration
 99
100    kappa: int
101    rho: int
102
103    subnet_registration_cost: int
max_name_length: int
min_name_length: int
max_allowed_subnets: int
max_allowed_modules: int
max_registrations_per_block: int
max_allowed_weights: int
floor_delegation_fee: int
floor_founder_share: int
min_weight_stake: int
curator: Ss58Address
general_subnet_application_cost: int
subnet_immunity_period: int
governance_config: GovernanceConfiguration
kappa: int
rho: int
subnet_registration_cost: int
class SubnetParamsMaps(typing.TypedDict):
106class SubnetParamsMaps(TypedDict):
107    netuid_to_founder: dict[int, Ss58Address]
108    netuid_to_founder_share: dict[int, int]
109    netuid_to_incentive_ratio: dict[int, int]
110    netuid_to_max_allowed_uids: dict[int, int]
111    netuid_to_max_allowed_weights: dict[int, int]
112    netuid_to_min_allowed_weights: dict[int, int]
113    netuid_to_max_weight_age: dict[int, int]
114    netuid_to_name: dict[int, str]
115    netuid_to_tempo: dict[int, int]
116    netuid_to_bonds_ma: dict[int, int]
117    netuid_to_maximum_set_weight_calls_per_epoch: dict[int, int]
118    netuid_to_emission: dict[int, int]
119    netuid_to_immunity_period: dict[int, int]
120    netuid_to_governance_configuration: dict[int, GovernanceConfiguration]
121    netuid_to_min_validator_stake: dict[int, int]
122    netuid_to_max_allowed_validators: dict[int, int]
123    netuid_to_module_burn_config: dict[int, BurnConfiguration]
124    netuid_to_subnet_metadata: dict[int, str]
125    netuid_to_max_encryption_period: dict[int, int]
126    netuid_to_copier_margin: dict[int, int]
127    netuid_to_use_weights_encryption: dict[int, int]
netuid_to_founder: dict[int, Ss58Address]
netuid_to_founder_share: 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_name: dict[int, str]
netuid_to_tempo: dict[int, int]
netuid_to_bonds_ma: dict[int, int]
netuid_to_maximum_set_weight_calls_per_epoch: dict[int, int]
netuid_to_emission: dict[int, int]
netuid_to_immunity_period: dict[int, int]
netuid_to_governance_configuration: dict[int, GovernanceConfiguration]
netuid_to_min_validator_stake: dict[int, int]
netuid_to_max_allowed_validators: dict[int, int]
netuid_to_module_burn_config: dict[int, BurnConfiguration]
netuid_to_subnet_metadata: dict[int, str]
netuid_to_max_encryption_period: dict[int, int]
netuid_to_copier_margin: dict[int, int]
netuid_to_use_weights_encryption: dict[int, int]
class UpdatableSubnetParams(typing.TypedDict):
131class UpdatableSubnetParams(TypedDict):
132    tempo: int
tempo: int
class SubnetParams(UpdatableSubnetParams, typing.TypedDict):
135class SubnetParams(UpdatableSubnetParams, TypedDict):
136    name: str
137    min_allowed_weights: int
138    max_allowed_weights: int
139    max_allowed_uids: int
140    max_weight_age: int
141    founder_share: int
142    incentive_ratio: int
143    founder: Ss58Address
144    maximum_set_weight_calls_per_epoch: int | None
145    bonds_ma: int | None
146    immunity_period: int
147    governance_config: GovernanceConfiguration
148    min_validator_stake: int | None
149    max_allowed_validators: int | None
150    module_burn_config: BurnConfiguration
151    subnet_metadata: str | None
152    max_encryption_period: int
153    copier_margin: int
154    use_weights_encryption: int
name: str
min_allowed_weights: int
max_allowed_weights: int
max_allowed_uids: int
max_weight_age: int
founder_share: int
incentive_ratio: int
founder: Ss58Address
maximum_set_weight_calls_per_epoch: int | None
bonds_ma: int | None
immunity_period: int
governance_config: GovernanceConfiguration
min_validator_stake: int | None
max_allowed_validators: int | None
module_burn_config: BurnConfiguration
subnet_metadata: str | None
max_encryption_period: int
copier_margin: int
use_weights_encryption: int
Inherited Members
UpdatableSubnetParams
tempo
class DisplaySubnetParams(typing.TypedDict):
157class DisplaySubnetParams(TypedDict):
158    name: str
159    tempo: int
160    min_allowed_weights: int
161    max_allowed_weights: int
162    max_allowed_uids: int
163    max_weight_age: int
164    trust_ratio: int
165    founder_share: int
166    incentive_ratio: int
167    founder: Ss58Address
168    maximum_set_weight_calls_per_epoch: int | None
169    bonds_ma: int
170    immunity_period: int
171    governance_config: DisplayGovernanceConfiguration
172    min_validator_stake: float
173    max_allowed_validators: int | None
174    module_burn_config: DisplayBurnConfiguration
175    subnet_metadata: str | None
176    emission: float
177    max_encryption_period: int
178    copier_margin: int
179    use_weights_encryption: int
name: str
tempo: int
min_allowed_weights: int
max_allowed_weights: int
max_allowed_uids: int
max_weight_age: int
trust_ratio: int
founder_share: int
incentive_ratio: int
founder: Ss58Address
maximum_set_weight_calls_per_epoch: int | None
bonds_ma: int
immunity_period: int
governance_config: DisplayGovernanceConfiguration
min_validator_stake: float
max_allowed_validators: int | None
module_burn_config: DisplayBurnConfiguration
subnet_metadata: str | None
emission: float
max_encryption_period: int
copier_margin: int
use_weights_encryption: int
class SubnetParamsWithEmission(SubnetParams, typing.TypedDict):
186class SubnetParamsWithEmission(SubnetParams, TypedDict):
187    """SubnetParams with emission field."""
188
189    emission: int
190    """Subnet emission percentage (0-100).
191    """

SubnetParams with emission field.

emission: int

Subnet emission percentage (0-100).

tempo: int
class ModuleInfo(typing.TypedDict):
194class ModuleInfo(TypedDict):
195    uid: int
196    key: Ss58Address
197    name: str
198    address: str  # "<ip>:<port>"
199    emission: int
200    incentive: int
201    dividends: int
202    stake_from: list[tuple[Ss58Address, int]]
203    regblock: int  # block number
204    last_update: int  # block number
205    stake: int
206    stake_delegation_fee: int
207    validator_weight_fee: int
208    metadata: str | None
uid: int
name: str
address: str
emission: int
incentive: int
dividends: int
stake_from: list[tuple[Ss58Address, int]]
regblock: int
last_update: int
stake: int
stake_delegation_fee: int
validator_weight_fee: int
metadata: str | None
class ModuleInfoWithBalance(builtins.dict):
211class ModuleInfoWithBalance(ModuleInfo):
212    balance: int
balance: int
uid: int
name: str
address: str
emission: int
incentive: int
dividends: int
stake_from: list[tuple[Ss58Address, int]]
regblock: int
last_update: int
stake: int
stake_delegation_fee: int
validator_weight_fee: int
metadata: str | None
class ModuleInfoWithOptionalBalance(builtins.dict):
215class ModuleInfoWithOptionalBalance(ModuleInfo):
216    balance: int | None
balance: int | None
uid: int
name: str
address: str
emission: int
incentive: int
dividends: int
stake_from: list[tuple[Ss58Address, int]]
regblock: int
last_update: int
stake: int
stake_delegation_fee: int
validator_weight_fee: int
metadata: str | None