U.S. stocks traded higher Tuesday, despite Greece getting closer to a default, as investors become mildly optimistic the country would reach an 11th-hour deal with its creditors after European Union authorities made a last-minute offer to Athens. All 10 sectors in the S&P 500 traded higher, led by gains in the energy, financial and materials sectors.

In afternoon trading, the Dow Jones Industrial Average (INDEXDJX:.DJI) added 43.18 points, or 0.25 percent, to 17,639.53. The Standard & Poor’s 500 index (INDEXSP:.INX) gained 8.18 points, or 0.40 percent, to 2,065.82. And the Nasdaq Composite (INDEXNASDAQ:.IXIC) rose 32.54 points, or 0.66 percent, to 4,997.61.

The Dow leaped 100 points in morning trading, a day after U.S. stocks suffered their worst losses of the year on fears Greece would default and leave the eurozone. The blue-chip index closed below its 200-day moving average.

However, creditors are attempting to strike a last-minute deal with Athens Tuesday after the country announced it would be unable to make its loan repayment to the International Monetary Fund (IMF) Tuesday.

“We want a viable solution. If we get a credible proposal that leaves even a sniff of a viable solution, we’ll be the first to take it,” a senior finance official told reporters in Brussels, Reuters reported.

Greece will be in arrears on an IMF repayment of 1.6 billion euros ($1.78 billion) as of 6 p.m. EDT.

While Greece’s debt drama will likely lead to higher volatility in the U.S. stock market ahead of Athens’ referendum vote Sunday, some experts don’t see immediate signs of a broader contagion.

“It’s likely there will be a flight to quality, especially to American stocks,” U.S. Trust said a research note this week.

The Nasdaq iShares biotechnology exchange-traded fund gained about 1.5 percent, boosted by gains from Biogen Inc. and Gilead Sciences Inc. Walt Disney Co. was the leader in the Dow Tuesday, up 1.5 percent, while Wal-Mart Stores Inc. was the laggard, down 0.3 percent.

Separately, data released Tuesday showed a further rebound in Americans’ optimism about the overall economy this month as U.S. consumer confidence jumped close to an eight-year high. The Conference Board’s Consumer Confidence Index rose to 101.4 in June, well above May's reading of  94.6.

This turnaround is especially encouraging coming at a time when gasoline prices have risen rapidly and equity prices have fallen, Paul Dales, senior U.S. economist at Capital Economics, said in a research note Tuesday. “Normally, such developments would reduce sentiment. But it appears that the drag from these factors has been more than offset by the strength of the labor market,” he said.