2 pool

Comment

Author: Admin | 2025-04-28

F: factories = json.load(f)# [...]# Fetch list of pools for each factory contractpairDataList = []for factoryName, factoryData in factories.items(): events = getPairEvents(w3.eth.contract(address=factoryData['factory'], abi=factory_abi), 0, w3.eth.block_number) print(f'Found {len(events)} pools for {factoryName}') for e in events: pairDataList.append({ "token0": e["args"]["token0"], "token1": e["args"]["token1"], "pair": e["args"]["pair"], "factory": factoryName })We will simply invert pairDataList into a dictionary where the keys are the token pairs, and the values are the list of pools that trade this pair. When looping through the list, we ignore the pairs that don't involve ETH. When the loop is over, pairs with at least 2 pools are selected and will be stored in lists with at least 2 elements:# [...]WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" # official WETH addresspair_pool_dict = {}for pair_object in pairDataList: # Check for ETH (WETH) in the pair. pair = (pair_object['token0'], pair_object['token1']) if WETH not in pair: continue# Make sure the pair is referenced in the dictionary. if pair not in pair_pool_dict: pair_pool_dict[pair] = []# Add the pool to the list of pools that trade this pair. pair_pool_dict[pair].append(pair_object)# Create the final dictionnary of pools that will be traded on.pool_dict = {}for pair, pool_list in pair_pool_dict.items(): if len(pool_list) >= 2: pool_dict[pair] = pool_listSome stats should be printed to have a better grip on the data we are working with:# Number of different pairsprint(f'We have {len(pool_dict)} different pairs.')# Total number of poolsprint(f'We have {sum([len(pool_list) for pool_list in pool_dict.values()])} pools in total.')# Pair with the most poolsprint(f'The pair with the most pools is {max(pool_dict, key=lambda k: len(pool_dict[k]))} with {len(max(pool_dict.values(), key=len))} pools.')# Distribution of the number of pools per pair, decilespool_count_list = [len(pool_list) for pool_list in pool_dict.values()]pool_count_list.sort(reverse=True)print(f'Number of pools per pair, in deciles: {pool_count_list[::int(len(pool_count_list)/10)]}')# Distribution of the number of pools per pair, percentiles (deciles of the first decile)pool_count_list.sort(reverse=True)print(f'Number of pools per pair, in percentiles: {pool_count_list[::int(len(pool_count_list)/100)][:10]}')At the time of writing, this outputs the following:We have 1431 different pairs.We have 2509 pools in total.The pair with the most pools is ('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xdAC17F958D2ee523a2206206994597C13D831ec7') with 16 pools.Number of pools per pair, in deciles: [16, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]Number of pools per pair, in percentiles: [16, 5, 4, 3, 3, 3, 3, 3, 3,

Add Comment