Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0x1FD4Cc54564F880d267D8cB75f60b04f4777843B
Balance 0 ETH
Nonce 1
Code Size 10235 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

10235 bytes
0x608060405234801561001057600080fd5b506004361061012c5760003560e01c80639137c1a7116100ad578063d6c3187111610071578063d6c3187114610353578063dbe934511461035b578063e09d1f6a14610381578063f2fde38b146103d5578063fb971d01146103fb5761012c565b80639137c1a7146102a357806394ab898c146102c9578063a6f9dae1146102d1578063b17e9ee6146102f7578063bce64ada146103255761012c565b80635699c7b1116100f45780635699c7b11461021b57806368f1b7c714610249578063715018a6146102775780638da5cb5b1461027f5780638f32d59b146102875761012c565b80630448a8e61461013157806306aa2d481461016b5780631382da2c146101ab578063393a4d34146101d157806351cff8d9146101f5575b600080fd5b6101696004803603606081101561014757600080fd5b506001600160a01b038135811691602081013582169160409091013516610403565b005b6101996004803603604081101561018157600080fd5b506001600160a01b03813581169160200135166105c0565b60408051918252519081900360200190f35b610199600480360360208110156101c157600080fd5b50356001600160a01b031661064b565b6101d96106d2565b604080516001600160a01b039092168252519081900360200190f35b6101696004803603602081101561020b57600080fd5b50356001600160a01b0316610737565b6101996004803603604081101561023157600080fd5b506001600160a01b0381358116916020013516610aa9565b6101996004803603604081101561025f57600080fd5b506001600160a01b0381358116916020013516610acb565b610169610ae4565b6101d9610b75565b61028f610b84565b604080519115158252519081900360200190f35b610169600480360360208110156102b957600080fd5b50356001600160a01b0316610baa565b6101d9610c13565b610169600480360360208110156102e757600080fd5b50356001600160a01b0316610c22565b6101996004803603604081101561030d57600080fd5b506001600160a01b0381358116916020013516610ccb565b6101996004803603604081101561033b57600080fd5b506001600160a01b0381358116916020013516610ced565b6101d9610d0f565b6101996004803603602081101561037157600080fd5b50356001600160a01b0316610d1e565b6103af6004803603604081101561039757600080fd5b506001600160a01b0381358116916020013516610d3f565b604080519485526020850193909352838301919091526060830152519081900360800190f35b610169600480360360208110156103eb57600080fd5b50356001600160a01b0316610d61565b610169610db4565b61040b610d0f565b6001600160a01b031663aa5dcecc6040518163ffffffff1660e01b815260040160206040518083038186803b15801561044357600080fd5b505afa158015610457573d6000803e3d6000fd5b505050506040513d602081101561046d57600080fd5b50516001600160a01b031633146104c5576040805162461bcd60e51b81526020600482015260176024820152767468697320697320696c6c6567616c206164647265737360481b604482015290519081900360640190fd5b60008060006104d48686610e98565b5092509250925060008060006104ea8988610e98565b509250925092506104fc898987610fe3565b610507898884610fe3565b61051289898661105e565b61051d89888361105e565b60006105298a8a610aa9565b905060006105378b8a610aa9565b90506105538b8b61054e858c63ffffffff61107e16565b6110df565b6105688b8a61054e848963ffffffff61107e16565b604080516001600160a01b03808e168252808d1660208301528b168183015290517f7266de4b1e3ac6803b7f817fca44bef48f3eba3d105c3ebe0bba1f6bc6965f2f9181900360600190a15050505050505050505050565b60006105ca6106d2565b6001600160a01b031663bd02d0f56105e285856110ff565b6040518263ffffffff1660e01b81526004018082815260200191505060206040518083038186803b15801561061657600080fd5b505afa15801561062a573d6000803e3d6000fd5b505050506040513d602081101561064057600080fd5b505190505b92915050565b60006106556106d2565b6001600160a01b031663bd02d0f561066c8461115f565b6040518263ffffffff1660e01b81526004018082815260200191505060206040518083038186803b1580156106a057600080fd5b505afa1580156106b4573d6000803e3d6000fd5b505050506040513d60208110156106ca57600080fd5b505192915050565b6002546000906001600160a01b0316610727576040805162461bcd60e51b81526020600482015260126024820152711cdd1bdc9859d9481a5cc81b9bdd081cd95d60721b604482015290519081900360640190fd5b506002546001600160a01b031690565b61073f610d0f565b6001600160a01b031663ffeed7a96040518163ffffffff1660e01b815260040160206040518083038186803b15801561077757600080fd5b505afa15801561078b573d6000803e3d6000fd5b505050506040513d60208110156107a157600080fd5b50516040805163278330f160e21b81526001600160a01b03848116600483015291519190921691639e0cc3c4916024808301926020929190829003018186803b1580156107ed57600080fd5b505afa158015610801573d6000803e3d6000fd5b505050506040513d602081101561081757600080fd5b5051610864576040805162461bcd60e51b81526020600482015260176024820152767468697320697320696c6c6567616c206164647265737360481b604482015290519081900360640190fd5b600080600061087384336111af565b5092509250925082600014156108c6576040805162461bcd60e51b8152602060048201526013602482015272077697468647261772076616c7565206973203606c1b604482015290519081900360640190fd5b6108d1843384610fe3565b6108dc84338361105e565b6108e8843360006110df565b6108f284336112f5565b600354604080516340c10f1960e01b81523360048201526024810186905290516001600160a01b03909216916340c10f19916044808201926020929091908290030181600087803b15801561094657600080fd5b505af115801561095a573d6000803e3d6000fd5b505050506040513d602081101561097057600080fd5b50516109b5576040805162461bcd60e51b815260206004820152600f60248201526e19195d881b5a5b9d0819985a5b1959608a1b604482015290519081900360640190fd5b60006109bf610d0f565b6001600160a01b03166306490f476040518163ffffffff1660e01b815260040160206040518083038186803b1580156109f757600080fd5b505afa158015610a0b573d6000803e3d6000fd5b505050506040513d6020811015610a2157600080fd5b50516040805163a2e6204560e01b815290519192506001600160a01b0383169163a2e620459160048082019260009290919082900301818387803b158015610a6857600080fd5b505af1158015610a7c573d6000803e3d6000fd5b50505050610aa285610a9d86610a9189610d1e565b9063ffffffff61107e16565b611312565b5050505050565b6000610ab36106d2565b6001600160a01b031663bd02d0f56105e2858561138b565b600080610ad884846111af565b50919695505050505050565b610aec610b84565b610b2b576040805162461bcd60e51b815260206004820181905260248201526000805160206127a7833981519152604482015290519081900360640190fd5b6001546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600180546001600160a01b0319169055565b6001546001600160a01b031690565b6001546000906001600160a01b0316610b9b6113e9565b6001600160a01b031614905090565b610bb2610b84565b610bf1576040805162461bcd60e51b815260206004820181905260248201526000805160206127a7833981519152604482015290519081900360640190fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b6003546001600160a01b031681565b610c2a610b84565b610c69576040805162461bcd60e51b815260206004820181905260248201526000805160206127a7833981519152604482015290519081900360640190fd5b6002546040805163a6f9dae160e01b81526001600160a01b0384811660048301529151919092169163a6f9dae191602480830192600092919082900301818387803b158015610cb757600080fd5b505af1158015610aa2573d6000803e3d6000fd5b6000610cd56106d2565b6001600160a01b031663bd02d0f56105e285856113ed565b6000610cf76106d2565b6001600160a01b031663bd02d0f56105e28585611456565b6000546001600160a01b031690565b6000610d286106d2565b6001600160a01b031663bd02d0f561066c846114b6565b600080600080610d4f86866111af565b93509350935093505b92959194509250565b610d69610b84565b610da8576040805162461bcd60e51b815260206004820181905260248201526000805160206127a7833981519152604482015290519081900360640190fd5b610db181611504565b50565b610dbc610b84565b610dfb576040805162461bcd60e51b815260206004820181905260248201526000805160206127a7833981519152604482015290519081900360640190fd5b6002546001600160a01b031615610e4a576040805162461bcd60e51b815260206004820152600e60248201526d1cdd1bdc9859d9481a5cc81cd95d60921b604482015290519081900360640190fd5b6000604051610e5890611b28565b604051809103906000f080158015610e74573d6000803e3d6000fd5b50600280546001600160a01b0319166001600160a01b039290921691909117905550565b6000806000806000610ea8610d0f565b6001600160a01b03166306490f476040518163ffffffff1660e01b815260040160206040518083038186803b158015610ee057600080fd5b505afa158015610ef4573d6000803e3d6000fd5b505050506040513d6020811015610f0a57600080fd5b50516040805163ef39f11f60e01b81526001600160a01b038a81166004830152825193945060009384939186169263ef39f11f926024808301939192829003018186803b158015610f5a57600080fd5b505afa158015610f6e573d6000803e3d6000fd5b505050506040513d6040811015610f8457600080fd5b50805160209091015190925090506000610f9f8a8a856115a5565b90506000610fae8b8b856116f4565b905060008115610fcd5781831115610fc65781610fc8565b825b610fcf565b825b9c949b509299509097509195505050505050565b610feb6106d2565b6001600160a01b031663e2a4853a6110038585611456565b836040518363ffffffff1660e01b81526004018083815260200182815260200192505050600060405180830381600087803b15801561104157600080fd5b505af1158015611055573d6000803e3d6000fd5b50505050505050565b6110666106d2565b6001600160a01b031663e2a4853a61100385856113ed565b6000828201838110156110d8576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6110e76106d2565b6001600160a01b031663e2a4853a611003858561138b565b60408051735f6c6173745769746864726177616c507269636560601b6020808301919091526001600160601b0319606086811b8216603485015285901b1660488301528251603c818403018152605c909201909252805191012092915050565b604080516f5f63756d756c6174697665507269636560801b60208083019190915260609390931b6001600160601b0319166030820152815180820360240181526044909101909152805191012090565b6000806000806000806000806111c58a8a610e98565b93509350935093506111d5610d0f565b6001600160a01b031663628f043d6040518163ffffffff1660e01b815260040160206040518083038186803b15801561120d57600080fd5b505afa158015611221573d6000803e3d6000fd5b505050506040513d602081101561123757600080fd5b505160408051638b234cb160e01b81526001600160a01b038d8116600483015291519190921691638b234cb1916024808301926020929190829003018186803b15801561128357600080fd5b505afa158015611297573d6000803e3d6000fd5b505050506040513d60208110156112ad57600080fd5b50516112c75750600096509094509250849150610d589050565b60006112d38b8b61181c565b90506000610fcf82610a916112e88f8f610aa9565b899063ffffffff61107e16565b60006113008361064b565b905061130d8383836118fb565b505050565b61131a6106d2565b6001600160a01b031663e2a4853a611331846114b6565b836040518363ffffffff1660e01b81526004018083815260200182815260200192505050600060405180830381600087803b15801561136f57600080fd5b505af1158015611383573d6000803e3d6000fd5b505050505050565b604080517117dc195b991a5b99d5da5d1a191c985dd85b60721b6020808301919091526001600160601b0319606086811b8216603285015285901b1660468301528251603a818403018152605a909201909252805191012092915050565b3390565b604080517f5f6c61737457697468647261776e5265776172644361700000000000000000006020808301919091526001600160601b0319606086811b8216603785015285901b16604b8301528251603f818403018152605f909201909252805191012092915050565b604080517317db185cdd15da5d1a191c985ddb94995dd85c9960621b6020808301919091526001600160601b0319606086811b8216603485015285901b1660488301528251603c818403018152605c909201909252805191012092915050565b604080516d17dc995dd85c991cd05b5bdd5b9d60921b60208083019190915260609390931b6001600160601b031916602e820152815180820360220181526042909101909152805191012090565b6001600160a01b0381166115495760405162461bcd60e51b81526004018080602001828103825260268152602001806127606026913960400191505060405180910390fd5b6001546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b6000806115b28585610ced565b604080516370a0823160e01b81526001600160a01b038781166004830152915192935087926000928416916370a08231916024808301926020929190829003018186803b15801561160257600080fd5b505afa158015611616573d6000803e3d6000fd5b505050506040513d602081101561162c57600080fd5b5051604080516318160ddd60e01b815290519192506000916001600160a01b038516916318160ddd916004808301926020929190829003018186803b15801561167457600080fd5b505afa158015611688573d6000803e3d6000fd5b505050506040513d602081101561169e57600080fd5b5051905060006116cc826116c06116bb8a8963ffffffff61191b16565b61195d565b9063ffffffff61197716565b90506116e76116e280838663ffffffff6119b916565b611a12565b9998505050505050505050565b6000806117018585610ccb565b604080516370a0823160e01b81526001600160a01b038781166004830152915192935087926000928416916370a08231916024808301926020929190829003018186803b15801561175157600080fd5b505afa158015611765573d6000803e3d6000fd5b505050506040513d602081101561177b57600080fd5b5051604080516318160ddd60e01b815290519192506000916001600160a01b038516916318160ddd916004808301926020929190829003018186803b1580156117c357600080fd5b505afa1580156117d7573d6000803e3d6000fd5b505050506040513d60208110156117ed57600080fd5b505190506000611807826116c0898863ffffffff61191b16565b90506116e76116e2828563ffffffff6119b916565b60008061182984846105c0565b905060006118368561064b565b9050600061184a828463ffffffff61191b16565b90506000866001600160a01b03166370a08231876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156118a457600080fd5b505afa1580156118b8573d6000803e3d6000fd5b505050506040513d60208110156118ce57600080fd5b5051905060006118e4838363ffffffff6119b916565b90506118ef81611a12565b98975050505050505050565b6119036106d2565b6001600160a01b031663e2a4853a61100385856110ff565b60006110d883836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611a2c565b600061064582670de0b6b3a764000063ffffffff6119b916565b60006110d883836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611ac3565b6000826119c857506000610645565b828202828482816119d557fe5b04146110d85760405162461bcd60e51b81526004018080602001828103825260218152602001806127866021913960400191505060405180910390fd5b600061064582670de0b6b3a764000063ffffffff61197716565b60008184841115611abb5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611a80578181015183820152602001611a68565b50505050905090810190601f168015611aad5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60008183611b125760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611a80578181015183820152602001611a68565b506000838581611b1e57fe5b0495945050505050565b610c2a80611b368339019056fe6080604052600080546001600160a01b0319163317905534801561002257600080fd5b50610bf8806100326000396000f3fe608060405234801561001057600080fd5b50600436106101215760003560e01c8063a6f9dae1116100ad578063d5d2c56011610071578063d5d2c560146103f5578063dc97d96214610418578063e2a4853a14610435578063e2b202bf14610458578063f6bb3cc41461047557610121565b8063a6f9dae114610332578063abfdcced14610358578063bd02d0f51461037d578063c031a180146103ac578063ca446dd9146103c957610121565b8063616b59f6116100f4578063616b59f6146101be5780636e899550146101db5780637ae1cfca146102525780638c16009514610283578063986e791a146102a057610121565b80630e14a3761461012657806321f8a721146101455780632c62ff2d1461017e5780633e49bed01461019b575b600080fd5b6101436004803603602081101561013c57600080fd5b5035610492565b005b6101626004803603602081101561015b57600080fd5b50356104fd565b604080516001600160a01b039092168252519081900360200190f35b6101436004803603602081101561019457600080fd5b5035610518565b610143600480360360408110156101b157600080fd5b508035906020013561057d565b610143600480360360208110156101d457600080fd5b50356105dc565b610143600480360360408110156101f157600080fd5b8135919081019060408101602082013564010000000081111561021357600080fd5b82018360208201111561022557600080fd5b8035906020019184600183028401116401000000008311171561024757600080fd5b50909250905061063a565b61026f6004803603602081101561026857600080fd5b50356106a6565b604080519115158252519081900360200190f35b6101436004803603602081101561029957600080fd5b50356106bb565b6102bd600480360360208110156102b657600080fd5b5035610719565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102f75781810151838201526020016102df565b50505050905090810190601f1680156103245780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101436004803603602081101561034857600080fd5b50356001600160a01b03166107b8565b6101436004803603604081101561036e57600080fd5b50803590602001351515610827565b61039a6004803603602081101561039357600080fd5b5035610894565b60408051918252519081900360200190f35b61039a600480360360208110156103c257600080fd5b50356108a6565b610143600480360360408110156103df57600080fd5b50803590602001356001600160a01b03166108b8565b6101436004803603604081101561040b57600080fd5b5080359060200135610933565b61039a6004803603602081101561042e57600080fd5b5035610992565b6101436004803603604081101561044b57600080fd5b50803590602001356109a4565b6101436004803603602081101561046e57600080fd5b5035610a03565b6101436004803603602081101561048b57600080fd5b5035610a61565b6000546001600160a01b031633146104df576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b600090815260036020526040902080546001600160a01b0319169055565b6000908152600360205260409020546001600160a01b031690565b6000546001600160a01b03163314610565576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b6000908152600560205260409020805460ff19169055565b6000546001600160a01b031633146105ca576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b60009182526006602052604090912055565b6000546001600160a01b03163314610629576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b600090815260046020526040812055565b6000546001600160a01b03163314610687576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b60008381526002602052604090206106a0908383610ac8565b50505050565b60009081526005602052604090205460ff1690565b6000546001600160a01b03163314610708576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b600090815260066020526040812055565b600081815260026020818152604092839020805484516001821615610100026000190190911693909304601f810183900483028401830190945283835260609390918301828280156107ac5780601f10610781576101008083540402835291602001916107ac565b820191906000526020600020905b81548152906001019060200180831161078f57829003601f168201915b50505050509050919050565b6000546001600160a01b03163314610805576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314610874576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b600091825260056020526040909120805460ff1916911515919091179055565b60009081526001602052604090205490565b60009081526004602052604090205490565b6000546001600160a01b03163314610905576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b60009182526003602052604090912080546001600160a01b0319166001600160a01b03909216919091179055565b6000546001600160a01b03163314610980576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b60009182526004602052604090912055565b60009081526006602052604090205490565b6000546001600160a01b031633146109f1576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b60009182526001602052604090912055565b6000546001600160a01b03163314610a50576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b600090815260016020526040812055565b6000546001600160a01b03163314610aae576040805162461bcd60e51b81526020600482015260116024820152600080516020610ba4833981519152604482015290519081900360640190fd5b6000818152600260205260408120610ac591610b46565b50565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610b095782800160ff19823516178555610b36565b82800160010185558215610b36579182015b82811115610b36578235825591602001919060010190610b1b565b50610b42929150610b86565b5090565b50805460018160011615610100020316600290046000825580601f10610b6c5750610ac5565b601f016020900490600052602060002090810190610ac591905b610ba091905b80821115610b425760008155600101610b8c565b9056fe6e6f742063757272656e74206f776e6572000000000000000000000000000000a265627a7a7231582057b8f79d63d7401460f294f799b49ede95894ae9e0caba7b38d88fb5d7c66fd364736f6c634300051100324f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572a265627a7a723158205ad1215a85ca72592cf7be5c2ea49eb8c27208c0311b670cbec87b559da8569864736f6c63430005110032

