# View Facet

The **View Facet** contains all the read-only functions for the protocol. It reaches across every storage contract in the protocol and surfaces balances, intents, trades, symbols, oracles, fee structures, liquidation state, pause flags, access control, and computed values like fees and P\&L.

> **Key Concepts:**
>
> * **Storage Organisation:** The View Facet is structured to mirror the protocol's internal storage layout — Account, App, Close Intent, Counterparty Relations, Fee Management, Liquidation, Open Intent, State Control, Access Control, Symbol, and Trade. Functions are grouped by which storage contract they read from.
> * **Pagination:** Several functions that return arrays (trades, intents, symbols) come in two flavours — a full ID array getter and a paginated object getter that takes `start` and `size` parameters. The paginated versions are safe to call on large datasets without hitting gas limits.
> * **Computed Views:** Beyond raw storage reads, the View Facet also exposes calculated values — premium amounts, P\&L, exercise fees, and open/close intent fees — using the same library logic the protocol itself uses internally. These are useful for simulating outcomes before submitting transactions.
> * **Cross Balance:** A user's allocated collateral for a specific counterparty relationship. `getCrossBalance()` returns the full `CrossEntry` struct for a given user/collateral/counterparty triplet.
> * **Scheduled Release:** The protocol tracks when balances are scheduled to be released back to parties. `getScheduledReleaseEntry()` exposes this per counterparty.

***

### Account Storage Views

#### getIsolatedBalance()

Returns the unallocated balance a user holds for a given collateral — the funds available for withdrawal or allocation.

```solidity
function getIsolatedBalance(address user, address collateral) external view returns (uint256);
```

#### getIsolatedLockedBalance()

Returns the portion of a user's isolated balance that is currently locked — for example, reserved for a pending withdrawal or locked during a protocol operation.

```solidity
function getIsolatedLockedBalance(address user, address collateral) external view returns (uint256);
```

#### getReserveBalance()

Returns the amount held in a user's reserve balance for a given collateral — separate from both their isolated and cross balances.

```solidity
function getReserveBalance(address user, address collateral) external view returns (uint256);
```

#### getCrossBalance()

Returns the full `CrossEntry` struct for a user's cross balance with a specific counterparty and collateral. This includes the allocated balance and any associated metadata for that bilateral relationship.

```solidity
function getCrossBalance(address user, address collateral, address counterParty) external view returns (CrossEntry memory);
```

#### getScheduledReleaseEntry()

Returns the `ScheduledReleaseEntry` for a user/collateral/counterparty combination — the protocol's record of when and how much collateral is scheduled to be released back to a party.

```solidity
function getScheduledReleaseEntry(address user, address collateral, address counterParty) external view returns (ScheduledReleaseEntry memory);
```

#### getCounterPartyAddresses()

Returns the full list of counterparty addresses that a user has a cross balance relationship with for a given collateral. Useful for enumerating all active bilateral relationships.

```solidity
function getCounterPartyAddresses(address user, address collateral) external view returns (address[] memory);
```

#### getWithdrawal()

Returns the full `Withdraw` struct for a given withdrawal ID — including the user, destination address, collateral, amount, and current status.

```solidity
function getWithdrawal(uint256 withdrawId) external view returns (Withdraw memory);
```

#### getLastWithdrawalId()

Returns the most recently assigned withdrawal ID. Useful for iterating over all withdrawals by incrementing from 1 to this value.

```solidity
function getLastWithdrawalId() external view returns (uint256);
```

#### getExpressWithdrawProviderConfig()

Returns the `ExpressWithdrawProviderConfig` for a given provider and collateral combination — the configuration that governs how that provider handles fast withdrawals for that token.

```solidity
function getExpressWithdrawProviderConfig(address provider, address collateral) external view returns (ExpressWithdrawProviderConfig memory);
```

#### getInvalidWithdrawalsPool()

Returns the address designated to receive collateral from withdrawals that fail validation checks.

