Example #1
0
    def transfer( self, amount_tao: int, destination: str):
        r""" Transfers token of amount to dest.
            
        """
        self.wallet.assert_coldkey()
        self.wallet.assert_coldkeypub()
        self.subtensor.connect()
        transfer_balance = Balance.from_float( amount_tao )
        acount_balance = self.subtensor.get_balance(self.wallet.coldkey.ss58_address)
        if acount_balance < transfer_balance:
            logger.log('USER-CRITICAL', "Not enough balance (\u03C4{}) to transfer \u03C4{}".format(acount_balance, transfer_balance))
            quit()

        logger.log('USER-ACTION', "Requesting transfer of \u03C4{}, from coldkey: {} to destination: {}".format(transfer_balance.tao, self.wallet.coldkey.public_key, destination))
        logger.log('USER-INFO', "Waiting for finalization...")
        result = self.subtensor.transfer( 
            wallet = self.wallet, 
            dest = destination, 
            amount = transfer_balance,  
            wait_for_finalization = True, 
            timeout = bittensor.__blocktime__ * 5 
        )
        if result:
            logger.log('USER-SUCCESS', "Transfer finalized with amount: \u03C4{} to destination: {} from coldkey.pub: {}".format(transfer_balance.tao, destination, self.wallet.coldkey.public_key))
        else:
            logger.log('USER-CRITICAL', "Transfer failed")
Example #2
0
    def stake( self, amount_tao: int, uid: int ):
        r""" Stakes token of amount to hotkey uid.
        """
        self.wallet.assert_coldkey()
        self.wallet.assert_coldkeypub()
        self.subtensor.connect()
        staking_balance = Balance.from_float( amount_tao )
        account_balance = self.subtensor.get_balance( self.wallet.coldkey.ss58_address )
        if account_balance < staking_balance:
            logger.log('USER-CRITICAL', "Not enough balance (\u03C4{}) to stake \u03C4{}".format(account_balance, staking_balance))
            quit()

        neurons = self._associated_neurons()
        neuron = neurons.get_by_uid( uid )
        if not neuron:
            logger.log('USER-CRITICAL', "Neuron with uid: {} is not associated with coldkey.pub: {}".format( uid, self.wallet.coldkey.public_key ))
            quit()

        logger.log('USER-ACTION', "Adding stake of \u03C4{} from coldkey {} to hotkey {}".format( staking_balance.tao, self.wallet.coldkey.public_key, neuron.hotkey))
        logger.log('USER-INFO', "Waiting for finalization...")
        result = self.subtensor.add_stake ( 
            wallet = self.wallet, 
            amount = staking_balance, 
            hotkey_id = neuron.hotkey, 
            wait_for_finalization = True, 
            timeout = bittensor.__blocktime__ * 5
        )
        if result: 
            logger.log('USER-SUCCESS', "Staked: \u03C4{} to uid: {} from coldkey.pub: {}".format( staking_balance.tao, uid, self.wallet.coldkey.public_key ))
        else:
            logger.log('USER-CRITICAL', "Stake transaction failed")
Example #3
0
    def unstake( self, amount_tao: int, uid: int ):
        r""" Unstaked token of amount to from uid.
        """
        self.wallet.assert_coldkey()
        self.wallet.assert_coldkeypub()
        self.subtensor.connect()
        unstaking_balance = Balance.from_float( amount_tao )
        neurons = self._associated_neurons()
        neuron = neurons.get_by_uid( uid )
        if not neuron:
            logger.log('USER-CRITICAL', "Neuron with uid: {} is not associated with coldkey.pub: {}".format( uid, self.wallet.coldkey.public_key))
            quit()

        neuron.stake = self.subtensor.get_stake_for_uid(neuron.uid)
        if unstaking_balance > neuron.stake:
            logger.log('USER-CRITICAL', "Neuron with uid: {} does not have enough stake ({}) to be able to unstake {}".format( uid, neuron.stake, unstaking_balance))
            quit()

        logger.log('USER-ACTION', "Requesting unstake of \u03C4{} from hotkey: {} to coldkey: {}".format(unstaking_balance.tao, neuron.hotkey, self.wallet.coldkey.public_key))
        logger.log('USER-INFO', "Waiting for finalization...")
        result = self.subtensor.unstake (
            wallet = self.wallet, 
            amount = unstaking_balance, 
            hotkey_id = neuron.hotkey, 
            wait_for_finalization = True, 
            timeout = bittensor.__blocktime__ * 5
        )
        if result:
            logger.log('USER-SUCCESS', "Unstaked: \u03C4{} from uid:{} to coldkey.pub:{}".format(unstaking_balance.tao, neuron.uid, self.wallet.coldkey.public_key))
        else:
            logger.log('USER-CRITICAL', "Unstaking transaction failed")
