Static compensators (STATCOMs) are conventionally used to improve grid stability by supporting reactive power. Microgrids are inherently less stable compared to conventional grids and need even better grid support infrastructure compared to conventional grids. Increase in renewable energy integration reduces the stability of the existing grid. Modern electronic loads also inject harmonics into the grid. With the emergence of power generation from solar energy with grid -connected single-phase inverter at homes, single-phase STATCOMs may be used to improve the grid stability in single-phase distribution grids and microgrids. Enhanced STATCOMs with energy storage device like a battery on its dc bus further improves the quality of grid support by providing active power for short periods along with reactive and harmonic support. Conventional methods like envelope, synchronous reference frame have been traditionally used to control the operations of a grid-connected inverter behaving as a solid-state harmonic compensator. But none of the conventional algorithms takes the physical limitations of the converter hardware into account in the control process. In this paper, an optimisation based control methodology is proposed which performs better than the existing control algorithms on many accounts. In this paper, an optimisation based reference current generation (ORCG) algorithm is proposed for the enhanced single-phase STATCOM that can generate a current reference for controlling the converter, taking various constraints and current limit into account. The proposed algorithm also inherently minimises the THD of compensated current which is an added benefit. © 2020 IEEE.