Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x74641ed232dbB8CBD9847484dD020d44453F0368
Balance 0 ETH
Nonce 1
Code Size 9361 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

9361 bytes
0x608060405234801561001057600080fd5b506004361061014d5760003560e01c80638bd85c44116100c3578063c8aea2471161007c578063c8aea24714610463578063e737b86e146104da578063eb321173146104e2578063f2fde38b146104ea578063f7fecc2714610510578063fc0c546a146105685761014d565b80638bd85c441461039c5780638da5cb5b146103a4578063ac7475ed146103ac578063b2eaeaaa146103d2578063bec3aa75146103f8578063c3453153146104155761014d565b806348bba3091161011557806348bba309146102105780634d028c27146102d957806350baa6221461031f5780635a8a17341461033c578063715018a61461034457806388a0c9291461034c5761014d565b80631c0676671461015257806325d5971f1461018f57806327e235e3146101ac5780632ad77f8f146101e457806341d4a1ab146101ec575b600080fd5b61018d600480360360c081101561016857600080fd5b5080359060208101359060408101359060608101359060808101359060a00135610570565b005b61018d600480360360208110156101a557600080fd5b50356107c7565b6101d2600480360360208110156101c257600080fd5b50356001600160a01b0316610b8e565b60408051918252519081900360200190f35b6101d2610ba0565b6101f4610ba6565b604080516001600160a01b039092168252519081900360200190f35b61018d6004803603606081101561022657600080fd5b8135919081019060408101602082013564010000000081111561024857600080fd5b82018360208201111561025a57600080fd5b8035906020019184602083028401116401000000008311171561027c57600080fd5b91939092909160208101903564010000000081111561029a57600080fd5b8201836020820111156102ac57600080fd5b803590602001918460208302840111640100000000831117156102ce57600080fd5b509092509050610bb5565b61030b600480360360608110156102ef57600080fd5b508035906001600160a01b036020820135169060400135610e70565b604080519115158252519081900360200190f35b61018d6004803603602081101561033557600080fd5b503561109a565b6101d2611296565b61018d61129c565b6103696004803603602081101561036257600080fd5b503561133e565b604080519687526020870195909552858501939093526060850191909152608084015260a0830152519081900360c00190f35b6101d2611373565b6101f4611379565b61018d600480360360208110156103c257600080fd5b50356001600160a01b0316611388565b61018d600480360360208110156103e857600080fd5b50356001600160a01b031661148f565b61018d6004803603602081101561040e57600080fd5b503561155a565b61043b6004803603602081101561042b57600080fd5b50356001600160a01b03166117cb565b6040805194151585526020850193909352838301919091526060830152519081900360800190f35b61018d6004803603606081101561047957600080fd5b8135919081019060408101602082013564010000000081111561049b57600080fd5b8201836020820111156104ad57600080fd5b803590602001918460208302840111640100000000831117156104cf57600080fd5b919350915035611851565b6101f46118e3565b61018d6118f2565b61018d6004803603602081101561050057600080fd5b50356001600160a01b0316611d12565b610518611e0a565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561055457818101518382015260200161053c565b505050509050019250505060405180910390f35b6101f4611e6c565b6004546001600160a01b031633146105b95760405162461bcd60e51b81526004018080602001828103825260258152602001806124076025913960400191505060405180910390fd5b4286101580156105c857508486105b80156105d357508385105b61061b576040805162461bcd60e51b8152602060048201526014602482015273125b9d985b1a59081cdd185ad9481c195c9a5bd960621b604482015290519081900360640190fd5b60008311801561062b5750600082115b80156106375750600081115b610679576040805162461bcd60e51b815260206004820152600e60248201526d496e76616c696420696e7075747360901b604482015290519081900360640190fd5b60075415806106ba5750600754600090815260086020526040902060010154421180156106ba57506007546000908152600860205260409020600201548610155b6106f55760405162461bcd60e51b81526004018080602001828103825260318152602001806122db6031913960400191505060405180910390fd5b600780546001019055610706612200565b86815260208082018781526040808401888152608085018881526060860188815260a08701888152600754600090815260089097529390952086518155935160018501559051600284015592516003830155915160048201559051600590910155600b546107749085611e7b565b600b55600754604080518981526020810188905280820187905290513392917fcdf5b97db577de28441798f046e8910e8e4cfa4634aa957d9c29d8d35e10db00919081900360600190a350505050505050565b60075460009081526008602052604090205442108015906107fc57506007546000908152600860205260409020600101544211155b80156108195750336000908152600a602052604090206001015415155b806108535750600754600090815260086020526040902060020154421180156108535750336000908152600a602052604090206001015415155b61089c576040805162461bcd60e51b8152602060048201526015602482015274125b9d985b1a590818db185a5b481c995c5d595cdd605a1b604482015290519081900360640190fd5b600260015414156108f4576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002600155336000908152600a60205260409020811580159061091b575081816001015410155b6109565760405162461bcd60e51b815260040180806020018281038252602381526020018061230c6023913960400191505060405180910390fd5b60018101546000906109689084611ede565b60018301555060038101805460009182905533825260066020526040909120546109929084611ede565b33600090815260066020526040902055600b546109af9084611ede565b600b556002546040805163a9059cbb60e01b81523360048201526024810186905290516001600160a01b039092169163a9059cbb916044808201926020929091908290030181600087803b158015610a0657600080fd5b505af1158015610a1a573d6000803e3d6000fd5b505050506040513d6020811015610a3057600080fd5b5051610a6d5760405162461bcd60e51b815260040180806020018281038252602781526020018061232f6027913960400191505060405180910390fd5b6003546001600160a01b031615801590610a875750600081115b15610b47576003546040805163a9059cbb60e01b81523360048201526024810184905290516001600160a01b039092169163a9059cbb916044808201926020929091908290030181600087803b158015610ae057600080fd5b505af1158015610af4573d6000803e3d6000fd5b505050506040513d6020811015610b0a57600080fd5b5051610b475760405162461bcd60e51b815260040180806020018281038252602d8152602001806123da602d913960400191505060405180910390fd5b600754604080518581526020810184905281513393927f673bfbb3dfcd8a2199b5dd0f5266f5ed6716f9502c7dcc5aa89b1d46554b96df928290030190a350506001805550565b60066020526000908152604090205481565b60055481565b6003546001600160a01b031681565b6004546001600160a01b03163314610bfe5760405162461bcd60e51b81526004018080602001828103825260258152602001806124076025913960400191505060405180910390fd5b6005544310610c54576040805162461bcd60e51b815260206004820181905260248201527f457863656564732061697264726f70206175746f207374616b65207068617365604482015290519081900360640190fd5b828114610c9f576040805162461bcd60e51b8152602060048201526014602482015273496e76616c696420496e7075742041727261797360601b604482015290519081900360640190fd5b8460075414610cf5576040805162461bcd60e51b815260206004820152601a60248201527f496e76616c6964205374616b652057696e646f7720496e646578000000000000604482015290519081900360640190fd5b60005b83811015610e6857610d08612236565b60018152838383818110610d1857fe5b90506020020135816020018181525050600081604001818152505080600a6000888886818110610d4457fe5b602090810292909201356001600160a01b03168352508181019290925260409081016000208351815460ff191690151517815591830151600183015582015160028201556060909101516003909101556009868684818110610da257fe5b835460018101855560009485526020948590200180546001600160a01b0319166001600160a01b039590920293909301359390931692909217905550838383818110610dea57fe5b9050602002013560066000888886818110610e0157fe5b905060200201356001600160a01b03166001600160a01b03166001600160a01b0316815260200190815260200160002081905550610e5c848484818110610e4457fe5b90506020020135600b54611e7b90919063ffffffff16565b600b5550600101610cf8565b505050505050565b6004546000906001600160a01b03163314610ebc5760405162461bcd60e51b81526004018080602001828103825260258152602001806124076025913960400191505060405180910390fd5b60008481526008602052604090206001015442118015610eec575060008481526008602052604090206002015442105b610f3d576040805162461bcd60e51b815260206004820152601a60248201527f5265776172642063616e6e6f74206265206164646564206e6f77000000000000604482015290519081900360640190fd5b6001600160a01b0383166000908152600a60205260409020600181015415801590610f6c575084816002015414155b610fb6576040805162461bcd60e51b8152602060048201526016602482015275125b9d985b1a59081c995dd85c99081c995c5d595cdd60521b604482015290519081900360640190fd5b60018101546000610fc78783611f20565b9050610fd38282611e7b565b600184018190556003840154909250610fec9086611e7b565b6003840155600283018790556001600160a01b03861660009081526006602052604090205461101b9082611e7b565b6001600160a01b0380881660008181526006602090815260409182902094909455600454600b5482519190941681529384018690528381018590526060840192909252905189927f45e1ba9e71ec24a10adf9d3f8cf6c41c4452fcb51b8aa6850861243fb23f76f3919081900360800190a35060019695505050505050565b6004546001600160a01b031633146110e35760405162461bcd60e51b81526004018080602001828103825260258152602001806124076025913960400191505060405180910390fd5b600254604080516370a0823160e01b8152306004820152905183926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561112d57600080fd5b505afa158015611141573d6000803e3d6000fd5b505050506040513d602081101561115757600080fd5b505110156111965760405162461bcd60e51b81526004018080602001828103825260228152602001806123b86022913960400191505060405180910390fd5b6002546040805163a9059cbb60e01b81523360048201526024810184905290516001600160a01b039092169163a9059cbb916044808201926020929091908290030181600087803b1580156111ea57600080fd5b505af11580156111fe573d6000803e3d6000fd5b505050506040513d602081101561121457600080fd5b50516112515760405162461bcd60e51b815260040180806020018281038252603081526020018061242c6030913960400191505060405180910390fd5b6004546040805183815290516001600160a01b03909216917f992ee874049a42cae0757a765cd7f641b6028cc35c3478bde8330bf417c3a7a99181900360200190a250565b60075481565b6112a4611f8b565b6000546001600160a01b039081169116146112f4576040805162461bcd60e51b81526020600482018190526024820152600080516020612377833981519152604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b600860205260009081526040902080546001820154600283015460038401546004850154600590950154939492939192909186565b600b5481565b6000546001600160a01b031690565b611390611f8b565b6000546001600160a01b039081169116146113e0576040805162461bcd60e51b81526020600482018190526024820152600080516020612377833981519152604482015290519081900360640190fd5b6001600160a01b03811661143b576040805162461bcd60e51b815260206004820152601860248201527f496e76616c6964206f70657261746f7220616464726573730000000000000000604482015290519081900360640190fd5b600480546001600160a01b0383166001600160a01b0319909116811790915560408051918252517fda12ee837e6978172aaf54b16145ffe08414fd8710092ef033c71b8eb6ec189a9181900360200190a150565b611497611f8b565b6000546001600160a01b039081169116146114e7576040805162461bcd60e51b81526020600482018190526024820152600080516020612377833981519152604482015290519081900360640190fd5b6001600160a01b038116611538576040805162461bcd60e51b815260206004820152601360248201527224b73b30b634b2103137b73ab9903a37b5b2b760691b604482015290519081900360640190fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b600754600090815260086020526040902054421080159061158f57506007546000908152600860205260409020600101544211155b6115ca5760405162461bcd60e51b81526004018080602001828103825260218152602001806123976021913960400191505060405180910390fd5b336000818152600a60205260408120600101548391906115eb908390611e7b565b905060008211801561161157506007546000908152600860205260409020600301548111155b801561163d5750600754600090815260086020526040902060050154600b5461163a9084611e7b565b11155b611685576040805162461bcd60e51b8152602060048201526014602482015273457863656564696e67206d6178206c696d69747360601b604482015290519081900360640190fd5b600254604080516323b872dd60e01b81523360048201523060248201526044810187905290516001600160a01b03909216916323b872dd916064808201926020929091908290030181600087803b1580156116df57600080fd5b505af11580156116f3573d6000803e3d6000fd5b505050506040513d602081101561170957600080fd5b50516117465760405162461bcd60e51b81526004018080602001828103825260288152602001806122616028913960400191505060405180910390fd5b6117503385611f8f565b503360009081526006602052604090205461176b9085611e7b565b33600090815260066020526040902055600b546117889085611e7b565b600b556007546040805186815290513392917f157efccb244e0e1ae7a36a1c28a1f45b62e1250e06e57d9cb44cc1cdc2d95d92919081900360200190a350505050565b6000806000806117d9612236565b506001600160a01b0385166000908152600a602090815260408083208151608081018352815460ff16158015825260018301549482019490945260028201549281019290925260030154606082015291955061183457600194505b806020015193508060400151925080606001519150509193509193565b6004546001600160a01b0316331461189a5760405162461bcd60e51b81526004018080602001828103825260258152602001806124076025913960400191505060405180910390fd5b60005b828110156118dc576118cb858585848181106118b557fe5b905060200201356001600160a01b031684610e70565b6118d457600080fd5b60010161189d565b5050505050565b6004546001600160a01b031681565b600754600090815260086020526040902054421080159061192757506007546000908152600860205260409020600101544211155b80156119445750336000908152600a602052604090206001015415155b8061197e57506007546000908152600860205260409020600201544211801561197e5750336000908152600a602052604090206001015415155b6119c7576040805162461bcd60e51b8152602060048201526015602482015274125b9d985b1a590818db185a5b481c995c5d595cdd605a1b604482015290519081900360640190fd5b60026001541415611a1f576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60026001908155336000908152600a6020526040812091820180546003840180549284905592909255600b54611a559083611ede565b600b55600254604080516370a0823160e01b8152306004820152905184926001600160a01b0316916370a08231916024808301926020929190829003018186803b158015611aa257600080fd5b505afa158015611ab6573d6000803e3d6000fd5b505050506040513d6020811015611acc57600080fd5b50511015611b0b5760405162461bcd60e51b81526004018080602001828103825260228152602001806123b86022913960400191505060405180910390fd5b33600090815260066020526040902054611b259083611ede565b33600081815260066020908152604080832094909455600254845163a9059cbb60e01b815260048101949094526024840187905293516001600160a01b039094169363a9059cbb93604480820194918390030190829087803b158015611b8a57600080fd5b505af1158015611b9e573d6000803e3d6000fd5b505050506040513d6020811015611bb457600080fd5b5051611bf15760405162461bcd60e51b815260040180806020018281038252602c815260200180612289602c913960400191505060405180910390fd5b6003546001600160a01b031615801590611c0b5750600081115b15611ccb576003546040805163a9059cbb60e01b81523360048201526024810184905290516001600160a01b039092169163a9059cbb916044808201926020929091908290030181600087803b158015611c6457600080fd5b505af1158015611c78573d6000803e3d6000fd5b505050506040513d6020811015611c8e57600080fd5b5051611ccb5760405162461bcd60e51b815260040180806020018281038252602d8152602001806123da602d913960400191505060405180910390fd5b600754604080518481526020810184905281513393927f264d516978993d9a3ad8f7f4be7c3ec864bd6e25e4ccb0da2bfc2bba01698c53928290030190a350506001805550565b611d1a611f8b565b6000546001600160a01b03908116911614611d6a576040805162461bcd60e51b81526020600482018190526024820152600080516020612377833981519152604482015290519081900360640190fd5b6001600160a01b038116611daf5760405162461bcd60e51b81526004018080602001828103825260268152602001806122b56026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b60606009805480602002602001604051908101604052809291908181526020018280548015611e6257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611e44575b5050505050905090565b6002546001600160a01b031681565b600082820183811015611ed5576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b90505b92915050565b6000611ed583836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525061206e565b600082815260086020526040812060040154600b5482911015611ed557600084815260086020526040902060040154600b54611f8391611f609190611ede565b600086815260086020526040902060040154611f7d908690612105565b9061215e565b949350505050565b3390565b6001600160a01b0382166000908152600a60205260408120805460ff1615611fca576001810154611fc09084611e7b565b6001820155612064565b611fd2612236565b60018082526020808301868152600060408086018281526001600160a01b038b16808452600a9095529082208651815460ff19169015151781559251838601555160028301556060909401516003909101556009805492830181559092527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0180546001600160a01b03191690911790555b5060019392505050565b600081848411156120fd5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156120c25781810151838201526020016120aa565b50505050905090810190601f1680156120ef5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60008261211457506000611ed8565b8282028284828161212157fe5b0414611ed55760405162461bcd60e51b81526004018080602001828103825260218152602001806123566021913960400191505060405180910390fd5b6000611ed583836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250600081836121ea5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156120c25781810151838201526020016120aa565b5060008385816121f657fe5b0495945050505050565b6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040518060800160405280600015158152602001600081526020016000815260200160008152509056fe556e61626c6520746f207472616e7366657220746f6b656e20746f2074686520636f6e7472616374556e61626c6520746f207472616e7366657220746f6b656e206261636b20746f20746865206163636f756e744f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737343616e6e6f742068617665206d6f7265207468616e206f6e65207374616b65207265717565737420617420612074696d6543616e6e6f74207769746864726177206265796f6e64207374616b6520616d6f756e74556e61626c6520746f207472616e7366657220746f6b656e20746f20746865206163636f756e74536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65725374616b696e67206174207468697320706f696e74206e6f7420616c6c6f7765644e6f7420656e6f7567682062616c616e636520696e2074686520636f6e7472616374556e61626c6520746f207472616e7366657220626f6e757320746f6b656e20746f20746865206163636f756e744f6e6c79206f70657261746f722063616e2063616c6c20746869732066756e6374696f6e2e556e61626c6520746f207472616e7366657220746f6b656e20746f20746865206f70657261746f72206163636f756e74a26469706673582212206dd8bb7f797a3decb5708d48afcdc261daef17e00b7aea2438956f7dd3f4327c64736f6c634300060c0033

