Skip to content

Commit ccf46a8

Browse files
authored
Merge pull request #2949 from opentensor/feat/roman/extend-liquidity-logic
Extend `liquidity` logic
2 parents ab0de6a + 0fccb08 commit ccf46a8

File tree

6 files changed

+48
-6
lines changed

6 files changed

+48
-6
lines changed

bittensor/core/async_subtensor.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,6 +3785,7 @@ async def add_liquidity(
37853785
liquidity: Balance,
37863786
price_low: Balance,
37873787
price_high: Balance,
3788+
hotkey: Optional[str] = None,
37883789
wait_for_inclusion: bool = True,
37893790
wait_for_finalization: bool = False,
37903791
period: Optional[int] = None,
@@ -3798,6 +3799,8 @@ async def add_liquidity(
37983799
liquidity: The amount of liquidity to be added.
37993800
price_low: The lower bound of the price tick range. In TAO.
38003801
price_high: The upper bound of the price tick range. In TAO.
3802+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to
3803+
`None`.
38013804
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
38023805
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
38033806
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(
38193822
liquidity=liquidity,
38203823
price_low=price_low,
38213824
price_high=price_high,
3825+
hotkey=hotkey,
38223826
wait_for_inclusion=wait_for_inclusion,
38233827
wait_for_finalization=wait_for_finalization,
38243828
period=period,
@@ -3992,6 +3996,7 @@ async def modify_liquidity(
39923996
netuid: int,
39933997
position_id: int,
39943998
liquidity_delta: Balance,
3999+
hotkey: Optional[str] = None,
39954000
wait_for_inclusion: bool = True,
39964001
wait_for_finalization: bool = False,
39974002
period: Optional[int] = None,
@@ -4003,6 +4008,8 @@ async def modify_liquidity(
40034008
netuid: The UID of the target subnet for which the call is being initiated.
40044009
position_id: The id of the position record in the pool.
40054010
liquidity_delta: The amount of liquidity to be added or removed (add if positive or remove if negative).
4011+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to
4012+
`None`.
40064013
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
40074014
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
40084015
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(
40494056
netuid=netuid,
40504057
position_id=position_id,
40514058
liquidity_delta=liquidity_delta,
4059+
hotkey=hotkey,
40524060
wait_for_inclusion=wait_for_inclusion,
40534061
wait_for_finalization=wait_for_finalization,
40544062
period=period,
@@ -4200,6 +4208,7 @@ async def remove_liquidity(
42004208
wallet: "Wallet",
42014209
netuid: int,
42024210
position_id: int,
4211+
hotkey: Optional[str] = None,
42034212
wait_for_inclusion: bool = True,
42044213
wait_for_finalization: bool = False,
42054214
period: Optional[int] = None,
@@ -4210,6 +4219,8 @@ async def remove_liquidity(
42104219
wallet: The wallet used to sign the extrinsic (must be unlocked).
42114220
netuid: The UID of the target subnet for which the call is being initiated.
42124221
position_id: The id of the position record in the pool.
4222+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to
4223+
`None`.
42134224
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
42144225
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
42154226
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(
42314242
wallet=wallet,
42324243
netuid=netuid,
42334244
position_id=position_id,
4245+
hotkey=hotkey,
42344246
wait_for_inclusion=wait_for_inclusion,
42354247
wait_for_finalization=wait_for_finalization,
42364248
period=period,

bittensor/core/extrinsics/asyncex/liquidity.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ async def add_liquidity_extrinsic(
1717
liquidity: Balance,
1818
price_low: Balance,
1919
price_high: Balance,
20+
hotkey: Optional[str] = None,
2021
wait_for_inclusion: bool = True,
2122
wait_for_finalization: bool = False,
2223
period: Optional[int] = None,
@@ -31,6 +32,7 @@ async def add_liquidity_extrinsic(
3132
liquidity: The amount of liquidity to be added.
3233
price_low: The lower bound of the price tick range.
3334
price_high: The upper bound of the price tick range.
35+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`.
3436
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
3537
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
3638
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(
5658
call_module="Swap",
5759
call_function="add_liquidity",
5860
call_params={
59-
"hotkey": wallet.hotkey.ss58_address,
61+
"hotkey": hotkey or wallet.hotkey.ss58_address,
6062
"netuid": netuid,
6163
"tick_low": tick_low,
6264
"tick_high": tick_high,
@@ -80,6 +82,7 @@ async def modify_liquidity_extrinsic(
8082
netuid: int,
8183
position_id: int,
8284
liquidity_delta: Balance,
85+
hotkey: Optional[str] = None,
8386
wait_for_inclusion: bool = True,
8487
wait_for_finalization: bool = False,
8588
period: Optional[int] = None,
@@ -92,6 +95,7 @@ async def modify_liquidity_extrinsic(
9295
netuid: The UID of the target subnet for which the call is being initiated.
9396
position_id: The id of the position record in the pool.
9497
liquidity_delta: The amount of liquidity to be added or removed (add if positive or remove if negative).
98+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`.
9599
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
96100
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
97101
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(
114118
call_module="Swap",
115119
call_function="modify_position",
116120
call_params={
117-
"hotkey": wallet.hotkey.ss58_address,
121+
"hotkey": hotkey or wallet.hotkey.ss58_address,
118122
"netuid": netuid,
119123
"position_id": position_id,
120124
"liquidity_delta": liquidity_delta.rao,
@@ -136,6 +140,7 @@ async def remove_liquidity_extrinsic(
136140
wallet: "Wallet",
137141
netuid: int,
138142
position_id: int,
143+
hotkey: Optional[str] = None,
139144
wait_for_inclusion: bool = True,
140145
wait_for_finalization: bool = False,
141146
period: Optional[int] = None,
@@ -147,6 +152,7 @@ async def remove_liquidity_extrinsic(
147152
wallet: The wallet used to sign the extrinsic (must be unlocked).
148153
netuid: The UID of the target subnet for which the call is being initiated.
149154
position_id: The id of the position record in the pool.
155+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`.
150156
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
151157
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
152158
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(
169175
call_module="Swap",
170176
call_function="remove_liquidity",
171177
call_params={
172-
"hotkey": wallet.hotkey.ss58_address,
178+
"hotkey": hotkey or wallet.hotkey.ss58_address,
173179
"netuid": netuid,
174180
"position_id": position_id,
175181
},

bittensor/core/extrinsics/liquidity.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def add_liquidity_extrinsic(
1717
liquidity: Balance,
1818
price_low: Balance,
1919
price_high: Balance,
20+
hotkey: Optional[str] = None,
2021
wait_for_inclusion: bool = True,
2122
wait_for_finalization: bool = False,
2223
period: Optional[int] = None,
@@ -31,6 +32,7 @@ def add_liquidity_extrinsic(
3132
liquidity: The amount of liquidity to be added.
3233
price_low: The lower bound of the price tick range.
3334
price_high: The upper bound of the price tick range.
35+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`.
3436
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
3537
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
3638
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(
5658
call_module="Swap",
5759
call_function="add_liquidity",
5860
call_params={
59-
"hotkey": wallet.hotkey.ss58_address,
61+
"hotkey": hotkey or wallet.hotkey.ss58_address,
6062
"netuid": netuid,
6163
"tick_low": tick_low,
6264
"tick_high": tick_high,
@@ -80,6 +82,7 @@ def modify_liquidity_extrinsic(
8082
netuid: int,
8183
position_id: int,
8284
liquidity_delta: Balance,
85+
hotkey: Optional[str] = None,
8386
wait_for_inclusion: bool = True,
8487
wait_for_finalization: bool = False,
8588
period: Optional[int] = None,
@@ -92,6 +95,7 @@ def modify_liquidity_extrinsic(
9295
netuid: The UID of the target subnet for which the call is being initiated.
9396
position_id: The id of the position record in the pool.
9497
liquidity_delta: The amount of liquidity to be added or removed (add if positive or remove if negative).
98+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`.
9599
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
96100
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
97101
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(
114118
call_module="Swap",
115119
call_function="modify_position",
116120
call_params={
117-
"hotkey": wallet.hotkey.ss58_address,
121+
"hotkey": hotkey or wallet.hotkey.ss58_address,
118122
"netuid": netuid,
119123
"position_id": position_id,
120124
"liquidity_delta": liquidity_delta.rao,
@@ -136,6 +140,7 @@ def remove_liquidity_extrinsic(
136140
wallet: "Wallet",
137141
netuid: int,
138142
position_id: int,
143+
hotkey: Optional[str] = None,
139144
wait_for_inclusion: bool = True,
140145
wait_for_finalization: bool = False,
141146
period: Optional[int] = None,
@@ -147,6 +152,7 @@ def remove_liquidity_extrinsic(
147152
wallet: The wallet used to sign the extrinsic (must be unlocked).
148153
netuid: The UID of the target subnet for which the call is being initiated.
149154
position_id: The id of the position record in the pool.
155+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to `None`.
150156
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
151157
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
152158
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(
169175
call_module="Swap",
170176
call_function="remove_liquidity",
171177
call_params={
172-
"hotkey": wallet.hotkey.ss58_address,
178+
"hotkey": hotkey or wallet.hotkey.ss58_address,
173179
"netuid": netuid,
174180
"position_id": position_id,
175181
},

bittensor/core/subtensor.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,7 @@ def add_liquidity(
30023002
liquidity: Balance,
30033003
price_low: Balance,
30043004
price_high: Balance,
3005+
hotkey: Optional[str] = None,
30053006
wait_for_inclusion: bool = True,
30063007
wait_for_finalization: bool = False,
30073008
period: Optional[int] = None,
@@ -3015,6 +3016,8 @@ def add_liquidity(
30153016
liquidity: The amount of liquidity to be added.
30163017
price_low: The lower bound of the price tick range. In TAO.
30173018
price_high: The upper bound of the price tick range. In TAO.
3019+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to
3020+
`None`.
30183021
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
30193022
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
30203023
period: The number of blocks during which the transaction will remain valid after it's submitted. If
@@ -3036,6 +3039,7 @@ def add_liquidity(
30363039
liquidity=liquidity,
30373040
price_low=price_low,
30383041
price_high=price_high,
3042+
hotkey=hotkey,
30393043
wait_for_inclusion=wait_for_inclusion,
30403044
wait_for_finalization=wait_for_finalization,
30413045
period=period,
@@ -3214,6 +3218,7 @@ def modify_liquidity(
32143218
netuid: int,
32153219
position_id: int,
32163220
liquidity_delta: Balance,
3221+
hotkey: Optional[str] = None,
32173222
wait_for_inclusion: bool = True,
32183223
wait_for_finalization: bool = False,
32193224
period: Optional[int] = None,
@@ -3225,6 +3230,8 @@ def modify_liquidity(
32253230
netuid: The UID of the target subnet for which the call is being initiated.
32263231
position_id: The id of the position record in the pool.
32273232
liquidity_delta: The amount of liquidity to be added or removed (add if positive or remove if negative).
3233+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to
3234+
`None`.
32283235
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
32293236
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
32303237
period: The number of blocks during which the transaction will remain valid after it's submitted. If
@@ -3271,6 +3278,7 @@ def modify_liquidity(
32713278
netuid=netuid,
32723279
position_id=position_id,
32733280
liquidity_delta=liquidity_delta,
3281+
hotkey=hotkey,
32743282
wait_for_inclusion=wait_for_inclusion,
32753283
wait_for_finalization=wait_for_finalization,
32763284
period=period,
@@ -3421,6 +3429,7 @@ def remove_liquidity(
34213429
wallet: "Wallet",
34223430
netuid: int,
34233431
position_id: int,
3432+
hotkey: Optional[str] = None,
34243433
wait_for_inclusion: bool = True,
34253434
wait_for_finalization: bool = False,
34263435
period: Optional[int] = None,
@@ -3431,6 +3440,8 @@ def remove_liquidity(
34313440
wallet: The wallet used to sign the extrinsic (must be unlocked).
34323441
netuid: The UID of the target subnet for which the call is being initiated.
34333442
position_id: The id of the position record in the pool.
3443+
hotkey: The hotkey with staked TAO in Alpha. If not passed then the wallet hotkey is used. Defaults to
3444+
`None`.
34343445
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block. Defaults to True.
34353446
wait_for_finalization: Whether to wait for finalization of the extrinsic. Defaults to False.
34363447
period: The number of blocks during which the transaction will remain valid after it's submitted. If
@@ -3452,6 +3463,7 @@ def remove_liquidity(
34523463
wallet=wallet,
34533464
netuid=netuid,
34543465
position_id=position_id,
3466+
hotkey=hotkey,
34553467
wait_for_inclusion=wait_for_inclusion,
34563468
wait_for_finalization=wait_for_finalization,
34573469
period=period,

tests/unit_tests/test_async_subtensor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,6 +3713,7 @@ async def test_add_liquidity(subtensor, fake_wallet, mocker):
37133713
liquidity=Balance.from_tao(150),
37143714
price_low=Balance.from_tao(180).rao,
37153715
price_high=Balance.from_tao(130).rao,
3716+
hotkey=None,
37163717
wait_for_inclusion=True,
37173718
wait_for_finalization=False,
37183719
period=None,
@@ -3745,6 +3746,7 @@ async def test_modify_liquidity(subtensor, fake_wallet, mocker):
37453746
netuid=netuid,
37463747
position_id=position_id,
37473748
liquidity_delta=Balance.from_tao(150),
3749+
hotkey=None,
37483750
wait_for_inclusion=True,
37493751
wait_for_finalization=False,
37503752
period=None,
@@ -3775,6 +3777,7 @@ async def test_remove_liquidity(subtensor, fake_wallet, mocker):
37753777
wallet=fake_wallet,
37763778
netuid=netuid,
37773779
position_id=position_id,
3780+
hotkey=None,
37783781
wait_for_inclusion=True,
37793782
wait_for_finalization=False,
37803783
period=None,

tests/unit_tests/test_subtensor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4043,6 +4043,7 @@ def test_add_liquidity(subtensor, fake_wallet, mocker):
40434043
liquidity=Balance.from_tao(150),
40444044
price_low=Balance.from_tao(180).rao,
40454045
price_high=Balance.from_tao(130).rao,
4046+
hotkey=None,
40464047
wait_for_inclusion=True,
40474048
wait_for_finalization=False,
40484049
period=None,
@@ -4074,6 +4075,7 @@ def test_modify_liquidity(subtensor, fake_wallet, mocker):
40744075
netuid=netuid,
40754076
position_id=position_id,
40764077
liquidity_delta=Balance.from_tao(150),
4078+
hotkey=None,
40774079
wait_for_inclusion=True,
40784080
wait_for_finalization=False,
40794081
period=None,
@@ -4103,6 +4105,7 @@ def test_remove_liquidity(subtensor, fake_wallet, mocker):
41034105
wallet=fake_wallet,
41044106
netuid=netuid,
41054107
position_id=position_id,
4108+
hotkey=None,
41064109
wait_for_inclusion=True,
41074110
wait_for_finalization=False,
41084111
period=None,

0 commit comments

Comments
 (0)