Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xEBe9Ad0Be3ec72c3dF0389b51471D4D3ab441a28
Balance 0 ETH
Nonce 1
Code Size 14652 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

14652 bytes
0x608060405234801561001057600080fd5b50600436106102275760003560e01c8063842e298111610130578063bcb6c0b5116100b8578063e97020d51161007c578063e97020d514610494578063f2fde38b1461049c578063f3fef3a3146104af578063f7b188a5146104c2578063ffc9896b146104ca57610227565b8063bcb6c0b514610435578063c350a1b514610448578063c4d66de81461045b578063cbe230c31461046e578063d43075471461048157610227565b80639f224f35116100ff5780639f224f35146103c7578063a694fc3a146103da578063ac92020d146103ed578063adc9772e1461040f578063af81c5b91461042257610227565b8063842e2981146103845780638456cb59146103975780638af827fc1461039f5780638da5cb5b146103bf57610227565b8063419bc8ad116101b35780635fa7b584116101825780635fa7b58414610346578063604282891461035957806362ad351b1461036c578063682ed99d14610374578063715018a61461037c57610227565b8063419bc8ad146102f657806345efe2e6146103095780635c975abb1461031c5780635f5817e31461033157610227565b806327a51639116101fa57806327a51639146102905780632e1a7d4d1461029857806332bfe469146102b8578063331a42e6146102ce5780634162169f146102e157610227565b8063034f64361461022c57806314f63f0714610241578063159cbb7c1461026a57806321faf1841461027d575b600080fd5b61023f61023a366004613360565b6104ec565b005b61025461024f366004613491565b61055a565b6040516102619190613662565b60405180910390f35b6102546102783660046134f5565b6107de565b61023f61028b366004613491565b610893565b610254610994565b6102ab6102a63660046134f5565b6109a4565b6040516102619190613826565b6102c0610a1f565b604051610261929190613675565b61023f6102dc366004613360565b610ae5565b6102e9610b97565b6040516102619190613597565b610254610304366004613491565b610ba6565b6102ab61031736600461337a565b610c5b565b610324610cc6565b6040516102619190613697565b610339610ccf565b60405161026191906135ab565b61023f610354366004613360565b610d31565b61023f610367366004613360565b610f48565b6102e9611146565b6102e9611155565b61023f611164565b610254610392366004613360565b611210565b61023f61121c565b6103b26103ad3660046133ac565b611288565b60405161026191906135f4565b6102e96116fb565b6102e96103d53660046134f5565b61170a565b6102ab6103e83660046134f5565b611734565b6104006103fb366004613360565b6117af565b6040516102619392919061382f565b6102ab61041d366004613491565b6117d6565b61023f610430366004613491565b611836565b61023f610443366004613360565b611965565b61023f6104563660046134ba565b611a17565b61023f610469366004613360565b611b39565b61032461047c366004613360565b611bf5565b6102ab61048f366004613360565b611c47565b6102ab611c5c565b61023f6104aa366004613360565b611c62565b6102ab6104bd366004613491565b611d65565b61023f611dbe565b6104dd6104d8366004613360565b611e28565b604051610261939291906135be565b6104f4611f97565b6001600160a01b03166105056116fb565b6001600160a01b03161461054e576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b61055781611f9b565b50565b60608161056657600391505b6001600160a01b03831661057f5761057c611f97565b92505b600061058c836002612013565b600a0a90506105a5600a8261206d90919063ffffffff16565b609b5490915060009060010167ffffffffffffffff811180156105c757600080fd5b506040519080825280602002602001820160405280156105f1578160200160208202803683370190505b50905060008060005b609b5481101561079e57600080609a6000609b858154811061061857fe5b60009182526020808320909101546001600160a01b03168352820192909252604001902060020154111561070b57610708609a6000609b858154811061065a57fe5b9060005260206000200160009054906101000a90046001600160a01b03166001600160a01b03166001600160a01b031681526020019081526020016000206002015461070288609960008e6001600160a01b03166001600160a01b031681526020019081526020016000206002016000609b88815481106106d757fe5b60009182526020808320909101546001600160a01b031683528201929092526040019020549061206d565b906120c6565b90505b6000609a6000609b858154811061071e57fe5b60009182526020808320909101546001600160a01b0316835282019290925260400190206003015490506107528582612013565b9450610768610761838361206d565b8590612013565b935061077a600a610702846005612013565b86846001018151811061078957fe5b602090810291909101015250506001016105fa565b506107b9600a61070260056107b385876120c6565b90612013565b836000815181106107c657fe5b60209081029190910101525090925050505b92915050565b609b5460609060009067ffffffffffffffff811180156107fd57600080fd5b50604051908082528060200260200182016040528015610827578160200160208202803683370190505b50905060005b609b5460ff8216101561088a5761086884609b8360ff168154811061084e57fe5b6000918252602090912001546001600160a01b031661212d565b828260ff168151811061087757fe5b602090810291909101015260010161082d565b5090505b919050565b61089b611f97565b6001600160a01b03166108ac6116fb565b6001600160a01b0316146108f5576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b6001600160a01b0382166109245760405162461bcd60e51b815260040161091b90613721565b60405180910390fd5b600081116109445760405162461bcd60e51b815260040161091b906136a2565b6001600160a01b0382166000908152609a6020526040902060030154609d546109729183916107b3916121e9565b609d556001600160a01b039091166000908152609a6020526040902060030155565b606061099f436107de565b905090565b60006109ae610cc6565b156109f3576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6107d8609b600081548110610a0457fe5b6000918252602090912001546001600160a01b031683612246565b609b5460609060009067ffffffffffffffff81118015610a3e57600080fd5b50604051908082528060200260200182016040528015610a68578160200160208202803683370190505b509150609d54905060005b609b5460ff82161015610ae057609a6000609b8360ff1681548110610a9457fe5b60009182526020808320909101546001600160a01b031683528201929092526040019020600301548351849060ff8416908110610acd57fe5b6020908102919091010152600101610a73565b509091565b610aed611f97565b6001600160a01b0316610afe6116fb565b6001600160a01b031614610b47576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b609c546001600160a01b0382811691161415610b755760405162461bcd60e51b815260040161091b906137a9565b609c80546001600160a01b0319166001600160a01b0392909216919091179055565b6098546001600160a01b031681565b609b5460609060009067ffffffffffffffff81118015610bc557600080fd5b50604051908082528060200260200182016040528015610bef578160200160208202803683370190505b50905060005b609b5460ff82161015610c5357610c3185609b8360ff1681548110610c1657fe5b6000918252602090912001546001600160a01b0316866125df565b828260ff1681518110610c4057fe5b6020908102919091010152600101610bf5565b509392505050565b609c546000906001600160a01b0383811691161415610c9657506001600160a01b0382166000908152609960205260409020600301546107d8565b506001600160a01b03808316600090815260996020908152604080832093851683526002909301905220546107d8565b60655460ff1690565b6060609b805480602002602001604051908101604052809291908181526020018280548015610d2757602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610d09575b5050505050905090565b610d39611f97565b6001600160a01b0316610d4a6116fb565b6001600160a01b031614610d93576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b610d9c81611bf5565b1515600114610dbd5760405162461bcd60e51b815260040161091b906136cb565b6001600160a01b0381166000908152609a602052604090206004015460ff16610df85760405162461bcd60e51b815260040161091b906136cb565b6000805b609b54811015610e4457826001600160a01b0316609b8281548110610e1d57fe5b6000918252602090912001546001600160a01b03161415610e3c578091505b600101610dfc565b506001600160a01b0382166000908152609a6020526040902060030154609d54610e6d916121e9565b609d556001600160a01b0382166000908152609a6020526040812060030155609b80546000198101908110610e9e57fe5b600091825260209091200154609b80546001600160a01b039092169183908110610ec457fe5b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550609b805480610efd57fe5b60008281526020808220830160001990810180546001600160a01b03191690559092019092556001600160a01b03939093168152609a9092525060409020600401805460ff19169055565b610f50611f97565b6001600160a01b0316610f616116fb565b6001600160a01b031614610faa576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b806001600160a01b0316609b600081548110610fc257fe5b6000918252602090912001546001600160a01b03161415610ff55760405162461bcd60e51b815260040161091b906137a9565b6000609a6000609b60008154811061100957fe5b6000918252602080832091909101546001600160a01b031683528201929092526040018120600401805460ff191692151592909217909155609b8054609a918391829061105257fe5b60009182526020808320909101546001600160a01b03168352820192909252604001812060030154609b80549193508492909161108b57fe5b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555080609a6000609b6000815481106110cc57fe5b60009182526020808320909101546001600160a01b03168352820192909252604001812060030191909155609b8054600192609a929091829061110b57fe5b6000918252602080832091909101546001600160a01b031683528201929092526040019020600401805460ff19169115159190911790555050565b6097546001600160a01b031690565b609c546001600160a01b031681565b61116c611f97565b6001600160a01b031661117d6116fb565b6001600160a01b0316146111c6576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b6033546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3603380546001600160a01b0319169055565b60606107d88243610ba6565b611224611f97565b6001600160a01b03166112356116fb565b6001600160a01b03161461127e576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b6112866126cf565b565b6001600160a01b038086166000908152609960209081526040808320938816835260019093019052908120606091906112c1908661276f565b915060009050815b6001600160a01b03808a166000908152609960209081526040808320938c1683526001909301905220548110801561134257506001600160a01b03808a166000908152609960209081526040808320938c168352600190930190522080548791908390811061133457fe5b906000526020600020015411155b1561135357600191820191016112c9565b5060005b8451811015611389578585828151811061136d57fe5b602002602001015111611381576001909101905b600101611357565b5060008167ffffffffffffffff811180156113a357600080fd5b506040519080825280602002602001820160405280156113dd57816020015b6113ca61331a565b8152602001906001900390816113c25790505b509050826000805b83518110156115b7576001600160a01b03808d166000908152609960209081526040808320938f168352600190930190529081205484108015611488575089609960008f6001600160a01b03166001600160a01b0316815260200190815260200160002060010160008e6001600160a01b03166001600160a01b03168152602001908152602001600020858154811061147a57fe5b906000526020600020015411155b6114935760006114f5565b609960008e6001600160a01b03166001600160a01b0316815260200190815260200160002060010160008d6001600160a01b03166001600160a01b0316815260200190815260200160002084815481106114e957fe5b90600052602060002001545b90506000808211801561150757508b82105b6115115781611513565b8b5b905060008a51851061152657600061153b565b8a858151811061153257fe5b60200260200101515b9050811580159061154c5750808211155b80611555575080155b15611585578187858151811061156757fe5b60209081029190910101515261157e866001612013565b95506115ac565b8087858151811061159257fe5b6020908102919091010151526115a9856001612013565b94505b5050506001016113e5565b5060005b83518110156116eb576115cf8560016121e9565b811461160e576116096001856115e58483612013565b815181106115ef57fe5b6020026020010151600001516121e990919063ffffffff16565b611610565b885b84828151811061161c57fe5b6020026020010151602001818152505061164e8c8c86848151811061163d57fe5b6020026020010151600001516125df565b84828151811061165a57fe5b6020026020010151604001818152505061168b84828151811061167957fe5b6020026020010151600001518c61212d565b84828151811061169757fe5b602002602001015160600181815250506116c88482815181106116b657fe5b6020026020010151602001518c61212d565b8482815181106116d457fe5b6020908102919091010151608001526001016115bb565b50919a9950505050505050505050565b6033546001600160a01b031690565b609b818154811061171a57600080fd5b6000918252602090912001546001600160a01b0316905081565b600061173e610cc6565b15611783576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6107d8609b60008154811061179457fe5b6000918252602090912001546001600160a01b0316836127c6565b609a6020526000908152604090206002810154600382015460049092015490919060ff1683565b60006117e0610cc6565b15611825576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b61182f83836127c6565b9392505050565b61183e611f97565b6001600160a01b031661184f6116fb565b6001600160a01b031614611898576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b6001600160a01b0382166118be5760405162461bcd60e51b815260040161091b90613721565b6118c782611bf5565b156118e45760405162461bcd60e51b815260040161091b906137fe565b609b805460018082019092557fbba9db4cdbea0a37c207bbb83e20f828cd4441c49891101dc94fd20dc8efc3490180546001600160a01b0319166001600160a01b0385169081179091556000908152609a6020526040902060038101839055600401805460ff19169091179055609d5461195e9082612013565b609d555050565b61196d611f97565b6001600160a01b031661197e6116fb565b6001600160a01b0316146119c7576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b6098546001600160a01b03828116911614156119f55760405162461bcd60e51b815260040161091b906137a9565b609880546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff1680611a305750611a3061296d565b80611a3e575060005460ff16155b611a795760405162461bcd60e51b815260040180806020018281038252602e81526020018061386e602e913960400191505060405180910390fd5b600054610100900460ff16158015611aa4576000805460ff1961ff0019909116610100171660011790555b611aad82611b39565b6001600160a01b0384166000818152609a6020526040812060038101869055600401805460ff19166001908117909155609b805491820181559091527fbba9db4cdbea0a37c207bbb83e20f828cd4441c49891101dc94fd20dc8efc3490180546001600160a01b0319169091179055609d8390558015611b33576000805461ff00191690555b50505050565b600054610100900460ff1680611b525750611b5261296d565b80611b60575060005460ff16155b611b9b5760405162461bcd60e51b815260040180806020018281038252602e81526020018061386e602e913960400191505060405180910390fd5b600054610100900460ff16158015611bc6576000805460ff1961ff0019909116610100171660011790555b611bce61297e565b611bd6612a2f565b611bdf82611f9b565b8015611bf1576000805461ff00191690555b5050565b60006001600160a01b038216611c0d5750600061088e565b6001600160a01b0382166000908152609a602052604090206004015460ff16806107d8575050609c546001600160a01b0390811691161490565b60996020526000908152604090206003015481565b609d5481565b611c6a611f97565b6001600160a01b0316611c7b6116fb565b6001600160a01b031614611cc4576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b6001600160a01b038116611d095760405162461bcd60e51b81526004018080602001828103825260268152602001806138486026913960400191505060405180910390fd5b6033546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3603380546001600160a01b0319166001600160a01b0392909216919091179055565b6000611d6f610cc6565b15611db4576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b61182f8383612246565b611dc6611f97565b6001600160a01b0316611dd76116fb565b6001600160a01b031614611e20576040805162461bcd60e51b815260206004820181905260248201526000805160206138bd833981519152604482015290519081900360640190fd5b611286612acc565b606080600080609b8054905067ffffffffffffffff81118015611e4a57600080fd5b50604051908082528060200260200182016040528015611e74578160200160208202803683370190505b50905060005b609b5460ff82161015611f00576001600160a01b0386166000908152609960205260408120609b80546002909201929160ff8516908110611eb757fe5b60009182526020808320909101546001600160a01b031683528201929092526040019020548251839060ff8416908110611eed57fe5b6020908102919091010152600101611e7a565b50609b8160996000886001600160a01b03166001600160a01b031681526020019081526020016000206003015482805480602002602001604051908101604052809291908181526020018280548015611f8257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611f64575b50505050509250935093509350509193909250565b3390565b6001600160a01b038116158015611fbb57506097546001600160a01b0316155b15611fc557610557565b6097546001600160a01b0382811691161415611ff35760405162461bcd60e51b815260040161091b906137a9565b609780546001600160a01b0383166001600160a01b031990911617905550565b60008282018381101561182f576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b60008261207c575060006107d8565b8282028284828161208957fe5b041461182f5760405162461bcd60e51b815260040180806020018281038252602181526020018061389c6021913960400191505060405180910390fd5b600080821161211c576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b81838161212557fe5b049392505050565b6000804384141561215a57506001600160a01b0382166000908152609a602052604090206002015461182f565b506001600160a01b0382166000908152609a602090815260408083208684529091529020548061182f576001600160a01b0383166000908152609a602052604081206121a9906001018661276f565b509050806121ba5760009150610c53565b6001600160a01b0384166000908152609a60209081526040808320848452909152902054915050905092915050565b600082821115612240576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008082116122675760405162461bcd60e51b815260040161091b906136f2565b600060996000612275611f97565b6001600160a01b03908116825260208201929092526040016000908120609c549093508692838116911614156122d857609b6000815481106122b357fe5b60009182526020909120015460038401546001600160a01b0390911692509050612352565b609b6000815481106122e657fe5b6000918252602090912001546001600160a01b03838116911614156123355760038301546001600160a01b038316600090815260028501602052604090205461232e916121e9565b9050612352565b506001600160a01b03811660009081526002830160205260409020545b848110156123725760405162461bcd60e51b815260040161091b90613747565b6123848661237e611f97565b87612b4f565b6001600160a01b03821660009081526002840160205260408120546123a990876121e9565b6001600160a01b0384166000908152609a6020526040812060020154919250906123d390886121e9565b6098549091506001600160a01b0316158015906124145750609b6000815481106123f957fe5b6000918252602090912001546001600160a01b038581169116145b15612527576098546000906001600160a01b031663e91e7fc5612435611f97565b6040518263ffffffff1660e01b81526004016124519190613597565b602060405180830381600087803b15801561246b57600080fd5b505af115801561247f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124a3919061350d565b6001600160a01b03861660009081526002880160205260409020549091508111156124e05760405162461bcd60e51b815260040161091b906137cf565b6001600160a01b0385166000908152600287016020526040902054889061250790836121e9565b10156125255760405162461bcd60e51b815260040161091b9061377e565b505b61253a612532611f97565b858484612ba6565b609c546001600160a01b038981169116141561256557600385015461255f90886121e9565b60038601555b60006001600160a01b038516612579611f97565b6001600160a01b03167f5287a7a1db844ac1b6b020c8496896a86cd70340654083bb1acec1209e9a8c658a6040516125b19190613826565b60405180910390a45050506001600160a01b0316600090815260029091016020526040902054905092915050565b6000804383141561261a57506001600160a01b03808516600090815260996020908152604080832093871683526002909301905220546126c7565b506001600160a01b038085166000908152609960209081526040808320938716835292815282822085835290522054806126c7576001600160a01b038086166000908152609960209081526040808320938816835260019093019052908120612683908561276f565b5090508061269457600091506126c5565b6001600160a01b03808716600090815260996020908152604080832093891683529281528282208483529052205491505b505b949350505050565b6126d7610cc6565b1561271c576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612752611f97565b604080516001600160a01b039092168252519081900360200190a1565b6000808061278785612782866001612013565b612d36565b90508061279b5760008092509250506127bf565b8460018203815481106127aa57fe5b90600052602060002001546001820392509250505b9250929050565b60006127d183611bf5565b6127ed5760405162461bcd60e51b815260040161091b906136cb565b612800836127f9611f97565b3085612dd7565b609c546000906001600160a01b0385811691161461281e5783612842565b609b60008154811061282c57fe5b6000918252602090912001546001600160a01b03165b9050600060996000612852611f97565b6001600160a01b039081168252602080830193909352604091820160009081209186168152600282019093529082205490925061288f9086612013565b6001600160a01b0384166000908152609a6020526040812060020154919250906128b99087612013565b609c549091506001600160a01b03888116911614156128e75760038301546128e19087612013565b60038401555b6128f2612532611f97565b60016001600160a01b038516612906611f97565b6001600160a01b03167f5287a7a1db844ac1b6b020c8496896a86cd70340654083bb1acec1209e9a8c658960405161293e9190613826565b60405180910390a450506001600160a01b03909116600090815260029091016020526040902054905092915050565b600061297830612e31565b15905090565b600054610100900460ff1680612997575061299761296d565b806129a5575060005460ff16155b6129e05760405162461bcd60e51b815260040180806020018281038252602e81526020018061386e602e913960400191505060405180910390fd5b600054610100900460ff16158015612a0b576000805460ff1961ff0019909116610100171660011790555b612a13612e37565b612a1b612ed7565b8015610557576000805461ff001916905550565b600054610100900460ff1680612a485750612a4861296d565b80612a56575060005460ff16155b612a915760405162461bcd60e51b815260040180806020018281038252602e81526020018061386e602e913960400191505060405180910390fd5b600054610100900460ff16158015612abc576000805460ff1961ff0019909116610100171660011790555b612ac4612e37565b612a1b612fd0565b612ad4610cc6565b612b1c576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa612752611f97565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052612ba190849061307b565b505050565b6001600160a01b03808516600090815260996020908152604080832093871680845284835281842043855283528184208790558352600184019091529020541580612c2757506001600160a01b0384166000908152600182016020526040902080544391906000198101908110612c1957fe5b906000526020600020015414155b15612c5a576001600160a01b03841660009081526001808301602090815260408320805492830181558352909120439101555b6001600160a01b03841660008181526002830160209081526040808320879055609a8083528184204385528084529184208790559390925291909152600101541580612cdd57506001600160a01b0384166000908152609a6020526040902060010180544391906000198101908110612ccf57fe5b906000526020600020015414155b15612d11576001600160a01b0384166000908152609a60209081526040822060019081018054918201815583529120439101555b506001600160a01b039092166000908152609a60205260409020600201919091555050565b8154600090612d47575060006107d8565b82546000905b80821015612d96576000612d61838361312c565b905084868281548110612d7057fe5b90600052602060002001541115612d8957809150612d90565b8060010192505b50612d4d565b600082118015612dbe575083856001840381548110612db157fe5b9060005260206000200154145b15612dcf57506000190190506107d8565b5090506107d8565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052611b3390859061307b565b3b151590565b600054610100900460ff1680612e505750612e5061296d565b80612e5e575060005460ff16155b612e995760405162461bcd60e51b815260040180806020018281038252602e81526020018061386e602e913960400191505060405180910390fd5b600054610100900460ff16158015612a1b576000805460ff1961ff0019909116610100171660011790558015610557576000805461ff001916905550565b600054610100900460ff1680612ef05750612ef061296d565b80612efe575060005460ff16155b612f395760405162461bcd60e51b815260040180806020018281038252602e81526020018061386e602e913960400191505060405180910390fd5b600054610100900460ff16158015612f64576000805460ff1961ff0019909116610100171660011790555b6000612f6e611f97565b603380546001600160a01b0319166001600160a01b038316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3508015610557576000805461ff001916905550565b600054610100900460ff1680612fe95750612fe961296d565b80612ff7575060005460ff16155b6130325760405162461bcd60e51b815260040180806020018281038252602e81526020018061386e602e913960400191505060405180910390fd5b600054610100900460ff1615801561305d576000805460ff1961ff0019909116610100171660011790555b6065805460ff191690558015610557576000805461ff001916905550565b60006130d0826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166131519092919063ffffffff16565b805190915015612ba1578080602001905160208110156130ef57600080fd5b5051612ba15760405162461bcd60e51b815260040180806020018281038252602a8152602001806138dd602a913960400191505060405180910390fd5b6000600280830660028506018161313f57fe5b04600283046002850401019392505050565b60606126c784846000858561316585612e31565b6131b6576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b602083106131f45780518252601f1990920191602091820191016131d5565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613256576040519150601f19603f3d011682016040523d82523d6000602084013e61325b565b606091505b509150915061326b828286613276565b979650505050505050565b6060831561328557508161182f565b8251156132955782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156132df5781810151838201526020016132c7565b50505050905090810190601f16801561330c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b80356001600160a01b038116811461088e57600080fd5b600060208284031215613371578081fd5b61182f82613349565b6000806040838503121561338c578081fd5b61339583613349565b91506133a360208401613349565b90509250929050565b600080600080600060a086880312156133c3578081fd5b6133cc86613349565b945060206133db818801613349565b94506040870135935060608701359250608087013567ffffffffffffffff80821115613405578384fd5b818901915089601f830112613418578384fd5b81358181111561342457fe5b8381026040518582820101818110858211171561343d57fe5b604052828152858101935084860182860187018e101561345b578788fd5b8795505b8386101561347d57803585526001959095019493860193860161345f565b508096505050505050509295509295909350565b600080604083850312156134a3578182fd5b6134ac83613349565b946020939093013593505050565b6000806000606084860312156134ce578283fd5b6134d784613349565b9250602084013591506134ec60408501613349565b90509250925092565b600060208284031215613506578081fd5b5035919050565b60006020828403121561351e578081fd5b5051919050565b6000815180845260208085019450808401835b8381101561355d5781516001600160a01b031687529582019590820190600101613538565b509495945050505050565b6000815180845260208085019450808401835b8381101561355d5781518752958201959082019060010161357b565b6001600160a01b0391909116815260200190565b60006020825261182f6020830184613525565b6000606082526135d16060830186613525565b82810360208401526135e38186613568565b915050826040830152949350505050565b602080825282518282018190526000919060409081850190868401855b828110156136555781518051855286810151878601528581015186860152606080820151908601526080908101519085015260a09093019290850190600101613611565b5091979650505050505050565b60006020825261182f6020830184613568565b6000604082526136886040830185613568565b90508260208301529392505050565b901515815260200190565b6020808252600f908201526e1393d7d513d2d15397d5d15251d215608a1b604082015260600190565b6020808252600d908201526c24a72b20a624a22faa27a5a2a760991b604082015260600190565b60208082526015908201527443414e5f4e4f545f57495448445241575f5a45524f60581b604082015260600190565b6020808252600c908201526b5a45524f5f4144445245535360a01b604082015260600190565b6020808252601d908201527f414d4f554e545f455843454544535f5354414b45445f42414c414e4345000000604082015260600190565b602080825260119082015270111053d7d513d2d15394d7d313d0d2d151607a1b604082015260600190565b6020808252600c908201526b53414d455f4144445245535360a01b604082015260600190565b602080825260159082015274111053d7d0531317d513d2d15394d7d313d0d2d151605a1b604082015260600190565b6020808252600e908201526d4558495354535f414c524541445960901b604082015260600190565b90815260200190565b9283526020830191909152151560408201526060019056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a6564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65725361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a26469706673582212205ac1861473ffcce393c2f34b6e12ae8907a30a339c6b740814d6753514fcc98f64736f6c63430007060033

