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

# Build loan

> Builds or mutates a loan through a sequence of high-level actions. Supported step types currently include `repay`, `flashBorrow`, and `swapCollateral`.



## OpenAPI

````yaml post /markets/creditbook/build
openapi: 3.1.3
info:
  title: Loopscale API
  version: 1.0.0
servers:
  - url: https://tars.loopscale.com/v1
    description: Loopscale Production Server
security: []
paths:
  /markets/creditbook/build:
    post:
      tags:
        - Markets
      summary: Build loan
      description: >-
        Builds or mutates a loan through a sequence of high-level actions.
        Supported step types currently include `repay`, `flashBorrow`, and
        `swapCollateral`.
      operationId: buildLoan
      parameters:
        - name: user-wallet
          in: header
          required: true
          schema:
            type: string
          description: Wallet address of the borrower whose loan is being built or updated.
        - name: payer
          in: header
          required: false
          schema:
            type: string
          description: Optional fee payer. Defaults to `user-wallet` when omitted.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LoanBuildRequest'
      responses:
        '200':
          description: >-
            Derived loan address and the transaction sequence produced by the
            requested build steps.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LoanBuildResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '500':
          $ref: '#/components/responses/GeneralError'
components:
  schemas:
    LoanBuildRequest:
      type: object
      required:
        - steps
      properties:
        loan:
          type: string
          description: >-
            Optional existing loan address. Omit to start from a new
            flash-borrow step.
        steps:
          type: array
          items:
            $ref: '#/components/schemas/LoanBuildStep'
    LoanBuildResponse:
      type: object
      required:
        - loan
        - transactions
      properties:
        loan:
          type: string
          description: Resulting loan address after the build flow completes.
        transactions:
          type: array
          items:
            $ref: '#/components/schemas/VersionedTransactionResponse'
    LoanBuildStep:
      type: object
      required:
        - type
        - params
      properties:
        type:
          type: string
          enum:
            - repay
            - flashBorrow
            - swapCollateral
        params:
          type: object
          description: >-
            Step payload for the selected type. `repay` uses the repay endpoint
            shape without the top-level `loan`, `flashBorrow` uses the
            flash-borrow payload, and `swapCollateral` uses the swap-collateral
            payload without the top-level `loan`.
          additionalProperties: true
    VersionedTransactionResponse:
      type: object
      required:
        - message
        - signatures
      properties:
        message:
          type: string
          description: Base64-encoded versioned transaction message
        signatures:
          type: array
          items:
            $ref: '#/components/schemas/VersionedTransactionSignature'
    VersionedTransactionSignature:
      type: object
      required:
        - publicKey
        - signature
      properties:
        publicKey:
          type: string
        signature:
          type: string
  responses:
    BadRequest:
      description: Bad Request
      content:
        text/plain:
          schema:
            type: string
            example: 'Something went wrong: You have an error in your SQL syntax.'
    GeneralError:
      description: General Server Error
      content:
        text/plain:
          schema:
            type: string
            example: >-
              Failed to deserialize the JSON body into the target type: missing
              field `mints` at line 1 column 1.

````