-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update
calc_open_short
to match solidity (#152)
# Resolved Issues #29 #121 # Description This PR updates the Rust open short and derivative implementations to match Solidity. With help from @sentilesdal I uncovered a bug with sol differential tests where the current vault share price was not correctly used on the rust end. Fixing this allowed us to drop several test tolerances as well. I'll follow up with another PR that applies this fix elsewhere. I also did some minor variable renames, added & modified max short checks, and resolved a few lingering FIXMEs. I ran all of the tests with 10x fuzz constants locally without any failures. ## Lower tolerances on tests 🎉 - After the fix, I was able to completely remove the error tolerance on `fuzz_calc_open_short`. - I also updated the epsilon & tolerance values for the `fuzz_short_deposit_derivative` and `fuzz_short_principal_derivative` tests. I use a larger epsilon and smaller tolerance, which I think is what we prefer (more distant points should match linearity assumptions better due to the lack of monotonicity coming from `pow`). - `fuzz_sol_calculate_max_short_without_budget_then_open_short` lowered base test tolerance due to both the open short fix and the vault share price fix. ## Increased tolerances on tests 😭 - I had to increase tolerance on `fuzz_calculate_spot_price_after_short` from `fixed!(0)` to `fixed!(100)`. However, the test is more difficult now because it uses a random variable rate instead of 0%. - note: `test_sol_calculate_pool_deltas_after_open_short` looks like it has a new tolerance, but this was simply assigning an existing tolerance to a variable at the top of the test. - `fuzz_sol_calculate_max_short_without_budget_then_open_short` raised bond test tolerance from 1e2 to 1e10, but 1e2 wasn't holding up to extensive fuzz testing in the first place. ## Math outline The below formulation follows the logic outlined in `HyperdriveShort.sol`. I made some slight changes to variable names and ordering of presentation.   
- Loading branch information
Showing
5 changed files
with
451 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.