```solidity
function getInvalidWithdrawalsPool() external view returns (address);
```

#### getReleaseInterval()

Returns the effective release interval for a user — their custom interval if one has been configured, otherwise the system default.

```solidity
function getReleaseInterval(address user) external view returns (uint256);
```

#### getDefaultReleaseInterval()

Returns the protocol-wide default release interval applied to any PartyB that hasn't been given a custom one.

```solidity
function getDefaultReleaseInterval() external view returns (uint256);
```

#### getUserReleaseInterval()

Returns both whether a user has a custom release interval configured and what that interval is. More useful than `getReleaseInterval()` when you need to distinguish between custom and default.

```solidity
function getUserReleaseInterval(address user) external view returns (bool hasConfigured, uint256 interval);
```

**Example Response:**

```json
{
  "hasConfigured": true,
  "interval": 86400
}
```

#### getMaxConnectedCounterParties()

Returns the protocol-wide cap on how many counterparty relationships a single party can have open simultaneously.

```solidity
function getMaxConnectedCounterParties() external view returns (uint256);
```

#### isManualSync()

Returns whether a user (typically a PartyB) has been flagged as requiring manual balance synchronisation before they can resume trading. This flag is set when a PartyB's config is updated via `setPartyBConfig()`.

```solidity
function isManualSync(address user) external view returns (bool);
```

#### getNonce()

Returns the current nonce between two parties. Nonces are used internally to prevent replay attacks and ensure state consistency across bilateral operations.

```solidity
function getNonce(address party, address counterParty) external view returns (uint256);
```

***

### App Storage Views

#### getVersion()

Returns the current protocol version number stored in `AppStorage`.

```solidity
function getVersion() external view returns (uint16);
```

#### getBalanceLimitPerUser()

Returns the maximum balance a single user can hold for a given collateral.

```solidity
function getBalanceLimitPerUser(address collateral) external view returns (uint256);
```

#### getMaxCloseOrdersLength()

Returns the maximum number of close orders that can be submitted per trade at one time.

```solidity
function getMaxCloseOrdersLength() external view returns (uint256);
```

#### getMaxTradePerPartyA()

Returns the maximum number of concurrent open trades a PartyA can hold.

```solidity
function getMaxTradePerPartyA() external view returns (uint256);
```

#### getPriceOracleAddress()

Returns the address of the primary price oracle contract used for settlement price lookups.

```solidity
function getPriceOracleAddress() external view returns (address);
```

#### isWhitelistedCollateral()

Returns whether a given token address is whitelisted as a valid collateral in the protocol.

```solidity
function isWhitelistedCollateral(address collateral) external view returns (bool);
```

#### getTradeNftAddress()

Returns the address of the ERC-721 contract used to represent trade ownership as NFTs.

```solidity
function getTradeNftAddress() external view returns (address);
```

#### isSignatureUsed()

Returns whether a given signature hash has already been consumed by the protocol. Used to prevent signature replay.

```solidity
function isSignatureUsed(bytes32 sigHash) external view returns (bool);
```

#### getSignatureVerifier()

Returns the address of the contract responsible for verifying UPnL and settlement price signatures.

```solidity
function getSignatureVerifier() external view returns (address);
```

#### Timing Parameter Views

These return the current values of all protocol timing parameters set via `ControlFacet`:

```solidity
function getPartyADeallocateCooldown() external view returns (uint256);
function getPartyBDeallocateCooldown() external view returns (uint256);
function getForceCancelOpenIntentTimeout() external view returns (uint256);
function getForceCancelCloseIntentTimeout() external view returns (uint256);
function getPartyBExclusiveWindow() external view returns (uint256);
function getSettlementPriceSigValidTime() external view returns (uint256);
function getUpnlSigValidTime() external view returns (uint256);
```

#### getPartyBConfig()

Returns the full `PartyBConfig` struct for a given PartyB — including their active status, oracle assignment, and other solver-specific settings.

