> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trusset.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Remove Liquidity

> Burn LP shares and withdraw the borrow asset

Redeems LP shares for the borrow asset at the current share price, which includes accrued interest. No approval is needed, so this is a single transaction.

<Warning>
  `shares` is always parsed at 18 decimals, regardless of the market's borrow asset. This is the one amount in the API that does not follow the borrow asset's precision. Read a provider's share balance from [Get Provider Balance](/endpoints/lending/get-provider-balance) and pass it through unchanged.
</Warning>

## Path Parameters

<ParamField path="marketId" type="string" required>Market ID.</ParamField>

## Body Parameters

<ParamField body="shares" type="string" required>
  LP shares to redeem as a decimal string with up to 18 decimal places, for example `"250000"`. Must be greater than zero.
</ParamField>

<ParamField body="provider" type="string" required>
  Wallet holding the shares, and the wallet that will sign. Two checks run against it: the provider's own share balance, and whether the pool can pay what those shares are worth. Neither can be asked without the address, so it is required rather than merely honoured. Omitting it returns `PROVIDER_REQUIRED`.

  A redemption that fails either check is refused with `INSUFFICIENT_SHARES` or `INSUFFICIENT_LIQUIDITY`, instead of handing back calldata that reverts. Not required when confirming with `txHash`, where the provider is taken from the mined transaction.
</ParamField>

<ParamField body="txHash" type="string">
  Hash of the transaction you broadcast for this operation. Send it to confirm the transaction and record the result. Omit it to receive the calldata.
</ParamField>

## Response Fields

<ResponseField name="data" type="object">
  <Expandable>
    <ResponseField name="action" type="string">`SIGN_TRANSACTION` when `txHash` is omitted.</ResponseField>
    <ResponseField name="transaction" type="object">Unsigned transaction, `{ to, data, value, chainId }`, for the `removeLiquidity` call. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="functionName" type="string">`removeLiquidity`. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="quoteValidForSeconds" type="integer">How long the liquidity check behind this payload holds, in seconds. The check reserves the interest that accrues over that window, so a payload broadcast inside it will not be refused for liquidity that accrual consumed. Present only when the check actually ran.</ResponseField>
    <ResponseField name="txHash" type="string">Transaction hash. Returned when confirming with `txHash`.</ResponseField>
    <ResponseField name="sharesRedeemed" type="string">Shares actually burned, read from the `LiquidityRemoved` event, at 18 decimals. Returned when confirming with `txHash`.</ResponseField>
    <ResponseField name="amount" type="string">Settlement amount that actually left the pool, in borrow asset units. Null when the event could not be read from the receipt. Returned when confirming with `txHash`.</ResponseField>
  </Expandable>
</ResponseField>

<Note>
  Withdrawal is bounded by available liquidity, not by share balance. A provider holding shares worth more than the pool's idle balance cannot exit fully while borrowers hold the difference, and the contract reverts rather than partially filling. Supply `provider` to have that refused before you sign, or check `availableLiquidity` on [Get Market Metrics](/endpoints/lending/get-metrics) before redeeming a large position.
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.trusset.org/lending-external-securities/api/positions/{marketId}/remove-liquidity" \
    -H "X-API-Key: trusset_your_key_here" \
    -H "Content-Type: application/json" \
    -d '{"shares": "50000"}'
  ```
</RequestExample>

<ResponseExample>
  ```json Calldata Response theme={null}
  {
    "success": true,
    "data": {
      "action": "SIGN_TRANSACTION",
      "transaction": {
        "to": "0x70a0e25c7b768b87e658348b3b577678a173e038",
        "data": "0x...",
        "value": "0",
        "chainId": 11155111
      },
      "functionName": "removeLiquidity"
    }
  }
  ```

  ```json Confirmed Response theme={null}
  {
    "success": true,
    "data": {
      "txHash": "0x9f2c41d8b7e05a3164c2870fbd935e1a4c7802db6135ea9048f7c21b5d3ea41b",
      "sharesRedeemed": "50000.000000000000000000",
      "amount": "50082.576000"
    }
  }
  ```

  ```json Error - Insufficient Liquidity theme={null}
  {
    "success": false,
    "error": {
      "code": "INSUFFICIENT_LIQUIDITY",
      "message": "The market has 12500.000000 USDC of uncommitted liquidity, which is less than this redemption is worth. Wait for borrowers to repay, or redeem fewer shares."
    }
  }
  ```
</ResponseExample>

## Error Codes

| Code                       | HTTP  | Cause                                                                                                                                                  |
| -------------------------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `NO_MARKET_ADDRESS`        | `400` | The market has no on-chain address recorded                                                                                                            |
| `VALIDATION_ERROR`         | `400` | `shares` is not a positive decimal string, or carries more than 18 decimal places                                                                      |
| `PROVIDER_REQUIRED`        | `400` | `provider` was omitted while building calldata                                                                                                         |
| `INSUFFICIENT_SHARES`      | `400` | `shares` exceeds the market's outstanding shares, or the balance held by `provider`                                                                    |
| `INSUFFICIENT_LIQUIDITY`   | `400` | The redemption is worth more than the pool can pay once accruing interest is reserved. The message names the largest share count that would still fill |
| `MARKET_NOT_FOUND`         | `404` | No market with this ID on your instance                                                                                                                |
| `MARKET_STATE_UNAVAILABLE` | `503` | The market could not be read to check shares or liquidity. Retry shortly                                                                               |
