# Wrap

The wrapping process allows users to deposit **ERC20/ETH fungible tokens** into the **WrapX contract** in exchange for an WToken representation of the deposited value. The following steps outline the technical flow of this process.

#### TLDR: What is Wrap?

* Deposited Tokens to Pool
* Receives WToken
* Transaction is logged on-chain

#### **Flow Breakdown**

1. **User Prepares Wrapping Parameters**\
   The user initiates the wrapping process by specifying:
   * **Recipient Address**: The address that will receive the minted **WToken**.
   * **ETH Wrapping**:
     * Token name is encoded in the `data` parameter.
     * ETH amount is sent as `msg.value`.
   * **ERC20 Wrapping**:
     * `data` parameter includes **slippage protection** (first 32 bytes as `uint256`).
     * Remaining bytes in `data` encode the token name.
2. **User Calls the `wrap` Function**
   * Depending on the asset type, the user calls:
     * **ETH Wrapping**:

       ```solidity
       solidityCopyEditwrap(to, data) {value: ethAmount}
       ```

       * The `data` parameter contains only the **token name**.
     * **ERC20 Wrapping**:

       ```solidity
       solidityCopyEditwrap(to, data)
       ```

       * The `data` parameter contains:
         * **First 32 bytes**: Slippage amount (as `uint256`).
         * **Remaining bytes**: Token name.
3. **System Validates Parameters**\
   Before proceeding with wrapping, the smart contract performs the following checks:
   * **Token Name Validity**: Extracts and validates the token name from `data`.
   * **Maximum Supply Constraint**: Ensures the new mint does not exceed the contract's defined supply cap.
   * **Payment Verification**:
     * For **ETH**: Confirms that `msg.value` matches the required amount.
     * For **ERC20**: Ensures the caller has approved and transferred the required token amount.
4. **System Calculates Fees**
   * The contract applies a **1% fee** based on the **base wrapped value**.&#x20;
   * The remaining amount defines the **wrapped asset value**.
5. **System Mints an WToken**
   * A new **WToken is minted** to the specified recipient.
   * The WToken includes:
     * A **unique `tokenId`**.
     * An **associated name**, derived from the provided parameters.
     * **Metadata** referencing the wrapped asset value.
6. **System Emits a `Wrap` Event**
   * A blockchain event is emitted with details, including:
     * The **recipient's address**.
     * The **WToken’s tokenId**.
     * The **amount wrapped** (ETH or ERC20).
     * The **fee deducted**.

***

#### **Outcome**

* The **user receives an WToken** representing their wrapped assets.
* The **contract holds the deposited WTokens**, ensuring they can later be unwrapped.
* The transaction is **logged on-chain**, allowing for future tracking.

<figure><img src="https://2893729312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fvn1xEZY5M6YAiIBwmr9F%2Fuploads%2F393p8DZolFc8TUK9L9BK%2F2.drawio.png?alt=media&#x26;token=606e6e84-f11f-4c47-9b63-274c152b1657" alt=""><figcaption><p>WrapX - Wrap</p></figcaption></figure>
