bittensor.utils.balance#

Attributes#

Classes#

Balance

Represents the bittensor balance of the wallet, stored as rao (int).

FixedPoint

Represents a fixed point U64F64 number.

Functions#

check_and_convert_to_balance(amount)

Helper function to check and convert the amount type to a Balance object.

fixed_to_float(fixed[, frac_bits, total_bits])

rao(amount)

Helper function to create a Balance object from an int (Rao)

tao(amount)

Helper function to create a Balance object from a float (Tao)

Module Contents#

class bittensor.utils.balance.Balance(balance)#

Represents the bittensor balance of the wallet, stored as rao (int). This class provides a way to interact with balances in two different units: rao and tao. It provides methods to convert between these units, as well as to perform arithmetic and comparison operations.

Variables:
  • unit (str) – A string representing the symbol for the tao unit.

  • rao_unit (str) – A string representing the symbol for the rao unit.

  • rao (int) – An integer that stores the balance in rao units.

  • tao (float) – A float property that gives the balance in tao units.

Parameters:

balance (Union[int, float])

Initialize a Balance object. If balance is an int, it’s assumed to be in rao. If balance is a float, it’s assumed to be in tao.

Parameters:

balance (Union[int, float]) – The initial balance, in either rao (if an int) or tao (if a float).

static from_float(amount, netuid=0)#

Given tao, return Balance() object with rao(int) and tao(float), where rao = int(tao*pow(10,9)) :param amount: The amount in tao. :type amount: float :param netuid: The subnet uid for set currency unit. Defaults to 0. :type netuid: int

Returns:

A Balance object representing the given amount.

Parameters:
static from_rao(amount, netuid=0)#

Given rao, return Balance object with rao(int) and tao(float), where rao = int(tao*pow(10,9))

Parameters:
  • amount (int) – The amount in rao.

  • netuid (int) – The subnet uid for set currency unit. Defaults to 0.

Returns:

A Balance object representing the given amount.

static from_tao(amount, netuid=0)#

Given tao, return Balance object with rao(int) and tao(float), where rao = int(tao*pow(10,9))

Parameters:
  • amount (float) – The amount in tao.

  • netuid (int) – The subnet uid for set currency unit. Defaults to 0.

Returns:

A Balance object representing the given amount.

static get_unit(netuid)#
Parameters:

netuid (int)

rao: int#
rao_unit: str#
set_unit(netuid)#
Parameters:

netuid (int)

property tao#
unit: str#
class bittensor.utils.balance.FixedPoint#

Bases: TypedDict

Represents a fixed point U64F64 number. Where bits is a U128 representation of the fixed point number.

This matches the type of the Alpha shares.

Initialize self. See help(type(self)) for accurate signature.

bits: int#
bittensor.utils.balance.check_and_convert_to_balance(amount)#

Helper function to check and convert the amount type to a Balance object. This is used to support backwards compatibility while also providing a deprecation notice.

Parameters:

amount (Union[float, int, Optional[Balance]])

Return type:

Balance

bittensor.utils.balance.fixed_to_float(fixed, frac_bits=64, total_bits=128)#
Parameters:
  • fixed (Union[FixedPoint, scalecodec.ScaleType])

  • frac_bits (int)

  • total_bits (int)

Return type:

float

bittensor.utils.balance.rao(amount)#

Helper function to create a Balance object from an int (Rao)

Parameters:

amount (int)

Return type:

Balance

bittensor.utils.balance.tao(amount)#

Helper function to create a Balance object from a float (Tao)

Parameters:

amount (float)

Return type:

Balance

bittensor.utils.balance.units = ['τ', 'α', 'β', 'γ', 'δ', 'ε', 'ζ', 'η', 'θ', 'ι', 'κ', 'λ', 'μ', 'ν', 'ξ', 'ο', 'π', 'ρ', 'σ',...#