Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Fix: Parse Events with an EventFilter Abigen #92

Open
Evan-Kim2028 opened this issue May 22, 2023 · 1 comment
Open

Fix: Parse Events with an EventFilter Abigen #92

Evan-Kim2028 opened this issue May 22, 2023 · 1 comment

Comments

@Evan-Kim2028
Copy link

Ideally all logs should not be manually parsed but should be handled with EventFilters generated through abigen. Currently new_from_event_log is a function used for parsing, which does not handle EventFilters generated through an abigen.

@0xKitsune
Copy link
Owner

Thanks for opening an issue for this. As mentioned in messages, here is a reference for how to use event filters generated by abigen. Feel free to make a PR!

abigen!(

    IUniswapV3Factory,
    r#"[
        event PoolCreated(address indexed token0, address indexed token1, uint24 indexed fee, int24 tickSpacing, address pool)
    ]"#;
);

  pub async fn new_from_log<M: 'static + Middleware>(
        log: Log,
        middleware: Arc<M>,
    ) -> Result<Self, DAMMError<M>> {
        let event_signature = log.topics[0];

        if event_signature == POOL_CREATED_EVENT_SIGNATURE {
            if let Some(block_number) = log.block_number {
                let pool_created_event = PoolCreatedFilter::decode_log(&RawLog::from(log))?;

                UniswapV3Pool::new_from_address(
                    pool_created_event.pool,
                    block_number.as_u64(),
                    middleware,
                )
                .await
            } else {
            //Some error ideally
            }
        } else {
            //Some error ideally
        }
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants