> For the complete documentation index, see [llms.txt](https://docs.symm.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.symm.io/contract-documentation/symmio-perps-v0.8.5/diamond-core-facets/partyb-account.md).

# PartyB Account

The PartyB Account Facet manages collateral allocation, deallocation, and reserve vault operations for PartyB (solvers/hedgers). It also provides self-activation of cross PartyB mode. The underlying logic is implemented in the `PartyBAccountFacetImpl` library.

{% hint style="info" %}
**Note:** In v0.8.5, the following key changes apply:

* **Cross PartyB Mode:** When cross mode is active for a PartyB, `allocateForPartyB` and `deallocateForPartyB` require `partyA = address(0)` (the cross bucket). Calling with any other PartyA address reverts. `transferAllocation` reverts in cross mode, since moving funds between per-PartyA buckets is meaningless when everything is pooled.
* **Self-Activation of Cross Mode:** A new `activateCrossPartyB` function lets PartyB opt into cross mode themselves, provided the global feature flag is enabled and the locked-values migration is complete. An admin can also activate cross mode via `ControlFacet.setCrossPartyB`.
* **Reserve Vault:** The reserve vault functions are unchanged. The reserve vault is a last-resort fallback during force close for isolated-mode PartyBs. In cross mode, the reserve vault is **not used** during force close (the "ignore uPnL" fallback is used instead).
  {% endhint %}

***

#### Overview

The PartyB Account Facet provides:

* **Allocate for PartyB:** Moves funds from PartyB's free balance into an allocated balance for a specific PartyA (or the cross bucket in cross mode).
* **Deallocate for PartyB:** Returns allocated funds to PartyB's free balance. Requires a Muon uPnL signature for solvency verification.
* **Transfer Allocation:** Moves allocated funds from one PartyA bucket to another (isolated mode only).
* **Reserve Vault:** Deposit to and withdraw from an emergency reserve vault used during force close.
* **Activate Cross Mode:** PartyB self-activates cross mode after migration is complete.

***

#### allocateForPartyB()

Allocates collateral from PartyB's free balance to the allocated balance for a specific PartyA. In cross mode, `partyA` must be `address(0)`.

**Function Signature:**

```solidity
function allocateForPartyB(
    uint256 amount,
    address partyA
) public whenNotPartyBActionsPaused notLiquidatedPartyB(signer, partyA) onlyPartyB;
```

**Parameters:**

* `amount`: The collateral amount to allocate (in **18 decimals**).
* `partyA`: The PartyA address to allocate for. Use `address(0)` in cross mode.

**Access:** Only callable by PartyB.

**Example:**

```solidity
// Isolated mode: allocate for a specific PartyA
symmioDiamond.allocateForPartyB(100e18, partyAAddress);

// Cross mode: allocate to the cross bucket
symmioDiamond.allocateForPartyB(100e18, address(0));
```

**Events Emitted:**

* `AllocateForPartyB(address partyB, address partyA, uint256 amount, uint256 newAllocatedBalance)`
* `BalanceChangePartyB(address partyB, address partyA, uint256 amount, BalanceChangeType.ALLOCATE)`

***

#### deallocateForPartyB()

Deallocates collateral from PartyB's allocated balance back to free balance. Requires a Muon `SingleUpnlSig` to verify PartyB remains solvent after deallocation. In cross mode, `partyA` must be `address(0)`.

**Function Signature:**

```solidity
function deallocateForPartyB(
    uint256 amount,
    address partyA,
    SingleUpnlSig memory upnlSig
) external whenNotPartyBActionsPaused notLiquidatedPartyB(signer, partyA) notSuspended(signer) notLiquidatedPartyA(partyA) onlyPartyB;
```

**Parameters:**

* `amount`: The collateral amount to deallocate (in **18 decimals**).
* `partyA`: The PartyA address to deallocate from. Use `address(0)` in cross mode.
* `upnlSig`: The Muon signature containing PartyB's uPnL for solvency verification. In cross mode, the nonce in the signature uses the actual cross nonce (not zero).

**Access:** Only callable by PartyB. Neither party can be in liquidation. PartyB must not be suspended.

**Events Emitted:**

* `DeallocateForPartyB(address partyB, address partyA, uint256 amount, uint256 newAllocatedBalance)`
* `BalanceChangePartyB(address partyB, address partyA, uint256 amount, BalanceChangeType.DEALLOCATE)`

***

#### transferAllocation()

Transfers allocated funds from one PartyA bucket to another within the same PartyB. This lets PartyB rebalance capital across counterparties without going through deallocation and reallocation, which would reset cooldown timers. Requires a Muon `SingleUpnlSig` to verify solvency after the transfer.

**Important:** This function reverts in cross mode. All funds are pooled in a single bucket, so transferring between per-PartyA buckets is meaningless.

**Function Signature:**

```solidity
function transferAllocation(
    uint256 amount,
    address origin,
    address recipient,
    SingleUpnlSig memory upnlSig
) external whenNotPartyBActionsPaused;
```

**Parameters:**

* `amount`: The collateral amount to transfer (in **18 decimals**).
* `origin`: The PartyA address to transfer from.
* `recipient`: The PartyA address to transfer to.
* `upnlSig`: The Muon signature for solvency verification.

**Access:** Only callable by PartyB.

**Events Emitted:**

* `TransferAllocation(uint256 amount, address origin, uint256 newOriginBalance, address recipient, uint256 newRecipientBalance)`
* `BalanceChangePartyB(address partyB, address origin, uint256 amount, BalanceChangeType.DEALLOCATE)`
* `BalanceChangePartyB(address partyB, address recipient, uint256 amount, BalanceChangeType.ALLOCATE)`

***

#### depositToReserveVault()

Deposits funds from the caller's free balance into a PartyB's emergency reserve vault. The reserve vault is a last-resort fallback during force close. If PartyB becomes insolvent after a force close, the deficit can be covered from the reserve vault before triggering liquidation.

The caller does not need to be the PartyB itself; anyone can deposit into a PartyB's reserve vault.

**Function Signature:**

```solidity
function depositToReserveVault(
    uint256 amount,
    address partyB
) external whenNotPartyBActionsPaused notSuspended(signer) notSuspended(partyB);
```

**Parameters:**

* `amount`: The collateral amount to deposit (in **18 decimals**).
* `partyB`: The PartyB whose reserve vault will receive the deposit.

**Example:**

```solidity
// Deposit 500e18 into a PartyB's reserve vault
symmioDiamond.depositToReserveVault(500e18, partyBAddress);
```

**Events Emitted:**

* `DepositToReserveVault(address sender, address partyB, uint256 amount)`

***

#### withdrawFromReserveVault()

Withdraws funds from the caller's own reserve vault back to their free balance. Only the PartyB that owns the vault can withdraw.

**Function Signature:**

```solidity
function withdrawFromReserveVault(uint256 amount) external whenNotPartyBActionsPaused notSuspended(signer);
```

**Parameters:**

* `amount`: The collateral amount to withdraw (in **18 decimals**).

**Events Emitted:**

* `WithdrawFromReserveVault(address partyB, uint256 amount)`

***

#### activateCrossPartyB()

Lets a PartyB self-activate cross mode. Once activated, all per-PartyA allocated balances are accessed through the unified cross bucket (`address(0)`), enabling pooled capital management across all PartyA relationships.

**Prerequisites:**

* The global cross mode feature flag must be enabled (`crossPartyBModeActivated = true`).
* The PartyB's locked-values migration must be complete (`partyBLockedValuesMigrated[partyB] = true`), meaning `MigrationFacet.migrateCrossLockedValues` has been called for this PartyB.

An admin with `MIGRATION_ROLE` can alternatively activate cross mode for a PartyB via `ControlFacet.setCrossPartyB` without the migration check.

**Function Signature:**

```solidity
function activateCrossPartyB() external whenNotPartyBActionsPaused notSuspended(signer) onlyPartyB;
```

**Access:** Only callable by a registered PartyB. PartyB must not be suspended.

**Example:**

```solidity
// PartyB self-activates cross mode
symmioDiamond.activateCrossPartyB();
```

**Events Emitted:**

* `ActivateCrossPartyB(address partyB)`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.symm.io/contract-documentation/symmio-perps-v0.8.5/diamond-core-facets/partyb-account.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