Verified Source Code Full Match

Compiler: v0.7.6+commit.7338295f EVM: istanbul Optimization: Yes (200 runs)
UZV1Staking.sol 831 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
pragma abicoder v2;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import {Arrays} from "@openzeppelin/contracts/utils/Arrays.sol";

import {IUZV1Staking} from "./interfaces/IUZV1Staking.sol";
import {IUZV1DAO} from "./interfaces/dao/IUZV1DAO.sol";

import {UZV1ProAccess} from "./membership/UZV1ProAccess.sol";
import {SharedDataTypes} from "./libraries/SharedDataTypes.sol";

/**
 * @title UnizenStaking
 * @author Unizen
 * @notice Unizen staking contract V1 that keeps track of stakes and TVL
 **/
contract UZV1Staking is IUZV1Staking, UZV1ProAccess {
    using SafeMath for uint256;
    /* === STATE VARIABLES === */
    // dao contract
    IUZV1DAO public dao;

    // storage of user stakes
    mapping(address => SharedDataTypes.StakerUser) public stakerUsers;

    // stakeable tokens data
    mapping(address => SharedDataTypes.StakeableToken) public stakeableTokens;

    // all whitelisted tokens
    address[] public activeTokens;

    // zcxht token address
    address public zcxht;

    // combined weight of all active tokens
    // stored to prevent recalculations of the weight
    // for every pool update
    uint256 public combinedTokenWeight;

    function initialize(
        address _zcx,
        uint256 _zcxTokenWeight,
        address _accessToken
    ) public initializer {
        UZV1ProAccess.initialize(_accessToken);
        // setup first stakeable token
        SharedDataTypes.StakeableToken storage _token = stakeableTokens[_zcx];

        // set token data
        _token.weight = _zcxTokenWeight;
        _token.active = true;

        // add token to active list
        activeTokens.push(_zcx);

        // setup helpers for token weight
        combinedTokenWeight = _zcxTokenWeight;
    }

    /* === VIEW FUNCTIONS === */

    /**
     * @dev Helper function to get the current TVL
     *
     * @return array with amounts staked on this contract
     **/
    function getTVLs() external view override returns (uint256[] memory) {
        return getTVLs(block.number);
    }

    /**
     * @dev Helper function to get the TVL on a block.number
     *
     * @return array with amounts staked on this contract
     **/
    function getTVLs(uint256 _blocknumber)
        public
        view
        override
        returns (uint256[] memory)
    {
        uint256[] memory _tvl = new uint256[](activeTokens.length);
        for (uint8 i = 0; i < activeTokens.length; i++) {
            _tvl[i] = _getTVL(_blocknumber, activeTokens[i]);
        }
        return _tvl;
    }

    function _getTVL(uint256 _blocknumber, address _token)
        internal
        view
        returns (uint256)
    {
        uint256 _tvl;
        if (_blocknumber == block.number) {
            // if blocknumber is current block number, we return the last saved TVL
            _tvl = stakeableTokens[_token].totalValueLocked;
        } else {
            _tvl = stakeableTokens[_token].totalValueLockedSnapshots[
                _blocknumber
            ];
            // if we don't find a TVL snapshot, we search in the snapshot array
            if (_tvl == 0) {
                (uint256 _lastSavedBlock, ) = _findLastSavedBlock(
                    stakeableTokens[_token].totalValueLockedKeys,
                    _blocknumber
                );
                if (_lastSavedBlock == 0) {
                    _tvl = 0;
                } else {
                    _tvl = stakeableTokens[_token].totalValueLockedSnapshots[
                        _lastSavedBlock
                    ];
                }
            }
        }
        return _tvl;
    }

    /**
     * @dev used to calculate the users stake of the pool
     * @param _user optional user addres, if empty the sender will be used
     * @param _precision optional denominator, default to 3
     *
     * @return array with the percentage stakes of the user based on TVL of each allowed token
     *  [
     *   weightedAverage,
     *   shareOfUtilityToken,
     *   ShareOfLPToken...
     *  ]
     *
     **/
    function getUserTVLShare(address _user, uint256 _precision)
        external
        view
        override
        returns (uint256[] memory)
    {
        // precision is 3 by default
        if (_precision == 0) {
            _precision = 3;
        }

        // default to sender if no user is specified
        if (_user == address(0)) {
            _user = _msgSender();
        }

        uint256 _denominator = 10**(_precision.add(2));

        // for precision rounding
        _denominator = _denominator.mul(10);

        uint256[] memory _shares = new uint256[](activeTokens.length + 1);

        uint256 _sumWeight = 0;
        uint256 _sumShares = 0;

        for (uint256 i = 0; i < activeTokens.length; i++) {
            // calculate users percentage stakes
            uint256 _tokenShare;
            if (stakeableTokens[activeTokens[i]].totalValueLocked > 0) {
                _tokenShare = stakerUsers[_user]
                    .stakedAmount[activeTokens[i]]
                    .mul(_denominator)
                    .div(stakeableTokens[activeTokens[i]].totalValueLocked);
            }

            // check current weight of token
            uint256 _tokenWeight = stakeableTokens[activeTokens[i]].weight;
            // add current token weight to weight sum
            _sumWeight = _sumWeight.add(_tokenWeight);
            // add users current token share to share sum
            _sumShares = _sumShares.add(_tokenShare.mul(_tokenWeight));
            // add users percentage stakes of current token, including precision rounding
            _shares[i + 1] = _tokenShare.add(5).div(10);
        }

        // calculate final weighted average of user stakes
        _shares[0] = _sumShares.div(_sumWeight).add(5).div(10);

        return _shares;
    }

    /**
     * @dev Helper function to get the staked token amount
     *
     * @return uint256 staked amount of token
     **/
    function getUsersStakedAmountOfToken(address _user, address _token)
        external
        view
        override
        returns (uint256)
    {
        if (_token == zcxht) {
            return stakerUsers[_user].zcxhtStakedAmount;
        } else {
            return stakerUsers[_user].stakedAmount[_token];
        }
    }

    /**
     * @dev Helper function to fetch all existing data to an address
     *
     * @return array of token addresses
     * @return array of users staked amount for each token
     * @return ZCXHT staked amount
     **/
    function getUserData(address _user)
        external
        view
        override
        returns (
            address[] memory,
            uint256[] memory,
            uint256
        )
    {
        // init temporary array with token count
        uint256[] memory _userStakes = new uint256[](activeTokens.length);

        // loop through all known tokens
        for (uint8 i = 0; i < activeTokens.length; i++) {
            // get user stakes for active token
            _userStakes[i] = stakerUsers[_user].stakedAmount[activeTokens[i]];
        }

        // return active token stakes
        return (
            activeTokens,
            _userStakes,
            stakerUsers[_user].zcxhtStakedAmount
        );
    }

    /**
     * @dev Creates a list of active tokens, excluding inactive tokens
     *
     * @return address[] array of active stakeable token tokens
     **/
    function getActiveTokens() public view override returns (address[] memory) {
        return activeTokens;
    }

    /**
     * @dev Creates a list of active token weights, excluding inactive tokens
     *
     * @return weights uint256[] array including every active token weight
     * @return combinedWeight uint256 combined weight of all active tokens
     **/
    function getTokenWeights()
        external
        view
        override
        returns (uint256[] memory weights, uint256 combinedWeight)
    {
        // create new memory array at the size of the current token count
        weights = new uint256[](activeTokens.length);
        combinedWeight = combinedTokenWeight;
        // loop through maximum amount of allowed tokens
        for (uint8 i = 0; i < activeTokens.length; i++) {
            // add token to active token list
            weights[i] = stakeableTokens[activeTokens[i]].weight;
        }
    }

    /**
     * @dev  Returns all block number snapshots for an specific user and token
     *
     * @param _user Address of the user
     * @param _token Address of the token
     * @param _startBlock Start block to search for snapshots
     * @param _endBlock End block to search for snapshots
     * @param _claimedBlocks Array of block numbers when the user has claimed
     *
     * @return snapshots snapshoted data grouped by stakes
     **/
    function getUserStakesSnapshots(
        address _user,
        address _token,
        uint256 _startBlock,
        uint256 _endBlock,
        uint256[] memory _claimedBlocks
    )
        external
        view
        override
        returns (SharedDataTypes.StakeSnapshot[] memory snapshots)
    {
        (, uint256 _index) = _findLastSavedBlock(
            stakerUsers[_user].stakedAmountKeys[_token],
            _startBlock
        );

        // read how many snapshots fits in the current startBlock-endBlok period
        uint256 numSnapshots;
        for (
            uint256 i = _index;
            i < stakerUsers[_user].stakedAmountKeys[_token].length &&
                stakerUsers[_user].stakedAmountKeys[_token][i] <= _endBlock;
            i++
        ) {
            numSnapshots++;
        }
        for (uint256 i = 0; i < _claimedBlocks.length; i++) {
            // If the claimed block is inside the period to be calculated...
            if (_claimedBlocks[i] <= _endBlock) {
                numSnapshots++;
            }
        }

        // create the snapshot array
        SharedDataTypes.StakeSnapshot[]
            memory _snapshot = new SharedDataTypes.StakeSnapshot[](
                numSnapshots
            );

        // Add bookmarks for every tranche
        uint256 _iStaked = _index;
        uint256 _iClaimed = 0;
        for (uint256 i = 0; i < _snapshot.length; i++) {
            // calculate start block from stakes
            uint256 _snapshotStakedBlock = (_iStaked <
                stakerUsers[_user].stakedAmountKeys[_token].length &&
                stakerUsers[_user].stakedAmountKeys[_token][_iStaked] <=
                _endBlock)
                ? stakerUsers[_user].stakedAmountKeys[_token][_iStaked]
                : 0;
            uint256 _startSnapshotBlock = (_snapshotStakedBlock > 0 &&
                _snapshotStakedBlock < _startBlock)
                ? _startBlock
                : _snapshotStakedBlock;
            // calculate start block from claims
            uint256 _claimedBlock = (_iClaimed < _claimedBlocks.length)
                ? _claimedBlocks[_iClaimed]
                : 0;
            if (
                (_startSnapshotBlock != 0 &&
                    _startSnapshotBlock <= _claimedBlock) || _claimedBlock == 0
            ) {
                _snapshot[i].startBlock = _startSnapshotBlock;
                _iStaked = _iStaked.add(1);
            } else {
                _snapshot[i].startBlock = _claimedBlock;
                _iClaimed = _iClaimed.add(1);
            }
        }

        // repeat the iteration to calculate endBlock and tokenTVL
        for (uint256 i = 0; i < _snapshot.length; i++) {
            // If this is the last snapshoted block, we get the last reward
            // block. Else, we get the next initial block minus 1
            _snapshot[i].endBlock = (i == numSnapshots.sub(1))
                ? _endBlock
                : _snapshot[i.add(1)].startBlock.sub(1);
            // read staked amount
            _snapshot[i].stakedAmount = _getUserStakeForToken(
                _user,
                _token,
                _snapshot[i].startBlock
            );
            // We read the token TVL at first and last block of this snapshot
            _snapshot[i].startTVL = _getTVL(_snapshot[i].startBlock, _token);
            _snapshot[i].endTVL = _getTVL(_snapshot[i].endBlock, _token);
        }

        return _snapshot;
    }

    /**
     * @dev Helper function to get the current staked tokens of a user
     *
     * @return uint256[] array with amounts for every stakeable token
     **/
    function getUserStakes(address _user)
        external
        view
        override
        returns (uint256[] memory)
    {
        return getUserStakes(_user, block.number);
    }

    /**
     * @dev Helper function to get the staked tokens of a user on a block.number
     *
     * @return uint256[] array with amounts for every stakeable token
     **/
    function getUserStakes(address _user, uint256 _blocknumber)
        public
        view
        override
        returns (uint256[] memory)
    {
        // create in memory array with the size of existing active tokens
        uint256[] memory _userStakes = new uint256[](activeTokens.length);

        // loop through active tokens
        for (uint8 i = 0; i < activeTokens.length; i++) {
            // get user stakes for active token
            _userStakes[i] = _getUserStakeForToken(
                _user,
                activeTokens[i],
                _blocknumber
            );
        }

        // return the data
        return _userStakes;
    }

    /**
     * @dev Get the staked amount of a certain token on a block.number
     *
     * @return _stakedAmount amount of staked amount
     **/
    function _getUserStakeForToken(
        address _user,
        address _token,
        uint256 _blocknumber
    ) internal view returns (uint256) {
        uint256 _stakedAmount;
        if (_blocknumber == block.number) {
            // if blocknumber is current block number, we return the last saved staked amount
            _stakedAmount = stakerUsers[_user].stakedAmount[_token];
        } else {
            _stakedAmount = stakerUsers[_user].stakedAmountSnapshots[_token][
                _blocknumber
            ];
            // if we don't find a staked amount snapshot, we search in the snapshot array
            if (_stakedAmount == 0) {
                (uint256 _lastSavedBlock, ) = _findLastSavedBlock(
                    stakerUsers[_user].stakedAmountKeys[_token],
                    _blocknumber
                );
                if (_lastSavedBlock == 0) {
                    _stakedAmount = 0;
                } else {
                    _stakedAmount = stakerUsers[_user].stakedAmountSnapshots[
                        _token
                    ][_lastSavedBlock];
                }
            }
        }
        return _stakedAmount;
    }

    /* === MUTATING FUNCTIONS === */

    /**
     * @dev  Convenience function to stake zcx token
     * @param _amount Amount of tokens the user wants to stake
     *
     * @return the new amount of tokens staked
     **/
    function stake(uint256 _amount)
        external
        override
        whenNotPaused
        returns (uint256)
    {
        return _stake(activeTokens[0], _amount);
    }

    /**
     * @dev  Convenience function to stake lp token
     * @param _lpToken Address of token to stake
     * @param _amount Amount of tokens the user wants to stake
     *
     * @return the new amount of tokens staked
     **/
    function stake(address _lpToken, uint256 _amount)
        external
        override
        whenNotPaused
        returns (uint256)
    {
        return _stake(_lpToken, _amount);
    }

    /**
     * @dev  This allows users to actually add tokens to the staking pool
     *       and take part
     * @param _token Address of token to stake
     * @param _amount Amount of tokens the user wants to stake
     *
     * @return the new amount of tokens staked
     **/
    function _stake(address _token, uint256 _amount)
        internal
        returns (uint256)
    {
        require(isAllowedToken(_token), "INVALID_TOKEN");
        // transfer tokens
        SafeERC20.safeTransferFrom(
            IERC20(_token),
            _msgSender(),
            address(this),
            _amount
        );

        address _stakeToken = (_token == zcxht) ? activeTokens[0] : _token; // if stake zcxht, equal to stake zcx

        // get current user data
        SharedDataTypes.StakerUser storage _stakerUser = stakerUsers[
            _msgSender()
        ];

        // calculate new amount of user stakes
        uint256 _newStakedAmount = _stakerUser.stakedAmount[_stakeToken].add(
            _amount
        );

        uint256 _newTVL = stakeableTokens[_stakeToken].totalValueLocked.add(
            _amount
        );

        // check if holder token is staked
        if (_token == zcxht) {
            _stakerUser.zcxhtStakedAmount = _stakerUser.zcxhtStakedAmount.add(
                _amount
            );
        }

        _saveStakeInformation(
            _msgSender(),
            _stakeToken,
            _newStakedAmount,
            _newTVL
        );

        // shoot event
        emit TVLChange(_msgSender(), _stakeToken, _amount, true);

        // return users new holdings of token
        return _stakerUser.stakedAmount[_stakeToken];
    }

    /**
     * @dev  Convenience function to withdraw utility token
     * @param _amount optional value, if empty the total user stake will be used
     **/
    function withdraw(uint256 _amount)
        external
        override
        whenNotPaused
        returns (uint256)
    {
        return _withdraw(activeTokens[0], _amount);
    }

    /**
     * @dev  Convenience function to withdraw LP tokens
     * @param _lpToken Address of token to withdraw
     * @param _amount optional value, if empty the total user stake will be used
     **/
    function withdraw(address _lpToken, uint256 _amount)
        external
        override
        whenNotPaused
        returns (uint256)
    {
        return _withdraw(_lpToken, _amount);
    }

    /**
     * @dev  This allows users to unstake their tokens at any point of time
     *       and also leaves it open to the users how much will be unstaked
     * @param _token Address of token to withdraw
     * @param _amount optional value, if empty the total user stake will be used
     **/
    function _withdraw(address _token, uint256 _amount)
        internal
        returns (uint256)
    {
        require(_amount > 0, "CAN_NOT_WITHDRAW_ZERO");
        SharedDataTypes.StakerUser storage _stakerUser = stakerUsers[
            _msgSender()
        ];
        address _stakeToken = _token;
        uint256 _maxWithdrawable;
        if (_stakeToken == zcxht) {
            _stakeToken = activeTokens[0];
            _maxWithdrawable = _stakerUser.zcxhtStakedAmount;
        } else if (_stakeToken == activeTokens[0]) {
            _maxWithdrawable = _stakerUser.stakedAmount[_stakeToken].sub(
                _stakerUser.zcxhtStakedAmount
            );
        } else {
            _maxWithdrawable = _stakerUser.stakedAmount[_stakeToken];
        }
        require(_maxWithdrawable >= _amount, "AMOUNT_EXCEEDS_STAKED_BALANCE");
        SafeERC20.safeTransfer(IERC20(_token), _msgSender(), _amount); // calculate the new user stakes of the token
        uint256 _newStakedAmount = _stakerUser.stakedAmount[_stakeToken].sub(
            _amount
        );
        uint256 _newTVL = stakeableTokens[_stakeToken].totalValueLocked.sub(
            _amount
        );

        // DAO check, if available. Only applies to utility token withdrawals
        if (address(dao) != address(0) && _stakeToken == activeTokens[0]) {
            // get locked tokens of user (active votes)
            uint256 _lockedTokens = dao.getLockedTokenCount(_msgSender());
            // check that the user has enough unlocked tokens
            require(
                _stakerUser.stakedAmount[_stakeToken] >= _lockedTokens,
                "DAO_ALL_TOKENS_LOCKED"
            );
            require(
                _stakerUser.stakedAmount[_stakeToken].sub(_lockedTokens) >=
                    _amount,
                "DAO_TOKENS_LOCKED"
            );
        }

        _saveStakeInformation(
            _msgSender(),
            _stakeToken,
            _newStakedAmount,
            _newTVL
        );

        // check if holder token is withdrawn
        if (_token == zcxht) {
            _stakerUser.zcxhtStakedAmount = _stakerUser.zcxhtStakedAmount.sub(
                _amount
            );
        }
        // shoot event
        emit TVLChange(_msgSender(), _stakeToken, _amount, false);

        return _stakerUser.stakedAmount[_stakeToken];
    }

    /**
     * @dev  Checks if the token is whitelisted and active
     * @param _token address of token to check
     * @return bool Active status of checked token
     **/
    function isAllowedToken(address _token) public view returns (bool) {
        if (_token == address(0)) return false;
        return stakeableTokens[_token].active || _token == zcxht;
    }

    /**
     * @dev  Allows updating the utility token address that can be staked, in case
     *       of a token swap or similar event.
     * @param _token Address of new ERC20 token address
     **/
    function updateStakeToken(address _token) external onlyOwner {
        require(activeTokens[0] != _token, "SAME_ADDRESS");
        // deactive the old token
        stakeableTokens[activeTokens[0]].active = false;
        // cache the old weight
        uint256 weight = stakeableTokens[activeTokens[0]].weight;
        // assign the new address
        activeTokens[0] = _token;
        // update new token data with old settings
        stakeableTokens[activeTokens[0]].weight = weight;
        stakeableTokens[activeTokens[0]].active = true;
    }

    /**
     * @dev  Adds new token to whitelist
     * @param _token Address of new token
     * @param _weight Weight of new token
     **/
    function addToken(address _token, uint256 _weight) external onlyOwner {
        require(_token != address(0), "ZERO_ADDRESS");
        require(isAllowedToken(_token) == false, "EXISTS_ALREADY");

        // add token address to active token list
        activeTokens.push(_token);

        // set token weight
        stakeableTokens[_token].weight = _weight;
        // set token active
        stakeableTokens[_token].active = true;

        // add token weight to maximum weight helper
        combinedTokenWeight = combinedTokenWeight.add(_weight);
    }

    /**
     * @dev  Removes token from whitelist, if no tokens are locked
     * @param _token Address of token to remove
     **/
    function removeToken(address _token) external onlyOwner {
        require(isAllowedToken(_token) == true, "INVALID_TOKEN");
        require(stakeableTokens[_token].active, "INVALID_TOKEN");

        // get token index
        uint256 _idx;
        for (uint256 i = 0; i < activeTokens.length; i++) {
            if (activeTokens[i] == _token) {
                _idx = i;
            }
        }

        // remove token weight from maximum weight helper
        combinedTokenWeight = combinedTokenWeight.sub(
            stakeableTokens[_token].weight
        );

        // reset token weight
        stakeableTokens[_token].weight = 0;

        // remove from active tokens list
        activeTokens[_idx] = activeTokens[activeTokens.length - 1];
        activeTokens.pop();
        // set token inactive
        stakeableTokens[_token].active = false;
    }

    function setHolderToken(address _zcxht) external onlyOwner {
        require(zcxht != _zcxht, "SAME_ADDRESS");
        zcxht = _zcxht;
    }

    /**
     * @dev  Allows to update the weight of a specific token
     * @param _token Address of the token
     * @param _newWeight new token weight
     **/
    function updateTokenWeight(address _token, uint256 _newWeight)
        external
        onlyOwner
    {
        require(_token != address(0), "ZERO_ADDRESS");
        require(_newWeight > 0, "NO_TOKEN_WEIGHT");
        // update token weight
        combinedTokenWeight = combinedTokenWeight
            .sub(stakeableTokens[_token].weight)
            .add(_newWeight);
        stakeableTokens[_token].weight = _newWeight;
    }

    /**
     * @dev  Allows updating the dao address, in case of an upgrade.
     * @param _newDAO Address of the new Unizen DAO contract
     **/
    function updateDAO(address _newDAO) external onlyOwner {
        require(address(dao) != _newDAO, "SAME_ADDRESS");
        dao = IUZV1DAO(_newDAO);
    }

    /* === INTERNAL FUNCTIONS === */

    /**
     * @dev Save staking information after stake or withdraw and make an
     * sanapshot
     *
     * @param _user user that makes the stake/withdraw
     * @param _token token where the stake/withdraw has been made
     * @param _newStakedAmount staked/withdrawn amount of tokens
     * @param _newTVL TVL of the token after the stake/withdraw
     */
    function _saveStakeInformation(
        address _user,
        address _token,
        uint256 _newStakedAmount,
        uint256 _newTVL
    ) internal {
        SharedDataTypes.StakerUser storage _stakerUser = stakerUsers[_user];

        // updated total stake of current user
        _stakerUser.stakedAmountSnapshots[_token][
            block.number
        ] = _newStakedAmount;
        if (
            (_stakerUser.stakedAmountKeys[_token].length == 0) ||
            _stakerUser.stakedAmountKeys[_token][
                _stakerUser.stakedAmountKeys[_token].length - 1
            ] !=
            block.number
        ) {
            _stakerUser.stakedAmountKeys[_token].push(block.number);
        }
        _stakerUser.stakedAmount[_token] = _newStakedAmount;

        // update tvl of token
        stakeableTokens[_token].totalValueLockedSnapshots[
            block.number
        ] = _newTVL;
        if (
            (stakeableTokens[_token].totalValueLockedKeys.length == 0) ||
            stakeableTokens[_token].totalValueLockedKeys[
                stakeableTokens[_token].totalValueLockedKeys.length - 1
            ] !=
            block.number
        ) {
            stakeableTokens[_token].totalValueLockedKeys.push(block.number);
        }
        stakeableTokens[_token].totalValueLocked = _newTVL;
    }

    /**
     * @dev Helper function to get the last saved block number in a block index array
     *
     * @return lastSavedBlock last block number stored in the block index array
     * @return index index of the last block number stored in the block index array
     **/
    function _findLastSavedBlock(
        uint256[] storage _blockKeys,
        uint256 _blockNumber
    ) internal view returns (uint256 lastSavedBlock, uint256 index) {
        uint256 _upperBound = Arrays.findUpperBound(
            _blockKeys,
            _blockNumber.add(1)
        );
        if (_upperBound == 0) {
            return (0, 0);
        } else {
            return (_blockKeys[_upperBound - 1], _upperBound - 1);
        }
    }

    /* === EVENTS === */
    event TVLChange(
        address indexed user,
        address indexed token,
        uint256 amount,
        bool indexed changeType
    );
}
Math.sol 31 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
}
IUZV1Staking.sol 72 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
pragma abicoder v2;

