Category: Gnosis (GNO)

Getting to the Core

The first and most foundational of the three primary layers the Gnosis platform is built on is the Gnosis Core. From event token creation and settlement, a market mechanism, and different oracle solutions to a management interface, the Core layer provides all the smart contracts needed to create prediction markets on Gnosis.

So far, we’ve implemented over 25 smart contracts written in Solidity. All contracts are free and open to use. They are released under GPLv3, making sure all extensions and future developments will be free, too. Today, we’d like to give an overview of our contract architecture and show how token trades on a prediction market built on Gnosis would look like.

Two central contracts: Event and Market Contract

Usually, every prediction market consists of two objects: an event object referencing a real world event as well as a market object which connects the market maker with the event.

To create these event and market objects, we have built two central contracts: the event contract and the market contract.

Event Contract

The event contract allows you to create new event contracts which can then be used to resolve markets once the event has occurred.

Every event contract has the following properties:

  1. Oracle
  2. Outcome Tokens
  3. Collateral Tokens

To resolve an event, an event contract needs to get the information about what actually happened in the real world — who won the presidential election; what is Apple’s stock price at the end of the year? Oracles capture this real-world information and set the outcome for an event in the event contract.

Thus, every event contract has to reference a defined Oracle contract (1). Gnosis is Oracle agnostic, i.e. any contract can serve as an Oracle, hence any Oracle solution that will be developed on Ethereum might also be used for Gnosis.

There’s a lot to say about Oracles, that’s why we’ll discuss the different Oracle categories for our prediction market applications as well as the Oracles we’ve already developed in a separate post.

Events can either resolve to an outcome out of a defined list of outcomes (categorical events) or to a number within a defined range (scalar events). An example for a categorical event would be the winner of the World Cup on date X which has a list of teams as outcomes: team A, team B, or team C. An example for a scalar event would be the Apple stock price on date X.

For every event outcome, an ECR-20 compatible outcome token is created. That means that every event contract will be associated with at least two Outcome token contracts (2).

Scalar events are represented with two outcome tokens. One outcome token for long positions, and one for short positions.

Categorical events have an outcome token for every defined outcome (one for team A, team B, and team C in the above World Cup example).

You can buy and sell sets of outcome tokens or long/short tokens in exchange for collateral tokens. A Collateral Token (3) is the currency in which the event is traded, i.e. ETH, BTC, USD, stable coins, etc.

Participating in a prediction market on a categorical event

Let’s picture a prediction market on a categorical event, for example the winner of the World Cup final. The event has two outcomes: Team Germany or Team Argentina. The currency (or collateral token) of the market is ETH.

You participate in the market by investing 10 ETH. For your investment of 10 ETH (collateral token), you will receive 10 outcome tokens for every outcome, i.e. 10 Team Germany tokens and 10 Team Argentina tokens.

You can buy sets of outcome tokens in exchange for collateral tokens.

If you decide to bet on Team Germany, you would sell all outcome tokens for Team Argentina. The price you can ask for Team Argentina tokens depends on the market’s estimate on Team Argentina winning the World Cup. Assuming the market believes that Team Argentina will win with a 70% probability, you can sell 10 Team Argentina tokens for 7 ETH (collateral token).

You can sell sets of outcome tokens in exchange for collateral tokens.

That means that you’ve only invested 10 ETH (initially put in)–7 ETH (received from the Team Argentina token sale) = 3 ETH to purchase the 10 Team Germany tokens.

If Germany indeed wins the World Cup, Team Germany tokens will have a value of 1 while Team Argentina tokens will be worthless. Therefore, you will be able to redeem your 10 Team Germany tokens for 10 ETH and thus make a profit of 10 ETH–3 ETH (invested to purchase Team Germany Tokens) = 7 ETH. Conversely, if Team Argentina wins the World Cup, your Team Germany tokens will have a value of 0. Hence, you will incur a loss of 3 ETH.

The set of outcome tokens has to cover all possible outcomes so that the probability of all outcomes adds up to 100%. Before the event outcome is known, the value of each outcome token represents the probability of that outcome occurring. Once the event outcome is known, the winning outcome has a probability of 100% and therefore is worth 1 while all other losing outcomes have the probability of 0% and therefore are worth 0.

Participating in a prediction market on a scalar event

