-
Notifications
You must be signed in to change notification settings - Fork 31
/
market.sol.compiled
1 lines (1 loc) · 35.2 KB
/
market.sol.compiled
1
{"Market":{"code":"0x60606040526000600455600660055561227f8061001c6000396000f3606060405236156100cf5760e060020a600035046303cf4fd681146100d15780630e1087c31461019b578063155dd5ee14610215578063177766e6146102455780632043285d146102f257806342bf44311461040f578063502414e41461051e5780635c665f89146105775780636b1cb549146105c35780637ae2b5c714610725578063a26759cb1461073f578063d4dfadbf14610780578063d5544f9414610a04578063dc06b85914610a19578063ec0b415314610a22578063ee5f013e14610a53578063fe4667e914610b2e575b005b6100cf60043560243560443560643560843560a43560008581526020819052604081206008015481908190819060ff16811415611e6b57604080822081516005820154600492909201548152602081810189905283519182900384018220825260ff8c16828201528184018b9052606082018a90529251600160a060020a039290921692600192608083810193829003018187866161da5a03f11561000257505060405151600160a060020a03161415611e6b57600854935089811415611d265760019950611d2a565b610cee6000600060006000600060006020604051908101604052806000815260200150600060066040518059106101cf5750595b90808252806020026020018201604052509150600190505b6004548111611c0b57600081815260036020526040812054611ca091600160a060020a039190911690610581565b6100cf60043533600160a060020a031660009081526009602052604081205411156117d8576117db336001610581565b610d216004356040805160208181018352600080835284815280825283812080546001828101805488516002868101546003880154600489015460059099015496851615610100026000190190941691909104601f81018a90048a0283018a01909b528a825296998a98899889988998979195949093600160a060020a03929092169290918791830182828015611ceb5780601f10611cc057610100808354040283529160200191611ceb565b610dbb604080516020818101835260008083528351808301855281815284518084018652828152855180850187528381528651808601885284815287518087018952858152885196870189528587529751969793969295919490939260069080591061035b5750595b90808252806020026020018201604052816020015b604080516020818101909252600081528252600019909201910181610370579050509150600190505b6004548111611b2057600081815260036020908152604091829020600190810180548451600293821615610100026000190190911692909204601f810184900484028301840190945283825290929091830182828015611be65780601f10611bbb57610100808354040283529160200191611be6565b61100460043560243560443560643560843560a43560c43560e435610104356000844311158015610503575060008713801561044b5750600082125b801561049c5750604080518b815260208181018c90528183018b9052606082018a90526080820189905260a0820188905282519182900360c001909120600090815260029091522054829003879013155b8061050357506000871280156104b25750600082135b80156105035750604080518b815260208181018c90528183018b9052606082018a90526080820189905260a0820188905282519182900360c001909120600090815260029091522054829003879012155b80156113fb57506000611416858c8c866000038d8802610b41565b6040805160206004803580820135601f81018490048402850184019095528484526100cf949193602493909291840191908190840183828082843750949650505050505050600060006000600034111561188457610002565b6110046004356024355b600160a060020a0382166000908152600960205260408120548190111561182457816000141561182e5760408082205482526007602052902060010154611828565b6100cf60043560243560443560643560843560a43560c43560e435610104356101243561014435604080518c815260208181018d90528183018c9052606082018b9052608082018a905260a08201899052915160009260029260c08181019391829003018186866161da5a03f11561000257505060408051805160ff88166020838101919091528284018890526060830187905292519093600160a060020a038a169360019360808181019492939183900301908290866161da5a03f11561000257505060405151600160a060020a03161480156106a15750864311155b801561070a57506000891380156106b85750600082125b80156106d65750600081815260026020526040902054829003899013155b8061070a57506000891280156106ec5750600082135b801561070a5750600081815260026020526040902054829003899012155b801561143f5750600061145a878e8e866000038f8802610b41565b6110046004356024356000818310156121da575081611828565b6100cf33600160a060020a031660009081526009602052604081205481901115611788576040808220548252600760205281206001018054340190556117d8565b61101660043560408051602081810183526000808352835180830185528181528451808401865282815285518085018752838152865180860188528481528751808701895285815288518088018a5286815289519788018a5286885298519798949793969295919490939092919081908190603c908059106107ff5750595b90808252806020026020018201604052509650603c6040518059106108215750595b90808252806020026020018201604052509550603c6040518059106108435750595b90808252806020026020018201604052509450603c6040518059106108655750595b81815260209182028101909101604052600154909450600093506000190191505b600082121580156108975750603c83105b15611d075760008281526020819052604081206008015460ff161415611d1a575060005b600082815260208190526040902060070154811015611d1a5780826103e80201878481518110156100025760406000818120602084810290950185019590955285815260069490940190925291205487519091889181101561000257906020019060200201909081815260200150506000600050600083815260200190815260200160002060005060090160005060008d600160a060020a031681526020019081526020016000206000506000016000506000828152602001908152602001600020600050548584815181101561000257906020019060200201909081815260200150506000600050600083815260200190815260200160002060005060090160005060008d600160a060020a031681526020019081526020016000206000506001016000505484848151811015610002575050602084810286010152600192830192016108bb565b61111160043560006000611870836000610581565b61100460045481565b6110046004356024356044355b6000808412611f345783831115611f5957818484031015611f645750828203611f5d565b604080516020604435600481810135601f81018490048402850184019095528484526100cf948135946024803595939460649492939101918190840183828082843750506040805160e435808a013560208181028085018201909552818452989a9935996084359960a435995060c4359850909650610104955092936024929092019290918291850190849080828437509496505050505050506000600060006000600693506006600160005054101561112a576001805480820190915593505b60068410156113d95760068c101561118b578b93506112b3565b6110046004356024356044356064356084355b6000808080808080805b600154861015611f6b576000600050600087815260200190815260200160002060005060090160005060008e600160a060020a0316815260200190815260200160002060005060020160009054906101000a900460ff166000148015610bd0575060006000600050600088815260200190815260200160002060005060070160005054115b15611f81576000945060009350600092505b600086815260208190526040902060070154831015611f7c57670de0b6b3a76400006000600050600088815260200190815260200160002060005060090160005060008f600160a060020a03168152602001908152602001600020600050600101600050540591508b861415610c6257670de0b6b3a76400008905909101905b600090506000600060005060008881526020019081526020016000206000506006016000506000858152602001908152602001600020600050600001600050541215611f8d576000600050600087815260200190815260200160002060005060060160005060008481526020019081526020016000206000506000016000505460000390508050611faa565b604080519687526020870195909552858501939093526060850191909152608084015260a0830152519081900360c00190f35b604051808781526020018060200186815260200185815260200184815260200183600160a060020a031681526020018281038252878181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015610da85780820380516001836020036101000a031916815260200191505b5097505050505050505060405180910390f35b6040518080602001806020018060200180602001806020018060200187810387528d8181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015610e2f5780820380516001836020036101000a031916815260200191505b5087810386528c8181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015610e885780820380516001836020036101000a031916815260200191505b5087810385528b8181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015610ee15780820380516001836020036101000a031916815260200191505b5087810384528a8181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015610f3a5780820380516001836020036101000a031916815260200191505b508781038352898181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015610f935780820380516001836020036101000a031916815260200191505b508781038252888181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015610fec5780820380516001836020036101000a031916815260200191505b509c5050505050505050505050505060405180910390f35b60408051918252519081900360200190f35b60405180806020018060200180602001806020018581038552898181518152602001915080519060200190602002808383829060006004602084601f0104600f02600301f1509050018581038452888181518152602001915080519060200190602002808383829060006004602084601f0104600f02600301f1509050018581038352878181518152602001915080519060200190602002808383829060006004602084601f0104600f02600301f1509050018581038252868181518152602001915080519060200190602002808383829060006004602084601f0104600f02600301f1509050019850505050505050505060405180910390f35b6040805192835260208301919091528051918290030190f35b600092505b60015483108015611141575060068410155b15610b145760008381526020819052604090206008015460ff166001148061117457506040600090812084825260070154145b1561117f5782935083505b6001929092019161112f565b6000848152602081905260408120818155600181810180548482559293929091600290821615610100026000190190911604601f81901061137757505b5050600060028281018290556003830182905560048301829055600583018054600160a060020a03191690556007830182905560088301805460ff19169055600a8301829055600b9092018190558581526020818152604082208e81558d516001918201805481865294849020909592851615610100026000190190941691909104601f90810183900484019391928f01908390106113a957805160ff19168380011785555b5061127a929150611391565b50506000848152602081905260409020600281018a905560038101899055600481018890556005018054600160a060020a031916871790555b600092505b84518310156113d957600084815260208190526040902060070154600a90101561136b57505060406000818120600781018054600181019091558483526006919091016020529190208451859084908110156100025790602001906020020151816000016000508190555080600060005060008681526020019081526020016000206000506006016000506000858152602001908152602001600020600050600082016000505481600001600050559050505b600192909201916112b8565b601f0160209004906000526020600020908101906111c891905b808211156113a55760008155600101611391565b5090565b8280016001018555821561126e579182015b8281111561126e5782518260005055916020019190600101906113bb565b505050505050505050505050565b5060005b9998505050505050505050565b01135b801561142457506000611431848c8c868d8860000302610b41565b6113f8866000610581565b01135b156113e7575060016113eb565b611421856000610581565b01135b80156114685750600061177d338e8e868f8860000302610b41565b61143c886000610581565b01135b156113d95760008c81526020818152604080832033600160a060020a03168452600901909152812060020154610100900460ff161415611527576001600060005060008e8152602001908152602001600020600050600901600050600033600160a060020a0316815260200190815260200160002060005060020160016101000a81548160ff02191690830217905550600060005060008d8152602001908152602001600020600050600a016000818150548092919060010191905055505b60008c815260208181526040808320600160a060020a038a168452600901909152812060020154610100900460ff1614156115e1576001600060005060008e8152602001908152602001600020600050600901600050600088600160a060020a0316815260200190815260200160002060005060020160016101000a81548160ff02191690830217905550600060005060008d8152602001908152602001600020600050600a016000818150548092919060010191905055505b81600060005060008e8152602001908152602001600020600050600901600050600033600160a060020a0316815260200190815260200160002060005060000160005060008d8152602001908152602001600020600082828250540192505081905550898202600060005060008e8152602001908152602001600020600050600901600050600033600160a060020a0316815260200190815260200160002060005060010160008282825054039250508190555081600060005060008e8152602001908152602001600020600050600901600050600088600160a060020a0316815260200190815260200160002060005060000160005060008d8152602001908152602001600020600082828250540392505081905550898202600060005060008e8152602001908152602001600020600050600901600050600088600160a060020a031681526020019081526020016000206000506001016000828282505401925050819055508160026000506000838152602001908152602001600020600082828250540392505081905550505050505050505050505050565b611465336000610581565b506008805460019081019182905560008281526007602090815260408083208054600160a060020a0319163390811782559401805434019055600160a060020a0393909316825260099052208190555b50565b81136117d85733600160a060020a0316600081815260096020908152604080832054835260079091528082206001018054859003905551839082818181858883f1505050505050565b5060005b92915050565b61183f836000600060006000610b41565b600160a060020a03841660009081526009602090815260408083205483526007909152902060010154019050611828565b61187b846001610581565b91509150915091565b33600160a060020a0316600090815260066020526040812054111561190d576040600081812054815260036020908152918120600190810180548851828552938590209194600293821615610100026000190190911692909204601f9081018390048201939289019083901061193257805160ff19168380011785555b50611962929150611391565b60008181526003602052604081205461196b91600160a060020a039190911690610581565b82800160010185558215611901579182015b82811115611901578251826000505591602001919060010190611944565b50505b50505050565b600454600554919450600093501015611a2857600480546001019081905591505b6000821115611ac95760008281526003602081815260408084208054600160a060020a03168552600683529084208490558584529181528154600160a060020a0319163317825586516001928301805481865294839020909460029481161561010002600019011693909304601f9081018390048401939192890190839010611ace57805160ff19168380011785555b50611afe929150611391565b5060025b600454811161198c576000818152600360205260408120548491611a5991600160a060020a031690610581565b13158015611a9357508160001480611a935750600082815260036020526040812054611aa491600160a060020a039190911690610581565b125b15611a9c579050805b600101611a2c565b600082815260036020526040812054611a9191600160a060020a039190911690610581565b610002565b82800160010185558215611a1c579182015b82811115611a1c578251826000505591602001919060010190611ae0565b505033600160a060020a03166000908152600660205260409020829055611965565b8160008151811015610002579060200190602002015182600181518110156100025790602001906020020151836002815181101561000257906020019060200201518460038151811015610002579060200190602002015185600481518110156100025790602001906020020151866005815181101561000257505060c0870151949c50929a509098509650945092505b5050909192939495565b820191906000526020600020905b815481529060010190602001808311611bc957829003601f168201915b5050505050826001830381518110156100025760209081029091010152600101610399565b816000815181101561000257906020019060200201518260018151811015610002579060200190602002015183600281518110156100025790602001906020020151846003815181101561000257906020019060200201518560048151811015610002579060200190602002015186600581518110156100025790602001906020020151975097509750975097509750611bb1565b8260018303815181101561000257602090810290910101526001016101e7565b820191906000526020600020905b815481529060010190602001808311611cce57829003601f168201915b5050505050945095509550955095509550955091939550919395565b50949a9399509197509550909350505050565b60001990910190610886565b8993505b838a11611e38576000898152602081815260408083208d84526007835281842054600160a060020a0316845260090190915281206002015460ff161415611ed357670de0b6b3a7640000600060005060008b81526020019081526020016000206000506009016000506000600760005060008e815260200190815260200160002060005060000160009054906101000a9004600160a060020a0316600160a060020a0316815260200190815260200160002060005060010160005054059250600091505b600089815260208190526040902060070154821015611e775760406000818120848252600681016020908152928220548c83529190925260029190910154611edf91908790610a2f565b6000898152602081905260409020600a810154600b909101541415611e6b576040600020600801805460ff191660011790555b50505050505050505050565b60008a815260076020908152604080832060018181018054890190558d85528484528285209154600160a060020a03168552600982018452918420600201805460ff1916831790558c845292909152600b909101805490910190555b60019990990198611d2a565b60008a8152602081815260408083208e84526007835281842054600160a060020a031684526009018252808320868452909152902054670de0b6b3a76400009082020590930192905060019190910190611dee565b83600003831015611f5957818385600003031015611f64578284600003039050611f5d565b5060005b9392505050565b5080611f5d565b50949b9a5050505050505050505050565b958301955b60019590950194610b4b565b506000858152602081815260408083208584526006019091529020545b61200c8d8d8d8d8a865b600080805b6000858152602081905260409020600701548110156121e15760406000818120838252600681016020908152928220548883529190925260029190910154670de0b6b3a7640000916121ed918790610a2f565b91909101908382128061201f5750846000145b1561202e576001945090925082905b670de0b6b3a76400006000600050600088815260200190815260200160002060005060090160005060008f600160a060020a031681526020019081526020016000206000506001016000505405915081508b86141561209757670de0b6b3a76400008905909101905b50600085815260208181526040808320858452600601909152812054819012156121865760006000506000878152602001908152602001600020600050600201600050546000600050600088815260200190815260200160002060005060060160005060008581526020019081526020016000206000506000016000505460000311156121815760006000506000878152602001908152602001600020600050600201600050546000600050600088815260200190815260200160002060005060060160005060008581526020019081526020016000206000506000016000505460000303905080505b6121ad565b50600085815260208181526040808320600281015486855260069190910190925290912054015b6121bb8d8d8d8d8a86611fb4565b9190910190838212156121ce5781935083505b60019290920191610be2565b5080611828565b50979650505050505050565b600087815260208181526040808320600160a060020a038f1684526009018252808320868452909152902054020590910190878514801561222d57508681145b1561227757600085815260208181526040808320848452600681018352908320548884529290915260020154670de0b6b3a76400009161226e918790610a2f565b87020591909101905b600101611fb956","info":{"source":"contract Market {\n\n struct Order {\n uint price;\n uint size;\n address user;\n }\n struct Option {\n int strike;\n }\n struct Position {\n mapping(uint => int) positions;\n int cash;\n bool expired;\n bool hasPosition;\n }\n struct OptionChain {\n uint expiration;\n string underlying;\n uint margin;\n uint realityID;\n bytes32 factHash;\n address ethAddr;\n mapping(uint => Option) options;\n uint numOptions;\n bool expired;\n mapping(address => Position) positions;\n uint numPositions;\n uint numPositionsExpired;\n }\n mapping(uint => OptionChain) optionChains;\n uint numOptionChains;\n struct Account {\n address user;\n int capital;\n }\n mapping(bytes32 => int) orderFills; //keeps track of cumulative order fills\n struct MarketMaker {\n address user;\n string server;\n }\n mapping(uint => MarketMaker) marketMakers; //starts at 1\n uint public numMarketMakers = 0;\n uint maxMarketMakers = 6;\n mapping(address => uint) marketMakerIDs;\n mapping(uint => Account) accounts;\n uint numAccounts;\n mapping(address => uint) accountIDs; //starts at 1\n\n function Market() {\n }\n\n function addFunds() {\n if (accountIDs[msg.sender]>0) {\n accounts[accountIDs[msg.sender]].capital += int(msg.value);\n } else {\n uint accountID = ++numAccounts;\n accounts[accountID].user = msg.sender;\n accounts[accountID].capital += int(msg.value);\n accountIDs[msg.sender] = accountID;\n }\n }\n\n function withdrawFunds(uint amount) {\n if (accountIDs[msg.sender]>0) {\n if (int(amount)<=getFunds(msg.sender, true)) {\n accounts[accountIDs[msg.sender]].capital -= int(amount);\n msg.sender.send(amount);\n }\n }\n }\n\n function getFunds(address user, bool onlyAvailable) constant returns(int) {\n if (accountIDs[user]>0) {\n if (onlyAvailable == false) {\n return accounts[accountIDs[user]].capital;\n } else {\n return accounts[accountIDs[user]].capital + getMaxLossAfterTrade(user, 0, 0, 0, 0);\n }\n } else {\n return 0;\n }\n }\n\n function getFundsAndAvailable(address user) constant returns(int, int) {\n return (getFunds(user, false), getFunds(user, true));\n }\n\n function marketMaker(string server) {\n if (msg.value>0) throw;\n if (marketMakerIDs[msg.sender]>0) {\n marketMakers[marketMakerIDs[msg.sender]].server = server;\n } else {\n int funds = getFunds(marketMakers[i].user, false);\n uint marketMakerID = 0;\n if (numMarketMakers<maxMarketMakers) {\n marketMakerID = ++numMarketMakers;\n } else {\n for (uint i=2; i<=numMarketMakers; i++) {\n if (getFunds(marketMakers[i].user, false)<=funds && (marketMakerID==0 || getFunds(marketMakers[i].user, false)<getFunds(marketMakers[marketMakerID].user, false))) {\n marketMakerID = i;\n }\n }\n }\n if (marketMakerID>0) {\n marketMakerIDs[marketMakers[marketMakerID].user] = 0;\n marketMakers[marketMakerID].user = msg.sender;\n marketMakers[marketMakerID].server = server;\n marketMakerIDs[msg.sender] = marketMakerID;\n } else {\n throw;\n }\n }\n }\n\n function getMarketMakers() constant returns(string, string, string, string, string, string) {\n string[] memory servers = new string[](6);\n for (uint i=1; i<=numMarketMakers; i++) {\n servers[i-1] = marketMakers[i].server;\n }\n return (servers[0], servers[1], servers[2], servers[3], servers[4], servers[5]);\n }\n\n function getMarketMakerFunds() constant returns(int, int, int, int, int, int) {\n int[] memory funds = new int[](6);\n for (uint i=1; i<=numMarketMakers; i++) {\n funds[i-1] = getFunds(marketMakers[i].user, false);\n }\n return (funds[0], funds[1], funds[2], funds[3], funds[4], funds[5]);\n }\n\n function getOptionChain(uint optionChainID) constant returns (uint, string, uint, uint, bytes32, address) {\n return (optionChains[optionChainID].expiration, optionChains[optionChainID].underlying, optionChains[optionChainID].margin, optionChains[optionChainID].realityID, optionChains[optionChainID].factHash, optionChains[optionChainID].ethAddr);\n }\n\n function getMarket(address user) constant returns(uint[], int[], int[], int[]) {\n uint[] memory optionIDs = new uint[](60);\n int[] memory strikes = new int[](60);\n int[] memory positions = new int[](60);\n int[] memory cashes = new int[](60);\n uint z = 0;\n for (int optionChainID=int(numOptionChains)-1; optionChainID>=0 && z<60; optionChainID--) {\n if (optionChains[uint(optionChainID)].expired == false) {\n for (uint optionID=0; optionID<optionChains[uint(optionChainID)].numOptions; optionID++) {\n optionIDs[z] = uint(optionChainID)*1000 + optionID;\n strikes[z] = optionChains[uint(optionChainID)].options[optionID].strike;\n positions[z] = optionChains[uint(optionChainID)].positions[user].positions[optionID];\n cashes[z] = optionChains[uint(optionChainID)].positions[user].cash;\n z++;\n }\n }\n }\n return (optionIDs, strikes, positions, cashes);\n }\n\n function expire(uint accountID, uint optionChainID, uint8 v, bytes32 r, bytes32 s, bytes32 value) {\n if (optionChains[optionChainID].expired == false) {\n if (ecrecover(sha3(optionChains[optionChainID].factHash, value), v, r, s) == optionChains[optionChainID].ethAddr) {\n uint lastAccount = numAccounts;\n if (accountID==0) {\n accountID = 1;\n } else {\n lastAccount = accountID;\n }\n for (accountID=accountID; accountID<=lastAccount; accountID++) {\n if (optionChains[optionChainID].positions[accounts[accountID].user].expired == false) {\n int result = optionChains[optionChainID].positions[accounts[accountID].user].cash / 1000000000000000000;\n for (uint optionID=0; optionID<optionChains[optionChainID].numOptions; optionID++) {\n int moneyness = getMoneyness(optionChains[optionChainID].options[optionID].strike, uint(value), optionChains[optionChainID].margin);\n result += moneyness * optionChains[optionChainID].positions[accounts[accountID].user].positions[optionID] / 1000000000000000000;\n }\n accounts[accountID].capital = accounts[accountID].capital + result;\n optionChains[optionChainID].positions[accounts[accountID].user].expired = true;\n optionChains[optionChainID].numPositionsExpired++;\n }\n }\n if (optionChains[optionChainID].numPositionsExpired == optionChains[optionChainID].numPositions) {\n optionChains[optionChainID].expired = true;\n }\n }\n }\n }\n\n function getMoneyness(int strike, uint settlement, uint margin) constant returns(int) {\n if (strike>=0) { //call\n if (settlement>uint(strike)) {\n if (settlement-uint(strike)<margin) {\n return int(settlement-uint(strike));\n } else {\n return int(margin);\n }\n } else {\n return 0;\n }\n } else { //put\n if (settlement<uint(-strike)) {\n if (uint(-strike)-settlement<margin) {\n return int(uint(-strike)-settlement);\n } else {\n return int(margin);\n }\n } else {\n return 0;\n }\n }\n }\n\n function addOptionChain(uint existingOptionChainID, uint expiration, string underlying, uint margin, uint realityID, bytes32 factHash, address ethAddr, int[] strikes) {\n uint optionChainID = 6;\n if (numOptionChains<6) {\n optionChainID = numOptionChains++;\n } else {\n for (uint i=0; i < numOptionChains && optionChainID>=6; i++) {\n if (optionChains[i].expired==true || optionChains[i].numOptions==0) {\n optionChainID = i;\n }\n }\n }\n if (optionChainID<6) {\n if (existingOptionChainID<6) {\n optionChainID = existingOptionChainID;\n } else {\n delete optionChains[optionChainID];\n optionChains[optionChainID].expiration = expiration;\n optionChains[optionChainID].underlying = underlying;\n optionChains[optionChainID].margin = margin;\n optionChains[optionChainID].realityID = realityID;\n optionChains[optionChainID].factHash = factHash;\n optionChains[optionChainID].ethAddr = ethAddr;\n }\n for (i=0; i < strikes.length; i++) {\n if (optionChains[optionChainID].numOptions<10) {\n uint optionID = optionChains[optionChainID].numOptions++;\n Option option = optionChains[optionChainID].options[i];\n option.strike = strikes[i];\n optionChains[optionChainID].options[i] = option;\n }\n }\n }\n }\n\n function orderMatchTest(uint optionChainID, uint optionID, uint price, int size, uint orderID, uint blockExpires, address addr, address sender, int matchSize) constant returns(bool) {\n if (block.number<=blockExpires && ((size>0 && matchSize<0 && orderFills[sha3(optionChainID, optionID, price, size, orderID, blockExpires)]-matchSize<=size) || (size<0 && matchSize>0 && orderFills[sha3(optionChainID, optionID, price, size, orderID, blockExpires)]-matchSize>=size)) && getFunds(addr, false)+getMaxLossAfterTrade(addr, optionChainID, optionID, -matchSize, matchSize * int(price))>0 && getFunds(sender, false)+getMaxLossAfterTrade(sender, optionChainID, optionID, matchSize, -matchSize * int(price))>0) {\n return true;\n }\n return false;\n }\n\n function orderMatch(uint optionChainID, uint optionID, uint price, int size, uint orderID, uint blockExpires, address addr, uint8 v, bytes32 r, bytes32 s, int matchSize) {\n bytes32 hash = sha256(optionChainID, optionID, price, size, orderID, blockExpires);\n if (ecrecover(hash, v, r, s) == addr && block.number<=blockExpires && ((size>0 && matchSize<0 && orderFills[hash]-matchSize<=size) || (size<0 && matchSize>0 && orderFills[hash]-matchSize>=size)) && getFunds(addr, false)+getMaxLossAfterTrade(addr, optionChainID, optionID, -matchSize, matchSize * int(price))>0 && getFunds(msg.sender, false)+getMaxLossAfterTrade(msg.sender, optionChainID, optionID, matchSize, -matchSize * int(price))>0) {\n if (optionChains[optionChainID].positions[msg.sender].hasPosition == false) {\n optionChains[optionChainID].positions[msg.sender].hasPosition = true;\n optionChains[optionChainID].numPositions++;\n }\n if (optionChains[optionChainID].positions[addr].hasPosition == false) {\n optionChains[optionChainID].positions[addr].hasPosition = true;\n optionChains[optionChainID].numPositions++;\n }\n optionChains[optionChainID].positions[msg.sender].positions[optionID] += matchSize;\n optionChains[optionChainID].positions[msg.sender].cash -= matchSize * int(price);\n optionChains[optionChainID].positions[addr].positions[optionID] -= matchSize;\n optionChains[optionChainID].positions[addr].cash += matchSize * int(price);\n orderFills[hash] -= matchSize;\n }\n }\n\n function getMaxLossAfterTrade(address user, uint optionChainID, uint optionID, int positionChange, int cashChange) constant returns(int) {\n int totalMaxLoss = 0;\n for (uint i=0; i<numOptionChains; i++) {\n if (optionChains[i].positions[user].expired == false && optionChains[i].numOptions>0) {\n bool maxLossInitialized = false;\n int maxLoss = 0;\n for (uint s=0; s<optionChains[i].numOptions; s++) {\n int pnl = optionChains[i].positions[user].cash / 1000000000000000000;\n if (i==optionChainID) {\n pnl += cashChange / 1000000000000000000;\n }\n uint settlement = 0;\n if (optionChains[i].options[s].strike<0) {\n settlement = uint(-optionChains[i].options[s].strike);\n } else {\n settlement = uint(optionChains[i].options[s].strike);\n }\n pnl += moneySumAtSettlement(user, optionChainID, optionID, positionChange, i, settlement);\n if (pnl<maxLoss || maxLossInitialized==false) {\n maxLossInitialized = true;\n maxLoss = pnl;\n }\n pnl = optionChains[i].positions[user].cash / 1000000000000000000;\n if (i==optionChainID) {\n pnl += cashChange / 1000000000000000000;\n }\n settlement = 0;\n if (optionChains[i].options[s].strike<0) {\n if (uint(-optionChains[i].options[s].strike)>optionChains[i].margin) {\n settlement = uint(-optionChains[i].options[s].strike)-optionChains[i].margin;\n }\n } else {\n settlement = uint(optionChains[i].options[s].strike)+optionChains[i].margin;\n }\n pnl += moneySumAtSettlement(user, optionChainID, optionID, positionChange, i, settlement);\n if (pnl<maxLoss) {\n maxLoss = pnl;\n }\n }\n totalMaxLoss += maxLoss;\n }\n }\n return totalMaxLoss;\n }\n\n function moneySumAtSettlement(address user, uint optionChainID, uint optionID, int positionChange, uint i, uint settlement) internal returns(int) {\n int pnl = 0;\n for (uint j=0; j<optionChains[i].numOptions; j++) {\n pnl += optionChains[i].positions[user].positions[j] * getMoneyness(optionChains[i].options[j].strike, settlement, optionChains[i].margin) / 1000000000000000000;\n if (i==optionChainID && j==optionID) {\n pnl += positionChange * getMoneyness(optionChains[i].options[j].strike, settlement, optionChains[i].margin) / 1000000000000000000;\n }\n }\n return pnl;\n }\n\n function min(uint a, uint b) constant returns(uint) {\n if (a<b) {\n return a;\n } else {\n return b;\n }\n }\n}\n","language":"Solidity","languageVersion":"0.2.0","compilerVersion":"0.2.0","compilerOptions":"--bin --abi --userdoc --devdoc --add-std --optimize -o /var/folders/sj/bz257rsj0w1g7cpjjycd7wpw0000gn/T/solc800911265","abiDefinition":[{"constant":false,"inputs":[{"name":"accountID","type":"uint256"},{"name":"optionChainID","type":"uint256"},{"name":"v","type":"uint8"},{"name":"r","type":"bytes32"},{"name":"s","type":"bytes32"},{"name":"value","type":"bytes32"}],"name":"expire","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"getMarketMakerFunds","outputs":[{"name":"","type":"int256"},{"name":"","type":"int256"},{"name":"","type":"int256"},{"name":"","type":"int256"},{"name":"","type":"int256"},{"name":"","type":"int256"}],"type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"withdrawFunds","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"optionChainID","type":"uint256"}],"name":"getOptionChain","outputs":[{"name":"","type":"uint256"},{"name":"","type":"string"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"bytes32"},{"name":"","type":"address"}],"type":"function"},{"constant":true,"inputs":[],"name":"getMarketMakers","outputs":[{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"string"}],"type":"function"},{"constant":true,"inputs":[{"name":"optionChainID","type":"uint256"},{"name":"optionID","type":"uint256"},{"name":"price","type":"uint256"},{"name":"size","type":"int256"},{"name":"orderID","type":"uint256"},{"name":"blockExpires","type":"uint256"},{"name":"addr","type":"address"},{"name":"sender","type":"address"},{"name":"matchSize","type":"int256"}],"name":"orderMatchTest","outputs":[{"name":"","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"server","type":"string"}],"name":"marketMaker","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"user","type":"address"},{"name":"onlyAvailable","type":"bool"}],"name":"getFunds","outputs":[{"name":"","type":"int256"}],"type":"function"},{"constant":false,"inputs":[{"name":"optionChainID","type":"uint256"},{"name":"optionID","type":"uint256"},{"name":"price","type":"uint256"},{"name":"size","type":"int256"},{"name":"orderID","type":"uint256"},{"name":"blockExpires","type":"uint256"},{"name":"addr","type":"address"},{"name":"v","type":"uint8"},{"name":"r","type":"bytes32"},{"name":"s","type":"bytes32"},{"name":"matchSize","type":"int256"}],"name":"orderMatch","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"a","type":"uint256"},{"name":"b","type":"uint256"}],"name":"min","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[],"name":"addFunds","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"user","type":"address"}],"name":"getMarket","outputs":[{"name":"","type":"uint256[]"},{"name":"","type":"int256[]"},{"name":"","type":"int256[]"},{"name":"","type":"int256[]"}],"type":"function"},{"constant":true,"inputs":[{"name":"user","type":"address"}],"name":"getFundsAndAvailable","outputs":[{"name":"","type":"int256"},{"name":"","type":"int256"}],"type":"function"},{"constant":true,"inputs":[],"name":"numMarketMakers","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[{"name":"strike","type":"int256"},{"name":"settlement","type":"uint256"},{"name":"margin","type":"uint256"}],"name":"getMoneyness","outputs":[{"name":"","type":"int256"}],"type":"function"},{"constant":false,"inputs":[{"name":"existingOptionChainID","type":"uint256"},{"name":"expiration","type":"uint256"},{"name":"underlying","type":"string"},{"name":"margin","type":"uint256"},{"name":"realityID","type":"uint256"},{"name":"factHash","type":"bytes32"},{"name":"ethAddr","type":"address"},{"name":"strikes","type":"int256[]"}],"name":"addOptionChain","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"user","type":"address"},{"name":"optionChainID","type":"uint256"},{"name":"optionID","type":"uint256"},{"name":"positionChange","type":"int256"},{"name":"cashChange","type":"int256"}],"name":"getMaxLossAfterTrade","outputs":[{"name":"","type":"int256"}],"type":"function"},{"inputs":[],"type":"constructor"}],"userDoc":{"methods":{}},"developerDoc":{"methods":{}}}}}