-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from drinkcoffee/peter-pool-calcs
Common pool calculations file
- Loading branch information
Showing
4 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod pool_calcs; | ||
pub mod pool_constants; | ||
pub mod univ3contract; | ||
pub mod univ3sdk; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use eyre::{eyre, Result}; | ||
use uniswap_v3_sdk::prelude::FeeAmount; | ||
|
||
pub fn fee_to_float(fee: FeeAmount) -> f32 { | ||
let fee_num: usize = fee as usize; | ||
let fee_num = fee_num as f32; | ||
fee_num / 10000.0 | ||
} | ||
|
||
pub fn tick_to_exchange_rate( | ||
tick: i32, | ||
token_one_decimals: u64, | ||
token_two_decimals: u64, | ||
) -> Result<f64> { | ||
let tick = tick as f64; | ||
let base: f64 = 1.0001; | ||
|
||
let token_decimals_diff = token_one_decimals.checked_sub(token_two_decimals); | ||
match token_decimals_diff { | ||
None => Err(eyre!( | ||
"Token decimals subtraction overflow: ({} - {})", | ||
token_one_decimals, | ||
token_two_decimals | ||
)), | ||
Some(diff) => { | ||
let denominator = 10u64.pow(diff.try_into()?); | ||
Ok(base.powf(tick) / denominator as f64) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters