Just days later, the deal with refiner Philadelphia Energy Solutions went up in flames.

A critical unit at the Philadelphia refinery exploded, trapping roughly 3 million barrels of ICBCS-owned oil, worth hundreds of millions of dollars, at the plant. The refinery swiftly declared bankruptcy and shut permanently.

London-based ICBCS sold most of the oil at a sharp discount, and the losses pushed it into the red for 2019, according to a source familiar with the bank's finances.

The source told Reuters the bank is expected to disclose in its annual earnings report in March that after selling most of its PES oil inventory at a big discount, it lost around $200 million (£156 milllion), far exceeding the $130 million provision for losses in the first-half earnings report published in August.

ICBCS declined to comment for this story.

Independent refiners commonly use what are known as intermediation agreements, where a bank agrees to supply a refinery with crude oil and then buys and resells the refined products. This was ICBCS's first such agreement with a U.S. refinery, and it involved extending credit to PES, whose financial struggles in recent years had limited its access to funding.

ICBCS - a joint venture between Industrial and Commercial Bank of China, the world's biggest-listed lender by assets, and South Africa's Standard Bank, Africa's biggest lender, is still trying to recoup losses from the deal.

ICBCS cut staffing. In December, it merged its base metals desk with its precious metals team.

"The energy business remained intact despite the losses," the source said, adding that the bank could still work on similar deals to finance refiners, but expects to be more cautious when selecting customers.

As of Feb. 3, ICBCS said it was owed $334 million by PES in connection with the deal.

ICBCS had about 3.3 million barrels of crude oil, gasoline and other refined products in or near the 335,000-barrel-per-day refinery when its alkylation unit exploded on June 21, and financed $1.5 billion in the total intermediation deal, according to court filings by ICBCS attorneys in July.

"That's something that would make a bank quite nervous," said Kurt Barrow, an IHS Markit consultancy vice president. "That collateral is king to them," he said, referring to the fuels.

ICBCS started talks with PES in 2018, when the Philadelphia refiner was working through a previous bankruptcy. PES had been working with Bank of America Merrill Lynch, but switched to ICBCS as BofA wanted to raise its borrowing rates, according to two sources familiar with the plan. Bank of America did not respond to a request for comment.

PES intended to sign with ICBCS by January 2019, but the deal took six months longer as the refinery struggled to separate from the systems established with BofA, the sources said. PES was not available for comment.

Independent refiners commonly use intermediation, or supply-and-offtake, agreements, Barrow said, but U.S. banks have participated in fewer of these arrangements following the passage of the Volcker Rule, which restricts a bank's ability to bet its own funds in financial markets.

Even though ICBCS had charged rates to account for the riskiness of working with PES over the life of its contract, it did not factor in an almost immediate default.

It was also difficult and costly to extract the oil and products from the shut refinery. PES workers had to remove the crude and products stuck at the bottom of tanks using vacuum systems in a process that could not start for roughly five months after the closure, according to two sources familiar with the work.

Some of the products were not processed through to completion, and were sold off-spec, or not meeting the quality set by a contract or regulation, which reduces the value. The inventory removal process is expected to run through March, a source familiar with the plan said.

(Reporting by Laila Kearney and Florence Tan; Additional reporting by Pratima Desai in London and Cheng Leng in Beijing; Editing by David Gaffen and David Gregorio)

By Laila Kearney and Florence Tan