# Unwrap

The unwrapping process allows an **WToken** holder to exchange their WToken for its underlying asset through the **WrapX contract**. The following steps outline the technical flow for this operation.

#### TLDR: What is Unwrap?

* **WToken** is burned
* Receives **ERC20/ETH fungible tokens**
* Transaction is logged on-chain

#### **Flow Breakdown**

1. **User Prepares Unwrapping Parameters**\
   The user initiates the process by defining the necessary parameters:
   * **Recipient Address**: Specifies who will receive the unwrapped assets.
   * **Token ID**: Identifies the WToken to be unwrapped.
   * **Minimum Expected Output**: Ensures slippage protection by setting a threshold for the unwrapped value.
2. **User Calls the `unwrap()` Function**
   * The user submits a transaction invoking the `unwrap()` function on the **WrapX contract**, providing the prepared parameters.
3. **System Validates the Request**\
   Upon receiving the transaction, the smart contract performs the following checks:
   * **Ownership Verification**: Confirms that the caller either owns the WToken or has been granted approval.
   * **Minimum Output Check**: Ensures that the unwrapped asset's expected value meets or exceeds the specified threshold.
4. **System Calculates the Unwrap Value**\
   The system determines the output amount based on predefined rules:
   * The **FOAMM (Fractional Ownership Automated Market Maker)** model calculates the base amount.
   * A **1% fee** is deducted from the calculated value and transferred to the designated **fee recipient**.
5. **System Burns the WToken**
   * The WrapX contract **permanently removes (burns)** the WToken from circulation, making it non-recoverable.
6. **System Transfers the Unwrapped Asset to the Recipient**\
   Based on the type of WToken being unwrapped, the system executes one of the following transfers:
   * **For WrapXNative** **WTokens** → **ETH** is sent to the recipient.
   * **For WrapXToken** **WTokens** → The corresponding **ERC20 tokens** are transferred.
7. **System Emits an `Unwrap` Event**
   * A blockchain event is emitted, containing transaction details such as:
     * The WToken’s token ID
     * The recipient’s address
     * The amount of unwrapped assets received
     * The applied fee

***

#### **Outcome**

* The **WToken is burned** and removed from circulation.
* The **user receives** the underlying asset **minus the transaction fee**.
* The transaction is **recorded on-chain**, ensuring transparency and traceability.

<figure><img src="https://2893729312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fvn1xEZY5M6YAiIBwmr9F%2Fuploads%2FrPhOZ6l6fLj1qQrUFyfm%2F3.drawio.png?alt=media&#x26;token=0eafc3fa-865f-4caf-b9e8-f89eabc2b9a1" alt=""><figcaption><p>WrapX - Unwrap</p></figcaption></figure>
