Middn Protocol Architecture.
A technical view of how Middn can protect peer-to-peer settlement. Vault-backed escrow, contract-gated instructions, and 2/3 Safe fallback explained layer by layer.
Three layers, one boundary.
App orchestrates UX. Backend indexes & relays. Contracts hold the truth and the funds. The Safe arbitrates when humans must decide.
Available ≠ reserved.
A seller's vault holds two distinct balances. Available liquidity backs new offers and can be withdrawn at any time. Reserved liquidity is locked against an open trade and cannot be moved by the seller until the trade resolves.
When a buyer opens a deal, reserveLiquidity() moves the trade amount from available to reserved. Only then can the app reveal payment instructions to the buyer.
Fee and gas reserve accounting.
The design separates the trade amount from protocol fees and any relayer reserve, so settlement accounting stays explicit instead of hidden inside the UI.
Seller funds amount + fee + gas
Seller deposits the trade amount, the platform fee, and the gas reserve. Buyer receives the full advertised amount. Cleanest UX for buyers.
Fee deducted from payout
Seller deposits amount + gas reserve only. Middn fee is deducted from the buyer's payout at release. Lower upfront capital requirement.
The architecture can support either mode; the chosen settlement model is encoded per offer instead of being implied by the front-end.
The relayed UX path
Middn can sponsor gas via a relayer wallet so users don't need native ETH/ARB/MATIC for every action. The user (or the trade rules) still authorize the action — the relayer only submits transactions.
The gas reserve refunds the relayer wallet after each settled trade. Unused gas reserve can be refunded to the seller per trade config.
Middn pays gas. Middn does not own funds.Core functions. What lives where.
Filter by category. Each function is tagged on-chain or off-chain — anything that moves funds is always on-chain.
availableBalance[token].availableBalance.reserveLiquidity().availableBalance to reservedBalance. Atomic; reverts if insufficient.RELEASED.availableBalance.DISPUTED. No automatic release until resolved.RELEASE or REFUND. Single keypair cannot execute.7d timelock so users can exit before change applies.Every trade walks the same path.
Twelve canonical states. Every transition is gated by either a user-signed action, a contract condition, or a Safe-approved decision.
availableBalance after timeout or cancel.Four outcomes, four paths.
Every escrow ends in one of four ways. Click through to see exactly which contract calls run, and in what order.
openDeal()reserveLiquidity() runs internallyDisputes reviewed off-chain. Settled on-chain.
Smart contracts cannot verify bank transfers, screenshots or RWA conditions. So Middn separates the two layers: human review off-chain, Safe-executed settlement on-chain.
openDispute(). Funds freeze.resolveDisputeBySafe().Who can do what.
Permissions are scoped narrowly. Anyone who can move funds is a Safe, not a single key. Anyone who can decide an outcome is many people, not one.
If the API fails.
The app is the premium UX but never the only path. If Middn's API goes down — temporarily or permanently — users can still recover their funds directly from the contracts.
EscrowEngine.
refundExpired(dealId) after timeout.
claim(dealId) always pulls funds owed to the caller.
Architecture, in one breath.
Middn is a settlement primitive. The app is UX. The backend is plumbing. The contracts are the source of truth. The Safe is the only entity that can override defaults. Funds never leave user custody without an on-chain rule allowing it.