diff --git a/.gitignore b/.gitignore index 58fdc92b60c..63ed8ea8d2b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ openbb_terminal/config_terminal.py openbb_terminal/feature_flags.py openbb_terminal/reports/stored/* openbb_terminal/dashboards/.ipynb_checkpoints +openbb_terminal/custom_reports/*/.ipynb_checkpoints openbb_terminal/reports/.ipynb_checkpoints openbb_terminal/reports/widgets/.ipynb_checkpoints !openbb_terminal/reports/stored/.gitkeep @@ -32,6 +33,7 @@ openbb_terminal/portfolio/portfolios/* *.http bots/interactive/*.html .coverage.* +!openbb_terminal/custom_reports/*/.ipynb # pyinstaller artifacts *.pyo diff --git a/openbb_terminal/custom_reports/lunar_crash/coin_highs.png b/openbb_terminal/custom_reports/lunar_crash/coin_highs.png new file mode 100644 index 00000000000..953aa4c98ae Binary files /dev/null and b/openbb_terminal/custom_reports/lunar_crash/coin_highs.png differ diff --git a/openbb_terminal/custom_reports/lunar_crash/luna_crash.html b/openbb_terminal/custom_reports/lunar_crash/luna_crash.html new file mode 100644 index 00000000000..cfefb8b0615 --- /dev/null +++ b/openbb_terminal/custom_reports/lunar_crash/luna_crash.html @@ -0,0 +1,346 @@ + + + + + + luna_crash + + + + + + + +
+ OpenBB +
+

Analyst: Minh Hoang

+

Date : 16 May, 2022

+

Time : 00:46 BST

+
+

LUNA CRASH EVENTS

+
+

Over the past few days, we witnessed the bank run of the largest decentralized stablecoin, UST, together with the demise of LUNA. +

+Its effect has spread over the entire Terra ecosystem as well as the entire crypto market. +


Just a few weeks ago, LUNA and the Terra ecosystem are still the darlings of crypto investors.
+Experiencing a 20,000% increase since the beginning of 2021, LUNA reached its ATH of $119 in January 2021. +

Overall, just a few days ago, Terra was the second biggest smart contract platform in terms of total value lock, with almost $22 billion.
+Its biggest dApp is Anchor, a lending and borrowing protocol with the (in)famous APY of 20%.
+This lucrative return is too hard to ignore, even within the crypto market. Within a year, its TVL has shot up from $500M to almost $17.5B. +


+The bloodbath initially started with UST losing its peg against USD. +After that, both LUNA and UST have been completely destroyed. +You might be wondering, how did this happen in less than a week? +To explain this, we first have to understand the stablizing mechanism of the Terra ecosystem. +
+
+A centralized stablecoin such as USDT would needs actual backed assets, such as BTC, to consistently track the dollar. +As UST is a decentralized, and algorithmic stablecoin, the mint and burnt mechanism between LUNA & UST plays the crucial role in sustaining the peg. +
+
+In essence, Terra protocol allow its users to burn 1$ worth of LUNA to mint 1 UST and vice versa, burn UST to mint 1$ worth of LUNA. +
+
+This creates an arbitrage opportunity whenever UST loses its peg against the dollar. +Let’s say when UST is traded at $0.90, you can buy UST and burn it for 1$ worth of LUNA, making a profit of 10 cent. +By burning UST, UST supply would decrease and therefore, raising price back to $1 as in Economics 101. +
+
+The other way around, when UST is traded at $1.10, you can burn $1 worth of LUNA to mint UST. +This would flood more UST to the market, forcing price to go back to $1. +Whenever there’s a price discrepancy between USD and UST, Terra relies on this genius arbitrage incentives to bring price back to $1. +

