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

Use vault share price of time of maturity instead of current vault share price when calculating pnl of matured positions #1683

Open
slundqui opened this issue Sep 13, 2024 · 0 comments

Comments

@slundqui
Copy link
Contributor

slundqui commented Sep 13, 2024

There's a bug where calling rust's calc_close_long or calc_close_short when calculating the unrealized value of matured, but not closed, positions. Since the rust functions under the hood returns shares, agent0 converts it back to base using the current vault share price. This is correct when the position isn't matured, but since hyperdrive auto closes matured positions via checkpointing, we should be using the vault share price of when the position matured to convert from shares to base.

This issue is exacerbated when a user asks for shares back when closing (in the case of e.g., steth, where agent0 makes trades using yield), as there is a difference between the shares gotten from rust and the actual shares returned when closed due to the same issue. Here, the solution is:

user_return_in_shares = rust_shares_returned * maturity_share_price / current_share_price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant