# 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\*}
}%
$$
