numotrade / numo

🤖 Smart contract suite for Numo.
https://docs.numo.trade
Other
0 stars 0 forks source link

Implement capped power invariant with precision #14

Closed robertleifke closed 1 month ago

robertleifke commented 1 month ago

This PR implements a CFMM with the quartic invariant where the power is 4, and the invariant must be greater than or equal to zero. Since the invariant involves a fractional exponent, it requires a high precision fixed point arithmetic to make sure the invariant rounds close to zero. Therefore we use the UD60x18 type from the PRBMath library.

The invariant is $0 = \frac{x}{L} - {({p_1}^{3} - \frac{3}{4} \frac{y}{L})}^{\frac{4}{3}}$ but simplifies to $scale0 >= {({strike}^{3} - \frac{3}{4} scale1)}^{\frac{4}{3}}$

Learn more here: https://hackmd.io/@Z6CPUVWyQV-cMF924gYOVg/BJPg-dl_R