🖨️Custom Market Creation

The process of creating a new market in our system involves two main steps:

  1. Requesting market creation

  2. Executing the market request.

Step 1: Requesting Market Creation

To initiate the creation of a new market, users need to call the createNewMarket function on the MarketFactory contract.

solidity

function createNewMarket(Input calldata \_input) external payable returns (bytes32 requestKey);

Parameters

_input A struct containing the following information:

  • indexTokenTicker: The custom id for the index token (e.g., "ETH:1" for Ethereum)

  • marketTokenName: The name of the market token

  • marketTokenSymbol: The symbol for the market token

  • strategy: Information about the pricing strategy (if any)

The strategy struct differs depending on the chain, as some chains support Chainlink's push price feed, and some don't.

For chains that support Chainlink's push price feed, the strategy struct looks like this:

struct SecondaryStrategy {
        // Does the asset have a secondary strategy?
        bool exists;
        // What type of secondary strategy is it?
        FeedType feedType;
        // What is the address of the secondary strategy? (Chainlink etc.)
        address feedAddress;
        // What is the feed ID of the secondary strategy? (Pyth)
        bytes32 feedId;
    }

For chains that don't support Chainlink's push price feed, the strategy struct only contains the parameters associated with the Pyth secondary feeds.

struct SecondaryStrategy {
        // Does the asset have a secondary strategy?
        bool exists;
        // What is the feed ID of the secondary strategy? (Pyth)
        bytes32 feedId;
    }

Return Value

  • requestKey: A unique identifier for the market creation request.

Important Notes

  • The ticker must follow a specific format: TICKER:RANK (e.g., "ETH:1" for Ethereum).

  • The function is payable and requires sending ETH to cover the market creation fee and price update fee.

  • The market for that specific customId must not already exist, or the request will fail.

  • There's a minimum cancellation time (3 minutes by default) before a request can be cancelled.

Step 2: Executing Market Request

After a market creation request has been made and the price has been updated, anyone can execute the market request to finalize the market creation.

The price should be updated automatically.

If successful, the market's state will be initialized within all of the main storage contracts (Market, MarketFactory, TradeStorage, PriceFeed etc.), and 2 new smart contracts will be generated, unique to the new market:

  • Vault: The smart contract responsible for storing all funds associated with the market and handling accounting.

  • RewardTracker: The smart contract responsible for handling the distribution of rewards associated with the market.

The original requester will receive the PoolOwner role, which will enable them to manage configuration for the market, and claim rewards.

solidity

function executeMarketRequest(bytes32 \_requestKey) external nonReentrant returns (MarketId id)

Parameters

  • _requestKey: The unique identifier of the market creation request (returned from createNewMarket).

Return Value

  • id: The unique identifier (MarketId) of the newly created market.

Important Notes

  • This function can be called by anyone, not just the original requester.

  • The caller of this function receives the marketExecutionFee as a reward for executing the request.

Additional Information

  • Users can cancel their market creation requests after a minimum time period using the cancelCreationRequest function.

  • The contract owner can update various parameters such as fees, default configurations, and associated contracts.

By following these two steps, users can create new markets for over 16,000 assets in the system. The two-step process allows for price verification and helps prevent spam or malicious market creations.

Last updated