I believe I have found a bug in that events generated from internal contract transactions are not received from event listeners when using the websockets api. I’m working on a bot that listens for events from certain sets of contracts, in particular the uniswap factory contract which emits a PairCreated
event anytime a new uniswap pair is created through the factory.
To test this bot I’m comparing it’s results against https:// twitter. com/uniswaptokenbot which tweets all pairs that are created. I’ve noticed a discrepancy between what my bot finds, and what this twitter bot finds. This discrepancy is that any pair created through an internal contract transaction will be missed by my bot, but discovered by the twitter account. However this doesn’t always appear to be the case, but it is the main common denominator of events which are missed by my bot.
The code I have which listens for the events is displayed below
// 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
}
}