zellic-audit
Initial commit
f998fcd
raw
history blame
21 kB
{
"language": "Solidity",
"sources": {
"/contracts/stakOKApi.sol": {
"content": "// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.16;\r\nimport \"./Ownable.sol\";\r\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\r\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\r\n\r\n\r\ncontract staking is Ownable {\r\n using SafeMath for uint256;\r\n\r\n address public treasury;\r\n\r\n uint256 constant private divider=10000;\r\n\r\n uint256 public depoiteTax=0;\r\n\r\n uint256 public withdrawTax=0;\r\n\r\n uint256 public rewardPercentage=150;\r\n\r\n uint256 public totalInvestedToken;\r\n\r\n uint256 public totalWithdrawToken;\r\n\r\n IERC20 public token;\r\n \r\n\r\n struct user {\r\n uint256 deposites;\r\n uint256 totalRewardWithdrawToken;\r\n uint256 checkToken;\r\n uint256 withdrawCheckToken;\r\n uint256 totalRewards;\r\n }\r\n\r\n mapping (address=>user) public investor;\r\n\r\n\tevent NewDeposit(address indexed user, uint256 amount);\r\n event compoundRewards (address indexed user, uint256 amount);\r\n\tevent withdrawal(address indexed user, uint256 amount);\r\n\tevent RewardWithdraw(address indexed user,uint256 amount);\r\n event SetTax(uint256 DepositTax,uint256 withdrawTax);\r\n event SetRewardPercentage(uint256 rewardPercentage);\r\n constructor() Ownable(0x0c2f01db0e79a1D40B5a478A33a1B31A450C8F95){\r\n treasury=0x0c2f01db0e79a1D40B5a478A33a1B31A450C8F95;\r\n token= IERC20(0x29cD78954c023cd9BffC435a816E568eDaf732aF);\r\n }\r\n \r\n \r\n function setWallet( address _treasury) public onlyOwner{\r\n require(_treasury!=address(0),\"Error: Can not set treasury wallet to zero address \");\r\n treasury=_treasury;\r\n }\r\n\r\n function setTax(uint256 _depoiteTax,uint256 _withdrawTax) public onlyOwner{\r\n require(_depoiteTax<=2000,\"Deposit Tax Must be less than 20%\");\r\n require(_withdrawTax<=2000,\"Withdraw Tax Must be less than 20%\");\r\n depoiteTax=_depoiteTax;\r\n withdrawTax=_withdrawTax;\r\n emit SetTax(_depoiteTax,_withdrawTax);\r\n }\r\n\r\n function setRewardPercentage(uint256 _rewardPercentage) public onlyOwner{\r\n require(_rewardPercentage>=100,\"Reward Percentage Must be less than 1%\");\r\n require(_rewardPercentage<=2000,\"Reward Percentage Must be less than 20%\");\r\n rewardPercentage=_rewardPercentage; \r\n emit SetRewardPercentage(_rewardPercentage); \r\n }\r\n\r\n function invest(uint256 amount) public payable {\r\n user storage users =investor[msg.sender];\r\n \r\n require(amount<=token.allowance(msg.sender, address(this)),\"Insufficient Allowence to the contract\");\r\n uint256 tax=amount.mul(depoiteTax).div(divider);\r\n \r\n token.transferFrom(msg.sender, treasury, tax);\r\n token.transferFrom(msg.sender, address(this), amount.sub(tax));\r\n users.totalRewards+=calclulateReward(msg.sender);\r\n users.deposites+=amount;\r\n totalInvestedToken=totalInvestedToken.add(amount.sub(tax));\r\n users.checkToken=block.timestamp;\r\n emit NewDeposit(msg.sender, amount);\r\n }\r\n \r\n function compound() public payable {\r\n user storage users =investor[msg.sender];\r\n \r\n (uint256 amount)=calclulateReward(msg.sender);\r\n \r\n require(amount>0,\"compound Amount very low\");\r\n users.deposites+=amount;\r\n totalInvestedToken=totalInvestedToken.add(amount);\r\n emit compoundRewards (msg.sender, amount);\r\n \r\n users.withdrawCheckToken=block.timestamp;\r\n users.checkToken=block.timestamp;\r\n }\r\n \r\n function withdrawToken(uint256 amount)public {\r\n uint256 totalDeposite=getUserTotalDepositToken(msg.sender);\r\n require(totalDeposite>0,\"No Deposite Found\");\r\n require(amount<=totalDeposite,\"Amount Exceeds Deposite Amount\");\r\n require(amount<=getContractTokenBalacne(),\"Not Enough Token for withdrwal from contract please try after some time\");\r\n uint256 tax=amount.mul(withdrawTax).div(divider);\r\n token.transfer(treasury, tax);\r\n token.transfer(msg.sender, amount.sub(tax));\r\n investor[msg.sender].totalRewards+=calclulateReward(msg.sender);\r\n investor[msg.sender].deposites-=amount;\r\n investor[msg.sender].checkToken=block.timestamp;\r\n emit withdrawal(msg.sender, amount);\r\n }\r\n \r\n function withdrawRewardToken()public {\r\n (uint256 totalRewards)=calclulateReward(msg.sender).add(investor[msg.sender].totalRewards);\r\n require(totalRewards>0,\"No Rewards Found\");\r\n require(totalRewards<=getContractTokenBalacne(),\"Not Enough Token for withdrwal from contract please try after some time\");\r\n uint256 taxR=totalRewards.mul(withdrawTax).div(divider);\r\n token.transfer(msg.sender, totalRewards.sub(taxR));\r\n investor[msg.sender].totalRewardWithdrawToken+=totalRewards;\r\n investor[msg.sender].totalRewards=0;\r\n investor[msg.sender].checkToken=block.timestamp;\r\n totalWithdrawToken+=totalRewards;\r\n emit RewardWithdraw(msg.sender, totalRewards);\r\n }\r\n \r\n \r\n function calclulateReward(address _user) public view returns(uint256){\r\n uint256 totalRewardToken;\r\n user storage users=investor[_user];\r\n if(users.deposites>0){ \r\n uint256 depositeAmount=users.deposites;\r\n uint256 time = block.timestamp.sub(users.checkToken);\r\n totalRewardToken += depositeAmount.mul(rewardPercentage).div(divider).mul(time).div(1 days).div(365); \r\n }\r\n return(totalRewardToken);\r\n }\r\n\r\n function getUserTotalDepositToken(address _user) public view returns(uint256 _totalInvestment){\r\n \r\n _totalInvestment=investor[_user].deposites;\r\n \r\n }\r\n \r\n function getUserTotalRewardWithdrawToken(address _user) public view returns(uint256 _totalWithdraw){\r\n _totalWithdraw=investor[_user].totalRewardWithdrawToken;\r\n }\r\n \r\n\r\n function getContractTokenBalacne() public view returns(uint256 totalToken){\r\n totalToken=token.balanceOf(address(this));\r\n }\r\n\r\n function getContractBNBBalacne() public view returns(uint256 totalBNB){\r\n totalBNB=address(this).balance;\r\n }\r\n \r\n function withdrawalBNB() public payable onlyOwner{\r\n payable(owner()).transfer(getContractBNBBalacne());\r\n }\r\n \r\n receive() external payable {\r\n \r\n }\r\n \r\n}"
},
"/contracts/Ownable.sol": {
"content": "\r\n\r\n// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.16;\r\nimport \"@openzeppelin/contracts/utils/Context.sol\";\r\n/**\r\n * @dev Contract module which provides a basic access control mechanism, where\r\n * there is an account (an owner) that can be granted exclusive access to\r\n * specific functions.\r\n *\r\n * By default, the owner account will be the one that deploys the contract. This\r\n * can later be changed with {transferOwnership}.\r\n *\r\n * This module is used through inheritance. It will make available the modifier\r\n * `onlyOwner`, which can be applied to your functions to restrict their use to\r\n * the owner.\r\n */\r\nabstract contract Ownable is Context {\r\n address private _owner;\r\n\r\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r\n\r\n /**\r\n * @dev Initializes the contract setting the deployer as the initial owner.\r\n */\r\n constructor(address newOwner) {\r\n _transferOwnership(newOwner);\r\n }\r\n\r\n /**\r\n * @dev Returns the address of the current owner.\r\n */\r\n function owner() public view virtual returns (address) {\r\n return _owner;\r\n }\r\n\r\n /**\r\n * @dev Throws if called by any account other than the owner.\r\n */\r\n modifier onlyOwner() {\r\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\r\n _;\r\n }\r\n\r\n /**\r\n * @dev Leaves the contract without owner. It will not be possible to call\r\n * `onlyOwner` functions anymore. Can only be called by the current owner.\r\n *\r\n * NOTE: Renouncing ownership will leave the contract without an owner,\r\n * thereby removing any functionality that is only available to the owner.\r\n */\r\n function renounceOwnership() public virtual onlyOwner {\r\n _transferOwnership(address(0));\r\n }\r\n\r\n /**\r\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\r\n * Can only be called by the current owner.\r\n */\r\n function transferOwnership(address newOwner) public virtual onlyOwner {\r\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\r\n _transferOwnership(newOwner);\r\n }\r\n\r\n /**\r\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\r\n * Internal function without access restriction.\r\n */\r\n function _transferOwnership(address newOwner) internal virtual {\r\n address oldOwner = _owner;\r\n _owner = newOwner;\r\n emit OwnershipTransferred(oldOwner, newOwner);\r\n }\r\n}"
},
"@openzeppelin/contracts/utils/math/SafeMath.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)\n\npragma solidity ^0.8.0;\n\n// CAUTION\n// This version of SafeMath should only be used with Solidity 0.8 or later,\n// because it relies on the compiler's built in overflow checks.\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations.\n *\n * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler\n * now has built in overflow checking.\n */\nlibrary SafeMath {\n /**\n * @dev Returns the addition of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n uint256 c = a + b;\n if (c < a) return (false, 0);\n return (true, c);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b > a) return (false, 0);\n return (true, a - b);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) return (true, 0);\n uint256 c = a * b;\n if (c / a != b) return (false, 0);\n return (true, c);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a division by zero flag.\n *\n * _Available since v3.4._\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b == 0) return (false, 0);\n return (true, a / b);\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n *\n * _Available since v3.4._\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b == 0) return (false, 0);\n return (true, a % b);\n }\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n return a + b;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n return a - b;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n return a * b;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers, reverting on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator.\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n return a / b;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * reverting when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n return a % b;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n * overflow (when the result is negative).\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {trySub}.\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n unchecked {\n require(b <= a, errorMessage);\n return a - b;\n }\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers, reverting with custom message on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n unchecked {\n require(b > 0, errorMessage);\n return a / b;\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * reverting with custom message when dividing by zero.\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {tryMod}.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n unchecked {\n require(b > 0, errorMessage);\n return a % b;\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
}
},
"settings": {
"remappings": [],
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "byzantium",
"libraries": {},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}
}