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.
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:
The API will figure out the optimal values for each loop and automate all actions.
Install Dependencies
Install the required packages:
Set Environment Variables
Create a .env
file in your project root:
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.
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.
Configure the AAVE looping transaction
Configure the AAVE looping strategy and prepare the transaction using the Compass API SDK.
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.
Here is the full script from the tutorial. Copy and paste in your code editor and play around!
Let’s break down the key parameters for the AAVE looping strategy:
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.
Here are some example configurations for different risk appetites:
When implementing AAVE looping strategies, consider the following risks:
Access detailed API documentation and references
Learn more about AAVE’s lending protocol
View more code examples and implementations