Optimal Contracts, Aggregate Risk, and the Financial Accelerator