By Hyunjoo Jin and Nivedita Balu

(Reuters) -Tesla Inc on Wednesday reported a higher-than-expected quarterly profit as a string of price increases on its best-selling electric vehicles helped offset production challenges, sending its shares up 4% in extended trading.

“With each of the Fremont and Shanghai factories achieving their highest-ever production months and new factory growth, we are focused on a record-breaking second half of 2022,” Tesla said in a statement.

Tesla said it has converted approximately 75% of its bitcoin purchases into fiat currency, which added $936 million of cash to its balance sheet.

The EV maker posted an adjusted profit of $2.27 per share versus analysts’ consensus estimates of $1.81.

Its automotive gross margin fell to 27.9%, down from a year earlier and the preceding quarter, amid inflationary pressure.

The company has raised prices of its cars several times this year to cope with higher costs of lithium used in batteries and aluminum used for the body, along with other raw materials.

Chief Executive Officer Elon Musk has said, however, that Tesla would drop prices when inflation cools.

Total revenue fell to $16.93 billion in the second quarter from $18.76 billion a quarter earlier, ending its streak of posting record revenue in recent quarters, as it struggled to meet demand for its electric cars due to a shutdown of its Shanghai factory and production challenges at new plants.

Analysts were expecting revenue of $17.10 billion, according to IBES data from Refinitiv.

Tesla is bracing for a potential recession and mounting competition from rivals. It also faces challenges of significantly boosting production in the second half, after China’s lockdowns hit production of the company and its suppliers.

Musk also has said Tesla’s new factories in Texas and Berlin were struggling to boost production, calling them “gigantic money furnaces” which are losing billions of dollars.

Musk said he had “a super bad feeling about the economy” in June and began layoffs.

(Reporting by Hyunjoo Jin in San Francisco and Nivedita Balu in Bengaluru Editing by Anil D’Silva, Peter Henderson and Matthew Lewis)