Doji docs
Developers

Architecture

How the pieces connect, a loan's life and where the money goes, in three diagrams.

Doji lends MUSD against veBTC on Mezo at a fixed rate until a fixed Thursday. Two immutable contracts hold everything: CreditMarkets (lender offers and one market per Thursday, with ERC-1155 credit units) and LoanManager (custody of veBTC positions, loans, auctions and settlement). A keeper script on GitHub Actions calls the same public functions anyone can call. The website reads the chain directly; there is no backend and no database.

1. How the pieces connect

Drawing the diagram

2. A loan's life

Drawing the diagram

Every ending reduces its Thursday market's open-loan count by exactly one. When the Thursday has passed and that count is zero, anyone can call finalize and the market's lenders can redeem.

3. Where the money goes

Drawing the diagram

Each Thursday is its own market, so a loss on one date never touches another. Inside a date, every unit (lenders' and the protocol's) shares collections pro rata.

What the website reads and writes

The app talks to the chain through wagmi and viem, reads addresses from a book keyed by chain id (generated from the deployment record) and simulates every write before the wallet sees it. Every sent transaction is confirmed from the RPC and Mezo's explorer together.

ScreenReadsWrites
LandingveBTC supply and PriceFeed fetchPrice on Mezo mainnet; open offers (nextOfferId, offerOf), marketOf per Thursday, risk settings, open auctions, explorer verificationnone
Borrowoffers, quoteFill, fetchPrice, risk settings, the wallet's veBTC (balanceOf, ownerToNFTokenIdList, escrowType, grantManager, lockOf) and positions Doji holds for itBTC approve, lockAndBorrow; or veBTC approve, deposit, borrow
Lendoffers, quoteFill, the wallet's offers (OfferPosted logs), units per Thursday (balanceOf, pendingUnits, claimOf, marketOf)MUSD approve, postOffer, cancelOffer, claimUnits, safeTransferFrom, withdrawCollected, finalize, redeem
My loanspositions from Deposited logs with positionOf, loanOf, owedOf, collateralValue, lockOf, isUnsafe, isOverdue, veBTC voted, fee distributor claimable, claimableMusd, claimableBtcMUSD approve, repay, roll, withdrawCollateral, claim
Loan pagethe same for any id, plus auctionOf and auctionPricepurchase, startAuction, cancelAuction, prepareSettle, settle
Try to break itlive targetsnone: twelve simulated calls that the contracts refuse

The source of these diagrams is ARCHITECTURE.md.