A fully-collateralized zero-coupon discount bond issuer. One contract manages
many independent bond series. In a series, an issuer sells bonds at a discount:
a bond costs price today and redeems for a larger fixed faceValue at
maturity. Every series is kept fully backed at all times, so redemption is
unconditionally guaranteed.
reserve(series) >= bondsOutstanding(series) * faceValue (always)
An ordinary bond is a promise: the issuer intends to pay face value at maturity, but a defaulting issuer can leave holders unpaid. This contract removes the promise and replaces it with collateral. A bond can only be sold if the series' reserve already covers its full face value after the sale — the sale is gated on solvency. Because backing can never lag issuance, the reserve can never be short at maturity, and there is no default path to handle. That impossibility is the whole point of the design versus an under-collateralized bond.
Every token unit belonging to a series lives in one number, reserve.
- Buyers pay
count * priceINTO the reserve. Those proceeds count toward backing, so the issuer only has to pre-fund the discount shortfall (faceValue - priceper bond) throughfund(). Full face backing is thus financed jointly by buyer proceeds and issuer top-up. buyrevertsUnderfundedif, after the sale,reservewould be belowbondsOutstanding * faceValue. Solvency is enforced at sale time.redeemremoves exactlycount * faceValuefrom bothreserveandbondsOutstanding, so the backing inequality is preserved by construction.issuerWithdrawSurpluspays out onlyreserve - bondsOutstanding * faceValue— strictly the un-owed buffer (accumulated proceeds plus any over-funding). It can never touch the funds backing live bonds. Once every bond has matured and redeemed,bondsOutstanding == 0, so the entire remainder becomes withdrawable surplus.
This is the cleaner of the two candidate models: with a single reserve number,
per-series conservation is simply reserve == tokensIn - tokensOut, and there is
no separate "proceeds pot" to reconcile.
The issuer can pull reserve − bondsOutstanding·faceValue at any time, and never
one wei more. No sequence of buys, redemptions, transfers, withdrawals, or time
warps lets the issuer reach the funds owed to outstanding bondholders.
No division occurs anywhere — faceValue and price are absolute per-bond token
amounts and count is an integer, so count * price and count * faceValue are
exact. There is no rounding, hence nothing can ever round against the reserve.
createSeries(token, faceValue, price, maturity, maxBonds)— issuer defines a series (requiresfaceValue > price > 0,maturity > now,maxBonds > 0) and becomes its owner. ReturnsseriesId.fund(seriesId, amount)— issuer deposits backing (at least the discount shortfall for the bonds it expects to sell).buy(seriesId, count)— buyer payscount * price, receivescountbonds. Reverts onSaleClosed(at/after maturity),MaxBondsExceeded, orUnderfunded.transferBonds(seriesId, to, count)— bonds are transferable; a pure ledger move that leaves backing untouched. The recipient inherits redemption rights.redeem(seriesId, count)— at/after maturity, holder burnscountbonds and receivescount * faceValue.issuerWithdrawSurplus(seriesId)— issuer withdraws the un-owed surplus.
series(id), bondsOf(id, holder), reserve(id), backingRequired(id),
surplus(id), redeemableAt(id) (maturity timestamp), isMatured(id),
seriesCount().
BondManager tracks reserves by explicit bookkeeping, so a token that delivers
fewer units than requested would desync the reserve from the real balance. Every
inbound pull measures the actual balance delta and reverts
FeeOnTransferUnsupported if it differs from the requested amount — the contract
rejects such tokens loudly rather than mis-accounting silently. Use standard,
non-rebasing, non-fee ERC-20s. (test/mocks/FeeOnTransferERC20.sol exists purely
to assert this rejection.)
- Full-backing solvency —
reserve >= bondsOutstanding * faceValuefor every series, under every buy / redeem / withdraw / transfer / time sequence. - Conservation — per series,
reserve == tokensIn − tokensOut; the sum of series reserves equals the contract's token balance; no cross-series mixing. - Can't redeem before maturity; can't buy past
maxBonds; can't buy when it would underfund; issuer can't withdraw backing owed; double-redeem is impossible (bonds are burned before payout); transfers conserve total bonds. nonReentranton every state-changing external entry point that moves tokens; effects-before-interaction ordering;SafeERC20throughout.
55 tests, all green — 51 unit/fuzz + 4 stateful invariants.
Three invariants (invariant_FullBacking, invariant_Conservation,
invariant_SurplusDecomposition) each run 64 × 200 = 12,800 calls with 0
reverts under fail-on-revert = true (pinned inline), driving two series over a
shared token through a bounded, revert-free handler — proving the suite is
non-hollow.
A second adversarial pass hammered the full-backing solvency model across every
buy / fund / redeem / withdraw-surplus / transfer / time interleaving, including
cross-series interference over a shared token, boundary surplus math, reentrancy
on redeem/buy/withdraw, per-series authorization, and the checked-arithmetic
overflow behaviour of the outstanding * face backing gate.
Finding: no solvency bug. The invariant reserve ≥ outstanding·faceValue is
preserved by construction on every path — the sale gate enforces it at issuance,
redeem removes exactly count·face from both sides, surplus withdrawal floors the
reserve at backing, and transfers touch neither term. Overflow of the backing
product is self-limiting: the buy that would create it reverts under 0.8 checked
math, so an under-backed bond can never be minted.
Hardening added this pass:
- A fourth invariant,
invariant_BackingHoldsUnderArbitraryCalls, driven by an un-clamped handler that fires arbitrary (revert-tolerated) buys/redeems. Unlike a gate-clamped handler, it actually probes the solvency gate: deleting theUnderfundedcheck makes it fail (verified by mutation). - Cross-function reentrancy tests re-entering
buyandissuerWithdrawSurplusmid-payout (both stopped by the shared guard); a non-holder-redeem test; a per-series issuer-authorization test; an overflow self-limit test; and a full-lifecycle interleave fuzz asserting exact face payout and intact backing. - Mutation sanity: disabling the buy solvency gate fails 2 unit tests and the new adversarial invariant; reverted after confirming.
forge test # unit + invariant
forge test --match-contract Invariant
forge build --sizes # BondManager runtime: 3,645 B (well under EIP-170's 24,576)
forge fmt --checkforge script script/Deploy.s.sol:Deploy --rpc-url <RPC> --broadcastBondManager takes no constructor arguments; issuers create series after deployment.