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

# Sweep Infrastructure Fees

> Pay the infrastructure fee the market has booked to the Trusset wallet fixed in the contract

Builds the `sweepInfrastructureFees` transaction, which pays everything the market has booked as Trusset's infrastructure fee to the Trusset wallet. That wallet is a constant in the market contract, `0x65FF3a731366472d40CF458332457403168c2BEA`, and the market has no setter for it.

Any wallet may sign, and nothing reaches the signer. The sweep only moves money that is already booked to Trusset. Until it runs, that money sits on the market as a liability that is never lent out and that no liquidity provider can withdraw.

The booked balance has two sources. Trusset takes 15 percent of repaid interest and of interest recovered through liquidation, and 87 percent of every fixed transaction fee. [Get Cashflows](/endpoints/lending/get-cashflows) itemises both.

## Path Parameters

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

## Body Parameters

<ParamField body="txHash" type="string">
  Hash of the sweep you broadcast. 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`. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="transaction" type="object">Unsigned transaction, `{ to, data, value, chainId }`, targeting the market. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="functionName" type="string">`sweepInfrastructureFees`. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="description" type="string">What the transaction pays and to whom, in words. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="permissionless" type="boolean">Always `true`. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="requiredRole" type="string">Always `null`, because the sweep needs no role. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="requiredSigner" type="string">Always `null`, because any wallet may sign. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="note" type="string">States that the market pays the wallet fixed in the contract, never the signer. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="destination" type="string">The Trusset wallet, read from the market. `null` when that read fails, which does not stop the sweep, because the contract pays its constant either way.</ResponseField>
    <ResponseField name="amount" type="string">On the calldata call, what was booked when the calldata was built. On the confirm call, what the sweep actually paid, read from the `InfrastructureFeePaid` event.</ResponseField>
    <ResponseField name="amountRaw" type="string">`amount` in the borrow asset's smallest unit.</ResponseField>
    <ResponseField name="asset" type="object">The borrow asset: `address`, `symbol`, `decimals`.</ResponseField>
    <ResponseField name="confirmWith" type="object">Where to send the hash: `endpoint` names this route and `field` is `txHash`. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="kind" type="string">`infrastructure`. Returned when confirming with `txHash`.</ResponseField>
    <ResponseField name="txHash" type="string">Sweep transaction hash. Returned when confirming with `txHash`.</ResponseField>
    <ResponseField name="signedBy" type="string">The wallet that sent the sweep. Returned when confirming with `txHash`.</ResponseField>
    <ResponseField name="at" type="string">ISO 8601 time of the block the sweep mined in. `null` when the block time could not be read. Returned when confirming with `txHash`.</ResponseField>
  </Expandable>
</ResponseField>

The sweep pays whatever is booked when it mines, which can exceed the amount quoted when the calldata was built. A confirmed sweep is recorded on the market as an `INFRASTRUCTURE_FEES_SWEPT` transaction, visible through [List Transactions](/endpoints/lending/list-transactions).

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.trusset.org/lending-external-securities-v2/api/markets/{marketId}/infrastructure-fees/sweep" \
    -H "X-API-Key: trusset_your_key_here" \
    -H "Content-Type: application/json" \
    -d '{}'
  ```

  ```typescript TypeScript theme={null}
  const url = `https://api.trusset.org/lending-external-securities-v2/api/markets/${marketId}/infrastructure-fees/sweep`;
  const headers = { 'X-API-Key': 'trusset_your_key_here', 'Content-Type': 'application/json' };

  const built = await fetch(url, { method: 'POST', headers, body: JSON.stringify({}) });
  const { data } = await built.json();

  const tx = await wallet.sendTransaction(data.transaction);
  await tx.wait();

  await fetch(url, { method: 'POST', headers, body: JSON.stringify({ txHash: tx.hash }) });
  ```
</RequestExample>

<ResponseExample>
  ```json Calldata Response theme={null}
  {
    "success": true,
    "data": {
      "action": "SIGN_TRANSACTION",
      "transaction": {
        "to": "0x70a0e25c7b768b87e658348b3b577678a173e038",
        "data": "0x...",
        "value": "0",
        "chainId": 11155111
      },
      "functionName": "sweepInfrastructureFees",
      "description": "Pay the 150.0 USDC of accrued infrastructure fees to the platform wallet 0x65ff3a731366472d40cf458332457403168c2bea",
      "permissionless": true,
      "requiredRole": null,
      "requiredSigner": null,
      "note": "Any wallet may sign this transaction. The market pays the accrued infrastructure fee to the platform wallet fixed in the contract, never to the signer.",
      "destination": "0x65ff3a731366472d40cf458332457403168c2bea",
      "amount": "150.0",
      "amountRaw": "150000000",
      "asset": {
        "address": "0x98ad0ca091552e23c564b41c74282e5343d03e8a",
        "symbol": "USDC",
        "decimals": 6
      },
      "confirmWith": {
        "endpoint": "POST /lending-external-securities-v2/api/markets/clx_secmarket_001/infrastructure-fees/sweep",
        "field": "txHash"
      }
    }
  }
  ```

  ```json Confirmed Response theme={null}
  {
    "success": true,
    "data": {
      "kind": "infrastructure",
      "txHash": "0x5b1d7e2c90a4f36e8d0b1c7a95e4f2d38a6c0b91e7d5f4a2c3b8e06d19f7a254",
      "signedBy": "0x5ad87a0621175206b72d10e4b8577b192e7f40ab",
      "destination": "0x65ff3a731366472d40cf458332457403168c2bea",
      "amount": "150.0",
      "amountRaw": "150000000",
      "asset": {
        "address": "0x98ad0ca091552e23c564b41c74282e5343d03e8a",
        "symbol": "USDC",
        "decimals": 6
      },
      "at": "2026-09-25T14:03:12.000Z"
    }
  }
  ```

  ```json Error - Nothing Payable theme={null}
  {
    "success": false,
    "error": {
      "code": "NO_INFRASTRUCTURE_FEES",
      "message": "No infrastructure fee is payable on this market: 0.0 USDC has accrued, and the leg is booked only out of repaid interest and liquidation proceeds, so sweepInfrastructureFees would revert. Nothing to sign until interest is repaid or a liquidation settles."
    }
  }
  ```
</ResponseExample>

## Error Codes

| Code                      | HTTP  | Cause                                                                                         |
| ------------------------- | ----- | --------------------------------------------------------------------------------------------- |
| `VALIDATION_ERROR`        | `400` | `txHash` is not a 0x-prefixed 32-byte hex hash                                                |
| `MISSING_MARKET_ID`       | `400` | The market ID in the path is longer than 100 characters                                       |
| `NO_MARKET_ADDRESS`       | `400` | The market has no on-chain address recorded                                                   |
| `MARKET_NOT_FOUND`        | `404` | No market with this ID on your instance                                                       |
| `NO_INFRASTRUCTURE_FEES`  | `409` | Nothing is booked for Trusset, so the sweep would revert. The message states what has accrued |
| `MARKET_FEES_UNAVAILABLE` | `503` | The booked balances could not be read, so no transaction is offered. Retry shortly            |

Confirming with `txHash` can also return any [transaction verification error](/endpoints/introduction#confirm-a-transaction).
