> 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

```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 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://docs.fira.money/developers/user-flows/repay-fixed-rate.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.
