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.
1import { parseEther } from "viem"2import { parVaultAbi } from "./abi"34// Rent: 12 × 500 MUSD, cover 1,500, 3-day grace5// start, expiry: unix seconds (bigint); MONTH, DAY: seconds6const 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%1415const [ok, stressedIcr, headroom] = await publicClient.readContract({16 address: vault,17 abi: parVaultAbi,18 functionName: "health",19 args: [0n],20})
✓ 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()Quickstart
Every command below runs from the repository root.
- 1Run the tests
Against a model of the MUSD rules Par relies on.
- 2Run them against real MUSD
Clones mezo-org/musd and runs the core suite (test/Par.test.ts) on its fixtures.
- 3Deploy to Mezo testnet
Needs a key holding testnet BTC for gas. Prints the frontend env.
- 4Start the keeper
Watches every vault and circle, simulates first, alerts on Recovery Mode.
Contracts
| Contract | What it does | Testnet |
|---|---|---|
ParFactory | Deploys one ParVault clone (EIP-1167) per user and stores risk parameters: stressBps 4000, targetIcr 160%. | 0x2907…E4f0 |
ParVault | Owns the MUSD trove. Holds commitments (Scheduled, Claim, ClearingLine), runs the health check and the payout waterfall. | one clone per user |
ParCircuit | Circles 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 contract | Address |
|---|---|
| BorrowerOperations | 0xCdF7…beE5 |
| TroveManager | 0xE47c…6bb0 |
| PriceFeed | 0x86bC…9366 |
| MUSD token | 0x1189…c503 |
Functions
- 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()
- 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
- fileClaim(id, amount, evidence) · beneficiary
- disputeClaim(id) · principal or owner
- resolveClaim(id, approve, up, lo) · arbiter, within 7 days
- 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)
- 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
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)Keeper
| Job | Condition | Call |
|---|---|---|
| Missed installments | Scheduled, index unsettled, now > due + grace | vault.triggerMissed |
| Claims | Open: undisputed and now > filedAt + window, or disputed and the 7-day arbiter deadline passed | vault.executeClaim |
| Circuit | now ≥ close + settleWindow, net < 0, unsettled | circuit.forceSettle |
| Health watch | health(0).ok == false | alert the owner |
| Recovery Mode | revert 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.