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
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 asuint256
).Remaining bytes in
data
encode the token name.
User Calls the
wrap
FunctionDepending on the asset type, the user calls:
ETH Wrapping:
The
data
parameter contains only the token name.
ERC20 Wrapping:
The
data
parameter contains:First 32 bytes: Slippage amount (as
uint256
).Remaining bytes: Token name.
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.
System Calculates Fees
The contract applies a 1% fee based on the base wrapped value.
The remaining amount defines the wrapped asset value.
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.
System Emits a
Wrap
EventA 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.
Last updated