From f0d93656d1d0712748f8e476a8457f57a4f7d415 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 7 Jul 2025 14:24:21 -0700 Subject: [PATCH 1/3] add hotkey into extrinsics --- bittensor/core/extrinsics/asyncex/liquidity.py | 12 +++++++++--- bittensor/core/extrinsics/liquidity.py | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bittensor/core/extrinsics/asyncex/liquidity.py b/bittensor/core/extrinsics/asyncex/liquidity.py index cbe43575ba..8c41e1b66b 100644 --- a/bittensor/core/extrinsics/asyncex/liquidity.py +++ b/bittensor/core/extrinsics/asyncex/liquidity.py @@ -17,6 +17,7 @@ async def add_liquidity_extrinsic( liquidity: Balance, price_low: Balance, price_high: Balance, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -31,6 +32,7 @@ async def add_liquidity_extrinsic( liquidity: The amount of liquidity to be added. price_low: The lower bound of the price tick range. price_high: The upper bound of the price tick range. + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -56,7 +58,7 @@ async def add_liquidity_extrinsic( call_module="Swap", call_function="add_liquidity", call_params={ - "hotkey": wallet.hotkey.ss58_address, + "hotkey": hotkey or wallet.hotkey.ss58_address, "netuid": netuid, "tick_low": tick_low, "tick_high": tick_high, @@ -80,6 +82,7 @@ async def modify_liquidity_extrinsic( netuid: int, position_id: int, liquidity_delta: Balance, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -92,6 +95,7 @@ async def modify_liquidity_extrinsic( netuid: The UID of the target subnet for which the call is being initiated. position_id: The id of the position record in the pool. liquidity_delta: The amount of liquidity to be added or removed (add if positive or remove if negative). + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -114,7 +118,7 @@ async def modify_liquidity_extrinsic( call_module="Swap", call_function="modify_position", call_params={ - "hotkey": wallet.hotkey.ss58_address, + "hotkey": hotkey or wallet.hotkey.ss58_address, "netuid": netuid, "position_id": position_id, "liquidity_delta": liquidity_delta.rao, @@ -136,6 +140,7 @@ async def remove_liquidity_extrinsic( wallet: "Wallet", netuid: int, position_id: int, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -147,6 +152,7 @@ async def remove_liquidity_extrinsic( wallet: The wallet used to sign the extrinsic (must be unlocked). netuid: The UID of the target subnet for which the call is being initiated. position_id: The id of the position record in the pool. + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -169,7 +175,7 @@ async def remove_liquidity_extrinsic( call_module="Swap", call_function="remove_liquidity", call_params={ - "hotkey": wallet.hotkey.ss58_address, + "hotkey": hotkey or wallet.hotkey.ss58_address, "netuid": netuid, "position_id": position_id, }, diff --git a/bittensor/core/extrinsics/liquidity.py b/bittensor/core/extrinsics/liquidity.py index 9e22da4139..96e502692c 100644 --- a/bittensor/core/extrinsics/liquidity.py +++ b/bittensor/core/extrinsics/liquidity.py @@ -17,6 +17,7 @@ def add_liquidity_extrinsic( liquidity: Balance, price_low: Balance, price_high: Balance, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -31,6 +32,7 @@ def add_liquidity_extrinsic( liquidity: The amount of liquidity to be added. price_low: The lower bound of the price tick range. price_high: The upper bound of the price tick range. + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -56,7 +58,7 @@ def add_liquidity_extrinsic( call_module="Swap", call_function="add_liquidity", call_params={ - "hotkey": wallet.hotkey.ss58_address, + "hotkey": hotkey or wallet.hotkey.ss58_address, "netuid": netuid, "tick_low": tick_low, "tick_high": tick_high, @@ -80,6 +82,7 @@ def modify_liquidity_extrinsic( netuid: int, position_id: int, liquidity_delta: Balance, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -92,6 +95,7 @@ def modify_liquidity_extrinsic( netuid: The UID of the target subnet for which the call is being initiated. position_id: The id of the position record in the pool. liquidity_delta: The amount of liquidity to be added or removed (add if positive or remove if negative). + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -114,7 +118,7 @@ def modify_liquidity_extrinsic( call_module="Swap", call_function="modify_position", call_params={ - "hotkey": wallet.hotkey.ss58_address, + "hotkey": hotkey or wallet.hotkey.ss58_address, "netuid": netuid, "position_id": position_id, "liquidity_delta": liquidity_delta.rao, @@ -136,6 +140,7 @@ def remove_liquidity_extrinsic( wallet: "Wallet", netuid: int, position_id: int, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -147,6 +152,7 @@ def remove_liquidity_extrinsic( wallet: The wallet used to sign the extrinsic (must be unlocked). netuid: The UID of the target subnet for which the call is being initiated. position_id: The id of the position record in the pool. + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -169,7 +175,7 @@ def remove_liquidity_extrinsic( call_module="Swap", call_function="remove_liquidity", call_params={ - "hotkey": wallet.hotkey.ss58_address, + "hotkey": hotkey or wallet.hotkey.ss58_address, "netuid": netuid, "position_id": position_id, }, From aa3f2979071338e5449165f5155ee0d1a453020c Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 7 Jul 2025 14:24:37 -0700 Subject: [PATCH 2/3] add hotkey into subtensor calls --- bittensor/core/async_subtensor.py | 12 ++++++++++++ bittensor/core/subtensor.py | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index d198e72c4d..788a48cb93 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -3785,6 +3785,7 @@ async def add_liquidity( liquidity: Balance, price_low: Balance, price_high: Balance, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -3798,6 +3799,8 @@ async def add_liquidity( liquidity: The amount of liquidity to be added. price_low: The lower bound of the price tick range. In TAO. price_high: The upper bound of the price tick range. In TAO. + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to + `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -3819,6 +3822,7 @@ async def add_liquidity( liquidity=liquidity, price_low=price_low, price_high=price_high, + hotkey=hotkey, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, period=period, @@ -3992,6 +3996,7 @@ async def modify_liquidity( netuid: int, position_id: int, liquidity_delta: Balance, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -4003,6 +4008,8 @@ async def modify_liquidity( netuid: The UID of the target subnet for which the call is being initiated. position_id: The id of the position record in the pool. liquidity_delta: The amount of liquidity to be added or removed (add if positive or remove if negative). + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to + `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -4049,6 +4056,7 @@ async def modify_liquidity( netuid=netuid, position_id=position_id, liquidity_delta=liquidity_delta, + hotkey=hotkey, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, period=period, @@ -4200,6 +4208,7 @@ async def remove_liquidity( wallet: "Wallet", netuid: int, position_id: int, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -4210,6 +4219,8 @@ async def remove_liquidity( wallet: The wallet used to sign the extrinsic (must be unlocked). netuid: The UID of the target subnet for which the call is being initiated. position_id: The id of the position record in the pool. + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to + `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -4231,6 +4242,7 @@ async def remove_liquidity( wallet=wallet, netuid=netuid, position_id=position_id, + hotkey=hotkey, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, period=period, diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index a98b703beb..7afb5f97f5 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -3002,6 +3002,7 @@ def add_liquidity( liquidity: Balance, price_low: Balance, price_high: Balance, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -3015,6 +3016,8 @@ def add_liquidity( liquidity: The amount of liquidity to be added. price_low: The lower bound of the price tick range. In TAO. price_high: The upper bound of the price tick range. In TAO. + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to + `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -3036,6 +3039,7 @@ def add_liquidity( liquidity=liquidity, price_low=price_low, price_high=price_high, + hotkey=hotkey, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, period=period, @@ -3214,6 +3218,7 @@ def modify_liquidity( netuid: int, position_id: int, liquidity_delta: Balance, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -3225,6 +3230,8 @@ def modify_liquidity( netuid: The UID of the target subnet for which the call is being initiated. position_id: The id of the position record in the pool. liquidity_delta: The amount of liquidity to be added or removed (add if positive or remove if negative). + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to + `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -3271,6 +3278,7 @@ def modify_liquidity( netuid=netuid, position_id=position_id, liquidity_delta=liquidity_delta, + hotkey=hotkey, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, period=period, @@ -3421,6 +3429,7 @@ def remove_liquidity( wallet: "Wallet", netuid: int, position_id: int, + hotkey: Optional[str] = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, period: Optional[int] = None, @@ -3431,6 +3440,8 @@ def remove_liquidity( wallet: The wallet used to sign the extrinsic (must be unlocked). netuid: The UID of the target subnet for which the call is being initiated. position_id: The id of the position record in the pool. + hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to + `None`. wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True. wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False. period: The number of blocks during which the transaction will remain valid after it's submitted. If @@ -3452,6 +3463,7 @@ def remove_liquidity( wallet=wallet, netuid=netuid, position_id=position_id, + hotkey=hotkey, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, period=period, From 0fccb08ee69540d0e858d14a538f11334c3e54b0 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 7 Jul 2025 14:24:45 -0700 Subject: [PATCH 3/3] fix unit tests --- tests/unit_tests/test_async_subtensor.py | 3 +++ tests/unit_tests/test_subtensor.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/unit_tests/test_async_subtensor.py b/tests/unit_tests/test_async_subtensor.py index 7e60be2ae0..283189e17e 100644 --- a/tests/unit_tests/test_async_subtensor.py +++ b/tests/unit_tests/test_async_subtensor.py @@ -3713,6 +3713,7 @@ async def test_add_liquidity(subtensor, fake_wallet, mocker): liquidity=Balance.from_tao(150), price_low=Balance.from_tao(180).rao, price_high=Balance.from_tao(130).rao, + hotkey=None, wait_for_inclusion=True, wait_for_finalization=False, period=None, @@ -3745,6 +3746,7 @@ async def test_modify_liquidity(subtensor, fake_wallet, mocker): netuid=netuid, position_id=position_id, liquidity_delta=Balance.from_tao(150), + hotkey=None, wait_for_inclusion=True, wait_for_finalization=False, period=None, @@ -3775,6 +3777,7 @@ async def test_remove_liquidity(subtensor, fake_wallet, mocker): wallet=fake_wallet, netuid=netuid, position_id=position_id, + hotkey=None, wait_for_inclusion=True, wait_for_finalization=False, period=None, diff --git a/tests/unit_tests/test_subtensor.py b/tests/unit_tests/test_subtensor.py index d580a9f109..f0617d5f7a 100644 --- a/tests/unit_tests/test_subtensor.py +++ b/tests/unit_tests/test_subtensor.py @@ -4043,6 +4043,7 @@ def test_add_liquidity(subtensor, fake_wallet, mocker): liquidity=Balance.from_tao(150), price_low=Balance.from_tao(180).rao, price_high=Balance.from_tao(130).rao, + hotkey=None, wait_for_inclusion=True, wait_for_finalization=False, period=None, @@ -4074,6 +4075,7 @@ def test_modify_liquidity(subtensor, fake_wallet, mocker): netuid=netuid, position_id=position_id, liquidity_delta=Balance.from_tao(150), + hotkey=None, wait_for_inclusion=True, wait_for_finalization=False, period=None, @@ -4103,6 +4105,7 @@ def test_remove_liquidity(subtensor, fake_wallet, mocker): wallet=fake_wallet, netuid=netuid, position_id=position_id, + hotkey=None, wait_for_inclusion=True, wait_for_finalization=False, period=None,