Skip to content

Commit 5c43053

Browse files
committed
Initial commit
1 parent f0af642 commit 5c43053

File tree

2 files changed

+303
-11
lines changed

2 files changed

+303
-11
lines changed

bittensor_cli/src/__init__.py

Lines changed: 167 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44

55

66
class Constants:
7-
networks = ["local", "finney", "test", "archive"]
7+
networks = ["local", "finney", "test", "archive", "rao", "dev"]
88
finney_entrypoint = "wss://entrypoint-finney.opentensor.ai:443"
99
finney_test_entrypoint = "wss://test.finney.opentensor.ai:443"
1010
archive_entrypoint = "wss://archive.chain.opentensor.ai:443"
11+
rao_entrypoint = "wss://rao.chain.opentensor.ai:443/"
12+
dev_entrypoint = "wss://dev.chain.opentensor.ai:443 "
1113
local_entrypoint = "ws://127.0.0.1:9444"
1214
network_map = {
1315
"finney": finney_entrypoint,
1416
"test": finney_test_entrypoint,
1517
"archive": archive_entrypoint,
1618
"local": local_entrypoint,
19+
"dev": dev_entrypoint,
20+
"rao": rao_entrypoint
1721
}
1822
delegates_detail_url = "https://raw.githubusercontent.com/opentensor/bittensor-delegates/main/public/delegates.json"
1923

@@ -207,24 +211,34 @@ class WalletValidationTypes(Enum):
207211
"StakeInfoRuntimeApi": {
208212
"methods": {
209213
"get_stake_info_for_coldkey": {
214+
"params": [{"name": "coldkey_account_vec", "type": "Vec<u8>"}],
215+
"type": "Vec<u8>",
216+
},
217+
"get_stake_info_for_coldkeys": {
210218
"params": [
211-
{
212-
"name": "coldkey_account_vec",
213-
"type": "Vec<u8>",
214-
},
219+
{"name": "coldkey_account_vecs", "type": "Vec<Vec<u8>>"}
215220
],
216221
"type": "Vec<u8>",
217222
},
218-
"get_stake_info_for_coldkeys": {
223+
"get_subnet_stake_info_for_coldkeys": {
219224
"params": [
220-
{
221-
"name": "coldkey_account_vecs",
222-
"type": "Vec<Vec<u8>>",
223-
},
225+
{"name": "coldkey_account_vecs", "type": "Vec<Vec<u8>>"},
226+
{"name": "netuid", "type": "u16"},
224227
],
225228
"type": "Vec<u8>",
226229
},
227-
},
230+
"get_subnet_stake_info_for_coldkey": {
231+
"params": [
232+
{"name": "coldkey_account_vec", "type": "Vec<u8>"},
233+
{"name": "netuid", "type": "u16"},
234+
],
235+
"type": "Vec<u8>",
236+
},
237+
"get_total_subnet_stake": {
238+
"params": [{"name": "netuid", "type": "u16"}],
239+
"type": "Vec<u8>",
240+
},
241+
}
228242
},
229243
"ValidatorIPRuntimeApi": {
230244
"methods": {
@@ -302,6 +316,148 @@ class WalletValidationTypes(Enum):
302316
},
303317
}
304318

