The US trade deficit shrank unexpectedly by over 4 percent in June, as a weak dollar boosted exports to an all-time high, according to official figures released Tuesday.   US Commerce Department statistics show the June trade deficit at $56.8 billion, down from $59.2 billion in May. Exports of goods and services rose 4 percent to a record $164.4 billion, offsetting a 1.8 percent rise in imports.    Although the dollar has recently gained ground against the euro and other currencies, its earlier decline helped export orders by making US goods cheaper abroad.