> For the complete documentation index, see [llms.txt](https://docs.fira.money/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fira.money/developers/user-flows/repay-fixed-rate.md).

# Repay Fixed Rate

Repay fixed-rate debt using any input token, with automatic BT acquisition via AMM swap (pre-expiry) or BT+CT minting (post-expiry).

```mermaid
sequenceDiagram
  actor User
  participant Router as Router (ActionBorrow)
  participant FRLM as Fixed Rate LendingMarket (FRLM)
  participant FM as FiraMarket
  participant FW as FW
  participant CT as CouponToken (CT)

  Note over User,Router: User approves input token to Router (ERC20 approve)
  User->>Router: repay(marketParams, FRLM, FM, tokensToRepay, input)
  alt BT not expired
    Router->>FW: mintFwFromToken (input token → FW)
    FW-->>Router: FW out
    Router->>FM: swapFwForExactBt (FW → BT via AMM)
    FM-->>Router: BT out
    Router->>FRLM: approve BT, repay(marketParams, btToRepay, 0, user, "")
    FRLM-->>Router: position updated (debt reduced)
    Router-->>User: refund excess BT (if any)
  else BT expired
    Router->>FW: mintFwFromToken (input token → FW, sent to CT contract)
    FW-->>CT: FW deposited
    Router->>CT: mintBC(Router, Router) — mints both BT and CT to Router
    CT-->>Router: BT + CT out (CT is minted but economically worthless post-expiry)
    Router->>FRLM: approve BT, repay(marketParams, btToRepay, 0, user, "")
    FRLM-->>Router: position updated (debt reduced)
    Router-->>User: refund excess BT (if any)
    Note over Router: CT minted post-expiry stays in Router (zero value, never burned)
  end
```

**Key references**: `ActionBorrow.repay`.

## Details

* **Goal**: Repay debt using an input token; router converts to BT as needed.
* **Preconditions**:
  * Existing borrow: else `"AB: no borrow"`.
  * `tokensToRepay` must be ≤ current debt: else `"AB: repay too much"`.
  * Input token approval to router.
* **Expiry handling**:
  * **Pre-expiry**: Input token → FW (mint) → BT (AMM swap via FiraMarket). Repay, refund excess BT.
  * **Post-expiry**: Input token → FW (mint to CT contract) → `CT.mintBC` produces BT + CT. Only BT is used for repayment. CT is minted but NOT burned — it stays in the router with zero economic value.

## Views and events

**Views**

* Lending: `getUserPosition` (pre/post), `position(id, user)`.
* Market: `isExpired()`.
* FW: `previewDeposit`, `bcIndexStored()` for estimation on expired paths.

**Events**

* Lending: `EventsLib.Repay` (assets, shares), possibly `EventsLib.AccrueInterest`.
* Router/Misc: `MintFwFromToken`, `MintBcFromFw` when conversions occur.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.fira.money/developers/user-flows/repay-fixed-rate.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