Verified Source Code Partial Match

Compiler: v0.5.17+commit.d19bba13 EVM: istanbul Optimization: Yes (200 runs)
Withdraw.sol 1443 lines
// File: @openzeppelin/contracts/math/SafeMath.sol

pragma solidity ^0.5.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.
     *
     * _Available since v2.4.0._
     */
    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.
     *
     * _Available since v2.4.0._
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        // Solidity only automatically asserts when dividing by 0
        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.
     *
     * _Available since v2.4.0._
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }
}

// File: @openzeppelin/contracts/token/ERC20/IERC20.sol

pragma solidity ^0.5.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP. Does not include
 * the optional functions; to access them see {ERC20Detailed}.
 */
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: contracts/src/common/libs/Decimals.sol

pragma solidity 0.5.17;


/**
 * Library for emulating calculations involving decimals.
 */
library Decimals {
	using SafeMath for uint256;
	uint120 private constant BASIS_VAKUE = 1000000000000000000;

	/**
	 * @dev Returns the ratio of the first argument to the second argument.
	 * @param _a Numerator.
	 * @param _b Fraction.
	 * @return Calculated ratio.
	 */
	function outOf(uint256 _a, uint256 _b)
		internal
		pure
		returns (uint256 result)
	{
		if (_a == 0) {
			return 0;
		}
		uint256 a = _a.mul(BASIS_VAKUE);
		if (a < _b) {
			return 0;
		}
		return (a.div(_b));
	}

	/**
	 * @dev Returns multiplied the number by 10^18.
	 * @param _a Numerical value to be multiplied.
	 * @return Multiplied value.
	 */
	function mulBasis(uint256 _a) internal pure returns (uint256) {
		return _a.mul(BASIS_VAKUE);
	}

	/**
	 * @dev Returns divisioned the number by 10^18.
	 * This function can use it to restore the number of digits in the result of `outOf`.
	 * @param _a Numerical value to be divisioned.
	 * @return Divisioned value.
	 */
	function divBasis(uint256 _a) internal pure returns (uint256) {
		return _a.div(BASIS_VAKUE);
	}
}

