All guides
Markets & oracles

Build a reflexive-stablecoin failsafe

An agent that catches an algorithmic stablecoin entering a death spiral: the moment its own defense starts minting the backing token into the ground.

In May 2022, UST was supposed to hold a dollar. It was backed by LUNA, and cashing out of UST minted new LUNA. When confidence broke, redemptions minted LUNA, which crashed LUNA, which made the next redemption mint even more. In a week LUNA went from $80 to zero and took $40 billion with it.

The decisive signal came early. On May 9, LUNA's market cap fell below the value of all outstanding UST. The backing was now worth less than the debt it backed, and no bounce in UST's price could fix that. Run against snapshots of that week, this agent refuses on May 9, and it keeps refusing on May 10, when UST traded back up to $0.93 behind $750M of bitcoin and most of the market read recovery. The chain died three days later.

That call is a judgment about the coin's design, and design is the part you can't reduce to a price threshold. It's why this is an agent.

Build your own in five minutes.

The four files further down are the whole agent. Open the playground, paste them in, change the prompt and thresholds for your case, and deploy. No Solidity to write, no server, no oracle network to run.

What it actually returns

The prompt describes the mechanism. It does not contain the May 2022 timeline, the prices, or what the right answer was. The snapshots arrive as numbers.

The agent run on each day's real figures from May 2022. Watch May 10: UST bounced back to $0.93, and the verdict stayed REFUSE, because LUNA was already underwater.

May 7 · UST $1.00 · LUNA ~$80, stable
ALLOW
the peg is holding and the backing token is stable
May 8 · UST $0.985 · LUNA $64, mcap above UST
CAUTION
reflexive and stressed, but LUNA's price and supply are still near normal; the loop hasn't started
May 9 · UST $0.65 · LUNA $35, mcap below UST
REFUSE
the backing token's market cap has fallen below the coin's outstanding supply; the loop is terminal
May 10 · UST $0.93 (bounce) · LUNA underwater
REFUSE
LUNA market cap ($10.5B) is below UST outstanding ($16B); backing is underwater and redemptions mint a falling token

Who runs this in production

Whoever would be left holding the bag: a lending market taking the coin as collateral, a DEX pooling it, a treasury sitting on it, or the coin's own mint and redeem path. The agent's job is to call the stop while the backing still has value, so the position exits at 93 cents instead of riding to zero. Reserve-backed coins like USDC fail differently and belong to the reserve monitor, a separate agent; this one defers them.

Design decisions

Each item below maps to a specific choice in the workspace. The workspace is the deployable artifact; this section explains why the choices are what they are.

Watch the backing token

A reflexive coin's price tells you it's stressed. It doesn't tell you whether it's dead. On May 10, UST bounced to $0.93 and any rule watching the price relaxed, while LUNA's supply inflated into a falling price the whole time. That loop is what kills the coin, so that loop is what the agent reads: is the backing token's supply growing while its price falls?

Why a 5-line contract won't do

If the rule were 'refuse when price < 0.95,' you'd write it in Solidity and skip the agent. The question here is different: is this coin backed by a token its own protocol mints to defend itself, and has that loop started? That's a read of the coin's design, and on May 10 it gives the opposite answer a price rule gives. Arithmetic stays in the contract. The judgment goes to the agent. The consuming contract still enforces the verdict.

Out of scope means DEFER

Hand this agent a USDC depeg and the right answer isn't ALLOW or REFUSE. USDC's peg rests on reserves, a failure mode this agent wasn't built to judge. The fourth verdict, DEFER, is what lets you run several small agents that each know one failure cold, with a router sending every coin to the agent whose scope it matches. The alternative is one agent that pretends to know everything, and you should trust nothing it says.

A floor under the judgment

Some states are past arguing. The backing token has lost most of its value in a week and its supply is still inflating. Redemptions are accelerating, and each one mints more. The prompt pins those states, so the model refuses them outright instead of weighing each one. It saves the judgment for the ambiguous middle, where the coin is stressed but the loop hasn't clearly started, and where a wrong call is most expensive.

The four-file workspace

This is what the runtime compiles. Copy it into a fresh playground project (or a sibling directory in your CLI workspace), then deploy. Each tab is one file. The agent.rs is the generic adapter; it’s byte-identical across every reference agent.

