ttxd
v1.0.2
Published
⚒️ An SDK for building applications on top of V2 and V3 exchanges
Downloads
29
Readme
TT software
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.