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
  6from enum import Enum
  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
 27class VoteMode (Enum):
 28    authority = "0"
 29    vote = "1"
 30
 31
 32class GovernanceConfiguration(TypedDict):
 33    proposal_cost: int
 34    proposal_expiration: int
 35    vote_mode: int # 0: Authority, 1: Vote
 36    proposal_reward_treasury_allocation: float
 37    max_proposal_reward_treasury_allocation: int
 38    proposal_reward_interval: int
 39
 40
 41
 42class NetworkParams(TypedDict):
 43    # max
 44    max_name_length: int
 45    min_name_length: int # dont change the position
 46    max_allowed_subnets: int
 47    max_allowed_modules: int
 48    max_registrations_per_block: int
 49    max_allowed_weights: int
 50
 51    # mins
 52    floor_delegation_fee: int
 53    floor_founder_share: int
 54    min_weight_stake: int
 55
 56    # S0 governance
 57    curator: Ss58Address
 58    general_subnet_application_cost: int
 59
 60    # Other
 61    subnet_immunity_period: int
 62    min_burn: int
 63    max_burn: int
 64    governance_config: GovernanceConfiguration
 65
 66    kappa: int
 67    rho: int
 68
 69
 70class SubnetParamsMaps(TypedDict):
 71    netuid_to_founder: dict[int, Ss58Address]
 72    netuid_to_founder_share: dict[int, int]
 73    netuid_to_incentive_ratio: dict[int, int]
 74    netuid_to_max_allowed_uids: dict[int, int]
 75    netuid_to_max_allowed_weights: dict[int, int]
 76    netuid_to_min_allowed_weights: dict[int, int]
 77    netuid_to_max_weight_age: dict[int, int]
 78    netuid_to_name: dict[int, str]
 79    netuid_to_tempo: dict[int, int]
 80    netuid_to_trust_ratio: dict[int, int]
 81    netuid_to_bonds_ma: dict[int, int]
 82    netuid_to_maximum_set_weight_calls_per_epoch: dict[int, int]
 83    netuid_to_target_registrations_per_interval: dict[int, int]
 84    netuid_to_target_registrations_interval: dict[int, int]
 85    netuid_to_emission: dict[int, int]
 86    netuid_to_max_registrations_per_interval: dict[int, int]
 87    netuid_to_adjustment_alpha: dict[int, int]
 88    netuid_to_min_immunity_stake: dict[int, int]
 89    netuid_to_immunity_period: dict[int, int]
 90    netuid_to_governance_configuration: dict[int, GovernanceConfiguration]
 91
 92
 93class SubnetParams(TypedDict):
 94    name: str
 95    tempo: int
 96    min_allowed_weights: int
 97    max_allowed_weights: int
 98    max_allowed_uids: int
 99    max_weight_age: int
100    trust_ratio: int
101    founder_share: int
102    incentive_ratio: int
103    founder: Ss58Address
104    maximum_set_weight_calls_per_epoch: int | None
105    bonds_ma: int | None
106    target_registrations_interval: int
107    target_registrations_per_interval: int
108    max_registrations_per_interval: int
109    adjustment_alpha: int
110    min_immunity_stake: int
111    immunity_period: int
112    governance_config: GovernanceConfiguration
113
114
115# redundant "TypedDict" inheritance because of pdoc warns.
116# see https://github.com/mitmproxy/pdoc/blob/26d40827ddbe1658e8ac46cd092f17a44cf0287b/pdoc/doc.py#L691-L692
117class SubnetParamsWithEmission(SubnetParams, TypedDict):
118    """SubnetParams with emission field."""
119
120    emission: int
121    """Subnet emission percentage (0-100).
122    """
123
124
125class ModuleInfo(TypedDict):
126    uid: int
127    key: Ss58Address
128    name: str
129    address: str  # "<ip>:<port>"
130    emission: int
131    incentive: int
132    dividends: int
133    stake_from: list[tuple[str, int]]  # TODO: type key with Ss58Address
134    regblock: int  # block number
135    last_update: int  # block number
136    stake: int
137    delegation_fee: int
138    metadata: str
139
140
141class ModuleInfoWithBalance(ModuleInfo):
142    balance: int
143
144
145class ModuleInfoWithOptionalBalance(ModuleInfo):
146    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):
28class VoteMode (Enum):
29    authority = "0"
30    vote = "1"

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: '0'>
vote = <VoteMode.vote: '1'>
Inherited Members
enum.Enum
name
value
class GovernanceConfiguration(typing.TypedDict):
33class GovernanceConfiguration(TypedDict):
34    proposal_cost: int
35    proposal_expiration: int
36    vote_mode: int # 0: Authority, 1: Vote
37    proposal_reward_treasury_allocation: float
38    max_proposal_reward_treasury_allocation: int
39    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 NetworkParams(typing.TypedDict):
43class NetworkParams(TypedDict):
44    # max
45    max_name_length: int
46    min_name_length: int # dont change the position
47    max_allowed_subnets: int
48    max_allowed_modules: int
49    max_registrations_per_block: int
50    max_allowed_weights: int
51
52    # mins
53    floor_delegation_fee: int
54    floor_founder_share: int
55    min_weight_stake: int
56
57    # S0 governance
58    curator: Ss58Address
59    general_subnet_application_cost: int
60
61    # Other
62    subnet_immunity_period: int
63    min_burn: int
64    max_burn: int
65    governance_config: GovernanceConfiguration
66
67    kappa: int
68    rho: 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
min_burn: int
max_burn: int
governance_config: GovernanceConfiguration
kappa: int
rho: int
class SubnetParamsMaps(typing.TypedDict):
71class SubnetParamsMaps(TypedDict):
72    netuid_to_founder: dict[int, Ss58Address]
73    netuid_to_founder_share: dict[int, int]
74    netuid_to_incentive_ratio: dict[int, int]
75    netuid_to_max_allowed_uids: dict[int, int]
76    netuid_to_max_allowed_weights: dict[int, int]
77    netuid_to_min_allowed_weights: dict[int, int]
78    netuid_to_max_weight_age: dict[int, int]
79    netuid_to_name: dict[int, str]
80    netuid_to_tempo: dict[int, int]
81    netuid_to_trust_ratio: dict[int, int]
82    netuid_to_bonds_ma: dict[int, int]
83    netuid_to_maximum_set_weight_calls_per_epoch: dict[int, int]
84    netuid_to_target_registrations_per_interval: dict[int, int]
85    netuid_to_target_registrations_interval: dict[int, int]
86    netuid_to_emission: dict[int, int]
87    netuid_to_max_registrations_per_interval: dict[int, int]
88    netuid_to_adjustment_alpha: dict[int, int]
89    netuid_to_min_immunity_stake: dict[int, int]
90    netuid_to_immunity_period: dict[int, int]
91    netuid_to_governance_configuration: dict[int, GovernanceConfiguration]
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_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_adjustment_alpha: dict[int, int]
netuid_to_min_immunity_stake: dict[int, int]
netuid_to_immunity_period: dict[int, int]
netuid_to_governance_configuration: dict[int, GovernanceConfiguration]
class SubnetParams(typing.TypedDict):
 94class SubnetParams(TypedDict):
 95    name: str
 96    tempo: int
 97    min_allowed_weights: int
 98    max_allowed_weights: int
 99    max_allowed_uids: int
100    max_weight_age: int
101    trust_ratio: int
102    founder_share: int
103    incentive_ratio: int
104    founder: Ss58Address
105    maximum_set_weight_calls_per_epoch: int | None
106    bonds_ma: int | None
107    target_registrations_interval: int
108    target_registrations_per_interval: int
109    max_registrations_per_interval: int
110    adjustment_alpha: int
111    min_immunity_stake: int
112    immunity_period: int
113    governance_config: GovernanceConfiguration
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
target_registrations_interval: int
target_registrations_per_interval: int
max_registrations_per_interval: int
adjustment_alpha: int
min_immunity_stake: int
immunity_period: int
governance_config: GovernanceConfiguration
class SubnetParamsWithEmission(SubnetParams, typing.TypedDict):
118class SubnetParamsWithEmission(SubnetParams, TypedDict):
119    """SubnetParams with emission field."""
120
121    emission: int
122    """Subnet emission percentage (0-100).
123    """

SubnetParams with emission field.

emission: int

Subnet emission percentage (0-100).

class ModuleInfo(typing.TypedDict):
126class ModuleInfo(TypedDict):
127    uid: int
128    key: Ss58Address
129    name: str
130    address: str  # "<ip>:<port>"
131    emission: int
132    incentive: int
133    dividends: int
134    stake_from: list[tuple[str, int]]  # TODO: type key with Ss58Address
135    regblock: int  # block number
136    last_update: int  # block number
137    stake: int
138    delegation_fee: int
139    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):
142class ModuleInfoWithBalance(ModuleInfo):
143    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):
146class ModuleInfoWithOptionalBalance(ModuleInfo):
147    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