Skip to content

Commit d59355f

Browse files
author
Roman
committed
update async extrinsics
1 parent 7bb17d2 commit d59355f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

bittensor/core/extrinsics/asyncex/staking.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,30 @@ async def add_stake_extrinsic(
120120

121121
if safe_staking:
122122
pool = await subtensor.subnet(netuid=netuid)
123-
base_price = pool.price.rao
123+
received_amount, _ = pool.tao_to_alpha_with_slippage(staking_balance)
124+
base_price = received_amount.rao / staking_balance.rao
124125
price_with_tolerance = base_price * (1 + rate_tolerance)
125-
call_params.update(
126-
{
127-
"limit_price": price_with_tolerance,
128-
"allow_partial": allow_partial_stake,
129-
}
130-
)
131-
call_function = "add_stake_limit"
132126

133127
# For logging
134128
base_rate = pool.price.tao
135-
rate_with_tolerance = base_rate * (1 + rate_tolerance)
129+
136130
logging.info(
137131
f":satellite: [magenta]Safe Staking to:[/magenta] "
138132
f"[blue]netuid: [green]{netuid}[/green], amount: [green]{staking_balance}[/green], "
139133
f"tolerance percentage: [green]{rate_tolerance * 100}%[/green], "
140-
f"price limit: [green]{rate_with_tolerance}[/green], "
134+
f"price limit: [green]{price_with_tolerance}[/green], "
141135
f"original price: [green]{base_rate}[/green], "
142136
f"with partial stake: [green]{allow_partial_stake}[/green] "
143137
f"on [blue]{subtensor.network}[/blue][/magenta]...[/magenta]"
144138
)
139+
140+
call_params.update(
141+
{
142+
"limit_price": price_with_tolerance,
143+
"allow_partial": allow_partial_stake,
144+
}
145+
)
146+
call_function = "add_stake_limit"
145147
else:
146148
logging.info(
147149
f":satellite: [magenta]Staking to:[/magenta] "

bittensor/core/extrinsics/asyncex/unstaking.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ async def unstake_extrinsic(
107107
}
108108
if safe_staking:
109109
pool = await subtensor.subnet(netuid=netuid)
110-
base_price = pool.price.rao
110+
received_amount, _ = pool.alpha_to_tao_with_slippage(unstaking_balance)
111+
base_price = unstaking_balance.rao / received_amount.rao
111112
price_with_tolerance = base_price * (1 - rate_tolerance)
112113

113114
# For logging
114115
base_rate = pool.price.tao
115-
rate_with_tolerance = base_rate * (1 - rate_tolerance)
116116

117117
logging.info(
118118
f":satellite: [magenta]Safe Unstaking from:[/magenta] "
119119
f"netuid: [green]{netuid}[/green], amount: [green]{unstaking_balance}[/green], "
120120
f"tolerance percentage: [green]{rate_tolerance * 100}%[/green], "
121-
f"price limit: [green]{rate_with_tolerance}[/green], "
121+
f"price limit: [green]{price_with_tolerance}[/green], "
122122
f"original price: [green]{base_rate}[/green], "
123123
f"with partial unstake: [green]{allow_partial_stake}[/green] "
124124
f"on [blue]{subtensor.network}[/blue][magenta]...[/magenta]"

0 commit comments

Comments
 (0)