> 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/borrow-fixed-rate.md).

# Borrow Fixed Rate

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

  Note over User,Router: User approves collateralToken to Router (ERC20 approve)
  User->>Router: supplyAndBorrowSingleToken(marketParams, FRLM, FM, collateral, btToBorrow, output, limit, receiver)
  Router->>Router: transferFrom(user, collateralToken, collateral)
  Router->>FRLM: approve(collateralToken, collateral)
  Router->>FRLM: supplyCollateral(marketParams, collateral, user, "")
  FRLM-->>Router: position updated (collateral credited to user)
  Router->>FRLM: borrow(marketParams, btToBorrow, 0, user, Router)
  FRLM-->>Router: transfer BT to Router (loanToken = BT, debt on user)
  Router->>FM: transfer BT to FM, swapExactBtForFw(Router, btBorrowed, "")
  FM-->>Router: FW out to Router
  Router->>FW: transfer FW to FW contract
  Router->>FW: redeem(Router, fwOut, tokenRedeemFw, 0, true)
  FW-->>Router: tokenOut (e.g., USDC)
  Router-->>User: transfer tokenOut to receiver
```

**Also available**: `borrowSingleToken` — same flow but skips the collateral supply step (assumes collateral already supplied).

**Key references**: `src/fira_bonding/router/ActionBorrow.sol::supplyAndBorrowSingleToken`, `borrowSingleToken`.

## Details

* **Goal**: Supply collateral and receive a target token in one transaction (via BT→FW→token path).
* **Preconditions**:
  * User approved `collateralToken` to the router.
  * `tokensToBorrow > 0`, `collateralAmount > 0`, `receiver != 0x0`.
  * Market is initialized; `firaMarket` and `lendingMarket` set.
  * User must have authorized the router on the LendingMarket (`setAuthorization(router, true)`).
* **Parameters** (high level):
  * `marketParams` (Fira Lending), `collateralAmount`, `tokensToBorrow` (BT),
  * `output` (TokenOutput: `tokenOut`, `tokenRedeemFw`, `minTokenOut`, `firaSwap`, `swapData`),
  * `limitOrderData` (kept for interface compatibility, orderbook not used in current version).

## Views and events

**Views**

* Lending: `getUserPosition(marketParams, user)` → `supplyAssets`, `supplyShares`, `borrowAssets`, `borrowShares`, `collateralAssets`.
* Lending: `position(id, user)`, `market(id)`.
* Market (fixed-rate): `readTokens()`, `isExpired()`.

**Events**

* Lending: `EventsLib.SupplyCollateral`, `EventsLib.Borrow`.
* Market: `Swap` (BT→FW), `UpdateImpliedRate`.
* FW: `Deposit` (tokenIn→FW), `Redeem` (FW→tokenOut).

## Reward share (fixed-rate borrow)

* Suggested formula: `userBorrowBT / totalBorrowBT` over the epoch (TWAP).
* Functions to call:
  * `LendingMarket.getUserPosition(marketParamsBT, user)` → `borrowAssets` (userBorrowBT)
  * `LendingMarket.market(idBT).totalBorrowAssets` → `totalBorrowBT` (consider `accrueInterest(marketParamsBT)` before reading)
  * `FiraMarket.readTokens()` → BT address; `FiraMarket.isExpired()`
* Events to index: `EventsLib.Borrow`, `FiraMarket.Swap` (BT→FW), `IFiraWrappedStandardized.Redeem`


---

# 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/borrow-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.
