Skip to content

Commit 37123e5

Browse files
authored
Merge pull request #515 from opentensor/feat/roman/liquidity-provider
Integrate Liquidity Provider feature
2 parents 7d39145 + 4de77c8 commit 37123e5

File tree

11 files changed

+1542
-84
lines changed

11 files changed

+1542
-84
lines changed

bittensor_cli/cli.py

Lines changed: 328 additions & 22 deletions
Large diffs are not rendered by default.

bittensor_cli/src/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,11 @@ class WalletValidationTypes(Enum):
660660
),
661661
"yuma3_enabled": ("sudo_set_yuma3_enabled", False),
662662
"alpha_sigmoid_steepness": ("sudo_set_alpha_sigmoid_steepness", True),
663+
"user_liquidity_enabled": ("toggle_user_liquidity", True),
664+
}
665+
666+
HYPERPARAMS_MODULE = {
667+
"user_liquidity_enabled": "Swap",
663668
}
664669

665670
# Help Panels for cli help
@@ -699,6 +704,9 @@ class WalletValidationTypes(Enum):
699704
"VIEW": {
700705
"DASHBOARD": "Network Dashboard",
701706
},
707+
"LIQUIDITY": {
708+
"LIQUIDITY_MGMT": "Liquidity Management",
709+
},
702710
}
703711

704712

bittensor_cli/src/bittensor/chain_data.py

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,49 @@ def get(self, item, default=None):
148148

149149
@dataclass
150150
class SubnetHyperparameters(InfoBase):
151-
"""Dataclass for subnet hyperparameters."""
151+
"""
152+
This class represents the hyperparameters for a subnet.
153+
Attributes:
154+
rho (int): The rate of decay of some value.
155+
kappa (int): A constant multiplier used in calculations.
156+
immunity_period (int): The period during which immunity is active.
157+
min_allowed_weights (int): Minimum allowed weights.
158+
max_weight_limit (float): Maximum weight limit.
159+
tempo (int): The tempo or rate of operation.
160+
min_difficulty (int): Minimum difficulty for some operations.
161+
max_difficulty (int): Maximum difficulty for some operations.
162+
weights_version (int): The version number of the weights used.
163+
weights_rate_limit (int): Rate limit for processing weights.
164+
adjustment_interval (int): Interval at which adjustments are made.
165+
activity_cutoff (int): Activity cutoff threshold.
166+
registration_allowed (bool): Indicates if registration is allowed.
167+
target_regs_per_interval (int): Target number of registrations per interval.
168+
min_burn (int): Minimum burn value.
169+
max_burn (int): Maximum burn value.
170+
bonds_moving_avg (int): Moving average of bonds.
171+
max_regs_per_block (int): Maximum number of registrations per block.
172+
serving_rate_limit (int): Limit on the rate of service.
173+
max_validators (int): Maximum number of validators.
174+
adjustment_alpha (int): Alpha value for adjustments.
175+
difficulty (int): Difficulty level.
176+
commit_reveal_period (int): Interval for commit-reveal weights.
177+
commit_reveal_weights_enabled (bool): Flag indicating if commit-reveal weights are enabled.
178+
alpha_high (int): High value of alpha.
179+
alpha_low (int): Low value of alpha.
180+
liquid_alpha_enabled (bool): Flag indicating if liquid alpha is enabled.
181+
alpha_sigmoid_steepness (float):
182+
yuma_version (int): Version of yuma.
183+
subnet_is_active (bool): Indicates if subnet is active after START CALL.
184+
transfers_enabled (bool): Flag indicating if transfers are enabled.
185+
bonds_reset_enabled (bool): Flag indicating if bonds are reset enabled.
186+
user_liquidity_enabled (bool): Flag indicating if user liquidity is enabled.
187+
"""
152188

