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

# Create loan

> Creates a new loan with initial collateral and requested principal borrows, returning both the loan address and the serialized transaction needed to initialize it.



## OpenAPI

````yaml post /markets/creditbook/create
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/create:
    post:
      tags:
        - Markets
      summary: Create loan
      description: >-
        Creates a new loan with initial collateral and requested principal
        borrows, returning both the loan address and the serialized transaction
        needed to initialize it.
      operationId: createLoan
      parameters:
        - name: payer
          in: header
          required: true
          schema:
            type: string
          description: Wallet that pays transaction fees for the loan creation.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateLoanRequest'
      responses:
        '200':
          description: Serialized transaction and derived loan address.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateLoanResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '500':
          $ref: '#/components/responses/GeneralError'
components:
  schemas:
    CreateLoanRequest:
      type: object
      required:
        - depositCollateral
        - borrower
        - principalRequested
      properties:
        depositCollateral:
          type: array
          items:
            $ref: '#/components/schemas/LoanCreateCollateralInput'
        borrower:
          type: string
          description: Wallet address that will own the new loan.
        principalRequested:
          type: array
          items:
            $ref: '#/components/schemas/PrincipalBorrowRequest'
        assetIndexGuidance:
          $ref: '#/components/schemas/AssetIndexGuidance'
        loanNonce:
          type: string
          description: Optional nonce override used when deriving the loan PDA.
        isLoop:
          type: boolean
          description: Optional flag marking the created loan as a loop position.
    CreateLoanResponse:
      type: object
      required:
        - transaction
        - loanAddress
      properties:
        transaction:
          $ref: '#/components/schemas/VersionedTransactionResponse'
        loanAddress:
          type: string
          description: Derived loan PDA created by the transaction.
    LoanCreateCollateralInput:
      type: object
      required:
        - collateralAmount
        - collateralAssetData
      properties:
        collateralAmount:
          type: number
          description: >-
            Collateral amount to include in the initial loan creation, in
            lamports.
        collateralAssetData:
          $ref: '#/components/schemas/AssetDataInfo'
        loanCreationParams:
          type: object
          description: >-
            Optional asset-specific loan creation parameters used when pricing
            or validating the collateral.
          additionalProperties: true
        weightMatrixUpdate:
          type: array
          description: >-
            Target allocation weights across ledgers for this collateral.
            Loopscale expects five entries.
          items:
            type: number
    PrincipalBorrowRequest:
      type: object
      required:
        - ledgerIndex
        - principalAmount
        - principalMint
        - strategy
        - durationIndex
        - expectedLoanValues
      properties:
        ledgerIndex:
          type: integer
          description: Which ledger to borrow into (0–4). Use 0 for most cases.
        principalAmount:
          type: number
          description: Amount of principal to borrow in lamports
        principalMint:
          type: string
          description: Mint address of the principal token
        strategy:
          type: string
          description: Strategy address returned from quote
        durationIndex:
          type: integer
          description: Duration preset (0 = 1d, 1 = 1w, 2 = 1mo, 3 = 3mo, 4 = 5min)
        expectedLoanValues:
          type: object
          description: >-
            Values used to ensure the lender doesn't change order details before
            transaction completes
          allOf:
            - $ref: '#/components/schemas/ExpectedLoanValues'
    AssetIndexGuidance:
      type: array
      items:
        type: integer
      description: >-
        Optional oracle asset ordering hints used by Loopscale when validating a
        transaction.
    VersionedTransactionResponse:
      type: object
      required:
        - message
        - signatures
      properties:
        message:
          type: string
          description: Base64-encoded versioned transaction message
        signatures:
          type: array
          items:
            $ref: '#/components/schemas/VersionedTransactionSignature'
    AssetDataInfo:
      oneOf:
        - type: object
          required:
            - Spl
          properties:
            Spl:
              $ref: '#/components/schemas/SplAssetData'
        - type: object
          required:
            - StakedSol
          properties:
            StakedSol:
              $ref: '#/components/schemas/StakedSolAssetData'
        - type: object
          required:
            - Orca
          properties:
            Orca:
              $ref: '#/components/schemas/OrcaPositionAssetData'
        - type: object
          required:
            - Meteora
          properties:
            Meteora:
              $ref: '#/components/schemas/MeteoraDlmmPositionAssetData'
        - type: object
          required:
            - Raydium
          properties:
            Raydium:
              $ref: '#/components/schemas/RaydiumPositionAssetData'
      description: >-
        Tagged asset descriptor used for collateral inputs. LP position variants
        can optionally specify `tokenProgram` to override the token program used
        when deriving token accounts.
    ExpectedLoanValues:
      type: object
      required:
        - expectedApy
        - expectedLqt
      properties:
        expectedApy:
          type: number
          description: Expected APY in cBPS
        expectedLqt:
          type: array
          items:
            type: number
          description: Expected liquidation thresholds per ledger (cBPS)
    VersionedTransactionSignature:
      type: object
      required:
        - publicKey
        - signature
      properties:
        publicKey:
          type: string
        signature:
          type: string
    SplAssetData:
      type: object
      required:
        - mint
      properties:
        mint:
          type: string
          description: Collateral mint pubkey
    StakedSolAssetData:
      type: object
      required:
        - stakeAccount
        - stakePool
      properties:
        stakeAccount:
          type: string
          description: Stake account pubkey
        stakePool:
          type: string
          description: Stake pool pubkey
    OrcaPositionAssetData:
      type: object
      required:
        - positionMint
        - whirlpool
      properties:
        positionMint:
          type: string
          description: Position mint pubkey
        whirlpool:
          type: string
          description: Whirlpool pubkey
        tokenProgram:
          type: string
          description: Optional token program override for the position mint.
    MeteoraDlmmPositionAssetData:
      type: object
      required:
        - positionAddress
        - lbPair
      properties:
        positionAddress:
          type: string
          description: DLMM position address
        lbPair:
          type: string
          description: Meteora DLMM pair pubkey
        tokenProgram:
          type: string
          description: Optional token program override for the position mint.
    RaydiumPositionAssetData:
      type: object
      required:
        - mint
        - pool
      properties:
        mint:
          type: string
          description: Raydium position mint pubkey
        pool:
          type: string
          description: Raydium pool pubkey
        tokenProgram:
          type: string
          description: Optional token program override for the position mint.
  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.

````