{
    "id": "trail.dn.pendle_hyperliquid",
    "schemaVersion": "0.1.0",
    "name": "Delta-neutral: Pendle PT spot + HyperLiquid perp short",
    "summary": "Open a delta-neutral position: buy a Pendle PT (spot leg) and short equivalent notional on HyperLiquid (perp leg). Idle USDC kept as HL margin buffer. Capital split via automation; spot leg composes trail.spot.swap_and_buy_pt; short leg uses HL API + on-chain order leaf.",
    "family": "dnhl-susde-loop",
    "chains": ["ethereum", "base", "arbitrum"],
    "params": [
        { "name": "totalCapital", "type": "uint256", "required": true, "description": "Total USDC to deploy across both legs + margin buffer (base units)." },
        { "name": "fromAsset", "type": "address", "required": true, "description": "Funding asset (typically USDC)." },
        { "name": "underlyingAsset", "type": "address", "required": true, "description": "Asset the PT is denominated in (e.g. USDe)." },
        { "name": "ptAsset", "type": "address", "required": true, "description": "Pendle PT token address." },
        { "name": "pendleMarket", "type": "address", "required": true, "description": "Pendle market for the PT." },
        { "name": "hlAsset", "type": "string", "required": true, "description": "HyperLiquid asset id to short (e.g. 'USDe', 'ETH'). Must match HL's notation." },
        { "name": "hlLeverage", "type": "uint16", "required": true, "description": "HyperLiquid leverage to use for the short (e.g. 3 = 3x). Drives the margin requirement." },
        { "name": "limitPrice", "type": "uint256", "required": true, "description": "Limit-order price for the HL short (base-units quote/asset, HL convention)." },
        { "name": "marginBufferBps", "type": "uint16", "required": false, "default": 500, "description": "Additional margin buffer above HL's minimum, in bps. Default 500 = 5%." }
    ],
    "execution": {
        "mode": "sequential",
        "steps": [
            {
                "kind": "automation",
                "id": "split",
                "description": "Compute the capital split: spotLegAmount (for Pendle), shortLegMargin (for HL), idleMargin (buffer).",
                "scriptId": "split_capital_dn",
                "inputs": {
                    "totalCapital": "$totalCapital",
                    "targetLeverage": "$hlLeverage",
                    "marginBufferBps": "$marginBufferBps"
                },
                "outputs": ["spotLegAmount", "shortLegMargin", "idleMargin", "notional"]
            },
            {
                "kind": "subtrail",
                "id": "spotLeg",
                "description": "Spot leg: swap fromAsset → underlying → Pendle PT.",
                "trailId": "trail.spot.swap_and_buy_pt",
                "args": {
                    "fromAsset": "$fromAsset",
                    "underlyingAsset": "$underlyingAsset",
                    "ptAsset": "$ptAsset",
                    "pendleMarket": "$pendleMarket",
                    "amountIn": "$split.spotLegAmount"
                }
            },
            {
                "kind": "api",
                "id": "setLeverage",
                "description": "Set leverage on HyperLiquid for the short — venue API call, not an on-chain leaf.",
                "venue": "hyperliquid",
                "method": "set_leverage",
                "params": {
                    "asset": "$hlAsset",
                    "leverage": "$hlLeverage"
                }
            },
            {
                "kind": "leaf",
                "id": "hlShort",
                "description": "Place the short limit order on HyperLiquid (on-chain leaf — HL bridge/L1 has Merkle-gated order placement leaves).",
                "protocol": "hyperliquid",
                "action": "place_limit_order",
                "args": {
                    "asset": "$hlAsset",
                    "side": "short",
                    "notional": "$split.notional",
                    "limitPrice": "$limitPrice"
                }
            }
        ]
    },
    "preconditions": [
        "Vault has a HyperLiquid bridge/funding setup and the place_limit_order leaf enabled.",
        "Strategist has configured HyperLiquid API credentials for this vault (set_leverage step).",
        "Pendle market for $ptAsset is open (not at maturity).",
        "DEX adapter has a route from fromAsset → underlyingAsset."
    ],
    "risks": [
        "If the HL limit order doesn't fill, the position is one-sided (long spot, no short hedge) → MAJOR delta exposure. Strategist should monitor + cancel/replace.",
        "PT held to maturity has fixed yield but no liquid exit; if HL short carries higher cost than PT yield, position bleeds.",
        "Funding rate spikes on HL can flip the cost calculus; reassess if funding goes deeply negative.",
        "Pendle PT depeg from underlying (rare but real) creates basis risk that the HL short doesn't hedge."
    ],
    "llm_doc": "Open a delta-neutral position with spot PT exposure and a HyperLiquid perp short hedge. The capital split is computed by an off-chain automation (split_capital_dn) — the strategist provides total capital + target HL leverage, the script outputs spot/margin/buffer breakdown. Spot leg composes the reusable trail.spot.swap_and_buy_pt. Short leg uses HL's set_leverage API (off-chain) followed by an on-chain limit-order leaf. Use when the user wants 'delta-neutral', 'DN', or 'spot-hedge' on Pendle + HyperLiquid."
}
