Skip to content

Lend against legs

fact LegWrap, LegOracle and LegWrapFactory are deployed on Robinhood Chain testnet (deployment 11). The mechanics are described in full under Protocol: Credit; this page is the integrator’s view.

COUPON legs are ERC-1155 units. Lending markets take ERC-20 collateral with an oracle. LegWrap gives each struck series an ERC-20 share token that holds the COUPON units and the coupons they earn, and LegOracle prices one share in USDG. The factory opens a Morpho Blue market per series with USDG as the loan token.

ContractYour call
LegWrapFactorycreate(seriesId) if no market exists; wrapOf, oracleOf, marketOf, marketParams(seriesId) to read one
LegWrapwrap(units, to), unwrap(shares, to), harvest(), exit(shares, to), previewWrap, previewUnwrap, pool
LegOracleprice() in the convention Morpho expects

Nothing here has an owner, a pause or a parameter.

legs.setApprovalForAll(address(wrap), true);
// USDG owed so the new shares carry the same pool share as existing ones
uint256 buyIn = wrap.previewWrap(units);
usdg.approve(address(wrap), buyIn);
// pulls the units and the buy-in, mints `units` shares to `to`
wrap.wrap(units, to);

Share supply always equals the units held. The buy-in is zero while the pool is empty, which is the case for a freshly struck series.

Post the shares to the series market through Morpho’s own interface with marketParams(seriesId). Coupons keep accruing to the wrapper while the shares are collateral; harvest() (permissionless) pulls them into the pool and the oracle counts them, so the collateral value rises with every paid observation.

// collects accrued coupons, burns the shares, releases the units and pays the pool share
wrap.unwrap(shares, to);

exit(shares, to) releases the units without a pool payout, the fallback when a coupon claim cannot go through. At autocall or maturity the released units are redeemed on NoteCore by whoever holds them.

NumberSource
Collateral valueoracle.price() × shares
Coupons in the poolwrap.pool(), wrap.poolPerShareWad()
Barrier distancecore.getSeries(seriesId) and the series feed
Market stateMorpho market(id) for supply, borrow and utilisation

A breach changes the collateral from a par claim to stock delivered at s0. Market parameters (loan-to-value, rate model) are chosen with that in mind; read them from marketParams rather than assuming.