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

# Prepare an Aave position unwind

> Returns an **unsigned** `Pool.withdraw` transaction that exits an Aave position straight to the project's deposit address, so the existing deposit pipeline ingests the proceeds. Nothing is executed: the holding EOA owns the aTokens, so only it can authorise the withdraw, and the service holds no key on this path. The amount is capped server-side against Aave's full withdraw validation and is refused outright if the proceeds would fall foul of the project's deposit policy — that check happens here because this is the last point before an irreversible signature.



## OpenAPI

````yaml https://raw.githubusercontent.com/rhinestonewtf/openapi/refs/heads/main/deposit-service.json post /positions/{address}/unwind
openapi: 3.1.0
info:
  title: Deposit Service API
  version: 1.0.0
  description: >-
    Cross-chain deposit processing service with automatic token bridging and gas
    sponsorship
servers:
  - url: https://v1.orchestrator.rhinestone.dev/deposit-processor
security: []
paths:
  /positions/{address}/unwind:
    post:
      tags:
        - Utilities
      summary: Prepare an Aave position unwind
      description: >-
        Returns an **unsigned** `Pool.withdraw` transaction that exits an Aave
        position straight to the project's deposit address, so the existing
        deposit pipeline ingests the proceeds. Nothing is executed: the holding
        EOA owns the aTokens, so only it can authorise the withdraw, and the
        service holds no key on this path. The amount is capped server-side
        against Aave's full withdraw validation and is refused outright if the
        proceeds would fall foul of the project's deposit policy — that check
        happens here because this is the last point before an irreversible
        signature.
      parameters:
        - schema:
            type: string
            pattern: ^0x[a-fA-F0-9]{40}$
            description: >-
              The EOA holding the position. It signs and sends the returned
              transaction.
            example: '0x742d35Cc6634C0532925a3b844Bc9e7595f5bE91'
          required: true
          description: >-
            The EOA holding the position. It signs and sends the returned
            transaction.
          name: address
          in: path
        - schema:
            type: string
            description: API key for authentication
            example: your-api-key
          required: true
          description: API key for authentication
          name: x-api-key
          in: header
        - schema:
            type: string
            pattern: ^\d{4}-\d{2}\.[a-z0-9]+$
            description: >-
              API version identifier (e.g. "2026-04.amazon"). Optional today,
              will become required in a future release.
            example: 2026-04.amazon
          required: false
          description: >-
            API version identifier (e.g. "2026-04.amazon"). Optional today, will
            become required in a future release.
          name: x-api-version
          in: header
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PrepareUnwindRequestBody'
      responses:
        '200':
          description: Unsigned withdraw transaction
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PrepareUnwindResponse'
        '400':
          description: >-
            Invalid request, unauthorized, no such position, an amount above the
            withdrawable maximum, or proceeds the deposit policy would reject
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: >-
            API key lacks the required deposits scope, or the account belongs to
            another project
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    PrepareUnwindRequestBody:
      type: object
      properties:
        account:
          type: string
          pattern: ^0x[a-fA-F0-9]{40}$
          description: >-
            The registered deposit account the proceeds go to. The recipient is
            resolved from this server-side; it is never taken from the request
            directly.
        market:
          type: string
          pattern: ^0x[a-fA-F0-9]{40}$
          description: >-
            The Aave market's Pool address, as returned in a position's
            `market.address`. Required rather than inferred, because a chain can
            host several markets.
        chainId:
          type: integer
          exclusiveMinimum: 0
          example: 8453
        asset:
          type: string
          pattern: ^0x[a-fA-F0-9]{40}$
          description: The supplied underlying token to withdraw
        amount:
          type: string
          pattern: ^\d+$
          description: >-
            Base units to withdraw. Omit for the largest amount currently
            permitted. An amount above that maximum is rejected rather than
            silently reduced.
          example: '1000000000000000000'
      required:
        - account
        - market
        - chainId
        - asset
    PrepareUnwindResponse:
      type: object
      properties:
        transaction:
          type: object
          properties:
            to:
              type: string
            data:
              type: string
            value:
              type: string
            chainId:
              type: number
          required:
            - to
            - data
            - value
            - chainId
          description: >-
            Unsigned transaction for the holding EOA to sign and send. The
            backend never executes it — the EOA holds the aTokens, so only it
            can authorise the withdraw.
        amount:
          type: string
          description: Base units the transaction will withdraw
        isFullExit:
          type: boolean
          description: >-
            True when the whole position is being withdrawn, in which case the
            calldata uses the max-uint sentinel so interest accrued before the
            transaction lands is swept too.
        recipient:
          type: string
          description: >-
            The deposit address the proceeds are sent to, resolved from the
            registered account. Echoed so it is auditable.
        constraints:
          type: array
          items:
            type: string
          description: >-
            Why the amount is below the supplied balance, if it is. Empty for an
            unconstrained full exit.
      required:
        - transaction
        - amount
        - isFullExit
        - recipient
        - constraints
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
        details:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
              path:
                type: array
                items:
                  anyOf:
                    - type: string
                    - type: number
              code:
                type: string
            required:
              - message
      required:
        - error

````