> For the complete documentation index, see [llms.txt](https://docs.qiro.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.qiro.fi/developer-section/qiro-instant-settlement/facility-closures.md).

# Facility closures

`repayAndCloseFacility` atomically repays every outstanding facility obligation and closes the LOC. The partner does not choose a closure amount, drawdown list, wallet, chain, contract, token, or allocation.

## High-level SDK

Use `repayAndCloseFacility(...)` for the normal partner flow.

The SDK:

1. retrieves the facility;
2. verifies the wallet is the facility’s active designated wallet;
3. creates a closure resource with a generated idempotency key;
4. handles up to two token approval transactions when needed;
5. verifies and sends the `repayDrawdownsAndClose` transaction;
6. verifies `RepaymentMade`, expected `DrawdownRepaid` events, and `LOCClosed` in the receipt;
7. polls the closure resource until `CLOSED` or `FAILED`.

## REST workflow

```http
GET  /v1/facilities/{facility_id}/closure-dues
POST /v1/facilities/{facility_id}/closures
GET  /v1/facility-closures/{closure_id}
POST /v1/facility-closures/{closure_id}/prepare
```

The dues preview is informational. Creation reads fresh obligations, creates the closure resource, blocks new drawdown requests, and returns the first unsigned action.

If the first action is `TOKEN_APPROVAL`, the partner signs and confirms the approval, then calls `prepare` for the next action. If allowance is already sufficient, creation can return the financial closure action directly.

The financial transaction repays all obligations and closes the LOC. Qiro marks the facility closed only after the required repayment and `LOCClosed` evidence is verified.

## Token approval

If allowance is sufficient, creation may return a `FACILITY_CLOSURE` action immediately.

If allowance is insufficient, creation returns `TOKEN_APPROVAL`. Some tokens require resetting a non-zero allowance to zero before setting a new allowance. The SDK supports this bounded path:

```
TOKEN_APPROVAL amount 0
TOKEN_APPROVAL amount fixed maximum
FACILITY_CLOSURE amount fixed maximum
```

The SDK stops if the API ever asks for more than two approval transactions.

## Main statuses

```
READY_FOR_SUBMISSION
SUBMITTING
CONFIRMING
CLOSED
FAILED
```

Do not treat a transaction hash alone as closure. The status endpoint is authoritative.