```solidity
function getPartyBConfig(address partyB) external view returns (PartyBConfig memory);
```

**Example Response:**

```json
{
  "isActive": true,
  "oracleId": 1
}
```

#### isSymbolTypesSupportedByPartyB()

Returns whether a specific PartyB has marked a given symbol type as supported for trading.

```solidity
function isSymbolTypesSupportedByPartyB(address partyB, uint256 symbolType) external view returns (bool);
```

#### isCallFromInstantLayer()

Returns whether the current execution context has been flagged as originating from the instant layer.

```solidity
function isCallFromInstantLayer() external view returns (bool);
```

***

### Close Intent Storage Views

#### getCloseIntent()

Returns the full `CloseIntent` struct for a given intent ID — including status, trade ID, price, quantity, deadline, and fee structure.

```solidity
function getCloseIntent(uint256 intentId) external view returns (CloseIntent memory);
```

#### getCloseIntentIds()

Returns all close intent IDs ever created for a specific trade. Includes all statuses — pending, filled, expired, cancelled.

```solidity
function getCloseIntentIds(uint256 tradeId) external view returns (uint256[] memory);
```

#### getCloseIntents()

Returns a paginated slice of `CloseIntent` structs for a given trade. Use `start` and `size` to page through large histories without hitting gas limits.

```solidity
function getCloseIntents(uint256 tradeId, uint256 start, uint256 size) external view returns (CloseIntent[] memory);
```

#### getLastCloseIntentId()

Returns the most recently assigned close intent ID — useful for knowing the upper bound when iterating.

```solidity
function getLastCloseIntentId() external view returns (uint256);
```

***

### Counterparty Relations Storage Views

#### getBoundPartyB()

Returns the PartyB address that a given PartyA is currently bound to. Returns the zero address if no binding exists.

```solidity
function getBoundPartyB(address partyA) external view returns (address);
```

#### getUnbindingRequestTime()

Returns the timestamp at which a PartyA submitted an unbinding request. Returns 0 if no request is pending.

```solidity
function getUnbindingRequestTime(address partyA) external view returns (uint256);
```

#### getUnbindingCooldown()

Returns the protocol-wide cooldown period a party must wait between submitting an unbinding request and it taking effect.

```solidity
function getUnbindingCooldown() external view returns (uint256);
```

#### isInstantActionsModeActive()

Returns whether instant actions mode is currently active for a given user.

```solidity
function isInstantActionsModeActive(address user) external view returns (bool);
```

#### getInstantActionsModeDeactivateTime()

Returns the earliest timestamp at which a user can deactivate their instant actions mode.

```solidity
function getInstantActionsModeDeactivateTime(address user) external view returns (uint256);
```

#### getDeactiveInstantActionModeCooldown()

Returns the protocol-wide cooldown before instant actions mode can be deactivated after activation.

```solidity
function getDeactiveInstantActionModeCooldown() external view returns (uint256);
```

***

### Fee Management Storage Views

#### getDefaultFeeCollector()

Returns the address that receives platform fees when no affiliate-specific collector is configured.

```solidity
function getDefaultFeeCollector() external view returns (address);
```

#### isAffiliateActive()

Returns whether a given affiliate address is currently active and eligible to receive fee routing.

```solidity
function isAffiliateActive(address affiliate) external view returns (bool);
```

#### getAffiliateFeeCollector()

Returns the address that receives fees on behalf of a specific affiliate.

```solidity
function getAffiliateFeeCollector(address affiliate) external view returns (address);
```

#### getAffiliateFee()

Returns the `Fee` struct defining an affiliate's fee structure for a specific symbol — including open and close fee rates.

```solidity
function getAffiliateFee(address affiliate, uint256 symbolId) external view returns (Fee memory);
```

***

### Liquidation Storage Views

#### getInProgressLiquidationId()

