0

I am new to dev in python with Web3.

I want to calculate the buy and sell tax for a token in uniswap.( like honeypot.is website, but directly onchain)

I search here and in google but i can't find any topics about this.

Thanks for your help.

0

1 Answer 1

1

The only reliable method how to get the taxes is to execute the transaction and measure its slippage. To do that:

  1. Decide on the input amount of tokens to buy or sell.

  2. Fork the blockchain at a recent block, using hardhat or a similar tool.

  3. Calculate the expected output amount given your input amount, for example using a getAmountOut() call.

  4. Create and send a buy/sell transaction with the input amount, send it to the local hardhat instance, and measure the received output amount

  5. Compare the expected output amount with the measured output amount. The difference is due to the sales tax.

Be aware that the owner of the contract typically is allowed to change the sales tax at a later point.

2
  • Thanks for your reply. It's a little complicated. Isn't there another lighter solution? Moreover, in the case of modification of taxes by the creator of the contract, the hardhat fork will not take the change into account.
    – CryptoSeb
    Sep 26, 2022 at 18:48
  • The problem is that in the real world, you cannot assume non-adversial counterparties, so simulation is the only reliable way to get the fees.
    – kfx
    Sep 27, 2022 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.