A federal bankruptcy court judge on Friday said he will approve OxyContin-maker Purdue Pharma’s latest deal to settle thousands of lawsuits over the toll of opioids that includes some money for thousands of victims of the epidemic.

The deal overseen by U.S. Bankruptcy Judge Sean Lane would require members of the Sackler family who own the company to contribute up to $7 billion over 15 years. The new agreement replaces one the U.S. Supreme Court rejected last year, finding it would have improperly protected members of the family against future lawsuits. The judge said he would explain his decision in a hearing on Tuesday.

It's among the largest in a series of opioid settlements brought by state and local governments against drugmakers, wholesalers and pharmacies. It could close a long chapter — and maybe the entire book — on a legal odyssey over efforts to hold the company to account for its role in an opioid crisis connected to 900,000 deaths in the U.S. since 1999, including from heroin and illicit fentanyl.

Lawyers and judges involved have described it as one of the most complicated bankruptcies in U.S. history. Ultimately, attorneys representing Purdue, cities, states, counties, Native American tribes, people with addiction and others were nearly unanimous in urging the judge to approve the bankruptcy plan for Purdue, which filed for protection six years ago as it faced lawsuits with claims that grew to trillions of dollars.