// File: contracts/interface/IAddressConfig.sol

// SPDX-License-Identifier: MPL-2.0
pragma solidity >=0.5.17;

interface IAddressConfig {
	function token() external view returns (address);

	function allocator() external view returns (address);

	function allocatorStorage() external view returns (address);

	function withdraw() external view returns (address);

	function withdrawStorage() external view returns (address);

	function marketFactory() external view returns (address);

	function marketGroup() external view returns (address);

	function propertyFactory() external view returns (address);

	function propertyGroup() external view returns (address);

	function metricsGroup() external view returns (address);

	function metricsFactory() external view returns (address);

	function policy() external view returns (address);

	function policyFactory() external view returns (address);

	function policySet() external view returns (address);

	function policyGroup() external view returns (address);

	function lockup() external view returns (address);

	function lockupStorage() external view returns (address);

	function voteTimes() external view returns (address);

	function voteTimesStorage() external view returns (address);

	function voteCounter() external view returns (address);

	function voteCounterStorage() external view returns (address);

	function setAllocator(address _addr) external;

	function setAllocatorStorage(address _addr) external;

	function setWithdraw(address _addr) external;

	function setWithdrawStorage(address _addr) external;

	function setMarketFactory(address _addr) external;

	function setMarketGroup(address _addr) external;