import {SharedDataTypes} from "../libraries/SharedDataTypes.sol";

interface IUZV1Staking {
    /* view functions */
    function getTVLs() external view returns (uint256[] memory);

    function getTVLs(uint256 _blocknumber)
        external
        view
        returns (uint256[] memory);

    function getUserTVLShare(address _user, uint256 _precision)
        external
        view
        returns (uint256[] memory);

    function getUsersStakedAmountOfToken(address _user, address _token)
        external
        view
        returns (uint256);

    function getUserData(address _user)
        external
        view
        returns (
            address[] memory,
            uint256[] memory,
            uint256
        );

    function getActiveTokens() external view returns (address[] memory);

    function getTokenWeights()
        external
        view
        returns (uint256[] memory weights, uint256 combinedWeight);

    function getUserStakesSnapshots(
        address _user,
        address _token,
        uint256 _startBlock,
        uint256 _endBlock,
        uint256[] memory _claimedBlocks
    ) external view returns (SharedDataTypes.StakeSnapshot[] memory snapshots);

    function getUserStakes(address _user)
        external
        view
        returns (uint256[] memory);

    function getUserStakes(address _user, uint256 _blocknumber)
        external
        view
        returns (uint256[] memory);

    /* mutating functions */
    function stake(uint256 _amount) external returns (uint256);

