uniswap_v2.token_tax

Documentation for eth_defi.uniswap_v2.token_tax Python module.

Querying the buy tax, transfer tax & sell tax of an ERC20 token

Functions

estimate_token_taxes(uniswap, base_token, ...)

Estimates different token taxes for a token by running Ganache simulations for it.

Classes

TokenTaxInfo

Different token taxes we figured out.

Exceptions

ApprovalFailure

Yet another random Ganache failure.

OutOfGasDuringSell

The token is likely some sort of ponzi with restricted transfer.

OutOfGasDuringTransfer

The token is likely some sort of ponzi with restricted transfer.

SellFailed

Could not sell the token.

SwapError

The swap method reverted due to low liquidity of either the base or quote token

TransferFailure

The token transfer failed for some random reason.

TransferFromError

The token is likely broken.

exception SwapError

Bases: Exception

The swap method reverted due to low liquidity of either the base or quote token

__init__(*args, **kwargs)
__new__(**kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception TransferFromError

Bases: Exception

The token is likely broken.

See KICK on Ethereum mainnet.

__init__(*args, **kwargs)
__new__(**kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception OutOfGasDuringTransfer

Bases: Exception

The token is likely some sort of ponzi with restricted transfer.

See WETH-CGT on Ethereum mainnet.

__init__(*args, **kwargs)
__new__(**kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception OutOfGasDuringSell

Bases: Exception

The token is likely some sort of ponzi with restricted transfer.

See WETH-DEXE on Ethereum mainnet: 0xde4ee8057785a7e8e800db58f9784845a5c2cbd6

__init__(*args, **kwargs)
__new__(**kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception TransferFailure

Bases: Exception

The token transfer failed for some random reason.

VM Exception while processing transaction: revert Protection: 30 sec/tx allowed

https://tradingstrategy.ai/trading-view/polygon/quickswap/kmc-usdc

__init__(*args, **kwargs)
__new__(**kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception SellFailed

Bases: Exception

Could not sell the token.

__init__(*args, **kwargs)
__new__(**kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception ApprovalFailure

Bases: Exception

Yet another random Ganache failure.

__init__(*args, **kwargs)
__new__(**kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class TokenTaxInfo

Bases: object

Different token taxes we figured out.

base_token: eth_typing.evm.HexAddress

Token in the question

quote_token: eth_typing.evm.HexAddress

Which token we traded against it

buy_tax: float

How much % we lost of the token on buy

transfer_tax: float

How much % we lose the token when we transfer between addresses

sell_tax: float

How much % we lose the token when we sold it

__init__(base_token, quote_token, buy_tax, transfer_tax, sell_tax)
Parameters
Return type

None

estimate_token_taxes(uniswap, base_token, quote_token, buy_account, sell_account, buy_amount, approve=True, quote_token_details=None, base_token_details=None, gas_limit=None, gas_price=None)

Estimates different token taxes for a token by running Ganache simulations for it.

Parameters
  • uniswap (eth_defi.uniswap_v2.deployment.UniswapV2Deployment) – Uniswap deployment on a Ganache mainnet fork. Set up prior calling this function. See ganache.py and test_ganache.py for more details.

  • base_token (eth_typing.evm.HexAddress) – The token of which tax properties we are figuring out.

  • quote_token (eth_typing.evm.HexAddress) – Address of the quote token used for the trading pair. E.g. BUDS, WBNB Based on this information we can derive Uniswap trading pair address.

  • buy_account (eth_typing.evm.HexAddress) – The account that does initial buy to measure the buy tax. This account must be loaded with gas money (ETH/BNB) and quote_token for a purchase.

  • sell_account (eth_typing.evm.HexAddress) – The account that receives the token transfer and does the sell to measure the sell tax. This account must be loaded with gas money for the sell.

  • approve – Perform quote token approval before wap test

  • base_token_details (Optional[eth_defi.token.TokenDetails]) – Pass base token details. If not given automatically fetch.

  • quote_token_details (Optional[eth_defi.token.TokenDetails]) – Pass quote token details. If not given automatically fetch.

  • gas_limit (Optional[int]) – Use this gas limit for all transactions, so that we do not need to call eth_estimateGas on the node.

  • gas_price (Optional[int]) – Use this gas price for all transactions, so that we do not need to call eth_estimateGas on the node.

  • buy_amount (float) –

Returns

ToxTaxInfo tells us what we figure out about taxes. This can be later recorded to a database.

Return type

eth_defi.uniswap_v2.token_tax.TokenTaxInfo