WrapX Docs
  • Welcome to WrapX
    • Introduction
    • Background
    • Technical Doc
      • Wrap
      • Unwrap
      • Deploying a Wrapper Contract
  • ERC7527
    • Introduction
    • Publications
Powered by GitBook
On this page
  1. Welcome to WrapX
  2. Technical Doc

Wrap

Tokens to WToken

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:

        solidityCopyEditwrap(to, data) {value: ethAmount}
        • The data parameter contains only the token name.

      • ERC20 Wrapping:

        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.

    • 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.

PreviousTechnical DocNextUnwrap

Last updated 2 months ago

WrapX - Wrap