Example #4
0
    def transfer(self):
        r""" Transfers token of amount to dest.
            
        """
        self.subtensor.connect()
        amount = Balance.from_float(self.config.amount)
        balance = self.subtensor.get_balance(self.wallet.coldkey.ss58_address)
        if balance < amount:
            print(
                colored(
                    "Not enough balance ({}) to transfer {}".format(
                        balance, amount), 'red'))
            quit()

        print(
            colored(
                "Requesting transfer of {}, from coldkey: {} to dest: {}".
                format(amount.rao, self.wallet.coldkey.public_key,
                       dest), 'blue'))
        print(colored("Waiting for finalization...", 'white'))
        result = self.subtensor.transfer(self.config.dest,
                                         amount,
                                         wait_for_finalization=True,
                                         timeout=bittensor.__blocktime__ * 5)
        if result:
            print(
                colored(
                    "Transfer finalized with amount: {} Tao to dest: {} from coldkey.pub: {}"
                    .format(amount.tao, self.config.dest,
                            self.wallet.coldkey.public_key), 'green'))
        else:
            print(colored("Transfer failed", 'red'))
Example #5
0
    def stake( self ):
        r""" Stakes token of amount to hotkey uid.
        """
        self.wallet.assert_coldkey()
        self.wallet.assert_coldkeypub()
        self.wallet.assert_hotkey()
        self.subtensor.connect()
        amount = Balance.from_float( self.config.amount )
        balance = self.subtensor.get_balance( self.wallet.coldkey.ss58_address )
        if balance < amount:
            print(colored("Not enough balance ({}) to stake {}".format(balance, amount), 'red'))
            quit()

        neurons = self._associated_neurons()
        neuron = neurons.get_by_uid( self.config.uid )
        if not neuron:
            print(colored("Neuron with uid: {} is not associated with coldkey.pub: {}".format(self.config.uid, self.wallet.coldkey.public_key), 'red'))
            quit()

        print(colored("Adding stake of {} rao from coldkey {} to hotkey {}".format(amount.rao, self.wallet.coldkey.public_key, neuron.hotkey), 'blue'))
        print(colored("Waiting for finalization...", 'white'))
        result = self.subtensor.add_stake( amount, neuron.hotkey, wait_for_finalization = True, timeout = bittensor.__blocktime__ * 5)
        if result:
            print(colored("Staked: {} Tao to uid: {} from coldkey.pub: {}".format(amount.tao, self.config.uid, self.wallet.coldkey.public_key), 'green'))
        else:
            print(colored("Stake transaction failed", 'red'))
Example #6
0
    def unstake( self ):
        r""" Unstaked token of amount to from uid.
        """
        self.wallet.assert_coldkey()
        self.wallet.assert_coldkeypub()
        self.wallet.assert_hotkey()
        self.subtensor.connect()
        amount = Balance.from_float( self.config.amount )
        neurons = self._associated_neurons()
        neuron = neurons.get_by_uid( self.config.uid )
        if not neuron:
            print(colored("Neuron with uid: {} is not associated with coldkey.pub: {}".format( self.config.uid, self.wallet.coldkey.public_key), 'red'))
            quit()

        neuron.stake = self.subtensor.get_stake_for_uid(neuron.uid)
        if amount > neuron.stake:
            print(colored("Neuron with uid: {} does not have enough stake ({}) to be able to unstake {}".format( self.config.uid, neuron.stake, amount), 'red'))
            quit()

        print(colored("Requesting unstake of {} rao for hotkey: {} to coldkey: {}".format(amount.rao, neuron.hotkey, self.wallet.coldkey.public_key), 'blue'))
        print(colored("Waiting for finalization...", 'white'))
        result = self.subtensor.unstake(amount, neuron.hotkey, wait_for_finalization = True, timeout = bittensor.__blocktime__ * 5)
        if result:
            print(colored("Unstaked:{} from uid:{} to coldkey.pub:{}".format(amount.tao, neuron.uid, self.wallet.coldkey.public_key), 'green'))
        else:
            print(colored("Unstaking transaction failed", 'red'))