Optimal Loss Mitigation and Contract Design