Optimal Online Learning using Potential Functions