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 scaling bug in calculate_implied_rate sdk method #1003

Closed
DannyDelott opened this issue Apr 25, 2024 · 0 comments · Fixed by delvtech/hyperdrive-rs#6
Closed

Fix scaling bug in calculate_implied_rate sdk method #1003

DannyDelott opened this issue Apr 25, 2024 · 0 comments · Fixed by delvtech/hyperdrive-rs#6

Comments

@DannyDelott
Copy link
Contributor

Getting strange output for calculate_implied_rate.. 1255.82% seems really high! 😛

Reproduction

Using this:

pub fn calculate_implied_rate(
&self,
bond_amount: FixedPoint,
open_vault_share_price: FixedPoint,
variable_apy: FixedPoint,
) -> Result<I256> {

I'm calling it with these args:

bond_amount: 1000000000000000000 // "1"
open_vault_share_price: 1005446844189634821 // "1.005446844189634821"
variable_apy: 130000000000000000 // "0.13"

We get back: 12563492079684959896 // "12.563492079684959896"

Formatted and rendered in the ui under Implied Variable Rate:
image

Solution

We just need to adjust the variable rate here (since this term is shorter than a year):

let base_proceeds = bond_amount * variable_apy;
.

Reference

https://discord.com/channels/754739461707006013/1224785900073128080/1233120393938604142

MazyGio added a commit to delvtech/hyperdrive-rs that referenced this issue Apr 30, 2024
PR originally from
[delvtech/hyperdrive#1006](delvtech/hyperdrive#1006)

# Resolved Issues
Fixes [delvtech/hyperdrive/#1003
](delvtech/hyperdrive#1003)

# Description
Fixes calculate_implied_rate to adjust the variable rate according to
the term duration and compounding frequency.

We should probably add a test with a position duration different than 1
year, but I couldn't easily figure out how to.

# 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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant