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 long_trade_needed_given_reserves and reserves_given_rate_ignoring_exposure #180

Merged
merged 6 commits into from
Jul 22, 2024

Conversation

dpaiton
Copy link
Member

@dpaiton dpaiton commented Jul 16, 2024

Resolved Issues

working towards #21

Description

In #167 I wrote a test for long_trade_needed_given_reserves and reserves_given_rate_ignoring_exposure, which we will need to translate to the short variety for the targeted short flow. For the tests to pass I had to set fees, zeta, and exposure to zero. This was because the test itself used other components that required this, although the function of interest (long_trade_needed_given_reserves) does not have the same requirements.

In this PR I rewrote the test to be simpler and more direct, and found that the function was not passing with any sort of reasonable tolerance. I figured out the bug (we were not accounting for fees correctly) and fixed it.

Part of the fix for long_trade_needed_given_reserves included adding a sanity check on reserve levels, which revealed a bug in reserves_given_rate_ignoring_exposure, which was returning invalid reserve amounts due to non-zero exposure or zeta. Adding zeta to the equation fixed that problem, so all tests are passing again.

I had to increase the tolerance for the targeted long test. I'm not entirely sure why, but I think it's still reasonable so I will not investigate it further at this time.

@dpaiton dpaiton marked this pull request as draft July 16, 2024 21:41
@dpaiton dpaiton changed the title Dpaiton/targeted long fix fix long_trade_needed_given_reserves and reserves_given_rate_ignoring_exposure Jul 16, 2024
@dpaiton dpaiton force-pushed the dpaiton/targeted-long-fix branch 2 times, most recently from 94bae7c to 1e31fd5 Compare July 17, 2024 18:25
@dpaiton dpaiton marked this pull request as ready for review July 17, 2024 18:32
crates/hyperdrive-math/src/lib.rs Outdated Show resolved Hide resolved
crates/hyperdrive-math/src/lib.rs Outdated Show resolved Hide resolved
crates/hyperdrive-math/src/long/open.rs Outdated Show resolved Hide resolved
crates/hyperdrive-math/src/long/open.rs Outdated Show resolved Hide resolved
crates/hyperdrive-math/src/long/open.rs Outdated Show resolved Hide resolved
crates/hyperdrive-math/src/long/open.rs Outdated Show resolved Hide resolved
@dpaiton dpaiton force-pushed the dpaiton/targeted-long-fix branch 2 times, most recently from 828d34a to 60050f3 Compare July 22, 2024 19:47
@dpaiton dpaiton force-pushed the dpaiton/targeted-long-fix branch from 95e96fb to f838c22 Compare July 22, 2024 20:28
@dpaiton dpaiton enabled auto-merge (squash) July 22, 2024 20:28
@dpaiton dpaiton merged commit 2a3558f into main Jul 22, 2024
8 checks passed
@dpaiton dpaiton deleted the dpaiton/targeted-long-fix branch July 22, 2024 20:38
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

Successfully merging this pull request may close these issues.

2 participants