I want to find out whenever a new Uniswap pool is created and funded with an at least .5 ETH of liquidity. Is there a way to do this programmatically?
2 Answers
Disclaimer: I work with QuickNode
You can track these events using QuickAlerts and get realtime notification as soon as they occur. You have to track the topic0 hash of the event + the smart contract address. Let me explain how:
For Uniswap v2. You'd have to track Topic0 of the
PairCreated
event which is0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9
For Uniswap v3, You'd have to track Topic0 of the
PoolCreated
event which is0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118
Then the Factory smart contract needs to be tracked too,
- Factory contract for Uniswap v2:
0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f
- Factory contract for Uniswap v3:
0x1F98431c8aD98523631AE4a59f267346ea31F984
Learn how to setup QuickAlerts here:
The expression to track would be the events would be,
For Uniswap v2,
(tx_value >= 500000000000000000) && (tx_logs_address == '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f') && (tx_logs_topic0 == '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9')
For Uniswap v3,
(tx_value >= 500000000000000000) && (tx_logs_address == '0x1F98431c8aD98523631AE4a59f267346ea31F984') && (tx_logs_topic0 == '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118')
For both v2 and v3
(tx_value >= 500000000000000000) && ((tx_logs_address == '0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f' && tx_logs_topic0 == '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9') || (tx_logs_address == '0x1F98431c8aD98523631AE4a59f267346ea31F984' && tx_logs_topic0 == '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118'))
Deconstructing the expressions:
tx_value
checks for the ETH value of transactions 500000000000000000 in the above examples as the value needs to be mentioned in Wei.tx_log_address
checks for the address of smart contract.tx_logs_topic0
checks for the log topic0 of the emitted logs.
You can do this with web3.py by listening to PairCreated events emitted by the factory address and there after check whether this project launched with liquidity or not using Uniswap liquidity pool pair address abi to check for added liquidity amount.
from web3 import Web3
web3 = Web3(Web3.HTTPProvider("Enter your Alchemy Node"))
uniswap_factory = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'
Uniswap_factory_abi = json.loads('Enter ABi')
contract = web3.eth.contract(address=uniswap_factory, abi=Uniswap_factory_abi)
liquidityPairAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" #It's standard for most token to pair with WETH Address so we will be checking these pools.
lp_abi='Enter Uniswap v2 ABI' #Here is Uniswap V2 Address-0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
def get_token_from_lp(lpAddres):
uniswap_v2_pair = web3.eth.contract(address=lpAddres,abi=lp_abi)
tokenA_address = uniswap_v2_pair.functions.token0().call()
tokenB_address = uniswap_v2_pair.functions.token1().call()
if tokenA_address == liquidityPairAddress:
return 0
elif tokenB_address ==liquidityPairAddress:
return 1
def get_liquidity_balance(lp_address):
lp_contract = web3.eth.contract(address=lp_address, abi=lp_abi)
reserves = lp_contract.functions.getReserves().call()
index= get_token_from_lp(lp_address)
balance = reserves[index]
return balance
event_filter = contract.events.PairCreated.create_filter(fromBlock="latest")
while True:
try:
#events = event_filter.get_all_entries()
events = event_filter.get_new_entries()
if len(events) > 0:
for event in events:
if (event['args']['token1'] == liquidityPairAddress):
tokenAddress = event['args']['token0']
lp_address=contract.functions.getPair(tokenAddress,liquidityPairAddress).call()
lp_balance= get_liquidity_balance(lp_address)
tokenLiquidityAmount = float(web3.from_wei(lp_balance, "ether"))
print(f"Token Address: {tokenAddress}, Lp Amount{tokenLiquidityAmount}")
I hope this starter code get you going.