meshtensor-cli 9.26.0__tar.gz → 9.26.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/PKG-INFO +1 -1
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/__init__.py +0 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/balances.py +313 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/chain_data.py +1263 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/extrinsics/__init__.py +0 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/extrinsics/mev_shield.py +174 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/extrinsics/registration.py +1861 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/extrinsics/root.py +550 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/extrinsics/serving.py +255 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/extrinsics/transfer.py +239 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/meshtensor_interface.py +2598 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/minigraph.py +254 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/networking.py +12 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/subtensor_interface.py +2598 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/main-filters.j2 +24 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/main-header.j2 +36 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/neuron-details.j2 +111 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/price-multi.j2 +113 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/price-single.j2 +99 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/subnet-details-header.j2 +49 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/subnet-details.j2 +32 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/subnet-metrics.j2 +57 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/subnets-table.j2 +28 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/table.j2 +267 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/view.css +1058 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/view.j2 +43 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/templates/view.js +1053 -0
- meshtensor_cli-9.26.1/meshtensor_cli/src/meshtensor/utils.py +2007 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/pyproject.toml +1 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/__init__.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/balances.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/chain_data.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/extrinsics/__init__.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/extrinsics/mev_shield.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/extrinsics/registration.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/extrinsics/root.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/extrinsics/serving.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/extrinsics/transfer.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/meshtensor_interface.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/minigraph.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/networking.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/subtensor_interface.py +0 -1
- meshtensor_cli-9.26.0/meshtensor_cli/src/meshtensor/utils.py +0 -1
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/README.md +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/cli.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/doc_generation_helper.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/balances.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/chain_data.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/extrinsics/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/extrinsics/mev_shield.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/extrinsics/registration.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/extrinsics/root.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/extrinsics/serving.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/extrinsics/transfer.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/minigraph.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/networking.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/subtensor_interface.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/main-filters.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/main-header.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/neuron-details.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/price-multi.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/price-single.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/subnet-details-header.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/subnet-details.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/subnet-metrics.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/subnets-table.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/table.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/view.css +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/view.j2 +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/templates/view.js +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/bittensor/utils.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/axon/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/axon/axon.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/crowd/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/crowd/contribute.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/crowd/contributors.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/crowd/create.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/crowd/dissolve.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/crowd/refund.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/crowd/update.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/crowd/utils.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/crowd/view.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/governance/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/governance/governance.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/liquidity/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/liquidity/liquidity.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/liquidity/utils.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/proxy.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/stake/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/stake/add.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/stake/auto_staking.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/stake/children_hotkeys.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/stake/claim.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/stake/list.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/stake/move.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/stake/remove.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/stake/wizard.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/subnets/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/subnets/mechanisms.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/subnets/price.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/subnets/subnets.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/sudo.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/tc/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/tc/tc.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/treasury/__init__.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/treasury/treasury.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/view.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/wallets.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/src/commands/weights.py +0 -0
- {meshtensor_cli-9.26.0 → meshtensor_cli-9.26.1}/meshtensor_cli/version.py +0 -0
|
File without changes
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
# Copyright © 2021-2022 Yuma Rao
|
|
3
|
+
# Copyright © 2022 Opentensor Foundation
|
|
4
|
+
# Copyright © 2023 Opentensor Technologies Inc
|
|
5
|
+
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
7
|
+
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
|
|
8
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
9
|
+
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
|
|
12
|
+
# the Software.
|
|
13
|
+
|
|
14
|
+
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
15
|
+
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
16
|
+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
17
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
18
|
+
# DEALINGS IN THE SOFTWARE.
|
|
19
|
+
|
|
20
|
+
from typing import Union
|
|
21
|
+
from meshtensor_cli.src import UNITS
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Balance:
|
|
25
|
+
"""
|
|
26
|
+
Represents the meshtensor balance of the wallet, stored as meshlet (int).
|
|
27
|
+
This class provides a way to interact with balances in two different units: meshlet and tao.
|
|
28
|
+
It provides methods to convert between these units, as well as to perform arithmetic and comparison operations.
|
|
29
|
+
|
|
30
|
+
:var unit: A string representing the symbol for the mesh unit.
|
|
31
|
+
:var meshlet_unit: A string representing the symbol for the meshlet unit.
|
|
32
|
+
:var meshlet: An integer that stores the balance in meshlet units.
|
|
33
|
+
:var tao: A float property that gives the balance in mesh units.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
unit: str = chr(0x03C4) # This is the mesh unit
|
|
37
|
+
meshlet_unit: str = chr(0x03C1) # This is the meshlet unit
|
|
38
|
+
meshlet: int
|
|
39
|
+
tao: float
|
|
40
|
+
|
|
41
|
+
def __init__(self, balance: Union[int, float]):
|
|
42
|
+
"""
|
|
43
|
+
Initialize a Balance object. If balance is an int, it's assumed to be in meshlet.
|
|
44
|
+
If balance is a float, it's assumed to be in tao.
|
|
45
|
+
|
|
46
|
+
:param balance: The initial balance, in either meshlet (if an int) or mesh (if a float).
|
|
47
|
+
"""
|
|
48
|
+
if isinstance(balance, int):
|
|
49
|
+
self.meshlet = balance
|
|
50
|
+
elif isinstance(balance, float):
|
|
51
|
+
# Assume mesh value for the float
|
|
52
|
+
self.meshlet = int(balance * pow(10, 9))
|
|
53
|
+
else:
|
|
54
|
+
raise TypeError("balance must be an int (meshlet) or a float (tao)")
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def tao(self):
|
|
58
|
+
return self.meshlet / pow(10, 9)
|
|
59
|
+
|
|
60
|
+
def __int__(self):
|
|
61
|
+
"""
|
|
62
|
+
Convert the Balance object to an int. The resulting value is in meshlet.
|
|
63
|
+
"""
|
|
64
|
+
return self.meshlet
|
|
65
|
+
|
|
66
|
+
def __float__(self):
|
|
67
|
+
"""
|
|
68
|
+
Convert the Balance object to a float. The resulting value is in tao.
|
|
69
|
+
"""
|
|
70
|
+
return self.tao
|
|
71
|
+
|
|
72
|
+
def __str__(self):
|
|
73
|
+
"""
|
|
74
|
+
Returns the Balance object as a string in the format "symbolvalue", where the value is in tao.
|
|
75
|
+
"""
|
|
76
|
+
if self.unit == UNITS[0]:
|
|
77
|
+
return f"{self.unit} {float(self.tao):,.4f}"
|
|
78
|
+
else:
|
|
79
|
+
return f"\u200e{float(self.tao):,.4f} {self.unit}\u200e"
|
|
80
|
+
|
|
81
|
+
def __rich__(self):
|
|
82
|
+
return "[green]{}[/green][green]{}[/green][green].[/green][dim green]{}[/dim green]".format(
|
|
83
|
+
self.unit,
|
|
84
|
+
format(float(self.tao), "f").split(".")[0],
|
|
85
|
+
format(float(self.tao), "f").split(".")[1],
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def __str_meshlet__(self):
|
|
89
|
+
return f"{self.meshlet_unit}{int(self.meshlet)}"
|
|
90
|
+
|
|
91
|
+
def __rich_meshlet__(self):
|
|
92
|
+
return f"[green]{self.meshlet_unit}{int(self.meshlet)}[/green]"
|
|
93
|
+
|
|
94
|
+
def __repr__(self):
|
|
95
|
+
return self.__str__()
|
|
96
|
+
|
|
97
|
+
def __bool__(self):
|
|
98
|
+
return self.meshlet != 0
|
|
99
|
+
|
|
100
|
+
def __eq__(self, other: Union[int, float, "Balance"]):
|
|
101
|
+
if other is None:
|
|
102
|
+
return False
|
|
103
|
+
|
|
104
|
+
if hasattr(other, "meshlet"):
|
|
105
|
+
return self.meshlet == other.meshlet
|
|
106
|
+
else:
|
|
107
|
+
try:
|
|
108
|
+
# Attempt to cast to int from meshlet
|
|
109
|
+
other_meshlet = int(other)
|
|
110
|
+
return self.meshlet == other_meshlet
|
|
111
|
+
except (TypeError, ValueError):
|
|
112
|
+
raise NotImplementedError("Unsupported type")
|
|
113
|
+
|
|
114
|
+
def __ne__(self, other: Union[int, float, "Balance"]):
|
|
115
|
+
return not self == other
|
|
116
|
+
|
|
117
|
+
def __gt__(self, other: Union[int, float, "Balance"]):
|
|
118
|
+
if hasattr(other, "meshlet"):
|
|
119
|
+
return self.meshlet > other.meshlet
|
|
120
|
+
else:
|
|
121
|
+
try:
|
|
122
|
+
# Attempt to cast to int from meshlet
|
|
123
|
+
other_meshlet = int(other)
|
|
124
|
+
return self.meshlet > other_meshlet
|
|
125
|
+
except ValueError:
|
|
126
|
+
raise NotImplementedError("Unsupported type")
|
|
127
|
+
|
|
128
|
+
def __lt__(self, other: Union[int, float, "Balance"]):
|
|
129
|
+
if hasattr(other, "meshlet"):
|
|
130
|
+
return self.meshlet < other.meshlet
|
|
131
|
+
else:
|
|
132
|
+
try:
|
|
133
|
+
# Attempt to cast to int from meshlet
|
|
134
|
+
other_meshlet = int(other)
|
|
135
|
+
return self.meshlet < other_meshlet
|
|
136
|
+
except ValueError:
|
|
137
|
+
raise NotImplementedError("Unsupported type")
|
|
138
|
+
|
|
139
|
+
def __le__(self, other: Union[int, float, "Balance"]):
|
|
140
|
+
try:
|
|
141
|
+
return self < other or self == other
|
|
142
|
+
except TypeError:
|
|
143
|
+
raise NotImplementedError("Unsupported type")
|
|
144
|
+
|
|
145
|
+
def __ge__(self, other: Union[int, float, "Balance"]):
|
|
146
|
+
try:
|
|
147
|
+
return self > other or self == other
|
|
148
|
+
except TypeError:
|
|
149
|
+
raise NotImplementedError("Unsupported type")
|
|
150
|
+
|
|
151
|
+
def __add__(self, other: Union[int, float, "Balance"]):
|
|
152
|
+
if hasattr(other, "meshlet"):
|
|
153
|
+
return Balance.from_meshlet(int(self.meshlet + other.meshlet))
|
|
154
|
+
else:
|
|
155
|
+
try:
|
|
156
|
+
# Attempt to cast to int from meshlet
|
|
157
|
+
return Balance.from_meshlet(int(self.meshlet + other))
|
|
158
|
+
except (ValueError, TypeError):
|
|
159
|
+
raise NotImplementedError("Unsupported type")
|
|
160
|
+
|
|
161
|
+
def __radd__(self, other: Union[int, float, "Balance"]):
|
|
162
|
+
try:
|
|
163
|
+
return self + other
|
|
164
|
+
except TypeError:
|
|
165
|
+
raise NotImplementedError("Unsupported type")
|
|
166
|
+
|
|
167
|
+
def __sub__(self, other: Union[int, float, "Balance"]):
|
|
168
|
+
try:
|
|
169
|
+
return self + -other
|
|
170
|
+
except TypeError:
|
|
171
|
+
raise NotImplementedError("Unsupported type")
|
|
172
|
+
|
|
173
|
+
def __rsub__(self, other: Union[int, float, "Balance"]):
|
|
174
|
+
try:
|
|
175
|
+
return -self + other
|
|
176
|
+
except TypeError:
|
|
177
|
+
raise NotImplementedError("Unsupported type")
|
|
178
|
+
|
|
179
|
+
def __mul__(self, other: Union[int, float, "Balance"]):
|
|
180
|
+
if hasattr(other, "meshlet"):
|
|
181
|
+
return Balance.from_meshlet(int(self.meshlet * other.meshlet))
|
|
182
|
+
else:
|
|
183
|
+
try:
|
|
184
|
+
# Attempt to cast to int from meshlet
|
|
185
|
+
return Balance.from_meshlet(int(self.meshlet * other))
|
|
186
|
+
except (ValueError, TypeError):
|
|
187
|
+
raise NotImplementedError("Unsupported type")
|
|
188
|
+
|
|
189
|
+
def __rmul__(self, other: Union[int, float, "Balance"]):
|
|
190
|
+
return self * other
|
|
191
|
+
|
|
192
|
+
def __truediv__(self, other: Union[int, float, "Balance"]):
|
|
193
|
+
if hasattr(other, "meshlet"):
|
|
194
|
+
return Balance.from_meshlet(int(self.meshlet / other.meshlet))
|
|
195
|
+
else:
|
|
196
|
+
try:
|
|
197
|
+
# Attempt to cast to int from meshlet
|
|
198
|
+
return Balance.from_meshlet(int(self.meshlet / other))
|
|
199
|
+
except (ValueError, TypeError):
|
|
200
|
+
raise NotImplementedError("Unsupported type")
|
|
201
|
+
|
|
202
|
+
def __rtruediv__(self, other: Union[int, float, "Balance"]):
|
|
203
|
+
if hasattr(other, "meshlet"):
|
|
204
|
+
return Balance.from_meshlet(int(other.meshlet / self.meshlet))
|
|
205
|
+
else:
|
|
206
|
+
try:
|
|
207
|
+
# Attempt to cast to int from meshlet
|
|
208
|
+
return Balance.from_meshlet(int(other / self.meshlet))
|
|
209
|
+
except (ValueError, TypeError):
|
|
210
|
+
raise NotImplementedError("Unsupported type")
|
|
211
|
+
|
|
212
|
+
def __floordiv__(self, other: Union[int, float, "Balance"]):
|
|
213
|
+
if hasattr(other, "meshlet"):
|
|
214
|
+
return Balance.from_meshlet(int(self.tao // other.tao))
|
|
215
|
+
else:
|
|
216
|
+
try:
|
|
217
|
+
# Attempt to cast to int from meshlet
|
|
218
|
+
return Balance.from_meshlet(int(self.meshlet // other))
|
|
219
|
+
except (ValueError, TypeError):
|
|
220
|
+
raise NotImplementedError("Unsupported type")
|
|
221
|
+
|
|
222
|
+
def __rfloordiv__(self, other: Union[int, float, "Balance"]):
|
|
223
|
+
if hasattr(other, "meshlet"):
|
|
224
|
+
return Balance.from_meshlet(int(other.meshlet // self.meshlet))
|
|
225
|
+
else:
|
|
226
|
+
try:
|
|
227
|
+
# Attempt to cast to int from meshlet
|
|
228
|
+
return Balance.from_meshlet(int(other // self.meshlet))
|
|
229
|
+
except (ValueError, TypeError):
|
|
230
|
+
raise NotImplementedError("Unsupported type")
|
|
231
|
+
|
|
232
|
+
def __nonzero__(self) -> bool:
|
|
233
|
+
return bool(self.meshlet)
|
|
234
|
+
|
|
235
|
+
def __neg__(self):
|
|
236
|
+
return Balance.from_meshlet(-self.meshlet)
|
|
237
|
+
|
|
238
|
+
def __pos__(self):
|
|
239
|
+
return Balance.from_meshlet(self.meshlet)
|
|
240
|
+
|
|
241
|
+
def __abs__(self):
|
|
242
|
+
return Balance.from_meshlet(abs(self.meshlet))
|
|
243
|
+
|
|
244
|
+
def to_dict(self) -> dict:
|
|
245
|
+
return {"meshlet": self.meshlet, "mesh": self.tao}
|
|
246
|
+
|
|
247
|
+
@staticmethod
|
|
248
|
+
def from_float(amount: float):
|
|
249
|
+
"""
|
|
250
|
+
Given mesh (float), return Balance object with meshlet(int) and tao(float), where meshlet = int(tao*pow(10,9))
|
|
251
|
+
:param amount: The amount in tao.
|
|
252
|
+
|
|
253
|
+
:return: A Balance object representing the given amount.
|
|
254
|
+
"""
|
|
255
|
+
meshlet = int(amount * pow(10, 9))
|
|
256
|
+
return Balance(meshlet)
|
|
257
|
+
|
|
258
|
+
@staticmethod
|
|
259
|
+
def from_tao(amount: float):
|
|
260
|
+
"""
|
|
261
|
+
Given mesh (float), return Balance object with meshlet(int) and tao(float), where meshlet = int(tao*pow(10,9))
|
|
262
|
+
|
|
263
|
+
:param amount: The amount in tao.
|
|
264
|
+
|
|
265
|
+
:return: A Balance object representing the given amount.
|
|
266
|
+
"""
|
|
267
|
+
meshlet = int(amount * pow(10, 9))
|
|
268
|
+
return Balance(meshlet)
|
|
269
|
+
|
|
270
|
+
@staticmethod
|
|
271
|
+
def from_meshlet(amount: int):
|
|
272
|
+
"""
|
|
273
|
+
Given meshlet (int), return Balance object with meshlet(int) and tao(float), where meshlet = int(tao*pow(10,9))
|
|
274
|
+
|
|
275
|
+
:param amount: The amount in meshlet.
|
|
276
|
+
|
|
277
|
+
:return: A Balance object representing the given amount.
|
|
278
|
+
"""
|
|
279
|
+
return Balance(int(amount))
|
|
280
|
+
|
|
281
|
+
@staticmethod
|
|
282
|
+
def get_unit(netuid: int):
|
|
283
|
+
units = UNITS
|
|
284
|
+
base = len(units)
|
|
285
|
+
if netuid < base:
|
|
286
|
+
return units[netuid]
|
|
287
|
+
else:
|
|
288
|
+
result = ""
|
|
289
|
+
while netuid > 0:
|
|
290
|
+
result = units[netuid % base] + result
|
|
291
|
+
netuid //= base
|
|
292
|
+
return result
|
|
293
|
+
|
|
294
|
+
def set_unit(self, netuid: int):
|
|
295
|
+
self.unit = Balance.get_unit(netuid)
|
|
296
|
+
self.meshlet_unit = Balance.get_unit(netuid)
|
|
297
|
+
return self
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def fixed_to_float(fixed, frac_bits: int = 64, total_bits: int = 128) -> float:
|
|
301
|
+
# By default, this is a U64F64
|
|
302
|
+
# which is 64 bits of integer and 64 bits of fractional
|
|
303
|
+
|
|
304
|
+
data: int = fixed["bits"]
|
|
305
|
+
|
|
306
|
+
# Logical and to get the fractional part; remaining is the integer part
|
|
307
|
+
fractional_part = data & (2**frac_bits - 1)
|
|
308
|
+
# Shift to get the integer part from the remaining bits
|
|
309
|
+
integer_part = data >> (total_bits - frac_bits)
|
|
310
|
+
|
|
311
|
+
frac_float = fractional_part / (2**frac_bits)
|
|
312
|
+
|
|
313
|
+
return integer_part + frac_float
|