StandardMarket

contract StandardMarket is Proxied, Market, StandardMarketData
Title:Standard market contract - Backed implementation of standard markets
Author:Stefan George - <stefan@gnosis.pm>
modifier isCreator()
modifier atStage(Stages _stage)
function fund(uint _funding)
public
 isCreator
 atStage(Stages . MarketCreated)

Allows to fund the market with collateral tokens converting them into outcome tokens

Parameters:
  • _funding – Funding amount
function close()
public
 isCreator
 atStage(Stages . MarketFunded)

Allows market creator to close the markets by transferring all remaining outcome tokens to the creator

function withdrawFees()
public
 isCreator
returns (uint fees)

Allows market creator to withdraw fees generated by trades

Return:Fee amount
function buy(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint maxCost)
public
 atStage(Stages . MarketFunded)
returns (uint cost)

Allows to buy outcome tokens from market maker

Parameters:
  • outcomeTokenIndex – Index of the outcome token to buy
  • outcomeTokenCount – Amount of outcome tokens to buy
  • maxCost – The maximum cost in collateral tokens to pay for outcome tokens
Return:

Cost in collateral tokens

function sell(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint minProfit)
public
 atStage(Stages . MarketFunded)
returns (uint profit)

Allows to sell outcome tokens to market maker

Parameters:
  • outcomeTokenIndex – Index of the outcome token to sell
  • outcomeTokenCount – Amount of outcome tokens to sell
  • minProfit – The minimum profit in collateral tokens to earn for outcome tokens
Return:

Profit in collateral tokens

function shortSell(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint minProfit)
public
returns (uint cost)

Buys all outcomes, then sells all shares of selected outcome which were bought, keeping shares of all other outcome tokens.

Parameters:
  • outcomeTokenIndex – Index of the outcome token to short sell
  • outcomeTokenCount – Amount of outcome tokens to short sell
  • minProfit – The minimum profit in collateral tokens to earn for short sold outcome tokens
Return:

Cost to short sell outcome in collateral tokens

function trade(int[] memory outcomeTokenAmounts, int collateralLimit)
public
 atStage(Stages . MarketFunded)
returns (int netCost)

Allows to trade outcome tokens and collateral with the market maker

Parameters:
  • outcomeTokenAmounts – Amounts of each outcome token to buy or sell. If positive, will buy this amount of outcome token from the market. If negative, will sell this amount back to the market instead.
  • collateralLimit – If positive, this is the limit for the amount of collateral tokens which will be sent to the market to conduct the trade. If negative, this is the minimum amount of collateral tokens which will be received from the market for the trade. If zero, there is no limit.
Return:

If positive, the amount of collateral sent to the market. If negative, the amount of collateral received from the market. If zero, no collateral was sent or received.

function tradeImpl(uint8 outcomeCount, int[] memory outcomeTokenAmounts, int collateralLimit)
private
returns (int netCost, int outcomeTokenNetCost, uint fees)
function calcMarketFee(uint outcomeTokenCost)
public
view
returns (uint)

Calculates fee to be paid to market maker

Parameters:
  • outcomeTokenCost – Cost for buying outcome tokens
Return:

Fee for trade