    function stake(address _lpToken, uint256 _amount)
        external
        returns (uint256);

    function withdraw(uint256 _amount) external returns (uint256);

    function withdraw(address _lpToken, uint256 _amount)
        external
        returns (uint256);
}
IUZV1DAO.sol 7 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;

interface IUZV1DAO {
    /* view functions */
    function getLockedTokenCount(address _user) external returns (uint256);
}
UZV1ProAccess.sol 88 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
pragma abicoder v2;

import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";

/**
 * @title UZProAccess
 * @author Unizen
 * @notice Simple abstract class to add easy checks
 * for pro membership access token
 **/
abstract contract UZV1ProAccess is
    Initializable,
    OwnableUpgradeable,
    PausableUpgradeable
{
    // internal storage of the erc721 token
    IERC721 internal _membershipToken;

    function initialize(address _token) public virtual initializer {
        __Ownable_init();
        __Pausable_init();
        _setMembershipToken(_token);
    }

    function membershipToken() public view returns (address) {
        return address(_membershipToken);
    }

    /* === CONTROL FUNCTIONS === */
    /**
     * @dev pause smart contract
     */
    function pause() public onlyOwner {
        _pause();
    }

    /**
     * @dev unpause smart contract
     */
    function unPause() public onlyOwner {
        _unpause();
    }

    /**
     * @dev  Allows the owner of the contract, to update
     * the used membership token
     * @param _newToken address of the new erc721 token
     **/
    function setMembershipToken(address _newToken) public onlyOwner {
        _setMembershipToken(_newToken);
    }

    function _setMembershipToken(address _newToken) internal {
        if (_newToken == address(0) && address(_membershipToken) == address(0))
            return;

        require(_newToken != address(_membershipToken), "SAME_ADDRESS");
        _membershipToken = IERC721(_newToken);
    }

    /**
     * @dev  Internal function that checks if the users has any
     * membership tokens. Reverts, if none is found.
     * @param _user address of user to check
     **/
    function _checkPro(address _user) internal view {
        if (address(_membershipToken) != address(0)) {
            require(
                _membershipToken.balanceOf(_user) > 0,
                "FORBIDDEN: PRO_MEMBER"
            );
        }
    }

    /* === MODIFIERS === */
    modifier onlyPro(address _user) {
        _checkPro(_user);
        _;
    }

    /* === EVENTS === */
    event MembershipTokenUpdated(address _newTokenAddress);
}
SharedDataTypes.sol 152 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;

