Margin & Intent Accounts

Margin Accounts (MAs)

MAs are at the core of the AFP and are internal to the clearing system. They house the collateral that is required to open and maintain positions in products that a user trades.

Any address on Autonity (termed the Admin Address) can create a Margin Account by depositing any ERC-20 collateral into the clearing system. If a Margin Account does not exist for an Admin Address – Collateral Asset pair, a new one is created automatically. If one already exists, it is funded with the deposited collateral.

Collateral in a Margin Account is used to fund positions when trading products. By default, the Admin Address is also the designated Intent Account, allowing the admin address to trade the funds that it deposited and have administrative privileges over the Margin Account, such as:

  • Depositing/withdrawing funds
  • Adding/removing Intent Accounts

An Admin Address can either be an EOA or a smart contract.

Margin Account Architecture

The on-chain implementation of the Margin Account architecture is as follows:

There is one MarginAccount.sol contract per collateral asset which holds all the collateral deposited by Admin Addresses for that specific collateral asset. Individual MAs are then tracked within the Margin Account contract.

Such MarginAccount.sol contracts are created by:

function initializeMarginAccount(address collateralAsset) public returns (IMarginAccount)

on the MarginAccountRegistry.sol contract. Anyone can call the above function but it is in the Product Builder’s interest to ensure that the collateral asset that they have specified for their product is ready for trading (as it will cost extra gas to deploy a new MA contract).

Intent Accounts (IAs)

Intent Accounts (IAs) are Autonity addresses that can create intents (and so submit orders) that use the collateral in a Margin Account to trade products, but they do not have administrative privileges over those MAs (see Intents for more detail).

Analogy to a hedge fund

The setup described above is similar to how a hedge fund may be structured - where the Admin Address may be considered to be the managing partner of the fund, and is able to raise capital, withdraw funds, and hire/fire traders. Whereas IAs are the traders themselves who use the pool of capital of the fund to trade.

Margin Account Equity (MAE) Check

MAs serve the crucial purpose of housing collateral that is required to trade. As such, checking the equity available in a Margin Account for trading is crucial to determine if:

  • A Margin Account is liquidatable.
  • A Margin Account has sufficient Initial Margin to satisfy the Initial Margin Requirements of a trade that is submitted for clearing.

Margin Account Equity is Capital plus Unrealized PnL:

MAE = C + UPnL

An MAE Check can be run on a Margin Account for any trade. That trade can be for a single product or for multiple products simultaneously. The MAE Check is defined as the following:

  1. If a Margin Account does not exist for the collateral asset defined in the Product Specification, the check fails.

  2. Recalculate MAE on the basis that each product is settled at the price and quantity defined in the trade.

  3. If the MAE is less than zero, the account is bankrupt and the check fails.

  4. If position sizes are increasing or reversing perform the Initial Margin Check. If the check fails, the process fails.

  5. Otherwise, the check succeeds.