I think you are conflating natural selection the process with organisms that are a result of natural selection.
Natural selection isn’t a process that is intentionally made by anyone, but a way we describe a simplified model slew of complex processes.
Also conflated is what you are optimizing for. The only thing natural selection optimizes for is survival. That’s it. Nothing else matters expect which individuals survive long enough to pass their genes to the next generation. As a result niches develop and as each generation survives compared to their peers their survival strategies are optimized.
Optimization perfectly describes what is happening to the survivability and reproduction of certain genes.
You appear to be working backwards. That there was a niche and evolution somehow crafted an organism to fit that niche. That is misleading. Genes replicate, and in a certain context some genes survived and replicated better than in some other context. So genes evolved in that new context creating a niche.