> 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/account-layer-diamond/symmiohook-facet.md).

# SymmioHook Facet

### Overview

The SymmioHook Facet handles the following callbacks:

* **`onOpenPosition`:** No-op. The Account Layer does not need to track position opens (quote IDs are tracked at sendQuote time in the CoreFacet).
* **`onClosePosition`:** Removes the closed quote ID from the virtual account. If the virtual account has no remaining quotes, it is automatically deleted and its funds returned to the parent sub-account.
* **`onCancelQuote`:** Same as close: removes the quote ID and potentially deletes the virtual account.
* **`onFeeCharged`:** No-op. The Account Layer does not need to track fee charges.

***

#### onOpenPosition()

Called by Symmio core when a position is opened. No action is taken; this exists to prevent hook reverts.

```solidity
function onOpenPosition(uint256 quoteId, uint256 filledAmount, uint256 openedPrice, address partyA, address partyB) external onlySymmio whenNotPaused;
```

***

#### onClosePosition()

Called by Symmio core when a position is closed. Removes the quote ID from the virtual account's tracked quotes. If the virtual account has no remaining quotes, the virtual account is automatically deleted.

```solidity
function onClosePosition(uint256 quoteId, uint256 filledAmount, uint256 closedPrice, address partyA, address partyB) external onlySymmio nonReentrant whenNotPaused;
```

**Virtual Account Deletion on Empty:**

When the last quote is removed from a virtual account:

1. Any remaining allocated balance is deallocated and transferred back to the parent sub-account via `internalTransferToBalance`.
2. The virtual account is marked as `isExists = false`.
3. The virtual account address is added to the reuse pool for its isolation type and symbol, allowing future virtual accounts with the same key to reuse the address.
4. The affiliate's `onVirtualAccountDeletion` hook is called.

**Events:** `VirtualAccountDeleted(address account, address parent)` (emitted when auto-deletion occurs)

***

#### onCancelQuote()

Called by Symmio core when a quote is cancelled. Behaves identically to `onClosePosition`: removes the quote ID and potentially triggers virtual account deletion.

```solidity
function onCancelQuote(uint256 quoteId, address partyA, address partyB) external onlySymmio whenNotPaused;
```

***

#### onFeeCharged()

Called by Symmio core when a fee is charged. No action is taken; this exists to prevent hook reverts.

```solidity
function onFeeCharged(uint256 quoteId, uint256 amount, address partyA, address partyB, uint256 symbolId, address affiliate, uint8 feeType) external onlySymmio whenNotPaused;
```

***

#### Access Control

All callback functions include the `onlySymmio` modifier, ensuring they can only be called by the registered Symmio core diamond. This prevents external actors from manipulating virtual account state.


---

# 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/account-layer-diamond/symmiohook-facet.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.
