-
-
Save ArtemBernatskyy/bdbd3d214cd5e1203d75bf8ee4c7ba1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
"""Calculate 'fair' market tx fee based on blockchain throughput. | |
Note: | |
it's just a ballpark estimate, real market prices will differ, doing this is better then nothing )( | |
Parses average number of txs per hour from https://minaexplorer.com/stats, | |
parses total stake for all accounts from https://minaexplorer.com/ledger, | |
provides an educated guess of what tx fee should be based on current throughput and stake sum. | |
""" | |
import requests | |
from bs4 import BeautifulSoup | |
IGNORE_DEFAULT_STAKE_ACCOUNTS = True # assume this accounts ignore tx challenge | |
IGNORE_ZERO_NONCE_ACCOUNTS = False # just for testing purposes, ignores accounts with nonce = 0 | |
HOURS_TILL_THE_END_OF_CHALLENGE = 9 * 24 | |
# parse addresses from minaexplorer | |
page_source_raw = requests.get('https://minaexplorer.com/ledger') | |
page_source = page_source_raw.content.decode() | |
soup = BeautifulSoup(page_source, 'html.parser') | |
addresses_raw_list = soup.select('#ledgerTable > tbody > tr') | |
# remove accounts from o1 labs | |
addresses_raw_final = [address for address in addresses_raw_list if 'O(1)' not in address.text] | |
# parse stake and nonce from soup | |
parsed_list = [] | |
for address in addresses_raw_final: | |
stake = int(float(address.select('td')[2].text)) | |
nonce = int(address.select('td')[3].text) | |
parsed_list.append({'stake': stake, 'nonce': nonce}) | |
# find sum of stake in all accounts, will be used in ballpark estimate to find price per tx | |
sum_of_all_stakes = 0 | |
for address in parsed_list: | |
if address['stake'] == 66000 and IGNORE_DEFAULT_STAKE_ACCOUNTS: | |
# ignore accounts with started stake value, assume this accounts ignore tx challenge | |
continue | |
elif address['nonce'] == 0 and IGNORE_ZERO_NONCE_ACCOUNTS: | |
# ignore accounts with nonce zero, assume this accounts ignore tx challenge | |
continue | |
sum_of_all_stakes += int(address['stake']) | |
# parse average throughput for mina blockchain for past 48 hours | |
tx_per_hour_history = requests.get( | |
'https://us-east-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/charts-project-0-fpdae/service/http/incoming_webhook/embedding?tolerance=3600&id=8f94f199-abb7-4938-893b-5681ab4872d0&tenant=d9d50e76-b3ef-43bb-b33b-bb739d4125e7&attribution=false' # noqa: E501 | |
) | |
last_48_hours_txs = [int(tx['y']['$numberInt']) for tx in tx_per_hour_history.json()['data']['documents'][-48:]] | |
last_48_average_throughput = int(sum(last_48_hours_txs) / len(last_48_hours_txs)) | |
possible_tx_number_till_the_end_of_challenge = HOURS_TILL_THE_END_OF_CHALLENGE * last_48_average_throughput | |
print( | |
f'average throughput for mina blockchain in last 48 hours is: {last_48_average_throughput}, till the end of 2nd epoch: {possible_tx_number_till_the_end_of_challenge}' # noqa: E501 | |
) | |
# do a price discovery to be able to use all funds on tx sending | |
print(f'tx price should be: {int(sum_of_all_stakes / possible_tx_number_till_the_end_of_challenge)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment