diff --git a/crates/hyperdrive-math/src/long/fees.rs b/crates/hyperdrive-math/src/long/fees.rs index 2db0bd60b..a2dc9244d 100644 --- a/crates/hyperdrive-math/src/long/fees.rs +++ b/crates/hyperdrive-math/src/long/fees.rs @@ -12,7 +12,6 @@ impl State { /// c(x) = \phi_{c} \cdot \left( \tfrac{1}{p} - 1 \right) \cdot x /// $$ pub fn open_long_curve_fees(&self, base_amount: FixedPoint) -> FixedPoint { - // curve fee = ((1 / p) - 1) * phi_curve * dz self.curve_fee() * ((fixed!(1e18) / self.get_spot_price()) - fixed!(1e18)) * base_amount } @@ -36,7 +35,7 @@ impl State { bond_amount: FixedPoint, normalized_time_remaining: FixedPoint, ) -> FixedPoint { - // ((1 - p) * phi_curve * d_y * t) / c + // curve_fee = ((1 - p) * phi_curve * d_y * t) / c self.curve_fee() * (fixed!(1e18) - self.get_spot_price()) * bond_amount.mul_div_down(normalized_time_remaining, self.vault_share_price()) @@ -49,7 +48,7 @@ impl State { bond_amount: FixedPoint, normalized_time_remaining: FixedPoint, ) -> FixedPoint { - // flat fee = (d_y * (1 - t) * phi_flat) / c + // flat_fee = (d_y * (1 - t) * phi_flat) / c bond_amount.mul_div_down( fixed!(1e18) - normalized_time_remaining, self.vault_share_price(), diff --git a/crates/hyperdrive-math/src/long/max.rs b/crates/hyperdrive-math/src/long/max.rs index 0b0b95fec..0d12df48f 100644 --- a/crates/hyperdrive-math/src/long/max.rs +++ b/crates/hyperdrive-math/src/long/max.rs @@ -24,6 +24,10 @@ impl State { } /// Gets the pool's solvency. + /// + /// $$ + /// s = z - \tfrac{exposure}{c} - z_min + /// $$ pub fn get_solvency(&self) -> FixedPoint { self.share_reserves() - self.long_exposure() / self.vault_share_price() @@ -107,7 +111,7 @@ impl State { // numbers. // // Proceed to the next step of Newton's method. Once we have a - // candidate solution, we check to see if the pool is solvent if + // candidate solution, we check to see if the pool is solvent after // a long is opened with the candidate amount. If the pool isn't // solvent, then we're done. let maybe_derivative = self.solvency_after_long_derivative(max_base_amount); @@ -157,7 +161,9 @@ impl State { // // y_t = (mu * z_t) * ((1 + curveFee * (1 / p_0 - 1) * (1 - flatFee)) / (1 - flatFee)) ** (1 / t_s) // - // We can use this formula to solve our YieldSpace invariant for z_t: + // Our equation for price is the inverse of that used by YieldSpace, which must be considered when + // deriving the invariant from the price equation. + // With this in mind, we can use this formula to solve our YieldSpace invariant for z_t: // // k = (c / mu) * (mu * z_t) ** (1 - t_s) + // ( @@ -256,7 +262,7 @@ impl State { /// exposure after opening a long with $x$ base as: /// /// \begin{aligned} - /// z(x) &= z_0 + \tfrac{x - g(x)}{c} - z_{min} \\ + /// z(x) &= z_0 + \tfrac{x - g(x)}{c} \\ /// e(x) &= e_0 + min(exposure_{c}, 0) + 2 \cdot y(x) - x + g(x) \\ /// &= e_0 + min(exposure_{c}, 0) + 2 \cdot p_r^{-1} \cdot x - /// 2 \cdot c(x) - x + g(x) @@ -268,7 +274,7 @@ impl State { /// to calculate the approximate ending solvency of: /// /// $$ - /// s(x) \approx z(x) - \tfrac{e(x)}{c} - z_{min} + /// s(x) \approx z(x) - \tfrac{e(x) - min(exposure_{c}, 0)}{c} - z_{min} /// $$ /// /// If we let the initial solvency be given by $s_0$, we can solve for