Verified Source Code Full Match

Compiler: v0.6.12+commit.27d51765 EVM: istanbul Optimization: Yes (200 runs)
Context.sol 24 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

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

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

pragma solidity ^0.6.0;

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

        return c;
    }

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

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

        return c;
    }

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

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

        return c;
    }

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

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

        return c;
    }

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

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

pragma solidity ^0.6.2;

/**
 * @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 in 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");
        return _functionCallWithValue(target, data, value, errorMessage);
    }

    function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
        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);
            }
        }
    }
}
Ownable.sol 68 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

import "../GSN/Context.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.
 */
contract Ownable is Context {
    address private _owner;

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

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

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(_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;
    }
}
ERC20.sol 307 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

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

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

    mapping (address => uint256) private _balances;

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

    uint256 private _totalSupply;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        _beforeTokenTransfer(sender, recipient, amount);

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.6.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);
}
ReentrancyGuard.sol 62 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor () internal {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}
SDAOBondedTokenStake.sol 429 lines
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

contract SDAOBondedTokenStake is Ownable, ReentrancyGuard{

    using SafeMath for uint256;

    ERC20 public token; // Address of token contract and same used for rewards
    ERC20 public bonusToken; // Address of bonus token contract

    struct StakeInfo {
        bool exist;
        uint256 amount;
        uint256 rewardComputeIndex;
        uint256 bonusAmount;
    }

    // Staking period timestamp (Debatable on timestamp vs blocknumber - went with timestamp)
    struct StakePeriod {
        uint256 startPeriod;
        uint256 submissionEndPeriod;
        uint256 endPeriod;

        uint256 maxStake;

        uint256 windowRewardAmount;
        uint256 windowMaxAmount;
        
    }

    address public tokenOperator; // Address to manage the Stake 

    uint256 public maxAirDropStakeBlocks; // Block numbers to complete the airDrop Auto Stakes

    mapping (address => uint256) public balances; // Useer Token balance in the contract

    uint256 public currentStakeMapIndex; // Current Stake Index to avoid math calc in all methods

    mapping (uint256 => StakePeriod) public stakeMap;

    // List of Stake Holders
    address[] stakeHolders; 

    // All Stake Holders
    mapping(address => StakeInfo) stakeHolderInfo;

    // To store the total stake in a window
    uint256 public windowTotalStake;

    // Events
    event NewOperator(address tokenOperator);

    event WithdrawToken(address indexed tokenOperator, uint256 amount);

    event OpenForStake(uint256 indexed stakeIndex, address indexed tokenOperator, uint256 startPeriod, uint256 endPeriod, uint256 rewardAmount);
    event SubmitStake(uint256 indexed stakeIndex, address indexed staker, uint256 stakeAmount);
    event WithdrawStake(uint256 indexed stakeIndex, address indexed staker, uint256 stakeAmount, uint256 bonusAmount);
    event ClaimStake(uint256 indexed stakeIndex, address indexed staker, uint256 totalAmount, uint256 bonusAmount);
    event AddReward(address indexed staker, uint256 indexed stakeIndex, address tokenOperator, uint256 stakeAmount, uint256 rewardAmount, uint256 windowTotalStake);


    // Modifiers
    modifier onlyOperator() {
        require(
            msg.sender == tokenOperator,
            "Only operator can call this function."
        );
        _;
    }

    // Token Operator should be able to do auto renewal
    modifier allowSubmission() {        
        require(
            now >= stakeMap[currentStakeMapIndex].startPeriod && 
            now <= stakeMap[currentStakeMapIndex].submissionEndPeriod, 
            "Staking at this point not allowed"
        );
        _;
    }

    modifier validStakeLimit(address staker, uint256 stakeAmount) {

        uint256 stakerTotalStake;
        stakerTotalStake = stakeAmount.add(stakeHolderInfo[staker].amount);

        // Check for Max Stake per Wallet and stake window max limit 
        require(
            stakeAmount > 0 && 
            stakerTotalStake <= stakeMap[currentStakeMapIndex].maxStake && 
            windowTotalStake.add(stakeAmount) <= stakeMap[currentStakeMapIndex].windowMaxAmount,
            "Exceeding max limits"
        );
        _;

    }

    // Check for claim - Stake Window should be either in submission phase or after end period
    modifier allowClaimStake() {

        require(
          (now >= stakeMap[currentStakeMapIndex].startPeriod && now <= stakeMap[currentStakeMapIndex].submissionEndPeriod && stakeHolderInfo[msg.sender].amount > 0) || 
          (now > stakeMap[currentStakeMapIndex].endPeriod && stakeHolderInfo[msg.sender].amount > 0), "Invalid claim request");
        _;

    }

    constructor(address _token, uint256 _maxAirDropStakeBlocks)
    public
    {
        token = ERC20(_token);
        tokenOperator = msg.sender;
        currentStakeMapIndex = 0;
        windowTotalStake = 0;
        maxAirDropStakeBlocks = _maxAirDropStakeBlocks.add(block.number); 
    }

    function updateOperator(address newOperator) external onlyOwner {

        require(newOperator != address(0), "Invalid operator address");
        
        tokenOperator = newOperator;

        emit NewOperator(newOperator);
    }
    
    function withdrawToken(uint256 value) external onlyOperator
    {

        // Check if contract is having required balance 
        require(token.balanceOf(address(this)) >= value, "Not enough balance in the contract");
        require(token.transfer(msg.sender, value), "Unable to transfer token to the operator account");

        emit WithdrawToken(tokenOperator, value);
        
    }

    // To set the bonus token for future needs
    function setBonusToken(address _bonusToken) external onlyOwner {
        require(_bonusToken != address(0), "Invalid bonus token");
        bonusToken = ERC20(_bonusToken);
    }

    function openForStake(uint256 _startPeriod, uint256 _submissionEndPeriod, uint256 _endPeriod, uint256 _windowRewardAmount, uint256 _maxStake, uint256 _windowMaxAmount) external onlyOperator {

        // Check Input Parameters
        require(_startPeriod >= now && _startPeriod < _submissionEndPeriod && _submissionEndPeriod < _endPeriod, "Invalid stake period");
        require(_windowRewardAmount > 0 && _maxStake > 0 && _windowMaxAmount > 0, "Invalid inputs" );

        // Check Stake in Progress
        require(currentStakeMapIndex == 0 || (now > stakeMap[currentStakeMapIndex].submissionEndPeriod && _startPeriod >= stakeMap[currentStakeMapIndex].endPeriod), "Cannot have more than one stake request at a time");

        // Move the staking period to next one
        currentStakeMapIndex = currentStakeMapIndex + 1;
        StakePeriod memory stakePeriod;

        // Set Staking attributes
        stakePeriod.startPeriod = _startPeriod;
        stakePeriod.submissionEndPeriod = _submissionEndPeriod;
        stakePeriod.endPeriod = _endPeriod;
        stakePeriod.windowRewardAmount = _windowRewardAmount;
        stakePeriod.maxStake = _maxStake;
        stakePeriod.windowMaxAmount = _windowMaxAmount;

        stakeMap[currentStakeMapIndex] = stakePeriod;

        // Add the current window reward to the window total stake 
        windowTotalStake = windowTotalStake.add(_windowRewardAmount);

        emit OpenForStake(currentStakeMapIndex, msg.sender, _startPeriod, _endPeriod, _windowRewardAmount);

    }

    // To add the Stake Holder
    function _createStake(address staker, uint256 stakeAmount) internal returns(bool) {

        StakeInfo storage stakeInfo = stakeHolderInfo[staker];

        // Check if the user already staked in the past
        if(stakeInfo.exist) {

            stakeInfo.amount = stakeInfo.amount.add(stakeAmount);

        } else {

            StakeInfo memory req;

            // Create a new stake request
            req.exist = true;
            req.amount = stakeAmount;
            req.rewardComputeIndex = 0;

            // Add to the Stake Holders List
            stakeHolderInfo[staker] = req;

            // Add to the Stake Holders List
            stakeHolders.push(staker);

        }

        return true;

    }


    // To submit a new stake for the current window
    function submitStake(uint256 stakeAmount) external allowSubmission validStakeLimit(msg.sender, stakeAmount) {

        // Transfer the Tokens to Contract
        require(token.transferFrom(msg.sender, address(this), stakeAmount), "Unable to transfer token to the contract");

        _createStake(msg.sender, stakeAmount);

        // Update the User balance
        balances[msg.sender] = balances[msg.sender].add(stakeAmount);

        // Update current stake period total stake - For Auto Approvals
        windowTotalStake = windowTotalStake.add(stakeAmount); 
       
        emit SubmitStake(currentStakeMapIndex, msg.sender, stakeAmount);

    }


    // To withdraw stake during submission phase
    function withdrawStake(uint256 stakeAmount) external allowClaimStake nonReentrant{

        //require(
        //    (now >= stakeMap[stakeMapIndex].startPeriod && now <= stakeMap[stakeMapIndex].submissionEndPeriod),
        //    "Stake withdraw at this point is not allowed"
        //);

        StakeInfo storage stakeInfo = stakeHolderInfo[msg.sender];

        // Validate the input Stake Amount
        require(stakeAmount > 0 && stakeInfo.amount >= stakeAmount, "Cannot withdraw beyond stake amount");

        uint256 bonusAmount;

        // Update the staker balance in the staking window
        stakeInfo.amount = stakeInfo.amount.sub(stakeAmount);
        bonusAmount = stakeInfo.bonusAmount;
        stakeInfo.bonusAmount = 0;

        // Update the User balance
        balances[msg.sender] = balances[msg.sender].sub(stakeAmount);

        // Update current stake period total stake - For Auto Approvals
        windowTotalStake = windowTotalStake.sub(stakeAmount); 

        // Return to User Wallet
        require(token.transfer(msg.sender, stakeAmount), "Unable to transfer token to the account");

        // Call the bonus transfer function - Should transfer only if set 
        if(address(bonusToken) != address(0) && bonusAmount > 0) {
            require(bonusToken.transfer(msg.sender, bonusAmount), "Unable to transfer bonus token to the account");
        }

        emit WithdrawStake(currentStakeMapIndex, msg.sender, stakeAmount, bonusAmount);
    }

    // To claim from the stake window
    function claimStake() external allowClaimStake nonReentrant{

        StakeInfo storage stakeInfo = stakeHolderInfo[msg.sender];

        uint256 stakeAmount;
        uint256 bonusAmount;

        // No more stake windows or in submission phase
        stakeAmount = stakeInfo.amount;
        bonusAmount = stakeInfo.bonusAmount;
        stakeInfo.amount = 0;
        stakeInfo.bonusAmount = 0;

        // Update current stake period total stake
        windowTotalStake = windowTotalStake.sub(stakeAmount);

        // Check for balance in the contract
        require(token.balanceOf(address(this)) >= stakeAmount, "Not enough balance in the contract");

        // Update the User Balance
        balances[msg.sender] = balances[msg.sender].sub(stakeAmount);

        // Call the transfer function
        require(token.transfer(msg.sender, stakeAmount), "Unable to transfer token back to the account");

        // Call the bonus transfer function - Should transfer only if set 
        if(address(bonusToken) != address(0) && bonusAmount > 0) {
            require(bonusToken.transfer(msg.sender, bonusAmount), "Unable to transfer bonus token to the account");
        }
        
        emit ClaimStake(currentStakeMapIndex, msg.sender, stakeAmount, bonusAmount);

    }


    function _calculateRewardAmount(uint256 stakeMapIndex, uint256 stakeAmount) internal view returns(uint256) {

        uint256 calcRewardAmount;
        if(windowTotalStake > stakeMap[stakeMapIndex].windowRewardAmount) {
            calcRewardAmount = stakeAmount.mul(stakeMap[stakeMapIndex].windowRewardAmount).div(windowTotalStake.sub(stakeMap[stakeMapIndex].windowRewardAmount));
        }
        
        return calcRewardAmount;
    }


    // Update reward for staker in the respective stake window
    function computeAndAddReward(uint256 stakeMapIndex, address staker, uint256 stakeBonusAmount) 
    public 
    onlyOperator
    returns(bool)
    {

        // Check for the Incubation Period
        require(
            now > stakeMap[stakeMapIndex].submissionEndPeriod && 
            now < stakeMap[stakeMapIndex].endPeriod, 
            "Reward cannot be added now"
        );

        StakeInfo storage stakeInfo = stakeHolderInfo[staker];

        // Check if reward already computed
        require(stakeInfo.amount > 0 && stakeInfo.rewardComputeIndex != stakeMapIndex, "Invalid reward request");

        // Calculate the totalAmount
        uint256 totalAmount;
        uint256 rewardAmount;

        // Calculate the reward amount for the current window
        totalAmount = stakeInfo.amount;
        rewardAmount = _calculateRewardAmount(stakeMapIndex, totalAmount);
        totalAmount = totalAmount.add(rewardAmount);

        // Add the reward amount
        stakeInfo.amount = totalAmount;

        // Add the bonus Amount
        stakeInfo.bonusAmount = stakeInfo.bonusAmount.add(stakeBonusAmount);

        // Update the reward compute index to avoid mulitple addition
        stakeInfo.rewardComputeIndex = stakeMapIndex;

        // Update the User Balance
        balances[staker] = balances[staker].add(rewardAmount);

        emit AddReward(staker, stakeMapIndex, tokenOperator, totalAmount, rewardAmount, windowTotalStake);

        return true;
    }

    function updateRewards(uint256 stakeMapIndex, address[] calldata staker, uint256 stakeBonusAmount) 
    external 
    onlyOperator
    {
        for(uint256 indx = 0; indx < staker.length; indx++) {
            require(computeAndAddReward(stakeMapIndex, staker[indx], stakeBonusAmount));
        }
    }

    // AirDrop to Stake - Load existing stakes from Air Drop
    function airDropStakes(uint256 stakeMapIndex, address[] calldata staker, uint256[] calldata stakeAmount) external onlyOperator {

        // Add check for Block Number to restrict air drop auto stake phase after certain block number
        require(block.number < maxAirDropStakeBlocks, "Exceeds airdrop auto stake phase");

        // Check Input Parameters
        require(staker.length == stakeAmount.length, "Invalid Input Arrays");

        // Stakers should be for current window
        require(currentStakeMapIndex == stakeMapIndex, "Invalid Stake Window Index");

        for(uint256 indx = 0; indx < staker.length; indx++) {

            StakeInfo memory req;

            // Create a stake request with amount
            req.exist = true;
            req.amount = stakeAmount[indx];
            req.rewardComputeIndex = 0;

            // Add to the Stake Holders List
            stakeHolderInfo[staker[indx]] = req;

            // Add to the Stake Holders List
            stakeHolders.push(staker[indx]);

            // Update the User balance
            balances[staker[indx]] = stakeAmount[indx];

            // Update current stake period total stake - Along with Reward
            windowTotalStake = windowTotalStake.add(stakeAmount[indx]);

        }

    }


    // Getter Functions    
    function getStakeHolders() external view returns(address[] memory) {
        return stakeHolders;
    }

    function getStakeInfo(address staker) 
    external 
    view
    returns (bool found, uint256 amount, uint256 rewardComputeIndex, uint256 bonusAmount) 
    {

        StakeInfo memory stakeInfo = stakeHolderInfo[staker];
        
        found = false;
        if(stakeInfo.exist) {
            found = true;
        }

        amount = stakeInfo.amount;
        rewardComputeIndex = stakeInfo.rewardComputeIndex;
        bonusAmount = stakeInfo.bonusAmount;

    }


}

