> ## 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.

# Manage & close

> Adjust or unwind an existing position.

Every adjustment uses [`build_manage_tx`](/agents/tools/build-manage-tx) against a position's on-chain `id` (from [`get_positions`](/agents/tools/get-positions)).

## Find the position

```ts theme={null}
const { positions } = await call("get_positions", { userAddress: "0x…" });
const id = positions[0].id;
```

## Adjust

<CodeGroup>
  ```ts Add collateral theme={null}
  await call("build_manage_tx", { userAddress, id, action: "add_collateral", payToken: "0x…", amount: "5000" });
  ```

  ```ts Repay (full) theme={null}
  await call("build_manage_tx", { userAddress, id, action: "repay", payToken: "0x…", amount: "5000", full: true });
  ```

  ```ts Increase leverage theme={null}
  await call("build_manage_tx", { userAddress, id, action: "increase_leverage", desiredLtv: "75" });
  ```

  ```ts Withdraw / borrow theme={null}
  await call("build_manage_tx", { userAddress, id, action: "remove_collateral", amount: "1000" });
  await call("build_manage_tx", { userAddress, id, action: "borrow", amount: "1000" });
  ```
</CodeGroup>

## Close

```ts theme={null}
const bundle = await call("build_manage_tx", { userAddress, id, action: "close" });
// Send bundle.tx — swaps all collateral back to the loan token, repays, returns the rest.
```

Each returns the same `{ approvals, tx, meta }` bundle — sign approvals first, then the tx. Verify with `get_positions` after it confirms.
