Last active
October 5, 2021 23:00
-
-
Save mariorz/85c5d0c6f47d3fe0803ba2e2d7fff5d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from brownie import * | |
from web3._utils.filters import construct_event_filter_params | |
from web3 import Web3 | |
import requests | |
import time | |
erc20_abi_url = 'https://unpkg.com/@uniswap/v2-core@1.0.1/build/IERC20.json' | |
_cache = dict() | |
def get_cached_abi(abi_url): | |
"""Per process over-the-network ABI file retriever""" | |
spec = _cache.get(abi_url) | |
if not spec: | |
spec = _cache[abi_url] = requests.get(abi_url).json() | |
return spec | |
def create_contract(web3, abi_url, address): | |
spec = get_cached_abi(abi_url) | |
contract = web3.eth.contract(address, abi=spec['abi']) | |
return contract | |
def fetch_logs(token_address, topics): | |
start = time.time() | |
argument_filters = dict() | |
_filters = dict(**argument_filters) | |
pool = create_contract(web3, erc20_abi_url, token_address) | |
abi = pool.events.Transfer._get_event_abi() | |
abi_codec = pool.events.Transfer.web3.codec | |
data_filter_set, event_filter_params = construct_event_filter_params( | |
abi, | |
abi_codec, | |
contract_address=token_address, | |
argument_filters=_filters, | |
fromBlock=0, | |
address=token_address, | |
topics=topics) | |
logs = pool.events.Transfer.web3.eth.getLogs(event_filter_params) | |
end = time.time() | |
print("time secs:", end - start) | |
return logs | |
address_main = "0x055CEDfe14BCE33F985C41d9A1934B7654611AAC" | |
address_arbi = "0x8f93Eaae544e8f5EB077A1e09C1554067d9e2CA8" | |
topics_main = ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", | |
"0x0000000000000000000000000000000000000000000000000000000000000000", | |
"0x000000000000000000000000db1340a571333eb16ddae9518c4641e511b16dd5"] | |
topics_arbi = ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", | |
"0x0000000000000000000000000000000000000000000000000000000000000000", | |
"0x00000000000000000000000065faeb3d0e175f1410caadfb6fdf466bb54f2069"] | |
def main(): | |
network.disconnect() | |
print("---mainnet-----------") | |
network.connect('mainnet') | |
logs = fetch_logs(address_main, topics_main) | |
print(len(logs)) | |
print(logs) | |
network.disconnect() | |
print("---arbitrum----------") | |
network.connect('arbitrum-main') | |
logs = fetch_logs(address_arbi, topics_arbi) | |
print(len(logs)) | |
print(logs) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment