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

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

The question should be specific, self-contained, and written in natural language.
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.
