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

# Settle Position

> Returns the advanced funds from the position's one-time wallet to Vanish's trading accounts, wrapped around the instructions supplied in `main_tx`. Always returns a signed transaction for you to broadcast - there is no bundle route here.

Set `cleanup_leftover_sol` to `true` only on the settle that fully closes the position. Follow every settle with [`POST /borrow/commit`](/api-reference/lending/commit). Requires a signature valid for 10 minutes; see [Signing Requests](/guide/integration/signing#signing-requests) and the [Settle Flow](/guide/integration/lending#settle).



## OpenAPI

````yaml POST /borrow/settle
openapi: 3.0.1
info:
  title: Vanish Core API
  description: API endpoints for the Vanish Core service.
  license:
    name: MIT
  version: 2.0.0
servers:
  - url: https://core-api-dev.vanish.trade
security:
  - ApiKeyAuth: []
paths:
  /borrow/settle:
    post:
      summary: Settle Position
      description: >-
        Returns the advanced funds from the position's one-time wallet to
        Vanish's trading accounts, wrapped around the instructions supplied in
        `main_tx`. Always returns a signed transaction for you to broadcast -
        there is no bundle route here.


        Set `cleanup_leftover_sol` to `true` only on the settle that fully
        closes the position. Follow every settle with [`POST
        /borrow/commit`](/api-reference/lending/commit). Requires a signature
        valid for 10 minutes; see [Signing
        Requests](/guide/integration/signing#signing-requests) and the [Settle
        Flow](/guide/integration/lending#settle).
      requestBody:
        description: Details of the settle request.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BorrowSettleRequest'
        required: true
      responses:
        '200':
          description: Successful settle action response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BorrowActionResponse'
        '400':
          description: >-
            Bad request. The amount is not greater than 0, the one-time wallet
            was not found or does not belong to this user, the transaction
            failed simulation, or a settle was already initiated with this
            signature.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BorrowError'
        '401':
          description: >-
            Unauthorized. The request is missing a valid API key or the
            signature is invalid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BorrowError'
        '429':
          description: >-
            Rate limit exceeded. Contact the Vanish team to raise your team's
            requests-per-second cap.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BorrowError'
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BorrowError'
components:
  schemas:
    BorrowSettleRequest:
      required:
        - smart_wallet_id
        - user_address
        - token_address
        - amount
        - loan_additional_sol
        - cleanup_leftover_sol
        - main_tx
        - timestamp
        - user_signature
      type: object
      properties:
        smart_wallet_id:
          description: >-
            Identifier of the one-time wallet holding the position. Must belong
            to user_address.
          type: integer
          example: 4821
        user_address:
          description: The Solana wallet address of the user settling the position.
          type: string
        token_address:
          description: >-
            The address of the token expected to land back in the one-time
            wallet from your instructions. Wrapped SOL is normalised to native
            SOL after the signature check.
          type: string
        amount:
          description: >-
            The amount being settled, expressed in the smallest unit (e.g.,
            lamports for SOL). Must be greater than 0. Can be provided as a
            string or a number
          oneOf:
            - type: string
              pattern: ^[0-9]+$
            - type: integer
              format: int64
        loan_additional_sol:
          description: >-
            Additional SOL (in lamports) advanced for this settle if the
            one-time wallet is running low. Pass 0 when it already holds enough.
            Can be provided as a string or a number
          oneOf:
            - type: string
              pattern: ^[0-9]+$
            - type: integer
              format: int64
        cleanup_leftover_sol:
          description: >-
            When true, any SOL left in the one-time wallet after this settle
            lands is returned to Vanish's trading accounts and credited to the
            user, and the position is closed. Only set this on the settle that
            fully closes the position - a partial withdrawal still needs the
            remaining SOL.
          type: boolean
        main_tx:
          description: >-
            Serialized or encoded transaction data carrying your own withdraw or
            close instructions. The transaction must be provided unsigned, with
            the one-time wallet address set as the signer.
          type: string
        timestamp:
          description: >-
            Unix timestamp of when the settle was initiated (in milliseconds).
            Must be within 10 minutes of server time. Can be provided as a
            string or a number
          oneOf:
            - type: string
              pattern: ^[0-9]+$
            - type: integer
              format: int64
        user_signature:
          description: >-
            A digital signature of 'By signing, I hereby agree to Vanish's Terms
            of Service and agree to be bound by them
            (docs.vanish.trade/legal/TOS)


            Details:
            settle:{smart_wallet_id}:{token_address}:{amount}:{loan_additional_sol}:{cleanup_leftover_sol}:{timestamp}',
            signed by the user's wallet.
          type: string
    BorrowActionResponse:
      required:
        - action_id
        - tx_id
      type: object
      properties:
        action_id:
          description: Identifier of this lending or settle action.
          type: integer
          example: 88213
        tx_id:
          description: Transaction signature of the action. Poll it via /borrow/commit.
          type: string
        transaction:
          description: >-
            Base64-encoded signed transaction for you to broadcast. Null when
            Vanish submitted a Jito bundle instead; always populated for settle.
          type: string
          nullable: true
        jito_bundle_id:
          description: >-
            If the wrapped transaction was too large for a single transaction
            and Vanish submitted a two-transaction Jito bundle, its bundle ID;
            otherwise null. When set, there is nothing for you to broadcast.
            Always null for settle.
          type: string
          nullable: true
    BorrowError:
      required:
        - error
      type: object
      properties:
        error:
          description: >-
            The error code or short description. Endpoint errors use the HTTP
            status text (for example '400 Bad Request'); errors raised by the
            API key middleware and the rate limiter carry the description here
            instead.
          type: string
        message:
          description: >-
            The specific reason for the failure. Null on a signature
            verification failure, and absent entirely on API key and rate limit
            errors - check for the presence of this field rather than assuming
            every error body has the same shape.
          type: string
          nullable: true
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````