Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions crates/hyperdrive-math/src/long/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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())
Expand All @@ -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(),
Expand Down
14 changes: 10 additions & 4 deletions crates/hyperdrive-math/src/long/max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) +
// (
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down