Cover photo

Tare: Building an Overcollateralized Stablecoin That Refuses to Mint Against a Bad Price

An engineering walkthrough of a multi-collateral, Curve-ready stablecoin written in Vyper 0.4 — the registry, the redundant oracle, the risk-weighted health factor, and the bad-debt machinery that makes insolvency an accounting event instead of a crisis.

Most overcollateralized stablecoin failures are not failures of collateralization. They are failures of measurement. A CDP system is only as honest as the price it marks positions against, and only as solvent as its willingness to stop minting the moment that price becomes untrustworthy. The hard parts of a stablecoin engine are not deposit and mint — they are the three boundaries: what happens when an oracle lies, what happens when a position falls underwater faster than it can be liquidated, and what happens when the protocol owner is tempted to reach into a solvent user's vault.

Tare is a USD-pegged, overcollateralized, multi-collateral stablecoin built around those three boundaries. It locks collateral at a minimum 200% ratio, monitors every position with a risk-weighted health factor, lets permissionless liquidators restore solvency for a bonus, and defends its secondary-market peg with a Curve-style PegKeeper. There is no rebasing and no governance token. The owner can list collateral and trip circuit breakers, but holds no custody — no admin path can move a solvent user's collateral or rewrite their debt.

This post is about how that property is actually enforced in code, not just claimed in a README.


Why a registry instead of hard-coded collateral

The naive design hard-codes collateral slots: WETH, WBTC, each with constants baked into storage layout. Listing a new asset becomes a contract migration. Tare treats collateral as an owner-managed registry instead. Each registered asset carries its own bundle of parameters:

  • primary and fallback price feeds

  • an oracle deviation bound (in basis points)

  • a liquidation threshold

  • token decimals

Listing an asset is a single transaction, not a redeployment. The important consequence is risk isolation at the parameter level. A volatile asset can be listed at a lower liquidation threshold without weakening the parameters on safer collateral. The health-factor math reads per-asset thresholds, so the risk weighting is a property of the asset, not of the engine.

HF(user) = ( Σ_t valueₜ · liquidation_thresholdₜ / 100 ) · 1e18 / debt(user)

The summation over t is the per-collateral loop: each asset's USD value is discounted by its own threshold before contributing to the numerator. A position backed by a safe asset and a risky asset is not marked at a blended average — it is marked at the truth of each leg.


The oracle is the protocol

The single most consequential design decision in any CDP engine is what it does when a feed misbehaves. Tare's oracle_lib treats pricing as something that can halt, not just return a number.

Every collateral can carry a primary and a fallback feed. The library applies three guards on every read:

  1. Staleness. A feed older than the staleness window (3 hours) is rejected. A price that hasn't updated is not a price.

  2. Sanity. A zero or negative answer is rejected outright. A lone bad feed does not get to mint TARE.

  3. Cross-feed deviation. When primary and fallback disagree beyond the asset's deviation bound (5% / 500 bps at launch), pricing halts rather than picking a winner.

The design philosophy here is fail-closed. The system would rather refuse to operate than operate on a price it cannot defend. A single dead feed degrades gracefully to the fallback; a divergence between feeds is treated as evidence that at least one source is compromised, and the only safe response is to stop. The failure mode that destroys overcollateralized stablecoins — minting fresh debt against a manipulated mark — is structurally unavailable.


Bad debt as an accounting event, not a bank run

Liquidation works only while a position is profitable to liquidate. Below a certain depth, the collateral seized plus bonus no longer covers the debt repaid, and rational liquidators walk away. Most designs leave this case implicit, and the protocol quietly accumulates unbacked supply.

Tare makes it explicit with three pieces:

  • A donated TARE surplus buffer that absorbs shortfalls.

  • A permissionless settle_bad_debt that winds down a position too deep underwater for a profitable liquidation, drawing on the buffer.

  • A transparent total_bad_debt counter that books any remainder the buffer could not cover, and a retire_bad_debt path that pays it down once the buffer refills.

The point is that insolvency becomes a number on the ledger rather than a silent dilution of every holder. An indexer can read total_bad_debt and know exactly how much unbacked supply exists at any block. The protocol degrades visibly and recoverably instead of failing opaquely.


