WJU Contract

Overview

WJU (Wrapped JU) is the ERC-20 wrapped version of JuChain's native token JU. As an important component of the JAMM DEX ecosystem, WJU enables JU tokens to seamlessly participate in all DeFi activities. The WJU contract is designed to be simple and secure, providing 1:1 bidirectional exchange functionality.

Contract 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;
}

Token Information:

  • Name: "Wrapped JU"

  • Symbol: "WJU"

  • Decimals: 18 decimal places (same as JU)

  • Exchange Rate: 1 JU = 1 WJU

Core Functions

Wrapping Function (Deposit)

Direct JU Transfer

Users can directly send JU tokens to the WJU contract address, and the contract will automatically call the deposit() function for wrapping.

Active Wrapping Call

Wrapping Process:

  1. Receive JU tokens sent by user

  2. Increase user's WJU balance

  3. Increase WJU total supply

  4. Emit Deposit event

Features:

  • 1:1 exchange rate

  • Instant execution

  • No fees

  • No minimum/maximum limits

Unwrapping Function (Withdraw)

Unwrapping Process:

  1. Check if user has sufficient WJU balance

  2. Decrease user's WJU balance

  3. Transfer corresponding amount of JU tokens to user

  4. Emit Withdrawal event

Security Checks:

  • Balance sufficiency check

  • Uses Solidity 0.8.21's built-in overflow protection

  • Safe ETH transfer

ERC-20 Standard Implementation

Approval Function

Transfer Function

Security Features:

  • Balance sufficiency check

  • Custom error messages

  • Standard event emission

Authorized Transfer Function

Double Checks:

  • Allowance amount check

  • Balance sufficiency check

  • Automatic allowance reduction

Event System

Deposit Event

Records JU token wrapping to WJU operations, containing:

  • sender: Initiator of wrapping operation

  • amount: Amount wrapped

Withdrawal Event

Records WJU token unwrapping to JU operations, containing:

  • sender: Initiator of unwrapping operation

  • amount: Amount unwrapped

ERC-20 Standard Events

Integration in JAMM DEX

Router Integration

JAMMRouter contract deeply integrates WJU functionality:

Automatic Wrapping/Unwrapping

Router automatically performs wrapping/unwrapping when handling JU-related transactions:

Automatic Wrapping in Swaps

Automatic Unwrapping in Swaps

Usage Examples

Basic Wrapping/Unwrapping Operations

Balance Queries

ERC-20 Operations

Event Listening

Batch Operations

Last updated