-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
mod bit_math; | ||
mod compute_pool_address; | ||
pub use compute_pool_address::compute_pool_address; | ||
|
||
mod encode_sqrt_ratio_x96; | ||
pub use encode_sqrt_ratio_x96::encode_sqrt_ratio_x96; | ||
|
||
mod nearest_usable_tick; | ||
pub use nearest_usable_tick::nearest_usable_tick; | ||
|
||
mod full_math; | ||
pub use full_math::*; | ||
|
||
mod liquidity_math; | ||
pub use liquidity_math::add_delta; | ||
mod nearest_usable_tick; | ||
mod position; | ||
mod price_tick_conversions; | ||
mod tick_math; | ||
|
||
mod bit_math; | ||
use alloy_primitives::U256; | ||
pub use bit_math::*; | ||
|
||
mod tick_math; | ||
pub use compute_pool_address::compute_pool_address; | ||
pub use encode_sqrt_ratio_x96::encode_sqrt_ratio_x96; | ||
pub use full_math::*; | ||
pub use liquidity_math::add_delta; | ||
pub use nearest_usable_tick::nearest_usable_tick; | ||
pub use position::get_tokens_owed; | ||
pub use tick_math::*; | ||
|
||
pub const Q128: U256 = U256::from_limbs([0, 0, 1, 0]); |
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 super::Q128; | ||
use alloy_primitives::U256; | ||
|
||
/// Computes the amount of fees owed to a position | ||
pub fn get_tokens_owed( | ||
fee_growth_inside_0_last_x128: U256, | ||
fee_growth_inside_1_last_x128: U256, | ||
liquidity: u128, | ||
fee_growth_inside_0_x128: U256, | ||
fee_growth_inside_1_x128: U256, | ||
) -> (U256, U256) { | ||
let liquidity = U256::from(liquidity); | ||
let tokens_owed_0 = | ||
(fee_growth_inside_0_x128 - fee_growth_inside_0_last_x128) * liquidity / Q128; | ||
let tokens_owed_1 = | ||
(fee_growth_inside_1_x128 - fee_growth_inside_1_last_x128) * liquidity / Q128; | ||
(tokens_owed_0, tokens_owed_1) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_get_tokens_owed() { | ||
let (tokens_owed_0, tokens_owed_1) = get_tokens_owed(U256::ZERO, U256::ZERO, 1, Q128, Q128); | ||
assert_eq!(tokens_owed_0, U256::from(1)); | ||
assert_eq!(tokens_owed_1, U256::from(1)); | ||
} | ||
} |
Empty file.