ERC-8465 Credit-matched liquidity lending position (Credit-Matched Liquidity)

Draft · Vaults & DeFi · created 2026-10-20

A standard where a holder adds borrowed quote tokens to the base tokens they hold to open a concentrated liquidity position, and repays the loan first from that pool's fees. The position token (NFT) is held in escrow by the contract until repayment.

Why it is needed

Even someone holding an asset with a stable price, like a tokenized stock, cannot earn pool fees in a liquidity pool if no one supplies the opposite (quote) token. Several services already offer this kind of lending, each with its own different contracts and events, so a wallet that wants to display a holder's position, a lender that wants to serve multiple holders, or anyone trying to reconstruct a credit record has to integrate with each one separately. On top of that, the same three failures keep recurring. If a position is valued at the pool's own price, it can be drained by a single-transaction price manipulation (flash loan); if a tokenized stock's transfer registry blocks a particular address, a position stuck at that address becomes a loss for both sides; and because the price stops while the stock market is closed and jumps sharply on reopening, even a price from a few hours ago may in fact be a value that cannot actually be traded at.

What to implement

In depth

Price comes only from the external feed; the pool's own price is never used

When calculating the amounts that quoteLimit, health, and unwind pay out, the contract never uses the pool's own price, such as the pool's current tick, square-root price, or reserves. Instead it uses only the answer from the price feed (IPriceFeed) designated for each pool. For a price to be usable, answer must be greater than 0 and updatedAt must be no later than the block timestamp and no older than maxPriceAge; if the base token has a status source, it must be in Trading status and updatedAt must be after that status's since. Additionally, the feed's decimals() must be 18 or less, and the price must be greater than 0 and not exceed the maximum allowed price set by the contract. The pool price is used only to determine the ratio in which the two tokens are deposited at mint time and the ratio in which they are withdrawn at unwind time.

The formula for calculating position value

At usable price P, position value is computed as quote + base * P / 10**18 (rounded down). Here base is the amount of base that liquidity holds at P plus the base share already accrued to the position token, and quote is summed the same way. Base is summed first and priced only once, and fees that the position manager has not yet credited to the position token are excluded from the value. P itself is answer * 10**(18+quoteDecimals) / 10**(feedDecimals+baseDecimals), representing the value per 10**18 base units of the quote token, rounded down.

Opening: Collateral Limits and Price Gap Buffer

quoteLimit(pool, baseIn) returns the smaller of baseIn valued at the usable price and the quote the lender can currently lend, and returns 0 if the pool is unsupported or the price is unavailable (it does not revert). open() reverts if both baseIn and quoteToBorrow are 0, if quoteToBorrow exceeds quoteLimit, or if agentId is set but the caller is not the owner of that identity. It takes in the base, adds liquidity to the specified tickLower to tickUpper, and returns any remaining base. Notably, a new position will not open if it is already liquidatable at the usable price lowered by gapBps. This buffer accounts for cases where a session-based asset's next opening price gaps significantly below the prior session's closing price. Whatever value the lender sets for handoverDelay is enforced to be at least 14 days (1,209,600 seconds).

Escrow and Fixed Terms

While a position is in the Open state, the contract holds the position token and does not withdraw liquidity, collect fees, or transfer tokens except as specified by applyFees, close, and unwind. priceFeed, statusSource, maxPriceAge, unwindBps, gapBps, dueAt, and handoverDelay never change after opening, and owed never increases after opening. In other words, the lender can only liquidate or take over the position under the terms that held when it was healthy, and cannot later change those terms to its own advantage.

Health and Liquidatability Determination

For an Open position, health() reverts if the price is unavailable, and otherwise returns valueInQuote, owed, and unwindable. unwindable is true if owed is nonzero and either dueAt is set and the block timestamp is at or past it, or valueInQuote * 10000 < owed * unwindBps. This comparison multiplies out both sides without division, producing an exact boundary with no rounding error. A position with owed equal to 0 is never subject to liquidation even past maturity, and can only be ended by the holder's close().

Fee Handling: Quote Goes to the Lender First, Base Stays in the Position

applyFees() can be called by anyone and only operates on an Open position. It collects the position's quote fees, repays the lender with the smaller of that fee amount and owed, reduces owed by that amount, and pays any remaining quote to the holder. Base token fees are not paid out to anyone and remain inside the position, to be received by the holder along with the position token at close() or included in the final settlement at unwind(). applyFees() never reads the price.

Closing and Unwinding

close() can only be called by the holder and only succeeds if owed is received in full in quote; it never reads the price and returns the position token as is without moving any base token. unwind() can be called by anyone and only operates on an Open position with nonzero owed. If the price is available and health reports unwindable, it withdraws all liquidity and pays the lender quote first; if that falls short, it pays the shortfall directly to the lenderFallback() address in base, converted at price P and rounded up (with the position manager directing payment straight to that address), and leaves the remaining share in the position token, which passes to the holder. If the base token refuses the transfer, this does not fail; in that case the position token itself (along with the remaining base) is sent to lenderFallback().

When the Price Feed Breaks, Hand-over Transfers Without a Price

If the price remains unavailable past maturity, a hand-over is triggered when TERMINAL_GRACE (1 day) has passed since the status source reported Terminal, or when dueAt + handoverDelay has passed and the feed has given no price for that entire handoverDelay, or when Halted has lasted longer than handoverDelay. In this case, unwind() collects only quote, pays the lender up to owed, and if that quote covers owed in full, passes the position token to the holder; otherwise the whole position token goes to lenderFallback(). No base token is moved. An intra-session market closure (SessionBreak), no matter how long, never qualifies for hand-over, and no lender can set handoverDelay shorter than 14 days. This proposal is currently in Draft status, not yet finalized, and may change or be abandoned.

Things to watch out for

Original ERC · ← ERCs