Optimal control of energy extraction in wind-farm boundary layers