library SharedDataTypes {
    // struct for returning snapshot values
    struct StakeSnapshot {
        // initial block number snapshoted
        uint256 startBlock;
        // end block number snapshoted
        uint256 endBlock;
        // staked amount at initial block
        uint256 stakedAmount;
        // total value locked at start block
        uint256 startTVL;
        // total value locked at end block
        uint256 endTVL;
    }

    // general staker user information
    struct StakerUser {
        // snapshotted stakes of the user per token (token => block.number => stakedAmount)
        mapping(address => mapping(uint256 => uint256)) stakedAmountSnapshots;
        // snapshotted stakes of the user per token keys (token => block.number[])
        mapping(address => uint256[]) stakedAmountKeys;
        // current stakes of the user per token
        mapping(address => uint256) stakedAmount;
        // total amount of holder tokens
        uint256 zcxhtStakedAmount;
    }

    // information for stakeable tokens
    struct StakeableToken {
        // snapshotted total value locked (TVL) (block.number => totalValueLocked)
        mapping(uint256 => uint256) totalValueLockedSnapshots;
        // snapshotted total value locked (TVL) keys (block.number[])
        uint256[] totalValueLockedKeys;
        // current total value locked (TVL)
        uint256 totalValueLocked;
        uint256 weight;
        bool active;
    }

    // POOL DATA

    // data object for a user stake on a pool
    struct PoolStakerUser {
        // saved / withdrawn rewards of user
        uint256 totalSavedRewards;
        // total purchased allocation
        uint256 totalPurchasedAllocation;
        // native address, if necessary
        string nativeAddress;
        // date/time when user has claimed (paid in incubator pools) the reward
        uint256 claimedTime;
        // blocks where the user has claimed the rewards
        uint256[] claimedBlocks;
    }

    // flat data type of stake for UI
    struct FlatPoolStakerUser {
        address[] tokens;
        uint256[] amounts;
        uint256 pendingRewards;
        uint256 totalPurchasedAllocation;
        uint256 totalSavedRewards;
        uint256 claimedTime;
        PoolState state;
        UserPoolState userState;
    }

    // UI information for pool
    // data will be fetched via github token repository
    // blockchain / cAddress being the most relevant values
    // for fetching the correct token data
    struct PoolInfo {
        // token name
        string name;
        // name of blockchain, as written on github
        string blockchain;
        // tokens contract address on chain
        string cAddress;
    }

    // possible states of the reward pool
    enum PoolState {
        pendingStaking,
        staking,
        pendingPayment,
        payment,
        pendingDistribution,
        distribution,
        retired
    }

    // possible states of the reward pool's user
    enum UserPoolState {
        notclaimed,
        claimed,
        rejected,
        missed
    }

    // input data for new reward pools
    struct PoolInputData {
        // total rewards to distribute
        uint256 totalRewards;
        // start block for distribution
        uint256 startBlock;
        // end block for distribution
        uint256 endBlock;
        // erc token address
        address token;
        // pool type
        uint8 poolType;
        // information about the reward token
        PoolInfo tokenInfo;
    }

    struct PoolData {
        PoolState state;
        // pool information for the ui
        PoolInfo info;
        // start block of staking rewards
        uint256 startBlock;
        // end block of staking rewards
        uint256 endBlock;
        // start block of payment period
        uint256 paymentStartBlock;
        // end block of payment period
        uint256 paymentEndBlock;
        // start block of distribution period
        uint256 distributionStartBlock;
        // end block of distribution period
        uint256 distributionEndBlock;
        // total rewards for allocation
        uint256 totalRewards;
        // rewards per block
        uint256 rewardsPerBlock;
        // price of a single payment token
        uint256 rewardTokenPrice;
        // type of the pool
        uint8 poolType;
        // address of payment token
        address paymentToken;
        // address of reward token
        address token;
        // total remaining rewards for allocation (claimed or not claimed)
        // uint256 remainingRewards;
        // total open rewards for allocation (rewards not claimed)
        // uint256 openRewards;
    }
}
Arrays.sol 47 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../math/Math.sol";

