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

# Rebalance the leveraged credit book

> Rebalance the leveraged credit book in ONE atomic transaction.

List only the positions to change — anything not named is left untouched;
remove a position with close=true. Each target states an end state:
target_equity_usd (net USD committed) × target_multiplier.

Releasing targets run first (each unwind/delever frees tokens into the Credit
Account), the freed tokens are then routed by swaps at a GUARANTEED minimum
output (enforced on-chain), and consuming targets run last — so moving a
levered position between markets, token pairs, or protocols (Aave ↔ Morpho) is
simply a close plus an open in the same transaction.

Net book growth is funded from the Credit Account's existing idle balance —
fund it first via /v2/credit/transfer; a net release stays in the Credit
Account as idle balance. Any swap surplus above the guaranteed floors also
stays in the Credit Account (preview.estimated_max_dust) — recoverable, never
lost.

A book already at its target returns transaction: null with the preview — the
call is idempotent and safe to drive from a converge-to-target loop.

A rebalance too large for one transaction is rejected with a 422 — split it
into two calls. Every deleveraging step keeps the health factor ≥ 1.02 and
every leveraging step respects the protocol's borrow limits; Aave targets share
one account-level health factor, which the preview reports.

Dust tails and routing swaps below the swap router's minimum routable size do
not fail the call: a releasing target that cannot fully unwind returns its
honest residual in the preview, and an unroutable routing swap is skipped
(its uncovered amount only 422s the rebalance if it breaches the funding
tolerance).

For protocol=MORPHO pass a market_id from /v2/credit/morpho_markets; inspect the
current book via /v2/credit/looped_positions.



## OpenAPI

````yaml /v2/combined_spec.json post /v2/credit/rebalance
openapi: 3.1.0
info:
  title: Compass API
  description: Compass Labs DeFi API
  version: 0.0.1
servers:
  - url: https://api.compasslabs.ai
    description: Production server
security:
  - ApiKeyAuth: []
paths:
  /v2/credit/rebalance:
    post:
      tags:
        - Credit
      summary: Rebalance the leveraged credit book
      description: >-
        Rebalance the leveraged credit book in ONE atomic transaction.


        List only the positions to change — anything not named is left
        untouched;

        remove a position with close=true. Each target states an end state:

        target_equity_usd (net USD committed) × target_multiplier.


        Releasing targets run first (each unwind/delever frees tokens into the
        Credit

        Account), the freed tokens are then routed by swaps at a GUARANTEED
        minimum

        output (enforced on-chain), and consuming targets run last — so moving a

        levered position between markets, token pairs, or protocols (Aave ↔
        Morpho) is

        simply a close plus an open in the same transaction.


        Net book growth is funded from the Credit Account's existing idle
        balance —

        fund it first via /v2/credit/transfer; a net release stays in the Credit

        Account as idle balance. Any swap surplus above the guaranteed floors
        also

        stays in the Credit Account (preview.estimated_max_dust) — recoverable,
        never

        lost.


        A book already at its target returns transaction: null with the preview
        — the

        call is idempotent and safe to drive from a converge-to-target loop.


        A rebalance too large for one transaction is rejected with a 422 — split
        it

        into two calls. Every deleveraging step keeps the health factor ≥ 1.02
        and

        every leveraging step respects the protocol's borrow limits; Aave
        targets share

        one account-level health factor, which the preview reports.


        Dust tails and routing swaps below the swap router's minimum routable
        size do

        not fail the call: a releasing target that cannot fully unwind returns
        its

        honest residual in the preview, and an unroutable routing swap is
        skipped

        (its uncovered amount only 422s the rebalance if it breaches the funding

        tolerance).


        For protocol=MORPHO pass a market_id from /v2/credit/morpho_markets;
        inspect the

        current book via /v2/credit/looped_positions.
      operationId: v2_credit_rebalance
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreditRebalanceRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreditRebalanceResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: python
          label: Python (SDK)
          source: |-
            from compass_api_sdk import CompassAPI, models


            with CompassAPI(
                api_key_auth="<YOUR_API_KEY_HERE>",
            ) as compass_api:

                res = compass_api.credit.credit_rebalance(owner="0x4D3c07d1db7E4A9E44285fae9810d6549655bc74", chain=models.Chain.ETHEREUM, targets=[
                    {
                        "protocol": models.CreditProtocol.AAVE,
                        "collateral_token": "WETH",
                        "borrow_token": "USDC",
                        "target_multiplier": 2,
                    },
                ], max_slippage_percent=0.5, gas_sponsorship=False)

                # Handle response
                print(res)
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { CompassApiSDK } from "@compass-labs/api-sdk";

            const compassApiSDK = new CompassApiSDK({
              apiKeyAuth: "<YOUR_API_KEY_HERE>",
            });

            async function run() {
              const result = await compassApiSDK.credit.creditRebalance({
                owner: "0x4D3c07d1db7E4A9E44285fae9810d6549655bc74",
                chain: "ethereum",
                targets: [
                  {
                    protocol: "AAVE",
                    collateralToken: "WETH",
                    borrowToken: "USDC",
                    targetMultiplier: 2,
                  },
                ],
                maxSlippagePercent: 0.5,
                gasSponsorship: false,
              });

              console.log(result);
            }

            run();