To illustrate the token creation mechanism with a scalar event, let’s assume there is a prediction market on the Apple Inc. stock price per share at the end of 2017. The stock price ranges between $100 and $200 and the current price per share is $160.

You participate in the market by investing 10 ETH. For your investment of 10 ETH (collateral token), you will receive 10 outcome tokens for long positions and 10 outcome tokens for short positions.

You can buy sets of long/short tokens in exchange for collateral tokens.

If you think that the Apple Inc. stock price will rise until the end of 2017, you would keep your long tokens and sell your short tokens. Now you’re long on Apple! How many tokens you should buy in total depends on your estimate of the year end price and how certain you are of it.

The price you can ask for your short tokens depends on the market’s price estimate on the Apple Inc. stock price at the end of 2017. Assuming the market believes that the price will drop to $140, you can sell your short tokens for (Price_upperbound–Price)/ (Price_upperbound–Price_lowerbound) ETH, i.e. (200–140)/(200–100) = 60/100 = 0.6 ETH each.

You can sell sets of long/short tokens in exchange for collateral tokens.

If at the end of 2017, the Apple Inc. stock price per share is below $100 (the lower bound), long outcome tokens have no value while each short outcome token has the value of 1 ETH (collateral token). If the stock price is higher than $200 (the upper bound), each long outcome token has the value of 1 ETH (collateral token) while short outcome tokens have no value.

The market creator should try to set the upper and lower bounds such that all likely outcomes fall within these limits. When the anticipated outcome falls outside of these limits (or very close to them), the predicitive quality of the prediction market is compromised.

If the price would turn out to be the average value of the defined range, i.e. at $150 in our example, long and short outcome tokens would have the same value.

It turns out that at the end of 2017, the Apple stock price is within the lower and upper bound, at $180. The value of short outcome tokens decreases linearly and the value of long outcome tokens increases linearly the higher the price is in the range.

At market resolution, you would thus get (price–price_lowerbound)/(price_upperbound–price_lowerbound) ETH, i.e. (180–100)/(200–100) = 80/100 = 0.8 ETH for each long token you kept. Additionally, you received 0.6 ETH per short token you sold earlier.

Since you put in 1 ETH as a collateral token, this would leave you with a net profit of (0.8+0.6)–1 ETH = 0.4 ETH.

Thus, both long and short tokens have value once the outcome is known if the resolved value is inside the defined range. Regardless of the final price, the sum payoff of any complete set of outcome tokens (one short and one long outcome token) always corresponds to 1 ETH (collateral token).

Market Contract

The market contract allows you to create new market contracts which can then be used to trade outcome tokens on markets with a market maker. It is not strictly neccessary for an event contract to be accompanied by a market contract but it increases the usability of the prediction market.

Every market contract has the following properties:

  1. Event
  2. Market Maker
  3. Market Fee

A market contract is always associated to an Event (1) and has to be funded to provide initial liquidity and start trading. Markets are funded with collateral tokens, i.e. in the currency in which the event is traded: ETH, BTC, USD, stable coins or the like.

To buy and sell event outcome tokens, the market contract calls a Market Maker (2), a bot which is pricing the outcomes given the current state of the market.

As part of this framework, we implemented an automatic market maker based on the Logarithmic Market Scoring Rule (LMSR) developed by Robin Hanson. An LMSR market maker simply reacts to the supply and demand of outcomes — the prices of outcomes vary as their relative demands do. The more funding a market gets, the larger the trade volume would have to be in order to move the price. We’ll elaborate on the functioning and power of an LMSR market maker in a separate blog post.

If an automated market maker is used, however, the market maker is expected to lose all its funding once the outcome is decided. By the time everyone knows about the market’s outcome, anyone can trade against the market maker by buying all the winning outcome tokens and thus leaving the market maker with all losing outcome tokens. That’s why the market creator is able to define an optional Fee (3) once they’ve created a market maker. The fee essentially is a spread between the bid and ask price and can compensate the market creator for the funding they spent on the market to give it initial liquidity.

We highly encourage you to participate in our first public prediction market to be released by the end of September. And soon you’ll be able to build your own markets on Gnosis, so get ready! 😊 🚀


Getting to the Core was originally published in Gnosis on Medium, where people are continuing the conversation by highlighting and responding to this story.

<div class="infobox"><span class="appendinfo">This article was originally published on: <a href="https://blog.gnosis.pm/" target="_blank">The Gnosis Blog</a> on </span></div>