/**
 * @dev Collection of functions related to array types.
 */
library Arrays {
   /**
     * @dev Searches a sorted `array` and returns the first index that contains
     * a value greater or equal to `element`. If no such index exists (i.e. all
     * values in the array are strictly less than `element`), the array length is
     * returned. Time complexity O(log n).
     *
     * `array` is expected to be sorted in ascending order, and to contain no
     * repeated elements.
     */
    function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
        if (array.length == 0) {
            return 0;
        }

        uint256 low = 0;
        uint256 high = array.length;

        while (low < high) {
            uint256 mid = Math.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds down (it does integer division with truncation).
            if (array[mid] > element) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
        if (low > 0 && array[low - 1] == element) {
            return low - 1;
        } else {
            return low;
        }
    }
}
SafeMath.sol 214 lines
// 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, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0);
        uint256 c = a * b;
        if (c / a != b) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    /**
     * @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) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    /**
     * @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) {
        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, reverting 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) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting 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) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * 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);
        return a - b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * 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);
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * 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;
    }
}
Address.sol 189 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain`call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
      return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
IERC20.sol 77 lines
// 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);
}
IERC721.sol 129 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

import "../../introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);

    /**
      * @dev Safely transfers `tokenId` token from `from` to `to`.
      *
      * Requirements:
      *
      * - `from` cannot be the zero address.
      * - `to` cannot be the zero address.
      * - `tokenId` token must exist and be owned by `from`.
      * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
      * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
      *
      * Emits a {Transfer} event.
      */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
