Welcome to Best Swaps Rates. Within this application, you will have the opportunity to perform WETH-USDT swaps across various decentralized exchanges (DEXs) while selecting the most favorable exchange rate available. Currently deployed in Arbitrum.
- Deployed website: Best-Rates-Swaps.
- Smart Contracts repository: Repository.
- Smart Contract address: Treasury.sol.
The primary functionality of this project involves the exchange of assets from Wrapped Ether (WETH) to Tether (USDT) through various decentralized exchanges, with the objective of obtaining the most favorable exchange rate available among them.
To achieve the desired goal, two methods of swapping assets have been implemented. These two methods are utilized to demonstrate how a similar goal can be attained through two distinct procedures. These methods have been called:
- CommonSwaps.
- DEXAggregatorSwaps.
The common swaps method combines both an on-chain and off-chain structure. The best rate is previously calculated off-chain using the router view functions of each decentralized exchange. Once we have determined the best rate offered by an exchange, the on-chain swap occurs within our Treasury smart contract, selecting the decentralized exchange with the previously calculated best rate. Computing the best rate "off-chain" makes it more challenging for malicious actors, such as MEV bots, to engage in front-running or sandwich attacks.
The implemented Treasury smart contract can be found at the following link: here. This repository encompasses all aspects related to the smart contracts utilized in this project, including the contract itself, deployment scripts, and testing scripts.
- Smart Contract address: Treasury.sol.
This contract works in the following way:
- Any user has the option to deposit WETH tokens, and these tokens are pooled together within the contract without individual tracking for each user.
- Any user can access the platform and initiate a swap for the entire WETH balance held within the contract. The swap is facilitated through the exchange that provides the most favorable rate, as indicated by our frontend interface.
- Any user can withdraw the USDT amount of tokens held in the Treasury.
- There is a button available for users to retrieve the WETH and USDT token balances of the Treasury contract at any given moment.
Currently, the implemented exchanges available for swapping are UniSwapV2 and SushiSwapV2. It is worth noting that any other exchange, such as Curve or SushiSwapV3, can be incorporated by following the same procedure.
The DEXAggregatorSwaps method utilizes Paraswap's API. This method allows any user to initiate a direct swap of their WETH tokens to USDT from their wallet. The DEXAggregatorSwaps method selects the optimal route from SushiSwapV2, UniSwapV2, UniSwapV3, and Curve, facilitating the swap process and returning the USDT amount to the user's wallet.