How a loan works

Four moves. The order is the mechanism.

lender signs an offer  ->  borrower takes it  ->  the feed watches it  ->  it ends
   (off chain, free)      (USDG moves once)      (Chainlink, per loan)    (repay or close-out)

1. A lender signs an offer

The lender chooses the ticker, the size, the rate they want, the loan to value at which a liquidator may step in, and how long the offer stays valid. They sign it with EIP-712 and pay no gas. Nothing is on chain yet.

A lender who has changed their mind burns the offer's nonce, which does cost gas. That is the trade for a free offer.

expiry is the offer's validity, not the loan's term. If nobody takes the offer by that timestamp it is dead. The loan that comes out of it has no maturity: it lives while it is healthy.

2. A borrower takes it

The borrower posts the collateral, the contract checks the signature, the price and the cap, and the USDG goes from the lender straight to the borrower in one transfer.

The protocol custodies the collateral and nothing else. It never holds the principal, not for a block. A test asserts the contract's USDG balance is zero after every path, including the fuzzed one.

The loan must be healthy the moment it exists. A lender whose offer would be liquidatable on the block it is taken has signed a gift to a liquidator, so the contract refuses it.

3. The feed watches it

Only tickers with a Chainlink equity feed on this chain are accepted. Those feeds publish on a 24 hour heartbeat with a 0.5% deviation trigger, and they answer with 8 decimals.

Staleness here is a state, not an error. The underlying equity trades 24/5 while the token trades 24/7, so every feed goes quiet across every weekend by design. A protocol that reverted on staleness would freeze all its close-outs for exactly the hours when the collateral is still moving and nobody can see it. So:

Action Fresh price Weekend-quiet price Past 4 days
Take a new loan yes no no
Liquidate yes yes no
Repay yes yes yes

Repaying is never blocked. A borrower must never be trapped by an oracle going quiet.

4. It ends one of two ways

The borrower repays. Principal plus accrued interest goes to the lender, the protocol's share of the interest goes to the treasury, and the collateral is released to any address the borrower names. That address is not the one that funded the position, which is what keeps an entry and an exit from joining up on chain.

Or it is closed out. Anyone can liquidate an unhealthy loan. The liquidator pays the lender what is owed and receives the collateral that covers it plus a bonus. Whatever is left over goes back to the borrower, in the same transaction. See Risk.