diff --git a/hydradx/spec/Swap.ipynb b/hydradx/spec/Swap.ipynb index 136110ce..44e1b466 100644 --- a/hydradx/spec/Swap.ipynb +++ b/hydradx/spec/Swap.ipynb @@ -66,8 +66,10 @@ "$$\n", "\\begin{align}\n", "\\tilde{\\Delta Q_j} &= Q_j\\frac{- \\Delta R_j}{R_j(1 - f_A) + \\Delta R_j}\\\\\n", - "\\tilde{\\Delta Q_i} &= -\\frac{\\tilde{\\Delta Q_j}}{1 - f_P}\\\\\n", - "\\Delta R_i &= R_i\\frac{- \\tilde{\\Delta Q_i}}{Q_i + \\tilde{\\Delta Q_i}}\n", + "\\tilde{\\Delta Q_i} &= -\\frac{\\tilde{\\Delta Q_j}}{1 - f_Q}\\\\\n", + "\\Delta R_i &= R_i\\frac{- \\tilde{\\Delta Q_i}}{Q_i + \\tilde{\\Delta Q_i}}\\\\\n", + "\\Delta Q_j^m &= f_A\\frac{(Q_j + \\tilde{\\Delta Q_j})\\tilde{\\Delta Q_j}}{Q_j}\\\\\n", + "\\Delta Q_j &= \\tilde{\\Delta Q_j} + \\Delta Q_j^m\n", "\\end{align}\n", "$$\n", "\n", @@ -91,9 +93,11 @@ "$$\n", "\\begin{align}\n", "\\Delta Q_i &= Q_i\\frac{- \\Delta R_i}{R_i + \\Delta R_i}\\\\\n", - "\\Delta Q_j' &= -\\Delta Q_i (1 - f_P)\\\\\n", + "\\Delta Q_j' &= -\\Delta Q_i (1 - f_Q)\\\\\n", "\\Delta R_j' &= R_j\\frac{- \\Delta Q_j'}{Q_j + \\Delta Q_j'}\\\\\n", - "\\Delta R_j &= \\Delta R_j'(1 - f_A)\n", + "\\Delta R_j &= \\Delta R_j'(1 - f_A)\\\\\n", + "\\Delta Q_j^m &= f_A \\frac{R_j \\Delta Q_j'}{R_j + \\Delta R_j'}\\\\\n", + "\\Delta Q_j &= \\Delta Q_j' + \\Delta Q_j^m\n", "\\end{align}\n", "$$" ] @@ -111,52 +115,18 @@ "id": "826aedb1-dcd5-4b35-8f81-7cc5ca6faad2", "metadata": {}, "source": [ - "The LRNA fee amount is $-\\Delta Q_i f_P$, and it is burned until $L$ is brought up to $0$, at which point fees are moved to the LRNA side of the HDX sub-pool in Omnipool.\n", + "The total LRNA fee amount is $-\\Delta Q_i f_Q$, where $f_Q$ is the LRNA fee. We will burn some of it, and the rest will be used to buy HDX which will be sent to treasury.\n", + "Our dynamic LRNA fee will be $f_Q$ while $f_B$ will be some fixed fee corresponding to the LRNA that gets burned. Note that we require $f_B \\leq f_Q$.\n", "$$\n", "\\begin{align}\n", - "\\Delta L &= min(-\\Delta Q_i f_P, -L)\\\\\n", - "\\Delta Q_H &= -\\Delta Q_i f_P - \\Delta L\n", + "\\Delta Q_B &= -\\Delta Q_i f_B\\\\\n", + "\\Delta Q_H &= -\\Delta Q_i f_Q - \\Delta Q_B\n", "\\end{align}\n", "$$\n", - "where $Q_H$ is the LRNA side of the HDX sub-pool.\n", + "where $\\Delta Q_B$ is the amount of LRNA that gets burned, and $\\Delta Q_H$ is the amount of LRNA that is used to buy HDX.\n", "\n" ] }, - { - "cell_type": "markdown", - "id": "e4ce191c-569b-424f-b494-1ffefd0b2116", - "metadata": {}, - "source": [ - "## Direct calculation (updating pool state)\n", - "### $\\Delta R_i > 0$ provided\n", - "$$\n", - "\\begin{align}\n", - "\\Delta Q_i &= Q_i \\frac{-\\Delta R_i}{R_i + \\Delta R_i}\\\\\n", - "\\Delta Q_j &= -\\Delta Q_i(1 - f_P)\\\\\n", - "\\Delta R_j &= R_j \\frac{-\\Delta Q_j}{Q_j + \\Delta Q_j}(1 - f_A)\\\\\n", - "\\Delta L &= min(-\\Delta Q_i f_P, -L)\\\\\n", - "\\Delta Q_H &= -\\Delta Q_i f_P - \\Delta L\n", - "\\end{align}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "549adee6-8c99-4801-be86-10c77b584467", - "metadata": {}, - "source": [ - "### $\\Delta R_j < 0$ provided\n", - "$$\n", - "\\begin{align}\n", - "\\Delta Q_j &= Q_j\\frac{-\\Delta R_j}{R_j(1 - f_A) + \\Delta R_j}\\\\\n", - "\\Delta Q_i &= -\\frac{\\Delta Q_j}{1 - f_P}\\\\\n", - "\\Delta R_i &= R_i\\frac{-\\Delta Q_i}{Q_i + \\Delta Q_i}\\\\\n", - "\\Delta L &= min(-\\Delta Q_i f_P, -L)\\\\\n", - "\\Delta Q_H &= -\\Delta Q_i f_P - \\Delta L\n", - "\\end{align}\n", - "$$" - ] - }, { "cell_type": "markdown", "id": "7ac04084-09e9-4e27-bdea-d4deed673ce3", @@ -172,8 +142,10 @@ "source": [ "We have\n", "$$\n", - "\\Delta r^\\alpha_i = -\\Delta R_i\\\\\n", - "\\Delta r^\\alpha_j = -\\Delta R_j\n", + "\\begin{align}\n", + "\\Delta r^\\alpha_i &= -\\Delta R_i\\\\\n", + "\\Delta r^\\alpha_j &= -\\Delta R_j\n", + "\\end{align}\n", "$$" ] }, diff --git a/hydradx/spec/SwapLRNA.ipynb b/hydradx/spec/SwapLRNA.ipynb index 6dc0b6b3..e8565966 100644 --- a/hydradx/spec/SwapLRNA.ipynb +++ b/hydradx/spec/SwapLRNA.ipynb @@ -78,9 +78,19 @@ "source": [ "### Case 1: LRNA sold, $\\Delta q^\\alpha < 0$ specified\n", "\n", - "If $-\\Delta q^\\alpha > q^\\alpha$, the user does not have enough LRNA to sell, and the transaction must fail." + "If $-\\Delta q^\\alpha > q^\\alpha$, the user does not have enough LRNA to sell, and the transaction must fail.\n", + "We first calculate the feeless amount $\\Delta R_i'$. We next calculate the amount of LRNA we will mint to match the asset fee $\\Delta Q_m$.\n", + "The total amount of asset $i$ coming out is $\\Delta R_i$, while the total change in LRNA in the pool (incorporating both the LRNA sold to the pool and the LRNA minted) is $\\Delta Q_i$." ] }, + { + "metadata": {}, + "cell_type": "code", + "outputs": [], + "execution_count": null, + "source": "", + "id": "653a53e961b30275" + }, { "cell_type": "markdown", "id": "4554c820-71a3-4981-92ea-3442640e4537", @@ -88,9 +98,10 @@ "source": [ "$$\n", "\\begin{align}\n", - "\\Delta Q_i &= -\\Delta q^\\alpha\\\\\n", - "\\Delta R_i &= R_i\\frac{- \\Delta Q_i}{Q_i + \\Delta Q_i}(1 - f_A)\\\\\n", - "\\Delta L &= -\\frac{\\Delta Q_i (Q + L)}{Q + \\Delta Q_i} - \\Delta Q_i\\\\\n", + "\\Delta R_i' &= R_i\\frac{\\Delta q^\\alpha}{Q_i -\\Delta q^\\alpha}\\\\\n", + "\\Delta Q_m &= -\\frac{f_A \\Delta q^\\alpha(Q_i -\\Delta q^\\alpha)}{Q_i}\\\\\n", + "\\Delta R_i &= \\Delta R_i'(1-f_A)\\\\\n", + "\\Delta Q_i &= -\\Delta q^\\alpha + \\Delta Q_m\\\\\n", "\\Delta r_i^\\alpha &= - \\Delta R_i\\\\\n", "\\end{align}\n", "$$" @@ -132,9 +143,9 @@ "$$\n", "\\begin{align}\n", "\\Delta R_i &= -\\Delta r_i^\\alpha\\\\\n", - "\\Delta Q_i &= Q_i\\frac{-\\Delta R_i}{R_i(1 - f_A) + \\Delta R_i}\\\\\n", - "\\Delta L &= -\\frac{\\Delta Q_i (Q + L)}{Q + \\Delta Q_i} - \\Delta Q_i\\\\\n", - "\\Delta q^\\alpha &= - \\Delta Q_i\\\\\n", + "\\Delta q^\\alpha &= Q_i\\frac{\\Delta R_i}{R_i(1 - f_A) + \\Delta R_i}\\\\\n", + "\\Delta Q_m &= -\\frac{f_A(Q_i -\\Delta q^\\alpha)\\Delta R_i}{R_i(1 - f_A) + \\Delta R_i}\\\\\n", + "\\Delta Q_i &= -\\Delta q^\\alpha + \\Delta Q_m\\\\\n", "\\end{align}\n", "$$\n", "\n", @@ -199,7 +210,8 @@ "source": [], "metadata": { "collapsed": false - } + }, + "id": "c8ec5d4b56e4a375" } ], "metadata": {