Introducing state-of-the-art Buy/Sell Tax support

Reduce error rates and enhance the swap experience for your users with real-time buy/sell tax detection and intelligent trade routing.

Published on
September 5, 2024
News
Introducing state-of-the-art Buy/Sell Tax support

The rise of memecoins has led to an explosion of tokens with a buy or sell tax, also known as fee-on-transfer tokens (FoT), with ~25% of DEX users now trading these tokens on Ethereum. This category of tokens is part of a larger group of ERC20 tokens with custom properties – in this case, a “tax” is taken as a percentage of the swap when the token is bought or sold.

Buy/sell taxes throw a wrench into well built swap products, leading to not only high error and revert rates, causing headaches for developers, but also inaccurate quotes, leading to poor user experiences. They are the #1 cause of custom token related errors.

Until now, there hasn’t been a reliable way to get accurate, real-time information needed to properly support buy/sell taxes, leaving apps to rely on hacky workarounds, such as dynamically adjusting slippage tolerance, that don’t always work.

0x v2 solves this problem with real-time buy/sell tax detection and intelligent trade routing for the most reliable onchain execution in DeFi, minimizing error rates and enhancing the swap experience for your users.

“Whoops, something went wrong”

Custom token behavior isn’t a new phenomena that’s isolated to long-tail tokens and memecoins. Some of the most popular tokens have custom functionality that may not be apparent until you dig into the source code.

For example, USDC has custom rules that allow Circle to block, freeze, or directly modify the balance of any address. This is necessary for Circle to ensure compliance, mint and redeem USDC in exchange for US dollars, and transfer USDC across chains using CCTP.

Custom logic allows ERC20 tokens to be adapted for interesting new use cases, but the recent explosion of this new category of tokens with buy/sell taxes has also created challenges that impact developers and users alike.

Buy/sell taxes in particular wreak havoc on settlement contracts, as they wind up attempting to sell or receive less than what the quote demands. Some 0x integrators have reported up to 80% of all errors are due to custom token behaviors.

The lack of reliable buy/sell tax support in DeFi today results in high error and revert rates and inaccurate quotes, preventing apps from offering a truly robust swap product to their end users. Revert rates for trades that include tokens with buy/sell taxes on top aggregators can reach as high as 30% and aggregators often exclude taxes in quotes, potentially misleading users about the final amount they will receive.

The slippage of it all

Many current solutions to the buy/sell tax problem rely on querying an external static database of token properties to determine the buy/sell tax. This assumes a fixed percentage tax that applies uniformly to every trade. In reality, many taxes are dynamic and can vary by time, trade size, trade direction, liquidity source, volume, and apply to wallets in a non-uniform way. External data sources are also often incomplete or outdated.

In order to successfully execute trades with buy/sell tax tokens, swap products may attempt to use this static data to dynamically adjust slippage to account for the tax. However, hacky workarounds don’t always work.

Meddling with slippage to account for potential tax is a slippery slope. While it may lower error and revert rates in your app, if the slippage tolerance is set too low, the trade will revert. If it’s set too high, it opens users up to MEV attacks. Is it worth the trade-off? Not if there’s a better way.

Slippage is fundamentally a different concept from buy/sell tax, and it’s simply the wrong tool for the job.

Buy/sell tax support that just works

The most reliable method for delivering precise taxes to ensure that swaps go through every time is to run onchain simulations for a particular wallet and trade before returning a quote. That’s exactly what 0x v2 does. 

Instead of relying on static data, 0x v2 simulates each trade to detect and calculate the correct buy/sell tax in real-time and intelligently routes the trade through liquidity sources that support buy/sell tax tokens, minimizing errors and reducing reverts. 0x v2 also enables you to accurately surface the precise tax for a given trade to your users.

And it’s not just for a handful of tokens. With 0x v2, you’re guaranteed to have the widest coverage of tokens with buy/sell taxes because 0x APIs natively detect and factor in these costs upfront. From the time these tokens hit the chain, v2 is able to generate executable routes within an hour.

All of this means dramatically reduced error and revert rates, expanded token coverage, and an improved experience for your users. With 0x v2, you can say goodbye to hacky workarounds with buy/sell tax support that just works.

0x API v2 features

  • Returns valid quotes and calldata for tokens with a buy/sell tax in /price and /quote APIs
  • Returns the token’s custom behavior status via the API (buy/sell tax)
  • Returns the value of the tax via the API so that you can display it to your users
  • Returns the actual amount that the user will receive accounting for the buy/sell tax

Are you ready to get serious?

0x’s next-gen pricing engine is in open beta! v2 offers the most seamless swap experience at the best all-in prices with optimal trade execution, powerful new monetization features, and enhanced security.

Book a v2 onboarding call to get started.