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

Add distribute_excess_idle #17

Merged
merged 6 commits into from
Jun 3, 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
1 change: 1 addition & 0 deletions crates/hyperdrive-math/src/lp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod add;
mod math;
mod remove;
mod utils;
30 changes: 1 addition & 29 deletions crates/hyperdrive-math/src/lp/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl State {
I256::try_from(contribution)?
}
};
self.get_state_after_liquidity_update(share_contribution)
Ok(self.get_state_after_liquidity_update(share_contribution)?)
}

pub fn calculate_pool_deltas_after_add_liquidity(
Expand Down Expand Up @@ -108,34 +108,6 @@ impl State {
new_bond_reserves - bond_reserves,
))
}

/// Gets the resulting state when updating liquidity.
pub fn get_state_after_liquidity_update(&self, share_reserves_delta: I256) -> Result<State> {
let share_reserves = self.share_reserves();
let share_adjustment = self.share_adjustment();
let bond_reserves = self.bond_reserves();
let minimum_share_reserves = self.minimum_share_reserves();

// Calculate new reserve and adjustment levels.
let (updated_share_reserves, updated_share_adjustment, updated_bond_reserves) = self
.calculate_update_liquidity(
share_reserves,
share_adjustment,
bond_reserves,
minimum_share_reserves,
share_reserves_delta,
)?;

// Update and return the new state.
let mut new_info = self.info.clone();
new_info.share_reserves = U256::from(updated_share_reserves);
new_info.share_adjustment = updated_share_adjustment;
new_info.bond_reserves = U256::from(updated_bond_reserves);
Ok(State {
config: self.config.clone(),
info: new_info,
})
}
}

#[cfg(test)]
Expand Down
Loading
Loading