For the complete documentation index, see llms.txt. This page is also available as Markdown.

Creating an Account and Depositing Funds

In Symmio v0.8.5 a user's trading capital lives in a SubAccount created on the AccountLayer, a single shared diamond that manages every frontend's accounts. You no longer deploy your own account contract: you register as an affiliate, and users create SubAccounts under your affiliate on the shared AccountLayer.

SubAccounts and the VirtualAccounts beneath them are virtual (CREATE2-style) addresses with no deployed bytecode; the AccountLayer holds their state. For the full account model and the isolation types, see Building a New Frontend.

Step 1: Create a SubAccount

createSubAccounts(affiliate, accountsData[]) creates one or more SubAccounts under your affiliate. The Symmio core, isolation type, name, metadata, and single-VA flag are fields of the SubAccountCreationData struct, not positional arguments:

# SubAccountCreationData = (name, metadata, symmioCore, isolationType, singleVAMode)
# isolationType uses SubAccountIsolationType: 0=POSITION, 1=MARKET, 2=MARKET_DIRECTION, 3=CUSTOM
sub_account_data = [(
    "TradingAccount",      # name
    b"",                   # metadata
    symmio_core_address,   # symmioCore
    0,                     # isolationType (POSITION)
    False,                 # singleVAMode
)]

account_layer.functions.createSubAccounts(
    affiliate_address,
    sub_account_data,      # array, create several at once if you like
).transact({"from": user})

createSubAccounts returns the deterministic addresses of the created SubAccounts and emits SubAccountCreated for each. To list a user's SubAccounts later, call getUserSubAccountsAddresses(user, start, size) on the AccountLayer.

Migrating an existing MultiAccount frontend? The AccountManager wrapper exposes the old API (addAccount, getAccounts, _call) and creates CUSTOM-isolation SubAccounts that behave like the old model, so you can swap a contract address and migrate fully later. See Upgrading from MultiAccount (0.8.4).

Step 2: Deposit collateral

Collateral goes into the SubAccount on the AccountLayer. You can deposit alone, or deposit and allocate in a single call:

The actual ERC20 transferFrom happens inside the Symmio Core diamond, so Symmio Core is the address that needs the collateral allowance, not the AccountLayer. Approve it once before the first deposit:

amount is in the token's native decimals; Symmio converts to 18-decimal fixed-point internally, so the same code works for 6-decimal USDC and 18-decimal stablecoins. Read the collateral token address from getCollateral() on the Symmio Core view facet and its decimals from the token's decimals(). On success you'll see DepositForAccount, plus AllocateForAccount if you allocated.

Step 3: Fund the VirtualAccount before trading

On a non-CUSTOM SubAccount the margin for a trade lives in a VirtualAccount (VA) beneath the SubAccount, not in the SubAccount itself. Before the first trade you fund the next VA; the AccountLayer derives which VA that is from the isolation type and symbol, so you don't pass a VA address. The VA isolation type uses VirtualAccountIsolationType (POSITION, MARKET, MARKET_LONG, MARKET_SHORT):

To top up a VA that already exists, use addMargin(virtual_account, amount). On a CUSTOM SubAccount there's no automatic VA: trades run directly through the SubAccount, like the old MultiAccount model.

Once the SubAccount is funded and the VA has margin, you're ready to send a quote.

Last updated