JAMMERC20 Contract

Overview

JAMMERC20 is the standard implementation of LP tokens in JAMM DEX. It not only fully complies with the ERC-20 standard but also supports EIP-2612 Permit functionality. Each JAMMPair contract inherits from JAMMERC20, giving liquidity tokens complete token functionality and modern authorization mechanisms.

Contract Basic Information

contract JAMMERC20 is IJAMMERC20 {
    string public constant name = "JAMM LPs";
    string public constant symbol = "JAMM-LP";
    uint8 public constant decimals = 18;
    uint public totalSupply;
    mapping(address => uint) public balanceOf;
    mapping(address => mapping(address => uint)) public allowance;
}

Token Information:

  • Name: "JAMM LPs" (unified name for all trading pairs)

  • Symbol: "JAMM-LP" (unified symbol for all trading pairs)

  • Decimals: 18 decimal places

  • Supply: Dynamic, changes based on liquidity addition/removal

EIP-2612 Permit Support

Variable Description:

  • DOMAIN_SEPARATOR: EIP-712 domain separator for signature verification

  • PERMIT_TYPEHASH: Hash value of Permit message type

  • nonces: Nonce for each address to prevent replay attacks

Domain Separator Initialization

Domain Separator Components:

  • Domain type hash

  • Token name hash

  • Version number hash ("1")

  • Chain ID

  • Contract address

Core ERC-20 Functions

Internal Functions

Mint Tokens

Minting Logic:

  1. Increase total supply

  2. Increase target address balance

  3. Emit Transfer event (from zero address)

Burn Tokens

Burning Logic:

  1. Decrease source address balance

  2. Decrease total supply

  3. Emit Transfer event (to zero address)

Internal Approval

Internal Transfer

External Functions

Approval

Transfer

Authorized Transfer

Authorized Transfer Features:

  • Check if allowance is sufficient

  • If allowance is not maximum value, decrease allowance

  • Maximum value allowance won't decrease (saves gas)

Permit Function Details

Permit Function

Permit Process:

  1. Check deadline

  2. Build EIP-712 message digest

  3. Recover signer address

  4. Verify signer is the owner

  5. Execute approval operation

  6. Increment nonce to prevent replay

Message Structure

Structured data for Permit message:

Security Features

Overflow Protection

Uses Solidity 0.8.21's built-in overflow protection:

  • Addition overflow automatically reverts

  • Subtraction underflow automatically reverts

  • No need for additional SafeMath library

Replay Attack Protection

After each permit use, nonce automatically increments to prevent signature reuse.

Signature Verification

Strictly verifies signature validity and signer identity.

Usage Examples

Basic ERC-20 Operations

Permit Signature Generation

Using Permit for Authorization

Using Permit in Router

Event Listening

Listen to Transfer Events

Listen to Approval Events

Last updated