Skip to content

Commit

Permalink
rewrite to more closely reflect the math and make signs clear
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaiton committed Dec 6, 2024
1 parent e239bd1 commit fc925b9
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions crates/hyperdrive-math/src/short/max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,30 +729,23 @@ impl State {
/// Calculates the derivative of the pool's solvency w.r.t. the short
/// amount.
///
/// The derivative is calculated as:
///
/// ```math
/// \begin{aligned}
/// s'(\Delta y) &= z'(\Delta y) - 0 - 0
/// &= 0 - \left( P'(\Delta y) - \frac{(c'(\Delta y)
/// s'(\Delta y) = 0 - \left( P'(\Delta y) - \frac{(c'(\Delta y)
/// - g'(\Delta y))}{c} \right)
/// &= \frac{\phi_{c} \cdot (1 - p) \cdot (1 - \phi_{g})}{c}
/// - P'(\Delta y)
/// \end{aligned}
/// ```
fn solvency_after_short_derivative(
&self,
bond_amount: FixedPoint<U256>,
) -> Result<FixedPoint<I256>> {
let lhs = (self.curve_fee()
let lhs = self
.calculate_short_principal_derivative(bond_amount)?
.change_type::<I256>()?;
let rhs = (self.curve_fee()
* (fixed!(1e18) - self.calculate_spot_price_down()?)
* (fixed!(1e18) - self.governance_lp_fee())
/ self.vault_share_price())
.change_type::<I256>()?;
let rhs = self
.calculate_short_principal_derivative(bond_amount)?
.change_type::<I256>()?;
Ok(lhs - rhs)
Ok(-(lhs - rhs))
}
}

Expand Down

0 comments on commit fc925b9

Please sign in to comment.