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

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access::
>>> Color.RED
<Color.RED: 1>
  • value lookup:
>>> Color(1)
<Color.RED: 1>
  • name lookup:
>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details.

authority = <VoteMode.authority: 'Authority'>
vote = <VoteMode.vote: 'Vote'>
Inherited Members
enum.Enum
name
value
class DisplayGovernanceConfiguration(typing.TypedDict):
34class DisplayGovernanceConfiguration(TypedDict):
35    proposal_cost: float
36    proposal_expiration: float
37    vote_mode: VoteMode
38    proposal_reward_treasury_allocation: float
39    max_proposal_reward_treasury_allocation: float
40    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):
43class GovernanceConfiguration(TypedDict):
44    proposal_cost: int
45    proposal_expiration: int
46    vote_mode: int  # 0: Authority, 1: Vote
47    proposal_reward_treasury_allocation: float
48    max_proposal_reward_treasury_allocation: int
49    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):
52class DisplayBurnConfiguration(TypedDict):
53    min_burn: float
54    max_burn: float
55    adjustment_alpha: int
56    target_registrations_interval: int
57    target_registrations_per_interval: int
58    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):
61class BurnConfiguration(TypedDict):
62    min_burn: int
63    max_burn: int
64    adjustment_alpha: int
65    target_registrations_interval: int
66    target_registrations_per_interval: int
67    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):
70class NetworkParams(TypedDict):
71    # max
72    max_name_length: int
73    min_name_length: int  # dont change the position
74    max_allowed_subnets: int
75    max_allowed_modules: int
76    max_registrations_per_block: int
77    max_allowed_weights: int
78
79    # mins
80    floor_delegation_fee: int
81    floor_founder_share: int
82    min_weight_stake: int
83
84    # S0 governance
85    curator: Ss58Address
86    general_subnet_application_cost: int
87
88    # Other
89    subnet_immunity_period: int
90    governance_config: GovernanceConfiguration
91
92    kappa: int
93    rho: int
94
95    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):
 98class SubnetParamsMaps(TypedDict):
 99    netuid_to_founder: dict[int, Ss58Address]
100    netuid_to_founder_share: dict[int, int]
101    netuid_to_incentive_ratio: dict[int, int]
102    netuid_to_max_allowed_uids: dict[int, int]
103    netuid_to_max_allowed_weights: dict[int, int]
104    netuid_to_min_allowed_weights: dict[int, int]
105    netuid_to_max_weight_age: dict[int, int]
106    netuid_to_name: dict[int, str]
107    netuid_to_tempo: dict[int, int]
108    netuid_to_trust_ratio: dict[int, int]
109    netuid_to_bonds_ma: dict[int, int]
110    netuid_to_maximum_set_weight_calls_per_epoch: dict[int, int]
111    netuid_to_emission: dict[int, int]
112    netuid_to_immunity_period: dict[int, int]
113    netuid_to_governance_configuration: dict[int, GovernanceConfiguration]
114    netuid_to_min_validator_stake: dict[int, int]
115    netuid_to_max_allowed_validators: dict[int, int]
116    netuid_to_module_burn_config: dict[int, BurnConfiguration]
117    netuid_to_subnet_metadata: dict[int, str]
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_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_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]
class SubnetParams(typing.TypedDict):
119class SubnetParams(TypedDict):
120    name: str
121    tempo: int
122    min_allowed_weights: int
123    max_allowed_weights: int
124    max_allowed_uids: int
125    max_weight_age: int
126    trust_ratio: int
127    founder_share: int
128    incentive_ratio: int
129    founder: Ss58Address
130    maximum_set_weight_calls_per_epoch: int | None
131    bonds_ma: int | None
132    immunity_period: int
133    governance_config: GovernanceConfiguration
134    min_validator_stake: int | None
135    max_allowed_validators: int | None
136    module_burn_config: BurnConfiguration
137    subnet_metadata: str | None
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 | 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
class DisplaySubnetParams(typing.TypedDict):
140class DisplaySubnetParams(TypedDict):
141    name: str
142    tempo: int
143    min_allowed_weights: int
144    max_allowed_weights: int
145    max_allowed_uids: int
146    max_weight_age: int
147    trust_ratio: int
148    founder_share: int
149    incentive_ratio: int
150    founder: Ss58Address
151    maximum_set_weight_calls_per_epoch: int | None
152    bonds_ma: int
153    immunity_period: int
154    governance_config: DisplayGovernanceConfiguration
155    min_validator_stake: float
156    max_allowed_validators: int | None
157    module_burn_config: DisplayBurnConfiguration
158    subnet_metadata: str | None
159    emission: float
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
class SubnetParamsWithEmission(SubnetParams, typing.TypedDict):
163class SubnetParamsWithEmission(SubnetParams, TypedDict):
164    """SubnetParams with emission field."""
165
166    emission: int
167    """Subnet emission percentage (0-100).
168    """

SubnetParams with emission field.

emission: int

Subnet emission percentage (0-100).

class ModuleInfo(typing.TypedDict):
171class ModuleInfo(TypedDict):
172    uid: int
173    key: Ss58Address
174    name: str
175    address: str  # "<ip>:<port>"
176    emission: int
177    incentive: int
178    dividends: int
179    stake_from: list[tuple[Ss58Address, int]]
180    regblock: int  # block number
181    last_update: int  # block number
182    stake: int
183    delegation_fee: int
184    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
delegation_fee: int
metadata: str | None
class ModuleInfoWithBalance(builtins.dict):
187class ModuleInfoWithBalance(ModuleInfo):
188    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
delegation_fee: int
metadata: str | None
Inherited Members
builtins.dict
get
setdefault
pop
popitem
keys
items
values
update
fromkeys
clear
copy
class ModuleInfoWithOptionalBalance(builtins.dict):
191class ModuleInfoWithOptionalBalance(ModuleInfo):
192    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
delegation_fee: int
metadata: str | None
Inherited Members
builtins.dict
get
setdefault
pop
popitem
keys
items
values
update
fromkeys
clear
copy