IERC165.sol 24 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
SafeERC20.sol 75 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using SafeMath for uint256;
    using Address for address;

    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        // solhint-disable-next-line max-line-length
        require((value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).add(value);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) { // Return data is optional
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
Initializable.sol 55 lines
// SPDX-License-Identifier: MIT

// solhint-disable-next-line compiler-version
pragma solidity >=0.4.24 <0.8.0;

import "../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 */
abstract contract Initializable {

    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /// @dev Returns true if and only if the function is running in the constructor
    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}
AddressUpgradeable.sol 165 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain`call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
      return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
ContextUpgradeable.sol 32 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
import "../proxy/Initializable.sol";

/*
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal initializer {
        __Context_init_unchained();
    }

    function __Context_init_unchained() internal initializer {
    }
    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;
    }
    uint256[50] private __gap;
}
OwnableUpgradeable.sol 75 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.sol";
/**
 * @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.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * 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.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal initializer {
        __Context_init_unchained();
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal initializer {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the 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 virtual 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 virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
    uint256[49] private __gap;
}
PausableUpgradeable.sol 97 lines
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./ContextUpgradeable.sol";
import "../proxy/Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal initializer {
        __Context_init_unchained();
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal initializer {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
    uint256[49] private __gap;
}

Read Contract

activeTokens 0x9f224f35 → address
combinedTokenWeight 0xe97020d5 → uint256
dao 0x4162169f → address
getActiveTokens 0x5f5817e3 → address[]
getTVLs 0x159cbb7c → uint256[]
getTVLs 0x27a51639 → uint256[]
getTokenWeights 0x32bfe469 → uint256[], uint256
getUserData 0xffc9896b → address[], uint256[], uint256
getUserStakes 0x419bc8ad → uint256[]
getUserStakes 0x842e2981 → uint256[]
getUserStakesSnapshots 0x8af827fc → tuple[]
getUserTVLShare 0x14f63f07 → uint256[]
getUsersStakedAmountOfToken 0x45efe2e6 → uint256
isAllowedToken 0xcbe230c3 → bool
membershipToken 0x62ad351b → address
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
stakeableTokens 0xac92020d → uint256, uint256, bool
stakerUsers 0xd4307547 → uint256
zcxht 0x682ed99d → address

Write Contract 17 functions

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

addToken 0xaf81c5b9
address _token
uint256 _weight
initialize 0xc350a1b5
address _zcx
uint256 _zcxTokenWeight
address _accessToken
initialize 0xc4d66de8
address _token
pause 0x8456cb59
No parameters
removeToken 0x5fa7b584
address _token
renounceOwnership 0x715018a6
No parameters
setHolderToken 0x331a42e6
address _zcxht
setMembershipToken 0x034f6436
address _newToken
stake 0xa694fc3a
uint256 _amount
returns: uint256
stake 0xadc9772e
address _lpToken
uint256 _amount
returns: uint256
transferOwnership 0xf2fde38b
address newOwner
unPause 0xf7b188a5
No parameters
updateDAO 0xbcb6c0b5
address _newDAO
updateStakeToken 0x60428289
address _token
updateTokenWeight 0x21faf184
address _token
uint256 _newWeight
withdraw 0x2e1a7d4d
uint256 _amount
returns: uint256
withdraw 0xf3fef3a3
address _lpToken
uint256 _amount
returns: uint256

Recent Transactions

No transactions found for this address