Congressional negotiators finalized an immigration deal on Thursday that would codify legal protections for undocumented minors while giving President Donald Trump some tangible victories of his own.

The deal, which was forged in the Senate, still faces major hurdles; chief among them a healthy skepticism from conservatives—including some officials in the White House—and a difficult path to passage in the House. But one lawmaker told The Daily Beast that there was a “growing sense of optimism” that negotiators had crafted an agreement that could, at a minimum, pass the Senate and put pressure on the House to act.

Congressional sources and lawmakers were universally cagey in discussing the specifics, but after The Daily Beast reported on the the basic contours of the agreement, Sen. Jeff Flake (R-AZ) confirmed the details that were initially described by aides and lobbyists privy to the negotiations.

The final deal will codify the legal protections for so-called DREAMers that Trump rescinded when he ended the Deferred Action for Childhood Arrivals (DACA) program that began under his predecessor. The deal also seeks to undo another Trump decision: the termination of the Temporary Protected Status (TPS) designation for certain groups of immigrants, including Salvadorans, 200,000 of whom could face an end to their legal status in 2019.

In an interview Thursday afternoon, Flake confirmed those details to The Daily Beast. He said the DACA fix agreed to as part of the deal includes a pathway to citizenship for DREAMers. Additionally, they will have to wait 12 years from the time they are awarded protected status before they can gain citizenship, according to a congressional source familiar with the negotiations, and they can earn up to two years of credit for any time spent as a DACA beneficiary. Groups of immigrants such as Salvadorans would be able to access the diversity visa lottery program if they have Temporary Protected Status, according to Flake.

In exchange for backpedaling two of his initiatives, Trump would score some real policy victories. The deal will revamp but not end the visa lottery program, numerous sources said. The formula for so-called chain migration—the policy whereby lawful permanent residents can sponsor immigrants to the U.S.—was re-drawn in a way that alters the ability of those DREAMers to sponsor their relatives for legal status.

“The covered population—the parents who brought their kids across the border illegally—would not be able to access a citizenship track by virtue of their children,” Flake said. “So we’ve cut chain migration with regard to the covered population.”

Negotiations are ongoing about how to strengthen the e-Verify system that allows businesses to determine the legal status and eligibility of the workers they hire. The deal will, regardless, include a border security investment of at least $1 billion for new technology. Democrats have expressed a willingness to accept such an arrangement, provided it was geared toward new border monitoring technologies.

The final deal will also include money for some sort of physical structure along the southern border. Just what that structure will be called and what it will resemble is still unclear. Trump has demanded funding for a wall, though he has backed off of his insistence that it be a coast-to-coast concrete barrier funded by the Mexican government. Democrats, and some Republicans, are adamantly opposed to a wall being built.

In somewhat typical Washington fashion, negotiators were working to find the right nomenclature to satisfy both sides. Less difficult, though, is figuring out how much money will go to a border structure. The lobbyist said it would be well below the $18 billion that Trump has requested—and one lawmaker involved in the negotiations said just $1.6 billion was allocated.

As is always the case with such high-stakes negotiations, the possibility of failure remains real. Flake’s working group—which includes Sens. Lindsey Graham (R-S.C.), Dick Durbin (D-IL), Bob Menendez (D-N.J.), Michael Bennet (D-CO) and Cory Gardner (R-CO)—was already facing resistance on Thursday from their fellow lawmakers, who suggested that Trump was not on board with the proposal.

The main negotiations have been spearheaded by a bipartisan group of senators. But after a meeting at the White House this week, the whips of each chamber—Sens. Durbin and John Cornyn (R-TX) as well as Reps. Steny Hoyer (D-MD) and Kevin McCarthy (R-CA)—started their own working group.

The White House has been working alongside that unit. But there is also tangible concern among Democrats and some Republicans on Capitol Hill that the administration’s involvement might hamper matters more than they help.

In particular, aides have been wary that policy adviser Stephen Miller, a noted immigration hardliner, has been back-channeling with conservative lawmakers to demand tougher interior enforcement measures as part of any final product. Senators involved in the negotiations, notably Flake, have argued that Trump’s “instincts” are in the right place when it comes to saving DACA, despite the “advice” he receives from those around him—a thinly veiled reference to Miller.

So far, White House chief of staff John Kelly has run point in talks with congressional officials. But Marc Short, the White House Director of Legislative Affairs, told The Daily Beast that Miller was “not out of the loop.”

“We think he knows the issue of immigration better than anyone,” Short said, noting that Miller was a key aide on the policy for then-Sen. Jeff Sessions (R-AL). “Because of that, if there is a deal that can be done with Democrats, Stephen knows where and how.”

The next step for the Senate working group, the lawmakers said in a statement, is to “build support” for the deal in Congress—a task that is shaping up to be a tall order.

Officials in the administration were notably less bullish than congressional aides and outside advocates about the possibility of a deal passing both the House and Senate. One senior White House official said that the “scope continues to narrow but we still are a ways off.” There is also a broader fear that anything agreed upon in the Senate would ultimately die in the House, where Republican lawmakers are far less likely to be comfortable with any legislative product that codifies DACA and does not include more funding for a border wall.

And, in recent days, other developments have suggested that bipartisan progress may be limited to the Senate. On Wednesday, Reps. Bob Goodlatte (R-VA) and Michael McCaul (R-TX) introduced a separate immigration bill that contains more strict border enforcement measures in return for codifying DACA. It was widely viewed as an effort to muddy the waters of other congressional negotiations by setting a far harder line for what House Republicans should demand in any deal. Trump’s support for the measure complicated matters even further.

“The president’s support of the bill will make this deal dead on arrival in the House,” a senior House GOP aide told The Daily Beast. “Instead of jamming a Democrat-hatched deal down member’s throats, House Leadership should use the committee process and regular order to pass something that reflects the will of the American people.”

But Trump’s support for Goodlatte-McCaul was notably nuanced. In a statement following that legislation’s introduction, the White House only publicly praised four components of the bill rather than its total scope. Those four components are all within the purview of the Senate-dominated DACA deal talks.

“It has to get 60 votes,” Flake said. “We’re the only bipartisan deal in town.”