From 9296f0d0e80a9c8e99dd692d72f7d500f4948de1 Mon Sep 17 00:00:00 2001 From: jwinterm Date: Sat, 4 May 2024 16:26:59 -0400 Subject: [PATCH] Initial commit --- .gitignore | 135 +++++++++++++++++++++++++++++++++++++++++++ README.md | 19 ++++++ bitcoin.py | 30 ++++++++++ blockchain.py | 7 +++ btcxmrwowemission.py | 34 +++++++++++ monero.py | 39 +++++++++++++ wownero.py | 32 ++++++++++ 7 files changed, 296 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 bitcoin.py create mode 100644 blockchain.py create mode 100644 btcxmrwowemission.py create mode 100644 monero.py create mode 100644 wownero.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..11c1203 --- /dev/null +++ b/.gitignore @@ -0,0 +1,135 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +**/__pycache__/ + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.coverage +.tox/ +.nox/ +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# Ignore VSCode settings +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a020ec1 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Blockchain Analysis Emission + +This folder contains the following four class files and a script: + +## Class Files + +1. `blockchain.py`: This class file is a generic class. +2. `bitcoin.py`: This class file implements calculated and historical Bitcoin blockchain data. +3. `monero.py`: This class file contains calculated blockchain data. +4. `wownero.py`: This class file includes calculated blockchain data. + +## Script + +`btcxmrwowemission.py`: This script is responsible for instancing the classes and plotting some data. +The data is date-shifted and normalized in this script. + +## License + +This project is licensed under the public domain. diff --git a/bitcoin.py b/bitcoin.py new file mode 100644 index 0000000..412116a --- /dev/null +++ b/bitcoin.py @@ -0,0 +1,30 @@ +import blockchain +import numpy as np + +class Bitcoin(blockchain.Blockchain): + def __init__(self, number_of_blocks=7e6, block_skip=10): + super().__init__(number_of_blocks, block_skip) + # First generate fully calculated date and reward data + self.blocks = np.arange(0, self.number_of_blocks, self.block_skip) + self.launch_time = 1231006505 + self.time = self.blocks*600*self.block_skip + self.launch_time + self.date = np.array(self.time, dtype='datetime64[s]') + self.reward = np.zeros(len(self.blocks)) + self.cum_reward = np.zeros(len(self.blocks)) + for i in range(len(self.blocks)): + self.reward[i] = ((np.uint(50e8)//2**((i*self.block_skip)//210000))*1e-8) * self.block_skip + self.cum_reward[i] += self.reward[i] + + # Historical data for bitcoin emission + self.date_historical = [np.datetime64('2009-01-03'), np.datetime64('2012-11-28'), np.datetime64('2016-07-09'), np.datetime64('2024-04-20')] + for i in range(30): + next_date = self.date_historical[-1] + np.timedelta64(1461, 'D') + self.date_historical.append(next_date) + self.reward_historical = np.zeros(len(self.date_historical)) + self.cum_reward_historical = np.zeros(len(self.date_historical)) + for i in range(len(self.date_historical)): + self.reward_historical[i] = 210000*(np.uint(50e8)//2**i)*1e-8 + if i < len(self.date_historical)-1: + self.cum_reward_historical[i+1] = self.cum_reward_historical[i] + self.reward_historical[i] + print(i, self.date_historical[i], self.reward_historical[i], self.cum_reward_historical[i]) + print(self.date_historical, self.cum_reward_historical) \ No newline at end of file diff --git a/blockchain.py b/blockchain.py new file mode 100644 index 0000000..cd76934 --- /dev/null +++ b/blockchain.py @@ -0,0 +1,7 @@ +import numpy as np + +class Blockchain: + '''Contains time and reward information for a blockchain''' + def __init__(self, number_of_blocks=7e6, block_skip=10): + self.number_of_blocks = int(number_of_blocks) # Number of blocks to calculate + self.block_skip = int(block_skip) # Number of blocks to skip to save time diff --git a/btcxmrwowemission.py b/btcxmrwowemission.py new file mode 100644 index 0000000..bafebb3 --- /dev/null +++ b/btcxmrwowemission.py @@ -0,0 +1,34 @@ +import matplotlib.pyplot as plt +import numpy as np +import datetime as dt + +# Importing the classes +import bitcoin +import monero +import wownero +# Instance classes with specified number of blocks and block skip +btc = bitcoin.Bitcoin(7e6, 10) +xmr = monero.Monero(40e6, 100) +wow = wownero.Wownero(15e6, 100) + +# Adjusting the date to start at the same time +xmr.date = xmr.date - (xmr.date[0] - btc.date_historical[0]) +wow.date = wow.date - (wow.date[0] - btc.date_historical[0]) +# Normalizing the data by the total number of coins (or 18.132e6 for Monero) +btc.cum_reward_historical = btc.cum_reward_historical / btc.cum_reward_historical[-1] +xmr.cum_reward = xmr.cum_reward / 18.132e6 +wow.cum_reward = wow.cum_reward / wow.cum_reward[-1] + +# Plotting the data +plt.plot(btc.date_historical, btc.cum_reward_historical, '-', color='orange', label='Bitcoin') +plt.plot(xmr.date, xmr.cum_reward, '--', color='grey', label='Monero') +plt.plot(wow.date, wow.cum_reward, '-.', color='pink', label='Wownero') + +# Adding labels, grid, legend, etc +plt.xlabel('Time (years)') +plt.ylabel('% total coins emitted (pre-tail emission)') +plt.grid() +plt.legend() + +# Displaying the plot +plt.show() \ No newline at end of file diff --git a/monero.py b/monero.py new file mode 100644 index 0000000..7fcc06f --- /dev/null +++ b/monero.py @@ -0,0 +1,39 @@ +import blockchain +import numpy as np + +class Monero(blockchain.Blockchain): + def __init__(self, number_of_blocks=3e7, block_skip=100): + super().__init__(number_of_blocks, block_skip) + # First generate fully calculated date and reward data + self.already_generated_coins = 0 + self.blocks = np.arange(0, self.number_of_blocks, self.block_skip) + self.launch_time = 1397793600 + self.time = np.zeros(len(self.blocks)) + self.time[0] = self.launch_time + self.reward = np.zeros(len(self.blocks)) + self.cum_reward = np.zeros(len(self.blocks)) + self.XMR_DIFFICULTY_TARGET_V2 = 120 + self.XMR_DIFFICULTY_TARGET_V1 = 60 + self.MONEY_SUPPLY = 2**64 - 1 + self.XMR_EMISSION_SPEED_FACTOR_PER_MINUTE = 20 + self.XMR_FINAL_SUBSIDY_PER_MINUTE = 0.3e12 + self.v2_START = 1009827 + for i in range(len(self.blocks)): + if self.blocks[i] < self.v2_START: + target = self.XMR_DIFFICULTY_TARGET_V1 + target_minutes = target / 60 + emission_speed_factor = self.XMR_EMISSION_SPEED_FACTOR_PER_MINUTE - (target_minutes - 1) + else: + target = self.XMR_DIFFICULTY_TARGET_V2 + target_minutes = target / 60 + emission_speed_factor = self.XMR_EMISSION_SPEED_FACTOR_PER_MINUTE - (target_minutes - 1) + reward = (self.MONEY_SUPPLY - int(self.already_generated_coins)) >> int(emission_speed_factor) + if reward < self.XMR_FINAL_SUBSIDY_PER_MINUTE * target_minutes: + reward = self.XMR_FINAL_SUBSIDY_PER_MINUTE * target_minutes + self.already_generated_coins += reward * self.block_skip + self.reward[i] = reward*1e-12 * self.block_skip + self.cum_reward[i] = self.already_generated_coins*1e-12 + if i > 0: + self.time[i] = self.time[i-1] + target_minutes*60 * self.block_skip + self.date = np.array(self.time, dtype='datetime64[s]') + \ No newline at end of file diff --git a/wownero.py b/wownero.py new file mode 100644 index 0000000..83b8c1b --- /dev/null +++ b/wownero.py @@ -0,0 +1,32 @@ +import blockchain +import numpy as np + +class Wownero(blockchain.Blockchain): + def __init__(self, number_of_blocks=15e6, block_skip=100): + super().__init__(number_of_blocks, block_skip) + # First generate fully calculated date and reward data + self.already_generated_coins = 0 + self.blocks = np.arange(0, self.number_of_blocks, self.block_skip) + self.launch_time = 1524223213 + self.time = np.zeros(len(self.blocks)) + self.time[0] = self.launch_time + self.reward = np.zeros(len(self.blocks)) + self.cum_reward = np.zeros(len(self.blocks)) + self.WOW_DIFFICULTY_TARGET = 300 + self.MONEY_SUPPLY = 2**64 - 1 + self.WOW_EMISSION_SPEED_FACTOR_PER_MINUTE = 24 + self.WOW_FINAL_SUBSIDY_PER_MINUTE = 0 + for i in range(len(self.blocks)): + target = self.WOW_DIFFICULTY_TARGET + target_minutes = target / 60 + emission_speed_factor = self.WOW_EMISSION_SPEED_FACTOR_PER_MINUTE - (target_minutes - 1) + reward = (self.MONEY_SUPPLY - int(self.already_generated_coins)) >> int(emission_speed_factor) + if reward <= self.WOW_FINAL_SUBSIDY_PER_MINUTE * target_minutes: + reward = self.WOW_FINAL_SUBSIDY_PER_MINUTE * target_minutes + self.already_generated_coins += reward * self.block_skip + self.reward[i] = reward*1e-11 * self.block_skip + self.cum_reward[i] = self.already_generated_coins*1e-12 + if i > 0: + self.time[i] = self.time[i-1] + target_minutes*60 * self.block_skip + self.date = np.array(self.time, dtype='datetime64[s]') +