Iran is in a state of upheaval. Thousands of Iranian protesters have poured into the streets over the last week. Hundreds have been arrested and several have been killed. These are the largest protests to hit the country since the unrest that followed the 2009 presidential elections, and they seem to be driven largely by anger over unemployment and wages.

Iran's economy has been something of a mess for decades. Like a lot of autocratic regimes that find themselves sitting atop abundant natural resources, Iran's economy is dominated by oil and gas. The industry is largely state-run (along with large swaths of the rest of the economy), it provides the bulk of the country's exports, and those exports pay for half to 80 percent of all government spending. As a result, much of Iran's employment, pay, and welfare support is basically oil revenue funneled through the government to the rest of the population.

This distorts the country's economy and policy in some key ways.

Because Iran pours so much energy and resources into exporting oil and gas, the rest of its economy isn't very self-sufficient. That leaves the whole country extremely vulnerable to shocks: If the price of oil moves in unexpected ways, it can threaten the entire economy. And when the United States slapped sanctions on Iran under President Obama, it pitched the country's economy into a recession.

Further, the vast majority of international oil trading is done in U.S. dollars, meaning dollars are in high demand throughout Iran. And while the government tries to manage the situation by using different exchange rates for different functions in the economy, that can also backfire and create black markets in the dollar. As a result, the government can lose control of the rial's value relative to the dollar, leading to bouts of runaway inflation. Iran is effectively unable to control its own currency. International market conditions can force it to cut spending and impose austerity regardless of the needs of its domestic economy.

The nuclear deal Iran struck with America and the West in 2015 lifted many sanctions. And Iran's economy did recover: It's projected to grow 4.2 percent in the year ending in March 2018, and inflation has fallen to 10 percent from 34 percent.

But while 10 percent inflation isn't catastrophic, it's still quite high. And it can be much worse in specific areas: Prices for things like eggs and poultry have reportedly surged as much as 40 percent recently.

An increase in imports also shrunk Iran's trade surplus. That's a problem because the country needs hefty reserves of U.S. dollars to keep its odd monetary system on an even keel, and it needs big trade surpluses to keep the dollars flowing.

Finally, because Iran doesn't control its currency, the country is extra reliant on foreign investors to bring in money to grow jobs and capital. And the uncertainty created by Donald Trump's presidency, especially over the future course of sanctions, seems to be making it hard for Iran to attract those foreign investors.

Iranian President Hassan Rouhani and his government promised the gains from the end of sanctions would flow down to the average Iranian citizen. But that hasn't happened.

Rouhani's predecessor, President Ahmadenijad, was a populist who spent lavishly on Iran's people and businesses. Rouhani has actually reversed course, restraining pay and cutting back on investments. Officially, unemployment in the sectors outside oil and gas is around 12 percent. Among Iranians age 15 to 29 it's at an eye-watering 24 percent, and is likely higher still for women and young people in cities. Far from spending more to help Iranians, the government is moving to cut subsidies for things like food and fuel by as much as 50 percent.

To free Iran to spend more and revive its economy, Rouhani would have to first get rid of the rial's peg to the dollar and stop relying on oil and gas revenues. That would require a wholesale reformation of Iran's government policy and its relation to the rest of Iran's domestic economy. It would also call for a long struggle to build up Iran's other industries and sectors, until they can provide Iranian households and businesses more of the goods and services they need, without relying on imports from abroad. None of that would be easy, and would likely lead to upheavals of their own.

So Iran will probably take the easy route, and keep trying to muddle through with the contradictory system it has. That will allow Iran to lavish rewards on its citizens when times are good. But it will also require randomly punishing them whenever international macroeconomic forces capriciously demand.