# Asymmetric liquidity add The Sifchain Liquidity Provider system supports asymmmetric liquidity addition and removal. Liquidity Providers will be able to add $s$ Rowan to an exisiting liquidity pool without requiring any M-tokens or add $m$ M-tokens to an exisiting liquidity pool without requiring any Rowan. Likewise, they would be able to remove $s$ Rowan without M-tokens or remove $m$ M-tokens without Rowan. To support this process, we propose a composite mechanism that utilizes two existing primary mechanisms - **Add or Remove Liquidity** and **Swap**. The **Add or Remove Liquidity** mechanism supports symmetric additions and removals, i.e the Liquidity Provider would need to send both $s$ Rowan and $m$ M-tokens in a specific ratio in order to add liquidity. Similarly, the liquidity provider would receive both $s$ Rowan and $m$ M-tokens in a specific ratio when removing liquidity. We compose a composite **Asymmetric Liquidity Add or Remove** mechanism that first performs a **Swap** to obtain the complementary token and uses it to **Add or Remove Liquidity** in a symmetric fashion. To the user, this would appear to be an **Asymmetric Liquidity Add or Remove** as all the intermediate steps are executed in the back end. ## Asymmetric Liquidity Add A liqudity provider wants to add $s= {\Delta \mathbf S}$ Rowan to an exisiting liquidity pool. The liquidity provider does not provide any M-token to perform this action, thus making it an asymmetric liquidity add. $$ m = {\Delta \mathbf M} =0 $$ The next state after this $s$ Rowan has been added should be: $$ \mathbf S^+ = \mathbf S+s\\ \mathbf M^+ = \mathbf M $$ To accomplish the asymmetric liqudity add usign the symmetric **Add Liquidity** and **Swap** methods, we partition $s$ as follows: $$ s = s_{swap} + s_{add} + dust \\ s_{swap} = \mu s\\ s_{add} = (1-\mu) s $$ where $\mu$ is the curvature such that $$m_{swap} = f(s_{swap}, \mathbf S, \mathbf M)\\ m_{add} = (\mathbf M-m_{swap}) \frac{s_{add}}{\mathbf S+s_{swap}}$$ We know that $$ \mathbf M^+ = \mathbf M - m_{swap} + m_{add} = \mathbf M$$ For this to hold true, $$m_{swap} = m_{add}$$ Substituting $m_{swap} = f_{swap}(s_{swap}, \mathbf S, \mathbf M)$ and $m_{add} = (\mathbf M-m_{swap}) \frac{s_{add}}{S+s_{swap}}$ to represent all references to $m$ in terms to $s$, we get $$m_{swap} = f_{swap}(s_{swap}, \mathbf S,\mathbf M) = (M-f_{swap}(s_{swap}, \mathbf S, \mathbf M)) \frac{s_{add}}{\mathbf S+s_{swap}}$$ Next, we solve for $s_{swap}$ in terms of the parametrized swap fee $f_{swap}$. The general form of the parametrized swap fee is given by $$y = f_{swap}(x, \mathbf X,\mathbf Y) = \lambda_l\frac{\mathbf x \mathbf{Y}}{x +\mathbf{X}}\left(1 - \frac{\mathbf{X}}{(x+\mathbf{X})} \right) $$ Plugging in - $m_{swap} = f_{swap}(s_{swap}, \mathbf S,\mathbf M) = \lambda_l\frac{s_{swap} \mathbf{M_L}}{s_{swap}+\mathbf{S_L}}\left(1 - \frac{\mathbf{S_L}}{(s_{swap}+\mathbf{S_L})} \right)$ - $m_{add} = (\mathbf M-m_{swap}) \frac{s_{add}}{S+s_{swap}}$ we get $$ \lambda_l\frac{s_{swap} \mathbf{M_L}}{s_{swap}+\mathbf{S_L}}\left(1 - \frac{\mathbf{S_L}}{(s_{swap}+\mathbf{S_L})} \right) = \left\{\mathbf M-\left[\lambda_l\frac{s_{swap} \mathbf{M_L}}{s_{swap}+\mathbf{S_L}}\left(1 - \frac{\mathbf{S_L}}{(s_{swap}+\mathbf{S_L})} \right)\right]\right\} \frac{s_{add}}{\mathbf S+s_{swap}} $$ We have solved for $s_{swap}$ using the Wolfram Solvers below. [Wolfram Solver 1](https://www.wolframalpha.com/input/?i=solve+for+x+in+L*%28%28x*M%29%2F%28x%2BS%29%29*%281-%28S%2F%28x%2BS%29%29%29+%3D+%7BM+-+%5BL*%28x*M%2F%28x%2BS%29%29*%281-%28S%2F%28x%2BS%29%29%29%5D%7D*%5By%2F%28x%2BS%29%5D) where $x = s_{swap}, y = s_{add}, M = \mathbf M_L, S = \mathbf S_L$ and $L = \lambda_l$ [Wolfram Solver 2](https://www.wolframalpha.com/input/?i=solve+for+x+in+L*%28%28x*M%29%2F%28x%2BS%29%29*%281-%28S%2F%28x%2BS%29%29%29*%281%2B%28y%2F%28x%2BS%29%29%29+%3D+%7BM*%5By%2F%28x%2BS%29%5D%7D) where $x = s_{swap}, y = s_{add}, M = \mathbf M_L, S = \mathbf S_L$ and $L = \lambda_l$ Thus we have decomposed $s = s_{swap} + s_{add}$. The resulting composition also satisifies $m_{swap} = m_{add}$. This gives the next state: $$ \mathbf S^+ = \mathbf S+\mu s+(1-\mu)s = \mathbf S+s_{swap}+s_{add}\\ \mathbf M^+ = \mathbf M - m_{swap} + m_{add} = \mathbf M $$ where $$\mu = \frac{s_{swap}}{s}$$ Psuedo-code: ``` def asymmetric_liquidy_add(s): Step 1: Solve for pre_s_swap = s_swap + dust Step 2: Swap s_swap for m_swap Step 3: Symmetric liquidity add (s-s_swap, m_swap) ``` ## Asymmetric Liquidity Remove A liqudity provider wants to remove $s= {\Delta \mathbf S}$ Rowan from an exisiting liquidity pool. The liquidity provider does not provide any M-token to perform this action, thus making it an asymmetric liquidity remove. $$ m = {\Delta \mathbf M} =0 $$ The next state after this $s$ Rowan has been removed should be: $$ \mathbf S^+ = \mathbf S-s\\ \mathbf M^+ = \mathbf M $$ To accomplish the asymmetric liqudity remove using the symmetric **Remove Liquidity** and **Swap** methods, we partition $s$ as follows: $$ s_{swap} = \omega s\\ s_{rem} = (1-\omega) s $$ where $\omega$ is the fraction of the liquidity stake being burned. $$\omega = s_{rem}/\mathbf S$$ In the case of a symmetric liquidity remove, the liquidity provider would get $s_{rem}$ and $m_{rem}$ after the remove $$ s_{rem}=\omega \mathbf S\\ m_{rem}=\omega \mathbf M $$ making the next state $$ \mathbf S^+ = (1-\omega)\mathbf S\\ \mathbf M^+ = (1-\omega)\mathbf M $$ For the remove to be assymetric, we need to satisfy the condition $$\mathbf M^+ = \mathbf M$$ For this, we require $m_{swap} = m_{rem}$, so that $$\mathbf M^+ = \mathbf M - m_{rem} + m_{swap} = \mathbf M$$ So we define $$m_{swap} = m_{rem} = \omega M$$ Therefore, the liquidity provider receives $s$ Rowan after the asymmetric liquidity remove $$s = s_{rem} + s_{swap}$$ where $$s_{swap} = f(m_{swap}, \mathbf S^+, \mathbf M^+) = f(m_{swap}, (1-\omega)\mathbf S, (1-\omega)\mathbf M)$$ We know that the parametrized swap fee $f_{swap}$ is $$s_{swap} = f_{swap}(m, \mathbf {M_L},\mathbf {S_L}) = \lambda_l\frac{ m \mathbf{S_L}}{ m+\mathbf{M_L}}\left(1 - \frac{\mathbf{M_L}}{{m}+\mathbf{M_L}} \right) $$ Expressing the parametrized swap fee as a function of $m$ being $m_{swap}$ with - $\mathbf {S_L}$ being $(1-\omega)\mathbf S$ - $\mathbf {M_L}$ being $(1-\omega)\mathbf M$ we have $$ f(m_{swap}, (1-\omega)\mathbf S, (1-\omega)\mathbf M) = \lambda_l\frac{m_{swap} (1-\omega)\mathbf S}{m_{swap}+(1-\omega)\mathbf M}\left(1 - \frac{(1-\omega)\mathbf M}{{m_{swap}}+(1-\omega)\mathbf M} \right) $$ This is $s_{swap}$, since $s_{swap} = f(m_{swap}, (1-\omega)\mathbf S, (1-\omega)\mathbf M)$ $$ s_{swap} = \lambda_l\frac{m_{swap} (1-\omega)\mathbf S}{m_{swap}+(1-\omega)\mathbf M}\left(1 - \frac{(1-\omega)\mathbf M}{{m_{swap}}+(1-\omega)\mathbf M} \right) $$ But since the liquidity provider has put $m_{swap} = m_{rem}$ back into the pool via the Swap mechanism the total state change is actually $$ \mathbf S^{++} = \mathbf S - s_{rem} - s_{swap} = = \mathbf S-\omega \mathbf S - f(m_{swap}, \mathbf S^+, \mathbf M^+)\\ \mathbf M^{++} = \mathbf M - m_{rem} + m_{swap} = \mathbf M $$ Psuedo-code: ``` def asym_liquidy_rem(w): Step 1: Symmetric liquidity remove of w => (s_rem,m_rem) Step 2: Then Swap m_rem for s_swap Step 3: total liqudity removed = s_rem + s_swap ``` --------- --------- --------- NOTES --------- Quantity of tokens to add to the Liquidity $s=\Delta S$, with $m = \Delta M =0$. This 'net' state change: $$ S^+ = S+s\\ M^+ = M $$ how can we accomplish this with the swamp and existing symmetric liquidity add method? Partition $s$ as follows: $$ s_{swap} = \mu s\\ s_{add} = (1-\mu) s $$ such that $m_{swap} = f(s_{swap}, S, M)$ and $m_{add} = (M-m_{swap}) \frac{s_{add}}{S+s_{swap}}$ recalling that $M^+ = M - m_{swap} + m_{add} = M$ we require that $m_{swap} = m_{add}$ therefore $f(s_{swap}, S, M) = (M-f(s_{swap}, S, M)) \frac{s_{add}}{S+s_{swap}}$ --- $f(s_{swap}, S, M) = (M-f(s_{swap}, S, M)) \frac{S-s_{swap}}{S+s_{swap}}$ ATTN: we need to solve for $s_{swap}$ --- if we were to plug in our specific fee rule we could knock out $f(\cdot, S, M)$ abstraction and simplify analytically. What is that we have decomposed $s = s_{swap} + s_{add}$ and the resulting composition also satisifies $m_{swap} = m_{add}$. clarify $\mu = \frac{s_{swap}}{s}$ Psuedo-code: ``` def asym_liquidy_add(s): solve for s_swap swap s_swap for m_swap symmetric liquidity add (s-s_swap, m_swap) ``` ## consider asymmetric liquidity removal $$ S^+ = S-s\\ M^+ = M $$ there some fraction of the LP stake being burned $\omega$ as the liquidity remover I would get $s_{rem}= \omega S$ $m_{rem}= \omega M$ and the systems posterior state would be $S^+ = (1-\omega)S$ $M^+ = (1-\omega)M$ BUT we need to compose with a swap in order to receive only tokens of type s. so define $m_{swap} = m_{rem} = \omega M$ and therefore my actually take is: $s = s_{rem} + s_{swap}$ where $s_{swap} = f(m_{swap}, (1-\omega)S, (1-\omega)M)$ but since i've put $m_{swap} = m_{rem}$ back into the pool via the swap mechanism the total state change is actually $$ S^{++} = S - \omega s - s_{swap} = S-\omega s - f(m_{swap}, S^+, M^+)\\ M^{++} = M = M - m_{rem} + m_{swap} $$ Psuedo-code: ``` def asym_liquidy_rem(w): symmetric liquidity remove of w => (s_rem,m_rem) then swap m_rem for s_swap total out = s_rem + s_swap ```