+But why can’t the burn-and-mint mechanism save the day? Let’s go back to what happened. +
+
+The crash started it off with UST losing its dollar peg repeatedly. +This causes investors, and whales in specific, losing their confidence in this algorithmic stablecoins. +The peak of uncertainty was on the weekend of 7th and 8th of May. +During two days, a massive amount of UST were withdrawn from Anchor protocol. +On Friday, 6th of May, there was still around 14 billion of UST locked in Anchor protocol as deposits. +On Monday, this figure was down to 10.8 billion. This means that around 3.2 billion of UST were taken out over the weekend. +Inevitably, this put a massive selling pressure on UST and lead to UST further losing its peg. +
+
+As UST peg is too far away from 1 dollar, a massive amount of LUNA needs to minted in order to push the price back. +With such a large amount of LUNA dumped in the market, the circulating supply shot up and caused luna price to fall. +Let’s keep in mind that this happened during a market crash, and hence the selling pressure has doubled up. +

+This is clearly reflected in the LUNA’s circulating supply. +In just few days, number of Luna went to the moon, from less than 400 millions token to over 6 trillions. +
+
+Eventually, with the enormous selling pressure, Luna price has fallen below $1 mark, even lower than UST’s supposed value. +This continues until Luna’s market cap became smaller than UST’s. +With this, the peg stablization mechanism can no longer work, ended the hope of many investors that price can still go back up. +


+As a revival plan, Do Kwon proposed to hard-fork Luna to a completely new chain, with a snapshot before the attack. +
+
+This new chain would have maximum supply of 1 billion coins. Out of these:
+ * 400M would be given to Luna holders before the depeg happened
+ * 400M to UST holders at the time of the upgrade
+ * 100M to Luna holders when the blockchain stops functioning
+ * 100M for community pool +
+
+He also mentioned to change the mint-and-burnt mechanism to a collateralized version, similar to what MakerDAO does with their DAI stablecoin. +
+
+The biggest question is: do investors have the courage to give Do Kwon and Terra’s team their trust one more time? +This bank run has put an end to a once $40 billion cryptocurrency and once the top 3 biggest stablecoins by market caps, wiping out fortunes of investors and validators. +

