# DeFi Math Helper (APR/APY, Impermanent Loss, Liquidation Price, Leverage)

> DeFi Math Helper (APR/APY, Impermanent Loss, Liquidation Price, Leverage) is a paid API for AI agents from api.agentstools.dev, paid per call via x402, $0.002/call, status unknown (last checked 2026-09-14).

Performs DeFi financial computations including APR/APY conversion, funding rate annualization, impermanent loss, liquidation price, leverage, and LP value calculations.

## Facts

- Endpoint: GET https://api.agentstools.dev/quant/defi
- Price: $0.002/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-14
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/defi-math-helper-apr-apy-impermanent-loss-liquidation-price-leverage-e0a41a69
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_P4Rk4mR1j81fjWhl7izfx

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability defi-math-helper-apr-apy-impermanent-loss-liquidation-price-leverage-e0a41a69
```

Example prompt: What's my liquidation price if I go long at an entry price of $2000 with 10x leverage and a 0.5% maintenance margin? Also, what's the APY if the APR is 12% compounded monthly (n=12)?

## When to prefer this

Use this endpoint when you need fast, pure-math DeFi calculations without connecting to any blockchain or live data source — ideal for computing APR/APY conversions, estimating impermanent loss scenarios, determining liquidation prices before entering a trade, or sizing leverage positions based on equity and notional values.

## Known failure modes

- Missing required 'op' query parameter returns an error
- Supplying wrong parameters for the chosen op (e.g. missing 'apr' for op=apr_to_apy) causes a validation error
- Invalid enum value for 'op' or 'side' returns a 400-style error
- Non-numeric values for numeric fields cause parse errors
- Payment not included or insufficient results in a 402 Payment Required response

## How this service works

DeFi math helper: APR and APY conversion, funding annualization, impermanent loss, liquidation price, and leverage. Pure computation over your inputs.

## Output

Returns a JSON object with the computed result for the requested DeFi operation — e.g. the APY value, impermanent loss percentage, liquidation price level, annualized funding rate, leverage ratio, or LP value — based purely on the input parameters provided.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "required": [
  "input"
 ],
 "properties": {
  "input": {
   "type": "object",
   "required": [
    "type",
    "method"
   ],
   "properties": {
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "enum": [
      "GET",
      "HEAD",
      "DELETE"
     ],
     "type": "string"
    },
    "queryParams": {
     "type": "object",
     "required": [
      "op"
     ],
     "properties": {
      "n": {
       "type": "number",
       "description": "Compounding periods per year for the rate conversions"
      },
      "op": {
       "enum": [
        "apr_to_apy",
        "apy_to_apr",
        "funding_annualized",
        "impermanent_loss",
        "liquidation_price",
        "leverage",
        "lp_value"
       ],
       "type": "string",
       "description": "Which DeFi formula to evaluate"
      },
      "apr": {
       "type": "number",
       "description": "APR as a decimal for op=apr_to_apy"
      },
      "apy": {
       "type": "number",
       "description": "APY as a decimal for op=apy_to_apr"
      },
      "rate": {
       "type": "number",
       "description": "Per-period funding rate for op=funding_annualized"
      },
      "side": {
       "enum": [
        "long",
        "short"
       ],
       "type": "string",
       "description": "Position side for op=liquidation_price"
      },
      "equity": {
       "type": "number",
       "description": "Equity for op=leverage"
      },
      "leverage": {
       "type": "number",
       "description": "Leverage for op=liquidation_price and op=leverage"
      },
      "notional": {
       "type": "number",
       "description": "Notional for op=leverage"
      },
      "entry_price": {
       "type": "number",
       "description": "Entry price for op=liquidation_price"
      },
      "price_ratio": {
       "type": "number",
       "description": "Price ratio k for impermanent loss and LP value"
      },
      "initial_value": {
       "type": "number",
       "description": "Optional initial value for op=lp_value"
      },
      "periods_per_year": {
       "type": "number",
       "description": "Funding periods per year, default 1095"
      },
      "maintenance_margin": {
       "type": "number",
       "description": "Maintenance margin as a decimal, default 0.005"
      }
     }
    }
   },
   "additionalProperties": false
  },
  "output": {
   "type": "object",
   "req
… (truncated)
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/defi-math-helper-apr-apy-impermanent-loss-liquidation-price-leverage-e0a41a69/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from api.agentstools.dev](https://www.zero.xyz/host/api.agentstools.dev/llms.txt)
