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):
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.
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
vote_mode: VoteMode
class
GovernanceConfiguration(typing.TypedDict):
class
DisplayBurnConfiguration(typing.TypedDict):
class
BurnConfiguration(typing.TypedDict):
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
curator: Ss58Address
governance_config: GovernanceConfiguration
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_governance_configuration: dict[int, GovernanceConfiguration]
netuid_to_module_burn_config: dict[int, BurnConfiguration]
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
founder: Ss58Address
governance_config: GovernanceConfiguration
module_burn_config: BurnConfiguration
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
founder: Ss58Address
governance_config: DisplayGovernanceConfiguration
module_burn_config: DisplayBurnConfiguration
163class SubnetParamsWithEmission(SubnetParams, TypedDict): 164 """SubnetParams with emission field.""" 165 166 emission: int 167 """Subnet emission percentage (0-100). 168 """
SubnetParams with emission field.
Inherited Members
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
key: Ss58Address
stake_from: list[tuple[Ss58Address, int]]
class
ModuleInfoWithBalance(builtins.dict):
key: Ss58Address
stake_from: list[tuple[Ss58Address, int]]
Inherited Members
- builtins.dict
- get
- setdefault
- pop
- popitem
- keys
- items
- values
- update
- fromkeys
- clear
- copy
class
ModuleInfoWithOptionalBalance(builtins.dict):
key: Ss58Address
stake_from: list[tuple[Ss58Address, int]]
Inherited Members
- builtins.dict
- get
- setdefault
- pop
- popitem
- keys
- items
- values
- update
- fromkeys
- clear
- copy