Manager Contract

The Manager.sol contract serves as the central coordination layer for the entire Worldbook ecosystem. It implements sophisticated access control, fee management, orderbook registration, and emergency response capabilities.

Contract Overview

  • File: Manager.sol

  • Size: ~900 lines of code

  • Role: Central coordination and control layer

  • Security: Role-based access control with inheritance hierarchy

Key Responsibilities

1. Access Control System

  • Role Management: Hierarchical role system with inheritance

  • Permission Delegation: Centralized permission checking for all OrderBooks

  • Emergency Controls: Pause/unpause capabilities across the entire system

2. OrderBook Registry

  • Registration: Validates and registers new OrderBook contracts

  • Bytecode Verification: Ensures only legitimate contracts are registered

  • Pair Management: Manages unique trading pairs and prevents duplicates

3. Fee Management

  • 4-Tier Fee System: Sophisticated fee structure with customization options

  • Maker Rebates: Support for negative maker fees (rebates)

  • Fee Collection: Centralized fee collection and distribution

  • User Discounts: Percentage and absolute discount mechanisms

4. Token Whitelist and Standard Token Registry

  • Quote Token Control: Manages which tokens can be used as quote assets

  • Minimum Amounts: Sets minimum order sizes per token

  • Standard Tokens: Registry for exact-transfer ERC-20s and optional enforcement for BASE on registration

  • Dynamic Management: Add/remove tokens from whitelist

5. Self-Trade Prevention (STP)

  • User STP Modes: Configurable self-trade prevention behavior

  • Three Modes: NONE, EXPIRE_MAKER, and SKIP

  • Default Mode: EXPIRE_MAKER for new users

Access Control Architecture

Role Hierarchy

Important: ADMIN_ROLE automatically has PAUSER_ROLE privileges through the hasOrderBookRole function implementation. The Manager contract itself also holds PAUSER_ROLE to perform batch pause/unpause.

Role Definitions

Role Capabilities

DEFAULT_ADMIN_ROLE:

  • Grant and revoke ADMIN_ROLE

  • Grant and revoke PAUSER_ROLE

  • Role management only (no operational privileges)

ADMIN_ROLE:

  • All operational functions

  • Fee management

  • OrderBook registration control

  • Token whitelist management

  • System configuration

  • Inherits PAUSER_ROLE privileges

PAUSER_ROLE:

  • Emergency pause/unpause operations

  • Community managers and emergency responders

  • Limited to emergency response only

Fee Management System

4-Tier Fee Structure

Worldbook implements a sophisticated fee system with four layers:

Layer 1: Default Fees

Maker Rebates:

  • Maker fees can be negative to incentivize liquidity provision

  • Rebates are funded from taker fees

  • Maximum rebate: 0.05% (500 basis points, different from max fee of 0.5%)

Layer 2: OrderBook-Specific Overrides

Layer 3: User Percentage Discounts

Layer 4: User Absolute Discounts

Fee Calculation Logic

Fee Collection

OrderBook Registration System

Registration Process

Validation Steps:

  1. Access Control: If allowAnyoneRegisterOrderBook is false, only ADMIN_ROLE may register. Callers with FACTORY_ROLE bypass bytecode checks.

  2. Registration Fee: Require payment of registrationFee (admins exempt)

  3. Input Validation: Verify token addresses and uniqueness

  4. Quote Token Check: Ensure quote token is whitelisted (if active)

  5. Bytecode Verification: Verify contract matches expected bytecode (exact or normalized hash)

  6. Parameter Verification: Validate OrderBook configuration

  7. Storage: Store registration and emit event

  8. Fee Transfer: Send fee to collector, refund excess

Registration Fee System

The Manager supports optional registration fees for OrderBook creation:

Key Features:

  • Admin role is exempt from registration fees

  • Fees are sent directly to the fee collector

  • Excess payment is automatically refunded

  • Can be set to 0 to disable fees

  • Prevents spam OrderBook creation

Bytecode Verification

Security Benefits:

  • Prevents registration of malicious contracts

  • Ensures only approved OrderBook versions are used

  • Maintains system integrity and user trust

Normalized Bytecode Verification

To support OrderBooks with different immutable constructor parameters (manager/base/quote addresses, decimals, scales), the Manager can verify a canonical normalized runtime hash:

If the caller has FACTORY_ROLE, bytecode checks are skipped to allow trusted factories to register books.

Normalized Bytecode Verification

To support OrderBooks with different immutable constructor parameters (manager/base/quote addresses, decimals, scales), the Manager can verify a canonical normalized runtime hash:

If the caller has FACTORY_ROLE, bytecode checks are skipped to allow trusted factories to register books.

Pair Management

Quote Token Whitelist System

Whitelist Control

Whitelist Management

Emergency Controls

System-Wide Pause

System-Wide Unpause

Batch Pause/Unpause Operations

For more granular control and gas efficiency when dealing with many OrderBooks:

Batch Operation Benefits:

  • Avoids gas limits when pausing/unpausing many OrderBooks

  • Provides pagination for large-scale operations

  • Returns specific addresses that were successfully affected

  • Enables targeted emergency responses

  • Continues operation even if individual OrderBooks fail to pause/unpause

Usage Example:

Pauser Management

Admins can manage who has emergency pause privileges:

Emergency Use Cases:

  • Critical security vulnerabilities discovered

  • Market manipulation attempts

  • Extreme market conditions

  • Regulatory compliance requirements

Configuration Functions

Fee Configuration

Registration Control

Events

Registration Events

Fee Events

Emergency Events

Security Features

Input Validation

  • Zero address checks for all critical parameters

  • Fee rate bounds checking (MAX_FEE = 0.5%, MAX_REBATE = 0.05%)

  • Bytecode hash validation

  • Token pair uniqueness enforcement

Access Control

  • Role-based permissions with inheritance

  • Centralized role checking for all OrderBooks

  • Emergency response capabilities

Emergency Response

  • System-wide pause/unpause functionality

  • Graceful error handling (continues if individual OrderBook fails)

  • Event emission for transparency

Standard Token Registry and Token Denylist

Standard ERC-20 Registry

  • When enforcement is enabled, registerOrderBook requires the BASE token to be marked standard.

  • “Standard” means exact-transfer, non-rebasing ERC-20 for gas-fast paths.

Emergency Token Denylist

Denied tokens cannot be used in new OrderBooks (applies to both base and quote), regardless of whitelist status.

Self-Trade Prevention (STP)

STP Modes

The Manager contract supports three STP modes for preventing self-trading:

STP Configuration

STP Behavior

NONE: Self-trades are allowed and executed normally

EXPIRE_MAKER: When self-trade is detected:

  • Maker order is automatically cancelled

  • Collateral is refunded to the maker

  • Taker order continues to match with other orders

SKIP: When self-trade is detected:

  • Maker order is skipped (remains active)

  • Taker order continues to match with other orders

Integration Points

OrderBook Integration

Frontend Integration

  • Event monitoring for system changes

  • Role-based UI elements

  • Real-time fee calculation

  • Emergency status indicators

The Manager contract provides the foundational infrastructure for secure, scalable, and maintainable decentralized exchange operations while maintaining flexibility for future enhancements and community governance.

Last updated