Skip to main content

GMD Exchange

GMD Exchange facilitates creation of prediction markets, which relies on GMD Oracle for outcome resolution. Users may trade bets via orderbook or take part in tote markets.

GMD Exchange

Smart contract that deploys Market contracts and acts as a central hub for all events emitted by Market contracts.


Interface Definition

Public interface provides a standardized set of functions to interact with the exchange onchain. Exchange acts as notification hub for Settlement events logged by Markets. Allows for indexing events by market and account involved.

pragma solidity ^0.8.20;

import {MarketLib} from "./MarketLib.sol";
import {EventLib} from "../oracle/EventLib.sol";

interface IExchange {
// Fee Policy & Management

// Returns the fee policy for a given account, including taker, maker, and settlement rates.
function getFeeRate(address _account) external view returns (MarketLib.FeePolicy memory);

// Retrieves the fee pool address for a specific currency.
function getFeePool(address _currency) external view returns (address);

// Market & Event Queries

// Returns the current state of a market, including parameters and resolution status.
function getMarket(address _market) external view returns (MarketLib.MarketParams memory);

// Fetches the outcome of an event from the oracle.
function getEventOutcome(bytes32 _eventId) external view returns (EventLib.EventOutcome memory);

// Retrieves current event state and details.
function getEvent(bytes32 _eventId) external view returns (EventLib.Event memory);

// Events
event FeeRateUpdated(address indexed account, int256 takerRate, int256 makerRate, uint256 settleRate);
event CurrencyPoolAdded(address currency, address pool);

// Market state events
event MarketTypeAdded(string _type, address _contract);
event MarketCreated(address indexed market, string name, bytes32 description, uint256 expiry);
event MarketPaused(address indexed market, string name);
event MarketResumed(address indexed market, string name);
event MarketResolved(
address indexed market,
MarketLib.MarketState state,
EventLib.OutcomeType _type,
int256[] outcome,
uint256 amount
);
event MarketExpirySet(address indexed market, uint256 expiry);
event FeesClaimed(address indexed market, uint256 amount);
event MarketSwept(address indexed market, uint256 amount);

// Trade state events
event Match(
address indexed market,
address indexed maker,
address indexed taker,
bytes takerSide,
uint256 amount,
uint256 price,
uint256 timestamp
);
event FillDetails(
address indexed market,
address indexed account,
uint256 contract_spend,
uint256 contract_receive,
uint256 currency_spend,
uint256 currency_receive,
int256 currency_net,
int256 reward_fee,
int256 pool_net
);
event ToteStaked(address indexed market, address indexed account, bytes side, uint256 amount);
event RewardsClaimed(address indexed market, address indexed account, uint256 amount);
}

GMD Market

Gameday prediction market contract, which matches participant interests via orderbook or tote markets. Gameday binary swap implementation allows users to seamlessly enter and exit option positions - optimizing capital utilization for high volume traders.

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {MarketLib} from "./MarketLib.sol";

interface IBetPool {
event MarketResumed(address indexed market);
event MarketPaused(address indexed market);

error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
error PoolSwapInsufficientAllowance(address token, address from, uint256 allowance);
error PoolSwapInsufficientBalance(address token, address sender, uint256 balance);

/**
* @dev Returns market state concatenated into ContractState struct.
*/
function getState() external view returns (MarketLib.MarketParams memory);

/**
* @dev Returns all non-zero balances encoded with abi.encode(bytes[] keys, uint256[] values)
*
* Event balances represents claimable rewards if market resolves to that outcome.
*/
function getBalances(address _account) external view returns (bytes[] memory, uint256[] memory);

function getBalances() external view returns (bytes[] memory, uint256[] memory);

/**
* @dev Returns poolBalance of _account.
*
* Total amount staked in the pool by _account.
*
*/
function getStakedBalance(address _account) external view returns (uint256);

function getStakedBalance() external view returns (uint256);

/**
* @dev Get total outstanding staked balance.
*
* totalSupply is the sum of poolBalances, it is equal to sum of yes or no balances.
*/
function getTotalSupply() external view returns (uint256);

/**
* @dev Get exchange address.
*
* Exchange is the contract that manages fee rates and market creation.
* It sets the feePool address where fees are transfered when fees are claimed.
*/
function getExchange() external view returns (address);

/**
* @dev Get staking token address.
*
* Staking token is the token used to stake in the pool.
*/
function getCurrency() external view returns (address);

/**
* @dev Get unclaimed amount fees collected by the contract.
*/
function getFees() external view returns (uint256);

/**
* @dev Get total volume of matched bets by the market.
*/
function getVolume() external view returns (uint256);

/**
* @dev If market is resolved, transfer rewards less fees to msg.sender, returns rewards amount.
*/
function sweepRewards() external returns (uint256);

/**
* @dev If market is resolved, transfer rewards less fees to _account, returns rewards amount.
*/
function sweepRewards(address _account) external returns (uint256);

/**
* @dev If market is unresolved within 7 days, anyone can set market resolutionState to refund.
*
* Acts as a failsafe to prevent funds from being locked indefinitely.
* msgSender receives refund amount equal to stakedBalance.
*/
function sweepTimelock() external returns (uint256);

/**
* @dev Transfer fees collected to exchange feePool and returns fees amount.
*/
function claimFees() external returns (uint256);
}