Tokens with taxes
For tokens subject to taxes, specific adaptations are essential in trading workflows:
Disable Exact Out Feature:
Disable the exact out feature for these tokens since they are predominantly traded with the exact in trade type. Trade involving taxed tokens and using Exact Out will result in an error message.
Increase Slippage:
Elevate the slippage tolerance to compensate for reduced proceeds when selling taxed tokens.
Recommend increasing slippage directly on the UI when dealing with taxed tokens, with adjustments corresponding to the tax rates.
Dynamically adjust slippage based on the tax amount provided for each token in the trade to ensure successful transactions despite the tax implications (we provide a recommended slippage on each quote, as we describe at the end of this article)
Tax Information is included in Quotes Endpoint and Information Endpoints:
Tax details for each token involved in a trade are included in the quotes endpoint response. Attributes such as buyTax and sellTax for each tokenFrom and tokenTo are present in the information, facilitating users' understanding of tax implications and aiding informed decision-making.
For instance, when querying the quotes endpoint, the UI should will return tax-related information for each token involved, such as buyTax and sellTax. Additionally, the UI should dynamically adapt the slippage settings based on the tax amount associated with each token, promoting seamless trading experiences despite tax considerations.
You can also find the tax information in the endpoints that return information about tokens (popular tokens, search, token information).
A recommended slippage value is included with each quote
We’ve added a recommendedSlippage field, allowing you to see the suggested slippage for a specific token pair. By default, the recommended slippage is set to 0.5%. However, if token taxes apply, this value may be adjusted to prevent failed trades caused by insufficient amounts.
Setting the Appropriate Slippage Before Requesting a Quote
To ensure a correct slippage value before making a quote request, you can calculate it directly using the token information, rather than waiting for a recommendation from the API. The process involves checking the tax information for both the token you are sending (tokenFrom) and the token you are receiving (tokenTo):
Check Token Taxes:
For the tokenFrom, you need to inspect the
sellTax
.For the tokenTo, look at the
buyTax
.
Calculate Slippage:
If either token has taxes applied, you can calculate a proper slippage based on the sum of the buy and sell taxes. For example:
If taxes are present, the slippage should be set higher to account for these fees, starting with a base value of
0.5%
plus the combined taxes from both tokens. If no taxes are applied, the default slippage is used.
By calculating slippage this way, you ensure that your transaction has enough tolerance to account for token taxes and prevent failed swaps. In the example code, the slippage increases by adding the tax percentages to a base of 0.5% when taxes are applied.
Last updated