Financial constraints and market failures. The microfoundations of new Keynesian economics