Read Contract

balances 0x27e235e3 → uint256
bonusToken 0x41d4a1ab → address
currentStakeMapIndex 0x5a8a1734 → uint256
getStakeHolders 0xf7fecc27 → address[]
getStakeInfo 0xc3453153 → bool, uint256, uint256, uint256
maxAirDropStakeBlocks 0x2ad77f8f → uint256
owner 0x8da5cb5b → address
stakeMap 0x88a0c929 → uint256, uint256, uint256, uint256, uint256, uint256
token 0xfc0c546a → address
tokenOperator 0xe737b86e → address
windowTotalStake 0x8bd85c44 → uint256

Write Contract 12 functions

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

airDropStakes 0x48bba309
uint256 stakeMapIndex
address[] staker
uint256[] stakeAmount
claimStake 0xeb321173
No parameters
computeAndAddReward 0x4d028c27
uint256 stakeMapIndex
address staker
uint256 stakeBonusAmount
returns: bool
openForStake 0x1c067667
uint256 _startPeriod
uint256 _submissionEndPeriod
uint256 _endPeriod
uint256 _windowRewardAmount
uint256 _maxStake
uint256 _windowMaxAmount
renounceOwnership 0x715018a6
No parameters
setBonusToken 0xb2eaeaaa
address _bonusToken
submitStake 0xbec3aa75
uint256 stakeAmount
transferOwnership 0xf2fde38b
address newOwner
updateOperator 0xac7475ed
address newOperator
updateRewards 0xc8aea247
uint256 stakeMapIndex
address[] staker
uint256 stakeBonusAmount
withdrawStake 0x25d5971f
uint256 stakeAmount
withdrawToken 0x50baa622
uint256 value

Recent Transactions

No transactions found for this address