Returns the active liquidation ID for a given PartyA/PartyB/collateral combination. Returns 0 if no liquidation is currently in progress for that combination.

```solidity
function getInProgressLiquidationId(address partyA, address partyB, address collateral) external view returns (uint256);
```

#### getLiquidationDetail()

Returns the full `LiquidationDetail` struct for a given liquidation ID — including the parties involved, collateral, UPnL snapshot, collateral price at liquidation time, and current status.

```solidity
function getLiquidationDetail(uint256 liquidationId) external view returns (LiquidationDetail memory);
```

#### getLastLiquidationId()

Returns the most recently assigned liquidation ID.

```solidity
function getLastLiquidationId() external view returns (uint256);
```

***

### Open Intent Storage Views

#### getOpenIntent()

Returns the full `OpenIntent` struct for a given intent ID — including all `TradeAgreements` fields, price, deadline, status, fee structure, PartyB whitelist, and user data.

```solidity
function getOpenIntent(uint256 intentId) external view returns (OpenIntent memory);
```

#### getActiveOpenIntentIds()

Returns the full array of currently active open intent IDs for a given user.

```solidity
function getActiveOpenIntentIds(address user) external view returns (uint256[] memory);
```

#### getActiveOpenIntentsCount()

Returns just the count of active open intents for a user — cheaper than fetching the full array when only the number is needed.

```solidity
function getActiveOpenIntentsCount(address user) external view returns (uint256);
```

#### getActiveOpenIntents()

Returns a paginated slice of full `OpenIntent` structs for a user's active intents. Safe to call on users with large numbers of open intents.

```solidity
function getActiveOpenIntents(address user, uint256 start, uint256 size) external view returns (OpenIntent[] memory);
```

#### getPartyAOpenIntentIndex() & getPartyBOpenIntentIndex()

Return the index of an intent within the PartyA or PartyB active intents array respectively. Used internally for efficient array management and exposed here for debugging and off-chain reconciliation.

```solidity
function getPartyAOpenIntentIndex(uint256 intentId) external view returns (uint256);
function getPartyBOpenIntentIndex(uint256 intentId) external view returns (uint256);
```

#### getLastOpenIntentId()

Returns the most recently assigned open intent ID.

```solidity
function getLastOpenIntentId() external view returns (uint256);
```

***

### State Control Storage Views

#### Individual Pause State Checks

Each operation type has its own boolean pause flag with a dedicated getter. These are the same flags toggled by `ControlFacet`'s pause/unpause functions:

```solidity
function isGlobalPaused() external view returns (bool);
function isDepositingPaused() external view returns (bool);
function isWithdrawingPaused() external view returns (bool);
function isPartyBActionsPaused() external view returns (bool);
function isPartyAActionsPaused() external view returns (bool);
function isLiquidatingPaused() external view returns (bool);
function isThirdPartyActionsPaused() external view returns (bool);
function isInternalTransferPaused() external view returns (bool);
function isExternalTransferPaused() external view returns (bool);
function isExpressWithdrawPaused() external view returns (bool);
function isInstantLayerPaused() external view returns (bool);
```

#### getAllPauseStates()

Returns all eleven pause flags plus the global PartyB emergency mode status in a single call. The most efficient way for a frontend or monitoring system to get a complete picture of the protocol's operational state.

```solidity
function getAllPauseStates() external view returns (
    bool globalPaused,
    bool depositingPaused,
    bool withdrawingPaused,
    bool expressWithdrawPaused,
    bool partyBActionsPaused,
    bool partyAActionsPaused,
    bool liquidatingPaused,
    bool thirdPartyActionsPaused,
    bool internalTransferPaused,
    bool externalTransferPaused,
    bool instantLayerPaused,
    bool partyBsEmergencyMode
);
```

**Example Response:**