153189
rho: int
154190
kappa: int
155191
immunity_period: int
156192
min_allowed_weights: int
157-
max_weights_limit: float
193+
max_weight_limit: float
158194
tempo: int
159195
min_difficulty: int
160196
max_difficulty: int
@@ -177,43 +213,53 @@ class SubnetHyperparameters(InfoBase):
177213
alpha_high: int
178214
alpha_low: int
179215
liquid_alpha_enabled: bool
180-
yuma3_enabled: bool
181-
alpha_sigmoid_steepness: int
216+
alpha_sigmoid_steepness: float
217+
yuma_version: int
218+
subnet_is_active: bool
219+
transfers_enabled: bool
220+
bonds_reset_enabled: bool
221+
user_liquidity_enabled: bool
182222

183223
@classmethod
184224
def _fix_decoded(
185225
cls, decoded: Union[dict, "SubnetHyperparameters"]
186226
) -> "SubnetHyperparameters":
187227
return cls(
188-
rho=decoded.get("rho"),
189-
kappa=decoded.get("kappa"),
190-
immunity_period=decoded.get("immunity_period"),
191-
min_allowed_weights=decoded.get("min_allowed_weights"),
192-
max_weights_limit=decoded.get("max_weights_limit"),
193-
tempo=decoded.get("tempo"),
194-
min_difficulty=decoded.get("min_difficulty"),
195-
max_difficulty=decoded.get("max_difficulty"),
196-
weights_version=decoded.get("weights_version"),
197-
weights_rate_limit=decoded.get("weights_rate_limit"),
198-
adjustment_interval=decoded.get("adjustment_interval"),
199-
activity_cutoff=decoded.get("activity_cutoff"),
200-
registration_allowed=decoded.get("registration_allowed"),
201-
target_regs_per_interval=decoded.get("target_regs_per_interval"),
202-
min_burn=decoded.get("min_burn"),
203-
max_burn=decoded.get("max_burn"),
204-
bonds_moving_avg=decoded.get("bonds_moving_avg"),
205-
max_regs_per_block=decoded.get("max_regs_per_block"),
206-
serving_rate_limit=decoded.get("serving_rate_limit"),
207-
max_validators=decoded.get("max_validators"),
208-
adjustment_alpha=decoded.get("adjustment_alpha"),
209-
difficulty=decoded.get("difficulty"),
210-
commit_reveal_period=decoded.get("commit_reveal_period"),
211-
commit_reveal_weights_enabled=decoded.get("commit_reveal_weights_enabled"),
212-
alpha_high=decoded.get("alpha_high"),
213-
alpha_low=decoded.get("alpha_low"),
214-
liquid_alpha_enabled=decoded.get("liquid_alpha_enabled"),
215-
yuma3_enabled=decoded.get("yuma3_enabled"),
216-
alpha_sigmoid_steepness=decoded.get("alpha_sigmoid_steepness"),
228+
activity_cutoff=decoded["activity_cutoff"],
229+
adjustment_alpha=decoded["adjustment_alpha"],
230+
adjustment_interval=decoded["adjustment_interval"],
231+
alpha_high=decoded["alpha_high"],
232+
alpha_low=decoded["alpha_low"],
233+
alpha_sigmoid_steepness=fixed_to_float(
234+
decoded["alpha_sigmoid_steepness"], frac_bits=32
235+
),
236+
bonds_moving_avg=decoded["bonds_moving_avg"],
237+
bonds_reset_enabled=decoded["bonds_reset_enabled"],
238+
commit_reveal_weights_enabled=decoded["commit_reveal_weights_enabled"],
239+
commit_reveal_period=decoded["commit_reveal_period"],
240+
difficulty=decoded["difficulty"],
241+
immunity_period=decoded["immunity_period"],
242+
kappa=decoded["kappa"],
243+
liquid_alpha_enabled=decoded["liquid_alpha_enabled"],
244+
max_burn=decoded["max_burn"],
245+
max_difficulty=decoded["max_difficulty"],
246+
max_regs_per_block=decoded["max_regs_per_block"],
247+
max_validators=decoded["max_validators"],
248+
max_weight_limit=decoded["max_weights_limit"],
249+
min_allowed_weights=decoded["min_allowed_weights"],
250+
min_burn=decoded["min_burn"],
251+
min_difficulty=decoded["min_difficulty"],
252+
registration_allowed=decoded["registration_allowed"],
253+
rho=decoded["rho"],
254+
serving_rate_limit=decoded["serving_rate_limit"],
255+
subnet_is_active=decoded["subnet_is_active"],
256+
target_regs_per_interval=decoded["target_regs_per_interval"],
257+
tempo=decoded["tempo"],
258+
transfers_enabled=decoded["transfers_enabled"],
259+
user_liquidity_enabled=decoded["user_liquidity_enabled"],
260+
weights_rate_limit=decoded["weights_rate_limit"],
261+
weights_version=decoded["weights_version"],
262+
yuma_version=decoded["yuma_version"],
217263
)
218264

