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

# AAVE Leverage Long/Short

> Execute an Aave looping strategy that involves repeated supply and borrow
operations.

This endpoint creates a multicall transaction that performs a series of operations:
1. Approves and supplies initial token
2. For each loop:
    - Borrows another token
    - Swaps borrowed token back to supply token
    - Supplies the swapped tokens

The transaction must be authorized using the /authorization endpoint to prevent replay attacks.



## OpenAPI

````yaml /v1/combined_spec.json post /v1/transaction_bundler/aave/loop
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:
  /v1/transaction_bundler/aave/loop:
    post:
      tags:
        - Transaction Bundler
      summary: AAVE Leverage Long/Short
      description: >-
        Execute an Aave looping strategy that involves repeated supply and
        borrow

        operations.


        This endpoint creates a multicall transaction that performs a series of
        operations:

        1. Approves and supplies initial token

        2. For each loop:
            - Borrows another token
            - Swaps borrowed token back to supply token
            - Supplies the swapped tokens

        The transaction must be authorized using the /authorization endpoint to
        prevent replay attacks.
      operationId: v1_transaction_bundler_aave_loop
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AaveLoopRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/BundlerTransactionResponse'
                  - $ref: '#/components/schemas/SafeTransactionResponse'
                title: Response V1 Transaction Bundler Aave Loop
        '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.transaction_bundler.transaction_bundler_aave_loop(chain=models.AaveLoopRequestChain.ARBITRUM, sender="0x29F20a192328eF1aD35e1564aBFf4Be9C5ce5f7B", collateral_token="USDC", borrow_token="WETH", initial_collateral_amount="1000", multiplier="2.5", max_slippage_percent="0.5", loan_to_value="60", estimate_gas=True, signed_authorization={
                    "nonce": 1000,
                    "address": "0xcA11bde05977b3631167028862bE2a173976CA11",
                    "chain_id": 42161,
                    "r": "0x5f9f3f3226ac91bc01a72dd117141f6c6de1ed30d3af9f95c3423316dc21d615",
                    "s": "0x78f7982ede9dabc53d7153974c5692fda8a21fc73bdafc42aaf135505e22817c",
                    "y_parity": 0,
                }, is_account_abstraction=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.transactionBundler.transactionBundlerAaveLoop({
                chain: "arbitrum",
                sender: "0x29F20a192328eF1aD35e1564aBFf4Be9C5ce5f7B",
                estimateGas: true,
                signedAuthorization: {
                  nonce: 1000,
                  address: "0xcA11bde05977b3631167028862bE2a173976CA11",
                  chainId: 42161,
                  r: "0x5f9f3f3226ac91bc01a72dd117141f6c6de1ed30d3af9f95c3423316dc21d615",
                  s: "0x78f7982ede9dabc53d7153974c5692fda8a21fc73bdafc42aaf135505e22817c",
                  yParity: 0,
                },
                collateralToken: "USDC",
                borrowToken: "WETH",
                initialCollateralAmount: "1000",
                multiplier: "2.5",
                maxSlippagePercent: "0.5",
                loanToValue: "60",
                isAccountAbstraction: false,
              });

              console.log(result);
            }

            run();
