I have a list of token addresses that I would like to poll for when the Add Liquidity ETH
method is called. I know that you can access contract events by using:
web3 = Web3(my_provider)
contract = web3.eth.contract(address=token_address, abi=token_abi)
contract.events.event_name_here
However, two things seem unclear to me...
- Some tokens aren't verified contracts and therefor do not have an ABI listed. And even if they are and do have an ABI listed. It seems that it is inconsistent whether or not that method is listed in there. So how is it possible to get the contract when the ABI is not listed?
- If you assume what the ABI is by using the standard ERC20 ABI as listed in an answer here: https://ethereum.stackexchange.com/a/29929. Wouldn't you still run in to the same issue as above where the contract will not show you the
Add Liquidity ETH
method.
To provide an example if we look at APAD. You can see liquidity was added about a week ago as shown in the screenshot here:
In APAD's case, their method is called addLiquidity
and it can be seen in their source code and ABI. So I understand that this differs a little bit from other contracts that call it addLiquidityETH
or whatever else.
What is the best way to detect when this event happens? Am I on the right track with trying to do this by using contract.events
? If so how would I check for when that event happens?
EDIT
With some help from the answer below I am getting further along. I am able to detect transfers that are being made by doing the following:
token_contract = web3.eth.contract(address=created_pair.get_token_address(weth_contract),
abi=standard_erc20_abi)
check_liquidity_filter = token_contract.events.Transfer.createFilter(fromBlock='latest')
asyncio.run(await log_liquidity(check_liquidity_filter, 2))
And here is my log_liquidity
method:
async def log_liquidity(event_filter, poll_interval):
while True:
print("checking for liquidity")
for res in event_filter.get_new_entries():
print(Web3.toJSON(res))
await asyncio.sleep(poll_interval)
In my most recent example I pulled the token data for this pairing:
token0: https://etherscan.io/address/0x694aeb98D02bf69a20a1bA754F07acfA2F4D8f9E
token1: https://etherscan.io/address/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
pair: https://etherscan.io/address/0x2297cfc74CcD5880d835d1009Bd6328D3D9E62e3
Token1
being WETH
and Token0
being the new Token in question.
I eventually picked up the following event that happened:
{
"args": {
"from": "0x2297cfc74CcD5880d835d1009Bd6328D3D9E62e3",
"to": "0x970075Ffb8feCaA79135c385dB8461dFF488c96B",
"value": 26448300574725940621084517}, "event": "Transfer",
"logIndex": 13,
"transactionIndex": 13,
"transactionHash": "0xefb43d7c033a6b6fe1aeda8812c1a4a1c2b0a7db2bb54cbffc56b3a06405c210",
"address": "0x694aeb98D02bf69a20a1bA754F07acfA2F4D8f9E",
"blockHash": "0x2c33968dd4f2fcd70214a019903ea00ea61cbfbff896b12d913dd29c6580f9ad",
"blockNumber": 14420431
}
}
This does not seem to line up with the initial liquidity being added from the transaction here:
https://etherscan.io/tx/0x18efca59fefef67da7512da180ed29fd564931d71f7bf81114f3a2e88721c1a7
- It does not seem to be the correct block number.
- The
To address
in the pair seems to be the pairing address, but this is supposed to be thefrom address
?