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

Common pool calculations file #26

Merged
merged 5 commits into from
Nov 15, 2024
Merged

Common pool calculations file #26

merged 5 commits into from
Nov 15, 2024

Conversation

drinkcoffee
Copy link
Owner

Added a file with common pool calculations:

  • fee to float,
  • tick number to exchange rate.

The tick to exchange rate calculation currently does not handle decimals for the tokens being different.

let val: f64 = 1.0001;

if token_one_decimals != token_two_decimals {
println!("Exchange when token decimals not the same not yet supported");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should return an error (anyhow!()) and then anything that uses the fn can choose to print the error or return it etc

Copy link
Owner Author

Choose a reason for hiding this comment

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

yep

@@ -0,0 +1,17 @@
use uniswap_v3_sdk::prelude::FeeAmount;

pub fn fee_to_float(fee: FeeAmount) -> f32 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does this need to be a float?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Because the result can be 0.01, for instance. Though the current usage of the result is as a string, it is likely that the result will be used in calculations of the cost of doing a price change.

Handle error, underflow and denominator
@drinkcoffee drinkcoffee merged commit 859043b into main Nov 15, 2024
3 checks passed
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.

3 participants