> For the complete documentation index, see [llms.txt](https://docs.aftermath.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aftermath.finance/perpetuals/architecture/account.md).

# Account

## Create Account

When a user creates an account on Aftermath Perpetuals, an `Account` object is transferred to the user's address. This object can be used to open a position in any of the available markets. The `Account` object identifies the positions in the markets and can be freely transferred to another Sui address by the user. Losing access of the `Account` object means permanently losing access to the markets' positions. It is possible to have multiple `Account` objects in the same address.

## Deposit Collateral

A user can deposit collateral into the account at any time. The deposited collateral remains in the account until the user decides to allocate it to a market to open a position. When this happens, the collateral is withdrawn from the account and deposited into the market's vault to be used as margin for the position.

## Withdraw Collateral

A user can withdraw all the non-allocated collateral from the account at any time. Before withdrawing the collateral allocated in the markets, the user needs to deallocate it. Deallocating collateral is limited by the status of the position. The formula to calculate the position's (*p*) *free collateral:*

$$
{\small
\begin{align\*}
\small
& FreeCollateral(p) = \frac{CappedMargin(p) - MarginRequirements(p)}{CollateralPrice}
\\\\
\&CappedMargin(p) =  Collateral(p) \cdot CollateralPrice + UnrealizedFundings(p) + \min{Pnl(p), 0}
\end{align\*}
}%
$$


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.aftermath.finance/perpetuals/architecture/account.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
