Setup

The function used by the contract deployer to set up AMM parameters. This must be called before users can interact with the contract.

function setup(
    address _oracle,
    bytes32 _questionId,
    uint _numOutcomes,
    uint _subsidy,
    uint _overround
  ) public onlyOwner() {
    require(init == false,'Already init');
    require(_overround > 0,'Cannot have 0 overround');
    CT.prepareCondition(_oracle, _questionId, _numOutcomes);
    condition = CT.getConditionId(_oracle, _questionId, _numOutcomes);

    IERC20(token).safeTransferFrom(msg.sender, address(this), _subsidy);

    numOutcomes = _numOutcomes;
    int128 n = ABDKMath.fromUInt(_numOutcomes);
    int128 initial_subsidy = getTokenEth(token, _subsidy);

    int128 overround = ABDKMath.divu(_overround, 10000); //TODO: if the overround is too low, then the exp overflows
    alpha = ABDKMath.div(overround, ABDKMath.mul(n,ABDKMath.ln(n)));
    b = ABDKMath.mul(ABDKMath.mul(initial_subsidy, n), alpha);

    for(uint i=0; i<_numOutcomes; i++) {
      q.push(initial_subsidy);
    }

    init = true;

    total_shares = ABDKMath.mul(initial_subsidy, n);
    current_cost = cost();
  }

This function allows you to customise the parameters used by the market maker in employing the Ls LMSR algorithm.

This function can only be called by the contract deployer and it is necessary to be called before it is possible to trade with the market maker.

_oracle: this is the address that is required to report the outcome of the prediction market at resolution. It can either be an externally owned account or a reference to another smart contract. This does not need to be the same as the person that deployed the contract. There are a variety of approaches that can be used for choosing the oracle and we discuss these further below.

_questionId: This is a unique bytes32 representation of the question ID. This ID will be used by the oracle in order to report the outcome (and can therefore be used to allow a single oracle to report on multiple events). The question ID could be an ipfs hash to a file storing metadata for the prediction market (such as a description of each of the outcomes).

_numOutcomes: an integer representing the number of discrete outcomes available for the market.

_subsidy: this represents the total amount of tokens that will be used to fund the market maker and can be viewed as the initial liquidity. The properties of the LsLMSR are such that choosing large numbers for _subsidy (ie where you fund the market maker with large amounts of capital) provides a tighter spread for traders, however results in higher potential losses (bounded loss is proportional to initial capital)

_overround: this represents the amount of profit that can be made by the market maker or the ‘houses edge’. It is expressed in ‘bips’ where a value of 100 is equivalent to 1% profit. For reference, traditional book makers use an overround of between 5 and 10%. It is worth noting here that the calculations used by LsLMSR involve exponential arithmetic. Where the overround value is small, it is possible for the calculation to overflow (this is a limitation of the ethereum virtual machine). The minimum overround is dependent on the number of outcomes for the market and is displayed in the table at the bottom of this page.

In order for the oracle to report the outcome of the prediction market, it must call the function reportPayouts() found on the conditional tokens contract. This can either be done directly where the oracle is an externally owned account, or by a separate smart contract.

It is possible to write additional smart contracts that can interact with chainlink nodes or kleros arbitration and parse this information in a manner that can be reported to the conditional tokens contract.

Through the clever use of smart contracts, any information that can be brought on-chain can be used to create a prediction market. 

Minimum overround

Number of outcomesMinimum overround (bps)
2174
3275
4347
5403
6448
7487
8520
9550
10576
11600
12622
13642
14660
15678
16694
17709
18723
19737
20749
21762
22773
23784
24795
25805
26815
27824
28834
29842
30851
31859
32867
33875
34882
35889
36896
37903
38910
39916
40923
41929
42935
43941
44947
45952
46958
47963
48968
49973
50979
51983
52988
53993
54998
551002
561007
571011
581016
591020
601024
611028
621032
631036
641040
651044
661048
671052
681055
691059
701063
711066
721070
731073
741077
751080
761083
771086
781090
791093
801096
811099
821102
831105
841108
851111
861114
871117
881120
891123
901125
911128
921131
931134
941136
951139
961142
971144
981147
991149
1001152
1011154
1021157
1031159
1041162
1051164
1061166
1071169
1081171
1091173
1101176
1111178
1121180
1131182
1141185
1151187
1161189
1171191
1181193
1191195
1201197
1211199
1221202
1231204
1241206
1251208
1261210
1271212
1281214
1291215
1301217
1311219
1321221
1331223
1341225
1351227
1361229
1371230
1381232
1391234
1401236
1411238
1421239
1431241
1441243
1451245
1461246
1471248
1481250
1491251
1501253
1511255
1521256
1531258
1541260
1551261
1561263
1571265
1581266
1591268
1601269
1611271
1621272
1631274
1641275
1651277
1661278
1671280
1681281
1691283
1701284
1711286
1721287
1731289
1741290
1751292
1761293
1771295
1781296
1791297
1801299
1811300
1821302
1831303
1841304
1851306
1861307
1871308
1881310
1891311
1901312
1911314
1921315
1931316
1941317
1951319
1961320
1971321
1981323
1991324
2001325
2011326
2021328
2031329
2041330
2051331
2061332
2071334
2081335
2091336
2101337
2111338
2121340
2131341
2141342
2151343
2161344
2171345
2181347
2191348
2201349
2211350
2221351
2231352
2241353
2251355
2261356
2271357
2281358
2291359
2301360
2311361
2321362
2331363
2341364
2351365
2361366
2371368
2381369
2391370
2401371
2411372
2421373
2431374
2441375
2451376
2461377
2471378
2481379
2491380
2501381
2511382
2521383
2531384
2541385
2551386