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

fix(tick_map): fix next_initialized_tick_within_one_word #94

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
shuhuiluo marked this conversation as resolved.
Show resolved Hide resolved
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) =
shuhuiluo marked this conversation as resolved.
Show resolved Hide resolved
provider.next_initialized_tick_within_one_word(110, false, TICK_SPACING)?;
assert_eq!(tick, 2550);
assert!(!initialized);
shuhuiluo marked this conversation as resolved.
Show resolved Hide resolved
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