The Network Origins of the Gains from Trade