Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix open_short_curve_fee #97

Merged
merged 4 commits into from
May 14, 2024
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
7 changes: 4 additions & 3 deletions crates/hyperdrive-math/src/short/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ impl State {
pub fn open_short_curve_fee(&self, bond_amount: FixedPoint) -> FixedPoint {
// NOTE: Round up to overestimate the curve fee.
self.curve_fee()
.mul_up(fixed!(1e18) - self.calculate_spot_price())
.mul_up(bond_amount)
.mul_down(fixed!(1e18) - self.calculate_spot_price())
.mul_down(bond_amount)
}

/// Calculates the governance fee paid by the trader when they open a short.
pub fn open_short_governance_fee(&self, bond_amount: FixedPoint) -> FixedPoint {
self.governance_lp_fee() * self.open_short_curve_fee(bond_amount)
self.governance_lp_fee()
.mul_down(self.open_short_curve_fee(bond_amount))
}

/// Calculates the curve fee paid by shorts for a given bond amount.
Expand Down
13 changes: 1 addition & 12 deletions crates/hyperdrive-math/src/short/max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ mod tests {
chain::TestChain,
constants::{FAST_FUZZ_RUNS, FUZZ_RUNS},
};
use tracing_test::traced_test;

use super::*;
use crate::test_utils::agent::HyperdriveMathAgent;
Expand All @@ -508,7 +507,6 @@ mod tests {
/// `calculate_max_short`'s functionality. With this in mind, we provide
/// `calculate_max_short` with a budget of `U256::MAX` to ensure that the two
/// functions are equivalent.
#[ignore]
#[tokio::test]
async fn fuzz_calculate_max_short_no_budget() -> Result<()> {
let chain = TestChain::new().await?;
Expand Down Expand Up @@ -579,21 +577,16 @@ mod tests {
}

/// Tests that the absolute max short can be executed on chain.
#[ignore]
#[traced_test]
#[tokio::test]
async fn fuzz_calculate_absolute_max_short_execute() -> Result<()> {
// Spawn a test chain and create two agents -- Alice and Bob. Alice
// is funded with a large amount of capital so that she can initialize
// the pool. Bob is funded with plenty of capital to ensure we can execute
// the absolute maximum short.
let mut rng = thread_rng();
let chain = TestChain::new().await?;

for _ in 0..*FUZZ_RUNS {
// // Snapshot the chain BEFORE creating any agents.
let id = chain.snapshot().await?;

let chain = TestChain::new().await?;
let mut alice = chain.alice().await?;
let mut bob = chain.bob().await?;
let config = alice.get_config().clone();
Expand Down Expand Up @@ -646,15 +639,11 @@ mod tests {
// for deposit << the global max short number of bonds.
bob.fund(global_max_short + fixed!(10e18)).await?;
bob.open_short(global_max_short, None, None).await?;

// Revert to the snapshot and reset the agent's wallets.
chain.revert(id).await?;
}

Ok(())
}

#[traced_test]
#[tokio::test]
async fn fuzz_calculate_max_short() -> Result<()> {
// Spawn a test chain and create two agents -- Alice and Bob. Alice
Expand Down
Loading