示例#1
0
 def load_feeds(self):
     logs = decode_logs(
         get_logs_asap(str(self.registry),
                       [self.registry.topics['FeedConfirmed']]))
     self.feeds = {
         log['asset']: log['latestAggregator']
         for log in logs if log['denomination'] == DENOMINATIONS['USD']
     }
     self.feeds.update(ADDITIONAL_FEEDS)
     logger.info(f'loaded {len(self.feeds)} feeds')
示例#2
0
 def load_from_ens(self):
     # track older registries to pull experiments
     resolver = contract('0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41')
     topics = construct_event_topic_set(
         filter_by_name('AddressChanged', resolver.abi)[0],
         web3.codec,
         {'node': web3.ens.namehash('v2.registry.ychad.eth')},
     )
     events = decode_logs(get_logs_asap(str(resolver), topics))
     logger.info('loaded %d registry versions', len(events))
     return [Contract(event['newAddress']) for event in events]
def get_token_transfers(token, start_block, end_block) -> pd.DataFrame:
    topics = construct_event_topic_set(
        filter_by_name('Transfer', token.abi)[0],
        web3.codec,
    )
    postgres.cache_token(token.address)
    decimals = contract(token.address).decimals()
    events = decode_logs(
        get_logs_asap(token.address,
                      topics,
                      from_block=start_block,
                      to_block=end_block))
    return pd.DataFrame(
        Parallel(1, 'threading')(
            delayed(_process_transfer_event)(event, token, decimals)
            for event in events))
示例#4
0
def get_protocol_fees(address):
    """
    Get all protocol fee payouts for a given vault.

    Fees can be found as vault share transfers to the rewards address.
    """
    vault = Vault.from_address(address)
    rewards = vault.vault.rewards()

    topics = construct_event_topic_set(
        filter_by_name('Transfer', vault.vault.abi)[0],
        web3.codec,
        {
            'sender': address,
            'receiver': rewards
        },
    )
    logs = decode_logs(get_logs_asap(address, topics))
    return {log.block_number: log['value'] / vault.scale for log in logs}
示例#5
0
    def unwrap(self) -> List[Wrapper]:
        registry = Registry()
        wrappers = [self.wrapper] if isinstance(self.wrapper,
                                                str) else self.wrapper
        topics = construct_event_topic_set(
            filter_by_name('Transfer', registry.vaults[0].vault.abi)[0],
            web3.codec,
            {'receiver': wrappers},
        )
        addresses = [str(vault.vault) for vault in registry.vaults]
        from_block = min(ThreadPoolExecutor().map(contract_creation_block,
                                                  addresses))

        # wrapper -> {vaults}
        deposits = defaultdict(set)
        for log in decode_logs(get_logs_asap(addresses, topics, from_block)):
            deposits[log['receiver']].add(log.address)

        return [
            Wrapper(name=vault.name, vault=str(vault.vault), wrapper=wrapper)
            for wrapper in wrappers for vault in registry.vaults
            if str(vault.vault) in deposits[wrapper]
        ]
示例#6
0
def find_transfers(address, from_address, to_address, start_block, end_block):
    topics = construct_event_topic_set(abi, web3.codec, {
        "from": from_address,
        "to": to_address
    })
    return get_logs_asap(address, topics, start_block, end_block)