The extreme laboratory of San Juan, Puerto Rico, opens a window on the future of American municipal finance, reflecting the island’s rundown economy; population flight under growing debt; vulture investors scrapping for roadkill; and the decline of local democracy.

As large hedge fund and mutual fund managers pick over the remains, 3.5 million Puerto Ricans—U.S. citizens—are getting poorer each day, and losing control over their destiny. On Wednesday, an independent oversight board for Puerto Rico ordered the new governor to find $4.5 billion in revenue or savings in addition to his proposed austerity program.

But let’s go to the beginning of this latest chapter in a longer story; one potentially with implications for fiscally strapped states and underfunded pensions in such places as Illinois, Connecticut and Kentucky, and possibly a city, county, or revenue authority near you.

A decade ago, Goldman, Sachs & Co. GS, -2.91% showed up with an ingenious idea for Puerto Rico’s now-insolvent Government Development Bank—essentially, the local central bank—to borrow its way out of a small amount of trouble, and pay off $6.8 billion in older, unfunded debt.

Goldman did so with a stroke of financial engineering that diverted a share of the island’s sales tax proceeds to pay for the new debt it was issuing. Think of the water main to your house with a siphon on it. Your shower and kitchen tap still get plenty of water, and you hardly notice some water is now diverted by the bank that’s taken a lien on your fixtures.

Goldman structured the bonds to sell at a deep discount, and postponed interest payments until redemption—more than 50 years in the future—according to California State University finance academics Brandy Hadley and Jim Estes.

Puerto Rico didn’t have to show this debt as a liability, or an expense “since there are no current interest payments,” Hadley and Estes wrote in the International Journal on Governmental Financial Management, yet Goldman capital appreciation bonds were actually “a very expensive financing mechanism” and could “serve to hide the future liability.”

The Government Development Bank also lobbied the Puerto Rican legislature to borrow $2 billion on behalf of the territory’s biggest underfunded pension plan, the Employees Retirement System of the Government of the Commonwealth of Puerto Rico, and prop up about 100,000 pensioners. The retirement system had only 19 cents to pay every $1 of obligations at the time, though investors and others have asked ever since why the fund’s lead underwriter, a unit of Swiss bank UBS AG UBS, -0.64% , thought that borrowing billions more was a solution.

Today, the government pension has less than a penny for each dollar of obligations.

The legislature declined to issue those bonds. And that was the right answer. But the pension and its adviser, UBS, went ahead anyway, borrowing directly at the height of the financial markets crisis—as UBS itself was exiting from the municipals underwriting business. They did so by pledging to pay for the old obligations with future employer contributions.

So now, if we think of that water main to Puerto Rico as a revenue stream, there’s a siphon tapping the sales taxes, and a leak in employer pension payments, as well. And that’s in addition to a heap of general obligation bonds (the mortgage on the house). Some of the hedge funds and mutual funds who bought this debt are now pressing competing claims for payment.

UBS wasn’t really all the way out, by the way. Having collected several millions of dollars in discounts and fees for issuing the pension debt, a local unit of the Swiss bank in Puerto Rico now pocketed millions more by retailing these bonds solely to Puerto Ricans.

Yes, UBS was not only the debt underwriter, it was also the retail broker, through a series of closed-end funds that it formed, and also the only meaningful market maker.

UBS closed-end bond funds invested more than 40% of their investors’ assets in pension debt and in a subsequent series of sales tax bonds UBS underwrote—according to an analysis by Craig McCann, founder of the Securities Litigation and Consulting Group in Fairfax, Va., and a former senior financial economist at the Securities and Exchange Commission. The result: hundreds of millions of dollars more in losses.

This begins to look something like what is known as a pyramid scheme, with recent investors paying earlier claims in an ever-expanding black hole. But let’s not say that, because federal regulators—some of them likely now looking for defense work—didn’t bring that case.

To complete the circle, the pension plan was also buying some of the sales tax bonds issued to pay off other commonwealth debt: $163 million worth, which supposedly had risen in value to $230 million, as of the territory’s most recent annual financial statement. But Hadley and Estes estimate those bonds are really worth only about $16,731 at market prices.

US President Barack Obama waits to sign the Freedom of Information Improvement Act of 2016 and the Puerto Rico Oversight, Management, and Economic Stability Act, into law in the Oval Office of the White House. Getty Images

Last year, Congress established a seven-member Financial Oversight and Management Board for Puerto Rico with sweeping authority to restructure the territory’s debt—now totaling more than $70 billion—and with the power to overrule the elected governor, as necessary.

One of the board’s first duties is to set a deadline for when the governor must produce “an approvable and certifiable fiscal plan”—that’s Jan. 31, unless extended for 45 days, as likely—and the board can come up with its own plan if the governor is unable to.

In late December, the board issued a series of stark pronouncements to set the conditions for the negotiations and restructuring to come. “Puerto Rico has a massive fiscal deficit, a declining economy and no access to capital markets,” board chairman Jose Carrion wrote to the incoming governor, Ricardo Rossello Nevares. Carrion said the territory can “no longer afford to provide non-essential services,” that education and healthcare spending must be “reduced substantially,” and that the privatization of a number of government assets—including real estate, the state insurance fund and ports—all are on the table.

On Wednesday, Carrion and the oversight board added “pension reform” to its list.

Amid the disrepair—which includes double-digit unemployment, even after a 10% decline in population over the last decade, making the debt burden all the more unsustainable — UBS has settled about $374 million in retail complaints, and related actions by the Securities and Exchange Commission and the Financial Industry Regulatory Authority.

Meanwhile, the board itself is now looking for a financial adviser. And the new governor reportedly is trying to hire Donald Trump’s former campaign manager, Corey Lewandowski, to give the commonwealth some heft in Washington with the incoming Trump administration.

How does democracy become a casualty of municipal debt?

“The first step is to create an independent financial control board” with authority to enter into binding debt agreements, approve or disapprove annual budgets, and even receive and disburse government receipts, New York University Law School professor Clayton Gillette and University of Pennsylvania Law School professor David Skeel Jr. wrote in a paper last year.

That Gillette and Skeel—who is now a member of the Puerto Rican oversight board, appointed by President Barack Obama—were proposing a solution to the island territory’s fiscal crisis doesn’t mitigate the coercive costs of debt and an oversight board to local democracy.

If you recognize any of these conditions in a state or city near you—high public debt, witless officials, and plans to borrow their way out of trouble—I advise extreme caution.