> For the complete documentation index, see [llms.txt](https://constant-finance.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://constant-finance.gitbook.io/docs/v0/concepts/orders-and-matching.md).

# Orders and Matching

Orders let borrowers and suppliers state the terms they are willing to accept before any assets move. They are signed offchain and become economically effective only after a compatible match passes onchain validation and settlement.

## Supply Order

A Supply Order authorizes the protocol to use supplier assets within clearly signed limits.

| Information             | Meaning                                                                                            |
| ----------------------- | -------------------------------------------------------------------------------------------------- |
| Order ID                | A supplier-controlled identifier that, together with the supplier address, distinguishes the Order |
| Supply asset and amount | The offered token and the maximum signed capacity                                                  |
| Minimum supplier rate   | The lowest fixed unit rate the supplier will accept                                                |
| Term                    | The required duration to be agreed with the Borrow Order                                           |
| Expiry                  | The final time at which the signature may be used                                                  |
| Owner                   | The supplier who signed the Order                                                                  |
| Signature               | Proof that the supplier authorized these terms for the Gateway                                     |

In the current Sepolia flow, the matched assets move directly from the supplier's wallet at settlement, and the resulting Constant NFT is minted directly to that supplier.

Three independent states determine whether a Supply Order can execute:

* **Order capacity** is the unused part of the signed amount according to protocol accounting.
* **Wallet balance** is the amount the supplier currently owns.
* **Token approval** is the amount the Gateway is allowed to transfer.

All three must be sufficient when the match is submitted.

## Borrow Order

A Borrow Order describes the loan the borrower wants to open.

| Information             | Meaning                                                                                              |
| ----------------------- | ---------------------------------------------------------------------------------------------------- |
| Order ID                | A borrower-controlled identifier that, together with the borrower address, distinguishes the request |
| Borrow asset and amount | The token and principal requested by the borrower                                                    |
| Borrower rate           | The fixed unit rate offered by the borrower                                                          |
| Term                    | The duration used to establish the Position maturity                                                 |
| Expiry                  | The final time at which the signature may be used                                                    |
| ERC-20 collateral       | Fungible assets to be locked in the Position                                                         |
| NFT collateral          | Supported NFTs to be locked in the Position                                                          |
| Owner                   | The borrower who signed the request                                                                  |
| Fee field               | The fee-payment field in the signed request; the current Sepolia Basic origination fee is zero       |
| Signature               | Proof that the borrower authorized these terms for the Gateway                                       |

## Refinancing Order

A Refinancing Order points to an existing Position and describes the new debt terms, term, expiry, and collateral arrangement approved by that Position's borrower. It belongs to the refinance flow rather than the standard Basic origination flow.

See [Refinance](/docs/v0/concepts/refinance.md) for the complete lifecycle.

## How Orders Match

```mermaid
flowchart LR
    BO[Borrow Order] --> C[Compatibility checks]
    SO1[Supply Order A] --> C
    SO2[Supply Order B] --> C
    C --> G[Gateway settlement]
    G --> P[Position]
    G --> N1[Constant NFT A]
    G --> N2[Constant NFT B]
```

At a high level, a valid Basic match needs:

* valid signatures that have not expired;
* matching debt assets and compatible terms;
* supplier rates that fit within the borrower rate after the configured protocol spread;
* enough unused Supply Order capacity to fund the requested amount;
* sufficient live supplier balances and Gateway approvals;
* supported collateral owned by the borrower;
* a healthy Position at the time it opens; and
* a Borrow Order that has not already been used.

Several Supply Orders may fund one Borrow Order. Every non-zero supplier fill creates its own Constant NFT, while the Position combines the debt by asset.

## Atomic Settlement

For the current Order flows, the Gateway is the signing domain, asset spender, and execution entry point. It validates the complete match before the loan is finalized.

Asset transfers, collateral custody, Position creation, and Constant NFT minting all happen in one transaction. If a signature, capacity, balance, approval, collateral, or health check fails, the transaction leaves no partial loan behind.

## Capacity After Repayment

Once repayment is synchronized with the Gateway's accounting, reducing principal can restore the protocol-level capacity of a Supply Order. That accounting update does not by itself return assets to a wallet or recreate an ERC-20 approval.

Before restored capacity can fund another match, the supplier may still need to claim the repayment and approve the Gateway again.

Transferring a Constant NFT changes who owns the claim. It does not change who signed the original Supply Order.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://constant-finance.gitbook.io/docs/v0/concepts/orders-and-matching.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
