Router
The xSwapRouter contract plays a pivotal role in the xSwap ecosystem, facilitating seamless token swaps, liquidity management, and the unique distribution mechanism for xSwap's native token, SWA, through xSwapPoints. As part of our commitment to innovation and scalability, the xSwapRouter contract is designed to be both stateless and upgradable, ensuring that it remains efficient and functional as the xSwap platform evolves.
xSwapRouter Contract Features
Statelessness and Upgradability
The xSwapRouter is meticulously crafted to be stateless, meaning it does not hold token balances. This design choice ensures that routers can be replaced or upgraded without risk, accommodating discoveries of more efficient smart contract patterns or the addition of new functionalities.
Core Functions of xSwapRouter
Liquidity Management
addLiquidity & addLiquidityETH: These functions allow users to add liquidity to ERC-20/ERC-20 pools or ERC-20/WXFI pools, respectively. They ensure assets are added at the ideal ratio, reflecting the current market price at the transaction's execution. For the Token Sale event, this facilitates participants to contribute USDT and become liquidity providers, anticipating rewards in SWA tokens.
removeLiquidity & removeLiquidityETH: These enable liquidity providers to withdraw their assets from ERC-20/ERC-20 pools or ERC-20/WXFI pools. These functions are essential for managing liquidity positions and adjusting investments according to market dynamics.
Token Swaps
swapExactTokensForTokens & swapTokensForExactTokens: Facilitate token swaps by allowing users to either specify the exact amount of input tokens or the exact amount of output tokens they desire, ensuring efficient pathfinding for optimal trade execution.
swapExactETHForTokens & swapTokensForExactETH: Specialized functions for swapping XFI for tokens or tokens for XFI, utilizing WXFI as a bridge in the background for seamless integration with Ethereum-based assets.
Liquidity and Price Calculations
getReserves: Retrieves the reserves for a given token pair directly from the liquidity pool, returning the values sorted by the token order. This information is crucial for determining current liquidity levels and pricing for swaps.
quote: Provides a method for calculating equivalent asset amounts based on existing reserves, facilitating optimal liquidity contributions and withdrawals by determining the amount of one asset required given an amount of another asset and the current state of the pool reserves.
getAmountOut & getAmountIn: These functions calculate the maximum output amount for a given input and the minimum input amount required for a desired output, respectively. They account for fees within the transaction, making them essential for determining optimal swap amounts.
Path-Based Swap Calculations
getAmountsOut & getAmountsIn: By inputting an array of token addresses (path), these functions compute the maximum output token amounts for a given input amount and the minimum required input token amounts for a desired output amount across multiple pairs. This path-based approach enables users to swap tokens across multiple liquidity pools in a single transaction, optimizing for the best possible rates.
Last updated