Developers

Three contracts. One keeper. This app.

Everything Par does is onchain and permissionless: anyone can trigger a missed payment, execute an undisputed claim or force-settle a defaulter.

Run the second command from the repository root. It installs dependencies, runs a local chain with a model of MUSD, deploys Par, seeds both demos, and starts the keeper and this app.

MEZO · 31611
1import { parseEther } from "viem"
2import { parVaultAbi } from "./abi"
3
4// Rent: 12 × 500 MUSD, cover 1,500, 3-day grace
5// start, expiry: unix seconds (bigint); MONTH, DAY: seconds
6const hash = await walletClient.writeContract({
7 address: vault,
8 abi: parVaultAbi,
9 functionName: "createScheduled",
10 args: [landlord, tenant, parseEther("500"), start,
11 MONTH, 3 * DAY, 12, parseEther("1500"), expiry],
12})
13// reverts with Unhealthy() unless it survives BTC −40%
14
15const [ok, stressedIcr, headroom] = await publicClient.readContract({
16 address: vault,
17 abi: parVaultAbi,
18 functionName: "health",
19 args: [0n],
20})
ASSERTED IN contracts/test/Par.test.tstest numbers
✓ rent guarantee: missed installment is paid from buffer,
  then minted from the trove
    Payout(id 0, landlord, 1500, fromBuffer 500, minted 1000)
    trigger again → AlreadySettled · too early → TooEarly
✓ rejects a commitment that would not survive the stress test
    1 BTC at $50k, cap 20,000 → Unhealthy()
01

Quickstart

Every command below runs from the repository root.

  1. 1
    Run the tests

    Against a model of the MUSD rules Par relies on.

  2. 2
    Run them against real MUSD

    Clones mezo-org/musd and runs the core suite (test/Par.test.ts) on its fixtures.

  3. 3
    Deploy to Mezo testnet

    Needs a key holding testnet BTC for gas. Prints the frontend env.

  4. 4
    Start the keeper

    Watches every vault and circle, simulates first, alerts on Recovery Mode.

02

Contracts

ContractWhat it doesTestnet
ParFactoryDeploys one ParVault clone (EIP-1167) per user and stores risk parameters: stressBps 4000, targetIcr 160%.0x2907…E4f0
ParVaultOwns the MUSD trove. Holds commitments (Scheduled, Claim, ClearingLine), runs the health check and the payout waterfall.one clone per user
ParCircuitCircles with invite-and-join membership (only factory vaults can join), invoices, O(1) netting, settle, forceSettle and claim.0x1980…9CB1

Par integrates with the official MUSD deployment (@mezo-org/musd-contracts 1.1.0):

MUSD contractAddress
BorrowerOperations0xCdF7…beE5
TroveManager0xE47c…6bb0
PriceFeed0x86bC…9366
MUSD token0x1189…c503
03

Functions

ParVault · owner
  • openTrove(seed, up, lo) payable
  • createScheduled(…) · start ≥ now, expiry ≥ last due + grace + 300 s
  • createClaim(…) · arbiter ≠ owner, beneficiary, principal · window ≥ 60 s
  • createClearingLine(circuit, cap, expiry)
  • withdrawCollateral / borrow / repay
  • refinance(up, lo)
  • withdrawMUSDBuffer / withdrawIdleBTC
  • claimCollateral()
  • closeTrove()
  • transferOwnership(to) → acceptOwnership()
ParVault · anyone
  • topUp(up, lo) payable
  • payInstallment(id, index)
  • triggerMissed(id, index, up, lo)
  • executeClaim(id, up, lo) · undisputed after window, disputed after 7 days
  • closeCommitment(id) · after expiry (beneficiary: any time); not while a claim is open or an expired line is owed (LineOwed)
  • health(extra) → ok, stressedIcr, headroom
  • recoveryTopUp(draw, price) → btc
ParVault · claim parties
  • fileClaim(id, amount, evidence) · beneficiary
  • disputeClaim(id) · principal or owner
  • resolveClaim(id, approve, up, lo) · arbiter, within 7 days
ParCircuit · members
  • createCircle(cycleLength, settleWindow)
  • addMember(circle, member, vault, lineId) · admin invites
  • join(circle, vault, lineId) · member accepts
  • removeMember(circle, member) · admin or member
  • setSuspended(circle, member, bool) · admin only
  • createInvoice(circle, debtor, amount, ref) · not if suspended
  • acceptInvoice(id) · not if suspended / rejectInvoice(id)
  • settle(circle, cycle)
  • claim(circle, cycle)
ParCircuit · anyone
  • forceSettle(circle, cycle, debtor, up, lo) · draws the line, even after its expiry
  • suspended(circle, member)
  • net / gross / totalOwed / collected
  • nettingEfficiencyBps(circle, cycle)
  • creditLimit / lineHeadroom(circle, member)
  • currentCycle / cycleClose / finalAt
04

Events

ParFactory : VaultCreated(owner, vault)  VaultOwnerChanged(vault, from, to)
ParVault   : TroveOpened(coll, seed)  CommitmentCreated(id, kind, beneficiary, cap, expiry)
             InstallmentPaid(id, index, payer, amount)  InstallmentMissed(id, index, amount)
             ClaimFiled(id, amount, evidence)  ClaimDisputed(id)  ClaimResolved(id, approved)
             Payout(id, to, amount, fromBuffer, minted)  CommitmentClosed(id, released)
             OwnershipTransferStarted(from, to)  OwnershipTransferred(from, to)  CollateralClaimed(amount)
ParCircuit : CircleCreated  MemberInvited  MemberJoined  MemberRemoved  MemberSuspended(circle, member, suspended)
             InvoiceCreated  InvoiceAccepted  InvoiceRejected
             Settled(circle, cycle, debtor, amount, forced)  Claimed(circle, cycle, creditor, amount)
             CycleFinalized(circle, cycle, collected, totalOwed)
05

Keeper

JobConditionCall
Missed installmentsScheduled, index unsettled, now > due + gracevault.triggerMissed
ClaimsOpen: undisputed and now > filedAt + window, or disputed and the 7-day arbiter deadline passedvault.executeClaim
Circuitnow ≥ close + settleWindow, net < 0, unsettledcircuit.forceSettle
Health watchhealth(0).ok == falsealert the owner
Recovery Moderevert RecoveryModeNeedsReserve(b)alert with b, retry

Every call is simulated first, so a job that isn't due costs nothing. Hints come from HintHelpers and SortedTroves, with zero hints as a fallback.