Fascinating article exploring levels of cooperation in different animals. In summary, tolerance (e.g. lack of aggression towards humans by wolves) can lead to cooperative behaviour.

Chimpanzees, though they know to deceive us (and each other) never
really learn that we are pointing towards food for them, whereas dogs
know this well.

So both have some form of theory of mind, but very different to the one we have.

A trial on wolves showed that this behaviour could be bred in  relatively rapidly (forty generations). The trial suggests that it might not have been survival of the fittest operating on dogs, but rather survival of the friendliest. So much interesting stuff in there to read. Well worth it.