If you are just interested in the period between 1819-1821 just butterfly Riego's coup.If he landed in Buenos Aires San Martín had no chance of winning and if he joined forces with the Viceroy of Perú he would have beaten Bolivar with ease.Riego's coup also caused the independence of Mexico (royalist won the war but didn't want the liberal constitution that Riego implanted). So if you butterfly away Riego's coup the royalist would have won the war.From there moving to a confederation and then into a commonwealth would have been a possibility.
If you go a bit back the Count of Aranda was planning on making the Spanish empire a confederacy with 4 kings (The king of New Spain,the king of New Granada,the king of Perú and the king of la Plata) and one emperor (the emperor of Spain,Cuba,Puerto Rico,Hispaniola and the Phillipines).