Occasionally Missing Events

I have a program that listens for new events coming from the uniswap factory contracts to detect when a new factory is created. It seems about 50% of the time it misses actual events and does not receive an event when a factory is created. As mentioned this only happens roughly 50% of the time.

To compare the results of my program I’m using this twitter account which tweets out when new pairs are created as a baseline. The last pair created that was detected by my bot is this one however all pairs created since then have been missed by my bot.

Here is a snippet of my code that I’m using

        // this uses contract bindings generated by abigen to create a factory contract
	factory, err := c.uc.Factory()
	if err != nil {
		return err
	}
	ch := make(chan *uniswapv2factory.Uniswapv2factoryPairCreated, 100)
	sub, err := factory.WatchPairCreated(nil, ch, nil, nil)
	if err != nil {
		return err
	}
	defer func() {
		sub.Unsubscribe()
		close(ch)
	}()
	logger := c.l.Named("uniswap.factory")
	logger.Info("starting uniswap factory pair creation monitor")
	for {
		select {
		case <-c.ctx.Done():
			return nil
		case err := <-sub.Err():
			logger.Error("encountered error watching uniswap factory", zap.Error(err))
			return err
		case evLog := <-ch:
                       // do stuff
		}
	}

I’m running this bot from a digital ocean droplet in the cloud

Thanks for sharing! Your idea is interesting. Do you have any other targets to look for ?

Since yesterday my bot has missed all uniswap pair creation via the factory. This is a but suboptimal as it harms the usability of my bot. Is there anything I can do to remedy this situation?

I’ve taken a look at some of the pairs that have been created, and it appears that they are being created via internal contract transactions. I suspect this might be why Infura is missing out on some of the events and not detecting factory creation.

This transaction is one such example, an internal transaction was responsible for the pair creation.


@chrisek

I’m developing this functionality as part of a larger service that handles information aggregation and discovery of unique targets without the user needing to deal with this themselves. If you’re interested in learning more about this you can dm me on twitter.