Skip to main content

FPMM Factory

Overview

The Factory contract serves as a crucial component in the GPM ecosystem. Its primary function is to create and deploy new instances of FixedProductMarketMaker (FPMM) contracts for each prediction market. When the PredictionsOracle contract initiates the creation of a new market, it calls upon the Factory to generate a dedicated FPMM contract for that specific market.

The factory's role is to standardize and streamline the process of FPMM creation, ensuring that each market has its own isolated instance for liquidity provision and trading. This separation allows for better scalability and management of individual markets within the broader GPM system.

Key Features and Considerations

  1. Flexible Market Creation: Allows for the creation of markets with different collateral tokens, condition IDs, fees, and end times.

  2. Event Logging: Emits detailed events for each market creation, facilitating off-chain tracking and indexing.

  3. No State Storage: The FPMMFactory itself doesn't store any state, making it lightweight and gas-efficient.

  4. Integration with ConditionalTokens: Works directly with the ConditionalTokens contract, allowing for seamless integration within the prediction market ecosystem.

Contract Details

  • License: MIT
  • Solidity Version: ^0.8.24
  • Source Code: FPMM Factory

Events

event FixedProductMarketMakerCreation(
address indexed creator,
FixedProductMarketMaker fixedProductMarketMaker,
ConditionalTokens indexed conditionalTokens,
IERC20 indexed collateralToken,
bytes32[] conditionIds,
uint fee
);

This event is emitted when a new FixedProductMarketMaker is created. It includes:

  • creator: Address of the account that created the market maker.
  • fixedProductMarketMaker: Address of the newly created FPMM contract.
  • conditionalTokens: Address of the ConditionalTokens contract used.
  • collateralToken: Address of the ERC20 token used as collateral.
  • conditionIds: Array of condition IDs for the market.
  • fee: Fee percentage set for the market.

Function Signatures and Descriptions

constructor

constructor() {}

An empty constructor. The FPMMFactory contract doesn't need any initialization.

createFixedProductMarketMaker

function createFixedProductMarketMaker(
ConditionalTokens conditionalTokens,
IERC20 collateralToken,
bytes32[] calldata conditionIds,
uint fee,
uint marketEndTime,
address oracleAddress
) external returns (FixedProductMarketMaker fpmm)

Creates a new FixedProductMarketMaker instance.

Parameters:

  • conditionalTokens: Address of the ConditionalTokens contract.
  • collateralToken: Address of the ERC20 token used as collateral.
  • conditionIds: Array of condition IDs for the market.
  • fee: Fee percentage for the market.
  • marketEndTime: Timestamp when the market ends.
  • oracleAddress: Address of the oracle contract.

Returns:

  • fpmm: Address of the newly created FixedProductMarketMaker.

This function performs the following steps:

  1. Retrieves the bytecode of the FixedProductMarketMaker contract.
  2. Generates a unique salt for CREATE2 based on the input parameters.
  3. Uses CREATE2 to deploy a new FixedProductMarketMaker with a deterministic address.
  4. Initializes the newly created FixedProductMarketMaker.
  5. Emits a FixedProductMarketMakerCreation event.

Usage Example

// Deploy the Factory contract
Factory factory = new Factory();

// Create a new FixedProductMarketMaker
FixedProductMarketMaker fpmm = factory.createFixedProductMarketMaker(
ConditionalTokens(conditionalTokensAddress),
IERC20(collateralTokenAddress),
conditionIds,
fee,
marketEndTime,
oracleAddress
);

// The address of the new FPMM can now be used to interact with the market

Security Considerations

  1. Input Validation: The createFixedProductMarketMaker function doesn't perform extensive input validation. It's crucial to ensure that valid parameters are passed, especially for the fee and marketEndTime.

  2. Predictable Addresses: While deterministic addresses can be beneficial, they also allow anyone to predict the address of a market before it's created. This should be considered in the broader system design.

  3. No Access Control: The createFixedProductMarketMaker function is callable by anyone. If restrictions on who can create markets are needed, they should be implemented at a higher level or by modifying this contract.

  4. Dependence on External Contracts: The FPMMFactory relies on the correct implementation of the FixedProductMarketMaker, ConditionalTokens, and IERC20 contracts. Ensure these contracts are secure and correctly implemented.