319+
UNITS = [
320+
"\u03c4", # τ (tau, 0)
321+
"\u03b1", # α (alpha, 1)
322+
"\u03b2", # β (beta, 2)
323+
"\u03b3", # γ (gamma, 3)
324+
"\u03b4", # δ (delta, 4)
325+
"\u03b5", # ε (epsilon, 5)
326+
"\u03b6", # ζ (zeta, 6)
327+
"\u03b7", # η (eta, 7)
328+
"\u03b8", # θ (theta, 8)
329+
"\u03b9", # ι (iota, 9)
330+
"\u03ba", # κ (kappa, 10)
331+
"\u03bb", # λ (lambda, 11)
332+
"\u03bc", # μ (mu, 12)
333+
"\u03bd", # ν (nu, 13)
334+
"\u03be", # ξ (xi, 14)
335+
"\u03bf", # ο (omicron, 15)
336+
"\u03c0", # π (pi, 16)
337+
"\u03c1", # ρ (rho, 17)
338+
"\u03c3", # σ (sigma, 18)
339+
"t", # t (tau, 19)
340+
"\u03c5", # υ (upsilon, 20)
341+
"\u03c6", # φ (phi, 21)
342+
"\u03c7", # χ (chi, 22)
343+
"\u03c8", # ψ (psi, 23)
344+
"\u03c9", # ω (omega, 24)
345+
# Hebrew letters
346+
"\u05d0", # א (aleph, 25)
347+
"\u05d1", # ב (bet, 26)
348+
"\u05d2", # ג (gimel, 27)
349+
"\u05d3", # ד (dalet, 28)
350+
"\u05d4", # ה (he, 29)
351+
"\u05d5", # ו (vav, 30)
352+
"\u05d6", # ז (zayin, 31)
353+
"\u05d7", # ח (het, 32)
354+
"\u05d8", # ט (tet, 33)
355+
"\u05d9", # י (yod, 34)
356+
"\u05da", # ך (final kaf, 35)
357+
"\u05db", # כ (kaf, 36)
358+
"\u05dc", # ל (lamed, 37)
359+
"\u05dd", # ם (final mem, 38)
360+
"\u05de", # מ (mem, 39)
361+
"\u05df", # ן (final nun, 40)
362+
"\u05e0", # נ (nun, 41)
363+
"\u05e1", # ס (samekh, 42)
364+
"\u05e2", # ע (ayin, 43)
365+
"\u05e3", # ף (final pe, 44)
366+
"\u05e4", # פ (pe, 45)
367+
"\u05e5", # ץ (final tsadi, 46)
368+
"\u05e6", # צ (tsadi, 47)
369+
"\u05e7", # ק (qof, 48)
370+
"\u05e8", # ר (resh, 49)
371+
"\u05e9", # ש (shin, 50)
372+
"\u05ea", # ת (tav, 51)
373+
# Georgian Alphabet (Mkhedruli)
374+
"\u10d0", # ა (Ani, 97)
375+
"\u10d1", # ბ (Bani, 98)
376+
"\u10d2", # გ (Gani, 99)
377+
"\u10d3", # დ (Doni, 100)
378+
"\u10d4", # ე (Eni, 101)
379+
"\u10d5", # ვ (Vini, 102)
380+
# Armenian Alphabet
381+
"\u0531", # Ա (Ayp, 103)
382+
"\u0532", # Բ (Ben, 104)
383+
"\u0533", # Գ (Gim, 105)
384+
"\u0534", # Դ (Da, 106)
385+
"\u0535", # Ե (Ech, 107)
386+
"\u0536", # Զ (Za, 108)
387+
# "\u055e", # ՞ (Question mark, 109)
388+
# Runic Alphabet
389+
"\u16a0", # ᚠ (Fehu, wealth, 81)
390+
"\u16a2", # ᚢ (Uruz, strength, 82)
391+
"\u16a6", # ᚦ (Thurisaz, giant, 83)
392+
"\u16a8", # ᚨ (Ansuz, god, 84)
393+
"\u16b1", # ᚱ (Raidho, ride, 85)
394+
"\u16b3", # ᚲ (Kaunan, ulcer, 86)
395+
"\u16c7", # ᛇ (Eihwaz, yew, 87)
396+
"\u16c9", # ᛉ (Algiz, protection, 88)
397+
"\u16d2", # ᛒ (Berkanan, birch, 89)
398+
# Cyrillic Alphabet
399+
"\u0400", # Ѐ (Ie with grave, 110)
400+
"\u0401", # Ё (Io, 111)
401+
"\u0402", # Ђ (Dje, 112)
402+
"\u0403", # Ѓ (Gje, 113)
403+
"\u0404", # Є (Ukrainian Ie, 114)
404+
"\u0405", # Ѕ (Dze, 115)
405+
# Coptic Alphabet
406+
"\u2c80", # Ⲁ (Alfa, 116)
407+
"\u2c81", # ⲁ (Small Alfa, 117)
408+
"\u2c82", # Ⲃ (Vida, 118)
409+
"\u2c83", # ⲃ (Small Vida, 119)
410+
"\u2c84", # Ⲅ (Gamma, 120)
411+
"\u2c85", # ⲅ (Small Gamma, 121)
412+
# Arabic letters
413+
"\u0627", # ا (alef, 52)
414+
"\u0628", # ب (ba, 53)
415+
"\u062a", # ت (ta, 54)
416+
"\u062b", # ث (tha, 55)
417+
"\u062c", # ج (jeem, 56)
418+
"\u062d", # ح (ha, 57)
419+
"\u062e", # خ (kha, 58)
420+
"\u062f", # د (dal, 59)
421+
"\u0630", # ذ (dhal, 60)
422+
"\u0631", # ر (ra, 61)
423+
"\u0632", # ز (zay, 62)
424+
"\u0633", # س (seen, 63)
425+
"\u0634", # ش (sheen, 64)
426+
"\u0635", # ص (sad, 65)
427+
"\u0636", # ض (dad, 66)
428+
"\u0637", # ط (ta, 67)
429+
"\u0638", # ظ (dha, 68)
430+
"\u0639", # ع (ain, 69)
431+
"\u063a", # غ (ghain, 70)
432+
"\u0641", # ف (fa, 71)
433+
"\u0642", # ق (qaf, 72)
434+
"\u0643", # ك (kaf, 73)
435+
"\u0644", # ل (lam, 74)
436+
"\u0645", # م (meem, 75)
437+
"\u0646", # ن (noon, 76)
438+
"\u0647", # ه (ha, 77)
439+
"\u0648", # و (waw, 78)
440+
"\u0649", # ى (alef maksura, 79)
441+
"\u064a", # ي (ya, 80)
442+
# Ogham Alphabet
443+
"\u1680", #   (Space, 90)
444+
"\u1681", # ᚁ (Beith, birch, 91)
445+
"\u1682", # ᚂ (Luis, rowan, 92)
446+
"\u1683", # ᚃ (Fearn, alder, 93)
447+
"\u1684", # ᚄ (Sail, willow, 94)
448+
"\u1685", # ᚅ (Nion, ash, 95)
449+
"\u169b", # ᚛ (Forfeda, 96)
450+
# Brahmi Script TODO verify these https://discord.com/channels/799672011265015819/1176889593136693339/1288500713625878558
451+
"\u11000", # 𑀀 (A, 122)
452+
"\u11001", # 𑀁 (Aa, 123)
453+
"\u11002", # 𑀂 (I, 124)
454+
"\u11003", # 𑀃 (Ii, 125)
455+
"\u11005", # 𑀅 (U, 126)
456+
# Tifinagh Alphabet
457+
"\u2d30", # ⴰ (Ya, 127)
458+
"\u2d31", # ⴱ (Yab, 128)
459+
]
460+
305461
NETWORK_EXPLORER_MAP = {
306462
"opentensor": {
307463
"local": "https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fentrypoint-finney.opentensor.ai%3A443#/explorer",

bittensor_cli/src/bittensor/chain_data.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,47 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["SubnetInfo"]:
571571
)
572572
return result
573573

574+
@dataclass
575+
class SubnetInfoV2:
576+
"""Dataclass for subnet info."""
577+
netuid: int
578+
owner_ss58: str
579+
max_allowed_validators: int
580+
scaling_law_power: float
581+
subnetwork_n: int
582+
max_n: int
583+
blocks_since_epoch: int
584+
modality: int
585+
emission_value: float
586+
burn: Balance
587+
tao_locked: Balance
588+
hyperparameters: "SubnetHyperparameters"
589+
dynamic_pool: "DynamicPool"
590+
591+
@classmethod
592+
def from_vec_u8(cls, vec_u8: bytes) -> Optional["SubnetInfoV2"]:
593+
"""Returns a SubnetInfoV2 object from a ``vec_u8``."""
594+
if len(vec_u8) == 0:
595+
return None
596+
decoded = bt_decode.SubnetInfoV2.decode(vec_u8) # TODO fix values
597+
598+
if decoded is None:
599+
return None
600+
601+
return cls.fix_decoded_values(decoded)
602+
603+
@classmethod
604+
def list_from_vec_u8(cls, vec_u8: bytes) -> List["SubnetInfoV2"]:
605+
"""Returns a list of SubnetInfoV2 objects from a ``vec_u8``."""
606+
decoded = bt_decode.SubnetInfoV2.decode_vec(vec_u8) # TODO fix values
607+
608+
if decoded is None:
609+
return []
610+
611+
decoded = [cls.fix_decoded_values(d) for d in decoded]
612+
613+
return decoded
614+
574615

575616
custom_rpc_type_registry = {
576617
"types": {
@@ -597,6 +638,35 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["SubnetInfo"]:
597638
["owner", "AccountId"],
598639
],
599640
},
641+
"DynamicPoolInfoV2": {
642+
"type": "struct",
643+
"type_mapping": [
644+
["netuid", "u16"],
645+
["alpha_issuance", "u64"],
646+
["alpha_outstanding", "u64"],
647+
["alpha_reserve", "u64"],
648+
["tao_reserve", "u64"],
649+
["k", "u128"],
650+
],
651+
},
652+
"SubnetInfoV2": {
653+
"type": "struct",
654+
"type_mapping": [
655+
["netuid", "u16"],
656+
["owner", "AccountId"],
657+
["max_allowed_validators", "u16"],
658+
["scaling_law_power", "u16"],
659+
["subnetwork_n", "u16"],
660+
["max_allowed_uids", "u16"],
661+
["blocks_since_last_step", "Compact<u32>"],
662+
["network_modality", "u16"],
663+
["emission_values", "Compact<u64>"],
664+
["burn", "Compact<u64>"],
665+
["tao_locked", "Compact<u64>"],
666+
["hyperparameters", "SubnetHyperparameters"],
667+
["dynamic_pool", "Option<DynamicPoolInfoV2>"],
668+
],
669+
},
600670
"DelegateInfo": {
601671
"type": "struct",
602672
"type_mapping": [
@@ -610,6 +680,16 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["SubnetInfo"]:
610680
["total_daily_return", "Compact<u64>"],
611681
],
612682
},
683+
"DelegateInfoLight": {
684+
"type": "struct",
685+
"type_mapping": [
686+
["delegate_ss58", "AccountId"],
687+
["owner_ss58", "AccountId"],
688+
["take", "u16"],
689+
["owner_stake", "Compact<u64>"],
690+
["total_stake", "Compact<u64>"],
691+
],
692+
},
613693
"NeuronInfo": {
614694
"type": "struct",
615695
"type_mapping": [
@@ -688,6 +768,37 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["SubnetInfo"]:
688768
["ip_type_and_protocol", "Compact<u8>"],
689769
],
690770
},
771+
"ScheduledColdkeySwapInfo": {
772+
"type": "struct",
773+
"type_mapping": [
774+
["old_coldkey", "AccountId"],
775+
["new_coldkey", "AccountId"],
776+
["arbitration_block", "Compact<u64>"],
777+
],
778+
},
779+
"SubnetState": {
780+
"type": "struct",
781+
"type_mapping": [
782+
["netuid", "Compact<u16>"],
783+
["hotkeys", "Vec<AccountId>"],
784+
["coldkeys", "Vec<AccountId>"],
785+
["active", "Vec<bool>"],
786+
["validator_permit", "Vec<bool>"],
787+
["pruning_score", "Vec<Compact<u16>>"],
788+
["last_update", "Vec<Compact<u64>>"],
789+
["emission", "Vec<Compact<u64>>"],
790+
["dividends", "Vec<Compact<u16>>"],
791+
["incentives", "Vec<Compact<u16>>"],
792+
["consensus", "Vec<Compact<u16>>"],
793+
["trust", "Vec<Compact<u16>>"],
794+
["rank", "Vec<Compact<u16>>"],
795+
["block_at_registration", "Vec<Compact<u64>>"],
796+
["local_stake", "Vec<Compact<u64>>"],
797+
["global_stake", "Vec<Compact<u64>>"],
798+
["stake_weight", "Vec<Compact<u16>>"],
799+
["emission_history", "Vec<Vec<Compact<u64>>>"],
800+
],
801+
},
691802
"StakeInfo": {
692803
"type": "struct",
693804
"type_mapping": [
@@ -696,6 +807,31 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["SubnetInfo"]:
696807
["stake", "Compact<u64>"],
697808
],
698809
},
810+
"DynamicInfo": {
811+
"type": "struct",
812+
"type_mapping": [
813+
["owner", "AccountId"],
814+
["netuid", "Compact<u16>"],
815+
["tempo", "Compact<u16>"],
816+
["last_step", "Compact<u64>"],
817+
["blocks_since_last_step", "Compact<u64>"],
818+
["emission", "Compact<u64>"],
819+
["alpha_in", "Compact<u64>"],
820+
["alpha_out", "Compact<u64>"],
821+
["tao_in", "Compact<u64>"],
822+
["total_locked", "Compact<u64>"],
823+
["owner_locked", "Compact<u64>"],
824+
],
825+
},
826+
"SubstakeElements": {
827+
"type": "struct",
828+
"type_mapping": [
829+
["hotkey", "AccountId"],
830+
["coldkey", "AccountId"],
831+
["netuid", "Compact<u16>"],
832+
["stake", "Compact<u64>"],
833+
],
834+
},
699835
"SubnetHyperparameters": {
700836
"type": "struct",
701837
"type_mapping": [

0 commit comments

Comments
 (0)