+ + + \ No newline at end of file diff --git a/openbb_terminal/custom_reports/lunar_crash/luna_supply.png b/openbb_terminal/custom_reports/lunar_crash/luna_supply.png new file mode 100644 index 00000000000..03585b8ad35 Binary files /dev/null and b/openbb_terminal/custom_reports/lunar_crash/luna_supply.png differ diff --git a/openbb_terminal/custom_reports/lunar_crash/luna_terra.png b/openbb_terminal/custom_reports/lunar_crash/luna_terra.png new file mode 100644 index 00000000000..cfc6c78057b Binary files /dev/null and b/openbb_terminal/custom_reports/lunar_crash/luna_terra.png differ diff --git a/openbb_terminal/custom_reports/lunar_crash/lunatics.ipynb b/openbb_terminal/custom_reports/lunar_crash/lunatics.ipynb new file mode 100644 index 00000000000..e65688d8673 --- /dev/null +++ b/openbb_terminal/custom_reports/lunar_crash/lunatics.ipynb @@ -0,0 +1,274 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "70ba2c8a", + "metadata": {}, + "source": [ + "## Notebook setup" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "driven-billion", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import io\n", + "import warnings\n", + "import datetime\n", + "import numpy as np\n", + "import pandas as pd\n", + "import base64\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import matplotlib_inline.backend_inline\n", + "\n", + "import sys\n", + "sys.path.append('../../../')\n", + "\n", + "from openbb_terminal import api as openbb\n", + "from openbb_terminal.helper_classes import TerminalStyle\n", + "\n", + "%matplotlib inline\n", + "matplotlib_inline.backend_inline.set_matplotlib_formats(\"svg\")\n", + "warnings.filterwarnings(\"ignore\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c3fe7db5-ec6a-42cf-9e66-52dc1de22370", + "metadata": {}, + "outputs": [], + "source": [ + "try:\n", + " theme = TerminalStyle(\"dark\", \"dark\", \"dark\")\n", + "except:\n", + " pass\n", + "stylesheet = openbb.widgets.html_report_stylesheet()\n", + "# with open(\"./OpenBB_reports_logo.png\", \"rb\") as image_file:\n", + "with open(\"../../reports/OpenBB_reports_logo.png\", \"rb\") as image_file:\n", + " openbb_image_encoded = base64.b64encode(image_file.read())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6aa8b34-aa60-45ce-8ba0-0182addffab8", + "metadata": {}, + "outputs": [], + "source": [ + "author = \"Minh Hoang\"\n", + "report_title = f\"LUNATICS REPORT\"\n", + "report_date = datetime.datetime.now().strftime('%d %B, %Y')\n", + "report_time = datetime.datetime.now().strftime('%H:%M') \n", + "report_timezone = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo\n", + "report_name = \"luna_crash\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "abfe37e4-ea38-42c3-8fb5-7cceb233fb12", + "metadata": {}, + "outputs": [], + "source": [ + "body = \"\"\n", + "\n", + "img = f'\"OpenBB\"'\n", + "body += openbb.widgets.header(img, author, report_date, report_time, report_timezone, f'LUNA CRASH EVENTS')\n", + "\n", + "body += openbb.widgets.tablinks([\"Overview\", \"Before\", \"During\", \"After\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "381b353b-3e01-4db7-ab3d-429b5785e98e", + "metadata": {}, + "outputs": [], + "source": [ + "# OVERVIEW\n", + "text = \"\"\"Over the past few days, we witnessed the bank run on the largest decentralized stablecoin, UST, together with the demise of LUNA. \n", + "

\n", + "Its effect has spread over the entire Terra ecosystem as well as the entire crypto market. \n", + "\"\"\"\n", + "htmlcode = openbb.widgets.p(text, \"width:1200px; margin-bottom:8px\")\n", + "body += openbb.widgets.add_tab(\"Overview\", htmlcode, False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "adc40a71-f245-4542-a303-fbf0970b9759", + "metadata": {}, + "outputs": [], + "source": [ + "# BEFORE\n", + "htmlcode = openbb.widgets.add_external_fig(\"./luna_supply.png\", \"width:500px; margin-bottom:16px\")\n", + "text = \"\"\"Just a few weeks ago, LUNA and the Terra ecosystem were the darlings of crypto investors.
\n", + "Experiencing a 20,000% increase since the beginning of 2021, LUNA reached its ATH of $119 in January 2021.\n", + "\"\"\"\n", + "htmlcode += openbb.widgets.p(text, \"width:1200px; margin-bottom:8px\")\n", + "htmlcode += openbb.widgets.add_external_fig(\"./coin_highs.png\", \"width:500px; margin-bottom:16px\")\n", + "text = \"\"\"Overall, before the crisis, Terra was the second biggest smart contract platform in terms of total value locked, with almost $22 billion.
\n", + "Its biggest dApp is Anchor, a lending and borrowing protocol with the (in)famous APY of 20%.
\n", + "This lucrative return is too hard to ignore, even within the crypto market. Within a year, its TVL has shot up from $500M to almost $17.5B.\n", + "\"\"\"\n", + "htmlcode += openbb.widgets.p(text, \"width:1200px; margin-bottom:8px\")\n", + "htmlcode += openbb.widgets.add_external_fig(\"./tvl.png\", \"width:500px; margin-bottom:16px\")\n", + "body += openbb.widgets.add_tab(\"Before\", htmlcode, False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e08062d0-cc29-4308-87c6-b54d5d7339a7", + "metadata": {}, + "outputs": [], + "source": [ + "# DURING\n", + "text = \"\"\"\n", + "The bloodbath initially started with UST losing its peg against USD. \n", + "After that, both LUNA and UST have been completely destroyed. \n", + "You might be wondering, how did this happen in less than a week? \n", + "To explain this, we first have to understand the stablizing mechanism of the Terra ecosystem.\n", + "
\n", + "
\n", + "A centralized stablecoin such as USDT would need actual backed assets, such as BTC, to consistently track the dollar. \n", + " As UST is a decentralized, and algorithmic stablecoin, the mint and burnt mechanism between LUNA & UST play a crucial role in sustaining the peg.\n", + "
\n", + "
\n", + "In essence, Terra protocol allow its users to burn 1$ worth of LUNA to mint 1 UST and vice versa, burn UST to mint 1$ worth of LUNA.\n", + "
\n", + "
\n", + "This creates an arbitrage opportunity whenever UST loses its peg against the dollar. \n", + "Let’s say when UST is traded at $0.90, you can buy UST and burn it for 1$ worth of LUNA, making a profit of 10 cent. \n", + "By burning UST, UST supply would decrease and therefore, raising price back to $1 as in Economics 101.\n", + "
\n", + "
\n", + "The other way around, when UST is traded at $1.10, you can burn $1 worth of LUNA to mint UST. \n", + "This would flood more UST into the market, forcing the price to go back to $1.\n", + "Whenever there’s a price discrepancy between USD and UST, Terra relies on this genius arbitrage incentives to bring price back to $1.\n", + "\"\"\"\n", + "htmlcode = openbb.widgets.p(text, \"width:1200px; margin-bottom:8px; margin-top:16px\")\n", + "htmlcode += openbb.widgets.add_external_fig(\"./ust_terra.png\", \"width:500px; margin-left:2em\")\n", + "\n", + "text = \"\"\"\n", + "But why can’t the burn-and-mint mechanism save the day? Let’s go back to what happened.\n", + "
\n", + "
\n", + "The crash started it off with UST losing its dollar peg repeatedly. \n", + "This causes investors, and whales in specific, to lose their confidence in the security of an algorithmic stablecoin.\n", + "The peak of uncertainty was on the weekend of the 7th and 8th of May.\n", + "During two days, a massive amount of UST was withdrawn from the Anchor protocol.\n", + "On Friday, the 6th of May, there were still around 14 billion UST locked in the Anchor protocol as deposits.\n", + "Then on Monday, this figure was down to 10.8 billion. This means that around 3.2 billion of UST were taken out over the weekend. \n", + "Inevitably, this created massive selling pressure on UST and lead to UST further losing its peg. \n", + "
\n", + "
\n", + "As the UST peg is too far away from 1 dollar, a massive amount of LUNA needs to be minted to bring the price back. \n", + "With such a large amount of LUNA dumped into the market, the circulating supply shot up and caused LUNA's price to fall. \n", + " Let’s keep in mind that this happened during a market crash, and hence the selling pressure has doubled up.\n", + "\"\"\"\n", + "htmlcode += openbb.widgets.p(text, \"width:1200px; margin-bottom:8px; margin-top:16px\")\n", + "htmlcode += openbb.widgets.add_external_fig(\"./luna_terra.png\", \"width:500px;\")\n", + "\n", + "text = \"\"\"\n", + "This was reflected in the LUNA’s circulating supply.\n", + "In just a few days, the number of Luna went to the moon, from less than 400 million tokens to over 6 trillion. \n", + "
\n", + "
\n", + "Eventually, with the enormous selling pressure, Luna's price has fallen below the $1 mark, even lower than UST’s supposed value.\n", + "This continues until Luna’s market cap became smaller than UST’s.\n", + "With this, the peg stabilization mechanism can no longer work, ending the hope of many investors that its price can still go back up.\n", + "This continues until Luna’s market cap became smaller than UST’s. With this, the peg stabilization mechanism can no longer work, ending the hope of many investors that its price can still go back up.\n", + "\"\"\"\n", + "htmlcode += openbb.widgets.p(text, \"width:1200px; margin-bottom:8px; margin-top:16px\")\n", + "body += openbb.widgets.add_tab(\"During\", htmlcode, False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "660ea74b-316a-45b0-af95-ee0a4ec162ef", + "metadata": {}, + "outputs": [], + "source": [ + "# AFTER\n", + "text = \"\"\"\n", + "As a revival plan, Do Kwon proposed to hard-fork Luna to a completely new chain, with a snapshot before the attack. \n", + "
\n", + "
\n", + "This new chain would have maximum supply of 1 billion coins. Out of these:
\n", + " * 400M would be given to Luna holders before the depeg happened
\n", + " * 400M to UST holders at the time of the upgrade
\n", + " * 100M to Luna holders when the blockchain stops functioning
\n", + " * 100M for community pool\n", + "
\n", + "
\n", + "He also mentioned changing the mint-and-burnt mechanism to a collateralized version, similar to what MakerDAO does with their DAI stablecoin.\n", + "Ironically, just early this year, he posted on Twitter: “By my hand $DAI will die.” When UST was struggling to maintain its peg, $DAI stood still with its peg. \n", + "
\n", + "
\n", + "The biggest question is: do investors have the courage to give Do Kwon and Terra’s team their trust one more time? \n", + "This bank run has put an end to a once $40 billion cryptocurrency and once the top 3 biggest stablecoins by market caps, wiping out fortunes of investors and validators. \n", + "\"\"\"\n", + "htmlcode = openbb.widgets.p(text, \"width:1200px; margin-bottom:8px; margin-top:16px\")\n", + "body += openbb.widgets.add_tab(\"After\", htmlcode, False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5ddfca2f-658c-41ae-be37-e588cd2daa37", + "metadata": {}, + "outputs": [], + "source": [ + "body += openbb.widgets.tab_clickable_evt()\n", + "\n", + "report = openbb.widgets.html_report(title=report_name, stylesheet=stylesheet, body=body)\n", + "\n", + "# to save the results\n", + "with open(report_name + \".html\", \"w\") as fh:\n", + " fh.write(report)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e15cef06-0d10-4153-b6d3-9762be0ed1dd", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "celltoolbar": "Tags", + "interpreter": { + "hash": "aa1c4d436101635411b2afa2ce061827695b6e3d0efa7f05338cbf11ad26165e" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/openbb_terminal/custom_reports/lunar_crash/tvl.png b/openbb_terminal/custom_reports/lunar_crash/tvl.png new file mode 100644 index 00000000000..e221bd759d5 Binary files /dev/null and b/openbb_terminal/custom_reports/lunar_crash/tvl.png differ diff --git a/openbb_terminal/custom_reports/lunar_crash/ust_terra.png b/openbb_terminal/custom_reports/lunar_crash/ust_terra.png new file mode 100644 index 00000000000..3dd13824ca4 Binary files /dev/null and b/openbb_terminal/custom_reports/lunar_crash/ust_terra.png differ diff --git a/openbb_terminal/reports/widget_helpers.py b/openbb_terminal/reports/widget_helpers.py index 2d9ea2cecf6..2cf32c8b7eb 100644 --- a/openbb_terminal/reports/widget_helpers.py +++ b/openbb_terminal/reports/widget_helpers.py @@ -6,6 +6,7 @@ The library includes both python code and html/css/js elements that can be found """ import os from typing import List +import base64 from jinja2 import Template @@ -96,20 +97,22 @@ def h(level: int, text: str) -> str: return f"{text}" -def p(text: str) -> str: +def p(text: str, style: str = "") -> str: """Wrap text into an HTML `p` tag. Parameters ---------- text : str Contents for HTML `p` tag + style: str + Div style Returns ------- str HTML code as string """ - return f"

{text}

" + return f'

{text}

' def row(elements: List) -> str: @@ -163,7 +166,7 @@ def kpi(thresholds: List[float], sentences: List[str], value: float) -> str: return "" -def add_tab(title: str, htmlcode: str) -> str: +def add_tab(title: str, htmlcode: str, comment_cell: bool = True) -> str: """Add new tab section for the report. By default adds an opinion editable box at the start. Parameters @@ -172,18 +175,22 @@ def add_tab(title: str, htmlcode: str) -> str: Title associated with this tab / section htmlcode : str All HTML code contain within this section + comment_cell : bool + Comment cell Returns ------- str HTML code as string """ - return f"""

-


' + if comment_cell: + html_text += """

No comment. -

{htmlcode} -
""" +

""" + html_text += f"{htmlcode}" + return html_text def tab_clickable_evt() -> str: @@ -277,3 +284,26 @@ def header(img, author, report_date, report_time, report_tz, title) -> str:

{title}

""" + + +def add_external_fig(figloc: str, style: str = "") -> str: + """Add external figure to HTML + + Parameters + ---------- + figloc : str + Relative figure location + style: str + Div style + + Returns + ------- + str + HTML code for figure + """ + try: + with open(figloc, "rb") as image_file: + img = base64.b64encode(image_file.read()).decode() + return f'' + except Exception: + return ""