forked from gitter-badger/etheropt.github.io
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathetheropt.sol.compiled
1 lines (1 loc) · 36 KB
/
etheropt.sol.compiled
1
{"Etheropt":{"code":"0x606060405260006004600050556123378061001a6000396000f3606060405236156100fb5760e060020a600035046303cf4fd681146100fd5780630e1087c3146101c7578063155dd5ee14610241578063177766e6146102715780632043285d1461031e57806342bf44311461043b578063502414e41461054a5780635c665f89146105a3578063615664ba146105ef5780636b1cb549146105f45780637ae2b5c7146107565780637c7c7695146107705780637d380265146107955780638ce25a931461094a578063a26759cb14610953578063ce88b14514610994578063d4dfadbf146109b7578063d5544f9414610c3b578063dc06b85914610c50578063ec0b415314610c59578063fe4667e914610c8a575b005b6100fb60043560243560443560643560843560a43560008581526020819052604081206008015481908190819060ff16811415611fc957604080822081516005820154600492909201548152602081810189905283519182900384018220825260ff8c16828201528184018b9052606082018a90529251600160a060020a039290921692600192608083810193829003018187866161da5a03f11561000257505060405151600160a060020a03161415611fc957600754935089811415611e845760019950611e88565b610e4a6000600060006000600060006020604051908101604052806000815260200150600060066040518059106101fb5750595b90808252806020026020018201604052509150600190505b6004548111611d6957600081815260036020526040812054611dfe91600160a060020a0391909116906105ad565b6100fb60043533600160a060020a031660009081526008602052604081205411156112f3576119183360016105ad565b610e7d6004356040805160208181018352600080835284815280825283812080546001828101805488516002868101546003880154600489015460059099015496851615610100026000190190941691909104601f81018a90048a0283018a01909b528a825296998a98899889988998979195949093600160a060020a03929092169290918791830182828015611e495780601f10611e1e57610100808354040283529160200191611e49565b610f1760408051602081810183526000808352835180830185528181528451808401865282815285518085018752838152865180860188528481528751808701895285815288519687018952858752975196979396929591949093926006908059106103875750595b90808252806020026020018201604052816020015b60408051602081810190925260008152825260001990920191018161039c579050509150600190505b6004548111611c7e57600081815260036020908152604091829020600190810180548451600293821615610100026000190190911692909204601f810184900484028301840190945283825290929091830182828015611d445780601f10611d1957610100808354040283529160200191611d44565b61116060043560243560443560643560843560a43560c43560e43561010435600084431115801561052f57506000871380156104775750600082125b80156104c85750604080518b815260208181018c90528183018b9052606082018a90526080820189905260a0820188905282519182900360c001909120600090815260029091522054829003879013155b8061052f57506000871280156104de5750600082135b801561052f5750604080518b815260208181018c90528183018b9052606082018a90526080820189905260a0820188905282519182900360c001909120600090815260029091522054829003879012155b801561130a57506000611325858c8c866000038d8802610c9d565b6040805160206004803580820135601f81018490048402850184019095528484526100fb94919360249390929184019190819084018382808284375094965050505050505060006000600060003411156119cd57610002565b6111606004356024355b600160a060020a0382166000908152600860205260408120548190111561196f578160001415611977576040808220548252600660205290206001015461169b565b6100fb565b6100fb60043560243560443560643560843560a43560c43560e435610104356101243561014435604080518c815260208181018d90528183018c9052606082018b9052608082018a905260a08201899052915160009260029260c08181019391829003018186866161da5a03f11561000257505060408051805160ff88166020838101919091528284018890526060830187905292519093600160a060020a038a169360019360808181019492939183900301908290866161da5a03f11561000257505060405151600160a060020a03161480156106d25750864311155b801561073b57506000891380156106e95750600082125b80156107075750600081815260026020526040902054829003899013155b8061073b575060008912801561071d5750600082135b801561073b5750600081815260026020526040902054829003899012155b801561134e57506000611369878e8e866000038f8802610c9d565b61116060043560243560008183101561169857508161169b565b611160600435600160a060020a0381166000908152600860205260409020545b919050565b60408051602060248035600481810135601f81018590048502860185019096528585526100fb9581359591946044949293909201918190840183828082843750506040805160c435808a013560208181028085018201909552818452989a99359960643599608435995060a435985090965060e495509293602492909201929091829185019084908082843750949650505050505050600060006000600060069350600660016000505410156120c9576001805480820190915593505b600684101561228c576000848152602081905260408120818155600181810180548482559293929091600290821615610100026000190190911604601f81901061214457505b5050600060028281018290556003830182905560048301829055600583018054600160a060020a03191690556007830182905560088301805460ff19169055600a8301829055600b9092018190558581526020818152604082208e81558d516001918201805481865294849020909592851615610100026000190190941691909104601f90810183900484019391928f019083901061216257805160ff19168380011785555b50612192929150611a52565b61116060075481565b6100fb33600160a060020a0316600090815260086020526040812054819011156112a3576040808220548252600660205281206001018054340190556112f3565b611172600435600081815260066020526040902054600160a060020a0316610790565b61118f60043560408051602081810183526000808352835180830185528181528451808401865282815285518085018752838152865180860188528481528751808701895285815288518088018a5286815289519788018a5286885298519798949793969295919490939092919081908190603c90805910610a365750595b90808252806020026020018201604052509650603c604051805910610a585750595b90808252806020026020018201604052509550603c604051805910610a7a5750595b90808252806020026020018201604052509450603c604051805910610a9c5750595b81815260209182028101909101604052600154909450600093506000190191505b60008212158015610ace5750603c83105b15611e655760008281526020819052604081206008015460ff161415611e78575060005b600082815260208190526040902060070154811015611e785780826103e80201878481518110156100025760406000818120602084810290950185019590955285815260069490940190925291205487519091889181101561000257906020019060200201909081815260200150506000600050600083815260200190815260200160002060005060090160005060008d600160a060020a031681526020019081526020016000206000506000016000506000828152602001908152602001600020600050548584815181101561000257906020019060200201909081815260200150506000600050600083815260200190815260200160002060005060090160005060008d600160a060020a03168152602001908152602001600020600050600101600050548484815181101561000257505060208481028601015260019283019201610af2565b61128a600435600060006119b98360006105ad565b61116060045481565b6111606004356024356044355b600080841261209257838311156120b7578184840310156120c257508282036120bb565b6111606004356024356044356064356084355b6000808080808080805b6001548610156116a1576000600050600087815260200190815260200160002060005060090160005060008e600160a060020a0316815260200190815260200160002060005060020160009054906101000a900460ff166000148015610d2c575060006000600050600088815260200190815260200160002060005060070160005054115b156116b7576000945060009350600092505b6000868152602081905260409020600701548310156116b257670de0b6b3a76400006000600050600088815260200190815260200160002060005060090160005060008f600160a060020a03168152602001908152602001600020600050600101600050540591508b861415610dbe57670de0b6b3a76400008905909101905b6000905060006000600050600088815260200190815260200160002060005060060160005060008581526020019081526020016000206000506000016000505412156116c35760006000506000878152602001908152602001600020600050600601600050600084815260200190815260200160002060005060000160005054600003905080506116e0565b604080519687526020870195909552858501939093526060850191909152608084015260a0830152519081900360c00190f35b604051808781526020018060200186815260200185815260200184815260200183600160a060020a031681526020018281038252878181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015610f045780820380516001836020036101000a031916815260200191505b5097505050505050505060405180910390f35b6040518080602001806020018060200180602001806020018060200187810387528d8181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015610f8b5780820380516001836020036101000a031916815260200191505b5087810386528c8181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015610fe45780820380516001836020036101000a031916815260200191505b5087810385528b8181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561103d5780820380516001836020036101000a031916815260200191505b5087810384528a8181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156110965780820380516001836020036101000a031916815260200191505b508781038352898181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156110ef5780820380516001836020036101000a031916815260200191505b508781038252888181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156111485780820380516001836020036101000a031916815260200191505b509c5050505050505050505050505060405180910390f35b60408051918252519081900360200190f35b60408051600160a060020a03929092168252519081900360200190f35b60405180806020018060200180602001806020018581038552898181518152602001915080519060200190602002808383829060006004602084601f0104600f02600301f1509050018581038452888181518152602001915080519060200190602002808383829060006004602084601f0104600f02600301f1509050018581038352878181518152602001915080519060200190602002808383829060006004602084601f0104600f02600301f1509050018581038252868181518152602001915080519060200190602002808383829060006004602084601f0104600f02600301f1509050019850505050505050505060405180910390f35b6040805192835260208301919091528051918290030190f35b506007805460019081019182905560008281526006602090815260408083208054600160a060020a0319163390811782559401805434019055600160a060020a0393909316825260089052208190555b50565b5060005b9998505050505050505050565b01135b801561133357506000611340848c8c868d8860000302610c9d565b6113078660006105ad565b01135b156112f6575060016112fa565b6113308560006105ad565b01135b80156113775750600061168d338e8e868f8860000302610c9d565b61134b8860006105ad565b01135b1561167f5760008c81526020818152604080832033600160a060020a03168452600901909152812060020154610100900460ff161415611436576001600060005060008e8152602001908152602001600020600050600901600050600033600160a060020a0316815260200190815260200160002060005060020160016101000a81548160ff02191690830217905550600060005060008d8152602001908152602001600020600050600a016000818150548092919060010191905055505b60008c815260208181526040808320600160a060020a038a168452600901909152812060020154610100900460ff1614156114f0576001600060005060008e8152602001908152602001600020600050600901600050600088600160a060020a0316815260200190815260200160002060005060020160016101000a81548160ff02191690830217905550600060005060008d8152602001908152602001600020600050600a016000818150548092919060010191905055505b81600060005060008e8152602001908152602001600020600050600901600050600033600160a060020a0316815260200190815260200160002060005060000160005060008d8152602001908152602001600020600082828250540192505081905550898202600060005060008e8152602001908152602001600020600050600901600050600033600160a060020a0316815260200190815260200160002060005060010160008282825054039250508190555081600060005060008e8152602001908152602001600020600050600901600050600088600160a060020a0316815260200190815260200160002060005060000160005060008d8152602001908152602001600020600082828250540392505081905550898202600060005060008e8152602001908152602001600020600050600901600050600088600160a060020a0316815260200190815260200160002060005060010160008282825054019250508190555081600260005060008381526020019081526020016000206000828282505403925050819055505b505050505050505050505050565b6113743360006105ad565b50805b92915050565b50949b9a5050505050505050505050565b958301955b60019590950194610ca7565b506000858152602081815260408083208584526006019091529020545b6117428d8d8d8d8a865b600080805b6000858152602081905260409020600701548110156122995760406000818120838252600681016020908152928220548883529190925260029190910154670de0b6b3a7640000916122a5918790610c66565b9190910190838212806117555750846000145b15611764576001945090925082905b670de0b6b3a76400006000600050600088815260200190815260200160002060005060090160005060008f600160a060020a031681526020019081526020016000206000506001016000505405915081508b8614156117cd57670de0b6b3a76400008905909101905b50600085815260208181526040808320858452600601909152812054819012156118bb5760006000506000878152602001908152602001600020600050600201600050546000600050600088815260200190815260200160002060005060060160005060008581526020019081526020016000206000506000016000505460000311156118f05760006000506000878152602001908152602001600020600050600201600050546000600050600088815260200190815260200160002060005060060160005060008581526020019081526020016000206000506000016000505460000303905080506118f4565b50600085815260208181526040808320600281015486855260069190910190925290912054015b6118f98d8d8d8d8a866116ea565b5060005b6118e2565b91909101908382121561190c5781935083505b60019290920191610d3e565b81131580156119275750600081135b156112f35733600160a060020a0316600081815260086020908152604080832054835260069091528082206001018054859003905551839082818181858883f1505050505050565b50600061169b565b611988836000600060006000610c9d565b600160a060020a0384166000908152600860209081526040808320548352600690915290206001015401905061169b565b6119c48460016105ad565b91509150915091565b33600160a060020a03166000908152600560205260408120541115611a66576040600081812054815260036020908152918120600190810180548851828552938590209194600293821615610100026000190190911692909204601f90810183900482019392890190839010611a8b57805160ff19168380011785555b50611abb9291505b80821115611ac45760008155600101611a52565b600081815260036020526040812054611ac891600160a060020a0391909116906105ad565b82800160010185558215611a4a579182015b82811115611a4a578251826000505591602001919060010190611a9d565b50505b50505050565b5090565b92506000915060066004600050541015611b8657600480546001019081905591505b6000821115611c275760008281526003602081815260408084208054600160a060020a03168552600583529084208490558584529181528154600160a060020a0319163317825586516001928301805481865294839020909460029481161561010002600019011693909304601f9081018390048401939192890190839010611c2c57805160ff19168380011785555b50611c5c929150611a52565b5060025b6004548111611aea576000818152600360205260408120548491611bb791600160a060020a0316906105ad565b13158015611bf157508160001480611bf15750600082815260036020526040812054611c0291600160a060020a0391909116906105ad565b125b15611bfa579050805b600101611b8a565b600082815260036020526040812054611bef91600160a060020a0391909116906105ad565b610002565b82800160010185558215611b7a579182015b82811115611b7a578251826000505591602001919060010190611c3e565b505033600160a060020a03166000908152600560205260409020829055611abe565b8160008151811015610002579060200190602002015182600181518110156100025790602001906020020151836002815181101561000257906020019060200201518460038151811015610002579060200190602002015185600481518110156100025790602001906020020151866005815181101561000257505060c0870151949c50929a509098509650945092505b5050909192939495565b820191906000526020600020905b815481529060010190602001808311611d2757829003601f168201915b50505050508260018303815181101561000257602090810290910101526001016103c5565b816000815181101561000257906020019060200201518260018151811015610002579060200190602002015183600281518110156100025790602001906020020151846003815181101561000257906020019060200201518560048151811015610002579060200190602002015186600581518110156100025790602001906020020151975097509750975097509750611d0f565b826001830381518110156100025760209081029091010152600101610213565b820191906000526020600020905b815481529060010190602001808311611e2c57829003601f168201915b5050505050945095509550955095509550955091939550919395565b50949a9399509197509550909350505050565b60001990910190610abd565b8993505b838a11611f96576000898152602081815260408083208d84526006835281842054600160a060020a0316845260090190915281206002015460ff16141561203157670de0b6b3a7640000600060005060008b81526020019081526020016000206000506009016000506000600660005060008e815260200190815260200160002060005060000160009054906101000a9004600160a060020a0316600160a060020a0316815260200190815260200160002060005060010160005054059250600091505b600089815260208190526040902060070154821015611fd55760406000818120848252600681016020908152928220548c8352919092526002919091015461203d91908790610c66565b6000898152602081905260409020600a810154600b909101541415611fc9576040600020600801805460ff191660011790555b50505050505050505050565b60008a815260066020908152604080832060018181018054890190558d85528484528285209154600160a060020a03168552600982018452918420600201805460ff1916831790558c845292909152600b909101805490910190555b60019990990198611e88565b60008a8152602081815260408083208e84526006835281842054600160a060020a031684526009018252808320868452909152902054670de0b6b3a76400009082020590930192905060019190910190611f4c565b836000038310156120b7578183856000030310156120c25782846000030390506120bb565b5060005b9392505050565b50806120bb565b600092505b600154831080156120e0575060068410155b156108525760008381526020819052604090206008015460ff1660011480612113575060406000908120848252600a0154145b8061212d5750600083815260208190526040812060070154145b156121385782935083505b600192909201916120ce565b601f0160209004906000526020600020908101906108989190611a52565b8280016001018555821561093e579182015b8281111561093e578251826000505591602001919060010190612174565b50506000848152602081905260408120600281018b9055600381018a9055600481018990556005018054600160a060020a0319168817905592505b845183101561228c57600084815260208190526040902060070154600a90101561228057505060406000818120600781018054600181019091558483526006919091016020529190208451859084908110156100025790602001906020020151816000016000508190555080600060005060008681526020019081526020016000206000506006016000506000858152602001908152602001600020600050600082016000505481600001600050559050505b600192909201916121cd565b5050505050505050505050565b50979650505050505050565b600087815260208181526040808320600160a060020a038f168452600901825280832086845290915290205402059091019087851480156122e557508681145b1561232f57600085815260208181526040808320848452600681018352908320548884529290915260020154670de0b6b3a764000091612326918790610c66565b87020591909101905b6001016116ef56","info":{"source":"contract Etheropt {\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 mapping(address => uint) marketMakerIDs;\n mapping(uint => Account) accounts;\n uint public numAccounts;\n mapping(address => uint) accountIDs; //starts at 1\n\n function Market() {\n }\n\n function getAccountID(address user) constant returns(uint) {\n return accountIDs[user];\n }\n\n function getAccount(uint accountID) constant returns(address) {\n return accounts[accountID].user;\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) && int(amount)>0) {\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<6) {\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 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].numPositions==0 || optionChains[i].numOptions==0) {\n optionChainID = i;\n }\n }\n }\n if (optionChainID<6) {\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 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 } else {\n settlement = 0;\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/solc039447253","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":"Market","outputs":[],"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":true,"inputs":[{"name":"user","type":"address"}],"name":"getAccountID","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"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":"numAccounts","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[],"name":"addFunds","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"accountID","type":"uint256"}],"name":"getAccount","outputs":[{"name":"","type":"address"}],"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":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"}],"userDoc":{"methods":{}},"developerDoc":{"methods":{}}}}}