delvtech / hyperdrive

An automated market maker for fixed and variable yield with on-demand terms.
Apache License 2.0
25 stars 3 forks source link

Fix scaling bug in `calculate_implied_rate` sdk method #1003

Closed DannyDelott closed 2 months ago

DannyDelott commented 2 months ago

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

Reproduction

Using this: https://github.com/delvtech/hyperdrive/blob/1576e4c4368dd9c21b2df60274f223271e793d46/crates/hyperdrive-math/src/short/open.rs#L160-L165

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): https://github.com/delvtech/hyperdrive/blob/1576e4c4368dd9c21b2df60274f223271e793d46/crates/hyperdrive-math/src/short/open.rs#L167.

Reference

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