# MultiAccount Contract

The `MultiAccount` contract acts as a **control plane** for user-level trading accounts (PartyA contracts). Each Party A account holds isolated balances, positions, and state, while `MultiAccount` manages deployment, access, and orchestration logic. It enables:

* **Deterministic account creation** via `CREATE2`, enabling off-chain precomputation
* **Batched diamond calls** to forward multiple encoded operations to a PartyA contract
* **ERC-1271 support** for smart contract-based signature validation
* **Admin lifecycle control**, including pausing and implementation hot-swaps
* **Gasless delegation** via Symmio’s `InstantLayer` integration

All `PartyA` accounts are owned and governed via this registry-like contract, which maintains mappings between users and their deployed trading accounts.

## **Core Functions**

### 🔹 **Account Lifecycle**

```solidity
function addAccount(string memory name) external;
```

Deploys a new PartyA contract using `CREATE2` and registers it under the caller’s control. Emits `AddAccount`.

```solidity
function editAccountName(address accountAddress, string memory name) external;
```

Renames an existing PartyA contract. Only callable by the account owner. Emits `EditAccountName`.

### 🔹 **Diamond Operation Dispatcher**

```solidity
function _call(address account, bytes[] memory callDatas) external;
```

Executes a batch of encoded diamond calls on a PartyA account. Can only be called by the account owner or a registered `InstantLayer`. Reverts on failure. Emits a `Call` event per inner call.

### 🔹 **Signature Verification (ERC-1271)**

```solidity
function verifySignatureOfAccount(
    address account,
    bytes32 hash,
    bytes calldata signature
) external view returns (bytes4);
```

Validates a signed message against the account owner's address. Returns `0x1626ba7e` on success; `0xffffffff` on failure.

### 🔹 **TradeNFT Transfer Utility**

```solidity
function transferTradeNFT(
    address account,
    address to,
    uint256 tokenId
) external;
```

Transfers a TradeNFT from a PartyA contract to an external address. Owner-only.

### 🔹 **Admin & Emergency Controls**

```solidity
function setAccountImplementation(bytes memory newCode) external;
```

Sets a new implementation bytecode for future `CREATE2` deployments.

```solidity
function adminCallPartyA(address partyA, bytes calldata data) external;
```

Allows privileged (admin) execution on a PartyA contract—restricted by `SETTER_ROLE`.

```solidity
function pause() external;
function unpause() external;
```

Standard circuit-breaker functionality, gated by `PAUSER_ROLE` and `UNPAUSER_ROLE`.
