JAMMFactory Contract

JAMMFactory is the core factory contract of JAMM DEX, responsible for creating and managing all trading pairs. It uses CREATE2 deterministic deployment, supports a multi-tier fee system, and has built-in referrer management functionality. The Factory contract is the entry point and control center of the entire protocol.

Contract Basic Information

contract JAMMFactory is IJAMMFactory {
    // Contract Address: 0x6b5d54E6F73e96Ca960DBA71D778b98221939aa6 (Mainnet)
    // Contract Address: 0xbddd716a9d6325700d1c29562c819987e5b1f6a8 (Testnet)
}

Fee Constants

Supported Fee Tiers

uint24 public constant FEE_0_5_PERCENT = 50;   // 0.5%
uint24 public constant FEE_1_PERCENT = 100;    // 1.0%
uint24 public constant FEE_2_PERCENT = 200;    // 2.0%
uint24 public constant FEE_3_PERCENT = 300;    // 3.0%

These four constants define all fee tiers supported by JAMM DEX:

  • Base: 10000 (i.e., 100%)

  • 0.5%: 50/10000 = 0.005

  • 1.0%: 100/10000 = 0.01

  • 2.0%: 200/10000 = 0.02

  • 3.0%: 300/10000 = 0.03

State Variables

Management Addresses

Address Description:

  • mintTo: Address receiving protocol fees (in LP token form)

  • feeTo: Address receiving trading fees

  • feeToSetter: Administrator with exclusive permission to modify the above addresses

Trading Pair Registry

Data Structure:

  • getPair[tokenA][tokenB][fee]: Three-dimensional mapping to find trading pairs by token addresses and fee rate

  • allPairs: Array of all trading pair addresses for iteration

Referrer System

Records the referrer address corresponding to each user (tx.origin).

Initialization Code Hash

This hash value is used for CREATE2 address calculation to ensure deterministic trading pair addresses. The actual value is determined at contract deployment time.

Core Functions

Constructor

Sets the fee administrator address during deployment, which is the only initialization parameter.

Create Trading Pair

Creation Process:

  1. Parameter Validation: Check token address validity and fee rate legality

  2. Token Sorting: Ensure token0 < token1 to guarantee uniqueness

  3. Duplicate Check: Ensure trading pair with same parameters doesn't exist

  4. CREATE2 Deployment: Deploy new JAMMPair contract using deterministic address

  5. Initialization: Call initialize function of new contract

  6. Registration: Update mapping tables and arrays

  7. Event Emission: Emit PairCreated event

Query Functions

Returns the total number of created trading pairs.

Management Functions

Set Protocol Fee Recipient Address

Set Trading Fee Recipient Address

Set Fee Administrator

Access Control: All management functions can only be called by the current feeToSetter.

Referrer Management

Features:

  • Uses tx.origin instead of msg.sender

  • Each user can only set referrer once

  • Cannot be modified after setting

Event System

PairCreated Event

Records the creation of new trading pairs, including:

  • token0: First token address after sorting

  • token1: Second token address after sorting

  • fee: Fee rate

  • pair: Address of newly created trading pair

  • Last parameter: Current total number of trading pairs

Referrer Event

Records the establishment of referrer relationships.

CREATE2 Address Calculation

Address Pre-calculation

Trading pair addresses can be pre-calculated using the following method:

Salt Calculation

Salt consists of three parameters:

  • token0: Smaller token address

  • token1: Larger token address

  • fee: Fee rate value

Usage Examples

Create New Trading Pair

Query Trading Pairs

Set Referrer

Listen to Events

Last updated