219265

bittensor_cli/src/bittensor/subtensor_interface.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,33 @@ async def get_netuids_for_hotkey(
531531
res.append(record[0])
532532
return res
533533

534+
async def is_subnet_active(
535+
self,
536+
netuid: int,
537+
block_hash: Optional[str] = None,
538+
reuse_block: bool = False,
539+
) -> bool:
540+
"""Verify if subnet with provided netuid is active.
541+
542+
Args:
543+
netuid (int): The unique identifier of the subnet.
544+
block_hash (Optional[str]): The blockchain block_hash representation of block id.
545+
reuse_block (bool): Whether to reuse the last-used block hash.
546+
547+
Returns:
548+
True if subnet is active, False otherwise.
549+
550+
This means whether the `start_call` was initiated or not.
551+
"""
552+
query = await self.substrate.query(
553+
module="SubtensorModule",
554+
storage_function="FirstEmissionBlockNumber",
555+
block_hash=block_hash,
556+
reuse_block_hash=reuse_block,
557+
params=[netuid],
558+
)
559+
return True if query and query.value > 0 else False
560+
534561
async def subnet_exists(
535562
self, netuid: int, block_hash: Optional[str] = None, reuse_block: bool = False
536563
) -> bool:
@@ -1128,22 +1155,13 @@ async def get_subnet_hyperparameters(
11281155
Understanding the hyperparameters is crucial for comprehending how subnets are configured and
11291156
managed, and how they interact with the network's consensus and incentive mechanisms.
11301157
"""
1131-
main_result, yuma3_result, sigmoid_steepness = await asyncio.gather(
1132-
self.query_runtime_api(
1133-
runtime_api="SubnetInfoRuntimeApi",
1134-
method="get_subnet_hyperparams",
1135-
params=[netuid],
1136-
block_hash=block_hash,
1137-
),
1138-
self.query("SubtensorModule", "Yuma3On", [netuid]),
1139-
self.query("SubtensorModule", "AlphaSigmoidSteepness", [netuid]),
1158+
result = await self.query_runtime_api(
1159+
runtime_api="SubnetInfoRuntimeApi",
1160+
method="get_subnet_hyperparams_v2",
1161+
params=[netuid],
1162+
block_hash=block_hash,
11401163
)
1141-
result = {
1142-
**main_result,
1143-
**{"yuma3_enabled": yuma3_result},
1144-
**{"alpha_sigmoid_steepness": sigmoid_steepness},
1145-
}
1146-
if not main_result:
1164+
if not result:
11471165
return []
11481166

11491167
return SubnetHyperparameters.from_any(result)

bittensor_cli/src/bittensor/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,7 @@ def unlock_key(
13791379
err_msg = f"The password used to decrypt your {unlock_type.capitalize()}key Keyfile is invalid."
13801380
if print_out:
13811381
err_console.print(f":cross_mark: [red]{err_msg}[/red]")
1382+
return unlock_key(wallet, unlock_type, print_out)
13821383
return UnlockStatus(False, err_msg)
13831384
except KeyFileError:
13841385
err_msg = f"{unlock_type.capitalize()}key Keyfile is corrupt, non-writable, or non-readable, or non-existent."

bittensor_cli/src/commands/liquidity/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)