UNPKG

@gnosis.pm/pm-contracts

Version:

Collection of smart contracts for the Gnosis prediction market platform

739 lines 1.19 MB
{ "contractName": "StandardMarketProxy", "abi": [ { "constant": true, "inputs": [], "name": "creator", "outputs": [ { "name": "", "type": "address" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "marketMaker", "outputs": [ { "name": "", "type": "address" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "createdAtBlock", "outputs": [ { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { "name": "", "type": "uint256" } ], "name": "netOutcomeTokensSold", "outputs": [ { "name": "", "type": "int256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "masterCopy", "outputs": [ { "name": "", "type": "address" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "stage", "outputs": [ { "name": "", "type": "uint8" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "funding", "outputs": [ { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "fee", "outputs": [ { "name": "", "type": "uint24" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "eventContract", "outputs": [ { "name": "", "type": "address" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "FEE_RANGE", "outputs": [ { "name": "", "type": "uint24" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "inputs": [ { "name": "proxy", "type": "address" }, { "name": "_creator", "type": "address" }, { "name": "_eventContract", "type": "address" }, { "name": "_marketMaker", "type": "address" }, { "name": "_fee", "type": "uint24" } ], "payable": false, "stateMutability": "nonpayable", "type": "constructor" }, { "payable": true, "stateMutability": "payable", "type": "fallback" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "funding", "type": "uint256" } ], "name": "MarketFunding", "type": "event" }, { "anonymous": false, "inputs": [], "name": "MarketClosing", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "fees", "type": "uint256" } ], "name": "FeeWithdrawal", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "name": "buyer", "type": "address" }, { "indexed": false, "name": "outcomeTokenIndex", "type": "uint8" }, { "indexed": false, "name": "outcomeTokenCount", "type": "uint256" }, { "indexed": false, "name": "outcomeTokenCost", "type": "uint256" }, { "indexed": false, "name": "marketFees", "type": "uint256" } ], "name": "OutcomeTokenPurchase", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "name": "seller", "type": "address" }, { "indexed": false, "name": "outcomeTokenIndex", "type": "uint8" }, { "indexed": false, "name": "outcomeTokenCount", "type": "uint256" }, { "indexed": false, "name": "outcomeTokenProfit", "type": "uint256" }, { "indexed": false, "name": "marketFees", "type": "uint256" } ], "name": "OutcomeTokenSale", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "name": "buyer", "type": "address" }, { "indexed": false, "name": "outcomeTokenIndex", "type": "uint8" }, { "indexed": false, "name": "outcomeTokenCount", "type": "uint256" }, { "indexed": false, "name": "cost", "type": "uint256" } ], "name": "OutcomeTokenShortSale", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "name": "transactor", "type": "address" }, { "indexed": false, "name": "outcomeTokenAmounts", "type": "int256[]" }, { "indexed": false, "name": "outcomeTokenNetCost", "type": "int256" }, { "indexed": false, "name": "marketFees", "type": "uint256" } ], "name": "OutcomeTokenTrade", "type": "event" } ], "metadata": "{\"compiler\":{\"version\":\"0.5.6+commit.b259423e\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"constant\":true,\"inputs\":[],\"name\":\"creator\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"marketMaker\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"createdAtBlock\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"netOutcomeTokensSold\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"masterCopy\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"stage\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"funding\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"fee\",\"outputs\":[{\"name\":\"\",\"type\":\"uint24\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"eventContract\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"FEE_RANGE\",\"outputs\":[{\"name\":\"\",\"type\":\"uint24\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"proxy\",\"type\":\"address\"},{\"name\":\"_creator\",\"type\":\"address\"},{\"name\":\"_eventContract\",\"type\":\"address\"},{\"name\":\"_marketMaker\",\"type\":\"address\"},{\"name\":\"_fee\",\"type\":\"uint24\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"funding\",\"type\":\"uint256\"}],\"name\":\"MarketFunding\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"MarketClosing\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"fees\",\"type\":\"uint256\"}],\"name\":\"FeeWithdrawal\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"buyer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"outcomeTokenIndex\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"outcomeTokenCount\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"outcomeTokenCost\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"marketFees\",\"type\":\"uint256\"}],\"name\":\"OutcomeTokenPurchase\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"seller\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"outcomeTokenIndex\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"outcomeTokenCount\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"outcomeTokenProfit\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"marketFees\",\"type\":\"uint256\"}],\"name\":\"OutcomeTokenSale\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"buyer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"outcomeTokenIndex\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"outcomeTokenCount\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"cost\",\"type\":\"uint256\"}],\"name\":\"OutcomeTokenShortSale\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"transactor\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"outcomeTokenAmounts\",\"type\":\"int256[]\"},{\"indexed\":false,\"name\":\"outcomeTokenNetCost\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"marketFees\",\"type\":\"uint256\"}],\"name\":\"OutcomeTokenTrade\",\"type\":\"event\"}],\"devdoc\":{\"methods\":{}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/home/alan/src/github.com/gnosis/pm-contracts/contracts/Markets/StandardMarket.sol\":\"StandardMarketProxy\"},\"evmVersion\":\"petersburg\",\"libraries\":{},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"/home/alan/src/github.com/gnosis/pm-contracts/contracts/Events/Event.sol\":{\"keccak256\":\"0xdcacfa25145426b5681ad7d8bafb3c117c92a37b7a0175d72a10b42f130fb8c1\",\"urls\":[\"bzzr://bd10fbdb82f0d50866442c9e95317b3176c8ee067def27d764529973fb36420a\"]},\"/home/alan/src/github.com/gnosis/pm-contracts/contracts/MarketMakers/MarketMaker.sol\":{\"keccak256\":\"0xa71f8ce92412033d0900d44c01f0702aefced87d860cf116c6a4d3efe86913cf\",\"urls\":[\"bzzr://63c5bf60b931bb032fcab23514a3db171b680b11d8c6c05ac8caa88752e3be41\"]},\"/home/alan/src/github.com/gnosis/pm-contracts/contracts/Markets/Market.sol\":{\"keccak256\":\"0x7bc1ebf0ea0f4cd9b6e9bfff6c6ac9088c253bcfca4e27f31e5845799f0278d8\",\"urls\":[\"bzzr://5e3f86d96ab269d284b34563501469d539cc436d62f070dd0abda2519d5e60c0\"]},\"/home/alan/src/github.com/gnosis/pm-contracts/contracts/Markets/StandardMarket.sol\":{\"keccak256\":\"0x527abf1b0997e2d38ce3c97f7ed647b9e913424828594287e2b068f2fb41ad4c\",\"urls\":[\"bzzr://16756e1b212fd40f21de50d99c8b7a5dde0acc2b0b047af8beead831a1274bd7\"]},\"/home/alan/src/github.com/gnosis/pm-contracts/contracts/Oracles/Oracle.sol\":{\"keccak256\":\"0xf4d12f4a59c17e66dfa6791188f621a8914e2038a4e3f72d6fc9fb903ca8e18e\",\"urls\":[\"bzzr://a477ccd203e677cc904b1a4f8fcc85251c5b5e09c5c10eed27e01318584b16d1\"]},\"/home/alan/src/github.com/gnosis/pm-contracts/contracts/Tokens/OutcomeToken.sol\":{\"keccak256\":\"0x3d4c9ec14a60cf7577d366da5116e919a4331da8d6d993174f7d599f84ae74e0\",\"urls\":[\"bzzr://20f87450259a3af24ff1769faa9ab3b714d01921e9d8fa4efa75a0c277837a8a\"]},\"@gnosis.pm/util-contracts/contracts/Proxy.sol\":{\"keccak256\":\"0xeab0e83a9ec9e7f052c0455a11577061ec6d1994db08dae429abd6faaabf6555\",\"urls\":[\"bzzr://b2c1273d4ec30e2f9e768eea8c510f8493a7359b03e01923d93eea86b57ec145\"]},\"openzeppelin-solidity/contracts/drafts/SignedSafeMath.sol\":{\"keccak256\":\"0xb4b45cd5475c318722ac0f8d7e2b9e77fee6f4f36374c1110fe615d50fbc0650\",\"urls\":[\"bzzr://a90fb457269c8a03ec5b811c71acef08a2751a4d2019b0661328610f9357dae7\"]},\"openzeppelin-solidity/contracts/math/SafeMath.sol\":{\"keccak256\":\"0x4ccf2d7b51873db1ccfd54ca2adae5eac3b184f9699911ed4490438419f1c690\",\"urls\":[\"bzzr://1604f5b6d6e916c154efd8c6720cda069e5ba32dfa0a9dedf2b42e5b02d07f89\"]},\"openzeppelin-solidity/contracts/token/ERC20/ERC20.sol\":{\"keccak256\":\"0x852793a3c2f86d336a683b30d688ec3dcfc57451af5a2bf5975cda3b7191a901\",\"urls\":[\"bzzr://07fb42206812a17c1f71e548cfa5cec6f9aa1ae0ca5df870718ca4aa9759d1a5\"]},\"openzeppelin-solidity/contracts/token/ERC20/IERC20.sol\":{\"keccak256\":\"0x90e8c2521653bbb1768b05889c5760031e688d9cd361f167489b89215e201b95\",\"urls\":[\"bzzr://aa8b45b57edafc3d67bc5d916327ea16807fae33f753ca163ae0c4061b789766\"]}},\"version\":1}", "bytecode": "0x608060405234801561001057600080fd5b5060405160a080610895833981018060405260a081101561003057600080fd5b81019080805190602001909291908051906020019092919080519060200190929190805190602001909291908051906020019092919050505084600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100a457600080fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415801561014f5750600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156101675750620f424062ffffff168162ffffff16105b61017057600080fd5b83600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055504360028190555082600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637dc8f0866040518163ffffffff1660e01b815260040160206040518083038186803b15801561026157600080fd5b505afa158015610275573d6000803e3d6000fd5b505050506040513d602081101561028b57600080fd5b810190808051906020019092919050505060ff166040519080825280602002602001820160405280156102cd5781602001602082028038833980820191505090505b50600690805190602001906102e3929190610372565b5080600460146101000a81548162ffffff021916908362ffffff16021790555081600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600760006101000a81548160ff0219169083600281111561036357fe5b021790555050505050506103e4565b8280548282559060005260206000209081019282156103ae579160200282015b828111156103ad578251825591602001919060010190610392565b5b5090506103bb91906103bf565b5090565b6103e191905b808211156103dd5760008160009055506001016103c5565b5090565b90565b6104a2806103f36000396000f3fe6080604052600436106100915760003560e01c8063c040e6b811610059578063c040e6b81461025e578063cb4c86b714610297578063ddca3f43146102c2578063e274fd24146102f7578063fbde47f61461034e57610091565b806302d05d3f146100df5780631f21f9af1461013657806359acb42c1461018d578063a157979c146101b8578063a619486e14610207575b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050366000803760008036600084600019f43d6000803e80600081146100da573d6000f35b3d6000fd5b3480156100eb57600080fd5b506100f4610383565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014257600080fd5b5061014b6103a9565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561019957600080fd5b506101a26103cf565b6040518082815260200191505060405180910390f35b3480156101c457600080fd5b506101f1600480360360208110156101db57600080fd5b81019080803590602001909291905050506103d5565b6040518082815260200191505060405180910390f35b34801561021357600080fd5b5061021c6103f6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561026a57600080fd5b5061027361041b565b6040518082600281111561028357fe5b60ff16815260200191505060405180910390f35b3480156102a357600080fd5b506102ac61042e565b6040518082815260200191505060405180910390f35b3480156102ce57600080fd5b506102d7610434565b604051808262ffffff1662ffffff16815260200191505060405180910390f35b34801561030357600080fd5b5061030c610449565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561035a57600080fd5b5061036361046f565b604051808262ffffff1662ffffff16815260200191505060405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60025481565b600681815481106103e257fe5b906000526020600020016000915090505481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600760009054906101000a900460ff1681565b60055481565b600460149054906101000a900462ffffff1681565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b620f42408156fea165627a7a72305820abf8f0eb5357fd96067807d4c02e415fd7a0917dccb27be6890e8235cf88b6fd0029", "deployedBytecode": "0x6080604052600436106100915760003560e01c8063c040e6b811610059578063c040e6b81461025e578063cb4c86b714610297578063ddca3f43146102c2578063e274fd24146102f7578063fbde47f61461034e57610091565b806302d05d3f146100df5780631f21f9af1461013657806359acb42c1461018d578063a157979c146101b8578063a619486e14610207575b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050366000803760008036600084600019f43d6000803e80600081146100da573d6000f35b3d6000fd5b3480156100eb57600080fd5b506100f4610383565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014257600080fd5b5061014b6103a9565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561019957600080fd5b506101a26103cf565b6040518082815260200191505060405180910390f35b3480156101c457600080fd5b506101f1600480360360208110156101db57600080fd5b81019080803590602001909291905050506103d5565b6040518082815260200191505060405180910390f35b34801561021357600080fd5b5061021c6103f6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561026a57600080fd5b5061027361041b565b6040518082600281111561028357fe5b60ff16815260200191505060405180910390f35b3480156102a357600080fd5b506102ac61042e565b6040518082815260200191505060405180910390f35b3480156102ce57600080fd5b506102d7610434565b604051808262ffffff1662ffffff16815260200191505060405180910390f35b34801561030357600080fd5b5061030c610449565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561035a57600080fd5b5061036361046f565b604051808262ffffff1662ffffff16815260200191505060405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60025481565b600681815481106103e257fe5b906000526020600020016000915090505481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600760009054906101000a900460ff1681565b60055481565b600460149054906101000a900462ffffff1681565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b620f42408156fea165627a7a72305820abf8f0eb5357fd96067807d4c02e415fd7a0917dccb27be6890e8235cf88b6fd0029", "sourceMap": "384:649:9:-;;;460:571;8:9:-1;5:2;;;30:1;27;20:12;5:2;460:571:9;;;;;;;;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;460:571:9;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;580:5;644:1:29;621:25;;:11;:25;;;;613:34;;;;;;670:11;657:10;;:24;;;;;;;;;;;;;;;;;;551:137;686:1:9;651:37;;659:14;651:37;;;;:76;;;;;725:1;692:35;;700:12;692:35;;;;651:76;:96;;;;;364:7;731:16;;:4;:16;;;651:96;643:105;;;;;;768:8;758:7;;:18;;;;;;;;;;;;;;;;;;803:12;786:14;:29;;;;841:14;825:13;;:30;;;;;;;;;;;;;;;;;;898:13;;;;;;;;;;;:29;;;:31;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;898:31:9;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;898:31:9;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;898:31:9;;;;;;;;;;;;;;;;888:42;;;;;;;;;;;;;;;;;;;;;;;;29:2:-1;21:6;17:15;117:4;105:10;97:6;88:34;148:4;140:6;136:17;126:27;;0:157;888:42:9;;;;865:20;:65;;;;;;;;;;;;:::i;:::-;;946:4;940:3;;:10;;;;;;;;;;;;;;;;;;974:12;960:11;;:26;;;;;;;;;;;;;;;;;;1004:20;996:5;;:28;;;;;;;;;;;;;;;;;;;;;;;;460:571;;;;;384:649;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;", "deployedSourceMap": "384:649:9:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;848:19:29;870:10;;;;;;;;;;;848:32;;932:14;929:1;926;913:34;1031:1;1028;1012:14;1009:1;996:11;992:1;988:6;975:58;1067:16;1064:1;1061;1046:38;1104:7;1129:1;1124:38;;;;1195:16;1192:1;1185:27;1124:38;1143:16;1140:1;1133:27;873:22:8;;8:9:-1;5:2;;;30:1;27;20:12;5:2;873:22:8;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;965:30;;8:9:-1;5:2;;;30:1;27;20:12;5:2;965:30:8;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;901:26;;8:9:-1;5:2;;;30:1;27;20:12;5:2;901:26:8;;;:::i;:::-;;;;;;;;;;;;;;;;;;;1049:33;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1049:33:8;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;1049:33:8;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;205:25:29;;8:9:-1;5:2;;;30:1;27;20:12;5:2;205:25:29;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;1088:19:8;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1088:19:8;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1024;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1024:19:8;;;:::i;:::-;;;;;;;;;;;;;;;;;;;1001:17;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1001:17:8;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;933:26;;8:9:-1;5:2;;;30:1;27;20:12;5:2;933:26:8;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;329:42:9;;8:9:-1;5:2;;;30:1;27;20:12;5:2;329:42:9;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;873:22:8;;;;;;;;;;;;;:::o;965:30::-;;;;;;;;;;;;;:::o;901:26::-;;;;:::o;1049:33::-;;;;;;;;;;;;;;;;;;;;;;;;;:::o;205:25:29:-;;;;;;;;;;;;;:::o;1088:19:8:-;;;;;;;;;;;;;:::o;1024:::-;;;;:::o;1001:17::-;;;;;;;;;;;;;:::o;933:26::-;;;;;;;;;;;;;:::o;329:42:9:-;364:7;329:42;:::o", "source": "pragma solidity ^0.5.0;\nimport \"../Markets/Market.sol\";\nimport \"openzeppelin-solidity/contracts/token/ERC20/ERC20.sol\";\nimport \"openzeppelin-solidity/contracts/drafts/SignedSafeMath.sol\";\nimport \"../Events/Event.sol\";\nimport \"../MarketMakers/MarketMaker.sol\";\n\n\ncontract StandardMarketData {\n /*\n * Constants\n */\n uint24 public constant FEE_RANGE = 1000000; // 100%\n}\n\ncontract StandardMarketProxy is Proxy, MarketData, StandardMarketData {\n constructor(address proxy, address _creator, Event _eventContract, MarketMaker _marketMaker, uint24 _fee)\n Proxy(proxy)\n public\n {\n // Validate inputs\n require(address(_eventContract) != address(0) && address(_marketMaker) != address(0) && _fee < FEE_RANGE);\n creator = _creator;\n createdAtBlock = block.number;\n eventContract = _eventContract;\n netOutcomeTokensSold = new int[](eventContract.getOutcomeCount());\n fee = _fee;\n marketMaker = _marketMaker;\n stage = Stages.MarketCreated;\n }\n}\n\n/// @title Standard market contract - Backed implementation of standard markets\n/// @author Stefan George - <stefan@gnosis.pm>\ncontract StandardMarket is Proxied, Market, StandardMarketData {\n using SignedSafeMath for int;\n using SafeMath for uint;\n\n /*\n * Modifiers\n */\n modifier isCreator() {\n // Only creator is allowed to proceed\n require(msg.sender == creator);\n _;\n }\n\n modifier atStage(Stages _stage) {\n // Contract has to be in given stage\n require(stage == _stage);\n _;\n }\n\n /*\n * Public functions\n */\n /// @dev Allows to fund the market with collateral tokens converting them into outcome tokens\n /// @param _funding Funding amount\n function fund(uint _funding)\n public\n isCreator\n atStage(Stages.MarketCreated)\n {\n // Request collateral tokens and allow event contract to transfer them to buy all outcomes\n require( eventContract.collateralToken().transferFrom(msg.sender, address(this), _funding)\n && eventContract.collateralToken().approve(address(eventContract), _funding));\n eventContract.buyAllOutcomes(_funding);\n funding = _funding;\n stage = Stages.MarketFunded;\n emit MarketFunding(funding);\n }\n\n /// @dev Allows market creator to close the markets by transferring all remaining outcome tokens to the creator\n function close()\n public\n isCreator\n atStage(Stages.MarketFunded)\n {\n uint8 outcomeCount = eventContract.getOutcomeCount();\n for (uint8 i = 0; i < outcomeCount; i++)\n require(eventContract.outcomeTokens(i).transfer(creator, eventContract.outcomeTokens(i).balanceOf(address(this))));\n stage = Stages.MarketClosed;\n emit MarketClosing();\n }\n\n /// @dev Allows market creator to withdraw fees generated by trades\n /// @return Fee amount\n function withdrawFees()\n public\n isCreator\n returns (uint fees)\n {\n fees = eventContract.collateralToken().balanceOf(address(this));\n // Transfer fees\n require(eventContract.collateralToken().transfer(creator, fees));\n emit FeeWithdrawal(fees);\n }\n\n /// @dev Allows to buy outcome tokens from market maker\n /// @param outcomeTokenIndex Index of the outcome token to buy\n /// @param outcomeTokenCount Amount of outcome tokens to buy\n /// @param maxCost The maximum cost in collateral tokens to pay for outcome tokens\n /// @return Cost in collateral tokens\n function buy(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint maxCost)\n public\n atStage(Stages.MarketFunded)\n returns (uint cost)\n {\n require(int(outcomeTokenCount) >= 0 && int(maxCost) > 0);\n uint8 outcomeCount = eventContract.getOutcomeCount();\n require(outcomeTokenIndex >= 0 && outcomeTokenIndex < outcomeCount);\n int[] memory outcomeTokenAmounts = new int[](outcomeCount);\n outcomeTokenAmounts[outcomeTokenIndex] = int(outcomeTokenCount);\n (int netCost, int outcomeTokenNetCost, uint fees) = tradeImpl(outcomeCount, outcomeTokenAmounts, int(maxCost));\n require(netCost >= 0 && outcomeTokenNetCost >= 0);\n cost = uint(netCost);\n emit OutcomeTokenPurchase(msg.sender, outcomeTokenIndex, outcomeTokenCount, uint(outcomeTokenNetCost), fees);\n }\n\n /// @dev Allows to sell outcome tokens to market maker\n /// @param outcomeTokenIndex Index of the outcome token to sell\n /// @param outcomeTokenCount Amount of outcome tokens to sell\n /// @param minProfit The minimum profit in collateral tokens to earn for outcome tokens\n /// @return Profit in collateral tokens\n function sell(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint minProfit)\n public\n atStage(Stages.MarketFunded)\n returns (uint profit)\n {\n require(-int(outcomeTokenCount) <= 0 && -int(minProfit) < 0);\n uint8 outcomeCount = eventContract.getOutcomeCount();\n require(outcomeTokenIndex >= 0 && outcomeTokenIndex < outcomeCount);\n int[] memory outcomeTokenAmounts = new int[](outcomeCount);\n outcomeTokenAmounts[outcomeTokenIndex] = -int(outcomeTokenCount);\n (int netCost, int outcomeTokenNetCost, uint fees) = tradeImpl(outcomeCount, outcomeTokenAmounts, -int(minProfit));\n require(netCost <= 0 && outcomeTokenNetCost <= 0);\n profit = uint(-netCost);\n emit OutcomeTokenSale(msg.sender, outcomeTokenIndex, outcomeTokenCount, uint(-outcomeTokenNetCost), fees);\n }\n\n /// @dev Buys all outcomes, then sells all shares of selected outcome which were bought, keeping\n /// shares of all other outcome tokens.\n /// @param outcomeTokenIndex Index of the outcome token to short sell\n /// @param outcomeTokenCount Amount of outcome tokens to short sell\n /// @param minProfit The minimum profit in collateral tokens to earn for short sold outcome tokens\n /// @return Cost to short sell outcome in collateral tokens\n function shortSell(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint minProfit)\n public\n returns (uint cost)\n {\n // Buy all outcomes\n require( eventContract.collateralToken().transferFrom(msg.sender, address(this), outcomeTokenCount)\n && eventContract.collateralToken().approve(address(eventContract), outcomeTokenCount));\n eventContract.buyAllOutcomes(outcomeTokenCount);\n // Short sell selected outcome\n eventContract.outcomeTokens(outcomeTokenIndex).approve(address(this), outcomeTokenCount);\n uint profit = this.sell(outcomeTokenIndex, outcomeTokenCount, minProfit);\n cost = outcomeTokenCount - profit;\n // Transfer outcome tokens to buyer\n uint8 outcomeCount = eventContract.getOutcomeCount();\n for (uint8 i = 0; i < outcomeCount; i++)\n if (i != outcomeTokenIndex)\n require(eventContract.outcomeTokens(i).transfer(msg.sender, outcomeTokenCount));\n // Send change back to buyer\n require(eventContract.collateralToken().transfer(msg.sender, profit));\n emit OutcomeTokenShortSale(msg.sender, outcomeTokenIndex, outcomeTokenCount, cost);\n }\n\n /// @dev Allows to trade outcome tokens and collateral with the market maker\n /// @param 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.\n /// @param 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.\n /// @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.\n function trade(int[] memory outcomeTokenAmounts, int collateralLimit)\n public\n atStage(Stages.MarketFunded)\n returns (int netCost)\n {\n uint8 outcomeCount = eventContract.getOutcomeCount();\n require(outcomeTokenAmounts.length == outcomeCount);\n\n int outcomeTokenNetCost;\n uint fees;\n (netCost, outcomeTokenNetCost, fees) = tradeImpl(outcomeCount, outcomeTokenAmounts, collateralLimit);\n\n emit OutcomeTokenTrade(msg.sender, outcomeTokenAmounts, outcomeTokenNetCost, fees);\n }\n\n function tradeImpl(uint8 outcomeCount, int[] memory outcomeTokenAmounts, int collateralLimit)\n private\n returns (int netCost, int outcomeTokenNetCost, uint fees)\n {\n // Calculate net cost for executing trade\n outcomeTokenNetCost = marketMaker.calcNetCost(this, outcomeTokenAmounts);\n if(outcomeTokenNetCost < 0)\n fees = calcMarketFee(uint(-outcomeTokenNetCost));\n else\n fees = calcMarketFee(uint(outcomeTokenNetCost));\n\n require(int(fees) >= 0);\n netCost = outcomeTokenNetCost.add(int(fees));\n\n require(\n (collateralLimit != 0 && netCost <= collateralLimit) ||\n collateralLimit == 0\n );\n\n if(outcomeTokenNetCost > 0) {\n require(\n eventContract.collateralToken().transferFrom(msg.sender, address(this), uint(netCost)) &&\n eventContract.collateralToken().approve(address(eventContract), uint(outcomeTokenNetCost))\n );\n\n eventContract.buyAllOutcomes(uint(outcomeTokenNetCost));\n }\n\n for (uint8 i = 0; i < outcomeCount; i++) {\n if(outcomeTokenAmounts[i] != 0) {\n if(outcomeTokenAmounts[i] < 0) {\n require(eventContract.outcomeTokens(i).transferFrom(msg.sender, address(this), uint(-outcomeTokenAmounts[i])));\n } else {\n require(eventContract.outcomeTokens(i).transfer(msg.sender, uint(outcomeTokenAmounts[i])));\n }\n\n netOutcomeTokensSold[i] = netOutcomeTokensSold[i].add(outcomeTokenAmounts[i]);\n }\n }\n\n if(outcomeTokenNetCost < 0) {\n // This is safe since\n // 0x8000000000000000000000000000000000000000000000000000000000000000 ==\n // uint(-int(-0x8000000000000000000000000000000000000000000000000000000000000000))\n eventContract.sellAllOutcomes(uint(-outcomeTokenNetCost));\n if(netCost < 0) {\n require(eventContract.collateralToken().transfer(msg.sender, uint(-netCost)));\n }\n }\n }\n\n /// @dev Calculates fee to be paid to market maker\n /// @param outcomeTokenCost Cost for buying outcome tokens\n /// @return Fee for trade\n function calcMarketFee(uint outcomeTokenCost)\n public\n view\n returns (uint)\n {\n return outcomeTokenCost * fee / FEE_RANGE;\n }\n}\n", "sourcePath": "/home/alan/src/github.com/gnosis/pm-contracts/contracts/Markets/StandardMarket.sol", "ast": { "absolutePath": "/home/alan/src/github.com/gnosis/pm-contracts/contracts/Markets/StandardMarket.sol", "exportedSymbols": { "StandardMarket": [ 3199 ], "StandardMarketData": [ 2307 ], "StandardMarketProxy": [ 2389 ] }, "id": 3200, "nodeType": "SourceUnit", "nodes": [ { "id": 2298, "literals": [ "solidity", "^", "0.5", ".0" ], "nodeType": "PragmaDirective", "src": "0:23:9" }, { "absolutePath": "/home/alan/src/github.com/gnosis/pm-contracts/contracts/Markets/Market.sol", "file": "../Markets/Market.sol", "id": 2299, "nodeType": "ImportDirective", "scope": 3200, "sourceUnit": 2297, "src": "24:31:9", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol", "file": "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol", "id": 2300, "nodeType": "ImportDirective", "scope": 3200, "sourceUnit": 7779, "src": "56:63:9", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "openzeppelin-solidity/contracts/drafts/SignedSafeMath.sol", "file": "openzeppelin-solidity/contracts/drafts/SignedSafeMath.sol", "id": 2301, "nodeType": "ImportDirective", "scope": 3200, "sourceUnit": 7249, "src": "120:67:9", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "/home/alan/src/github.com/gnosis/pm-contracts/contracts/Events/Event.sol", "file": "../Events/Event.sol", "id": 2302, "nodeType": "ImportDirective", "scope": 3200, "sourceUnit": 393, "src": "188:29:9", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "/home/alan/src/github.com/gnosis/pm-contracts/contracts/MarketMakers/MarketMaker.sol", "file": "../MarketMakers/MarketMaker.sol", "id": 2303, "nodeType": "ImportDirective", "scope": 3200, "sourceUnit": 1607, "src": "218:41:9", "symbolAliases": [], "unitAlias": "" }, { "baseContracts": [], "contractDependencies": [], "contractKind": "contract", "documentation": null, "fullyImplemented": true, "id": 2307, "linearizedBaseContracts": [ 2307 ], "name": "StandardMarketData", "nodeType": "ContractDefinition", "nodes": [ { "constant": true, "id": 2306, "name": "FEE_RANGE", "nodeType": "VariableDeclaration", "scope": 2307, "src": "329:42:9", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint24", "typeString": "uint24" }, "typeName": { "id": 2304, "name": "uint24", "nodeType": "ElementaryTypeName", "src": "329:6:9", "typeDescriptions": { "typeIdentifier": "t_uint24", "typeString": "uint24" } }, "value": { "argumentTypes": null, "hexValue": "31303030303030", "id": 2305, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "364:7:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1000000_by_1", "typeString": "int_const 1000000" }, "value": "1000000" }, "visibility": "public" } ], "scope": 3200, "src": "262:120:9" }, { "baseContracts": [ { "arguments": null, "baseName": { "contractScope": null, "id": 2308, "name": "Proxy", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 6828, "src": "416:5:9", "typeDescriptions": { "typeIdentifier": "t_contract$_Proxy_$6828", "typeString": "contract Proxy" } }, "id": 2309, "nodeType": "InheritanceSpecifier", "src": "416:5:9" }, { "arguments": null, "baseName": { "contractScope": null, "id": 2310, "name": "MarketData", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 2230, "src": "423:10:9", "typeDescriptions": { "typeIdentifier": "t_contract$_MarketData_$2230", "typeString": "contract MarketData" } }, "id": 2311, "nodeType": "InheritanceSpecifier", "src": "423:10:9" }, { "arguments": null, "baseName": { "contractScope": null, "id": 2312, "name": "StandardMarketData", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 2307, "src": "435:18:9", "typeDescriptions": { "typeIdentifier": "t_contract$_StandardMarketData_$2307", "typeString": "contract StandardMarketData" } }, "id": 2313, "nodeType": "InheritanceSpecifier", "src": "435:18:9" } ], "contractDependencies": [ 2230, 2307, 6798, 6828 ], "contractKind": "contract", "documentation": null, "fullyImplemented": true, "id": 2389, "linearizedBaseContracts": [ 2389, 2307, 2230, 6828, 6798 ], "name": "StandardMarketProxy", "nodeType": "ContractDefinition", "nodes": [ { "body": { "id": 2387, "nodeType": "Block", "src": "606:425:9", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_bool", "typeString": "bool" }, "id": 2348, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_bool", "typeString": "bool" }, "id": 2344, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_address", "typeString": "address" }, "id": 2336, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 2331, "name": "_eventContract", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2319, "src": "659:14:9", "typeDescriptions": { "typeIdentifier": "t_contract$_Event_$392", "typeString": "contract Event" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_contract$_Event_$392", "typeString": "contract Event" } ], "id": 2330, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "651:7:9", "typeDescriptions": { "typeIdentifier": "t_type$_t_address_$", "typeString": "type(address)" }, "typeName": "address" }, "id": 2332, "isConstant": false, "isLValue": false, "isPure": false, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "651:23:9", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "nodeType": "BinaryOperation", "operator": "!=", "rightExpression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "hexValue": "30", "id": 2334, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "686:1:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" } ], "id": 2333, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "678:7:9", "typeDescriptions": { "typeIdentifier": "t_type$_t_address_$", "typeString": "type(address)" }, "typeName": "address" }, "id": 2335, "isConstant": false, "isLValue": false, "isPure": true, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "678:10:9", "typeDescriptions": { "typeIdentifier": "t_address_payable", "typeString": "address payable" } }, "src": "651:37:9", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "BinaryOperation", "operator": "&&", "rightExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_address", "typeString": "address" }, "id": 2343, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 2338, "name": "_marketMaker", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2321, "src": "700:12:9", "typeDescriptions": { "typeIdentifier": "t_con