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

Rust cleanup; add tests; simplify fn signatures #990

Merged
merged 8 commits into from
Apr 19, 2024
Merged

Conversation

dpaiton
Copy link
Contributor

@dpaiton dpaiton commented Apr 18, 2024

Resolved Issues

working towards resolving delvtech/hyperdrive-rs#29

Description

  • whenever calculate_open_short was called we would first compute state.calculate_spot_price and then pass it in as an argument, I removed the argument and put the calculation inside the function. If one wants to calculate open short for a different spot price, they should adjust the state and then call state.calculate_open_short(bond_amount). This is the same pattern we use for e.g. calc_spot_price_after_*.
  • I renamed a bunch of variables for consistency. Namely, adding "maybe" in front of Option parameters and changing short_amount to bond_amount.
  • I added public wallet and hyperdrive attributes to the agent, which will be helpful for the calc_open_short test I'm writing in a follow-up PR.
  • I renamed some tests so that they say fuzz_* if they are doing fuzzing (this makes it more consistent with the rest of the codebase).
  • I modified the max short test to use a random open_vault_share_price to increase fuzz coverage.
  • I added a test that had a TODO to test the unhappy path of opening a short that is greater than the max.
  • I moved the short_principal_derivative code out of max.rs and into open.rs, which will be helpful for my later targeted short PR.
  • I added tests for short_principal and short_principal_derivative
  • I renamed short_principal[_derivative] to calculate_short_principal[_derivative] to be consistent with the rest of the codebase.

Review Checklists

Please check each item before approving the pull request. While going
through the checklist, it is recommended to leave comments on items that are
referenced in the checklist to make sure that they are reviewed. If there are
multiple reviewers, copy the checklists into sections titled ## [Reviewer Name].
If the PR doesn't touch Solidity and/or Rust, the corresponding checklist can
be removed.

[[Reviewer Name]]

Rust

  • Testing
    • Are there new or updated unit or integration tests?
    • Do the tests cover the happy paths?
    • Do the tests cover the unhappy paths?
    • Are there an adequate number of fuzz tests to ensure that we are
      covering the full input space?
    • If matching Solidity behavior, are there differential fuzz tests that
      ensure that Rust matches Solidity?

@dpaiton dpaiton changed the title Dpaiton/code cleanup Rust cleanup; add tests; simplify fn signatures Apr 18, 2024
@dpaiton dpaiton force-pushed the dpaiton/code-cleanup branch from 147c49e to 5696bb6 Compare April 18, 2024 19:01
@coveralls
Copy link
Collaborator

coveralls commented Apr 18, 2024

Coverage Status

coverage: 93.337%. remained the same
when pulling 00ea923 on dpaiton/code-cleanup
into 78a1b59 on main.

@dpaiton dpaiton marked this pull request as ready for review April 18, 2024 19:01
Copy link

github-actions bot commented Apr 18, 2024

Hyperdrive Gas Benchmark

Benchmark suite Current: 00ea923 Previous: 78a1b59 Deviation Status
addLiquidity: min 33893 gas 33893 gas 0% 🟰
addLiquidity: avg 144957 gas 144492 gas 0.3218% 🚨
addLiquidity: max 428319 gas 428319 gas 0% 🟰
checkpoint: min 40220 gas 40220 gas 0% 🟰
checkpoint: avg 104106 gas 104036 gas 0.0673% 🚨
checkpoint: max 212154 gas 212154 gas 0% 🟰
closeLong: min 31517 gas 31517 gas 0% 🟰
closeLong: avg 138417 gas 138644 gas -0.1637%
closeLong: max 2640435 gas 2640435 gas 0% 🟰
closeShort: min 31394 gas 31394 gas 0% 🟰
closeShort: avg 132961 gas 132896 gas 0.0489% 🚨
closeShort: max 227565 gas 227553 gas 0.0053% 🚨
initialize: min 31305 gas 31305 gas 0% 🟰
initialize: avg 253631 gas 253636 gas -0.0020%
initialize: max 322760 gas 322760 gas 0% 🟰
openLong: min 33437 gas 33437 gas 0% 🟰
openLong: avg 167200 gas 166991 gas 0.1252% 🚨
openLong: max 253057 gas 253057 gas 0% 🟰
openShort: min 33959 gas 33959 gas 0% 🟰
openShort: avg 170098 gas 170515 gas -0.2446%
openShort: max 385545 gas 385545 gas 0% 🟰
redeemWithdrawalShares: min 31227 gas 31227 gas 0% 🟰
redeemWithdrawalShares: avg 61912 gas 62052 gas -0.2256%
redeemWithdrawalShares: max 167572 gas 167572 gas 0% 🟰
removeLiquidity: min 31191 gas 31191 gas 0% 🟰
removeLiquidity: avg 223472 gas 223882 gas -0.1831%
removeLiquidity: max 398887 gas 398863 gas 0.0060% 🚨

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@slundqui slundqui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but may want an additional review from @ryangoree wrt the removed parameter in calculate_open_short.

@dpaiton dpaiton force-pushed the dpaiton/code-cleanup branch from 5696bb6 to 1b66015 Compare April 18, 2024 19:41
@dpaiton dpaiton force-pushed the dpaiton/code-cleanup branch from 1b66015 to 00ea923 Compare April 18, 2024 19:42
@dpaiton dpaiton added this pull request to the merge queue Apr 19, 2024
Merged via the queue into main with commit d14c4ef Apr 19, 2024
37 checks passed
@dpaiton dpaiton deleted the dpaiton/code-cleanup branch April 19, 2024 21:20
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.

5 participants