A gerotor pump is a two-piece mechanism where two rotational components, interior and exterior, engage each other via a rotational motion to transfer a fluid in a direction parallel to their rotational axes. A natural question arises on what shape of the gerotor is the optimal one in the sense of maximum fluid being pumped for a unit of time, given the constraint of a fixed material needed to manufacture the pump. As there is no closed-formula to answer this question, we propose a new algorithm to design and optimize the shape of gerotor pumps to be as efficient as possible. The proposed algorithm is based on a fast construction of the envelope of the interior component and subsequent optimization. We demonstrate our algorithm on a benchmark gerotor and show that the optimized solution increases the estimated flowrate by 16%. We also use our algorithm to study the effect of the number of teeth on the cavity area of a gerotor.RYC-2017-22649 funded by MICIU/AEI/10.13039/501100011033 and EI ESF "ESF Investing in your future