Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0xdc8d23092b93F9BB7416F45dEa36f55996f34867
Balance 0 ETH
Nonce 1
Code Size 16293 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

16293 bytes
0x608060405234801561001057600080fd5b50600436106102115760003560e01c806389aaad2911610125578063cafbc49d116100ad578063de2273241161007c578063de227324146109ff578063e0d5b9e114610a24578063e30c397814610a41578063f05d16f714610a49578063f2fde38b14610a6657610211565b8063cafbc49d14610904578063cf820461146109cc578063d50a04f4146109d4578063db6c709c146109dc57610211565b80639ac47353116100f45780639ac4735314610776578063a4b138b014610846578063b14f84321461087e578063b9b8af0b146108be578063bee7d433146108c657610211565b806389aaad291461071d5780638da5cb5b1461072557806394727b411461072d57806396002aef1461074a57610211565b80634e71e0c8116101a85780635ed7ca5b116101775780635ed7ca5b146104d35780635f28cb74146104db578063683ec0a71461050757806379054391146105cf57806379c88f20146106f957610211565b80634e71e0c81461042657806353f81ef81461042e57806357fa3db71461046657806358f816bf146104b657610211565b80631f4e09af116101e45780631f4e09af1461029257806325cc3a20146102c45780633a20e9df146102f05780634d8a9499146103fa57610211565b80630398751214610216578063046f7da21461024a5780630ddeb632146102525780631a464fa114610275575b600080fd5b6102486004803603606081101561022c57600080fd5b50803590602081013590604001356001600160a01b0316610a8c565b005b610248610afa565b6102486004803603604081101561026857600080fd5b5080359060200135610b7a565b6102486004803603602081101561028b57600080fd5b5035610be5565b610248600480360360608110156102a857600080fd5b50803590602081013590604001356001600160a01b0316610d1a565b610248600480360360408110156102da57600080fd5b50803590602001356001600160a01b0316610e58565b61030d6004803603602081101561030657600080fd5b5035611031565b6040518080602001896001600160a01b03166001600160a01b03168152602001886001600160a01b03166001600160a01b0316815260200187815260200186600181111561035757fe5b60ff16815260200185815260200184600181111561037157fe5b60ff1681526020018315151515815260200182810382528a818151815260200191508051906020019080838360005b838110156103b85781810151838201526020016103a0565b50505050905090810190601f1680156103e55780820380516001836020036101000a031916815260200191505b50995050505050505050505060405180910390f35b6102486004803603604081101561041057600080fd5b50803590602001356001600160a01b03166111e5565b6102486113be565b61044b6004803603602081101561044457600080fd5b5035611474565b60408051921515835260208301919091528051918290030190f35b6104926004803603604081101561047c57600080fd5b50803590602001356001600160a01b031661148a565b604051808260038111156104a257fe5b60ff16815260200191505060405180910390f35b610248600480360360208110156104cc57600080fd5b503561152a565b6102486117a5565b61044b600480360360408110156104f157600080fd5b50803590602001356001600160a01b0316611828565b610248600480360360c081101561051d57600080fd5b81359190810190604081016020820135600160201b81111561053e57600080fd5b82018360208201111561055057600080fd5b803590602001918460018302840111600160201b8311171561057157600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550506001600160a01b038335169350505060208101359060ff6040820135169060600135611af7565b6105ec600480360360208110156105e557600080fd5b5035611b96565b604051808b8152602001806020018a6001600160a01b03166001600160a01b03168152602001896001600160a01b03166001600160a01b0316815260200188815260200187600181111561063c57fe5b60ff16815260200186815260200185600181111561065657fe5b60ff168152602001846001600160a01b03166001600160a01b031681526020018315151515815260200182810382528b818151815260200191508051906020019080838360005b838110156106b557818101518382015260200161069d565b50505050905090810190601f1680156106e25780820380516001836020036101000a031916815260200191505b509b50505050505050505050505060405180910390f35b610701611c8a565b604080516001600160a01b039092168252519081900360200190f35b610701611c99565b610701611ca8565b6102486004803603602081101561074357600080fd5b5035611cb7565b6102486004803603604081101561076057600080fd5b50803590602001356001600160a01b0316611e83565b610248600480360360e081101561078c57600080fd5b81359190810190604081016020820135600160201b8111156107ad57600080fd5b8201836020820111156107bf57600080fd5b803590602001918460018302840111600160201b831117156107e057600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550506001600160a01b038335169350505060208101359060ff60408201351690606081013590608001351515611fcc565b6102486004803603606081101561085c57600080fd5b506001600160a01b038135811691602081013582169160409091013516612267565b6108aa6004803603604081101561089457600080fd5b50803590602001356001600160a01b03166122bd565b604080519115158252519081900360200190f35b6108aa6122d1565b6108f2600480360360608110156108dc57600080fd5b508035906020810135906040013560ff166122da565b60408051918252519081900360200190f35b610248600480360360c081101561091a57600080fd5b81359190810190604081016020820135600160201b81111561093b57600080fd5b82018360208201111561094d57600080fd5b803590602001918460018302840111600160201b8311171561096e57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550506001600160a01b038335169350505060208101359060ff604082013516906060013561234d565b6108f26123c1565b6108f26123c7565b610248600480360360408110156109f257600080fd5b50803590602001356123cd565b61024860048036036040811015610a1557600080fd5b508035906020013515156124ae565b61024860048036036020811015610a3a57600080fd5b503561265e565b6107016127b9565b61024860048036036020811015610a5f57600080fd5b50356127c8565b61024860048036036020811015610a7c57600080fd5b50356001600160a01b0316612898565b60085460ff161580610aa857506000546001600160a01b031633145b610ae8576040805162461bcd60e51b815260206004820152600c60248201526b195c9c9bdc97da185b1d195960a21b604482015290519081900360640190fd5b610af58383836001612905565b505050565b6000546001600160a01b03163314610b45576040805162461bcd60e51b815260206004820152600960248201526837b7363ca7bbb732b960b91b604482015290519081900360640190fd5b6008805460ff191690556040517f62451d457bc659158be6e6247f56ec1df424a5c7597f71c20c2bc44e0965c8f990600090a1565b60085460ff161580610b9657506000546001600160a01b031633145b610bd6576040805162461bcd60e51b815260206004820152600c60248201526b195c9c9bdc97da185b1d195960a21b604482015290519081900360640190fd5b610be1828233610a8c565b5050565b60085460ff161580610c0157506000546001600160a01b031633145b610c41576040805162461bcd60e51b815260206004820152600c60248201526b195c9c9bdc97da185b1d195960a21b604482015290519081900360640190fd5b610c4a81612f98565b506000818152600660205260409020600781015461010090046001600160a01b03163314610cb4576040805162461bcd60e51b8152602060048201526012602482015271195c9c9bdc97db9bdd14195c9b5a5d1d195960721b604482015290519081900360640190fd5b60028101546040516001600160a01b0390911690839033907eaf27297c740fbece798135b71b06164310e0591b6c729e50b8026dcc60be5090600090a46002810180546001600160a01b031916331790556007018054610100600160a81b031916905550565b60085460ff161580610d3657506000546001600160a01b031633145b610d76576040805162461bcd60e51b815260206004820152600c60248201526b195c9c9bdc97da185b1d195960a21b604482015290519081900360640190fd5b826000610d8282611031565b50505050505091505060006001600160a01b0316816001600160a01b03161415610de4576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6001600160a01b038116331480610e0557506000546001600160a01b031633145b610e44576040805162461bcd60e51b81526020600482015260176024820152600080516020613f09833981519152604482015290519081900360640190fd5b610e518585856000612905565b5050505050565b816000610e6482611031565b50505050505091505060006001600160a01b0316816001600160a01b03161415610ec6576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6001600160a01b038116331480610ee757506000546001600160a01b031633145b610f26576040805162461bcd60e51b81526020600482015260176024820152600080516020613f09833981519152604482015290519081900360640190fd5b610f2f84612f98565b5060008481526006602052604090208054610f82576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6007810154600160a81b900460ff16610fde576040805162461bcd60e51b8152602060048201526019602482015278195c9c9bdc97ddda1a5d195b1a5cdd139bdd115b98589b1959603a1b604482015290519081900360640190fd5b6001600160a01b0384166000818152600983016020526040808220805460ff191660021790555187917f391da9ecb91abda3886c59d98ecdb8fa7154c525b5c6a575ef67cef1f5a8d85491a35050505050565b6060600080600080600080600061104789613349565b969e50949c50929a5090985096509450925090506001600160a01b0387161561106f576111da565b6004805460408051633a20e9df60e01b81529283018c9052516001600160a01b0390911691633a20e9df916024808301926000929190829003018186803b1580156110b957600080fd5b505afa1580156110cd573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405260e08110156110f657600080fd5b8101908080516040519392919084600160201b82111561111557600080fd5b90830190602082018581111561112a57600080fd5b8251600160201b81118282018810171561114357600080fd5b82525081516020918201929091019080838360005b83811015611170578181015183820152602001611158565b50505050905090810190601f16801561119d5780820380516001836020036101000a031916815260200191505b5060409081526020820151908201516060830151608084015160a085015160c090950151979f50929d50909b509950975095509193506000925050505b919395975091939597565b8160006111f182611031565b50505050505091505060006001600160a01b0316816001600160a01b03161415611253576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6001600160a01b03811633148061127457506000546001600160a01b031633145b6112b3576040805162461bcd60e51b81526020600482015260176024820152600080516020613f09833981519152604482015290519081900360640190fd5b6112bc84612f98565b506000848152600660205260409020805461130f576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6007810154600160a81b900460ff1661136b576040805162461bcd60e51b8152602060048201526019602482015278195c9c9bdc97ddda1a5d195b1a5cdd139bdd115b98589b1959603a1b604482015290519081900360640190fd5b6001600160a01b0384166000818152600983016020526040808220805460ff191660031790555187917f71195ce6244a4b5ea0742ce64ede6bac9a2111edb4e732886198ff6ecf58651c91a35050505050565b6001546001600160a01b03163314611410576040805162461bcd60e51b815260206004820152601060248201526f37b7363ca832b73234b733a7bbb732b960811b604482015290519081900360640190fd5b600154600080546040516001600160a01b0393841693909116917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a360018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b6000806114818333611828565b91509150915091565b60008061149684611031565b50505050505091505060006001600160a01b0316816001600160a01b031614156114f8576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b505060008281526006602090815260408083206001600160a01b038516845260090190915290205460ff165b92915050565b80600061153682611031565b50505050505091505060006001600160a01b0316816001600160a01b03161415611598576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6001600160a01b0381163314806115b957506000546001600160a01b031633145b6115f8576040805162461bcd60e51b81526020600482015260176024820152600080516020613f09833981519152604482015290519081900360640190fd5b61160183612f98565b50600083815260066020526040812090600782015460ff16600181111561162457fe5b14611676576040805162461bcd60e51b815260206004820152601760248201527f6572726f725f6d75737442654e6f744465706c6f796564000000000000000000604482015290519081900360640190fd5b60078101805460ff1916600190811790915560028201546003830154600484015460058501546006860154604080516001600160a01b03958616602082018190529181018590528b9795909616957f07ace6911e28d0d5b2e773ce49cdfa29db157b38bffccd5f0b56f02cfba8a64f95808a01959294929360ff90931692919081906060820190859081111561170857fe5b60ff168152602081018490526040838203810183528854600260018216156101000260001901909116049082018190526060909101908890801561178d5780601f106117625761010080835404028352916020019161178d565b820191906000526020600020905b81548152906001019060200180831161177057829003601f168201915b5050965050505050505060405180910390a350505050565b6000546001600160a01b031633146117f0576040805162461bcd60e51b815260206004820152600960248201526837b7363ca7bbb732b960b91b604482015290519081900360640190fd5b6008805460ff191660011790556040517f1ee9080f6b55ca44ce58681c8162e6c1ac1c47e1da791a4a1c1ec6186d8af1f390600090a1565b600080600061183685613349565b50505050505091505060006001600160a01b0316816001600160a01b031614156118e75760048054604080516317ca32dd60e21b81529283018890526001600160a01b0387811660248501528151921692635f28cb749260448083019392829003018186803b1580156118a857600080fd5b505afa1580156118bc573d6000803e3d6000fd5b505050506040513d60408110156118d257600080fd5b5080516020909101519093509150611af09050565b60006118f38686613523565b805490925015159050611ade576004805460408051633a20e9df60e01b8152928301899052516000926001600160a01b0390921691633a20e9df9160248083019286929190829003018186803b15801561194c57600080fd5b505afa158015611960573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405260e081101561198957600080fd5b8101908080516040519392919084600160201b8211156119a857600080fd5b9083019060208201858111156119bd57600080fd5b8251600160201b8111828201881017156119d657600080fd5b82525081516020918201929091019080838360005b83811015611a035781810151838201526020016119eb565b50505050905090810190601f168015611a305780820380516001836020036101000a031916815260200191505b5060405260200151935050506001600160a01b038216159050611adc5760048054604080516317ca32dd60e21b81529283018a90526001600160a01b0389811660248501528151921692635f28cb749260448083019392829003018186803b158015611a9b57600080fd5b505afa158015611aaf573d6000803e3d6000fd5b505050506040513d6040811015611ac557600080fd5b5080516020909101519095509350611af092505050565b505b611ae78161359b565b90549093509150505b9250929050565b60085460ff161580611b1357506000546001600160a01b031633145b611b53576040805162461bcd60e51b815260206004820152600c60248201526b195c9c9bdc97da185b1d195960a21b604482015290519081900360640190fd5b611b6386868686868660016135a2565b60405186907f507847149b655f0d87f5cadd67619cd1c0a53b2cbb153d2f08f83614b4c29b7890600090a2505050505050565b6006602090815260009182526040918290208054600180830180548651600293821615610100026000190190911692909204601f810186900486028301860190965285825291949293909290830182828015611c335780601f10611c0857610100808354040283529160200191611c33565b820191906000526020600020905b815481529060010190602001808311611c1657829003601f168201915b5050506002840154600385015460048601546005870154600688015460079098015496976001600160a01b0394851697938516965091945060ff9081169391928082169261010082041691600160a81b909104168a565b6002546001600160a01b031681565b6003546001600160a01b031681565b6000546001600160a01b031681565b806000611cc382611031565b50505050505091505060006001600160a01b0316816001600160a01b03161415611d25576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6001600160a01b038116331480611d4657506000546001600160a01b031633145b611d85576040805162461bcd60e51b81526020600482015260176024820152600080516020613f09833981519152604482015290519081900360640190fd5b611d8e83612f98565b5060008381526006602052604090206001600782015460ff166001811115611db257fe5b14611df8576040805162461bcd60e51b8152602060048201526011602482015270195c9c9bdc97db9bdd11195c1b1bde5959607a1b604482015290519081900360640190fd5b60078101805460ff1916905560028101546003820154600483015460058401546006850154604080516001600160a01b03958616602082018190529181018590528a9695909516947ffc64345d61f75f77f5039b0e23107d4abd73ecb7cd6c94fd44e8a6dd85918f6a946001808a01959394919360ff16929081906060820190859081111561170857fe5b816000611e8f82611031565b50505050505091505060006001600160a01b0316816001600160a01b03161415611ef1576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6001600160a01b038116331480611f1257506000546001600160a01b031633145b611f51576040805162461bcd60e51b81526020600482015260176024820152600080516020613f09833981519152604482015290519081900360640190fd5b611f5a84612f98565b50600084815260066020526040808220600781018054610100600160a81b0319166101006001600160a01b0389811691820292909217909255600290920154925190938893909216917f62160e4abadfc3a6afc583d10586d737c813753fe64d93f4283282b2b600a34491a450505050565b866000611fd882611031565b50505050505091505060006001600160a01b0316816001600160a01b0316141561203a576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6001600160a01b03811633148061205b57506000546001600160a01b031633145b61209a576040805162461bcd60e51b81526020600482015260176024820152600080516020613f09833981519152604482015290519081900360640190fd5b600086116120ef576040805162461bcd60e51b815260206004820152601e60248201527f6572726f725f6672656550726f64756374734e6f74537570706f727465640000604482015290519081900360640190fd5b6120f889612f98565b5060008981526006602090815260409091208951909161211f9160018401918c0190613e06565b506003810180546001600160a01b0319166001600160a01b038a161790556004810187905560058101805487919060ff19166001838181111561215e57fe5b02179055506006810185905580546002820154604080516001600160a01b038c811660208301529181018b90529116907f21953ef62f6c172d864b9ae2181d3c7114ef506c3546057e354cf6b5bab03ec4908c908c908c908c908c9080606081018460018111156121cb57fe5b60ff168152602001838152602001828103825287818151815260200191508051906020019080838360005b8381101561220e5781810151838201526020016121f6565b50505050905090810190601f16801561223b5780820380516001836020036101000a031916815260200191505b50965050505050505060405180910390a3831561225b5761225b8a61152a565b50505050505050505050565b6000546001600160a01b031633146122b2576040805162461bcd60e51b815260206004820152600960248201526837b7363ca7bbb732b960b91b604482015290519081900360640190fd5b610af58383836138fe565b60006122c98383611828565b509392505050565b60085460ff1681565b6000808260018111156122e957fe5b1415612306576122ff838563ffffffff61393b16565b9050612346565b612343670de0b6b3a76400006123378661232b6007548861393b90919063ffffffff16565b9063ffffffff61393b16565b9063ffffffff61399416565b90505b9392505050565b60085460ff16158061236957506000546001600160a01b031633145b6123a9576040805162461bcd60e51b815260206004820152600c60248201526b195c9c9bdc97da185b1d195960a21b604482015290519081900360640190fd5b6123b986868686868660006135a2565b505050505050565b60055481565b60075481565b6003546001600160a01b03163314612421576040805162461bcd60e51b8152602060048201526012602482015271195c9c9bdc97db9bdd14195c9b5a5d1d195960721b604482015290519081900360640190fd5b6000811161246a576040805162461bcd60e51b81526020600482015260116024820152706572726f725f696e76616c69645261746560781b604482015290519081900360640190fd5b6007819055604080518381526020810183905281517fc84d758f9836fe65b8f2be13d5e364b9373411e1158b63c1c5abbbae78949609929181900390910190a15050565b8160006124ba82611031565b50505050505091505060006001600160a01b0316816001600160a01b0316141561251c576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6001600160a01b03811633148061253d57506000546001600160a01b031633145b61257c576040805162461bcd60e51b81526020600482015260176024820152600080516020613f09833981519152604482015290519081900360640190fd5b61258584612f98565b50600084815260066020526040902080546125d8576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b60078101805485158015600160a81b0260ff60a81b199092169190911790915561262c5760405185907f507847149b655f0d87f5cadd67619cd1c0a53b2cbb153d2f08f83614b4c29b7890600090a2610e51565b60405185907fd8eb01debfba6841d33231e9b6df615367d622af29059b91eeb39b62f81f79ca90600090a25050505050565b61266781612f98565b50600081815260066020526040902080546126ba576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b6007810154600160a81b900460ff16612716576040805162461bcd60e51b8152602060048201526019602482015278195c9c9bdc97ddda1a5d195b1a5cdd139bdd115b98589b1959603a1b604482015290519081900360640190fd5b33600090815260098201602052604081205460ff16600381111561273657fe5b146127725760405162461bcd60e51b8152600401808060200182810382526026815260200180613f4a6026913960400191505060405180910390fd5b336000818152600983016020526040808220805460ff191660011790555184917fd07377dfece33da04bb307fc530a0eb06929f31a09309c84ae38079aad7b16a891a35050565b6001546001600160a01b031681565b6000546001600160a01b03163314612813576040805162461bcd60e51b815260206004820152600960248201526837b7363ca7bbb732b960b91b604482015290519081900360640190fd5b670de0b6b3a7640000811115612865576040805162461bcd60e51b81526020600482015260126024820152716572726f725f696e76616c6964547846656560701b604482015290519081900360640190fd5b600581905560405181907f3115e922830fe4bd99b46316ef2a8939b665b45d008bc585fb784f754abf038b90600090a250565b6000546001600160a01b031633146128e3576040805162461bcd60e51b815260206004820152600960248201526837b7363ca7bbb732b960b91b604482015290519081900360640190fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b61290f84836139d6565b5060008061291d8685613523565b90925090506001600783015460ff16600181111561293757fe5b1461297d576040805162461bcd60e51b8152602060048201526011602482015270195c9c9bdc97db9bdd11195c1b1bde5959607a1b604482015290519081900360640190fd5b6007820154600160a81b900460ff1615806129c0575060026001600160a01b038516600090815260098401602052604090205460ff1660038111156129be57fe5b145b612a11576040805162461bcd60e51b815260206004820152601960248201527f6572726f725f77686974656c6973744e6f74416c6c6f77656400000000000000604482015290519081900360640190fd5b60004282600001541115612ac75760008611612a6a576040805162461bcd60e51b8152602060048201526013602482015272195c9c9bdc97dd1bdc155c151bdbd4db585b1b606a1b604482015290519081900360640190fd5b8154612a7c908763ffffffff613c6e16565b80835583546040805183815290519293506001600160a01b038816927f602ca7f17c81aa5e62b3381000dd445f5af7c333574da85f4b246288afc073229181900360200190a3612b9e565b8260060154861015612b20576040805162461bcd60e51b815260206004820152601d60248201527f6572726f725f6e6577537562736372697074696f6e546f6f536d616c6c000000604482015290519081900360640190fd5b612b30428763ffffffff613c6e16565b9050612b3a613e84565b5060408051602080820183528382526001600160a01b0388166000818152600888018352849020835190558654845186815294519394919390927f9c3ab7e86c11d820cc311335294ebdf7299d8637d47253b930c4120b775d7cca928290030190a3505b82546040805183815290516001600160a01b03881692917fe22e8c2d8a284063fec10f270bc3c776ffb40bcf816b73eef36354d5f3d7b3d4919081900360200190a3600383015460009081906001600160a01b03168615612e115760048601546005870154612c11918b9160ff166122da565b9250612c34670de0b6b3a76400006123378560055461393b90919063ffffffff16565b6002549092506001600160a01b03166323b872dd3383612c5a878763ffffffff613cc816565b6040518463ffffffff1660e01b815260040180846001600160a01b03166001600160a01b03168152602001836001600160a01b03166001600160a01b031681526020018281526020019350505050602060405180830381600087803b158015612cc257600080fd5b505af1158015612cd6573d6000803e3d6000fd5b505050506040513d6020811015612cec57600080fd5b5051612d35576040805162461bcd60e51b8152602060048201526013602482015272195c9c9bdc97dc185e5b595b9d11985a5b1959606a1b604482015290519081900360640190fd5b8115612e115760025460008054604080516323b872dd60e01b81523360048201526001600160a01b03928316602482015260448101879052905191909316926323b872dd9260648083019360209390929083900390910190829087803b158015612d9e57600080fd5b505af1158015612db2573d6000803e3d6000fd5b505050506040513d6020811015612dc857600080fd5b5051612e11576040805162461bcd60e51b8152602060048201526013602482015272195c9c9bdc97dc185e5b595b9d11985a5b1959606a1b604482015290519081900360640190fd5b803b8015612f8b57855460408051602481018e90526001600160a01b038c8116604483015260648201939093526084810187905260a48082018790528251808303909101815260c490910182526020810180516001600160e01b03166301290e7360e61b178152915181516000946060949088169392918291908083835b60208310612eae5780518252601f199092019160209182019101612e8f565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612f10576040519150601f19603f3d011682016040523d82523d6000602084013e612f15565b606091505b50915091508115612f88576000818060200190516020811015612f3757600080fd5b5051905080612f86576040805162461bcd60e51b815260206004820152601660248201527532b93937b92fb932b532b1ba32b2213ca9b2b63632b960511b604482015290519081900360640190fd5b505b50505b5050505050505050505050565b6000818152600660205260408120805415612fb7576000915050613344565b6060600080600080600080600460009054906101000a90046001600160a01b03166001600160a01b0316633a20e9df8b6040518263ffffffff1660e01b81526004018082815260200191505060006040518083038186803b15801561301b57600080fd5b505afa15801561302f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405260e081101561305857600080fd5b8101908080516040519392919084600160201b82111561307757600080fd5b90830190602082018581111561308c57600080fd5b8251600160201b8111828201881017156130a557600080fd5b82525081516020918201929091019080838360005b838110156130d25781810151838201526020016130ba565b50505050905090810190601f1680156130ff5780820380516001836020036101000a031916815260200191505b5060409081526020820151908201516060830151608084015160a085015160c090950151979e50929c50909a5098509650945091925050506001600160a01b03861661315657600098505050505050505050613344565b898855865161316e9060018a019060208a0190613e06565b506002880180546001600160a01b038089166001600160a01b03199283161790925560038a018054928816929091169190911790556004880184905560058801805484919060ff1916600183818111156131c457fe5b02179055506006880182905560078801805482919060ff1916600183818111156131ea57fe5b021790555087600001548860020160009054906101000a90046001600160a01b03166001600160a01b03167fd608cf60e5a08e9db0f10b63c150bb7cdc66ee6286eb04ec5ba01d178e9010d68a6001018b60030160009054906101000a90046001600160a01b03168c600401548d60050160009054906101000a900460ff168e600601546040518080602001866001600160a01b03166001600160a01b031681526020018581526020018460018111156132a057fe5b60ff16815260208101849052604083820381018352885460026001821615610100026000190190911604908201819052606090910190889080156133255780601f106132fa57610100808354040283529160200191613325565b820191906000526020600020905b81548152906001019060200180831161330857829003601f168201915b5050965050505050505060405180910390a36001985050505050505050505b919050565b6060600080600080600080600061335e613e97565b600660008b81526020019081526020016000206040518061014001604052908160008201548152602001600182018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156134205780601f106133f557610100808354040283529160200191613420565b820191906000526020600020905b81548152906001019060200180831161340357829003601f168201915b505050918352505060028201546001600160a01b039081166020830152600383015416604082015260048201546060820152600582015460809091019060ff16600181111561346b57fe5b600181111561347657fe5b815260068201546020820152600782015460409091019060ff16600181111561349b57fe5b60018111156134a657fe5b8152600791909101546001600160a01b0361010082041660208084019190915260ff600160a81b909204919091161515604092830152820151908201516060830151608084015160a085015160c086015160e087015161012090970151959f50939d50919b50995097509550909350915050919395975091939597565b60008281526006602052604081208054909190613578576040805162461bcd60e51b815260206004820152600e60248201526d195c9c9bdc97db9bdd119bdd5b9960921b604482015290519081900360640190fd5b506001600160a01b03909116600090815260088201602052604090209092909150565b5442111590565b866135ea576040805162461bcd60e51b8152602060048201526013602482015272195c9c9bdc97db9d5b1b141c9bd91d58dd1259606a1b604482015290519081900360640190fd5b6000841161363f576040805162461bcd60e51b815260206004820152601e60248201527f6572726f725f6672656550726f64756374734e6f74537570706f727465640000604482015290519081900360640190fd5b600061364a88611031565b50505050505091505060006001600160a01b0316816001600160a01b0316146136b0576040805162461bcd60e51b81526020600482015260136024820152726572726f725f616c726561647945786973747360681b604482015290519081900360640190fd5b604051806101400160405280898152602001888152602001336001600160a01b03168152602001876001600160a01b031681526020018681526020018560018111156136f857fe5b81526020810185905260400160018152600060208083018290528515156040938401528b82526006815291902082518155828201518051919261374392600185019290910190613e06565b5060408201516002820180546001600160a01b039283166001600160a01b03199182161790915560608401516003840180549190931691161790556080820151600482015560a082015160058201805460ff1916600183818111156137a457fe5b021790555060c0820151600682015560e082015160078201805460ff1916600183818111156137cf57fe5b02179055506101008281015160079092018054610120909401511515600160a81b0260ff60a81b196001600160a01b03948516909302610100600160a81b03199095169490941791909116929092179091556040805191881660208301528101869052889033907f397627c8e8e4324a0f8a98a8274c00e4cee798d000625304ffbae6144ec64e54908a908a908a908a908a90806060810184600181111561387357fe5b60ff168152602001838152602001828103825287818151815260200191508051906020019080838360005b838110156138b657818101518382015260200161389e565b50505050905090810190601f1680156138e35780820380516001836020036101000a031916815260200191505b50965050505050505060405180910390a35050505050505050565b600380546001600160a01b03199081166001600160a01b039485161790915560028054821694841694909417909355600480549093169116179055565b60008261394a57506000611524565b8282028284828161395757fe5b04146123465760405162461bcd60e51b8152600401808060200182810382526021815260200180613f296021913960400191505060405180910390fd5b600061234683836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250613d0a565b6000806139e284612f98565b90506000806139f18686613523565b8054919350915015613a095760009350505050611524565b82613b68576004805460408051633a20e9df60e01b8152928301899052516000926001600160a01b0390921691633a20e9df9160248083019286929190829003018186803b158015613a5a57600080fd5b505afa158015613a6e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405260e0811015613a9757600080fd5b8101908080516040519392919084600160201b821115613ab657600080fd5b908301906020820185811115613acb57600080fd5b8251600160201b811182820188101715613ae457600080fd5b82525081516020918201929091019080838360005b83811015613b11578181015183820152602001613af9565b50505050905090810190601f168015613b3e5780820380516001836020036101000a031916815260200191505b506040526020015193505050506001600160a01b038116613b66576000945050505050611524565b505b60048054604080516317ca32dd60e21b81529283018990526001600160a01b03888116602485015281516000949190931692635f28cb7492604480840193919291829003018186803b158015613bbd57600080fd5b505afa158015613bd1573d6000803e3d6000fd5b505050506040513d6040811015613be757600080fd5b5060200151905080613c00576000945050505050611524565b60408051602080820183528382526001600160a01b038916600081815260088801835284902092519092558251848152925191928a927f9a2546e503275a77e7c86606d6512431c9046ffc6d3e53678e2693b201275714929181900390910190a35060019695505050505050565b600082820183811015612346576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b600061234683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250613dac565b60008183613d965760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613d5b578181015183820152602001613d43565b50505050905090810190601f168015613d885780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838581613da257fe5b0495945050505050565b60008184841115613dfe5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315613d5b578181015183820152602001613d43565b505050900390565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10613e4757805160ff1916838001178555613e74565b82800160010185558215613e74579182015b82811115613e74578251825591602001919060010190613e59565b50613e80929150613eeb565b5090565b6040518060200160405280600081525090565b604080516101408101825260008082526060602083018190529282018190529181018290526080810182905260a0810182905260c081018290529060e0820190815260006020820181905260409091015290565b613f0591905b80821115613e805760008155600101613ef1565b9056fe6572726f725f70726f647563744f776e6572734f6e6c79000000000000000000536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f776572726f725f77686974656c69737452657175657374416c72656164795375626d6974746564a2646970667358221220ffe1804a061281ba95a677dba273c26c08f0ff1411ce40c5f622911807e3ad5764736f6c63430006060033

