> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spiralstake.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# build_equity_exit_tx

> Build the unsigned atomic batch that fully unwinds an open equity vault.

Returns the **unsigned** call batch to close a vault the wallet holds (from [`get_positions`](/agents/tools/get-positions)`.equityPositions`): each of its yield loops is closed, then one self-funded router call repays the stock debt, withdraws the stock, swaps it to USDG and returns the proceeds. Non-custodial.

## Input

<ParamField path="strategyId" type="string" required>The vault's id (`equity-0x…`).</ParamField>
<ParamField path="userAddress" type="string" required>Wallet that owns the vault and will sign.</ParamField>

<ParamField path="yieldPositionIds" type="integer[]">
  The yield loop id(s) to close with the stock leg (from `get_positions`). Optional when the vault's `yieldLoopMatch` is `tagged`, `basis` or `mixed`; **required** when it is `ambiguous`. Each must be this wallet's open loop on the vault's yield market. Nothing outside this list is ever closed.
</ParamField>

<ParamField path="slippage" type="number" default="0.01">Ratio; capped at `0.01`.</ParamField>
<ParamField path="chainId" type="integer" default="1">Vaults exist on `4663` only.</ParamField>

## Output

```json theme={null}
{
  "chainId": 4663,
  "action": "equity_exit",
  "strategyId": "equity-0x50bc…",
  "atomic": true,
  "calls": [
    { "to": "0x…FlashLeverage", "data": "0x…" },   // deleverage(yield loop) — one per loop the vault owns
    { "to": "0x…Morpho",        "data": "0x…" },   // setAuthorization(router, true)
    { "to": "0x…Router",        "data": "0x…" },   // router.equityExit(...)
    { "to": "0x…Morpho",        "data": "0x…" }    // setAuthorization(router, false)
  ],
  "meta": {
    "position": { "…": "the equityPositions entry being unwound" },
    "closedYieldPositionIds": [3],
    "yieldLoopSelection": "basis",
    "minLoanOut": "…",
    "estimatedUsdgOut": "984.11",
    "expiresAt": "…",
    "signingUrl": "https://app.spiralstake.xyz/portfolio?position=3&chainId=4663",
    "instructions": "…"
  }
}
```

`minLoanOut` floors the USDG the router must return to you: the stock swap's min-out less the debt (with a small interest buffer), exactly as the app builds it. Exit swaps carry **no** fee.

## Executing

Same rules as the [deposit batch](/agents/tools/build-equity-deposit-tx): submit `calls` as one atomic batch (EIP-5792 / Safe); a wallet that cannot batch sends them in order and must always send the final revoke.

## Fail-closed cases

Refused when the wallet has no open vault for that id; when the stock leg has no debt (`equityExit` flash-loans the debt to repay it, so a debt-free leg is withdrawn straight from Morpho instead); or when the vault's `yieldLoopMatch` is `ambiguous` and no `yieldPositionIds` were given — the tool never guesses which loop to close.

<Warning>
  Always read `meta.closedYieldPositionIds` before signing: those loops are closed together with the stock leg.
</Warning>

<Note>
  The yield loop of an open vault cannot be closed on its own through [`build_manage_tx`](/agents/tools/build-manage-tx); this tool is the only way to unwind a vault.
</Note>
