32 releases (breaking)

0.29.0 Apr 14, 2024
0.27.0 Mar 16, 2024

#410 in Magic Beans

Download history 8/week @ 2023-12-31 38/week @ 2024-01-07 43/week @ 2024-01-14 48/week @ 2024-01-21 9/week @ 2024-01-28 1/week @ 2024-02-04 325/week @ 2024-02-11 441/week @ 2024-02-18 338/week @ 2024-02-25 358/week @ 2024-03-03 158/week @ 2024-03-10 109/week @ 2024-03-17 12/week @ 2024-03-24 153/week @ 2024-03-31 24/week @ 2024-04-07 590/week @ 2024-04-14

789 downloads per month

MIT license

505KB
10K SLoC

Uniswap V3 SDK Rust

Unit Tests crates.io

A Rust SDK for building applications on top of Uniswap V3. Migration from the TypeScript Uniswap/v3-sdk.

It is feature-complete with unit tests matching the TypeScript SDK. But error handling is not as graceful as one may expect. The error handling is still a work in progress.

Features

  • Opinionated Rust implementation of the Uniswap V3 SDK with a focus on readability and performance

  • Usage of alloy-rs types

  • Reimplementation of the math libraries in Uniswap V3 Math In Rust based on optimizations presented in Uni V3 Lib

  • Extensive unit tests and benchmarks

  • An extensions feature for additional functionalities related to Uniswap V3, including:

    • pool module for creating a Pool struct from a pool key and fetching the liquidity map within a tick range for the specified pool, using RPC client
    • position module for creating a Position struct from a token id and fetching the state and pool for all positions of the specified owner, using RPC client, etc
    • price_tick_conversions module for converting between prices and ticks
    • ephemeral_tick_data_provider module for fetching ticks using an ephemeral contract in a single eth_call
Expand to see the benchmarks
Function Time Reference
most_significant_bit 8.3693 µs 39.691 µs
least_significant_bit 5.0592 µs 16.619 µs
get_sqrt_ratio_at_tick 5.2105 µs 71.137 µs
get_tick_at_sqrt_ratio 34.331 µs 191.08 µs

Getting started

Add the following to your Cargo.toml file:

uniswap-v3-sdk = { version = "0.25.0", features = ["extensions"] }

Usage

The package structure follows that of the TypeScript SDK, but with snake_case instead of camelCase.

For easy import, use the prelude:

use uniswap_v3_sdk::prelude::*;

Contributing

Contributions are welcome. Please open an issue if you have any questions or suggestions.

Testing

Tests are run with cargo test. To test a specific module, use cargo test --test <module_name>.

Linting

Linting is done with clippy and rustfmt. To run the linter, use:

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

Benchmarking

Benchmarking is done with criterion. To run the benchmarks, use cargo bench.

License

This project is licensed under the MIT License.

Acknowledgements

This project is inspired by and adapted from the following projects:

Dependencies

~29–48MB
~887K SLoC