Attitude Control On Manifolds Via Optimization And Contractions With Automatic Gain Tuning