	function setPropertyFactory(address _addr) external;

	function setPropertyGroup(address _addr) external;

	function setMetricsFactory(address _addr) external;

	function setMetricsGroup(address _addr) external;

	function setPolicyFactory(address _addr) external;

	function setPolicyGroup(address _addr) external;

	function setPolicySet(address _addr) external;

	function setPolicy(address _addr) external;

	function setToken(address _addr) external;

	function setLockup(address _addr) external;

	function setLockupStorage(address _addr) external;

	function setVoteTimes(address _addr) external;

	function setVoteTimesStorage(address _addr) external;

	function setVoteCounter(address _addr) external;

	function setVoteCounterStorage(address _addr) external;
}

// File: contracts/src/common/config/UsingConfig.sol

pragma solidity 0.5.17;


/**
 * Module for using AddressConfig contracts.
 */
contract UsingConfig {
	address private _config;

	/**
	 * Initialize the argument as AddressConfig address.
	 */
	constructor(address _addressConfig) public {
		_config = _addressConfig;
	}

	/**
	 * Returns the latest AddressConfig instance.
	 */
	function config() internal view returns (IAddressConfig) {
		return IAddressConfig(_config);
	}

	/**
	 * Returns the latest AddressConfig address.
	 */
	function configAddress() external view returns (address) {
		return _config;
	}
}

// File: contracts/interface/IUsingStorage.sol

// SPDX-License-Identifier: MPL-2.0
pragma solidity >=0.5.17;

interface IUsingStorage {
	function getStorageAddress() external view returns (address);

	function createStorage() external;

	function setStorage(address _storageAddress) external;

	function changeOwner(address newOwner) external;
}

// File: @openzeppelin/contracts/GSN/Context.sol

pragma solidity ^0.5.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.
 */
