Giter Site home page Giter Site logo

uniswap-sdk-core-rust's Introduction

Uniswap SDK Core Rust

Unit Tests Lint crates.io

A Custom Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap decentralized exchange.

Warning

This is a custom Uniswap library

Quickstart

Add this to your Cargo.toml

[dependencies]
uniswap-sdk-core = "0.23.0";

And this to your code:

use uniswap_sdk_core::prelude::*;

Examples

The code below shows an example of how to create a new Token instance for the DAI token on the Ethereum Mainnet using the token! macro.

// The `prelude` module provides a convenient way to import a number of common dependencies at 
// once. This can be useful if you are working with multiple parts of the library and want to avoid
// having to import each dependency individually.
// Import necessary preludes and types
use uniswap_sdk_core::prelude::*;

fn main() {
    // Define the chain ID, address, decimals, symbol, and name for the token
    const CHAIN_ID: u64 = 1; // Ethereum Mainnet
    const TOKEN_ADDRESS: &str = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; // DAI Token Address
    const DECIMALS: u8 = 18;
    const SYMBOL: &str = "DAI";
    const NAME: &str = "Dai Stablecoin";

    // Use the `token!` macro to create a new `Token` instance
    let dai_token = token!(CHAIN_ID, TOKEN_ADDRESS, DECIMALS, SYMBOL, NAME);

    // Example usage of the `Token` methods
    println!("Token Address: {}", dai_token.address());
    println!("Is Native: {}", dai_token.is_native());

    // Example of comparing two tokens
    let another_dai_token = token!(CHAIN_ID, TOKEN_ADDRESS, DECIMALS, SYMBOL, NAME);
    println!("Are the tokens equal? {}", dai_token.equals(&another_dai_token));

    // Example of sorting tokens
    let another_token = token!(CHAIN_ID, "0x0000000000000000000000000000000000000002", DECIMALS, "ETH", "Ethereum");
    match dai_token.sorts_before(&another_token) {
        Ok(true) => println!("DAI sorts before ETH"),
        Ok(false) => println!("DAI does not sort before ETH"),
        Err(e) => println!("Error comparing tokens: {:?}", e),
    }
}

This example demonstrates how to create a Token instance for DAI on the Ethereum Mainnet using the token! macro.

It then prints the token's address and checks if it's a native token (which it isn't, so it prints false).

It also compares the DAI token with another DAI token instance to show that two instances of the same token are considered equal.

Finally, it attempts to sort the DAI token before an Ethereum token, which should print that DAI sorts before ETH, assuming the addresses are correctly set up for this comparison.

Remember to replace "0x6B175474E89094C44Da98b954EedeAC495271d0F" with the actual address of the DAI token you're working with, and adjust the CHAIN_ID if you're working on a different network (e.g., a testnet).

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contribution

Contributions are welcome! If you find a bug or have suggestions for improvements, feel free to open an issue or submit a pull request on the GitHub repository.

Acknowledgments

The Uniswap SDK Core in Rust is inspired by the original Uniswap SDK and aims to provide similar functionality in the Rust programming language.

Used by

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

(If you want to add project to the list, dm or open a PR)

uniswap-sdk-core-rust's People

Contributors

malik672 avatar shuhuiluo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.