{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### System timeline\n",
    " - initial raise\n",
    " - hatch sale\n",
    " - reference implementation launch"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Augumented bonding curve Mathematics\n",
    "\n",
    "### Hatch Sale Equations\n",
    "\n",
    "- Initial Raise $d_0$ Dai\n",
    "- Initial Reserve is $R_0 = (1-\\theta) d_0$\n",
    "- Hatch sale Price $p_0$ (dai per token) determines the initial supply: $S_0 = d_0/p_0$\n",
    "- Power Function Invariant shape: $V(R, S) = \\frac{S^\\kappa}{R}$\n",
    "- Price function (DAI per Token): $P(R) = \\frac{\\kappa R^{(\\kappa-1)/ \\kappa}}{V_0^{1 / \\kappa}}$\n",
    "- Supply function (tokens): $S(R) = \\sqrt[\\kappa]{V_0 R}$\n",
    "- Reserve function (xDAI): $R(S) = \\frac{S^{\\kappa}}{V_0} $\n",
    "- The invariant coef: $V_0 = V(R_0, S_0) = \\frac{S_0^\\kappa}{R_0} = \\left(\\frac{1}{p_0(1-\\theta)}\\right)^\\kappa R_0^{\\kappa-1}$\n",
    "- The post hatch price: $p_1=P(R_0) = \\frac{\\kappa R_0^{(\\kappa-1)/ \\kappa}}{V_0^{1 / \\kappa}} = \\kappa R_0^{(\\kappa-1)/ \\kappa} \\cdot(1-\\theta)p_0\\cdot R_0^{-(\\kappa-1)/\\kappa} = \\kappa(1-\\theta) p_0$\n",
    "- The Return factor: $\\frac{p_1}{p_0} = {\\kappa}(1-\\theta)$\n",
    "\n",
    "### Invariant Preserving Deposit-to-Mint\n",
    " - Deposit $\\Delta R$ xdai \n",
    " - Conservation equation: $V(R+ \\Delta R, S+\\Delta S) = \\frac{(S+\\Delta S)^\\kappa}{R+\\Delta R} =V_0$\n",
    " - Derived Mint equation: $\\Delta S = mint\\big(\\Delta R ; (R,S)\\big)= \\sqrt[\\kappa]{V_0(R+\\Delta R)}-S$\n",
    " - Realized Price is: $\\bar{P}(\\Delta R) =\\frac{\\Delta R}{\\Delta S} = \\frac{\\Delta R}{\\sqrt[\\kappa]{V_0(R+\\Delta R)}-\\sqrt[\\kappa]{V_0(R)}} \\rightarrow \\big(\\frac{\\partial S(R)}{\\partial R} \\big)^{-1}$ as $\\Delta R \\rightarrow 0$\n",
    " - The limiting price is the spot price: $\\lim_{\\Delta R \\rightarrow 0} \\bar{P}(\\Delta R)=\\big(\\frac{\\partial S(R)}{\\partial R}\\big)^{-1}= \\big(\\frac{V_0^{1/\\kappa} \\cdot  R^{1/\\kappa-1}}{\\kappa}\\big)^{-1}= \\frac{\\kappa R^{1-1/\\kappa}}{V_0^{1/\\kappa}} = \\frac{\\kappa R^{(\\kappa-1)/\\kappa}}{V_0^{1/\\kappa}} =P(R)$\n",
    " \n",
    "### Invariant Preserving Burn-to-Withdraw\n",
    " - Burn $\\Delta S$ tokens\n",
    " - Conservation equation: $V(R- \\Delta R, S-\\Delta S) = \\frac{(S-\\Delta S)^\\kappa}{R-\\Delta R} =V_0$\n",
    " - Derived Withdraw equation: $\\Delta R = withdraw\\big(\\Delta S ; (R,S)\\big)= R-\\frac{(S-\\Delta S)^\\kappa}{V_0}$\n",
    " - Realized Price is: $\\bar{P}(\\Delta S) =\\frac{\\Delta R}{\\Delta S} = \\frac{\\frac{S^{\\kappa}}{V_0}-\\frac{(S-\\Delta S)^\\kappa}{V_0}}{\\Delta S} \\rightarrow \\frac{\\partial R(S)}{\\partial S} $ as $\\Delta S \\rightarrow 0$\n",
    " - The limiting price is the spot price: $\\lim_{\\Delta S \\rightarrow 0} \\bar{P}(\\Delta S)=\\frac{\\partial R(S)}{\\partial S}=\\frac{\\kappa S^{\\kappa-1}}{V_0} = \\frac{\\kappa \\cdot (\\sqrt[\\kappa]{V_0 R})^{\\kappa-1}}{V_0}= \\frac{\\kappa R^{(\\kappa-1)/\\kappa}}{V_0^{1/\\kappa}}=P(R)$\n",
    " - Given friction coef $\\phi$ \n",
    "     - sent to burning agent address: $\\Delta R_{agent} = (1-\\phi) \\Delta R$\n",
    "     - sent to the funding pool address: $\\Delta R_{pool} = \\phi \\Delta R$\n",
    "     - due to the friction the true realized price for the agent is $(1-\\phi)\\cdot \\bar{P}(\\Delta S)$\n",
    "     - due to the friction the true return factor post withdraw is: ${\\kappa}(1-\\theta)(1-\\phi)$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "#integer_units = 10**12 #account for decimal places to a token\n",
    "#scale_units = 10**6 #millions of tokens, million of DAI\n",
    "#mu = integer_units*scale_units\n",
    "\n",
    "#value function for a given state (R,S)\n",
    "def invariant(R,S,kappa):\n",
    "    return (S**kappa)/R\n",
    "\n",
    "#given a value function (parameterized by kappa)\n",
    "#and an invariant coeficient V0\n",
    "#return Supply S as a function of reserve R\n",
    "def supply(R, kappa, V0):\n",
    "    return (V0*R)**(1/kappa)\n",
    "\n",
    "#given a value function (parameterized by kappa)\n",
    "#and an invariant coeficient V0\n",
    "#return a spot price P as a function of reserve R\n",
    "def spot_price(R, kappa, V0):\n",
    "    return kappa*R**((kappa-1)/kappa)/V0**(1/kappa)\n",
    "\n",
    "#for a given state (R,S)\n",
    "#given a value function (parameterized by kappa)\n",
    "#and an invariant coeficient V0\n",
    "#deposit deltaR to Mint deltaS\n",
    "#with realized price deltaR/deltaS\n",
    "def mint(deltaR, R,S, kappa, V0):\n",
    "    deltaS = (V0*(R+deltaR))**(1/kappa)-S\n",
    "    realized_price = deltaR/deltaS\n",
    "    return deltaS, realized_price\n",
    "\n",
    "#for a given state (R,S)\n",
    "#given a value function (parameterized by kappa)\n",
    "#and an invariant coeficient V0\n",
    "#burn deltaS to Withdraw deltaR\n",
    "#with realized price deltaR/deltaS\n",
    "def withdraw(deltaS, R,S, kappa, V0):\n",
    "    deltaR = R-((S-deltaS)**kappa)/V0\n",
    "    realized_price = deltaR/deltaS\n",
    "    return deltaR, realized_price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x1a1d032438>"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 29524 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "X= np.arange(0,12, .01)\n",
    "vals = [1-1/2**x for x in X]\n",
    "\n",
    "vals3 = [1/2**x for x in X]\n",
    "plt.plot(X,vals, X, vals3)\n",
    "plt.xlabel('months')\n",
    "plt.ylabel('percent vested')\n",
    "plt.title('Vesting Schdule with 1 month vesting \"Half-Life\"')\n",
    "plt.legend([\"Share of hatch tokens Vested\", \"Share of Hatch tokens Locked\"])\n",
    "plt.vlines(3,0,1, linestyle ='-.')\n",
    "plt.text(3.2,.85, str(int(1000*7/8)/10)+ \"% of tokens vested after 3 months\" )\n",
    "plt.scatter(3,7/8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6001922786573871"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "10*10**6*vals3[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 34384 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "d0 = 1 #million DAI\n",
    "p0 = .10 #DAI per tokens\n",
    "theta = .35\n",
    "\n",
    "R0 =  d0*(1-theta) #million DAI\n",
    "S0 = d0/p0\n",
    "\n",
    "kappa = 6\n",
    "V0 = invariant(R0,S0,kappa)\n",
    "\n",
    "reserve = np.arange(0,100,.01)\n",
    "supp = np.array([supply(r,kappa, V0) for r in reserve])\n",
    "price = np.array([spot_price(r,kappa, V0) for r in reserve])\n",
    "\n",
    "fig, ax1 = plt.subplots()\n",
    "\n",
    "color = 'tab:red'\n",
    "ax1.set_xlabel('Reserve (Millions of xDAI)')\n",
    "ax1.set_ylabel('Supply (Millions of Tokens)', color=color)\n",
    "ax1.plot(reserve, supp,'--', color=color)\n",
    "ax1.tick_params(axis='y', labelcolor=color)\n",
    "\n",
    "ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis\n",
    "\n",
    "color = 'tab:blue'\n",
    "ax2.set_ylabel('Price in xDAI per Token', color=color)  # we already handled the x-label with ax1\n",
    "ax2.plot(reserve, price,'-.', color=color)\n",
    "ax2.tick_params(axis='y', labelcolor=color)\n",
    "\n",
    "ax1.vlines(R0,0,supp[-1], alpha=.5)\n",
    "ax1.text(R0+.02*reserve[-1], supp[-1], \"Initial Value R=\"+str(int(100*R0)/100)+\" mil xDAI\")\n",
    "ax1.text(R0+.02*reserve[-1], .95*supp[-1], \"Initial Value S=\"+str(S0)+\" mil Tokens\")\n",
    "#ax1.hlines(S0,0,R0)\n",
    "\n",
    "ax2.text(R0+.02*reserve[-1], price[3], \"Initial Value p1=\"+str(int(100*spot_price(R0,kappa,V0))/100))\n",
    "\n",
    "\n",
    "plt.title('Augmented Bonding Curve with Invariant S^'+str(kappa)+'/R')\n",
    "fig.tight_layout()  # otherwise the right y-label is slightly clipped\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33676 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax1 = plt.subplots()\n",
    "\n",
    "cp = 100\n",
    "color = 'tab:red'\n",
    "ax1.set_xlabel('Supply (Millions of Tokens)')\n",
    "ax1.set_ylabel('Reserve (Millions of xDAI)', color=color)\n",
    "ax1.plot(supp[cp:], reserve[cp:],'--', color=color)\n",
    "ax1.tick_params(axis='y', labelcolor=color)\n",
    "\n",
    "ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis\n",
    "\n",
    "color = 'tab:blue'\n",
    "ax2.set_ylabel('Price in xDAI per Token', color=color)  # we already handled the x-label with ax1\n",
    "ax2.plot(supp[cp:], price[cp:],'-.', color=color)\n",
    "ax2.tick_params(axis='y', labelcolor=color)\n",
    "\n",
    "ax1.vlines(S0,0,reserve[-1], alpha=.5)\n",
    "ax1.text(S0*1.02, reserve[-1], \"Initial Value S=\"+str(int(100*S0)/100)+\" mil tokens\")\n",
    "ax1.text(S0*1.02, .95*reserve[-1], \"Initial Value R=\"+str(R0)+\" mil xDAI\")\n",
    "#ax1.hlines(S0,0,R0)\n",
    "\n",
    "ax2.text(S0*1.02, price[3], \"Initial Value p1=\"+str(int(100*spot_price(R0,kappa,V0))/100))\n",
    "\n",
    "\n",
    "plt.title('Augmented Bonding Curve with Invariant S^'+str(kappa)+'/R')\n",
    "fig.tight_layout()  # otherwise the right y-label is slightly clipped\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "#given V0 and kappa\n",
    "#sweep the reserve\n",
    "reserve = None\n",
    "reserve = np.arange(.01,100,.01)\n",
    "price = np.array([spot_price(r,kappa, V0) for r in reserve])\n",
    "\n",
    "#realized price for withdrawing burning .1% of tokens\n",
    "withdraw_price=[withdraw(supply(r,kappa,V0)/1000, r,supply(r,kappa,V0), kappa, V0)[1] for r in reserve]\n",
    "\n",
    "#realized price for depositing .1% more Xdai into the reserve\n",
    "mint_price=[mint(r/1000, r, supply(r,kappa,V0), kappa, V0)[1] for r in reserve]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/jpeg": "[encoded data, 213992 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from IPython.display import Image\n",
    "Image(filename='slippage.jpeg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "pdf = pd.DataFrame({'reserve':reserve, 'spot_price':price, '.1% mint_price':mint_price,'.1% withdraw_price':withdraw_price })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1a1c3d5438>"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 17136 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "pdf.plot(x='reserve')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "pdf['mint_slippage'] = (pdf['.1% mint_price']-pdf['spot_price'])/pdf['spot_price']\n",
    "pdf['withdraw_slippage'] = (pdf['spot_price']-pdf['.1% withdraw_price'])/pdf['spot_price']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1a19c4dac8>"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 10944 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "pdf.plot(x='reserve', y = ['mint_slippage', 'withdraw_slippage'])#, logy=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    "#given V0 and kappa\n",
    "R = 20\n",
    "S = supply(R,kappa,V0)\n",
    "p = spot_price(R,kappa,V0)\n",
    "#sweep the transaction fraction\n",
    "TXF = np.logspace(-6, 0, num=1000)\n",
    "\n",
    "#realized price for withdrawing burning .1% of tokens\n",
    "withdraw_price2=[withdraw(S*txf, R,S, kappa, V0)[1] for txf in TXF]\n",
    "\n",
    "#realized price for depositing .1% more Xdai into the reserve\n",
    "mint_price2=[mint(R*txf, R,S, kappa, V0)[1] for txf in TXF]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17.701881934929794\n"
     ]
    }
   ],
   "source": [
    "print(S)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [],
   "source": [
    "pdf2 = pd.DataFrame({'tx_fraction':TXF, 'spot_price':p*np.ones(len(TXF)), 'mint_price':mint_price2,'withdraw_price':withdraw_price2 })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1a1dc5e9e8>"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 15316 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "pdf2.plot(x='tx_fraction',y=['mint_price','withdraw_price','spot_price'], logx=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [],
   "source": [
    "pdf2['mint_slippage'] = (pdf2['mint_price']-pdf2['spot_price'])/pdf2['spot_price']\n",
    "pdf2['withdraw_slippage'] = (pdf2['spot_price']-pdf2['withdraw_price'])/pdf2['spot_price']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 0, 'Transaction size as percent of the asset Burned or Bonded')"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 33912 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "pdf2.plot(x='tx_fraction', y = ['mint_slippage', 'withdraw_slippage'], logx=True, logy=True)\n",
    "plt.title(\"Friction for Bond and Withdraw accounting Without Exit Tax\")\n",
    "plt.ylabel(\"Percentage Change: Realized Price Relative to Spot Price\")\n",
    "plt.xlabel(\"Transaction size as percent of the asset Burned or Bonded\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "tax = .02\n",
    "pdf2['withdraw_slippage_with_tax'] = pdf2['withdraw_slippage']+tax"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 0, 'Transaction size as percent of the asset Burned or Bonded')"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 31804 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "pdf2.plot(x='tx_fraction', y = ['mint_slippage', 'withdraw_slippage_with_tax'], logx=True, logy=True)\n",
    "plt.title(\"Friction for Bond and Withdraw accounting for Exit Tax\")\n",
    "plt.ylabel(\"Percentage Change: Realized Price Relative to Spot Price\")\n",
    "plt.xlabel(\"Transaction size as percent of the asset Burned or Bonded\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 31132 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 35052 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 34384 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 35708 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "Kappa_List = [2,4,6,8]\n",
    "for kappa in Kappa_List:\n",
    "    \n",
    "    V0 = invariant(R0,S0,kappa)\n",
    "    \n",
    "    reserve = np.arange(0,100,.01)\n",
    "    supp = np.array([supply(r,kappa, V0) for r in reserve])\n",
    "    price = np.array([spot_price(r,kappa, V0) for r in reserve])\n",
    "\n",
    "    fig, ax1 = plt.subplots()\n",
    "\n",
    "    color = 'tab:red'\n",
    "    ax1.set_xlabel('Reserve (Millions of xDAI)')\n",
    "    ax1.set_ylabel('Supply (Millions of Tokens)', color=color)\n",
    "    ax1.plot(reserve, supp,'--', color=color)\n",
    "    ax1.tick_params(axis='y', labelcolor=color)\n",
    "\n",
    "    ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis\n",
    "\n",
    "    color = 'tab:blue'\n",
    "    ax2.set_ylabel('Price in xDAI per Token', color=color)  # we already handled the x-label with ax1\n",
    "    ax2.plot(reserve, price,'-.', color=color)\n",
    "    ax2.tick_params(axis='y', labelcolor=color)\n",
    "\n",
    "    ax1.vlines(R0,0,supp[-1], alpha=.5)\n",
    "    ax1.text(R0+.02*reserve[-1], supp[-1], \"Initial Value R=\"+str(int(100*R0)/100)+\" mil xDAI\")\n",
    "    ax1.text(R0+.02*reserve[-1], .95*supp[-1], \"Initial Value S=\"+str(int(100*S0)/100)+\" mil Tokens\")\n",
    "    #ax1.hlines(S0,0,R0)\n",
    "\n",
    "    ax2.text(R0+.02*reserve[-1], price[3], \"Initial Value p1=\"+str(int(1000*spot_price(R0,kappa,V0))/1000))\n",
    "\n",
    "\n",
    "    plt.title('Augmented Bonding Curve with Invariant S^'+str(kappa)+'/R')\n",
    "    fig.tight_layout()  # otherwise the right y-label is slightly clipped\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Power function independent variables for analysis\n",
    "vec_d0 = np.arange(2.5,5.1,.1) #millon dai\n",
    "vec_theta = np.arange(.1,.55,.05) #unitless\n",
    "mat_R0 = np.outer(vec_d0.T, (1-vec_theta)) #million dai\n",
    "vec_p0 = np.arange(.01,.11,.01) #dai per token\n",
    "mat_S0 = np.outer(vec_d0.T, vec_p0) #milion tokens\n",
    "vec_kappa = np.arange(2,9,1) #integer\n",
    "\n",
    "mat_return_ratio = np.outer(vec_kappa.T, (1-vec_theta))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Hatch Return Rate p1/p0')"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 36776 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p0_lab = [str(int(100*p)/100) for p in vec_p0] \n",
    "th_lab = [str(int(100*th)/100) for th in vec_theta]\n",
    "k_lab = [str(k) for k in vec_kappa] \n",
    "sns.heatmap(mat_return_ratio.T,yticklabels=th_lab, xticklabels=k_lab, annot=True)\n",
    "plt.yticks(rotation=0)\n",
    "plt.xlabel('Invariant Power: Kappa')\n",
    "plt.ylabel('Funding Pool Fraction: Theta')\n",
    "plt.title('Hatch Return Rate p1/p0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Funding Pool Funds at Launch (Millions of xDAI)')"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 18948 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "d_lab = [str(int(100*d)/100) for d in vec_d0] \n",
    "sns.heatmap(vec_d0-mat_R0.T,yticklabels=th_lab, xticklabels=d_lab)#, annot=True)\n",
    "plt.yticks(rotation=0)\n",
    "\n",
    "plt.xlabel('Initial Fundraise: d0 (Millions of xDAI)')\n",
    "plt.ylabel('Funding Pool Fraction: Theta')\n",
    "plt.title('Funding Pool Funds at Launch (Millions of xDAI)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 15.0, 'Intial Raise d0 (Millions of xDAI)')"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 18880 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "d_lab = [str(int(100*d)/100) for d in vec_d0] \n",
    "sns.heatmap(mat_R0.T,yticklabels=th_lab, xticklabels=d_lab)#, annot=True)\n",
    "plt.yticks(rotation=0)\n",
    "\n",
    "plt.title('Initial Reserve: R0 (Millions of xDAI)')\n",
    "plt.ylabel('Funding Pool Fraction: Theta')\n",
    "plt.xlabel('Intial Raise d0 (Millions of xDAI)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 15.0, 'Intial Raise d0 (Millions of xDAI)')"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 20796 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.heatmap(mat_S0.T,yticklabels=p0_lab, xticklabels=d_lab)#, annot=True)\n",
    "plt.yticks(rotation=0)\n",
    "\n",
    "plt.title('Initial Supply: S0 (Millions of Tokens)')\n",
    "plt.ylabel('Hatch Sale Price: p0 (xDAI per Token)')\n",
    "plt.xlabel('Intial Raise d0 (Millions of xDAI)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