```json
{
  "globalPaused": false,
  "depositingPaused": false,
  "withdrawingPaused": false,
  "expressWithdrawPaused": false,
  "partyBActionsPaused": false,
  "partyAActionsPaused": false,
  "liquidatingPaused": false,
  "thirdPartyActionsPaused": false,
  "internalTransferPaused": false,
  "externalTransferPaused": false,
  "instantLayerPaused": false,
  "partyBsEmergencyMode": false
}
```

#### isPartyBsEmergencyMode()

Returns whether the system-wide PartyB emergency mode is currently active.

```solidity
function isPartyBsEmergencyMode() external view returns (bool);
```

#### isPartyBInEmergencyMode()

Returns whether a specific PartyB address is currently in individual emergency mode.

```solidity
function isPartyBInEmergencyMode(address partyB) external view returns (bool);
```

#### isAddressSuspended()

Returns whether a given address has been suspended from protocol operations.

```solidity
function isAddressSuspended(address user) external view returns (bool);
```

#### isWithdrawalSuspended()

Returns whether a specific withdrawal by ID has been suspended and cannot currently be completed or cancelled.

```solidity
function isWithdrawalSuspended(uint256 withdrawId) external view returns (bool);
```

***

### Access Control Storage Views

#### hasRole()

Returns whether a given address holds a specific role.

```solidity
function hasRole(address user, bytes32 role) external view returns (bool);
```

#### getRoleMembers()

Returns the full array of addresses that currently hold a given role. Uses the enumerable set stored in `AccessControlStorage`.

```solidity
function getRoleMembers(bytes32 role) external view returns (address[] memory);
```

#### getRoleMemberCount()

Returns the number of addresses holding a given role — cheaper than fetching the full array.

```solidity
function getRoleMemberCount(bytes32 role) external view returns (uint256);
```

#### getRoleMember()

Returns the address at a specific index within the members of a role. Useful for iterating role membership without fetching the entire array.

```solidity
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
```

***

### Symbol Storage Views

#### getOracle()

Returns the full `Oracle` struct for a given oracle ID — including the oracle's name and contract address.

```solidity
function getOracle(uint256 oracleId) external view returns (Oracle memory);
```

**Example Response:**

```json
{
  "id": 1,
  "name": "Chainlink ETH/USD",
  "contractAddress": "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419"
}
```

#### getLastOracleId()

Returns the most recently assigned oracle ID — the upper bound for iterating all registered oracles.

```solidity
function getLastOracleId() external view returns (uint256);
```

#### getSymbol()

Returns the full `Symbol` struct for a given symbol ID — including name, option type, oracle ID, collateral, platform fee, symbol type, and validity status.

```solidity
function getSymbol(uint256 symbolId) external view returns (Symbol memory);
```

**Example Response:**

```json
{
  "symbolId": 1,
  "isValid": true,
  "name": "ETH-CALL-3500-MAR2025",
  "optionType": 0,
  "oracleId": 1,
  "collateral": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  "platformFee": { "openFee": 500000000000000, "closeFee": 500000000000000 },
  "symbolType": 1
}
```

#### getSymbols()

Returns a paginated array of `Symbol` structs. `start` is a symbol ID offset; `size` controls how many to return. Returns an empty array if `start` exceeds the last symbol ID.

```solidity
function getSymbols(uint256 start, uint256 size) external view returns (Symbol[] memory);
```

#### getLastSymbolId()

Returns the most recently assigned symbol ID.

```solidity
function getLastSymbolId() external view returns (uint256);
```

***

### Trade Storage Views

#### getTrade()

Returns the full `Trade` struct for a given trade ID — including PartyA, PartyB, all trade agreement terms, current quantity, status, and settlement data.

```solidity
function getTrade(uint256 tradeId) external view returns (Trade memory);
```

#### getActiveTradeIdsOfPartyA()

Returns all currently active trade IDs for a given PartyA address.

```solidity
function getActiveTradeIdsOfPartyA(address user) external view returns (uint256[] memory);
```

#### getActiveTradesOfPartyA()

