Skip to content

Commit

Permalink
fix(tick_map): fix next_initialized_tick_within_one_word (#94)
Browse files Browse the repository at this point in the history
Adjusted the tick map logic to start from the next word when the current tick state is irrelevant. Also updated related tests and documentation to reflect these changes. Updated version numbers in Cargo.toml and README.md to 2.1.1.
  • Loading branch information
shuhuiluo authored Oct 18, 2024
1 parent 674727c commit 143e4e9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uniswap-v3-sdk"
version = "2.1.0"
version = "2.1.1"
edition = "2021"
authors = ["Shuhui Luo <twitter.com/aureliano_law>"]
description = "Uniswap V3 SDK for Rust"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ It is feature-complete with unit tests matching the TypeScript SDK.
Add the following to your `Cargo.toml` file:

```toml
uniswap-v3-sdk = { version = "2.0.0", features = ["extensions", "std"] }
uniswap-v3-sdk = { version = "2.1.1", features = ["extensions", "std"] }
```

### Usage
Expand Down
11 changes: 10 additions & 1 deletion src/extensions/ephemeral_tick_map_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ mod tests {
*BLOCK_ID,
)
.await?;
// [-887270, -92110, 100, 110, 22990, ...]
let tick = provider.get_tick(-92110)?;
assert_eq!(tick.liquidity_gross, 398290794261);
assert_eq!(tick.liquidity_net, 398290794261);
Expand All @@ -73,10 +74,18 @@ mod tests {
)?;
assert_eq!(tick, -887270);
assert!(initialized);
let (tick, initialized) =
provider.next_initialized_tick_within_one_word(-92120, true, TICK_SPACING)?;
assert_eq!(tick, -92160);
assert!(!initialized);
let (tick, initialized) =
provider.next_initialized_tick_within_one_word(0, false, TICK_SPACING)?;
assert!(initialized);
assert_eq!(tick, 100);
assert!(initialized);
let (tick, initialized) =
provider.next_initialized_tick_within_one_word(110, false, TICK_SPACING)?;
assert_eq!(tick, 2550);
assert!(!initialized);
Ok(())
}
}
2 changes: 2 additions & 0 deletions src/extensions/tick_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ impl<I: TickIndex> TickDataProvider for TickMap<I> {
let next = (compressed - Self::Index::try_from(bit_pos).unwrap()) * tick_spacing;
Ok((next, initialized))
} else {
// start from the word of the next tick, since the current tick state doesn't matter
let compressed = compressed + Self::Index::ONE;
let (word_pos, bit_pos) = compressed.position();
// all the 1s at or to the left of the `bit_pos`
let mask = U256::ZERO - (uint!(1_U256) << bit_pos);
Expand Down

0 comments on commit 143e4e9

Please sign in to comment.