|
| 1 | +# Asymmetric Liquidity Adds |
| 2 | + |
| 3 | +Sifnoded does not currently support asymmetric liquidity adds. This document proposes a procedure |
| 4 | +which would allow asymmetric adds. |
| 5 | + |
| 6 | +## Symmetric Adds |
| 7 | + |
| 8 | +When adding symmetrically to a pool the fraction of total pool units owned by the Liquidity Provider (LP) |
| 9 | +after the add must equal the amount of native token added to the pool as a fraction of total native asset token in the |
| 10 | +pool (after the add): |
| 11 | + |
| 12 | +``` |
| 13 | +l / (P + l) = r / (r + R) |
| 14 | +``` |
| 15 | + |
| 16 | +Where: |
| 17 | +``` |
| 18 | +l - LP units |
| 19 | +P - total pool units (before) |
| 20 | +r - amount of native token added |
| 21 | +R - native asset pool depth (before) |
| 22 | +``` |
| 23 | +Rearranging gives: |
| 24 | + |
| 25 | +``` |
| 26 | +(1) l = r * P / R |
| 27 | +``` |
| 28 | + |
| 29 | +## Asymmetric adds |
| 30 | + |
| 31 | +In the asymmetric case, by definition: |
| 32 | + |
| 33 | +``` |
| 34 | +R/A =/= r/a |
| 35 | +``` |
| 36 | + |
| 37 | +(this includes the case where the division is not defined i.e. when a=0 the division is not defined |
| 38 | +in which case the add is considered asymmetric) |
| 39 | + |
| 40 | +Where: |
| 41 | +``` |
| 42 | +R - native asset pool depth (before adding liquidity) |
| 43 | +A - external asset pool depth (before adding liquidity) |
| 44 | +r - amount of native token added |
| 45 | +a - amount of external token added |
| 46 | +``` |
| 47 | +Currently sifnoded blocks asymmetric adds. The following procedure is proposed to enable |
| 48 | +asymmetric adds. |
| 49 | + |
| 50 | +### Proposed method |
| 51 | + |
| 52 | +In the following formulas: |
| 53 | + |
| 54 | +``` |
| 55 | +p - current ratio shifting running rate |
| 56 | +f - swap fee rate |
| 57 | +``` |
| 58 | + |
| 59 | +If the pool is not in the same ratio as the add then either: |
| 60 | + |
| 61 | +1. Some r must be swapped for a, such that after the swap the add is symmetric |
| 62 | +2. Some a must be swapped for r, such that after the swap the add is symmetric |
| 63 | + |
| 64 | +#### Swap native token for external token |
| 65 | + |
| 66 | +Swap an amount, s, of native token such that: |
| 67 | + |
| 68 | +``` |
| 69 | +(R + s) / (A - g.s) = (R + r) / (A + a) = (r − s) / (a + g.s) |
| 70 | +``` |
| 71 | + |
| 72 | +where g is the swap formula: |
| 73 | + |
| 74 | +``` |
| 75 | +g.x = (1 - f) * (1 + r) * x * Y / (x + X) |
| 76 | +``` |
| 77 | + |
| 78 | +Solving for s (using mathematica!) gives: |
| 79 | + |
| 80 | +``` |
| 81 | +s = abs((sqrt(pow((-1*f*p*A*r-f*p*A*R-f*A*r-f*A*R+p*A*r+p*A*R+2*a*R+2*A*R), 2)-4*(a+A)*(a*R*R-A*r*R)) + f*p*A*r + f*p*A*R + f*A*r + f*A*R - p*A*r - p*A*R - 2*a*R - 2*A*R) / (2 * (a + A))). |
| 82 | +``` |
| 83 | + |
| 84 | +The number of pool units is then given by the symmetric formula (1): |
| 85 | + |
| 86 | +``` |
| 87 | +l = (r - s) * P / (R + s) |
| 88 | +``` |
| 89 | + |
| 90 | +#### Swap external token for native token |
| 91 | + |
| 92 | +Swap an amount, s, of native token such that: |
| 93 | + |
| 94 | +``` |
| 95 | +(R - s) / (A + g'.s) = (R + r) / (A + a) = (r + g'.s) / (a - s) |
| 96 | +``` |
| 97 | + |
| 98 | +Where g' is the swap formula: |
| 99 | + |
| 100 | +``` |
| 101 | +g' = (1 - f) * x * Y / ((x + X) * (1 + r)) |
| 102 | +``` |
| 103 | + |
| 104 | +Solving for s (using mathematica!) gives: |
| 105 | + |
| 106 | +``` |
| 107 | +s = abs((sqrt(R*(-1*(a+A))*(-1*f*f*a*R-f*f*A*R-2*f*p*a*R+4*f*p*A*r+2*f*p*A*R+4*f*A*r+4*f*A*R-p*p*a*R-p*p*A*R-4*p*A*r-4*p*A*R-4*A*r-4*A*R)) + f*a*R + f*A*R + p*a*R - 2*p*A*r - p*A*R - 2*A*r - 2*A*R) / (2 * (p + 1) * (r + R))) |
| 108 | +``` |
| 109 | + |
| 110 | +The number of pool units is then given by the symmetric formula (1): |
| 111 | + |
| 112 | +``` |
| 113 | +l = (a - s) * P / (A + s) |
| 114 | +``` |
| 115 | + |
| 116 | +### Equivalence with swapping |
| 117 | + |
| 118 | +Any procedure which assigns LP units should guarantee that if an LP adds (x,y) then removes all their |
| 119 | +liquidity from the pool, receiving (x',y') then it is never the case that x' > x and y' > y (all else being equal i.e. |
| 120 | +no LPD, rewards etc.). Furthermore |
| 121 | +assuming (without loss of generality) that x' =< x, if instead of adding to the pool then removing all liquidity |
| 122 | +the LP had swapped (x - x'), giving them a total of y'' (i.e. y'' = y + g.(x - x')), then y'' should equal y'. (Certainly y' cannot be greater than y'' otherwise |
| 123 | +the LP has achieved a cheap swap.) |
| 124 | + |
| 125 | +In the case of the proposed add liquidity procedure the amount the LP would receive by adding then removing would equal the amounts |
| 126 | +of each token after the internal swap (at this stage the add is symmetric and with symmetric adds x' = x and y' = y), that is: |
| 127 | +``` |
| 128 | +(2) x' = x - s |
| 129 | +(3) y' = y + g.s |
| 130 | +``` |
| 131 | +Plugging these into the equation for y'', y'' = y + g.(x - x'): |
| 132 | +``` |
| 133 | +y'' = y + g.(x - x') |
| 134 | + = y + g.s by rearranging (2) and substituting |
| 135 | + = y' by substituting (3) |
| 136 | +``` |
| 137 | +### Liquidity Protection |
| 138 | + |
| 139 | +Since the add liquidity process involves swapping then the Liquidity protection procedure must be applied. |
| 140 | + |
| 141 | +## References |
| 142 | + |
| 143 | +Detailed derivation of formulas https://hackmd.io/NjvaZY1qQiS17s_uEgZmTw?both |
0 commit comments