A holder of a token with a reliable price (a tokenized stock, ETH) could earn pool fees on it if someone supplied the other side. This draft lets a lender fund the quote side of a holder’s concentrated-liquidity position, held in an escrow the holder cannot withdraw from: fees repay the lender first, the holder closes by repaying, and anyone may unwind when the oracle price, never the pool’s own, says the position no longer covers the loan. It covers market sessions and weekend gaps for session-traded assets (no price is used while the market is closed, and an opening buffer covers the gap), assets whose transfer registry can block an address (an unwind pays the lender’s fallback address straight from the position manager), and exact accounting by balance changes.
Questions for lenders and AMM builders:
- Is the oracle-plus-market-session model enough for tokenized stocks, or should the draft read an asset-status interface directly?
- Who should bear a dead feed after the due date: the lender, or the holder through a timed hand-over?
- Is
address pool with v3-style positions the right first scope, with v4 through a wrapper?
Nice draft, and good that the reference is upfront about not being audited. Two thoughts on your questions from reading the reference, plus one small thing.
On a dead feed after the due date: I’d go with the timed hand-over. Only the base leg of unwind needs a price; the quote leg doesn’t. So after dueAt plus a grace period, unwind could collect quote up to owed without reading the feed and send the position token to lenderFallback(). The holder had the whole term plus the grace period to close. Without that the holder holds a free option: close if the asset recovers, walk away if it doesn’t, while the lender waits on a feed that may never come back.
On oracle plus session vs reading an asset status interface: a weekend is bounded and gapBps can be sized for it. A halt isn’t, and right now a halt reads the same as a closed market. Halts, delistings and redemptions are exactly when the reopening price gaps the most, and some never reopen. So I’d have the draft read asset status, mainly to tell a terminal state apart from a session close, so terminal states go to the hand-over above instead of waiting.
Small one: once fees bring owed to zero, the position still counts as unwindable at dueAt, so anyone can unwind it. No funds go to the wrong place, but it pulls the holder’s liquidity and the position ends as Unwound instead of Closed. If agentId feeds a credit history, a holder who repaid in full would show an unwind. Skipping the due-date check when owed is zero fixes it.
Thanks, all three land, and they answer the first two questions in the post.
A dead feed after the due date. Agreed: a timed hand-over. After dueAt plus a hand-over delay the lender lists in its terms (so a holder knows it at open), unwind reads no price: it collects quote up to owed and sends the position token to lenderFallback(). The holder had the term and the delay to close, so the free option is gone, and the lender no longer waits on a feed that may not come back. Before that time a dead feed still blocks unwind, as now.
Asset status. Agreed that a halt cannot read as a closed market. The next revision replaces the session source with an asset status that tells three cases apart: a session break (wait for the reopening price, as now), a halt (also no price, but unbounded, so past dueAt plus the delay it goes to the hand-over), and a terminal state such as a delisting or a redemption, which goes to the hand-over at once, due date or not. A base traded continuously keeps no status source.
owed at zero. You’re right, that’s a bug in the reference: _unwindable returns true at dueAt before it looks at owed. In the next revision a position with nothing owed is never unwindable; its holder closes it, paying nothing, and gets the token back as Closed. A test will hold it.
All three go into the next revision of the draft. For the delay: would you put a floor in the text, or leave it to each lender’s listed terms?
Glad they landed. On the delay I’d make the floor a MUST. The reference already reverts below 14 days, but the text only says SHOULD, so a conforming lender could list a few hours and take positions over a normal outage, which is the case your short delay section describes. A MUST keeps the two in line and lets a holder trust the number without checking every pool.
One more on the second revision. Your Security Considerations already cover a status source the lender controls, but even an honest Terminal hands over at once, holder’s part included, before dueAt too. Since close needs no price, a short window after Terminal before the hand-over, say a day from since, would let a holder who is watching repay and keep their part. The lender still isn’t left waiting on a price that won’t come, and a wrong Terminal gives holders a day to react.
@Zealynx Both are in the third revision (GitHub - priors-agents/erc-credit-matched-liquidity: Draft ERC: a lender funds the quote side of a holder's pool position in an escrow, repaid from fees first, unwound on an oracle price. Not audited · GitHub, commit 885d47e).
The floor is a MUST now: a position’s handoverDelay MUST be at least 14 days (1,209,600 seconds), and open MUST NOT record a shorter one, whatever delay the lender lists. That matches the reference, where listPool reverts with BadTerms() below MIN_HANDOVER_DELAY. The Rationale and the short-delay consideration now say why it is a requirement.
For Terminal, a hand-over is due only once TERMINAL_GRACE, one day (86,400 s), has passed since the since the status source reports, due date or not. Inside that day close works as always and unwind reverts as for any unusable price, unless the feed has already been silent for the whole delay past dueAt: that hand-over doesn’t wait for the day. A since ahead of the block opens no window early.
Security Considerations now cover a backdated since: it is the same trust as a false Terminal, and a holder limits it the same way, with a source the lender can’t write and by watching the status and the issuer’s notices.
Four new tests cover the day, a holder closing inside it, the hand-over after it, and the floor; they fail on the second revision’s reference and pass now (65 in all).
1 Like
Nice, the MUST and the day’s grace both read well, and thanks for adding the tests.
One more case, in the hand-over itself. _handOver sends the position token to lenderFallback() even when the quote it collects already covers owed. Then the lender is paid in full, outstanding is zero, and nothing needs a price to split: everything left in the token, the base and any quote above owed, is the holder’s. So a position that sits mostly in quote when the hand-over comes (the base traded up through the range before the feed went silent or the status turned Terminal) pays the lender in full and still gives it the holder’s whole part.
A price-free fix: when recovered == owed, transfer the token to the holder, and send it to lenderFallback() only when there’s a shortfall. The trade-off is that a lender then gains from pushing the pool price down right before calling unwind, so the quote falls short. It can only get what today’s rule already gives it, so the holder is never worse off than now, but it’s worth a line next to the one on moving the pool’s price.
@Zealynx Thanks, that one is right, and the fix is the one you describe (erc-credit-matched-liquidity@b24330a, and the PR, ethereum/ERCs#2109).
_handOver now transfers the position token to the holder when the quote it collected equals owed, and to lenderFallback() only on a shortfall. The priced unwind already did this, since a quote that covers owed leaves no base for the lender to take; the hand-over was the one path that gave the lender the holder’s part with nothing left to cover. The status stays HandedOver and the event PositionHandedOver, with outstanding at zero, so a reader still sees that no price was used, and an outstanding above zero now also means the lender holds the token. The Hand-over section says where the token goes, and that where it goes may not depend on a price.
test_handover_quoteCoversOwed_theHolderKeepsThePositionToken is your case: the pool trades up to 300 before the feed goes silent, the position holds 27,386.13 quote, and at the hand-over the lender takes 25,250 and the holder gets the token with 91.287 base and 2,136.13 quote in it. test_handover_terminal_quoteCoversOwed_unlessThePoolIsPushedDown does the same a day after a terminal status, then pushes the pool back to 250 before a second position’s hand-over: the quote falls about 250 short and the lender gets the token whole. Both fail on 2a60031, where the token went to the fallback address; 67 tests in all.
On the trade-off I agree with your reading, and it is now next to the pool-price line in Security Considerations: at a hand-over the pool’s price decides whether the quote covers owed, so a lender that pushes it down before calling unwind can take the whole position, as any hand-over that falls short does, but only once a hand-over is due, and a holder that wants to be sure of its part closes before then, which needs no price. The Rationale sentence saying that moving the pool before a hand-over gains nobody anything is gone, since it no longer holds.
1 Like
The liquidation condition should specify the exact valuation and rounding rules, not just the oracle source. In particular, define how token decimals, oracle decimals, fee accrual, and the required collateral buffer enter the coverage calculation, and round in the lender’s favor. Otherwise implementations can disagree at the threshold, or a one-unit rounding difference can make an unwind succeed in one implementation and fail in another.
@vupemewa Most of this is in the text already, but not all of it as a requirement, and you’re right that what is left can split two implementations at the line.
What the draft fixes today. Decimals: the feed’s answer is the price of one whole base token in whole quote tokens times 10 ** decimals(), and the contract MUST read the feed’s and both tokens’ decimals rather than assume them (Tokens, pools and prices). The buffer: Health makes a position unwindable exactly when valueInQuote * 10000 < owed * unwindBps, two whole products with no division, and Opening refuses a position that would be unwindable after a fall of gapBps. Fee accrual: owed is fixed at opening, the lender’s charge included, and MUST NOT increase, so nothing accrues into the comparison over time; quote fees reduce it as they are applied. Rounding: the only rule in the Specification is that the lender’s base at an unwind rounds up. “Values round down” sits in Security Considerations, the price’s integer form is not fixed, and fees the position manager has not yet credited MAY be left out of the value. So two conforming contracts can differ by a unit at the line, or by those fees.
What changes. This is in the draft and the reference now (GitHub - priors-agents/erc-credit-matched-liquidity: Draft ERC: a lender funds the quote side of a holder's pool position in an escrow, repaid from fees first, unwound on an oracle price. Not audited · GitHub, commit 2f1d864):
- Definitions give the price of an answer,
answer * 10 ** (18 + quoteDecimals) / 10 ** (feedDecimals + baseDecimals) rounded down, in quote units per 10 ** 18 base units. The value is quote + base * P / 10 ** 18 rounded down, with the base the liquidity holds and the base owed to the position token summed before it is valued once. Fees not yet credited MUST be left out.
- Tokens, pools and prices requires every inexact division to round in the lender’s favor: the price, the price lowered by
gapBps, the value, quoteLimit and the base counted in recovered round down; the charge in owed and the lender’s base round up.
- Test Cases pin it to the unit: a charge of 249.99999999 rounds up to 250; an answer of 77.12345678 gives
P = 77,123,456, so 100 base credited to the position token add exactly 7,712.3456; and at 77, a value of 27,774.999999 is unwindable while 27,775, 1.1 times 25,250, is not.
The reference already computes this way, so its code does not change. Three tests now hold it there, and each fails when the reference is changed to round the price up, round the charge down, or count a value on the line as below it.
One part stays with the pool: what a concentrated position holds at P goes through a square root. The text requires that square root rounded down in the pool’s own fixed-point form, and each amount rounded down, so implementations agree to the unit over the same pool math, not across pools whose math differs.