> 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/provide-liquidity.md).

# Provide Liquidity

```mermaid
sequenceDiagram
  actor User
  participant Router as Router (ActionAddRemoveLiqV3)
  participant FW as FW
  participant CT as CouponToken (CT)
  participant FM as FiraMarket (BT/FW/LP)

  Note over User,Router: User approves tokens to Router (ERC20 approve)
  User->>Router: addLiquidity*(receiver, FM, ...)
  alt Dual Token+BT (addLiquidityDualTokenAndBt)
    Router->>FW: mint FW from token input (deposit)
    FW-->>FM: FW sent to market
    Router->>FM: transferFrom(user, BT, netBtUsed) — BT from user to market
    Router->>FM: mint(receiver, netFwUsed, netBtUsed)
    FM-->>User: LP tokens to receiver
  else Dual FW+BT (addLiquidityDualFwAndBt)
    Router->>FM: transferFrom(user, FW, netFwUsed)
    Router->>FM: transferFrom(user, BT, netBtUsed)
    Router->>FM: mint(receiver, netFwUsed, netBtUsed)
    FM-->>User: LP tokens to receiver
  else Single Token (addLiquiditySingleToken)
    Router->>FW: mint FW from token input
    FW-->>FM: FW to market
    Router->>FM: swapFwForExactBt(market, btOut, "") — swap portion of FW to BT
    FM-->>FM: BT stays in market
    Router->>FM: mint(receiver, netFwLeft, netBtReceived)
    FM-->>User: LP tokens to receiver
  else Single Token Keep CT (addLiquiditySingleTokenKeepCt)
    Router->>FW: mint FW from token input (to Router)
    FW-->>Router: FW out
    Router->>CT: transfer portion of FW to CT contract
    Router->>FM: transfer remaining FW to market
    Router->>CT: mintBC(market, receiver) — BT to market, CT to receiver
    CT-->>FM: BT
    CT-->>User: CT tokens
    Router->>FM: mint(receiver, netFwAddLiquidity, netBtFromMint)
    FM-->>User: LP tokens to receiver
  end
```

**Key references**: `ActionAddRemoveLiqV3.addLiquidityDualTokenAndBt`, `addLiquidityDualFwAndBt`, `addLiquiditySingleToken`, `addLiquiditySingleBt`, `addLiquiditySingleFw`, `addLiquiditySingleTokenKeepCt`, `addLiquiditySingleFwKeepCt`.

## Details

* **Goal**: Provide liquidity to BT/FW market and receive LP.
* **Preconditions**:
  * Approvals for all inputs (`tokenIn`, `BT`, and/or `FW`).
  * Set `minLpOut` and approximation params when single-sided.
* **Additional entrypoints**:
  * `addLiquiditySingleBt` — BT only, swaps portion to FW.
  * `addLiquiditySingleFw` — FW only, swaps portion to BT.
  * `addLiquiditySingleFwKeepCt` — FW + keep CT variant.

## Views and events

**Views**

* Market: `readTokens()`, `isExpired()`, `readState(router)`, `observe(secondsAgos)`.
* LP: `balanceOf(user)`, `totalSupply()` (derive proportional share of `totalBt/totalFw`).

**Events**

* Router: `AddLiquidityDualTokenAndBt`, `AddLiquidityDualFwAndBt`, `AddLiquiditySingleBt`, `AddLiquiditySingleFw`, `AddLiquiditySingleToken`, `AddLiquiditySingleTokenKeepCt`, `AddLiquiditySingleFwKeepCt`.
* Market: `Mint`, `Swap` (during balancing), `UpdateImpliedRate`.

## Reward share (LP)

* Suggested formula: `lpBalance / totalSupply()` over the epoch (TWAP).
* Functions to call:
  * `IERC20(market).balanceOf(user)`, `IERC20(market).totalSupply()`
  * `FiraMarket.readState(router)` → `totalBt`, `totalFw`, `totalLp` (for underlying attribution)


---

# 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/provide-liquidity.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.