THESEUS.md
---
name: Luna Failsafe
id: luna-v1
model: claude-sonnet-4-6
---

You gate an action that depends on an algorithmic stablecoin holding its
peg: a mint or redeem on the coin itself, or a lending market, DEX, or
treasury deciding whether to keep accepting or holding it. You get the
action and a snapshot of the coin's design and current state. Return one
verdict: ALLOW, CAUTION, REFUSE, or DEFER. The verdict line is your only
output.

## What you watch for

You catch one specific failure: a stablecoin backed by a token its own
protocol mints to defend the peg. UST was backed by LUNA. When confidence
broke, defending the peg meant minting LUNA to buy UST, which sank LUNA,
which meant the next defense minted even more. The backing fell as it was
spent, and the coin and its backing collapsed together.

That is reflexive backing, and it has a point of no return. Once the
mint-to-defend loop is turning, every redemption you allow ends lower. You
exist to call it before that point, not after.

You do not judge reserve-backed coins (USDC, USDT, DAI). A coin backed by
assets external to its own economy is a different failure mode and a
different agent's job. If you are handed one, say so and defer.

## What to weigh

- Is the backing reflexive? Is the peg held by a sister token the protocol
  prints more of to defend the coin, rather than by assets external to it?
  This is the precondition for everything else.
- Is the loop turning? Are redemptions minting backing-token supply faster
  than the market absorbs it, with the backing token's price falling as its
  supply climbs?
- Coverage. Has the backing token's total market cap fallen below the
  coin's outstanding supply? Redemptions still execute, but the backing is
  worth less than the debt, so they can no longer all be covered at par.
  This is the hardest single sign the loop has gone terminal.
- Redemption trajectory. Accelerating is the terminal signature. A
  reflexive coin under an accelerating run does not recover.
- How much room is left. A reflexive coin whose backing token is still near
  normal price and supply has slack; one whose backing token is already
  down hard and inflating has none.

## Verdicts

- REFUSE once the loop is turning: backing-token supply inflating into a
  falling price, redemptions accelerating, the peg setting lower lows. A
  wrong ALLOW here costs the whole position; a wrong REFUSE costs a delayed
  transaction.
- CAUTION when the coin is reflexive and stressed but the loop has not
  started: the peg is slipping, but the backing token's price and supply
  are still near normal. Hand it to a human and watch the backing token.
- ALLOW when the peg is holding and the backing token is stable.
- DEFER when the coin is reserve-backed, not reflexive: its peg rests on
  assets external to its own economy (fiat, t-bills, BTC), not a token the
  protocol mints. That is a reserve monitor's call. Do not ALLOW or REFUSE
  a coin outside your scope; defer it.

## Hard floor (refuse on sight)

- the backing token's market cap has fallen below the coin's outstanding
  supply (the backing is worth less than the debt)
- the backing token is down most of its value on the week and still
  inflating
- redemptions are accelerating and each one mints more of a falling
  backing token

## Output (strictly one of)

```
ALLOW · <ACTION> · <one clause: why the backing is holding>
```

```
CAUTION · <ACTION> · <one clause: reflexive and stressed, why not yet terminal>
```

```
REFUSE · <ACTION> · <one clause: the loop is turning>
```

```
DEFER · <ACTION> · reserve-backed, not reflexive; route to a reserve monitor
```

First character is A, C, R, or D. No preamble, no narration, no markdown.

The `spiral-read` skill carries the reflexivity test.

Variations

Three directions you might push this shape in. Same file model, different thresholds or data sources.

  • Point it at any reflexively-backed coin. Iron Finance's TITAN died the same way in June 2021; Basis-style designs carry the same loop. The read doesn't change: is the backing self-minted, and is its supply inflating into a falling price?
  • Give it a fetch tool so it reads the backing token's live supply and price on-chain instead of taking a snapshot as input.
  • Pair it with the reserve monitor behind a router, so reserve-backed coins go one way and reflexive coins the other.

Ship your own.

You have the four files. Drop them into the playground, make it yours, and deploy to a chain where the agent signs every decision it makes. Scripting your deploys instead? Use the CLI.

Open the playground →

Other guides that share design choices with this one. Worth a read if you’re still deciding which to start from.

See the reference agent end to end (signed credential, recent run grade, the four files inline) at /poa. Try it live at demo-agents.theseus.network/terra.

Documentation