WJU Wrapped Token
Overview
WJU (Wrapped JU) is the ERC-20 wrapped version of JuChain's native token JU. Since AMM systems require all tokens to follow the ERC-20 standard, the WJU contract provides seamless conversion functionality between JU tokens and ERC-20 tokens, enabling JU tokens to participate in all JAMM DEX trading activities.
Contract Implementation
Basic Information
contract WJU is IWJU {
string public constant override name = "Wrapped JU";
string public constant override symbol = "WJU";
uint8 public constant override decimals = 18;
uint public override totalSupply;
mapping(address => uint) public override balanceOf;
mapping(address => mapping(address => uint)) public override allowance;
}The WJU contract fully implements the ERC-20 standard with the following characteristics:
Name: "Wrapped JU"
Symbol: "WJU"
Decimals: 18 decimal places
1:1 Exchange: 1 JU = 1 WJU
Core Functions
Wrapping Function (Deposit)
Users can wrap JU tokens into WJU through two methods:
Method 1: Direct JU Transfer
Users directly send JU tokens to the WJU contract address, and the contract automatically calls the deposit() function.
Method 2: Call deposit Function
Wrapping Process:
User sends JU tokens to the contract
Contract increases user's WJU balance
Increases WJU total supply
Triggers Deposit event
Unwrapping Function (Withdraw)
Users can convert WJU tokens back to JU tokens:
Unwrapping Process:
Check if user has sufficient WJU balance
Decrease user's WJU balance
Transfer corresponding amount of JU tokens to user
Trigger Withdrawal event
ERC-20 Standard Implementation
Transfer Function
Authorized Transfer Function
Approval Function
Event System
Deposit Event
Records JU token wrapping into WJU operations.
Withdrawal Event
Records WJU token unwrapping into JU operations.
ERC-20 Standard Events
Application in JAMM DEX
Router Integration
The JAMMRouter contract is deeply integrated with WJU, providing convenient JU token trading functionality:
JU Token Trading
Buy Tokens with JU
Trading Flow:
User sends JU tokens
Router wraps JU into WJU
Transfer WJU to trading pair
Execute swap logic
User receives target tokens
Sell Tokens for JU
Trading Flow:
User approves and transfers tokens
Execute swap to get WJU
Router unwraps WJU into JU
Transfer JU tokens to user
Liquidity Management
Add JU Liquidity
Remove JU Liquidity
Usage Examples
Basic Wrapping/Unwrapping
Query Balances
Listen to Events
Security Considerations
Contract Security
Simple Design: WJU contract logic is simple, reducing security risks
No Admin: Contract has no admin functions, completely decentralized
1:1 Exchange: Strict 1:1 exchange ratio that cannot be manipulated
Usage Security
Balance Checks: All operations check if balance is sufficient
Overflow Protection: Uses Solidity 0.8.21's built-in overflow protection
Event Logging: All operations have corresponding event records
Best Practices
For Users
Timely Unwrapping: If not needed for DEX use, promptly unwrap WJU to JU
Balance Management: Maintain appropriate WJU balance for trading
Gas Optimization: Batch operations to save gas fees
For Developers
Path Validation: In JU-related trades, ensure path correctly includes WJU
Balance Display: Show both JU and WJU balances in UI
Auto Wrapping: Provide automatic wrapping/unwrapping functionality for users
Summary
WJU wrapped token is an important component of the JAMM DEX ecosystem:
Seamless Integration: Enables JU tokens to participate in all DEX functions
1:1 Exchange: Guarantees complete value parity
Automation: Router contract automatically handles wrapping/unwrapping
Standard Compliance: Fully compliant with ERC-20 standard
Decentralization: No need to trust third parties, completely managed by smart contracts
The existence of WJU enables JuChain users to conveniently use native tokens to participate in DeFi activities. In the next section, we will explore LP Token Mechanisms.