contract Context {
    // Empty internal constructor, to prevent people from mistakenly deploying
    // an instance of this contract, which should be used via inheritance.
    constructor () internal { }
    // solhint-disable-previous-line no-empty-blocks

    function _msgSender() internal view returns (address payable) {
        return msg.sender;
    }

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

// File: @openzeppelin/contracts/ownership/Ownable.sol

pragma solidity ^0.5.0;

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
contract Ownable is Context {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(isOwner(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Returns true if the caller is the current owner.
     */
    function isOwner() public view returns (bool) {
        return _msgSender() == _owner;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public onlyOwner {
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     */
    function _transferOwnership(address newOwner) internal {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

// File: contracts/src/common/storage/EternalStorage.sol

pragma solidity 0.5.17;

/**
 * Module for persisting states.
 * Stores a map for `uint256`, `string`, `address`, `bytes32`, `bool`, and `int256` type with `bytes32` type as a key.
 */
contract EternalStorage {
	address private currentOwner = msg.sender;

	mapping(bytes32 => uint256) private uIntStorage;
	mapping(bytes32 => string) private stringStorage;
	mapping(bytes32 => address) private addressStorage;
	mapping(bytes32 => bytes32) private bytesStorage;
	mapping(bytes32 => bool) private boolStorage;
	mapping(bytes32 => int256) private intStorage;

	/**
	 * Modifiers to validate that only the owner can execute.
	 */
	modifier onlyCurrentOwner() {
		require(msg.sender == currentOwner, "not current owner");
		_;
	}

	/**
	 * Transfer the owner.
	 * Only the owner can execute this function.
	 */
	function changeOwner(address _newOwner) external {
		require(msg.sender == currentOwner, "not current owner");
		currentOwner = _newOwner;
	}

	// *** Getter Methods ***

	/**
	 * Returns the value of the `uint256` type that mapped to the given key.
	 */
	function getUint(bytes32 _key) external view returns (uint256) {
		return uIntStorage[_key];
	}

	/**
	 * Returns the value of the `string` type that mapped to the given key.
	 */
	function getString(bytes32 _key) external view returns (string memory) {
		return stringStorage[_key];
	}

	/**
	 * Returns the value of the `address` type that mapped to the given key.
	 */
	function getAddress(bytes32 _key) external view returns (address) {
		return addressStorage[_key];
	}

	/**
	 * Returns the value of the `bytes32` type that mapped to the given key.
	 */
	function getBytes(bytes32 _key) external view returns (bytes32) {
		return bytesStorage[_key];
	}

	/**
	 * Returns the value of the `bool` type that mapped to the given key.
	 */
	function getBool(bytes32 _key) external view returns (bool) {
		return boolStorage[_key];
	}

	/**
	 * Returns the value of the `int256` type that mapped to the given key.
	 */
	function getInt(bytes32 _key) external view returns (int256) {
		return intStorage[_key];
	}

	// *** Setter Methods ***

	/**
	 * Maps a value of `uint256` type to a given key.
	 * Only the owner can execute this function.
	 */
	function setUint(bytes32 _key, uint256 _value) external onlyCurrentOwner {
		uIntStorage[_key] = _value;
	}

	/**
	 * Maps a value of `string` type to a given key.
	 * Only the owner can execute this function.
	 */
	function setString(bytes32 _key, string calldata _value)
		external
		onlyCurrentOwner
	{
		stringStorage[_key] = _value;
	}

	/**
	 * Maps a value of `address` type to a given key.
	 * Only the owner can execute this function.
	 */
	function setAddress(bytes32 _key, address _value)
		external
		onlyCurrentOwner
	{
		addressStorage[_key] = _value;
	}

	/**
	 * Maps a value of `bytes32` type to a given key.
	 * Only the owner can execute this function.
	 */
	function setBytes(bytes32 _key, bytes32 _value) external onlyCurrentOwner {
		bytesStorage[_key] = _value;
	}

	/**
	 * Maps a value of `bool` type to a given key.
	 * Only the owner can execute this function.
	 */
	function setBool(bytes32 _key, bool _value) external onlyCurrentOwner {
		boolStorage[_key] = _value;
	}

	/**
	 * Maps a value of `int256` type to a given key.
	 * Only the owner can execute this function.
	 */
	function setInt(bytes32 _key, int256 _value) external onlyCurrentOwner {
		intStorage[_key] = _value;
	}

	// *** Delete Methods ***

	/**
	 * Deletes the value of the `uint256` type that mapped to the given key.
	 * Only the owner can execute this function.
	 */
	function deleteUint(bytes32 _key) external onlyCurrentOwner {
		delete uIntStorage[_key];
	}

	/**
	 * Deletes the value of the `string` type that mapped to the given key.
	 * Only the owner can execute this function.
	 */
	function deleteString(bytes32 _key) external onlyCurrentOwner {
		delete stringStorage[_key];
	}

	/**
	 * Deletes the value of the `address` type that mapped to the given key.
	 * Only the owner can execute this function.
	 */
	function deleteAddress(bytes32 _key) external onlyCurrentOwner {
		delete addressStorage[_key];
	}

	/**
	 * Deletes the value of the `bytes32` type that mapped to the given key.
	 * Only the owner can execute this function.
	 */
	function deleteBytes(bytes32 _key) external onlyCurrentOwner {
		delete bytesStorage[_key];
	}

	/**
	 * Deletes the value of the `bool` type that mapped to the given key.
	 * Only the owner can execute this function.
	 */
	function deleteBool(bytes32 _key) external onlyCurrentOwner {
		delete boolStorage[_key];
	}

	/**
	 * Deletes the value of the `int256` type that mapped to the given key.
	 * Only the owner can execute this function.
	 */
	function deleteInt(bytes32 _key) external onlyCurrentOwner {
		delete intStorage[_key];
	}
}

// File: contracts/src/common/storage/UsingStorage.sol

pragma solidity 0.5.17;




/**
 * Module for contrast handling EternalStorage.
 */
contract UsingStorage is Ownable, IUsingStorage {
	address private _storage;

	/**
	 * Modifier to verify that EternalStorage is set.
	 */
	modifier hasStorage() {
		require(_storage != address(0), "storage is not set");
		_;
	}

	/**
	 * Returns the set EternalStorage instance.
	 */
	function eternalStorage()
		internal
		view
		hasStorage
		returns (EternalStorage)
	{
		return EternalStorage(_storage);
	}

	/**
	 * Returns the set EternalStorage address.
	 */
	function getStorageAddress() external view hasStorage returns (address) {
		return _storage;
	}

	/**
	 * Create a new EternalStorage contract.
	 * This function call will fail if the EternalStorage contract is already set.
	 * Also, only the owner can execute it.
	 */
	function createStorage() external onlyOwner {
		require(_storage == address(0), "storage is set");
		EternalStorage tmp = new EternalStorage();
		_storage = address(tmp);
	}

	/**
	 * Assigns the EternalStorage contract that has already been created.
	 * Only the owner can execute this function.
	 */
	function setStorage(address _storageAddress) external onlyOwner {
		_storage = _storageAddress;
	}

	/**
	 * Delegates the owner of the current EternalStorage contract.
	 * Only the owner can execute this function.
	 */
	function changeOwner(address newOwner) external onlyOwner {
		EternalStorage(_storage).changeOwner(newOwner);
	}
}

// File: contracts/src/withdraw/WithdrawStorage.sol

pragma solidity 0.5.17;


contract WithdrawStorage is UsingStorage {
	// RewardsAmount
	function setRewardsAmount(address _property, uint256 _value) internal {
		eternalStorage().setUint(getRewardsAmountKey(_property), _value);
	}

	function getRewardsAmount(address _property) public view returns (uint256) {
		return eternalStorage().getUint(getRewardsAmountKey(_property));
	}

	function getRewardsAmountKey(address _property)
		private
		pure
		returns (bytes32)
	{
		return keccak256(abi.encodePacked("_rewardsAmount", _property));
	}

	// CumulativePrice
	function setCumulativePrice(address _property, uint256 _value) internal {
		// The previously used function
		// This function is only used in testing
		eternalStorage().setUint(getCumulativePriceKey(_property), _value);
	}

	function getCumulativePrice(address _property)
		public
		view
		returns (uint256)
	{
		return eternalStorage().getUint(getCumulativePriceKey(_property));
	}

	function getCumulativePriceKey(address _property)
		private
		pure
		returns (bytes32)
	{
		return keccak256(abi.encodePacked("_cumulativePrice", _property));
	}

	//LastWithdrawalPrice
	function setLastWithdrawalPrice(
		address _property,
		address _user,
		uint256 _value
	) internal {
		eternalStorage().setUint(
			getLastWithdrawalPriceKey(_property, _user),
			_value
		);
	}

	function getLastWithdrawalPrice(address _property, address _user)
		public
		view
		returns (uint256)
	{
		return
			eternalStorage().getUint(
				getLastWithdrawalPriceKey(_property, _user)
			);
	}

	function getLastWithdrawalPriceKey(address _property, address _user)
		private
		pure
		returns (bytes32)
	{
		return
			keccak256(
				abi.encodePacked("_lastWithdrawalPrice", _property, _user)
			);
	}

	//PendingWithdrawal
	function setPendingWithdrawal(
		address _property,
		address _user,
		uint256 _value
	) internal {
		eternalStorage().setUint(
			getPendingWithdrawalKey(_property, _user),
			_value
		);
	}

	function getPendingWithdrawal(address _property, address _user)
		public
		view
		returns (uint256)
	{
		return
			eternalStorage().getUint(getPendingWithdrawalKey(_property, _user));
	}

	function getPendingWithdrawalKey(address _property, address _user)
		private
		pure
		returns (bytes32)
	{
		return
			keccak256(abi.encodePacked("_pendingWithdrawal", _property, _user));
	}

	//lastWithdrawnReward
	function setStorageLastWithdrawnReward(
		address _property,
		address _user,
		uint256 _value
	) internal {
		eternalStorage().setUint(
			getStorageLastWithdrawnRewardKey(_property, _user),
			_value
		);
	}

	function getStorageLastWithdrawnReward(address _property, address _user)
		public
		view
		returns (uint256)
	{
		return
			eternalStorage().getUint(
				getStorageLastWithdrawnRewardKey(_property, _user)
			);
	}

	function getStorageLastWithdrawnRewardKey(address _property, address _user)
		private
		pure
		returns (bytes32)
	{
		return
			keccak256(
				abi.encodePacked("_lastWithdrawnReward", _property, _user)
			);
	}

	//lastWithdrawnRewardCap
	function setStorageLastWithdrawnRewardCap(
		address _property,
		address _user,
		uint256 _value
	) internal {
		eternalStorage().setUint(
			getStorageLastWithdrawnRewardCapKey(_property, _user),
			_value
		);
	}

	function getStorageLastWithdrawnRewardCap(address _property, address _user)
		public
		view
		returns (uint256)
	{
		return
			eternalStorage().getUint(
				getStorageLastWithdrawnRewardCapKey(_property, _user)
			);
	}

	function getStorageLastWithdrawnRewardCapKey(
		address _property,
		address _user
	) private pure returns (bytes32) {
		return
			keccak256(
				abi.encodePacked("_lastWithdrawnRewardCap", _property, _user)
			);
	}
}

// File: contracts/interface/IDevMinter.sol

// SPDX-License-Identifier: MPL-2.0
pragma solidity >=0.5.17;

interface IDevMinter {
	function mint(address account, uint256 amount) external returns (bool);

	function renounceMinter() external;
}

// File: contracts/interface/IWithdraw.sol

// SPDX-License-Identifier: MPL-2.0
pragma solidity >=0.5.17;

interface IWithdraw {
	function withdraw(address _property) external;

	function getRewardsAmount(address _property)
		external
		view
		returns (uint256);

	function beforeBalanceChange(
		address _property,
		address _from,
		address _to
	) external;

	/**
	 * caution!!!this function is deprecated!!!
	 * use calculateRewardAmount
	 */
	function calculateWithdrawableAmount(address _property, address _user)
		external
		view
		returns (uint256);

	function calculateRewardAmount(address _property, address _user)
		external
		view
		returns (
			uint256 _amount,
			uint256 _price,
			uint256 _cap,
			uint256 _allReward
		);

	function devMinter() external view returns (address);
}

// File: contracts/interface/ILockup.sol

// SPDX-License-Identifier: MPL-2.0
pragma solidity >=0.5.17;

interface ILockup {
	function lockup(
		address _from,
		address _property,
		uint256 _value
	) external;

	function update() external;

	function withdraw(address _property, uint256 _amount) external;

	function calculateCumulativeRewardPrices()
		external
		view
		returns (
			uint256 _reward,
			uint256 _holders,
			uint256 _interest,
			uint256 _holdersCap
		);

	function calculateRewardAmount(address _property)
		external
		view
		returns (uint256, uint256);

	/**
	 * caution!!!this function is deprecated!!!
	 * use calculateRewardAmount
	 */
	function calculateCumulativeHoldersRewardAmount(address _property)
		external
		view
		returns (uint256);

	function getPropertyValue(address _property)
		external
		view
		returns (uint256);

	function getAllValue() external view returns (uint256);

	function getValue(address _property, address _sender)
		external
		view
		returns (uint256);

	function calculateWithdrawableInterestAmount(
		address _property,
		address _user
	) external view returns (uint256);

	function cap() external view returns (uint256);

	function updateCap(uint256 _cap) external;

	function devMinter() external view returns (address);
}

// File: contracts/interface/IMetricsGroup.sol

// SPDX-License-Identifier: MPL-2.0
pragma solidity >=0.5.17;

interface IMetricsGroup {
	function addGroup(address _addr) external;

	function removeGroup(address _addr) external;

	function isGroup(address _addr) external view returns (bool);

	function totalIssuedMetrics() external view returns (uint256);

	function hasAssets(address _property) external view returns (bool);

	function getMetricsCountPerProperty(address _property)
		external
		view
		returns (uint256);

	function totalAuthenticatedProperties() external view returns (uint256);

	// deplicated!!!!!!!
	function setTotalAuthenticatedPropertiesAdmin(uint256 _value) external;
}

// File: contracts/interface/IPropertyGroup.sol

// SPDX-License-Identifier: MPL-2.0
pragma solidity >=0.5.17;

interface IPropertyGroup {
	function addGroup(address _addr) external;

	function isGroup(address _addr) external view returns (bool);
}

// File: contracts/src/withdraw/Withdraw.sol

pragma solidity 0.5.17;

// prettier-ignore










/**
 * A contract that manages the withdrawal of holder rewards for Property holders.
 */
contract Withdraw is IWithdraw, UsingConfig, WithdrawStorage {
	using SafeMath for uint256;
	using Decimals for uint256;
	address public devMinter;
	event PropertyTransfer(address _property, address _from, address _to);

	/**
	 * Initialize the passed address as AddressConfig address.
	 */
	constructor(address _config, address _devMinter)
		public
		UsingConfig(_config)
	{
		devMinter = _devMinter;
	}

	/**
	 * Withdraws rewards.
	 */
	function withdraw(address _property) external {
		/**
		 * Validate
		 * the passed Property address is included the Property address set.
		 */
		require(
			IPropertyGroup(config().propertyGroup()).isGroup(_property),
			"this is illegal address"
		);

		/**
		 * Gets the withdrawable rewards amount and the latest cumulative sum of the maximum mint amount.
		 */
		(uint256 value, uint256 lastPrice, uint256 lastPriceCap, ) =
			_calculateWithdrawableAmount(_property, msg.sender);

		/**
		 * Validates the result is not 0.
		 */
		require(value != 0, "withdraw value is 0");

		/**
		 * Saves the latest cumulative sum of the holder reward price.
		 * By subtracting this value when calculating the next rewards, always withdrawal the difference from the previous time.
		 */
		setStorageLastWithdrawnReward(_property, msg.sender, lastPrice);
		setStorageLastWithdrawnRewardCap(_property, msg.sender, lastPriceCap);

		/**
		 * Sets the number of unwithdrawn rewards to 0.
		 */
		setPendingWithdrawal(_property, msg.sender, 0);

		/**
		 * Updates the withdrawal status to avoid double withdrawal for before DIP4.
		 */
		__updateLegacyWithdrawableAmount(_property, msg.sender);

		/**
		 * Mints the holder reward.
		 */
		require(
			IDevMinter(devMinter).mint(msg.sender, value),
			"dev mint failed"
		);

		/**
		 * Since the total supply of tokens has changed, updates the latest maximum mint amount.
		 */
		ILockup lockup = ILockup(config().lockup());
		lockup.update();

		/**
		 * Adds the reward amount already withdrawn in the passed Property.
		 */
		setRewardsAmount(_property, getRewardsAmount(_property).add(value));
	}

	/**
	 * Updates the change in compensation amount due to the change in the ownership ratio of the passed Property.
	 * When the ownership ratio of Property changes, the reward that the Property holder can withdraw will change.
	 * It is necessary to update the status before and after the ownership ratio changes.
	 */
	function beforeBalanceChange(
		address _property,
		address _from,
		address _to
	) external {
		/**
		 * Validates the sender is Allocator contract.
		 */
		require(msg.sender == config().allocator(), "this is illegal address");

		/**
		 * Gets the cumulative sum of the transfer source's "before transfer" withdrawable reward amount and the cumulative sum of the maximum mint amount.
		 */
		(uint256 amountFrom, uint256 priceFrom, uint256 priceCapFrom, ) =
			_calculateAmount(_property, _from);

		/**
		 * Gets the cumulative sum of the transfer destination's "before receive" withdrawable reward amount and the cumulative sum of the maximum mint amount.
		 */
		(uint256 amountTo, uint256 priceTo, uint256 priceCapTo, ) =
			_calculateAmount(_property, _to);

		/**
		 * Updates the last cumulative sum of the maximum mint amount of the transfer source and destination.
		 */
		setStorageLastWithdrawnReward(_property, _from, priceFrom);
		setStorageLastWithdrawnReward(_property, _to, priceTo);
		setStorageLastWithdrawnRewardCap(_property, _from, priceCapFrom);
		setStorageLastWithdrawnRewardCap(_property, _to, priceCapTo);

		/**
		 * Gets the unwithdrawn reward amount of the transfer source and destination.
		 */
		uint256 pendFrom = getPendingWithdrawal(_property, _from);
		uint256 pendTo = getPendingWithdrawal(_property, _to);

		/**
		 * Adds the undrawn reward amount of the transfer source and destination.
		 */
		setPendingWithdrawal(_property, _from, pendFrom.add(amountFrom));
		setPendingWithdrawal(_property, _to, pendTo.add(amountTo));

		emit PropertyTransfer(_property, _from, _to);
	}

	/**
	 * Returns the holder reward.
	 */
	function _calculateAmount(address _property, address _user)
		private
		view
		returns (
			uint256 _amount,
			uint256 _price,
			uint256 _cap,
			uint256 _allReward
		)
	{
		ILockup lockup = ILockup(config().lockup());
		/**
		 * Gets the latest reward.
		 */
		(uint256 reward, uint256 cap) = lockup.calculateRewardAmount(_property);

		/**
		 * Gets the cumulative sum of the holder reward price recorded the last time you withdrew.
		 */

		uint256 allReward = _calculateAllReward(_property, _user, reward);
		uint256 capped = _calculateCapped(_property, _user, cap);
		uint256 value =
			capped == 0 ? allReward : allReward <= capped ? allReward : capped;

		/**
		 * Returns the result after adjusted decimals to 10^18, and the latest cumulative sum of the holder reward price.
		 */
		return (value, reward, cap, allReward);
	}

	/**
	 * Return the reward cap
	 */
	function _calculateCapped(
		address _property,
		address _user,
		uint256 _cap
	) private view returns (uint256) {
		/**
		 * Gets the cumulative sum of the holder reward price recorded the last time you withdrew.
		 */
		uint256 _lastRewardCap =
			getStorageLastWithdrawnRewardCap(_property, _user);
		IERC20 property = IERC20(_property);
		uint256 balance = property.balanceOf(_user);
		uint256 totalSupply = property.totalSupply();
		uint256 unitPriceCap = _cap.sub(_lastRewardCap).div(totalSupply);
		return unitPriceCap.mul(balance).divBasis();
	}

	/**
	 * Return the reward
	 */
	function _calculateAllReward(
		address _property,
		address _user,
		uint256 _reward
	) private view returns (uint256) {
		/**
		 * Gets the cumulative sum of the holder reward price recorded the last time you withdrew.
		 */
		uint256 _lastReward = getStorageLastWithdrawnReward(_property, _user);
		IERC20 property = IERC20(_property);
		uint256 balance = property.balanceOf(_user);
		uint256 totalSupply = property.totalSupply();
		uint256 unitPrice =
			_reward.sub(_lastReward).mulBasis().div(totalSupply);
		return unitPrice.mul(balance).divBasis().divBasis();
	}

	/**
	 * Returns the total rewards currently available for withdrawal. (For calling from inside the contract)
	 */
	function _calculateWithdrawableAmount(address _property, address _user)
		private
		view
		returns (
			uint256 _amount,
			uint256 _price,
			uint256 _cap,
			uint256 _allReward
		)
	{
		/**
		 * Gets the latest withdrawal reward amount.
		 */
		(uint256 _value, uint256 price, uint256 cap, uint256 allReward) =
			_calculateAmount(_property, _user);

		/**
		 * If the passed Property has not authenticated, returns always 0.
		 */
		if (
			IMetricsGroup(config().metricsGroup()).hasAssets(_property) == false
		) {
			return (0, price, cap, 0);
		}

		/**
		 * Gets the reward amount of before DIP4.
		 */
		uint256 legacy = __legacyWithdrawableAmount(_property, _user);

		/**
		 * Gets the reward amount in saved without withdrawal and returns the sum of all values.
		 */
		uint256 value =
			_value.add(getPendingWithdrawal(_property, _user)).add(legacy);
		return (value, price, cap, allReward);
	}

	/**
	 * Returns the total rewards currently available for withdrawal. (For calling from external of the contract)
	 * caution!!!this function is deprecated!!!
	 * use calculateRewardAmount
	 */
	function calculateWithdrawableAmount(address _property, address _user)
		external
		view
		returns (uint256)
	{
		(uint256 value, , , ) = _calculateWithdrawableAmount(_property, _user);
		return value;
	}

	/**
	 * Returns the rewards amount
	 */
	function calculateRewardAmount(address _property, address _user)
		external
		view
		returns (
			uint256 _amount,
			uint256 _price,
			uint256 _cap,
			uint256 _allReward
		)
	{
		return _calculateWithdrawableAmount(_property, _user);
	}

	/**
	 * Returns the reward amount of the calculation model before DIP4.
	 * It can be calculated by subtracting "the last cumulative sum of reward unit price" from
	 * "the current cumulative sum of reward unit price," and multiplying by the balance of the user.
	 */
	function __legacyWithdrawableAmount(address _property, address _user)
		private
		view
		returns (uint256)
	{
		uint256 _last = getLastWithdrawalPrice(_property, _user);
		uint256 price = getCumulativePrice(_property);
		uint256 priceGap = price.sub(_last);
		uint256 balance = IERC20(_property).balanceOf(_user);
		uint256 value = priceGap.mul(balance);
		return value.divBasis();
	}

	/**
	 * Updates and treats the reward of before DIP4 as already received.
	 */
	function __updateLegacyWithdrawableAmount(address _property, address _user)
		private
	{
		uint256 price = getCumulativePrice(_property);
		setLastWithdrawalPrice(_property, _user, price);
	}
}

Read Contract

calculateRewardAmount 0xe09d1f6a → uint256, uint256, uint256, uint256
calculateWithdrawableAmount 0x68f1b7c7 → uint256
configAddress 0xd6c31871 → address
devMinter 0x94ab898c → address
getCumulativePrice 0x1382da2c → uint256
getLastWithdrawalPrice 0x06aa2d48 → uint256
getPendingWithdrawal 0x5699c7b1 → uint256
getRewardsAmount 0xdbe93451 → uint256
getStorageAddress 0x393a4d34 → address
getStorageLastWithdrawnReward 0xbce64ada → uint256
getStorageLastWithdrawnRewardCap 0xb17e9ee6 → uint256
isOwner 0x8f32d59b → bool
owner 0x8da5cb5b → address

Write Contract 7 functions

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

beforeBalanceChange 0x0448a8e6
address _property
address _from
address _to
changeOwner 0xa6f9dae1
address newOwner
createStorage 0xfb971d01
No parameters
renounceOwnership 0x715018a6
No parameters
setStorage 0x9137c1a7
address _storageAddress
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x51cff8d9
address _property

Recent Transactions

No transactions found for this address