Overview
FHERC20Wrapper enables you to convert standard ERC20 tokens into confidential FHERC20 tokens and vice versa. This creates a privacy layer on top of existing tokens, allowing users to transact privately while maintaining interoperability with the broader DeFi ecosystem.Privacy Layer
Transform transparent ERC20 balances into encrypted FHERC20 balances for confidential transactions.
Reversible
Unwrap confidential tokens back to standard ERC20 at any time through a secure claim process.
1:1 Backing
Each wrapped token is backed 1:1 by the underlying ERC20 token held in the wrapper contract.
DeFi Bridge
Bridge between transparent DeFi protocols and confidential trading/transfers.
How It Works
Wrap Tokens
User deposits standard ERC20 tokens into the wrapper contract, which mints an equivalent amount of confidential FHERC20 tokens.
Confidential Transfers
User can now transfer the wrapped tokens confidentially using all FHERC20 features while balances remain encrypted.
Unwrap Request
When ready to exit, user burns confidential tokens. The burned amount is marked as publicly decryptable via
FHE.allowPublic, and a claim is created.Decrypt Off-Chain
The user (or anyone) requests decryption of the burned amount off-chain via
decryptForTx, receiving the plaintext and a Threshold Network signature.Wrapping Tokens
Function Signature
to: Address to receive the wrapped (confidential) tokensvalue: Amount of ERC20 tokens to wrap
How Wrapping Works
- User approves wrapper contract to spend ERC20 tokens
- Wrapper transfers ERC20 tokens from user to itself
- Wrapper mints equivalent confidential FHERC20 tokens to recipient
- Wrapped tokens can now be used confidentially
Example
Unwrapping Tokens
Unwrapping is a three-step process: burn on-chain, decrypt off-chain, then claim with proof.Step 1: Unwrap (Burn and Allow Public Decryption)
to: Address to receive the unwrapped ERC20 tokens (defaults tomsg.senderifaddress(0))value: Amount of confidential tokens to unwrap
- Burns the specified amount of confidential tokens from the caller
- Calls
FHE.allowPublic(burned)so anyone can request decryption of the burned amount - Creates a claim for the recipient
Due to the zero-replacement behavior, if you attempt to unwrap more than your balance, zero tokens will be burned and you’ll have a claim for zero tokens.
Step 2: Decrypt Off-Chain
Retrieve the claim’sctHash using getUserClaims, then request decryption via decryptForTx. Since FHE.allowPublic was called, no permit is needed:
Step 3: Claim Unwrapped Tokens
Submit the plaintext and signature to the contract. The contract verifies the proof and transfers the ERC20 tokens:ctHash: The ciphertext hash identifying the claimdecryptedAmount: The plaintext value returned bydecryptForTxdecryptionSignature: The Threshold Network signature proving the plaintext is authentic
Claim Management
Getting Claim Information
Getting User Claims
Complete Example
Symbol Management
The wrapper owner can update the token symbol:- Distinguishing wrapped versions (e.g., “wUSDC” vs “USDC”)
- Rebrand if needed
- Fix initial symbol mistakes
Security Considerations
Token Compatibility
Token Compatibility
Always test with the specific token before deploying to production.
Claim Flow
Claim Flow
Claiming requires completing the off-chain decryption step first:Implement proper UI feedback for the decryption step.
Zero-Replacement
Zero-Replacement
If you unwrap more than your balance, you get zero:Always ensure sufficient balance before unwrapping.
Claim Management
Claim Management
Users can accumulate multiple pending claims. Each must be claimed individually with its own decryption proof:Provide UI to track and manage multiple claims.
Use Cases
DEX Privacy
Wrap tokens before trading on a confidential DEX, then unwrap profits. Your trading activity and positions remain private.
Private Payments
Wrap stablecoins for confidential payments, then unwrap to cash out to bank accounts or fiat on-ramps.
Confidential Payroll
Companies can wrap tokens, distribute salaries confidentially, and employees unwrap to receive standard tokens.
Privacy Pools
Create pools where users deposit tokens for privacy, transact confidentially, and withdraw when desired.
Related Topics
- Understand Unwrap Claims for detailed claim management
- Learn about Core Features for confidential transfers
- Review Best Practices for secure implementations