From bb4e5e69e4e52f9888ff3575feeb7948dd76c4d4 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 8 Mar 2023 18:00:36 -0500 Subject: [PATCH] remove fee call --- bittensor/_subtensor/extrinsics/delegation.py | 53 ++--------------- bittensor/_subtensor/extrinsics/staking.py | 58 +++---------------- bittensor/_subtensor/extrinsics/transfer.py | 28 ++------- bittensor/_subtensor/extrinsics/unstaking.py | 48 ++------------- .../bittensor_tests/test_subtensor.py | 5 -- 5 files changed, 19 insertions(+), 173 deletions(-) diff --git a/bittensor/_subtensor/extrinsics/delegation.py b/bittensor/_subtensor/extrinsics/delegation.py index 1dce95daa2..95c0b610ac 100644 --- a/bittensor/_subtensor/extrinsics/delegation.py +++ b/bittensor/_subtensor/extrinsics/delegation.py @@ -205,34 +205,14 @@ def delegate_extrinsic( else: staking_balance = staking_balance - # Estimate transfer fee. - staking_fee = None # To be filled. - with bittensor.__console__.status(":satellite: Estimating Delegation Fees..."): - with subtensor.substrate as substrate: - call = substrate.compose_call( - call_module='SubtensorModule', - call_function='add_stake', - call_params={ - 'hotkey': delegate_ss58, - 'amount_staked': staking_balance.rao - } - ) - payment_info = substrate.get_payment_info(call = call, keypair = wallet.coldkey) - if payment_info: - staking_fee = bittensor.Balance.from_rao(payment_info['partialFee']) - bittensor.__console__.print("[green]Estimated Fee: {}[/green]".format( staking_fee )) - else: - staking_fee = bittensor.Balance.from_tao( 0.2 ) - bittensor.__console__.print(":cross_mark: [red]Failed[/red]: could not estimate delegation fee, assuming base fee of 0.2") - # Check enough balance to stake. - if staking_balance + staking_fee > my_prev_coldkey_balance: - bittensor.__console__.print(":cross_mark: [red]Not enough balance[/red]:[bold white]\n balance:{}\n amount: {}\n fee: {}\n coldkey: {}[/bold white]".format(my_prev_coldkey_balance, staking_balance, staking_fee, wallet.name)) + if staking_balance > my_prev_coldkey_balance: + bittensor.__console__.print(":cross_mark: [red]Not enough balance[/red]:[bold white]\n balance:{}\n amount: {}\n coldkey: {}[/bold white]".format(my_prev_coldkey_balance, staking_balance, wallet.name)) return False # Ask before moving on. if prompt: - if not Confirm.ask("Do you want to delegate:[bold white]\n amount: {}\n to: {}\n fee: {}\n take: {}\n owner: {}[/bold white]".format( staking_balance, delegate_ss58, staking_fee, delegate_take, delegate_owner) ): + if not Confirm.ask("Do you want to delegate:[bold white]\n amount: {}\n to: {}\n take: {}\n owner: {}[/bold white]".format( staking_balance, delegate_ss58, delegate_take, delegate_owner) ): return False try: @@ -332,39 +312,14 @@ def undelegate_extrinsic( else: staking_balance = amount - # Estimate transfer fee. - staking_fee = None # To be filled. - with bittensor.__console__.status(":satellite: Estimating Delegation Fees..."): - with subtensor.substrate as substrate: - call = substrate.compose_call( - call_module='SubtensorModule', - call_function='remove_stake', - call_params={ - 'hotkey': delegate_ss58, - 'amount_unstaked': staking_balance.rao - } - ) - payment_info = substrate.get_payment_info(call = call, keypair = wallet.coldkey) - if payment_info: - staking_fee = bittensor.Balance.from_rao(payment_info['partialFee']) - bittensor.__console__.print("[green]Estimated Fee: {}[/green]".format( staking_fee )) - else: - staking_fee = bittensor.Balance.from_tao( 0.2 ) - bittensor.__console__.print(":cross_mark: [red]Failed[/red]: could not estimate delegation fee, assuming base fee of 0.2") - # Check enough stake to unstake. if staking_balance > my_prev_delegated_stake: bittensor.__console__.print(":cross_mark: [red]Not enough stake[/red]:[bold white]\n stake:{}\n amount: {}\n coldkey: {}[/bold white]".format(my_prev_delegated_stake, staking_balance, wallet.name)) return False - - # Check enough balance to unstake. - if my_prev_coldkey_balance < staking_fee: - bittensor.__console__.print(":cross_mark: [red]Not enough balance[/red]:[bold white]\n balance:{}\n amount: {}\n fee: {}\n coldkey: {}[/bold white]".format(my_prev_coldkey_balance, staking_balance, staking_fee, wallet.name)) - return False # Ask before moving on. if prompt: - if not Confirm.ask("Do you want to un-delegate:[bold white]\n amount: {}\n to: {}\n fee: {}\n take: {}\n owner: {}[/bold white]".format( staking_balance, delegate_ss58, staking_fee, delegate_take, delegate_owner) ): + if not Confirm.ask("Do you want to un-delegate:[bold white]\n amount: {}\n to: {}\n take: {}\n owner: {}[/bold white]".format( staking_balance, delegate_ss58, delegate_take, delegate_owner) ): return False try: diff --git a/bittensor/_subtensor/extrinsics/staking.py b/bittensor/_subtensor/extrinsics/staking.py index 94cb93c963..37caab6afa 100644 --- a/bittensor/_subtensor/extrinsics/staking.py +++ b/bittensor/_subtensor/extrinsics/staking.py @@ -101,39 +101,19 @@ def add_stake_extrinsic( else: staking_balance = staking_balance - # Estimate transfer fee. - staking_fee = None # To be filled. - with bittensor.__console__.status(":satellite: Estimating Staking Fees..."): - with subtensor.substrate as substrate: - call = substrate.compose_call( - call_module='SubtensorModule', - call_function='add_stake', - call_params={ - 'hotkey': hotkey_ss58, - 'amount_staked': staking_balance.rao - } - ) - payment_info = substrate.get_payment_info(call = call, keypair = wallet.coldkeypub) - if payment_info: - staking_fee = bittensor.Balance.from_rao(payment_info['partialFee']) - bittensor.__console__.print("[green]Estimated Fee: {}[/green]".format( staking_fee )) - else: - staking_fee = bittensor.Balance.from_tao( 0.2 ) - bittensor.__console__.print(":cross_mark: [red]Failed[/red]: could not estimate staking fee, assuming base fee of 0.2") - # Check enough to stake. - if staking_balance > old_balance + staking_fee: - bittensor.__console__.print(":cross_mark: [red]Not enough stake[/red]:[bold white]\n balance:{}\n amount: {}\n fee: {}\n coldkey: {}[/bold white]".format(old_balance, staking_balance, staking_fee, wallet.name)) + if staking_balance > old_balance: + bittensor.__console__.print(":cross_mark: [red]Not enough stake[/red]:[bold white]\n balance:{}\n amount: {}\n coldkey: {}[/bold white]".format(old_balance, staking_balance, wallet.name)) return False # Ask before moving on. if prompt: if not own_hotkey: # We are delegating. - if not Confirm.ask("Do you want to delegate:[bold white]\n amount: {}\n to: {}\n fee: {}\n take: {}\n owner: {}[/bold white]".format( staking_balance, wallet.hotkey_str, staking_fee, hotkey_take, hotkey_owner) ): + if not Confirm.ask("Do you want to delegate:[bold white]\n amount: {}\n to: {}\n take: {}\n owner: {}[/bold white]".format( staking_balance, wallet.hotkey_str, hotkey_take, hotkey_owner) ): return False else: - if not Confirm.ask("Do you want to stake:[bold white]\n amount: {}\n to: {}\n fee: {}[/bold white]".format( staking_balance, wallet.hotkey_str, staking_fee) ): + if not Confirm.ask("Do you want to stake:[bold white]\n amount: {}\n to: {}[/bold white]".format( staking_balance, wallet.hotkey_str) ): return False try: @@ -272,38 +252,14 @@ def add_stake_multiple_extrinsic ( assert isinstance(amount, bittensor.Balance) staking_balance = amount - # Estimate staking fee. - stake_fee = None # To be filled. - with bittensor.__console__.status(":satellite: Estimating Staking Fees..."): - with subtensor.substrate as substrate: - call = substrate.compose_call( - call_module='SubtensorModule', - call_function='add_stake', - call_params={ - 'hotkey': hotkey_ss58, - 'amount_staked': staking_balance.rao - } - ) - payment_info = substrate.get_payment_info(call = call, keypair = wallet.coldkey) - if payment_info: - stake_fee = bittensor.Balance.from_rao(payment_info['partialFee']) - bittensor.__console__.print("[green]Estimated Fee: {}[/green]".format( stake_fee )) - else: - stake_fee = bittensor.Balance.from_tao( 0.2 ) - bittensor.__console__.print(":cross_mark: [red]Failed[/red]: could not estimate staking fee, assuming base fee of 0.2") - # Check enough to stake - if staking_all: - staking_balance -= stake_fee - max(staking_balance, bittensor.Balance.from_tao(0)) - - if staking_balance > old_balance - stake_fee: + if staking_balance > old_balance: bittensor.__console__.print(":cross_mark: [red]Not enough balance[/red]: [green]{}[/green] to stake: [blue]{}[/blue] from coldkey: [white]{}[/white]".format(old_balance, staking_balance, wallet.name)) continue # Ask before moving on. if prompt: - if not Confirm.ask("Do you want to stake:\n[bold white] amount: {}\n hotkey: {}\n fee: {}[/bold white ]?".format( staking_balance, wallet.hotkey_str, stake_fee) ): + if not Confirm.ask("Do you want to stake:\n[bold white] amount: {}\n hotkey: {}[/bold white ]?".format( staking_balance, wallet.hotkey_str) ): continue try: @@ -320,7 +276,7 @@ def add_stake_multiple_extrinsic ( # We only wait here if we expect finalization. if not wait_for_finalization and not wait_for_inclusion: bittensor.__console__.print(":white_heavy_check_mark: [green]Sent[/green]") - old_balance -= staking_balance + stake_fee + old_balance -= staking_balance successful_stakes += 1 if staking_all: # If staked all, no need to continue diff --git a/bittensor/_subtensor/extrinsics/transfer.py b/bittensor/_subtensor/extrinsics/transfer.py index 6e355d29b5..4c42f02862 100644 --- a/bittensor/_subtensor/extrinsics/transfer.py +++ b/bittensor/_subtensor/extrinsics/transfer.py @@ -75,34 +75,14 @@ def transfer_extrinsic( # Check balance. with bittensor.__console__.status(":satellite: Checking Balance..."): account_balance = subtensor.get_balance( wallet.coldkey.ss58_address ) - - # Estimate transfer fee. - with bittensor.__console__.status(":satellite: Estimating Transfer Fees..."): - with subtensor.substrate as substrate: - call = substrate.compose_call( - call_module='Balances', - call_function='transfer', - call_params={ - 'dest': dest, - 'value': transfer_balance.rao - } - ) - payment_info = substrate.get_payment_info(call = call, keypair = wallet.coldkey) - transfer_fee = "N/A" - if payment_info: - transfer_fee = bittensor.Balance.from_rao(payment_info['partialFee']) - bittensor.__console__.print("[green]Estimated Fee: {}[/green]".format( transfer_fee )) - else: - bittensor.__console__.print(":cross_mark: [red]Failed[/red]: could not estimate transfer fee, assuming base fee of 0.2") - transfer_fee = bittensor.Balance.from_tao( 0.2 ) - - if account_balance < transfer_balance + transfer_fee: - bittensor.__console__.print(":cross_mark: [red]Not enough balance[/red]:[bold white]\n balance: {}\n amount: {} fee: {}[/bold white]".format( account_balance, transfer_balance, transfer_fee )) + + if account_balance < transfer_balance: + bittensor.__console__.print(":cross_mark: [red]Not enough balance[/red]:[bold white]\n balance: {}\n amount: {}[/bold white]".format( account_balance, transfer_balance )) return False # Ask before moving on. if prompt: - if not Confirm.ask("Do you want to transfer:[bold white]\n amount: {}\n from: {}:{}\n to: {}\n for fee: {}[/bold white]".format( transfer_balance, wallet.name, wallet.coldkey.ss58_address, dest, transfer_fee )): + if not Confirm.ask("Do you want to transfer:[bold white]\n amount: {}\n from: {}:{}\n to: {}[/bold white]".format( transfer_balance, wallet.name, wallet.coldkey.ss58_address, dest )): return False with bittensor.__console__.status(":satellite: Transferring..."): diff --git a/bittensor/_subtensor/extrinsics/unstaking.py b/bittensor/_subtensor/extrinsics/unstaking.py index 8f556026ae..447c85baf4 100644 --- a/bittensor/_subtensor/extrinsics/unstaking.py +++ b/bittensor/_subtensor/extrinsics/unstaking.py @@ -138,30 +138,10 @@ def unstake_extrinsic ( if unstaking_balance > stake_on_uid: bittensor.__console__.print(":cross_mark: [red]Not enough stake[/red]: [green]{}[/green] to unstake: [blue]{}[/blue] from hotkey: [white]{}[/white]".format(stake_on_uid, unstaking_balance, wallet.hotkey_str)) return False - - # Estimate unstaking fee. - unstake_fee = None # To be filled. - with bittensor.__console__.status(":satellite: Estimating Staking Fees..."): - with subtensor.substrate as substrate: - call = substrate.compose_call( - call_module='SubtensorModule', - call_function='remove_stake', - call_params={ - 'hotkey': hotkey_ss58, - 'amount_unstaked': unstaking_balance.rao - } - ) - payment_info = substrate.get_payment_info(call = call, keypair = wallet.coldkey) - if payment_info: - unstake_fee = bittensor.Balance.from_rao(payment_info['partialFee']) - bittensor.__console__.print("[green]Estimated Fee: {}[/green]".format( unstake_fee )) - else: - unstake_fee = bittensor.Balance.from_tao( 0.2 ) - bittensor.__console__.print(":cross_mark: [red]Failed[/red]: could not estimate staking fee, assuming base fee of 0.2") - + # Ask before moving on. if prompt: - if not Confirm.ask("Do you want to unstake:\n[bold white] amount: {}\n hotkey: {}\n fee: {}[/bold white ]?".format( unstaking_balance, wallet.hotkey_str, unstake_fee) ): + if not Confirm.ask("Do you want to unstake:\n[bold white] amount: {}\n hotkey: {}[/bold white ]?".format( unstaking_balance, wallet.hotkey_str) ): return False @@ -280,30 +260,10 @@ def unstake_multiple_extrinsic ( if unstaking_balance > stake_on_uid: bittensor.__console__.print(":cross_mark: [red]Not enough stake[/red]: [green]{}[/green] to unstake: [blue]{}[/blue] from hotkey: [white]{}[/white]".format(stake_on_uid, unstaking_balance, wallet.hotkey_str)) continue - - # Estimate unstaking fee. - unstake_fee = None # To be filled. - with bittensor.__console__.status(":satellite: Estimating Staking Fees..."): - with subtensor.substrate as substrate: - call = substrate.compose_call( - call_module='SubtensorModule', - call_function='remove_stake', - call_params={ - 'hotkey': hotkey_ss58, - 'amount_unstaked': unstaking_balance.rao - } - ) - payment_info = substrate.get_payment_info(call = call, keypair = wallet.coldkey) - if payment_info: - unstake_fee = bittensor.Balance.from_rao(payment_info['partialFee']) - bittensor.__console__.print("[green]Estimated Fee: {}[/green]".format( unstake_fee )) - else: - unstake_fee = bittensor.Balance.from_tao( 0.2 ) - bittensor.__console__.print(":cross_mark: [red]Failed[/red]: could not estimate staking fee, assuming base fee of 0.2") - + # Ask before moving on. if prompt: - if not Confirm.ask("Do you want to unstake:\n[bold white] amount: {}\n hotkey: {}\n fee: {}[/bold white ]?".format( unstaking_balance, wallet.hotkey_str, unstake_fee) ): + if not Confirm.ask("Do you want to unstake:\n[bold white] amount: {}\n hotkey: {}[/bold white ]?".format( unstaking_balance, wallet.hotkey_str) ): continue try: diff --git a/tests/unit_tests/bittensor_tests/test_subtensor.py b/tests/unit_tests/bittensor_tests/test_subtensor.py index 094d214c14..13771f30d6 100644 --- a/tests/unit_tests/bittensor_tests/test_subtensor.py +++ b/tests/unit_tests/bittensor_tests/test_subtensor.py @@ -161,11 +161,6 @@ def test_stake_multiple(self): substrate=MagicMock( __enter__=MagicMock( return_value=MagicMock( - get_payment_info=MagicMock( - return_value={ - 'partialFee': int(0.125 * 10**9) # 0.125 TAO - } - ), compose_call=mock_compose_call, ), ),