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
See blog post about token tax and honey pots for more information
Read also unit test suite tests/test_token_tax.py to see the retrieval of token taxes for ELEPHANT token on BSC
Functions
|
Estimates different token taxes for a token by running Ganache simulations for it. |
Classes
Different token taxes we figured out. |
Exceptions
Yet another random Ganache failure. |
|
The token is likely some sort of ponzi with restricted transfer. |
|
The token is likely some sort of ponzi with restricted transfer. |
|
Could not sell the token. |
|
The swap method reverted due to low liquidity of either the base or quote token |
|
The token transfer failed for some random reason. |
|
The token is likely broken. |
- exception SwapError
Bases:
ExceptionThe 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:
ExceptionThe 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:
ExceptionThe 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:
ExceptionThe 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:
ExceptionThe 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:
ExceptionCould 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:
ExceptionYet 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:
objectDifferent 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
- __init__(base_token, quote_token, buy_tax, transfer_tax, sell_tax)
- Parameters
base_token (eth_typing.evm.HexAddress) –
quote_token (eth_typing.evm.HexAddress) –
buy_tax (float) –
transfer_tax (float) –
sell_tax (float) –
- 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.
See blog post about token tax and honey pots for more information.
See unit tests for usage examples
- 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