Skip to main content
POST
/
v2
/
credit
/
loop
Python (SDK)
from compass_api_sdk import CompassAPI, models


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

    res = compass_api.credit.credit_loop(owner="0x5e5b00ed886A6879C2B934612D2312975427fcAf", chain=models.Chain.ETHEREUM, collateral_token="WETH", borrow_token="USDC", initial_collateral_amount=1, multiplier=2, loan_to_value=70, protocol=models.CreditProtocol.AAVE, max_slippage_percent=0.5, gas_sponsorship=False)

    # Handle response
    print(res)
{
  "preview": {
    "iterations": 123,
    "total_collateral_supplied": "<string>",
    "total_borrowed": "<string>",
    "achieved_multiplier": "<string>",
    "projected_ltv": "<string>",
    "projected_health_factor": "<string>",
    "estimated_max_dust": "<string>",
    "legs": []
  },
  "transaction": {
    "chainId": "0x2105",
    "data": "0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d",
    "from": "0x4A83b4413CF41C3244027e1590E35a0F48403F0c",
    "gas": "0x7a120",
    "maxFeePerGas": "0x59682f00",
    "maxPriorityFeePerGas": "0x3b9aca00",
    "nonce": "0x5",
    "to": "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67",
    "value": "0x0"
  },
  "eip_712": {
    "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"
        }
      ]
    }
  }
}

Authorizations

x-api-key
string
header
required

Your Compass API Key. Get your key here.

Body

application/json

Open a leveraged loop: repeatedly supply collateral, borrow, and swap the borrow back to collateral — all in ONE atomic transaction from the Credit Account.

owner
string
default:0x5e5b00ed886A6879C2B934612D2312975427fcAf
required

The address that owns the Credit Account.

Example:

"0x5e5b00ed886A6879C2B934612D2312975427fcAf"

chain
enum<string>
default:ethereum
required

Blockchain network.

Available options:
base,
ethereum,
arbitrum,
hyperevm,
tempo,
bsc
Example:

"ethereum"

collateral_token
string
default:WETH
required

Token supplied as collateral each iteration. Must already be in the Credit Account for the initial amount. For MORPHO it must be the market's collateral token.

Examples:

"wstETH"

"WETH"

borrow_token
string
default:USDC
required

Token borrowed each iteration and swapped back to the collateral token. For MORPHO it must be the market's loan token.

Examples:

"WETH"

"USDC"

initial_collateral_amount
default:1
required

Collateral (in token units) already held in the Credit Account to seed the loop.

Required range: x > 0
Example:

1.5

multiplier
default:2
required

Target leverage: total collateral exposure = multiplier × initial_collateral_amount. Must be achievable at the requested loan_to_value (max ≈ 0.9 / (1 − LTV)).

Required range: x > 1
Example:

2

loan_to_value
default:70
required

Per-iteration borrow LTV in percent. Must not exceed the protocol's maximum for the market (Aave reserve/e-mode LTV; Morpho LLTV with a safety margin); borrows are sized slightly inside the requested value so no leg sits on the protocol's revert boundary.

Required range: 0 < x <= 100
Example:

70

protocol
enum<string>
default:AAVE

Lending protocol to loop into: AAVE or MORPHO. EULER looping is not available yet.

Available options:
AAVE,
EULER,
MORPHO
Example:

"AAVE"

market_id
string | null

Morpho only: the bytes32 market id (from /v2/credit/morpho_markets). Required when protocol=MORPHO.

max_slippage_percent
default:0.5

Per-swap slippage tolerance in percent. Loop dust is bounded by this per iteration, so tighter slippage means less dust.

Required range: 0 < x <= 10
Example:

0.3

emode_category
integer | null

Aave only: e-mode category to enable before looping (higher LTV for correlated pairs, e.g. ETH-correlated).

Required range: x >= 0
gas_sponsorship
boolean
default:false

If true, returns EIP-712 typed data for gas-sponsored execution instead of an unsigned transaction.

Example:

false

Response

Successful Response

The atomic loop transaction plus its guaranteed-floor preview.

preview
CreditLoopPreview · object
required

Projected end state, computed on guaranteed swap floors.

transaction
UnsignedTransaction · object | null

Unsigned transaction for direct execution by the owner. Present when gas_sponsorship=false.

Example:
{
"chainId": "0x2105",
"data": "0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d",
"from": "0x4A83b4413CF41C3244027e1590E35a0F48403F0c",
"gas": "0x7a120",
"maxFeePerGas": "0x59682f00",
"maxPriorityFeePerGas": "0x3b9aca00",
"nonce": "0x5",
"to": "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67",
"value": "0x0"
}
eip_712
BatchedSafeOperationsResponse · object | null

EIP-712 typed data for gas-sponsored execution. Present when gas_sponsorship=true.

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" }
]
}
}