Returns paginated `Trade` structs for a PartyA's active positions. Use `start` and `size` to page through large portfolios.

```solidity
function getActiveTradesOfPartyA(address user, uint256 start, uint256 size) external view returns (Trade[] memory);
```

#### getActiveTradeIdsForPartyB()

Returns all active trade IDs for a given PartyB scoped to a specific collateral token.

```solidity
function getActiveTradeIdsForPartyB(address partyB, address collateral) external view returns (uint256[] memory);
```

#### getPartyATradeIndex() & getPartyBTradeIndex()

Return the index of a trade within the PartyA or PartyB active trades array respectively. Exposed for off-chain reconciliation and debugging.

```solidity
function getPartyATradeIndex(uint256 tradeId) external view returns (uint256);
function getPartyBTradeIndex(uint256 tradeId) external view returns (uint256);
```

#### getLastTradeId()

Returns the most recently assigned trade ID.

```solidity
function getLastTradeId() external view returns (uint256);
```

***

### Computed Open Intent Views

These functions use the same fee and premium calculation logic as the protocol itself, letting callers simulate values before submitting transactions.

#### getOpenIntentPlatformFee()

Calculates the platform fee that would be charged when an open intent is filled, using the intent's stored fee structure and price.

```solidity
function getOpenIntentPlatformFee(uint256 intentId) external view returns (uint256);
```

#### getOpenIntentAffiliateFee()

Calculates the affiliate fee applicable to the open intent's fill at the stored price.

```solidity
function getOpenIntentAffiliateFee(uint256 intentId) external view returns (uint256);
```

#### getOpenIntentPremium()

Calculates the total premium for the open intent at the stored price — what PartyA pays to PartyB to open the options position.

```solidity
function getOpenIntentPremium(uint256 intentId) external view returns (uint256);
```

#### getOpenIntentPremiumProportional()

Calculates the premium for the open intent at a supplied price rather than the stored one. Useful for simulating fill outcomes at different price points.

```solidity
function getOpenIntentPremiumProportional(uint256 intentId, uint256 price) external view returns (uint256);
```

***

### Computed Close Intent Views

#### getCloseIntentPlatformFee()

Calculates the platform fee for closing a given quantity of a close intent at the specified price.

```solidity
function getCloseIntentPlatformFee(uint256 intentId, uint256 quantity, uint256 price) external view returns (uint256);
```

#### getCloseIntentAffiliateFee()

Calculates the affiliate fee for closing a given quantity of a close intent at the specified price.

```solidity
function getCloseIntentAffiliateFee(uint256 intentId, uint256 quantity, uint256 price) external view returns (uint256);
```

***

### Computed Trade Views

#### getTradeOpenAmount()

Returns the currently open (unfilled) quantity of a trade — the original quantity minus any amount that has already been partially closed.

```solidity
function getTradeOpenAmount(uint256 tradeId) external view returns (uint256);
```

#### getTradeAvailableAmountToClose()

Returns the quantity of a trade that is currently available to close — the open amount minus any quantity already locked in pending close intents.

```solidity
function getTradeAvailableAmountToClose(uint256 tradeId) external view returns (uint256);
```

#### getTradePnl()

Calculates the P\&L for a trade at a given current price and for a specified filled amount. Uses the same calculation logic as the settlement engine.

```solidity
function getTradePnl(uint256 tradeId, uint256 currentPrice, uint256 filledAmount) external view returns (uint256);
```

#### getTradePremium()

Returns the total premium amount for a trade — what was paid to open the options position.

```solidity
function getTradePremium(uint256 tradeId) external view returns (uint256);
```

#### getTradeExerciseFee()

Calculates the exercise fee that would be charged for a trade given a settlement price and the computed P\&L. Applies the trade's stored `ExerciseFee` rate and cap.

```solidity
function getTradeExerciseFee(uint256 tradeId, uint256 settlementPrice, uint256 pnl) external view returns (uint256);
```
