Skip to content

Commit

Permalink
Merge pull request #15 from shuhuiluo/feature/price_tick_conversions
Browse files Browse the repository at this point in the history
Extend price and tick conversion utilities
  • Loading branch information
shuhuiluo authored Jan 14, 2024
2 parents 90790de + 31c9db2 commit 7ea8533
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 55 deletions.
52 changes: 27 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uniswap-v3-sdk"
version = "0.10.1"
version = "0.11.0"
edition = "2021"
authors = ["Shuhui Luo <twitter.com/aureliano_law>"]
description = "Uniswap V3 SDK for Rust"
Expand All @@ -14,22 +14,24 @@ exclude = [".github", ".gitignore", "rustfmt.toml"]
all-features = true

[dependencies]
alloy-primitives = "0.6.0"
alloy-sol-types = "0.6.0"
alloy-primitives = "0.6"
alloy-sol-types = "0.6"
anyhow = "1.0"
aperture-lens = { version = "0.4.0", optional = true }
aperture-lens = { version = "0.4", optional = true }
bigdecimal = "0.4.2"
ethers = { version = "2.0", optional = true }
num-bigint = "0.4.4"
num-integer = "0.1.45"
num-traits = "0.2.17"
once_cell = "1.19.0"
ruint = "1.11.1"
thiserror = "1.0.53"
once_cell = "1.19"
regex = { version = "1.10", optional = true }
ruint = "1.11"
thiserror = "1.0"
uniswap-sdk-core = "0.10.0"
uniswap_v3_math = "0.4.1"

[features]
extensions = ["aperture-lens", "ethers"]
extensions = ["aperture-lens", "ethers", "regex"]

[dev-dependencies]
criterion = "0.5.1"
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ WIP.
- Reimplementation of the math libraries in [Uniswap V3 Math In Rust](https://github.com/0xKitsune/uniswap-v3-math)
based on optimizations presented in [Uni V3 Lib](https://github.com/Aperture-Finance/uni-v3-lib)
- Extensive unit tests and benchmarks
- An `extensions` module for additional functionality related to Uniswap V3
- An `extensions` feature for additional functionality related to Uniswap V3

## Getting started

Add the following to your `Cargo.toml` file:

```toml
uniswap-v3-sdk = "0.8.0"
uniswap-v3-sdk = { version = "0.11.0", features = ["extensions"] }
```

### Usage
Expand All @@ -46,8 +46,12 @@ Tests are run with `cargo test`. To test a specific module, use `cargo test --te

### Linting

Linting is done with `clippy` and `rustfmt`. To run the linter,
use `cargo clippy --all-targets --all-features -- -D warnings` and `cargo fmt --all -- --check`.
Linting is done with `clippy` and `rustfmt`. To run the linter, use:

```shell
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --all -- --check
```

### Benchmarking

Expand All @@ -65,3 +69,4 @@ This project is inspired by and adapted from the following projects:
- [Uniswap SDK Core Rust](https://github.com/malik672/uniswap-sdk-core-rust)
- [Uniswap V3 Math In Rust](https://github.com/0xKitsune/uniswap-v3-math)
- [Uni V3 Lib](https://github.com/Aperture-Finance/uni-v3-lib)
- [uniswap-v3-automation-sdk](https://github.com/Aperture-Finance/uniswap-v3-automation-sdk)
5 changes: 4 additions & 1 deletion src/extensions/ephemeral_tick_data_provider.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
//! ## Ephemeral Tick Data Provider
//! A data provider that fetches ticks using an [ephemeral contract](https://github.com/Aperture-Finance/Aperture-Lens/blob/904101e4daed59e02fd4b758b98b0749e70b583b/contracts/EphemeralGetPopulatedTicksInRange.sol) in a single `eth_call`.

use crate::prelude::*;
use alloy_primitives::Address;
use anyhow::Result;
use aperture_lens::prelude::get_populated_ticks_in_range;
use ethers::prelude::{BlockId, ContractError, Middleware};
use std::sync::Arc;

/// A data provider for ticks that fetches ticks using an ephemeral contract in a single `eth_call`.
/// A data provider that fetches ticks using an ephemeral contract in a single `eth_call`.
#[derive(Clone)]
pub struct EphemeralTickDataProvider {
pub pool: Address,
Expand Down
12 changes: 12 additions & 0 deletions src/extensions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
//! Extensions to the core library.

mod ephemeral_tick_data_provider;
mod price_tick_conversions;

pub use ephemeral_tick_data_provider::EphemeralTickDataProvider;
pub use price_tick_conversions::*;

use crate::prelude::*;
use alloy_primitives::U256;
use bigdecimal::BigDecimal;

pub fn u256_to_big_decimal(x: U256) -> BigDecimal {
BigDecimal::from(u256_to_big_int(x))
}
Loading

0 comments on commit 7ea8533

Please sign in to comment.