In this post I share that we are now paying out a total of 0.43 BRO tokens per day to ALIVE stakeholders in daily staking rewards, plus I share the script that I have created to make it possible, enjoy!
Made in Desygner
Hi there and welcome to my blog, my name is Erik Gustafsson and I go by the handle @flaxz.
0.43 BRO Per Day - Is Now Paid Out To ALIVE Stakeholders In Daily Staking Rewards
Yesterday I made the weekly payout of 3 BRO to ALIVE stakeholders, but I have always wanted this to be daily, and as I was able to finish all functionality of the script that I have created for this then starting from today we are now doing daily payouts instead.
This means that we are now paying out a total of 0.43 BRO per day to ALIVE stakeholders, the funding for this comes from @aliveprojects and the payouts themselves are done using the @youarealive account, and today 468 accounts got a share of this payout.
If you don't know what BRO is then it is a dividends paying token, and it pays out daily dividends from @brofund and related accounts, all you need to do is keep it in your Hive-engine wallet and not sell it to get part of those daily dividends.
We hope that this is a great motivator for people to keep and stake their ALIVE tokens rather than selling them, and to increase demand for it.
Trade ALIVE: https://tribaldex.com/trade/ALIVE
Trade ALIVEM: https://tribaldex.com/trade/ALIVEM
The Script
So the script that I have created for this comes in 2 parts, the first part gets the data with all token stakes, and then calculates the whole payout and formats everything into a .csv file that is then used directly by the second part to do the payout itself.
Here is the first part.
import pandas as pd
from hiveengine.api import Api
api = Api()
token = input("Enter staked token symbol: ")
holders = api.find_all("tokens", "balances", query = {"symbol": token})
df = pd.DataFrame(holders)
df.drop(columns = ["_id", "balance", "pendingUnstake", "delegationsIn"], inplace = True)
df["pendingUndelegations"] = df["pendingUndelegations"].astype(float)
df["stake"] = df["stake"].astype(float)
df["delegationsOut"] = df["delegationsOut"].astype(float)
df = df.assign(ownedStake = df.sum(axis = 1, numeric_only = True))
decNum = int(input("Enter number of decimals(0 to 8): "))
df["ownedStake"] = df["ownedStake"].round(decNum)
indexZero = df[df["ownedStake"] == 0.0].index
df.drop(indexZero, inplace = True)
df.drop(columns = ["symbol", "stake", "delegationsOut", "pendingUndelegations"], inplace = True)
df.sort_values(by=["ownedStake"], inplace = True, ascending = False)
dropHolder = input("Enter account to remove: ")
indexHolder = df[df["account"] == dropHolder].index
df.drop(indexHolder, inplace = True)
print("Successfully removed:", dropHolder)
payToken = input("Enter payout token symbol: ")
payDec = int(input("Enter number of decimals (0 to 8: "))
payAmount = float(input("Enter amount to pay out: "))
payMemo = input("Enter Memo for payout: ")
sumStake = float(df["ownedStake"].sum())
df = df.assign(amount = (payAmount * (df.sum(axis = 1, numeric_only = True) / sumStake)))
df["amount"] = df["amount"].astype(float)
indexZero2 = df[df["amount"] < 0.00000001].index
df.drop(indexZero2, inplace = True)
df["amount"] = df["amount"].round(payDec)
sumAmount = df["amount"].sum()
print("Sum payout:", sumAmount, payToken)
df = df.assign(symbol = payToken)
df = df.assign(memo = payMemo)
df.drop(columns = ["ownedStake"], inplace = True)
decPoint = input("Enter decimal point(.or,): ")
fileName = input("Enter CSV file name (including .csv): ")
df.to_csv(fileName, decimal = decPoint, index = False)
And here is the second part.
from beem import Hive
from beem import exceptions
from beem.nodelist import NodeList
import getpass
from hiveengine.wallet import Wallet
import pandas as pd
from time import sleep
hive_nodeList = NodeList()
hive_nodeList.update_nodes()
hive_nodes = hive_nodeList.get_hive_nodes()
hive = Hive(node = hive_nodes)
name = input("Enter wallet name: ")
def checkHiveWallet():
try:
hive.wallet.getActiveKeysForAccount(name)
except exceptions.MissingKeyError:
key = getpass.getpass("Please Supply the Hive Wallet Active Key: ")
try:
hive.wallet.addPrivateKey(key)
except exceptions.InvalidWifError:
print("Invalid Key! Please try again.")
checkHiveWallet()
def unlockWallet():
walletPassword = getpass.getpass("Wallet Password: ")
try:
hive.wallet.unlock(walletPassword)
except beemstorage.exceptions.WrongMasterPasswordException:
print("Invalid Password, please try again!")
unlockWallet()
if __name__ == "__main__":
unlockWallet()
checkHiveWallet()
activeKey = hive.wallet.getKeyForAccount(name, "active")
HVE = Hive(node = hive_nodes, keys = [activeKey])
wallet = Wallet(name, blockchain_instance = HVE)
file = input("Enter CSV file name: ")
decPoint = input("Enter decimal point(.or,): ")
df = pd.read_csv(file, decimal = decPoint)
df["amount"] = df["amount"].astype(float)
df["amount"] = df["amount"].round(8)
pay = df.values.tolist()
while len(pay) >= 1:
if len(pay) >= 20:
wallet.transfer(pay[0][0], pay[0][1], pay[0][2], pay[0][3])
wallet.transfer(pay[1][0], pay[1][1], pay[1][2], pay[1][3])
wallet.transfer(pay[2][0], pay[2][1], pay[2][2], pay[2][3])
wallet.transfer(pay[3][0], pay[3][1], pay[3][2], pay[3][3])
wallet.transfer(pay[4][0], pay[4][1], pay[4][2], pay[4][3])
wallet.transfer(pay[5][0], pay[5][1], pay[5][2], pay[5][3])
wallet.transfer(pay[6][0], pay[6][1], pay[6][2], pay[6][3])
wallet.transfer(pay[7][0], pay[7][1], pay[7][2], pay[7][3])
wallet.transfer(pay[8][0], pay[8][1], pay[8][2], pay[8][3])
wallet.transfer(pay[9][0], pay[9][1], pay[9][2], pay[9][3])
wallet.transfer(pay[10][0], pay[10][1], pay[10][2], pay[10][3])
wallet.transfer(pay[11][0], pay[11][1], pay[11][2], pay[11][3])
wallet.transfer(pay[12][0], pay[12][1], pay[12][2], pay[12][3])
wallet.transfer(pay[13][0], pay[13][1], pay[13][2], pay[13][3])
wallet.transfer(pay[14][0], pay[14][1], pay[14][2], pay[14][3])
wallet.transfer(pay[15][0], pay[15][1], pay[15][2], pay[15][3])
wallet.transfer(pay[16][0], pay[16][1], pay[16][2], pay[16][3])
wallet.transfer(pay[17][0], pay[17][1], pay[17][2], pay[17][3])
wallet.transfer(pay[18][0], pay[18][1], pay[18][2], pay[18][3])
wallet.transfer(pay[19][0], pay[19][1], pay[19][2], pay[19][3])
print(pay[:20])
del pay[:20]
elif len(pay) >= 10:
wallet.transfer(pay[0][0], pay[0][1], pay[0][2], pay[0][3])
wallet.transfer(pay[1][0], pay[1][1], pay[1][2], pay[1][3])
wallet.transfer(pay[2][0], pay[2][1], pay[2][2], pay[2][3])
wallet.transfer(pay[3][0], pay[3][1], pay[3][2], pay[3][3])
wallet.transfer(pay[4][0], pay[4][1], pay[4][2], pay[4][3])
wallet.transfer(pay[5][0], pay[5][1], pay[5][2], pay[5][3])
wallet.transfer(pay[6][0], pay[6][1], pay[6][2], pay[6][3])
wallet.transfer(pay[7][0], pay[7][1], pay[7][2], pay[7][3])
wallet.transfer(pay[8][0], pay[8][1], pay[8][2], pay[8][3])
wallet.transfer(pay[9][0], pay[9][1], pay[9][2], pay[9][3])
print(pay[:10])
del pay[:10]
else:
wallet.transfer(pay[0][0], pay[0][1], pay[0][2], pay[0][3])
print(pay[0])
del pay[0]
sleep(10)
print("Payout complete.")
It is all written in Python and it uses the Beem and Hiveengine modules from @holger80 to interact with the blockchain, plus a few more Python modules as well.
I can not say that it is pretty, but I will fine tune a few details up ahead, it works though and all functionality is there, and also do note that I only started to learn Python around 5 weeks ago, even if I was not completely unaware of it, but I do not have a coding background.
I will also publish this on Github with an MIT License when I have the time for it, plus note that the key adding and authentication part comes from @sc-steemit.
Don't start playing around with it unless you know what you are doing.
Thank You!
Thank you very much for reading this post and I hope you liked it, leave your thoughts in the coments below, and ...
Stay Awesome!
Sincerely,
Erik Gustafsson
This is my own personal opinion, do your own research before investing, and seek legal counsel if uncertain.