npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ttxd

v1.0.2

Published

⚒️ An SDK for building applications on top of V2 and V3 exchanges

Downloads

194

Readme

TT software

npm version npm bundle size (scoped version)

The latest version of the SDK is used in production in the DEX Interfaces, but it is considered Alpha testing software and may contain bugs or change significantly between patch versions.

Why Use This SDK?

This SDK allows seamless integration of swapping between V2 and V3 exchanges on chains like Ethereum, BNB, Polygon, and more, all while maintaining a modular approach that allows expansion to other DEXes and blockchains. It is ideal for developers looking to build DeFi projects with minimal latency and maximal flexibility.

Features

  • Multi-chain & multi-DEX support: Currently supports Ethereum, BNB Chain, Polygon, and Base, with more chains coming soon.
  • Modular architecture: Add additional DEXes and blockchains without refactoring core logic.
  • Lightweight: Designed for high performance, the SDK offers minimal overhead.

Installing

Using npm (ES6)

To install the SDK via npm, run the following command:

npm install ttxd

Swapping Tokens on V2 Exchanges

This guide provides an overview of swapping tokens on V2 exchanges.

Pair

A Pair represents a liquidity pool between two tokens. It holds reserves of both tokens and allows users to swap between them. Each pair is unique to a token pair combination.

RouteV2

RouteV2 defines the path for swapping tokens through one or more pairs. It specifies the sequence of pairs that a swap transaction will traverse to exchange one token for another.

TradeV2

A TradeV2 represents a trade along a given route with specified input or output amounts. It calculates the necessary input or output amounts based on the desired trade and current market conditions.

RouterV2

The RouterV2 provides methods to construct calldata for executing trades on the blockchain. It interacts with smart contracts to perform the actual token swap as specified by the trade parameters.

const pairAddress = Pair.getAddress(TokenA, TokenB);
const route = new RouteV2([pairAB, pairBC], TokenA, TokenB);
const trade = new TradeV2(route, amountIn, TradeType);
const swapParams = RouterV2.swapCallParameters(trade, {
  slippageTolerance,
  recipient,
  deadline,
});

Swapping Tokens on V3 Exchanges

Pool

Represents a Uniswap V3 liquidity pool.

Route

Defines the path for swapping tokens through one or more pools.

Trade

Represents a trade along a given route with specified input or output amounts.

SwapRouter

Provides methods to construct calldata for executing trades on the blockchain.

const poolAddress = Pool.getAddress(TokenA, TokenB, FeeAmount);
const pool = new Pool(
  TokenA,
  TokenB,
  FeeAmount,
  slot0.sqrtPriceX96.toString(),
  liquidity.toString(),
  slot0.tick
);
const swapRoute = new Route([pool], TokenA, TokenB);
const trade = Trade.createUncheckedTrade({
  route: swapRoute,
  inputAmount: amountIn,
  outputAmount: CurrencyAmount.fromRawAmount(
    TokenB,
    '<CALCULATED_OUTPUT_AMOUNT>'
  ),
  tradeType: TradeType,
});
const methodParameters = SwapRouter.swapCallParameters([trade], {
  slippageTolerance, 
  deadline,
  recipient,
};);
const txResponse = await signer.sendTransaction(tx);

V2-V3 SDK

In-depth documentation on this SDK is available at uniswap.org.

License

This project is licensed under the MIT License.