Circuit breakers that never trap exits

There are two owner-gated controls: pause, which blocks the entry of new risk (deposits, mints), and a one-way emergency_shutdown. The invariant that matters is that exits always stay open. A breaker can stop the protocol from taking on new exposure, but it can never strand a user inside a position. Redeeming collateral and burning debt remain available through every breaker state. This is the line between a safety mechanism and a custody risk.


Defending the peg on the open market

Overcollateralization fixes the floor — TARE is always redeemable against more than a dollar of collateral. It does not by itself fix the secondary-market price. For that, Tare ships a crvUSD-style PegKeeper pointed at a Curve StableSwap pool:

  • When TARE trades above peg (the pool is short on TARE), the keeper mints and provides TARE, taking on keeper debt.

  • When TARE trades below peg (the pool is heavy with TARE), the keeper withdraws and burns, retiring that debt.

The keeper is permissionless to call on a cooldown, so peg defense is a public good anyone can trigger rather than a privileged operation. The engine authorizes the keeper as a minter through an explicit set_peg_keeper wiring — the mint surface is small and named, not ambient.


Why Vyper

Three reasons, all about review surface:

  • Auditability. Python-like syntax, explicit control flow, no inline assembly. A reviewer reads a function top to bottom without decompiling intent.

  • Storage transparency. Every storage slot is declared at module scope. No hidden inheritance, no diamond proxies, no surprise about where state lives.

  • The 0.4 module system. initializes: and exports: make the engine ↔️ token ↔️ oracle wiring explicit. The TARE mint/burn surface is whitelisted at compile time — the set of addresses that can create supply is a property of the bytecode, not of runtime configuration.

For a system whose entire value proposition is "trust the accounting," minimizing the gap between what a reviewer reads and what the EVM executes is the whole game.


Testing the invariants, not just the functions

Unit tests check that functions do what they say. They do not catch the failures that actually sink CDP systems, which are system-wide properties violated by some unexpected interleaving of operations. Tare is gated on a stateful fuzzer that asserts solvency invariants across randomly-permuted sequences of deposit / mint / redeem / liquidate / settle, in addition to the unit and integration suites. Accounting is tracked independently of raw token balances specifically so that donation and inflation attacks — sending tokens directly to the contract to corrupt its bookkeeping — cannot move the invariants, because the invariants never trust balanceOf.

CI gates on a coverage threshold and runs the fuzzer on a fast budget every push, with a deeper search available for local runs.


What "no custody" actually means

The strongest claim Tare makes is that the owner cannot harm a solvent user. This is worth stating precisely, because it is the difference between a stablecoin and a deposit account at a counterparty you have to trust:

  • No admin function can transfer a solvent user's collateral.

  • No admin function can alter a user's debt.

  • The owner cannot mint TARE to itself.

  • withdraw_seized only touches collateral already seized from positions that were liquidated or settled — i.e. collateral that has already left a user's vault through the public, rule-bound path.

The owner's powers are confined to listing assets, tripping breakers, and sweeping collateral the protocol has already lawfully taken. Everything that touches a live user's position is permissionless and rule-bound.


Where it runs

The full stack is deployed and wired end-to-end on Sepolia — token, engine, PegKeeper, and a real Curve StableSwap-NG pool paired against Circle's testnet USDC, with live Chainlink aggregators feeding the oracle. Collateral tokens are freely-mintable mocks on testnet. There is a read-only status dashboard, a pool-seeding script, and a permissionless keeper-update cycle you can drive yourself.


Closing

The mechanism design here is not novel in its primitives — it owes obvious debts to MakerDAO's DAI, Liquity's LUSD, and Curve's crvUSD PegKeepers. What it tries to be is honest about its boundaries: a system that would rather halt than mint against a bad price, that books insolvency as a visible number instead of a silent dilution, and whose owner is structurally unable to touch a solvent position. Those three properties are where stablecoins actually fail, and they are where the engineering attention went.

Code, spec, and the full invariant set are open. Read the engine top to bottom — that was the point of writing it in Vyper.


Built by KhomDev — Vyper & DeFi smart-contract engineering.