Metabolic scaling is the product of life-history optimization