> 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

Supply collateral and borrow at a fixed rate in a single transaction, receiving USDC via the BT→FW→token path.

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