BP agrees to pay $340 million for restoration projects