UNPKG

@gnosis.pm/conditional-tokens-market-makers

Version:
1 lines 35.5 kB
{"contractName":"MarketMaker","abi":[{"constant":true,"inputs":[{"name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pmSystem","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"whitelist","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"collateralToken","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":"","type":"uint256"}],"name":"conditionIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"atomicOutcomeSlotCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"fee","outputs":[{"name":"","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"FEE_RANGE","outputs":[{"name":"","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"initialFunding","type":"uint256"}],"name":"AMMCreated","type":"event"},{"anonymous":false,"inputs":[],"name":"AMMPaused","type":"event"},{"anonymous":false,"inputs":[],"name":"AMMResumed","type":"event"},{"anonymous":false,"inputs":[],"name":"AMMClosed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"fundingChange","type":"int256"}],"name":"AMMFundingChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"newFee","type":"uint64"}],"name":"AMMFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"fees","type":"uint256"}],"name":"AMMFeeWithdrawal","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":"AMMOutcomeTokenTrade","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"constant":true,"inputs":[{"name":"outcomeTokenAmounts","type":"int256[]"}],"name":"calcNetCost","outputs":[{"name":"netCost","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"fundingChange","type":"int256"}],"name":"changeFunding","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"resume","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_fee","type":"uint64"}],"name":"changeFee","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"close","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"withdrawFees","outputs":[{"name":"fees","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"outcomeTokenAmounts","type":"int256[]"},{"name":"collateralLimit","type":"int256"}],"name":"trade","outputs":[{"name":"netCost","type":"int256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"outcomeTokenCost","type":"uint256"}],"name":"calcMarketFee","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"operator","type":"address"},{"name":"","type":"address"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_operator","type":"address"},{"name":"","type":"address"},{"name":"","type":"uint256[]"},{"name":"","type":"uint256[]"},{"name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"nonpayable","type":"function"}],"metadata":"{\"compiler\":{\"version\":\"0.5.10+commit.5a6ea5b1\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"constant\":true,\"inputs\":[{\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"resume\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"pmSystem\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"outcomeTokenAmounts\",\"type\":\"int256[]\"},{\"name\":\"collateralLimit\",\"type\":\"int256\"}],\"name\":\"trade\",\"outputs\":[{\"name\":\"netCost\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"close\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"withdrawFees\",\"outputs\":[{\"name\":\"fees\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"outcomeTokenAmounts\",\"type\":\"int256[]\"}],\"name\":\"calcNetCost\",\"outputs\":[{\"name\":\"netCost\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"fundingChange\",\"type\":\"int256\"}],\"name\":\"changeFunding\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"isOwner\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"whitelist\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"outcomeTokenCost\",\"type\":\"uint256\"}],\"name\":\"calcMarketFee\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"collateralToken\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_operator\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"bytes\"}],\"name\":\"onERC1155BatchReceived\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes4\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"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\":\"\",\"type\":\"uint256\"}],\"name\":\"conditionIds\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"atomicOutcomeSlotCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"fee\",\"outputs\":[{\"name\":\"\",\"type\":\"uint64\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_fee\",\"type\":\"uint64\"}],\"name\":\"changeFee\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"operator\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"bytes\"}],\"name\":\"onERC1155Received\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes4\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"FEE_RANGE\",\"outputs\":[{\"name\":\"\",\"type\":\"uint64\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"initialFunding\",\"type\":\"uint256\"}],\"name\":\"AMMCreated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"AMMPaused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"AMMResumed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"AMMClosed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"fundingChange\",\"type\":\"int256\"}],\"name\":\"AMMFundingChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"newFee\",\"type\":\"uint64\"}],\"name\":\"AMMFeeChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"fees\",\"type\":\"uint256\"}],\"name\":\"AMMFeeWithdrawal\",\"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\":\"AMMOutcomeTokenTrade\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"}],\"devdoc\":{\"methods\":{\"calcMarketFee(uint256)\":{\"details\":\"Calculates fee to be paid to market maker\",\"params\":{\"outcomeTokenCost\":\"Cost for buying outcome tokens\"},\"return\":\"Fee for trade\"},\"changeFunding(int256)\":{\"details\":\"Allows to fund the market with collateral tokens converting them into outcome tokens Note for the future: should combine splitPosition and mergePositions into one function, as code duplication causes things like this to happen.\"},\"close()\":{\"details\":\"Allows market owner to close the markets by transferring all remaining outcome tokens to the owner\"},\"isOwner()\":{\"details\":\"Returns true if the caller is the current owner.\"},\"owner()\":{\"details\":\"Returns the address of the current owner.\"},\"renounceOwnership()\":{\"details\":\"Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. * > Note: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.\"},\"supportsInterface(bytes4)\":{\"details\":\"See `IERC165.supportsInterface`. * Time complexity O(1), guaranteed to always use less than 30 000 gas.\"},\"trade(int256[],int256)\":{\"details\":\"Allows to trade outcome tokens and collateral with the market maker\",\"params\":{\"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.\",\"outcomeTokenAmounts\":\"Amounts of each atomic 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. The indices of this array range from 0 to product(all conditions' outcomeSlotCounts)-1. For example, with two conditions with three outcome slots each and one condition with two outcome slots, you will have 3*3*2=18 total atomic outcome tokens, and the indices will range from 0 to 17. The indices map to atomic outcome slots depending on the order of the conditionIds. Let's say the first condition has slots A, B, C the second has slots X, Y, and the third has slots I, J, K. We can associate each atomic outcome token with indices by this map: A&X&I == 0 B&X&I == 1 C&X&I == 2 A&Y&I == 3 B&Y&I == 4 C&Y&I == 5 A&X&J == 6 B&X&J == 7 C&X&J == 8 A&Y&J == 9 B&Y&J == 10 C&Y&J == 11 A&X&K == 12 B&X&K == 13 C&X&K == 14 A&Y&K == 15 B&Y&K == 16 C&Y&K == 17 This order is calculated via the generateAtomicPositionId function below: C&Y&I -> (2, 1, 0) -> 2 + 3 * (1 + 2 * (0 + 3 * (0 + 0)))\"},\"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.\"},\"transferOwnership(address)\":{\"details\":\"Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.\"},\"withdrawFees()\":{\"details\":\"Allows market owner to withdraw fees generated by trades\",\"return\":\"Fee amount\"}}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/home/alan/src/github.com/gnosis/conditional-tokens-market-makers/contracts/MarketMaker.sol\":\"MarketMaker\"},\"evmVersion\":\"petersburg\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"/home/alan/src/github.com/gnosis/conditional-tokens-market-makers/contracts/MarketMaker.sol\":{\"keccak256\":\"0xa4addb4855f472eb1a4719298b5db759e475dd42bcd8de73d04c1ffc3b01bf40\",\"urls\":[\"bzzr://f7e679bd8b58cbc371c1a3919f740c47234cfdbda8253b6f65d2b2b57086def2\",\"dweb:/ipfs/QmQmjcWGQdmoogx9DBm8wtXxejXjDyuhmDFeihiCmzjd8N\"]},\"/home/alan/src/github.com/gnosis/conditional-tokens-market-makers/contracts/Whitelist.sol\":{\"keccak256\":\"0xe608e935510e8190d6d9fd7a0a6ecc02776d0dd106cbcbe3bac5ee0309abfae5\",\"urls\":[\"bzzr://88b9da6174844aa2f45b5bf2686298a34a12c4546449ebc8344baaafd612ac42\",\"dweb:/ipfs/QmXqMsiTBAgfgZvfL5rP1QjFhfw56JBdyVmJJRmB2WoFJ4\"]},\"@gnosis.pm/conditional-tokens-contracts/contracts/CTHelpers.sol\":{\"keccak256\":\"0x921eadb1d6cd0e742448334fb84c39b358a18cdeb7c6badbb89cae847d44a201\",\"urls\":[\"bzzr://54ea8cd3a2ef100710306ce15475573542ad5235ced471d59fa1744cfaea51c8\",\"dweb:/ipfs/Qme871evGa1PBSBnV9PisLhYnFnnahLmBuy5KakLSUKRPF\"]},\"@gnosis.pm/conditional-tokens-contracts/contracts/ConditionalTokens.sol\":{\"keccak256\":\"0x11a610a3fa07ac8a59a09a76fdb944f058fdb06d3414fe49995595e68cd17d41\",\"urls\":[\"bzzr://aec70f70bf6166a9ae46146c7d293156967b345273a250667732f6f8a4355342\",\"dweb:/ipfs/QmWUFR7eKVsMS61UCK1yY2bQQhcqEQHAAmJ2FJ3GozWV8k\"]},\"@gnosis.pm/conditional-tokens-contracts/contracts/ERC1155/ERC1155.sol\":{\"keccak256\":\"0xd8e6583f45a98380ff10a5656a7ae7ba6a275e0d051043e5842f0d541abd7caa\",\"urls\":[\"bzzr://978cc82d056d10d8cc14b02f35801b10c0c2f87b0adbf6c41bbd622e20ab8cee\",\"dweb:/ipfs/QmYWqCK6moph6oeBEUc1nDaGz4GRdGXmykwKD5rykVbhcU\"]},\"@gnosis.pm/conditional-tokens-contracts/contracts/ERC1155/ERC1155TokenReceiver.sol\":{\"keccak256\":\"0x5d1e709c759b9bd72865c8608582d66fc338fde3a77f41abb04ae943915a5695\",\"urls\":[\"bzzr://55e5a597486430ad437bb8c8f0c93cf573b833fa84ccf64a25afaa01c761b839\",\"dweb:/ipfs/QmQ727N1676jG9F5iwakSG2RNeV82TVBGJHgHPmHxib8ah\"]},\"@gnosis.pm/conditional-tokens-contracts/contracts/ERC1155/IERC1155.sol\":{\"keccak256\":\"0x4971631d7de74464fed3e0abac04553e917be5e8cd10b3f825e2e7c39ccc2734\",\"urls\":[\"bzzr://e1e88dfe7440ceab59d4cd604d12e5dc93409a3c5058e497763703027ea7b9e6\",\"dweb:/ipfs/QmRzsL1o6iVEFmqBYCo3XpM4kpvbK7iSJWssXHQ3gHb5uq\"]},\"@gnosis.pm/conditional-tokens-contracts/contracts/ERC1155/IERC1155TokenReceiver.sol\":{\"keccak256\":\"0xca815b5ca57df8f1056b962c2728d6a1e56fc7d9a7869ccee8f5a1ac6075b75d\",\"urls\":[\"bzzr://61df3e61bf24c80714e326ffdc274aaefc342241de3e72374131f613cddbd042\",\"dweb:/ipfs/QmPnF3rGuY2H3Gifvha4dW7fJPptP7wJerHzjz4dpzfTJW\"]},\"@gnosis.pm/util-contracts/contracts/SignedSafeMath.sol\":{\"keccak256\":\"0xf96e8d30ae216bdded12e0330bd43258ff91d7f2e197ba51cd0bebe662b2abbb\",\"urls\":[\"bzzr://7693c86096ea689f6cf2a2a5a5e7247e1bb7bc3d6573e1d3044a94f6c8082544\",\"dweb:/ipfs/QmbDxe1eTT69qjLHwYWhxUU9nnE7ACZHLbWJCW8unoP7ET\"]},\"openzeppelin-solidity/contracts/introspection/ERC165.sol\":{\"keccak256\":\"0xac2eacd7e7762e275442f28f21d821544df5aae2ed7698af13be8c41b7005e2e\",\"urls\":[\"bzzr://43e901f6f210568ebc1d3591da3ce6a9d10796b854767a9c6e3da10305a8a332\",\"dweb:/ipfs/QmQhfx2Ufr8a2gFXm3KogL66xGgAuAWMwcamkWFKGG6Vya\"]},\"openzeppelin-solidity/contracts/introspection/IERC165.sol\":{\"keccak256\":\"0x661553e43d7c4fbb2de504e5999fd5c104d367488350ed5bf023031bd1ba5ac5\",\"urls\":[\"bzzr://fc2ba15143ce3a00268ecd15fc98eb2469b18bfe27a64bbab0ac6446f161c739\",\"dweb:/ipfs/QmV7wjtRf11ibUHh4g8JjuhMpy68pPhV95L2y46UBoRfsZ\"]},\"openzeppelin-solidity/contracts/math/SafeMath.sol\":{\"keccak256\":\"0x4ccf2d7b51873db1ccfd54ca2adae5eac3b184f9699911ed4490438419f1c690\",\"urls\":[\"bzzr://1604f5b6d6e916c154efd8c6720cda069e5ba32dfa0a9dedf2b42e5b02d07f89\",\"dweb:/ipfs/QmV3yVktya1s617QmuzQR2CfuJgUi3dR2xEZY9ecmqZ2G1\"]},\"openzeppelin-solidity/contracts/ownership/Ownable.sol\":{\"keccak256\":\"0xf79fb10e8235770eb4aea7249034076a3cc9f9119ad944fc48705bae9c9d20dc\",\"urls\":[\"bzzr://d12a11272051eb6586de8f7e0a82c04a98c9984ce8b2a6cf1ee439f65aba29a9\",\"dweb:/ipfs/QmS55hgTvNEAKinus19m65CB4wcymN8EiUPFpRx5tYJ1i2\"]},\"openzeppelin-solidity/contracts/token/ERC20/IERC20.sol\":{\"keccak256\":\"0x90e8c2521653bbb1768b05889c5760031e688d9cd361f167489b89215e201b95\",\"urls\":[\"bzzr://aa8b45b57edafc3d67bc5d916327ea16807fae33f753ca163ae0c4061b789766\",\"dweb:/ipfs/QmP5NaEwZthQeM2ESz4WTT3osrP7jhbvu7ocbttBi2JAw6\"]},\"openzeppelin-solidity/contracts/utils/Address.sol\":{\"keccak256\":\"0xf3358e5819ca73357abd6c90bdfffd0474af54364897f6b3e3234c4b71fbe9a1\",\"urls\":[\"bzzr://f7f6da60a184233fd666ac44e6fb2bd51ca6ebdc4867a310d368049aa4e62786\",\"dweb:/ipfs/Qmb3kNCoBUZdah1AgBBD4zMk898j5Qw8ahT1w5cCMYp5Y3\"]}},\"version\":1}","bytecode":"0x","deployedBytecode":"0x","sourceMap":"","deployedSourceMap":"","source":"pragma solidity ^0.5.1;\nimport { Ownable } from \"openzeppelin-solidity/contracts/ownership/Ownable.sol\";\nimport { IERC20 } from \"openzeppelin-solidity/contracts/token/ERC20/IERC20.sol\";\nimport { SafeMath } from \"openzeppelin-solidity/contracts/math/SafeMath.sol\";\nimport { SignedSafeMath } from \"@gnosis.pm/util-contracts/contracts/SignedSafeMath.sol\";\nimport { ERC1155TokenReceiver } from \"@gnosis.pm/conditional-tokens-contracts/contracts/ERC1155/ERC1155TokenReceiver.sol\";\nimport { CTHelpers } from \"@gnosis.pm/conditional-tokens-contracts/contracts/CTHelpers.sol\";\nimport { ConditionalTokens } from \"@gnosis.pm/conditional-tokens-contracts/contracts/ConditionalTokens.sol\";\nimport { Whitelist } from \"./Whitelist.sol\";\n\ncontract MarketMaker is Ownable, ERC1155TokenReceiver {\n using SignedSafeMath for int;\n using SafeMath for uint;\n /*\n * Constants\n */ \n uint64 public constant FEE_RANGE = 10**18;\n\n /*\n * Events\n */\n event AMMCreated(uint initialFunding);\n event AMMPaused();\n event AMMResumed();\n event AMMClosed();\n event AMMFundingChanged(int fundingChange);\n event AMMFeeChanged(uint64 newFee);\n event AMMFeeWithdrawal(uint fees);\n event AMMOutcomeTokenTrade(address indexed transactor, int[] outcomeTokenAmounts, int outcomeTokenNetCost, uint marketFees);\n \n /*\n * Storage\n */\n ConditionalTokens public pmSystem;\n IERC20 public collateralToken;\n bytes32[] public conditionIds;\n uint public atomicOutcomeSlotCount;\n uint64 public fee;\n uint public funding;\n Stage public stage;\n Whitelist public whitelist;\n\n uint[] outcomeSlotCounts;\n bytes32[][] collectionIds;\n uint[] positionIds;\n\n enum Stage {\n Running,\n Paused,\n Closed\n }\n\n /*\n * Modifiers\n */\n modifier atStage(Stage _stage) {\n // Contract has to be in given stage\n require(stage == _stage);\n _;\n }\n\n modifier onlyWhitelisted() {\n require(\n whitelist == Whitelist(0) || whitelist.isWhitelisted(msg.sender),\n \"only whitelisted users may call this function\"\n );\n _;\n }\n\n function calcNetCost(int[] memory outcomeTokenAmounts) public view returns (int netCost);\n\n /// @dev Allows to fund the market with collateral tokens converting them into outcome tokens\n /// Note for the future: should combine splitPosition and mergePositions into one function, as code duplication causes things like this to happen.\n function changeFunding(int fundingChange)\n public\n onlyOwner\n atStage(Stage.Paused)\n {\n require(fundingChange != 0, \"funding change must be non-zero\");\n // Either add or subtract funding based off whether the fundingChange parameter is negative or positive\n if (fundingChange > 0) {\n require(collateralToken.transferFrom(msg.sender, address(this), uint(fundingChange)) && collateralToken.approve(address(pmSystem), uint(fundingChange)));\n splitPositionThroughAllConditions(uint(fundingChange));\n funding = funding.add(uint(fundingChange));\n emit AMMFundingChanged(fundingChange);\n }\n if (fundingChange < 0) {\n mergePositionsThroughAllConditions(uint(-fundingChange));\n funding = funding.sub(uint(-fundingChange));\n require(collateralToken.transfer(owner(), uint(-fundingChange)));\n emit AMMFundingChanged(fundingChange);\n }\n }\n\n function pause() public onlyOwner atStage(Stage.Running) {\n stage = Stage.Paused;\n emit AMMPaused();\n }\n \n function resume() public onlyOwner atStage(Stage.Paused) {\n stage = Stage.Running;\n emit AMMResumed();\n }\n\n function changeFee(uint64 _fee) public onlyOwner atStage(Stage.Paused) {\n fee = _fee;\n emit AMMFeeChanged(fee);\n }\n\n /// @dev Allows market owner to close the markets by transferring all remaining outcome tokens to the owner\n function close()\n public\n onlyOwner\n {\n require(stage == Stage.Running || stage == Stage.Paused, \"This Market has already been closed\");\n for (uint i = 0; i < atomicOutcomeSlotCount; i++) {\n uint positionId = generateAtomicPositionId(i);\n pmSystem.safeTransferFrom(address(this), owner(), positionId, pmSystem.balanceOf(address(this), positionId), \"\");\n }\n stage = Stage.Closed;\n emit AMMClosed();\n }\n\n /// @dev Allows market owner to withdraw fees generated by trades\n /// @return Fee amount\n function withdrawFees()\n public\n onlyOwner\n returns (uint fees)\n {\n fees = collateralToken.balanceOf(address(this));\n // Transfer fees\n require(collateralToken.transfer(owner(), fees));\n emit AMMFeeWithdrawal(fees);\n }\n\n /// @dev Allows to trade outcome tokens and collateral with the market maker\n /// @param outcomeTokenAmounts Amounts of each atomic 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. The indices of this array range from 0 to product(all conditions' outcomeSlotCounts)-1. For example, with two conditions with three outcome slots each and one condition with two outcome slots, you will have 3*3*2=18 total atomic outcome tokens, and the indices will range from 0 to 17. The indices map to atomic outcome slots depending on the order of the conditionIds. Let's say the first condition has slots A, B, C the second has slots X, Y, and the third has slots I, J, K. We can associate each atomic outcome token with indices by this map:\n /// A&X&I == 0\n /// B&X&I == 1\n /// C&X&I == 2\n /// A&Y&I == 3\n /// B&Y&I == 4\n /// C&Y&I == 5\n /// A&X&J == 6\n /// B&X&J == 7\n /// C&X&J == 8\n /// A&Y&J == 9\n /// B&Y&J == 10\n /// C&Y&J == 11\n /// A&X&K == 12\n /// B&X&K == 13\n /// C&X&K == 14\n /// A&Y&K == 15\n /// B&Y&K == 16\n /// C&Y&K == 17\n /// This order is calculated via the generateAtomicPositionId function below: C&Y&I -> (2, 1, 0) -> 2 + 3 * (1 + 2 * (0 + 3 * (0 + 0)))\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(Stage.Running)\n onlyWhitelisted\n returns (int netCost)\n {\n require(outcomeTokenAmounts.length == atomicOutcomeSlotCount);\n\n // Calculate net cost for executing trade\n int outcomeTokenNetCost = calcNetCost(outcomeTokenAmounts);\n int fees;\n if(outcomeTokenNetCost < 0)\n fees = int(calcMarketFee(uint(-outcomeTokenNetCost)));\n else\n fees = int(calcMarketFee(uint(outcomeTokenNetCost)));\n\n require(fees >= 0);\n netCost = outcomeTokenNetCost.add(fees);\n\n require(\n (collateralLimit != 0 && netCost <= collateralLimit) ||\n collateralLimit == 0\n );\n\n if(outcomeTokenNetCost > 0) {\n require(\n collateralToken.transferFrom(msg.sender, address(this), uint(netCost)) &&\n collateralToken.approve(address(pmSystem), uint(outcomeTokenNetCost))\n );\n\n splitPositionThroughAllConditions(uint(outcomeTokenNetCost));\n }\n\n bool touched = false;\n uint[] memory transferAmounts = new uint[](atomicOutcomeSlotCount);\n for (uint i = 0; i < atomicOutcomeSlotCount; i++) {\n if(outcomeTokenAmounts[i] < 0) {\n touched = true;\n // This is safe since\n // 0x8000000000000000000000000000000000000000000000000000000000000000 ==\n // uint(-int(-0x8000000000000000000000000000000000000000000000000000000000000000))\n transferAmounts[i] = uint(-outcomeTokenAmounts[i]);\n }\n }\n if(touched) pmSystem.safeBatchTransferFrom(msg.sender, address(this), positionIds, transferAmounts, \"\");\n\n if(outcomeTokenNetCost < 0) {\n mergePositionsThroughAllConditions(uint(-outcomeTokenNetCost));\n }\n\n emit AMMOutcomeTokenTrade(msg.sender, outcomeTokenAmounts, outcomeTokenNetCost, uint(fees));\n\n touched = false;\n for (uint i = 0; i < atomicOutcomeSlotCount; i++) {\n if(outcomeTokenAmounts[i] > 0) {\n touched = true;\n transferAmounts[i] = uint(outcomeTokenAmounts[i]);\n } else {\n transferAmounts[i] = 0;\n }\n }\n if(touched) pmSystem.safeBatchTransferFrom(address(this), msg.sender, positionIds, transferAmounts, \"\");\n\n if(netCost < 0) {\n require(collateralToken.transfer(msg.sender, uint(-netCost)));\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 function onERC1155Received(address operator, address /*from*/, uint256 /*id*/, uint256 /*value*/, bytes calldata /*data*/) external returns(bytes4) {\n if (operator == address(this)) {\n return this.onERC1155Received.selector;\n }\n return 0x0;\n }\n\n function onERC1155BatchReceived(address _operator, address /*from*/, uint256[] calldata /*ids*/, uint256[] calldata /*values*/, bytes calldata /*data*/) external returns(bytes4) {\n if (_operator == address(this)) {\n return this.onERC1155BatchReceived.selector;\n }\n return 0x0;\n }\n\n function generateBasicPartition(uint outcomeSlotCount)\n private\n pure\n returns (uint[] memory partition)\n {\n partition = new uint[](outcomeSlotCount);\n for(uint i = 0; i < outcomeSlotCount; i++) {\n partition[i] = 1 << i;\n }\n }\n\n function generateAtomicPositionId(uint i)\n internal\n view\n returns (uint)\n {\n return positionIds[i];\n }\n\n function splitPositionThroughAllConditions(uint amount)\n private\n {\n for(uint i = conditionIds.length - 1; int(i) >= 0; i--) {\n uint[] memory partition = generateBasicPartition(outcomeSlotCounts[i]);\n for(uint j = 0; j < collectionIds[i].length; j++) {\n pmSystem.splitPosition(collateralToken, collectionIds[i][j], conditionIds[i], partition, amount);\n }\n }\n }\n\n function mergePositionsThroughAllConditions(uint amount)\n private\n {\n for(uint i = 0; i < conditionIds.length; i++) {\n uint[] memory partition = generateBasicPartition(outcomeSlotCounts[i]);\n for(uint j = 0; j < collectionIds[i].length; j++) {\n pmSystem.mergePositions(collateralToken, collectionIds[i][j], conditionIds[i], partition, amount);\n }\n }\n }\n}","compiler":{"name":"solc","version":"0.5.10+commit.5a6ea5b1.Emscripten.clang"},"networks":{},"schemaVersion":"3.0.16","updatedAt":"2020-03-16T19:03:53.115Z","devdoc":{"methods":{"calcMarketFee(uint256)":{"details":"Calculates fee to be paid to market maker","params":{"outcomeTokenCost":"Cost for buying outcome tokens"},"return":"Fee for trade"},"changeFunding(int256)":{"details":"Allows to fund the market with collateral tokens converting them into outcome tokens Note for the future: should combine splitPosition and mergePositions into one function, as code duplication causes things like this to happen."},"close()":{"details":"Allows market owner to close the markets by transferring all remaining outcome tokens to the owner"},"isOwner()":{"details":"Returns true if the caller is the current owner."},"owner()":{"details":"Returns the address of the current owner."},"renounceOwnership()":{"details":"Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. * > Note: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner."},"supportsInterface(bytes4)":{"details":"See `IERC165.supportsInterface`. * Time complexity O(1), guaranteed to always use less than 30 000 gas."},"trade(int256[],int256)":{"details":"Allows to trade outcome tokens and collateral with the market maker","params":{"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.","outcomeTokenAmounts":"Amounts of each atomic 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. The indices of this array range from 0 to product(all conditions' outcomeSlotCounts)-1. For example, with two conditions with three outcome slots each and one condition with two outcome slots, you will have 3*3*2=18 total atomic outcome tokens, and the indices will range from 0 to 17. The indices map to atomic outcome slots depending on the order of the conditionIds. Let's say the first condition has slots A, B, C the second has slots X, Y, and the third has slots I, J, K. We can associate each atomic outcome token with indices by this map: A&X&I == 0 B&X&I == 1 C&X&I == 2 A&Y&I == 3 B&Y&I == 4 C&Y&I == 5 A&X&J == 6 B&X&J == 7 C&X&J == 8 A&Y&J == 9 B&Y&J == 10 C&Y&J == 11 A&X&K == 12 B&X&K == 13 C&X&K == 14 A&Y&K == 15 B&Y&K == 16 C&Y&K == 17 This order is calculated via the generateAtomicPositionId function below: C&Y&I -> (2, 1, 0) -> 2 + 3 * (1 + 2 * (0 + 3 * (0 + 0)))"},"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."},"transferOwnership(address)":{"details":"Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner."},"withdrawFees()":{"details":"Allows market owner to withdraw fees generated by trades","return":"Fee amount"}}},"userdoc":{"methods":{}}}