Verified Source Code Partial Match

Compiler: v0.6.6+commit.6c089d02 EVM: istanbul Optimization: Yes (200 runs)
Marketplace.sol 1156 lines
// File: openzeppelin-solidity/contracts/GSN/Context.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

// File: openzeppelin-solidity/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

// File: openzeppelin-solidity/contracts/math/SafeMath.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return sub(a, b, "SafeMath: subtraction overflow");
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return mod(a, b, "SafeMath: modulo by zero");
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts with custom message when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }
}

// File: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;




/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin guidelines: functions revert instead
 * of returning `false` on failure. This behavior is nonetheless conventional
 * and does not conflict with the expectations of ERC20 applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20 {
    using SafeMath for uint256;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name_, string memory symbol_) public {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
     * called.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view returns (uint8) {
        return _decimals;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    /**
     * @dev Moves tokens `amount` from `sender` to `recipient`.
     *
     * This is internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal {
        _decimals = decimals_;
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be to transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}

// File: contracts/PurchaseListener.sol

pragma solidity ^0.6.6;

interface PurchaseListener {
    // TODO: find out about how to best detect who implements an interface
    //   see at least https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
    // function isPurchaseListener() external returns (bool);

    /**
     * Similarly to ETH transfer, returning false will decline the transaction
     *   (declining should probably cause revert, but that's up to the caller)
     * IMPORTANT: include onlyMarketplace modifier to your implementations!
     */
    function onPurchase(bytes32 productId, address subscriber, uint endTimestamp, uint priceDatacoin, uint feeDatacoin)
        external returns (bool accepted);
}

// File: contracts/Ownable.sol

pragma solidity ^0.6.6;

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
 */
contract Ownable {
    address public owner;
    address public pendingOwner;

    event OwnershipTransferred(
        address indexed previousOwner,
        address indexed newOwner
    );

    /**
     * @dev The Ownable constructor sets the original `owner` of the contract to the sender
     * account.
     */
    constructor() public {
        owner = msg.sender;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(msg.sender == owner, "onlyOwner");
        _;
    }

    /**
     * @dev Allows the current owner to set the pendingOwner address.
     * @param newOwner The address to transfer ownership to.
     */
    function transferOwnership(address newOwner) public onlyOwner {
        pendingOwner = newOwner;
    }

    /**
     * @dev Allows the pendingOwner address to finalize the transfer.
     */
    function claimOwnership() public {
        require(msg.sender == pendingOwner, "onlyPendingOwner");
        emit OwnershipTransferred(owner, pendingOwner);
        owner = pendingOwner;
        pendingOwner = address(0);
    }
}

// File: contracts/Marketplace.sol

// solhint-disable not-rely-on-time
pragma solidity ^0.6.6;






interface IMarketplace {
    enum ProductState {
        NotDeployed,                // non-existent or deleted
        Deployed                    // created or redeployed
    }

    enum Currency {
        DATA,                       // "token wei" (10^-18 DATA)
        USD                         // attodollars (10^-18 USD)
    }

    enum WhitelistState{
        None,
        Pending,
        Approved,
        Rejected
    }
    function getSubscription(bytes32 productId, address subscriber) external view returns (bool isValid, uint endTimestamp);
    function getPriceInData(uint subscriptionSeconds, uint price, Currency unit) external view returns (uint datacoinAmount);
}
interface IMarketplace1 is IMarketplace{
    function getProduct(bytes32 id) external view returns (string memory name, address owner, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds, ProductState state);
}
interface IMarketplace2 is IMarketplace{
    function getProduct(bytes32 id) external view returns (string memory name, address owner, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds, ProductState state, bool requiresWhitelist);
    function buyFor(bytes32 productId, uint subscriptionSeconds, address recipient) external;
}
/**
 * @title Streamr Marketplace
 * @dev note about numbers:
 *   All prices and exchange rates are in "decimal fixed-point", that is, scaled by 10^18, like ETH vs wei.
 *  Seconds are integers as usual.
 *
 * Next version TODO:
 *  - EIP-165 inferface definition; PurchaseListener
 */
contract Marketplace is Ownable, IMarketplace2 {
    using SafeMath for uint256;

    // product events
    event ProductCreated(address indexed owner, bytes32 indexed id, string name, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds);
    event ProductUpdated(address indexed owner, bytes32 indexed id, string name, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds);
    event ProductDeleted(address indexed owner, bytes32 indexed id, string name, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds);
    event ProductImported(address indexed owner, bytes32 indexed id, string name, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds);
    event ProductRedeployed(address indexed owner, bytes32 indexed id, string name, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds);
    event ProductOwnershipOffered(address indexed owner, bytes32 indexed id, address indexed to);
    event ProductOwnershipChanged(address indexed newOwner, bytes32 indexed id, address indexed oldOwner);

    // subscription events
    event Subscribed(bytes32 indexed productId, address indexed subscriber, uint endTimestamp);
    event NewSubscription(bytes32 indexed productId, address indexed subscriber, uint endTimestamp);
    event SubscriptionExtended(bytes32 indexed productId, address indexed subscriber, uint endTimestamp);
    event SubscriptionImported(bytes32 indexed productId, address indexed subscriber, uint endTimestamp);
    event SubscriptionTransferred(bytes32 indexed productId, address indexed from, address indexed to, uint secondsTransferred);

    // currency events
    event ExchangeRatesUpdated(uint timestamp, uint dataInUsd);

    // whitelist events
    event WhitelistRequested(bytes32 indexed productId, address indexed subscriber);
    event WhitelistApproved(bytes32 indexed productId, address indexed subscriber);
    event WhitelistRejected(bytes32 indexed productId, address indexed subscriber);
    event WhitelistEnabled(bytes32 indexed productId);
    event WhitelistDisabled(bytes32 indexed productId);

    //txFee events
    event TxFeeChanged(uint256 indexed newTxFee);


    struct Product {
        bytes32 id;
        string name;
        address owner;
        address beneficiary;        // account where revenue is directed to
        uint pricePerSecond;
        Currency priceCurrency;
        uint minimumSubscriptionSeconds;
        ProductState state;
        address newOwnerCandidate;  // Two phase hand-over to minimize the chance that the product ownership is lost to a non-existent address.
        bool requiresWhitelist;
        mapping(address => TimeBasedSubscription) subscriptions;
        mapping(address => WhitelistState) whitelist;
    }

    struct TimeBasedSubscription {
        uint endTimestamp;
    }

    /////////////// Marketplace lifecycle /////////////////

    ERC20 public datacoin;

    address public currencyUpdateAgent;
    IMarketplace1 prev_marketplace;
    uint256 public txFee;

    constructor(address datacoinAddress, address currencyUpdateAgentAddress, address prev_marketplace_address) Ownable() public {
        _initialize(datacoinAddress, currencyUpdateAgentAddress, prev_marketplace_address);
    }

    function _initialize(address datacoinAddress, address currencyUpdateAgentAddress, address prev_marketplace_address) internal {
        currencyUpdateAgent = currencyUpdateAgentAddress;
        datacoin = ERC20(datacoinAddress);
        prev_marketplace = IMarketplace1(prev_marketplace_address);
    }

    ////////////////// Product management /////////////////

    mapping (bytes32 => Product) public products;
    /*
        checks this marketplace first, then the previous
    */
    function getProduct(bytes32 id) public override view returns (string memory name, address owner, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds, ProductState state, bool requiresWhitelist) {
        (name, owner, beneficiary, pricePerSecond, currency, minimumSubscriptionSeconds, state, requiresWhitelist) = _getProductLocal(id);
        if (owner != address(0))
            return (name, owner, beneficiary, pricePerSecond, currency, minimumSubscriptionSeconds, state, requiresWhitelist);
        (name, owner, beneficiary, pricePerSecond, currency, minimumSubscriptionSeconds, state) = prev_marketplace.getProduct(id);
        return (name, owner, beneficiary, pricePerSecond, currency, minimumSubscriptionSeconds, state, false);
    }

    /**
    checks only this marketplace, not the previous marketplace
     */

    function _getProductLocal(bytes32 id) internal view returns (string memory name, address owner, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds, ProductState state, bool requiresWhitelist) {
        Product memory p = products[id];
        return (
            p.name,
            p.owner,
            p.beneficiary,
            p.pricePerSecond,
            p.priceCurrency,
            p.minimumSubscriptionSeconds,
            p.state,
            p.requiresWhitelist
        );
    }

    // also checks that p exists: p.owner == 0 for non-existent products
    modifier onlyProductOwner(bytes32 productId) {
        (,address _owner,,,,,,) = getProduct(productId);
        require(_owner != address(0), "error_notFound");
        require(_owner == msg.sender || owner == msg.sender, "error_productOwnersOnly");
        _;
    }

    /**
     * Imports product details (but NOT subscription details) from previous marketplace
     */
    function _importProductIfNeeded(bytes32 productId) internal returns (bool imported){
        Product storage p = products[productId];
        if (p.id != 0x0) { return false; }
        (string memory _name, address _owner, address _beneficiary, uint _pricePerSecond, IMarketplace1.Currency _priceCurrency, uint _minimumSubscriptionSeconds, IMarketplace1.ProductState _state) = prev_marketplace.getProduct(productId);
        if (_owner == address(0)) { return false; }
        p.id = productId;
        p.name = _name;
        p.owner = _owner;
        p.beneficiary = _beneficiary;
        p.pricePerSecond = _pricePerSecond;
        p.priceCurrency = _priceCurrency;
        p.minimumSubscriptionSeconds = _minimumSubscriptionSeconds;
        p.state = _state;
        emit ProductImported(p.owner, p.id, p.name, p.beneficiary, p.pricePerSecond, p.priceCurrency, p.minimumSubscriptionSeconds);
        return true;
    }

    function _importSubscriptionIfNeeded(bytes32 productId, address subscriber) internal returns (bool imported) {
        bool _productImported = _importProductIfNeeded(productId);

        // check that subscription didn't already exist in current marketplace
        (Product storage product, TimeBasedSubscription storage sub) = _getSubscriptionLocal(productId, subscriber);
        if (sub.endTimestamp != 0x0) { return false; }

        // check that subscription exists in the previous marketplace(s)
        // only call prev_marketplace.getSubscription() if product exists there
        // consider e.g. product created in current marketplace but subscription still doesn't exist
        // if _productImported, it must have existed in previous marketplace so no need to perform check
        if (!_productImported) {
            (,address _owner_prev,,,,,) = prev_marketplace.getProduct(productId);
            if (_owner_prev == address(0)) { return false; }
        }
        (, uint _endTimestamp) = prev_marketplace.getSubscription(productId, subscriber);
        if (_endTimestamp == 0x0) { return false; }
        product.subscriptions[subscriber] = TimeBasedSubscription(_endTimestamp);
        emit SubscriptionImported(productId, subscriber, _endTimestamp);
        return true;
    }
    function createProduct(bytes32 id, string memory name, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds) public whenNotHalted {
        _createProduct(id, name, beneficiary, pricePerSecond, currency, minimumSubscriptionSeconds, false);
    }

    function createProductWithWhitelist(bytes32 id, string memory name, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds) public whenNotHalted {
        _createProduct(id, name, beneficiary, pricePerSecond, currency, minimumSubscriptionSeconds, true);
        emit WhitelistEnabled(id);
    }


    function _createProduct(bytes32 id, string memory name, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds, bool requiresWhitelist) internal {
        require(id != 0x0, "error_nullProductId");
        require(pricePerSecond > 0, "error_freeProductsNotSupported");
        (,address _owner,,,,,,) = getProduct(id);
        require(_owner == address(0), "error_alreadyExists");
        products[id] = Product({id: id, name: name, owner: msg.sender, beneficiary: beneficiary, pricePerSecond: pricePerSecond,
            priceCurrency: currency, minimumSubscriptionSeconds: minimumSubscriptionSeconds, state: ProductState.Deployed, newOwnerCandidate: address(0), requiresWhitelist: requiresWhitelist});
        emit ProductCreated(msg.sender, id, name, beneficiary, pricePerSecond, currency, minimumSubscriptionSeconds);
    }

    /**
    * Stop offering the product
    */
    function deleteProduct(bytes32 productId) public onlyProductOwner(productId) {
        _importProductIfNeeded(productId);
        Product storage p = products[productId];
        require(p.state == ProductState.Deployed, "error_notDeployed");
        p.state = ProductState.NotDeployed;
        emit ProductDeleted(p.owner, productId, p.name, p.beneficiary, p.pricePerSecond, p.priceCurrency, p.minimumSubscriptionSeconds);
    }

    /**
    * Return product to market
    */
    function redeployProduct(bytes32 productId) public onlyProductOwner(productId) {
        _importProductIfNeeded(productId);
        Product storage p = products[productId];
        require(p.state == ProductState.NotDeployed, "error_mustBeNotDeployed");
        p.state = ProductState.Deployed;
        emit ProductRedeployed(p.owner, productId, p.name, p.beneficiary, p.pricePerSecond, p.priceCurrency, p.minimumSubscriptionSeconds);
    }

    function updateProduct(bytes32 productId, string memory name, address beneficiary, uint pricePerSecond, Currency currency, uint minimumSubscriptionSeconds, bool redeploy) public onlyProductOwner(productId) {
        require(pricePerSecond > 0, "error_freeProductsNotSupported");
        _importProductIfNeeded(productId);
        Product storage p = products[productId];
        p.name = name;
        p.beneficiary = beneficiary;
        p.pricePerSecond = pricePerSecond;
        p.priceCurrency = currency;
        p.minimumSubscriptionSeconds = minimumSubscriptionSeconds;
        emit ProductUpdated(p.owner, p.id, name, beneficiary, pricePerSecond, currency, minimumSubscriptionSeconds);
        if (redeploy) {
            redeployProduct(productId);
        }
    }

    /**
    * Changes ownership of the product. Two phase hand-over minimizes the chance that the product ownership is lost to a non-existent address.
    */
    function offerProductOwnership(bytes32 productId, address newOwnerCandidate) public onlyProductOwner(productId) {
        _importProductIfNeeded(productId);
        // that productId exists is already checked in onlyProductOwner
        products[productId].newOwnerCandidate = newOwnerCandidate;
        emit ProductOwnershipOffered(products[productId].owner, productId, newOwnerCandidate);
    }

    /**
    * Changes ownership of the product. Two phase hand-over minimizes the chance that the product ownership is lost to a non-existent address.
    */
    function claimProductOwnership(bytes32 productId) public whenNotHalted {
        _importProductIfNeeded(productId);
        // also checks that productId exists (newOwnerCandidate is zero for non-existent)
        Product storage p = products[productId];
        require(msg.sender == p.newOwnerCandidate, "error_notPermitted");
        emit ProductOwnershipChanged(msg.sender, productId, p.owner);
        p.owner = msg.sender;
        p.newOwnerCandidate = address(0);
    }

    /////////////// Whitelist management ///////////////

    function setRequiresWhitelist(bytes32 productId, bool _requiresWhitelist) public onlyProductOwner(productId) {
        _importProductIfNeeded(productId);
        Product storage p = products[productId];
        require(p.id != 0x0, "error_notFound");
        p.requiresWhitelist = _requiresWhitelist;
        if (_requiresWhitelist) {
            emit WhitelistEnabled(productId);
        } else {
            emit WhitelistDisabled(productId);
        }
    }

    function whitelistApprove(bytes32 productId, address subscriber) public onlyProductOwner(productId) {
        _importProductIfNeeded(productId);
        Product storage p = products[productId];
        require(p.id != 0x0, "error_notFound");
        require(p.requiresWhitelist, "error_whitelistNotEnabled");
        p.whitelist[subscriber] = WhitelistState.Approved;
        emit WhitelistApproved(productId, subscriber);
    }

    function whitelistReject(bytes32 productId, address subscriber) public onlyProductOwner(productId) {
        _importProductIfNeeded(productId);
        Product storage p = products[productId];
        require(p.id != 0x0, "error_notFound");
        require(p.requiresWhitelist, "error_whitelistNotEnabled");
        p.whitelist[subscriber] = WhitelistState.Rejected;
        emit WhitelistRejected(productId, subscriber);
    }

    function whitelistRequest(bytes32 productId) public {
        _importProductIfNeeded(productId);
        Product storage p = products[productId];
        require(p.id != 0x0, "error_notFound");
        require(p.requiresWhitelist, "error_whitelistNotEnabled");
        require(p.whitelist[msg.sender] == WhitelistState.None, "error_whitelistRequestAlreadySubmitted");
        p.whitelist[msg.sender] = WhitelistState.Pending;
        emit WhitelistRequested(productId, msg.sender);
    }

    function getWhitelistState(bytes32 productId, address subscriber) public view returns (WhitelistState wlstate) {
        (, address _owner,,,,,,) = getProduct(productId);
        require(_owner != address(0), "error_notFound");
        // if product is not local (maybe in old marketplace) this will return 0 (WhitelistState.None)
        Product storage p = products[productId];
        return p.whitelist[subscriber];
    }

    /////////////// Subscription management ///////////////

    function getSubscription(bytes32 productId, address subscriber) public override view returns (bool isValid, uint endTimestamp) {
        (,address _owner,,,,,,) = _getProductLocal(productId);
        if (_owner == address(0)) {
            return prev_marketplace.getSubscription(productId,subscriber);
        }

        (, TimeBasedSubscription storage sub) = _getSubscriptionLocal(productId, subscriber);
        if (sub.endTimestamp == 0x0) {
            // only call prev_marketplace.getSubscription() if product exists in previous marketplace too
            (,address _owner_prev,,,,,) = prev_marketplace.getProduct(productId);
            if (_owner_prev != address(0)) {
                return prev_marketplace.getSubscription(productId,subscriber);
            }
        }
        return (_isValid(sub), sub.endTimestamp);
    }

    function getSubscriptionTo(bytes32 productId) public view returns (bool isValid, uint endTimestamp) {
        return getSubscription(productId, msg.sender);
    }

    /**
     * Checks if the given address currently has a valid subscription
     * @param productId to check
     * @param subscriber to check
     */
    function hasValidSubscription(bytes32 productId, address subscriber) public view returns (bool isValid) {
        (isValid,) = getSubscription(productId, subscriber);
    }

    /**
     * Enforces payment rules, triggers PurchaseListener event
     */
    function _subscribe(bytes32 productId, uint addSeconds, address subscriber, bool requirePayment) internal {
        _importSubscriptionIfNeeded(productId, subscriber);
        (Product storage p, TimeBasedSubscription storage oldSub) = _getSubscriptionLocal(productId, subscriber);
        require(p.state == ProductState.Deployed, "error_notDeployed");
        require(!p.requiresWhitelist || p.whitelist[subscriber] == WhitelistState.Approved, "error_whitelistNotAllowed");
        uint endTimestamp;

        if (oldSub.endTimestamp > block.timestamp) {
            require(addSeconds > 0, "error_topUpTooSmall");
            endTimestamp = oldSub.endTimestamp.add(addSeconds);
            oldSub.endTimestamp = endTimestamp;
            emit SubscriptionExtended(p.id, subscriber, endTimestamp);
        } else {
            require(addSeconds >= p.minimumSubscriptionSeconds, "error_newSubscriptionTooSmall");
            endTimestamp = block.timestamp.add(addSeconds);
            TimeBasedSubscription memory newSub = TimeBasedSubscription(endTimestamp);
            p.subscriptions[subscriber] = newSub;
            emit NewSubscription(p.id, subscriber, endTimestamp);
        }
        emit Subscribed(p.id, subscriber, endTimestamp);

        uint256 price = 0;
        uint256 fee = 0;
        address recipient = p.beneficiary;
        if (requirePayment) {
            price = getPriceInData(addSeconds, p.pricePerSecond, p.priceCurrency);
            fee = txFee.mul(price).div(1 ether);
            require(datacoin.transferFrom(msg.sender, recipient, price.sub(fee)), "error_paymentFailed");
            if (fee > 0) {
                require(datacoin.transferFrom(msg.sender, owner, fee), "error_paymentFailed");
            }
        }

        uint256 codeSize;
        assembly { codeSize := extcodesize(recipient) }  // solhint-disable-line no-inline-assembly
        if (codeSize > 0) {
            // solhint-disable-next-line avoid-low-level-calls
            (bool success, bytes memory returnData) = recipient.call(
                abi.encodeWithSignature("onPurchase(bytes32,address,uint256,uint256,uint256)",
                productId, subscriber, oldSub.endTimestamp, price, fee)
            );

            if (success) {
                (bool accepted) = abi.decode(returnData, (bool));
                require(accepted, "error_rejectedBySeller");
            }
        }
    }

    function grantSubscription(bytes32 productId, uint subscriptionSeconds, address recipient) public whenNotHalted onlyProductOwner(productId){
        return _subscribe(productId, subscriptionSeconds, recipient, false);
    }


    function buyFor(bytes32 productId, uint subscriptionSeconds, address recipient) public override whenNotHalted {
        return _subscribe(productId, subscriptionSeconds, recipient, true);
    }


    /**
     * Purchases access to this stream for msg.sender.
     * If the address already has a valid subscription, extends the subscription by the given period.
     * @dev since v4.0: Notify the seller if the seller implements PurchaseListener interface
     */
    function buy(bytes32 productId, uint subscriptionSeconds) public whenNotHalted {
        buyFor(productId,subscriptionSeconds, msg.sender);
    }


    /** Gets subscriptions info from the subscriptions stored in this contract */
    function _getSubscriptionLocal(bytes32 productId, address subscriber) internal view returns (Product storage p, TimeBasedSubscription storage s) {
        p = products[productId];
        require(p.id != 0x0, "error_notFound");
        s = p.subscriptions[subscriber];
    }

    function _isValid(TimeBasedSubscription storage s) internal view returns (bool) {
        return s.endTimestamp >= block.timestamp;  // solhint-disable-line not-rely-on-time
    }

    // TODO: transfer allowance to another Marketplace contract
    // Mechanism basically is that this Marketplace draws from the allowance and credits
    //   the account on another Marketplace; OR that there is a central credit pool (say, an ERC20 token)
    // Creating another ERC20 token for this could be a simple fix: it would need the ability to transfer allowances

    /////////////// Currency management ///////////////

    // Exchange rates are formatted as "decimal fixed-point", that is, scaled by 10^18, like ether.
    //        Exponent: 10^18 15 12  9  6  3  0
    //                      |  |  |  |  |  |  |
    uint public dataPerUsd = 100000000000000000;   // ~= 0.1 DATA/USD

    /**
    * Update currency exchange rates; all purchases are still billed in DATAcoin
    * @param timestamp in seconds when the exchange rates were last updated
    * @param dataUsd how many data atoms (10^-18 DATA) equal one USD dollar
    */
    function updateExchangeRates(uint timestamp, uint dataUsd) public {
        require(msg.sender == currencyUpdateAgent, "error_notPermitted");
        require(dataUsd > 0, "error_invalidRate");
        dataPerUsd = dataUsd;
        emit ExchangeRatesUpdated(timestamp, dataUsd);
    }

    /**
    * Helper function to calculate (hypothetical) subscription cost for given seconds and price, using current exchange rates.
    * @param subscriptionSeconds length of hypothetical subscription, as a non-scaled integer
    * @param price nominal price scaled by 10^18 ("token wei" or "attodollars")
    * @param unit unit of the number price
    */
    function getPriceInData(uint subscriptionSeconds, uint price, Currency unit) public override view returns (uint datacoinAmount) {
        if (unit == Currency.DATA) {
            return price.mul(subscriptionSeconds);
        }
        return price.mul(dataPerUsd).mul(subscriptionSeconds).div(10**18);
    }

    /////////////// Admin functionality ///////////////

    event Halted();
    event Resumed();
    bool public halted = false;

    modifier whenNotHalted() {
        require(!halted || owner == msg.sender, "error_halted");
        _;
    }
    function halt() public onlyOwner {
        halted = true;
        emit Halted();
    }
    function resume() public onlyOwner {
        halted = false;
        emit Resumed();
    }

    function reInitialize(address datacoinAddress, address currencyUpdateAgentAddress, address prev_marketplace_address) public onlyOwner {
        _initialize(datacoinAddress, currencyUpdateAgentAddress, prev_marketplace_address);
    }

    function setTxFee(uint256 newTxFee) public onlyOwner {
        require(newTxFee <= 1 ether, "error_invalidTxFee");
        txFee = newTxFee;
        emit TxFeeChanged(txFee);
    }
}

Read Contract

currencyUpdateAgent 0x89aaad29 → address
dataPerUsd 0xd50a04f4 → uint256
datacoin 0x79c88f20 → address
getPriceInData 0xbee7d433 → uint256
getProduct 0x3a20e9df → string, address, address, uint256, uint8, uint256, uint8, bool
getSubscription 0x5f28cb74 → bool, uint256
getSubscriptionTo 0x53f81ef8 → bool, uint256
getWhitelistState 0x57fa3db7 → uint8
halted 0xb9b8af0b → bool
hasValidSubscription 0xb14f8432 → bool
owner 0x8da5cb5b → address
pendingOwner 0xe30c3978 → address
products 0x79054391 → bytes32, string, address, address, uint256, uint8, uint256, uint8, address, bool
txFee 0xcf820461 → uint256

Write Contract 21 functions

These functions modify contract state and require a wallet transaction to execute.

buy 0x0ddeb632
bytes32 productId
uint256 subscriptionSeconds
buyFor 0x03987512
bytes32 productId
uint256 subscriptionSeconds
address recipient
claimOwnership 0x4e71e0c8
No parameters
claimProductOwnership 0x1a464fa1
bytes32 productId
createProduct 0xcafbc49d
bytes32 id
string name
address beneficiary
uint256 pricePerSecond
uint8 currency
uint256 minimumSubscriptionSeconds
createProductWithWhitelist 0x683ec0a7
bytes32 id
string name
address beneficiary
uint256 pricePerSecond
uint8 currency
uint256 minimumSubscriptionSeconds
deleteProduct 0x94727b41
bytes32 productId
grantSubscription 0x1f4e09af
bytes32 productId
uint256 subscriptionSeconds
address recipient
halt 0x5ed7ca5b
No parameters
offerProductOwnership 0x96002aef
bytes32 productId
address newOwnerCandidate
reInitialize 0xa4b138b0
address datacoinAddress
address currencyUpdateAgentAddress
address prev_marketplace_address
redeployProduct 0x58f816bf
bytes32 productId
resume 0x046f7da2
No parameters
setRequiresWhitelist 0xde227324
bytes32 productId
bool _requiresWhitelist
setTxFee 0xf05d16f7
uint256 newTxFee
transferOwnership 0xf2fde38b
address newOwner
updateExchangeRates 0xdb6c709c
uint256 timestamp
uint256 dataUsd
updateProduct 0x9ac47353
bytes32 productId
string name
address beneficiary
uint256 pricePerSecond
uint8 currency
uint256 minimumSubscriptionSeconds
bool redeploy
whitelistApprove 0x25cc3a20
bytes32 productId
address subscriber
whitelistReject 0x4d8a9499
bytes32 productId
address subscriber
whitelistRequest 0xe0d5b9e1
bytes32 productId

Recent Transactions

No transactions found for this address