Leverage lending (“looping”) lets you boost yield by borrowing against your deposit, swapping the loan, and re-depositing — all to multiply exposure. With Compass API Python SDK, you can loop in one atomic call, no Solidity, no manual steps, minimal gas.

Example

Aave Looping Diagram

In this example, you’re depositing USDC, borrowing ETH, swapping it back into USDC, and re-supplying — on repeat — to achieve a target leverage (e.g. 2.19x). Compass bundles all of this into one atomic transaction.

This illustration demonstrates AAVE looping strategy with the following parameters, assuming that the price of ETH is 2333 USDC:

  • Collateral Asset: USDC
  • Loan Asset: ETH
  • Initial Collateral Amount: 1000 USDC
  • Loan to Value Ratio: 70%
  • Leverage: 2.19x

The API will figure out the optimal values for each loop and automate all actions.

Prerequisites

1

Install Dependencies

Install the required packages:

pip install compass-api-sdk python-dotenv web3
2

Set Environment Variables

Create a .env file in your project root:

# .env
PRIVATE_KEY="your_wallet_private_key"
RPC_URL="your_ethereum_rpc_url"
COMPASS_API_KEY="your_compass_api_key"

Implementation Guide

1

Initialize SDK, Web3, and Account

This step loads your environment variables, sets up the Web3 provider, and initializes your account and the Compass API SDK.

2

Get and sign authorization for transaction batching

Before you can execute AAVE looping, you need to get an authorization from the Compass API and sign it with your private key. This ensures only you can execute the batch.

3

Configure the AAVE looping transaction

Configure the AAVE looping strategy and prepare the transaction using the Compass API SDK.

4

Sign and broadcast the transaction

Sign the returned transaction with your private key and broadcast it to the network. This is the final step to actually send your AAVE looping transaction to Ethereum.

Full Code

Here is the full script from the tutorial. Copy and paste in your code editor and play around!

Understanding the Parameters

Let’s break down the key parameters for the AAVE looping strategy:

AAVE Loop Parameters

  • collateral_token: The token you want to supply as collateral (e.g., “USDC”, “WETH”, “WBTC”)
  • borrow_token: The token you want to borrow (e.g., “WETH”, “USDC”)
  • initial_collateral_amount: The amount of collateral token to supply initially
  • multiplier: The leverage multiplier (e.g., 2.0 means double exposure)
  • max_slippage_percent: Maximum allowed slippage for token swaps (1-100)
  • loan_to_value: The loan-to-value ratio in percentage (0-100)

The loan-to-value (LTV) ratio determines how much you can borrow against your collateral. For example, if LTV is 80%, you can borrow up to 80% of your collateral’s value. Be cautious with high LTV ratios as they increase liquidation risk.

The maximum possible multiplier is determined by the formula: 1 / (1 - loan_to_value/100). For example, with an LTV of 80%, the maximum multiplier would be 1 / (1 - 80/100) = 1 / 0.2 = 5. This represents the theoretical maximum leverage possible at that LTV ratio.

Example Strategies

Here are some example configurations for different risk appetites:

Conservative Strategy

looping_tx = sdk.transaction_batching.aave_loop(
    # ... other parameters ...
    collateral_token="USDC",
    borrow_token="WETH",
    initial_collateral_amount=1000,
    multiplier=1.5,
    max_slippage_percent=0.5,
    loan_to_value=65
)

Moderate Strategy

looping_tx = sdk.transaction_batching.aave_loop(
    # ... other parameters ...
    collateral_token="WETH",
    borrow_token="USDC",
    initial_collateral_amount=1,
    multiplier=2.0,
    max_slippage_percent=1,
    loan_to_value=75
)

Aggressive Strategy

looping_tx = sdk.transaction_batching.aave_loop(
    # ... other parameters ...
    collateral_token="WBTC",
    borrow_token="USDC",
    initial_collateral_amount=0.1,
    multiplier=2.5,
    max_slippage_percent=1,
    loan_to_value=80
)

Risk Considerations

When implementing AAVE looping strategies, consider the following risks:

  1. Liquidation Risk: Higher LTV ratios increase the risk of liquidation if the collateral value drops
  2. Interest Rate Risk: Borrowing rates may increase, affecting the profitability of your position
  3. Slippage Risk: Large trades may experience significant slippage, especially in volatile markets
  4. Smart Contract Risk: Always verify contract addresses and permissions

Resources