How precious metals were brought to Earth and preserved in a magma ocean