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

# Set Allow Extension

> Switch the maturity extension flow on or off for a market

Builds the `setAllowExtension` transaction, the master switch over maturity extensions. Requires `DEFAULT_ADMIN_ROLE` on the market, held by the admin the lender of record named at adoption. The market's creator never holds that role, so extensions exist on a market only when its lender of record chooses to offer them.

An extension moves a maturity the borrower signed, and it needs no signature from the borrower. Switch the flow on only where the lender of record's [terms of use](/endpoints/lending/save-terms) provide for extensions.

With the switch off, no extension can be proposed, confirmed or applied, while an open proposal can still be cancelled. Switching it off withdraws nothing: open proposals stay on the market, and a confirmed batch can be applied again once the switch is back on. See [Propose Extension](/endpoints/lending/propose-extension) for the flow itself.

## Path Parameters

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

## Body Parameters

<ParamField body="allowed" type="boolean" required>
  `true` to switch extensions on, `false` to switch them off.
</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. When `txHash` is present, every other field is ignored.
</ParamField>

## Confirm the Change

Send the mined hash back to this path as `{ "txHash": "0x..." }`. The API checks that the transaction called `setAllowExtension` on the market. It then reads the offering back from the chain and updates the market record. [Confirm Extension Transaction](/endpoints/lending/confirm-extension-transaction) also accepts this transaction.

## Response Fields

The calldata response carries the transaction twice. `transaction` holds `to` and `data`. The same `to` and `data` also sit directly on `data`, and that is where the `chainId` and `value` binding lands, so sign from those four 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">`{ to, data }` for the `setAllowExtension` call on the market. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="to" type="string">The market address. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="data" type="string">The encoded `setAllowExtension` call. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="value" type="string">Always `"0"`. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="chainId" type="integer">The chain your instance resolves to. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="functionName" type="string">`setAllowExtension`, or the verified function when confirming.</ResponseField>
    <ResponseField name="requiredRole" type="string">`DEFAULT_ADMIN_ROLE`. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="description" type="string">Plain-language summary of the change. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="requiredSigner" type="string">Always `null` here: the signer is whoever holds `DEFAULT_ADMIN_ROLE`, not one fixed address. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="heldByThisInstance" type="boolean">`true` when a verified wallet of your instance holds `DEFAULT_ADMIN_ROLE`, `false` when none does, `null` when the check could not be completed. The build is never refused on it. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="signerAddress" type="string">The wallet of your instance that holds `DEFAULT_ADMIN_ROLE`, or `null`. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="note" type="string">What to do when your instance cannot sign: the wallet the lender of record placed the role with must sign, because any other wallet reverts `NotAuthorized`. `null` when your instance can sign. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="confirmWith" type="object">`{ endpoint, field }`: the call that confirms this transaction, and the body field that carries the hash. Returned when `txHash` is omitted.</ResponseField>
    <ResponseField name="txHash" type="string">Transaction hash. Returned when confirming.</ResponseField>
    <ResponseField name="signedBy" type="string">The wallet that sent the transaction. Returned when confirming.</ResponseField>
    <ResponseField name="blockNumber" type="integer">Block the transaction was mined in. Returned when confirming.</ResponseField>
    <ResponseField name="offering" type="object">The market's rate and term offering, read back from the chain after the transaction, with `allowExtension` among its fields. The same object [Set Rate Mode](/endpoints/lending/set-rate-mode) returns. Returned when confirming.</ResponseField>
    <ResponseField name="updatedColumns" type="array">Names of the stored market fields this confirmation changed. Returned when confirming.</ResponseField>
  </Expandable>
</ResponseField>

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

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

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

  const tx = await adminWallet.sendTransaction({
    to: calldata.to,
    data: calldata.data,
    value: calldata.value,
    chainId: calldata.chainId
  });
  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..."
      },
      "to": "0x70a0e25c7b768b87e658348b3b577678a173e038",
      "data": "0x...",
      "functionName": "setAllowExtension",
      "requiredRole": "DEFAULT_ADMIN_ROLE",
      "requiredSigner": null,
      "heldByThisInstance": false,
      "signerAddress": null,
      "note": "No wallet registered on this instance holds DEFAULT_ADMIN_ROLE on this market, so a transaction signed here reverts NotAuthorized. The wallet the lender of record placed that role with must sign it.",
      "confirmWith": {
        "endpoint": "POST /lending-external-securities-v2/api/markets/clx_secmarket_001/allow-extension",
        "field": "txHash"
      },
      "chainId": 11155111,
      "value": "0"
    }
  }
  ```

  ```json Confirmed Response theme={null}
  {
    "success": true,
    "data": {
      "txHash": "0x9f2c41d8b7e05a3164c2870fbd935e1a4c7802db6135ea9048f7c21b5d3ea41b",
      "functionName": "setAllowExtension",
      "signedBy": "0x7712db30a7b4ffd9c445793089118b60e56d752a",
      "blockNumber": 6789012,
      "offering": {
        "maxLoanDuration": "15552000",
        "termGracePeriod": "259200",
        "terminalDueDate": null,
        "termPenalty": "200",
        "marketDueFloor": null,
        "allowExtension": true,
        "rateMode": "CURVE",
        "rateFloor": "0",
        "rateCap": "0",
        "maxFixedRate": null,
        "reserveRatio": "0",
        "operatorShare": "800"
      },
      "updatedColumns": ["allowExtension"]
    }
  }
  ```
</ResponseExample>

## Error Codes

| Code                     | HTTP  | Cause                                                                                                               |
| ------------------------ | ----- | ------------------------------------------------------------------------------------------------------------------- |
| `MISSING_MARKET_ID`      | `400` | The `marketId` path segment is longer than 100 characters                                                           |
| `VALIDATION_ERROR`       | `400` | `allowed` is missing or not a boolean, or `txHash` is malformed                                                     |
| `INVALID_CONFIRMATION`   | `400` | The market has no on-chain address, so there is nothing to confirm against                                          |
| `MARKET_NOT_FOUND`       | `404` | No market with this ID on your instance                                                                             |
| `MARKET_PENDING_CURATOR` | `409` | The market has no lender of record yet, so nobody holds `DEFAULT_ADMIN_ROLE`. Skipped when confirming with `txHash` |
| `INTERNAL_ERROR`         | `500` | The chain could not be read while confirming. Retry shortly                                                         |

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