delvtech / hyperdrive-rs

Rust SDK for the Hyperdrive AMM.
https://docs.rs/crate/hyperdrive-math/latest
Apache License 2.0
2 stars 0 forks source link

Fix calculate_implied_rate to return an annualized rate and scale tolerance up with implied_rate #112

Closed MazyGio closed 6 months ago

MazyGio commented 6 months ago

Description

calculate_implied_rate was meant to return an annualized rate, but it was returning an HPR instead. This fixes it to return an annualized rate, and adds helper functions for turning annualized rates into HPR.

This also makes the test tolerance for calculate_implied_rate scale with the total implied rate, to ensure the tests don't fail while the error is still within reasonable bounds for larger results.

Adds calculate_hpr_given_apr and calculate_hpr_given_apy functions.

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.