components:
  schemas:
    CreditRebalanceRequest:
      properties:
        owner:
          type: string
          title: Owner
          description: The address that owns the Credit Account.
          default: '0x4D3c07d1db7E4A9E44285fae9810d6549655bc74'
          examples:
            - '0x4D3c07d1db7E4A9E44285fae9810d6549655bc74'
        chain:
          $ref: '#/components/schemas/Chain'
          description: Blockchain network.
          default: ethereum
          examples:
            - ethereum
        targets:
          items:
            $ref: '#/components/schemas/RebalanceTarget'
          type: array
          minItems: 1
          title: Targets
          description: >-
            The positions to change. Scoped: only positions named here are
            touched; any position not listed is left untouched.
          default:
            - borrow_token: USDC
              collateral_token: WETH
              protocol: AAVE
              target_multiplier: 2
          examples:
            - - borrow_token: USDC
                collateral_token: WETH
                protocol: AAVE
                target_multiplier: 2
        max_slippage_percent:
          anyOf:
            - type: number
              maximum: 10
              exclusiveMinimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Max Slippage Percent
          description: >-
            Request-level per-swap slippage tolerance in percent (including
            routing swaps). A per-target max_slippage_percent overrides it where
            set.
          default: '0.5'
          examples:
            - 0.3
            - 0.5
        gas_sponsorship:
          type: boolean
          title: Gas Sponsorship
          description: >-
            If true, returns EIP-712 typed data for gas-sponsored execution
            instead of an unsigned transaction.
          default: false
          examples:
            - false
      type: object
      required:
        - owner
        - chain
        - targets
      title: CreditRebalanceRequest
      description: >-
        Rebalance one or more Credit Account positions to their named end-states
        —

        lever up or down, grow or shrink equity, open a new position, close an
        existing

        one, or migrate (close one and open another) — all in ONE atomic
        transaction

        from the Credit Account.
      default:
        owner: '0x4D3c07d1db7E4A9E44285fae9810d6549655bc74'
        chain: ethereum
        max_slippage_percent: 0.5
        gas_sponsorship: false
        targets:
          - borrow_token: USDC
            collateral_token: WETH
            protocol: AAVE
            target_multiplier: 2
    CreditRebalanceResponse:
      properties:
        transaction:
          anyOf:
            - $ref: '#/components/schemas/UnsignedTransaction'
            - type: 'null'
          description: >-
            Unsigned transaction for direct execution by the owner. Present when
            gas_sponsorship=false. Null when the book is already at its target —
            nothing to execute.
        eip_712:
          anyOf:
            - $ref: '#/components/schemas/BatchedSafeOperationsResponse-Output'
            - type: 'null'
          description: >-
            EIP-712 typed data for gas-sponsored execution. Present when
            gas_sponsorship=true.
        preview:
          $ref: '#/components/schemas/CreditRebalancePreview'
          description: Projected end state, computed on guaranteed swap floors.
      type: object
      required:
        - preview
      title: CreditRebalanceResponse
      description: The atomic rebalance transaction plus its guaranteed-floor preview.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    Chain:
      type: string
      enum:
        - base
        - ethereum
        - arbitrum
        - hyperevm
        - tempo
        - bsc
      title: Chain
      description: The chain to use.
    RebalanceTarget:
      properties:
        protocol:
          $ref: '#/components/schemas/CreditProtocol'
          description: >-
            Lending protocol of this position: AAVE or MORPHO. EULER rebalancing
            is not available yet.
          default: AAVE
        market_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Market Id
          description: >-
            Morpho only: the bytes32 market id (from /v2/credit/morpho_markets).
            Required when protocol=MORPHO.
        collateral_token:
          type: string
          title: Token
          description: >-
            Token supplied as collateral for this position. For MORPHO it must
            be the market's collateral token.
          examples:
            - wstETH
            - WETH
        borrow_token:
          type: string
          title: Token
          description: >-
            Token borrowed against the collateral for this position. For MORPHO
            it must be the market's loan token.
          examples:
            - WETH
            - USDC
        target_equity_usd:
          anyOf:
            - type: number
              exclusiveMinimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Target Equity Usd
          description: >-
            SIZE knob: the net value (collateral − debt, in USD) to commit to
            this position; total collateral ≈ target_equity_usd ×
            target_multiplier. To remove a position use close=true, never
            target_equity_usd=0.
          examples:
            - 10000
        target_multiplier:
          anyOf:
            - type: number
              minimum: 1
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Target Multiplier
          description: >-
            LEVERAGE knob: total collateral exposure ÷ equity. 1 means unlevered
            supplied collateral. The protocol maximum is enforced when the plan
            is built.
          examples:
            - 2
            - 3
        close:
          type: boolean
          title: Close
          description: >-
            If true, fully unwind this position: the debt is cleared exactly
            (accrued interest included) and the pair collateral is returned to
            the Credit Account.
          default: false
        max_slippage_percent:
          anyOf:
            - type: number
              maximum: 10
              exclusiveMinimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Max Slippage Percent
          description: >-
            Per-target override of the request-level per-swap slippage tolerance
            in percent.
          examples:
            - 0.3
            - 0.5
      type: object
      required:
        - collateral_token
        - borrow_token
      title: RebalanceTarget
      description: >-
        The desired end-state of ONE position in the Credit Account.


        Scoped-declarative: only positions named in ``targets`` are touched;
        anything

        unlisted is left as-is. Set ``close=true`` to fully unwind a position —
        never

        ``target_equity_usd=0``.
    UnsignedTransaction:
      properties:
        chainId:
          type: string
          title: Chainid
          description: The chain id of the transaction
        data:
          type: string
          title: Data
          description: The data of the transaction
        from:
          type: string
          title: From
          description: The sender of the transaction
        gas:
          anyOf:
            - type: string
            - type: 'null'
          title: Gas
          description: The gas of the transaction
        to:
          type: string
          title: To
          description: The recipient of the transaction
        value:
          type: string
          title: Value
          description: The value of the transaction
        nonce:
          type: string
          title: Nonce
          description: The nonce of the address
        maxFeePerGas:
          type: string
          title: Maxfeepergas
          description: The max fee per gas of the transaction
        maxPriorityFeePerGas:
          type: string
          title: Maxpriorityfeepergas
          description: The max priority fee per gas of the transaction
      type: object
      required:
        - chainId
        - data
        - from
        - gas
        - to
        - value
        - nonce
        - maxFeePerGas
        - maxPriorityFeePerGas
      title: UnsignedTransaction
      example:
        chainId: '0x2105'
        data: >-
          0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d
        from: '0x4A83b4413CF41C3244027e1590E35a0F48403F0c'
        gas: '0x7a120'
        maxFeePerGas: '0x59682f00'
        maxPriorityFeePerGas: '0x3b9aca00'
        nonce: '0x5'
        to: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67'
        value: '0x0'
    BatchedSafeOperationsResponse-Output:
      properties:
        domain:
          $ref: >-
            #/components/schemas/compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Domain
          description: EIP-712 domain separator
        types:
          $ref: >-
            #/components/schemas/compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Types
          description: EIP-712 type definitions
        primaryType:
          type: string
          const: SafeTx
          title: Primarytype
          description: Primary type for the structured data
        message:
          $ref: '#/components/schemas/SafeTxMessage'
          description: Safe transaction message data
      type: object
      required:
        - domain
        - types
        - primaryType
        - message
      title: BatchedSafeOperationsResponse
      description: Response containing EIP-712 typed data for Safe transaction signing.
      example:
        domain:
          chainId: 8453
          verifyingContract: '0x6B90E8B4E3E971E74C1A47a3a20976377E2dB4b1'
        message:
          baseGas: '0'
          data: >-
            0x8d80ff0a0000000000000000000000000000000000000000000000000000000000000020
          gasPrice: '0'
          gasToken: '0x0000000000000000000000000000000000000000'
          nonce: '7'
          operation: 1
          refundReceiver: '0x0000000000000000000000000000000000000000'
          safeTxGas: '0'
          to: '0x93C23AAE4793C14D6DF35D2A2A2234204e1559dA'
          value: '0'
        primaryType: SafeTx
        types:
          EIP712Domain:
            - name: chainId
              type: uint256
            - name: verifyingContract
              type: address
          SafeTx:
            - name: to
              type: address
            - name: value
              type: uint256
            - name: data
              type: bytes
            - name: operation
              type: uint8
            - name: safeTxGas
              type: uint256
            - name: baseGas
              type: uint256
            - name: gasPrice
              type: uint256
            - name: gasToken
              type: address
            - name: refundReceiver
              type: address
            - name: nonce
              type: uint256
    CreditRebalancePreview:
      properties:
        net_equity_moved_usd:
          type: string
          title: Net Equity Moved Usd
          description: >-
            Signed net equity moved: Σ(target − current equity, in USD) over the
            named targets. Positive = net book growth funded from the Credit
            Account's idle balance; negative = surplus equity released to idle.
            Truncated toward zero, so the reported magnitude is never larger
            than the true amount in either sign.
        total_legs:
          type: integer
          title: Total Legs
          description: >-
            Total on-chain legs across the whole transaction, including
            capital-routing swaps. A rebalance too large for one transaction is
            rejected with a 422.
        routing_swaps:
          items:
            $ref: '#/components/schemas/RoutingSwapPreview'
          type: array
          title: Routing Swaps
          description: >-
            The capital-routing swaps that move freed tokens between positions,
            at a guaranteed minimum output enforced on-chain.
          default: []
        estimated_max_dust:
          type: string
          title: Estimated Max Dust
          description: >-
            Upper bound of surplus all swaps (per-target and routing) can leave
            in the Credit Account (sum of each swap's quote minus its guaranteed
            floor). It accumulates in the Credit Account, is recoverable, and is
            never lost.
        aave_account_health_factor:
          anyOf:
            - type: string
            - type: 'null'
          title: Aave Account Health Factor
          description: >-
            Projected account-level Aave health factor after the rebalance —
            Aave collateral is pooled, so this is shared by every Aave target.
            Present whenever the end state holds any Aave collateral or debt;
            null for Morpho-only books. Never overstated at the 1.0 boundary.
        per_target:
          items:
            $ref: '#/components/schemas/RebalanceTargetPreview'
          type: array
          title: Per Target
          description: Per-target end state, in the same order as the request targets.
      additionalProperties: false
      type: object
      required:
        - net_equity_moved_usd
        - total_legs
        - estimated_max_dust
        - per_target
      title: CreditRebalancePreview
      description: >-
        Projected end state of the whole rebalance, computed on GUARANTEED swap
        floors.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    CreditProtocol:
      type: string
      enum:
        - AAVE
        - EULER
        - MORPHO
      title: CreditProtocol
      description: >-
        Which lending protocol a credit action targets.


        ``AAVE`` is the default so existing callers (which never send a
        ``protocol``

        field) keep hitting the unchanged Aave code path. ``EULER`` opts in to
        the

        Euler V2 path, where the market is identified by EVK vault address(es).

        ``MORPHO`` identifies Morpho Blue lending markets (bytes32 market id)
        and is

        currently read-only: positions and market discovery only — transaction

        builders land with the looping work (COM-7106/7107/7108), so transact

        endpoints reject it with a 422.
    compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Domain:
      properties:
        chainId:
          type: integer
          title: Chainid
          description: Chain ID
        verifyingContract:
          type: string
          title: Verifyingcontract
          description: Address of the Product Account
      type: object
      required:
        - chainId
        - verifyingContract
      title: EIP712Domain
      description: The EIP-712 domain separator.
    compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Types:
      properties:
        EIP712Domain:
          items:
            $ref: '#/components/schemas/EIP712DomainField'
          type: array
          title: Eip712Domain
          description: EIP712Domain type definition
        SafeTx:
          items:
            $ref: '#/components/schemas/SafeTxField'
          type: array
          title: Safetx
          description: SafeTx type definition
      type: object
      required:
        - EIP712Domain
        - SafeTx
      title: EIP712Types
      description: The type definitions for EIP-712 structured data.
    SafeTxMessage:
      properties:
        to:
          type: string
          title: To
          description: Destination address
        value:
          type: string
          title: Value
          description: Value in wei as a string
        data:
          type: string
          title: Data
          description: Transaction data as hex string
        operation:
          $ref: '#/components/schemas/OperationType'
          description: Operation type (0=Call, 1=DelegateCall)
        safeTxGas:
          type: string
          title: Safetxgas
          description: Gas for the transaction
        baseGas:
          type: string
          title: Basegas
          description: Base gas costs
        gasPrice:
          type: string
          title: Gasprice
          description: Gas price
        gasToken:
          type: string
          title: Gastoken
          description: Token address for gas payment
        refundReceiver:
          type: string
          title: Refundreceiver
          description: Address to receive gas refund
        nonce:
          type: string
          title: Nonce
          description: Transaction nonce
      type: object
      required:
        - to
        - value
        - data
        - operation
        - safeTxGas
        - baseGas
        - gasPrice
        - gasToken
        - refundReceiver
        - nonce
      title: SafeTxMessage
      description: The message data for the transaction.
    RoutingSwapPreview:
      properties:
        token_in:
          type: string
          title: Token In
          description: Token sold by the Credit Account into this routing swap.
        token_out:
          type: string
          title: Token Out
          description: Token bought and delivered to fund a consuming position.
        amount_in:
          type: string
          title: Amount In
          description: Token-in amount the Credit Account gives up to this swap.
        min_amount_out:
          type: string
          title: Min Amount Out
          description: >-
            Guaranteed minimum output (token-out units), enforced on-chain by
            the swap's minimum-return. Any fill above it stays in the Credit
            Account as recoverable dust.
      additionalProperties: false
      type: object
      required:
        - token_in
        - token_out
        - amount_in
        - min_amount_out
      title: RoutingSwapPreview
      description: >-
        One Phase-B capital-routing swap that moves freed tokens between
        positions.


        Book-level: it is not attributable to a single target.
    RebalanceTargetPreview:
      properties:
        protocol:
          $ref: '#/components/schemas/CreditProtocol'
          description: 'Lending protocol of this position: AAVE or MORPHO.'
        market_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Market Id
          description: 'Morpho only: the bytes32 market id of this position.'
        collateral_token:
          type: string
          title: Collateral Token
          description: >-
            Collateral token address (echoes the request target; joins against
            /v2/credit/looped_positions).
        borrow_token:
          type: string
          title: Borrow Token
          description: Borrow token address (echoes the request target).
        direction:
          $ref: '#/components/schemas/RebalanceDirection'
          description: >-
            What the plan does to this target: open, close, grow, shrink,
            lever_up, lever_down, or noop (already at target).
        legs:
          type: integer
          title: Legs
          description: >-
            On-chain legs planned for this target (loop + unloop iterations); 0
            for a noop.
        unloop_legs:
          items:
            $ref: '#/components/schemas/UnloopLegPreview'
          type: array
          title: Unloop Legs
          description: >-
            Per-iteration unwind breakdown — populated for releasers (close /
            shrink / lever_down).
          default: []
        loop_legs:
          items:
            $ref: '#/components/schemas/LoopLegPreview'
          type: array
          title: Loop Legs
          description: >-
            Per-iteration loop breakdown — populated for consumers (open / grow
            / lever_up).
          default: []
        resulting_collateral:
          type: string
          title: Resulting Collateral
          description: >-
            Guaranteed minimum collateral supplied to this position after the
            rebalance (token units).
        resulting_debt:
          type: string
          title: Resulting Debt
          description: >-
            Projected debt owed by this position after the rebalance
            (borrow-token units); 0 on a close.
        resulting_multiplier:
          type: string
          title: Resulting Multiplier
          description: >-
            Projected leverage of this position after the rebalance; 1 when the
            debt is cleared. Never promises more leverage (or, when
            deleveraging, more deleverage) than is guaranteed.
        resulting_health_factor:
          type: string
          title: Resulting Health Factor
          description: >-
            Projected health factor of this position after the rebalance. Never
            overstated at the 1.0 boundary — a liquidatable position is never
            presented as safe. See health_factor_scope for what it covers.
        health_factor_scope:
          type: string
          enum:
            - market
            - account
          title: Health Factor Scope
          description: >-
            'market' for Morpho (isolated per-market health). 'account' for
            Aave: collateral is pooled, so all collateral backs all debt and
            this health factor is shared by every Aave position on the account.
        estimated_max_dust:
          type: string
          title: Estimated Max Dust
          description: >-
            Upper bound of surplus this target's own swaps can leave in the
            Credit Account (sum of each swap's quote minus its guaranteed
            floor). Routing swaps are counted book-level, not here. It
            accumulates in the Credit Account, is recoverable, and is never
            lost.
      additionalProperties: false
      type: object
      required:
        - protocol
        - collateral_token
        - borrow_token
        - direction
        - legs
        - resulting_collateral
        - resulting_debt
        - resulting_multiplier
        - resulting_health_factor
        - health_factor_scope
        - estimated_max_dust
      title: RebalanceTargetPreview
      description: >-
        Projected end state of ONE named target, computed on guaranteed swap
        floors.
    EIP712DomainField:
      properties:
        name:
          type: string
          title: Name
        type:
          type: string
          title: Type
      type: object
      required:
        - name
        - type
      title: EIP712DomainField
      description: A field in the EIP712Domain type definition.
    SafeTxField:
      properties:
        name:
          type: string
          title: Name
        type:
          type: string
          title: Type
      type: object
      required:
        - name
        - type
      title: SafeTxField
      description: A field in the SafeTx type definition.
    OperationType:
      type: integer
      enum:
        - 0
        - 1
      title: OperationType
      description: Safe operation types.
    RebalanceDirection:
      type: string
      enum:
        - open
        - close
        - grow
        - shrink
        - lever_up
        - lever_down
        - noop
      title: RebalanceDirection
      description: What the plan does to one named target.
    UnloopLegPreview:
      properties:
        withdraw_amount:
          anyOf:
            - type: string
            - type: 'null'
          title: Withdraw Amount
          description: Collateral withdrawn this iteration (token units).
        min_swap_out:
          anyOf:
            - type: string
            - type: 'null'
          title: Min Swap Out
          description: >-
            Guaranteed swap output (borrow-token units) — enforced on-chain by
            the swap's minimum-return. Null on the final collateral sweep leg,
            which does not swap.
        repay_amount:
          anyOf:
            - type: string
            - type: 'null'
          title: Repay Amount
          description: >-
            Debt repaid this iteration (borrow-token units); null on the final
            collateral sweep leg.
        full_repay:
          type: boolean
          title: Full Repay
          description: >-
            True on the closing leg that clears the remaining debt exactly (Aave
            clamps to live debt; Morpho repays the remaining shares).
          default: false
      additionalProperties: false
      type: object
      required:
        - withdraw_amount
      title: UnloopLegPreview
      description: 'One planned unwind iteration: withdraw [+ swap + repay].'
    LoopLegPreview:
      properties:
        supply_amount:
          anyOf:
            - type: string
            - type: 'null'
          title: Supply Amount
          description: Collateral supplied this iteration (token units).
        borrow_amount:
          anyOf:
            - type: string
            - type: 'null'
          title: Borrow Amount
          description: >-
            Loan borrowed this iteration; null on the final supply-only
            iteration.
        min_swap_out:
          anyOf:
            - type: string
            - type: 'null'
          title: Min Swap Out
          description: >-
            Guaranteed swap output (collateral units) — the next iteration's
            supply. Enforced on-chain by the swap's minimum-return.
      additionalProperties: false
      type: object
      required:
        - supply_amount
      title: LoopLegPreview
      description: One planned loop iteration.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your Compass API Key. Get your key
        [here](https://www.compasslabs.ai/dashboard).

````