Skip to content
Merged
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
18 changes: 18 additions & 0 deletions crates/hyperdrive-math/src/short/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ impl State {
)
}

/// Gets the spot price after opening the short on the YieldSpace curve and
/// before calculating the fees.
pub fn get_spot_price_after_short(&self, bond_amount: FixedPoint) -> FixedPoint {
let shares_amount = self.calculate_shares_out_given_bonds_in_down(bond_amount);
self.spot_price_after_short(shares_amount * self.vault_share_price(), bond_amount)
}

fn spot_price_after_short(
&self,
base_amount: FixedPoint,
bond_amount: FixedPoint,
) -> FixedPoint {
let mut state: State = self.clone();
state.info.bond_reserves += bond_amount.into();
state.info.share_reserves -= (base_amount / state.vault_share_price()).into();
state.get_spot_price()
}

#[deprecated(since = "0.4.0", note = "please use `calculate_open_short` instead")]
pub fn get_short_deposit(
&self,
Expand Down