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

Fixed get_max_short #559

Merged
merged 77 commits into from
Aug 23, 2023
Merged

Conversation

jalextowle
Copy link
Contributor

@jalextowle jalextowle commented Aug 17, 2023

This PR fixes the get_max_short function and adds fuzz tests that verify that it is within a specified tolerance. This function will need to be improved as we start writing fuzz tests; however, this is a good cutoff point for now.

During the process of fixing get_max_short, I stumbled across two bugs in the logic for computing a short's deposit. The first is that we were removing the governance fee from the trader's short deposit and the second is that we weren't converting the flat fee to share fees when we added the flat fee to the short deposit. Both of these issues have been fixed and tested.

jrhea and others added 30 commits August 9, 2023 17:39
@jalextowle jalextowle force-pushed the jalextowle/rust/max-trades-with-netting branch from 8aff8b4 to 2a9a5c2 Compare August 18, 2023 20:31
@jalextowle jalextowle force-pushed the jalextowle/rust/max-trades-with-netting branch from 05285a2 to 29e7f0b Compare August 19, 2023 16:52
@jalextowle jalextowle force-pushed the jalextowle/rust/max-trades-with-netting branch from 29e7f0b to 1008653 Compare August 19, 2023 16:56
@jalextowle jalextowle force-pushed the jalextowle/rust/max-trades-with-netting branch from 7a9e912 to 160b4a5 Compare August 19, 2023 17:35
contracts/src/HyperdriveShort.sol Outdated Show resolved Hide resolved
crates/test-utils/src/agent.rs Show resolved Hide resolved
test/units/hyperdrive/OpenShortTest.t.sol Outdated Show resolved Hide resolved
@jalextowle jalextowle enabled auto-merge (squash) August 23, 2023 19:25
@jalextowle jalextowle merged commit 7dc98da into main Aug 23, 2023
8 checks passed
@jalextowle jalextowle deleted the jalextowle/rust/max-trades-with-netting branch August 23, 2023 20:25
jalextowle added a commit that referenced this pull request Aug 25, 2023
* implement and test netting

* fixed issues found running tests and fuzzing

* prettier

* remove old code

* exposure should be updated by the delta in openLong. also, changed mulDiv to mul

* more compact/efficient solvency check

* improve fuzz testing

* changed the closeShort method to mirror closeLong

* add cross checkpoint fuzzing tests

* add more comprehensive fuzzing, fix some minor issues and explain why certain tests fail

* derp

* finish merge

* Tweaked the fuzz tests

* move close position exposure logic to calculateClosePositionExposure helper

* remove shareReservesExceedsBondReserves revert

* move exposure to marketState and fix test_LongAvoidsDrainingBufferReserves() test

* test__calculateClosePositionExposure() tests

* remove print imports

* reduce num trades in netting fuzz to speed up test

* update foundry action

* add exposure to rust hyperdrive math

* update hyperdrive-math-py with exposure

* fml

* simplify calculateClosePositionExposure and update tests

* fix stack issue with via-ir prod build

* make calculateClosePositionExposure even simpler

* changing back to nightly for coverage bc it is 404ing

* added idleShareReserves calculation

* fixes to removeLiquidity idle calc. update tests

* remove printout

* Use ChaCha8Rng instead of ThreadRng so that fuzz runs are reproducible

* working on fixing tests

* Reverted to the old idle calculation and fixed some tests

* Update contracts/src/Hyperdrive.sol

Co-authored-by: Alex Towle <[email protected]>

* Fixed the remaining LP fairness tests

* Fixed the remaining `removeLiquidity` unit tests

* implementing review comments

* prettier

* more review fixes

* fix lint issues

* Update contracts/src/HyperdriveLong.sol

Co-authored-by: Alex Towle <[email protected]>

* Update contracts/src/Hyperdrive.sol

Co-authored-by: Alex Towle <[email protected]>

* Update contracts/src/HyperdriveLong.sol

Co-authored-by: Alex Towle <[email protected]>

* Update contracts/src/HyperdriveShort.sol

Co-authored-by: Alex Towle <[email protected]>

* prettier

* spelling

* put solvency check in method

* Update contracts/src/HyperdriveShort.sol

Co-authored-by: Alex Towle <[email protected]>

* Uncommented test

* Made several fixes to `get_max_short` and started to test it more rigorously

* Worked on improving the `get_max_short` calculation

* Significantly improved the accuracy of the agent's `get_max_short` calculation

* Added a `get_max_short` function

* Cleanups

* Removed some where clauses

* Tweaks

* Adds a unit test to test the fix

* Fixed the python tests

* Debugging

* Fixed a bug in `calculateShortProceeds`

* Fixed the `calculateShortProceeds` test

* Fuzzing parameter tweaks

* Last few fixes

* Appeased the linter

* Update test/units/hyperdrive/OpenShortTest.t.sol

Co-authored-by: Jonny Rhea <[email protected]>

* Addressed review feedback from @jrhea

---------

Co-authored-by: jonny rhea <[email protected]>
Co-authored-by: Jonny Rhea <[email protected]>
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.

3 participants