meshtensor-cli 9.18.1__py3-none-any.whl
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/__init__.py +22 -0
- meshtensor_cli/cli.py +10742 -0
- meshtensor_cli/doc_generation_helper.py +4 -0
- meshtensor_cli/src/__init__.py +1085 -0
- meshtensor_cli/src/commands/__init__.py +0 -0
- meshtensor_cli/src/commands/axon/__init__.py +0 -0
- meshtensor_cli/src/commands/axon/axon.py +132 -0
- meshtensor_cli/src/commands/crowd/__init__.py +0 -0
- meshtensor_cli/src/commands/crowd/contribute.py +621 -0
- meshtensor_cli/src/commands/crowd/contributors.py +200 -0
- meshtensor_cli/src/commands/crowd/create.py +783 -0
- meshtensor_cli/src/commands/crowd/dissolve.py +219 -0
- meshtensor_cli/src/commands/crowd/refund.py +233 -0
- meshtensor_cli/src/commands/crowd/update.py +418 -0
- meshtensor_cli/src/commands/crowd/utils.py +124 -0
- meshtensor_cli/src/commands/crowd/view.py +991 -0
- meshtensor_cli/src/commands/governance/__init__.py +0 -0
- meshtensor_cli/src/commands/governance/governance.py +794 -0
- meshtensor_cli/src/commands/liquidity/__init__.py +0 -0
- meshtensor_cli/src/commands/liquidity/liquidity.py +699 -0
- meshtensor_cli/src/commands/liquidity/utils.py +202 -0
- meshtensor_cli/src/commands/proxy.py +700 -0
- meshtensor_cli/src/commands/stake/__init__.py +0 -0
- meshtensor_cli/src/commands/stake/add.py +799 -0
- meshtensor_cli/src/commands/stake/auto_staking.py +306 -0
- meshtensor_cli/src/commands/stake/children_hotkeys.py +865 -0
- meshtensor_cli/src/commands/stake/claim.py +770 -0
- meshtensor_cli/src/commands/stake/list.py +738 -0
- meshtensor_cli/src/commands/stake/move.py +1211 -0
- meshtensor_cli/src/commands/stake/remove.py +1466 -0
- meshtensor_cli/src/commands/stake/wizard.py +323 -0
- meshtensor_cli/src/commands/subnets/__init__.py +0 -0
- meshtensor_cli/src/commands/subnets/mechanisms.py +515 -0
- meshtensor_cli/src/commands/subnets/price.py +733 -0
- meshtensor_cli/src/commands/subnets/subnets.py +2908 -0
- meshtensor_cli/src/commands/sudo.py +1294 -0
- meshtensor_cli/src/commands/tc/__init__.py +0 -0
- meshtensor_cli/src/commands/tc/tc.py +190 -0
- meshtensor_cli/src/commands/treasury/__init__.py +0 -0
- meshtensor_cli/src/commands/treasury/treasury.py +194 -0
- meshtensor_cli/src/commands/view.py +354 -0
- meshtensor_cli/src/commands/wallets.py +2311 -0
- meshtensor_cli/src/commands/weights.py +467 -0
- meshtensor_cli/src/meshtensor/__init__.py +0 -0
- meshtensor_cli/src/meshtensor/balances.py +313 -0
- meshtensor_cli/src/meshtensor/chain_data.py +1263 -0
- meshtensor_cli/src/meshtensor/extrinsics/__init__.py +0 -0
- meshtensor_cli/src/meshtensor/extrinsics/mev_shield.py +174 -0
- meshtensor_cli/src/meshtensor/extrinsics/registration.py +1861 -0
- meshtensor_cli/src/meshtensor/extrinsics/root.py +550 -0
- meshtensor_cli/src/meshtensor/extrinsics/serving.py +255 -0
- meshtensor_cli/src/meshtensor/extrinsics/transfer.py +239 -0
- meshtensor_cli/src/meshtensor/meshtensor_interface.py +2598 -0
- meshtensor_cli/src/meshtensor/minigraph.py +254 -0
- meshtensor_cli/src/meshtensor/networking.py +12 -0
- meshtensor_cli/src/meshtensor/templates/main-filters.j2 +24 -0
- meshtensor_cli/src/meshtensor/templates/main-header.j2 +36 -0
- meshtensor_cli/src/meshtensor/templates/neuron-details.j2 +111 -0
- meshtensor_cli/src/meshtensor/templates/price-multi.j2 +113 -0
- meshtensor_cli/src/meshtensor/templates/price-single.j2 +99 -0
- meshtensor_cli/src/meshtensor/templates/subnet-details-header.j2 +49 -0
- meshtensor_cli/src/meshtensor/templates/subnet-details.j2 +32 -0
- meshtensor_cli/src/meshtensor/templates/subnet-metrics.j2 +57 -0
- meshtensor_cli/src/meshtensor/templates/subnets-table.j2 +28 -0
- meshtensor_cli/src/meshtensor/templates/table.j2 +267 -0
- meshtensor_cli/src/meshtensor/templates/view.css +1058 -0
- meshtensor_cli/src/meshtensor/templates/view.j2 +43 -0
- meshtensor_cli/src/meshtensor/templates/view.js +1053 -0
- meshtensor_cli/src/meshtensor/utils.py +2007 -0
- meshtensor_cli/version.py +23 -0
- meshtensor_cli-9.18.1.dist-info/METADATA +261 -0
- meshtensor_cli-9.18.1.dist-info/RECORD +74 -0
- meshtensor_cli-9.18.1.dist-info/WHEEL +4 -0
- meshtensor_cli-9.18.1.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides utilities for managing liquidity positions and price conversions in the Meshtensor network. The
|
|
3
|
+
module handles conversions between MESH and Alpha tokens while maintaining precise calculations for liquidity
|
|
4
|
+
provisioning and fee distribution.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import math
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from rich.prompt import IntPrompt, FloatPrompt
|
|
12
|
+
|
|
13
|
+
from meshtensor_cli.src.meshtensor.balances import Balance, fixed_to_float
|
|
14
|
+
from meshtensor_cli.src.meshtensor.utils import (
|
|
15
|
+
console,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
# These three constants are unchangeable at the level of Uniswap math
|
|
19
|
+
MIN_TICK = -887272
|
|
20
|
+
MAX_TICK = 887272
|
|
21
|
+
PRICE_STEP = 1.0001
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class LiquidityPosition:
|
|
26
|
+
id: int
|
|
27
|
+
price_low: Balance # MESHLET
|
|
28
|
+
price_high: Balance # MESHLET
|
|
29
|
+
liquidity: Balance # MESH + ALPHA (sqrt by MESH balance * Alpha Balance -> math under the hood)
|
|
30
|
+
fees_tao: Balance # MESHLET
|
|
31
|
+
fees_alpha: Balance # MESHLET
|
|
32
|
+
netuid: int
|
|
33
|
+
|
|
34
|
+
def to_token_amounts(
|
|
35
|
+
self, current_subnet_price: Balance
|
|
36
|
+
) -> tuple[Balance, Balance]:
|
|
37
|
+
"""Convert a position to token amounts.
|
|
38
|
+
|
|
39
|
+
Arguments:
|
|
40
|
+
current_subnet_price: current subnet price in Alpha.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
tuple[int, int]:
|
|
44
|
+
Amount of Alpha in liquidity
|
|
45
|
+
Amount of MESH in liquidity
|
|
46
|
+
|
|
47
|
+
Liquidity is a combination of MESH and Alpha depending on the price of the subnet at the moment.
|
|
48
|
+
"""
|
|
49
|
+
sqrt_price_low = math.sqrt(self.price_low)
|
|
50
|
+
sqrt_price_high = math.sqrt(self.price_high)
|
|
51
|
+
sqrt_current_subnet_price = math.sqrt(current_subnet_price)
|
|
52
|
+
|
|
53
|
+
if sqrt_current_subnet_price < sqrt_price_low:
|
|
54
|
+
amount_alpha = self.liquidity * (1 / sqrt_price_low - 1 / sqrt_price_high)
|
|
55
|
+
amount_tao = 0
|
|
56
|
+
elif sqrt_current_subnet_price > sqrt_price_high:
|
|
57
|
+
amount_alpha = 0
|
|
58
|
+
amount_tao = self.liquidity * (sqrt_price_high - sqrt_price_low)
|
|
59
|
+
else:
|
|
60
|
+
amount_alpha = self.liquidity * (
|
|
61
|
+
1 / sqrt_current_subnet_price - 1 / sqrt_price_high
|
|
62
|
+
)
|
|
63
|
+
amount_tao = self.liquidity * (sqrt_current_subnet_price - sqrt_price_low)
|
|
64
|
+
return Balance.from_meshlet(int(amount_alpha)).set_unit(
|
|
65
|
+
self.netuid
|
|
66
|
+
), Balance.from_meshlet(int(amount_tao))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def price_to_tick(price: float) -> int:
|
|
70
|
+
"""Converts a float price to the nearest Uniswap V3 tick index."""
|
|
71
|
+
if price <= 0:
|
|
72
|
+
raise ValueError(f"Price must be positive, got `{price}`.")
|
|
73
|
+
|
|
74
|
+
tick = int(math.log(price) / math.log(PRICE_STEP))
|
|
75
|
+
|
|
76
|
+
if not (MIN_TICK <= tick <= MAX_TICK):
|
|
77
|
+
raise ValueError(
|
|
78
|
+
f"Resulting tick {tick} is out of allowed range ({MIN_TICK} to {MAX_TICK})"
|
|
79
|
+
)
|
|
80
|
+
return tick
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def tick_to_price(tick: int) -> float:
|
|
84
|
+
"""Convert an integer Uniswap V3 tick index to float price."""
|
|
85
|
+
if not (MIN_TICK <= tick <= MAX_TICK):
|
|
86
|
+
raise ValueError("Tick is out of allowed range")
|
|
87
|
+
return PRICE_STEP**tick
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def get_fees(
|
|
91
|
+
current_tick: int,
|
|
92
|
+
tick: dict,
|
|
93
|
+
tick_index: int,
|
|
94
|
+
quote: bool,
|
|
95
|
+
global_fees_tao: float,
|
|
96
|
+
global_fees_alpha: float,
|
|
97
|
+
above: bool,
|
|
98
|
+
) -> float:
|
|
99
|
+
"""Returns the liquidity fee."""
|
|
100
|
+
tick_fee_key = "fees_out_tao" if quote else "fees_out_alpha"
|
|
101
|
+
tick_fee_value = fixed_to_float(tick.get(tick_fee_key))
|
|
102
|
+
global_fee_value = global_fees_tao if quote else global_fees_alpha
|
|
103
|
+
|
|
104
|
+
if above:
|
|
105
|
+
return (
|
|
106
|
+
global_fee_value - tick_fee_value
|
|
107
|
+
if tick_index <= current_tick
|
|
108
|
+
else tick_fee_value
|
|
109
|
+
)
|
|
110
|
+
return (
|
|
111
|
+
tick_fee_value
|
|
112
|
+
if tick_index <= current_tick
|
|
113
|
+
else global_fee_value - tick_fee_value
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def get_fees_in_range(
|
|
118
|
+
quote: bool,
|
|
119
|
+
global_fees_tao: float,
|
|
120
|
+
global_fees_alpha: float,
|
|
121
|
+
fees_below_low: float,
|
|
122
|
+
fees_above_high: float,
|
|
123
|
+
) -> float:
|
|
124
|
+
"""Returns the liquidity fee value in a range."""
|
|
125
|
+
global_fees = global_fees_tao if quote else global_fees_alpha
|
|
126
|
+
return global_fees - fees_below_low - fees_above_high
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
# Calculate fees for a position
|
|
130
|
+
def calculate_fees(
|
|
131
|
+
position: dict[str, Any],
|
|
132
|
+
global_fees_tao: float,
|
|
133
|
+
global_fees_alpha: float,
|
|
134
|
+
tao_fees_below_low: float,
|
|
135
|
+
tao_fees_above_high: float,
|
|
136
|
+
alpha_fees_below_low: float,
|
|
137
|
+
alpha_fees_above_high: float,
|
|
138
|
+
netuid: int,
|
|
139
|
+
) -> tuple[Balance, Balance]:
|
|
140
|
+
fee_tao_agg = get_fees_in_range(
|
|
141
|
+
quote=True,
|
|
142
|
+
global_fees_tao=global_fees_tao,
|
|
143
|
+
global_fees_alpha=global_fees_alpha,
|
|
144
|
+
fees_below_low=tao_fees_below_low,
|
|
145
|
+
fees_above_high=tao_fees_above_high,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
fee_alpha_agg = get_fees_in_range(
|
|
149
|
+
quote=False,
|
|
150
|
+
global_fees_tao=global_fees_tao,
|
|
151
|
+
global_fees_alpha=global_fees_alpha,
|
|
152
|
+
fees_below_low=alpha_fees_below_low,
|
|
153
|
+
fees_above_high=alpha_fees_above_high,
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
fee_tao = fee_tao_agg - fixed_to_float(position["fees_tao"])
|
|
157
|
+
fee_alpha = fee_alpha_agg - fixed_to_float(position["fees_alpha"])
|
|
158
|
+
liquidity_frac = position["liquidity"]
|
|
159
|
+
|
|
160
|
+
fee_tao = liquidity_frac * fee_tao
|
|
161
|
+
fee_alpha = liquidity_frac * fee_alpha
|
|
162
|
+
|
|
163
|
+
return Balance.from_meshlet(int(fee_tao)), Balance.from_meshlet(int(fee_alpha)).set_unit(
|
|
164
|
+
netuid
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def prompt_liquidity(prompt: str, negative_allowed: bool = False) -> Balance:
|
|
169
|
+
"""Prompt the user for the amount of liquidity.
|
|
170
|
+
|
|
171
|
+
Arguments:
|
|
172
|
+
prompt: Prompt to display to the user.
|
|
173
|
+
negative_allowed: Whether negative amounts are allowed.
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
Balance converted from input to MESH.
|
|
177
|
+
"""
|
|
178
|
+
while True:
|
|
179
|
+
amount = FloatPrompt.ask(prompt)
|
|
180
|
+
try:
|
|
181
|
+
if amount <= 0 and not negative_allowed:
|
|
182
|
+
console.print("[red]Amount must be greater than 0[/red].")
|
|
183
|
+
continue
|
|
184
|
+
return Balance.from_tao(amount)
|
|
185
|
+
except ValueError:
|
|
186
|
+
console.print("[red]Please enter a valid number[/red].")
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def prompt_position_id() -> int:
|
|
190
|
+
"""Ask the user for the ID of the liquidity position to remove."""
|
|
191
|
+
while True:
|
|
192
|
+
position_id = IntPrompt.ask("Enter the [blue]liquidity position ID[/blue]")
|
|
193
|
+
|
|
194
|
+
try:
|
|
195
|
+
if position_id <= 1:
|
|
196
|
+
console.print("[red]Position ID must be greater than 1[/red].")
|
|
197
|
+
continue
|
|
198
|
+
return position_id
|
|
199
|
+
except ValueError:
|
|
200
|
+
console.print("[red]Please enter a valid number[/red].")
|
|
201
|
+
# will never return this, but fixes the type checker
|
|
202
|
+
return 0
|