components:
  schemas:
    AaveLoopRequest:
      properties:
        chain:
          type: string
          enum:
            - arbitrum
            - base
            - ethereum
          title: Chain
          default: arbitrum
          examples:
            - arbitrum
        sender:
          type: string
          title: Sender
          description: The address of the transaction sender.
          examples:
            - '0x29F20a192328eF1aD35e1564aBFf4Be9C5ce5f7B'
          default: '0x29F20a192328eF1aD35e1564aBFf4Be9C5ce5f7B'
        estimate_gas:
          type: boolean
          title: Estimate Gas
          description: >-
            Determines whether to estimate gas costs for transactions, also
            verifying that the transaction can be successfully executed.
          default: true
          examples:
            - true
        signed_authorization:
          anyOf:
            - $ref: '#/components/schemas/SignedAuthorization'
            - type: 'null'
          description: >-
            EIP-7702 authorization. Required when `is_account_abstraction` is
            False.
          examples:
            - address: '0xcA11bde05977b3631167028862bE2a173976CA11'
              chainId: 42161
              nonce: 1000
              r: >-
                0x5f9f3f3226ac91bc01a72dd117141f6c6de1ed30d3af9f95c3423316dc21d615
              s: >-
                0x78f7982ede9dabc53d7153974c5692fda8a21fc73bdafc42aaf135505e22817c
              yParity: 0
          default:
            address: '0xcA11bde05977b3631167028862bE2a173976CA11'
            chainId: 42161
            nonce: 1000
            r: '0x5f9f3f3226ac91bc01a72dd117141f6c6de1ed30d3af9f95c3423316dc21d615'
            s: '0x78f7982ede9dabc53d7153974c5692fda8a21fc73bdafc42aaf135505e22817c'
            yParity: 0
        collateral_token:
          type: string
          title: Token
          description: Symbol or address of token to supply to Aave..
          examples:
            - USDC
            - WETH
          default: USDC
        borrow_token:
          type: string
          title: Token
          description: Symbol or address of token to borrow from Aave..
          examples:
            - WETH
            - USDC
          default: WETH
        initial_collateral_amount:
          anyOf:
            - type: number
              exclusiveMinimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Initial Collateral Amount
          description: Amount of collateral token to supply to Aave
          examples:
            - '1000'
            - '1000000'
          default: '1000'
        multiplier:
          anyOf:
            - type: number
              exclusiveMinimum: 1
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Multiplier
          description: >-
            Leverage multiplier. Total loop collateral will be calculated as
            `multiplier` x `initial_collateral_amount`
          examples:
            - '2.5'
            - '3.8'
            - '4.1'
          default: '2.5'
        max_slippage_percent:
          anyOf:
            - type: number
              maximum: 100
              exclusiveMinimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Max Slippage Percent
          description: Maximum allowed slippage for token swaps in percentage
          examples:
            - 2.5
            - 0.5
            - 10
          default: '0.5'
        loan_to_value:
          anyOf:
            - type: number
              maximum: 100
              exclusiveMinimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Loan To Value
          description: Loan To Value percentage of the loop
          examples:
            - 20.5
            - 50.6
            - 70
          default: '60'
        emode_category:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
          title: Emode Category
          description: >-
            Aave E-Mode category ID to set before executing the loop. If not
            provided, E-Mode will not be changed.
          examples:
            - 0
            - 1
            - 2
        is_account_abstraction:
          type: boolean
          title: Is Account Abstraction
          description: Whether to use account abstraction for the transaction.
          default: false
          examples:
            - true
            - false
        account_owner:
          anyOf:
            - type: string
            - type: 'null'
          title: Account Owner
          description: >-
            The owner address of the smart account (Safe). Required when
            `is_account_abstraction` is True. This address will be used as the
            'from' address when building the execTransaction call.
          examples:
            - '0x06A9aF046187895AcFc7258450B15397CAc67400'
      type: object
      required:
        - chain
        - sender
        - collateral_token
        - borrow_token
        - initial_collateral_amount
        - multiplier
        - max_slippage_percent
        - loan_to_value
      title: AaveLoopRequest
      description: Request model for executing an Aave loop strategy.
      default:
        chain: arbitrum
        sender: '0x29F20a192328eF1aD35e1564aBFf4Be9C5ce5f7B'
        estimate_gas: true
        signed_authorization:
          address: '0xcA11bde05977b3631167028862bE2a173976CA11'
          chainId: 42161
          nonce: 1000
          r: '0x5f9f3f3226ac91bc01a72dd117141f6c6de1ed30d3af9f95c3423316dc21d615'
          s: '0x78f7982ede9dabc53d7153974c5692fda8a21fc73bdafc42aaf135505e22817c'
          yParity: 0
        collateral_token: USDC
        borrow_token: WETH
        initial_collateral_amount: '1000'
        multiplier: '2.5'
        max_slippage_percent: '0.5'
        loan_to_value: '60'
        is_account_abstraction: false
      required_allowances: []
    BundlerTransactionResponse:
      properties:
        transaction:
          $ref: '#/components/schemas/UnsignedMulticallTransaction'
          description: >-
            The unsigned multicall transaction data. User must sign and
            broadcast to network.
      type: object
      required:
        - transaction
      title: BundlerTransactionResponse
    SafeTransactionResponse:
      properties:
        transaction:
          $ref: '#/components/schemas/SafeTransactionParams'
          description: >-
            Safe transaction parameters. Sign safeTxHash and propose to Safe
            Transaction Service.
      type: object
      required:
        - transaction
      title: SafeTransactionResponse
      description: Response containing Safe transaction parameters for multi-sig proposal.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SignedAuthorization:
      properties:
        nonce:
          type: integer
          title: Nonce
          description: The nonce of the authorization
          examples:
            - 1000
        address:
          type: string
          title: Address
          description: The address of the authorization
          examples:
            - '0xcA11bde05977b3631167028862bE2a173976CA11'
        chainId:
          type: integer
          title: Chainid
          description: The chain ID
          examples:
            - 42161
        r:
          anyOf:
            - type: integer
            - type: string
          title: R
          description: The r value of the signature
          examples:
            - '0x5f9f3f3226ac91bc01a72dd117141f6c6de1ed30d3af9f95c3423316dc21d615'
        s:
          anyOf:
            - type: integer
            - type: string
          title: S
          description: The s value of the signature
          examples:
            - '0x78f7982ede9dabc53d7153974c5692fda8a21fc73bdafc42aaf135505e22817c'
        yParity:
          type: integer
          title: Yparity
          description: The y-parity of the signature (0 or 1)
          examples:
            - 0
      type: object
      required:
        - nonce
        - address
        - chainId
        - r
        - s
        - yParity
      title: SignedAuthorization
    UnsignedMulticallTransaction:
      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
        authorizationList:
          items:
            $ref: '#/components/schemas/SignedAuthorization'
          type: array
          title: Authorizationlist
          description: EIP-7702 authorization
          default: []
      type: object
      required:
        - chainId
        - data
        - from
        - gas
        - to
        - value
        - nonce
        - maxFeePerGas
        - maxPriorityFeePerGas
      title: UnsignedMulticallTransaction
      example:
        chainId: '0x2105'
        data: >-
          0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d
        from: '0x4A83b4413CF41C3244027e1590E35a0F48403F0c'
        gas: '0x7a120'
        maxFeePerGas: '0x59682f00'
        maxPriorityFeePerGas: '0x3b9aca00'
        nonce: '0x5'
        to: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67'
        value: '0x0'
    SafeTransactionParams:
      properties:
        to:
          type: string
          title: To
          description: Destination address (MultiSend contract for bundled txs)
          examples:
            - '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761'
        value:
          type: integer
          title: Value
          description: ETH value to send
          examples:
            - 0
        data:
          type: string
          title: Data
          description: Encoded transaction data
          examples:
            - 0x8d80ff0a...
        operation:
          type: integer
          title: Operation
          description: 0 = Call, 1 = DelegateCall
          examples:
            - 1
        safeTxGas:
          type: integer
          title: Safetxgas
          description: Gas for the Safe transaction execution
          examples:
            - 0
        baseGas:
          type: integer
          title: Basegas
          description: Base gas for the transaction
          examples:
            - 0
        gasPrice:
          type: integer
          title: Gasprice
          description: Gas price for refund calculation
          examples:
            - 0
        gasToken:
          type: string
          title: Gastoken
          description: Token address for gas refund (0x0 for ETH)
          examples:
            - '0x0000000000000000000000000000000000000000'
        refundReceiver:
          type: string
          title: Refundreceiver
          description: Address to receive gas refund
          examples:
            - '0x0000000000000000000000000000000000000000'
        nonce:
          type: integer
          title: Nonce
          description: Safe transaction nonce
          examples:
            - 42
        safeTxHash:
          type: string
          title: Safetxhash
          description: EIP-712 hash of the Safe transaction (sign this with your wallet)
          examples:
            - 0xabc123...
      type: object
      required:
        - to
        - value
        - data
        - operation
        - safeTxGas
        - baseGas
        - gasPrice
        - gasToken
        - refundReceiver
        - nonce
        - safeTxHash
      title: SafeTransactionParams
      description: >-
        Parameters for proposing a transaction to a Safe multi-sig wallet.


        This model is used when the Safe has threshold > 1 or when the user
        wants to propose

        a transaction for other owners to sign via the Safe Transaction Service.
    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
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your Compass API Key. Get your key
        [here](https://www.compasslabs.ai/dashboard).

````