├── Address.sol ├── BSC TESTNET INFO.txt ├── Context.sol ├── ERC20Token.sol ├── IERC20.sol ├── ILockContract.sol ├── ISellToken.sol ├── Initializable.sol ├── MetaKings.sol ├── Ownable.sol ├── README.md └── SafeMath.sol /Address.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | █▀▄▀█ █▀▀ ▀█▀ ▄▀█ █▄▀ █ █▄░█ █▀▀ █▀ 4 | █░▀░█ ██▄ ░█░ █▀█ █░█ █ █░▀█ █▄█ ▄█ 5 | 6 | Welcome to MetaKings 7 | > 100%Unmintable contract 8 | > 100%Unruggable contract 9 | > Website:https://Metakings.ai 10 | > Telegram:https://t.me/metakings 11 | */ 12 | 13 | pragma solidity >=0.6.2 <0.8.0; 14 | 15 | /** 16 | * @dev Collection of functions related to the address type 17 | */ 18 | library Address { 19 | /** 20 | * @dev Returns true if `account` is a contract. 21 | * 22 | * [IMPORTANT] 23 | * ==== 24 | * It is unsafe to assume that an address for which this function returns 25 | * false is an externally-owned account (EOA) and not a contract. 26 | * 27 | * Among others, `isContract` will return false for the following 28 | * types of addresses: 29 | * 30 | * - an externally-owned account 31 | * - a contract in construction 32 | * - an address where a contract will be created 33 | * - an address where a contract lived, but was destroyed 34 | * ==== 35 | */ 36 | function isContract(address account) internal view returns (bool) { 37 | // This method relies on extcodesize, which returns 0 for contracts in 38 | // construction, since the code is only stored at the end of the 39 | // constructor execution. 40 | 41 | uint256 size; 42 | // solhint-disable-next-line no-inline-assembly 43 | assembly { size := extcodesize(account) } 44 | return size > 0; 45 | } 46 | 47 | /** 48 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 49 | * `recipient`, forwarding all available gas and reverting on errors. 50 | * 51 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 52 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 53 | * imposed by `transfer`, making them unable to receive funds via 54 | * `transfer`. {sendValue} removes this limitation. 55 | * 56 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 57 | * 58 | * IMPORTANT: because control is transferred to `recipient`, care must be 59 | * taken to not create reentrancy vulnerabilities. Consider using 60 | * {ReentrancyGuard} or the 61 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 62 | */ 63 | function sendValue(address payable recipient, uint256 amount) internal { 64 | require(address(this).balance >= amount, "Address: insufficient balance"); 65 | 66 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 67 | (bool success, ) = recipient.call{ value: amount }(""); 68 | require(success, "Address: unable to send value, recipient may have reverted"); 69 | } 70 | 71 | /** 72 | * @dev Performs a Solidity function call using a low level `call`. A 73 | * plain`call` is an unsafe replacement for a function call: use this 74 | * function instead. 75 | * 76 | * If `target` reverts with a revert reason, it is bubbled up by this 77 | * function (like regular Solidity function calls). 78 | * 79 | * Returns the raw returned data. To convert to the expected return value, 80 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 81 | * 82 | * Requirements: 83 | * 84 | * - `target` must be a contract. 85 | * - calling `target` with `data` must not revert. 86 | * 87 | * _Available since v3.1._ 88 | */ 89 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 90 | return functionCall(target, data, "Address: low-level call failed"); 91 | } 92 | 93 | /** 94 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 95 | * `errorMessage` as a fallback revert reason when `target` reverts. 96 | * 97 | * _Available since v3.1._ 98 | */ 99 | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { 100 | return functionCallWithValue(target, data, 0, errorMessage); 101 | } 102 | 103 | /** 104 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 105 | * but also transferring `value` wei to `target`. 106 | * 107 | * Requirements: 108 | * 109 | * - the calling contract must have an ETH balance of at least `value`. 110 | * - the called Solidity function must be `payable`. 111 | * 112 | * _Available since v3.1._ 113 | */ 114 | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { 115 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 116 | } 117 | 118 | /** 119 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 120 | * with `errorMessage` as a fallback revert reason when `target` reverts. 121 | * 122 | * _Available since v3.1._ 123 | */ 124 | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { 125 | require(address(this).balance >= value, "Address: insufficient balance for call"); 126 | require(isContract(target), "Address: call to non-contract"); 127 | 128 | // solhint-disable-next-line avoid-low-level-calls 129 | (bool success, bytes memory returndata) = target.call{ value: value }(data); 130 | return _verifyCallResult(success, returndata, errorMessage); 131 | } 132 | 133 | /** 134 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 135 | * but performing a static call. 136 | * 137 | * _Available since v3.3._ 138 | */ 139 | function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { 140 | return functionStaticCall(target, data, "Address: low-level static call failed"); 141 | } 142 | 143 | /** 144 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 145 | * but performing a static call. 146 | * 147 | * _Available since v3.3._ 148 | */ 149 | function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { 150 | require(isContract(target), "Address: static call to non-contract"); 151 | 152 | // solhint-disable-next-line avoid-low-level-calls 153 | (bool success, bytes memory returndata) = target.staticcall(data); 154 | return _verifyCallResult(success, returndata, errorMessage); 155 | } 156 | 157 | /** 158 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 159 | * but performing a delegate call. 160 | * 161 | * _Available since v3.4._ 162 | */ 163 | function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { 164 | return functionDelegateCall(target, data, "Address: low-level delegate call failed"); 165 | } 166 | 167 | /** 168 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 169 | * but performing a delegate call. 170 | * 171 | * _Available since v3.4._ 172 | */ 173 | function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { 174 | require(isContract(target), "Address: delegate call to non-contract"); 175 | 176 | // solhint-disable-next-line avoid-low-level-calls 177 | (bool success, bytes memory returndata) = target.delegatecall(data); 178 | return _verifyCallResult(success, returndata, errorMessage); 179 | } 180 | 181 | function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { 182 | if (success) { 183 | return returndata; 184 | } else { 185 | // Look for revert reason and bubble it up if present 186 | if (returndata.length > 0) { 187 | // The easiest way to bubble the revert reason is using memory via assembly 188 | 189 | // solhint-disable-next-line no-inline-assembly 190 | assembly { 191 | let returndata_size := mload(returndata) 192 | revert(add(32, returndata), returndata_size) 193 | } 194 | } else { 195 | revert(errorMessage); 196 | } 197 | } 198 | } 199 | } -------------------------------------------------------------------------------- /BSC TESTNET INFO.txt: -------------------------------------------------------------------------------- 1 | https://testnet.bscscan.com/address/0x5Eba8183e6A542c4547383516B2b44E5721AE760#code -------------------------------------------------------------------------------- /Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | █▀▄▀█ █▀▀ ▀█▀ ▄▀█ █▄▀ █ █▄░█ █▀▀ █▀ 4 | █░▀░█ ██▄ ░█░ █▀█ █░█ █ █░▀█ █▄█ ▄█ 5 | 6 | Welcome to MetaKings 7 | > 100%Unmintable contract 8 | > 100%Unruggable contract 9 | > Website:https://Metakings.ai 10 | > Telegram:https://t.me/metakings 11 | */ 12 | 13 | pragma solidity >=0.4.0; 14 | 15 | /* 16 | * @dev Provides information about the current execution context, including the 17 | * sender of the transaction and its data. While these are generally available 18 | * via msg.sender and msg.data, they should not be accessed in such a direct 19 | * manner, since when dealing with GSN meta-transactions the account sending and 20 | * paying for execution may not be the actual sender (as far as an application 21 | * is concerned). 22 | * 23 | * This contract is only required for intermediate, library-like contracts. 24 | */ 25 | contract Context { 26 | // Empty internal constructor, to prevent people from mistakenly deploying 27 | // an instance of this contract, which should be used via inheritance. 28 | constructor() internal {} 29 | 30 | function _msgSender() internal view returns (address payable) { 31 | return msg.sender; 32 | } 33 | 34 | function _msgData() internal view returns (bytes memory) { 35 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 36 | return msg.data; 37 | } 38 | } -------------------------------------------------------------------------------- /ERC20Token.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | █▀▄▀█ █▀▀ ▀█▀ ▄▀█ █▄▀ █ █▄░█ █▀▀ █▀ 4 | █░▀░█ ██▄ ░█░ █▀█ █░█ █ █░▀█ █▄█ ▄█ 5 | 6 | Welcome to MetaKings 7 | > 100%Unmintable contract 8 | > 100%Unruggable contract 9 | > Website:https://Metakings.ai 10 | > Telegram:https://t.me/metakings 11 | */ 12 | pragma solidity >=0.4.0; 13 | 14 | import "./Ownable.sol"; 15 | import "./Context.sol"; 16 | import "./IERC20.sol"; 17 | import "./SafeMath.sol"; 18 | import "./Address.sol"; 19 | import "./ILockContract.sol"; 20 | 21 | /** 22 | * @dev Implementation of the {IERC20} interface. 23 | * 24 | * This implementation is agnostic to the way tokens are created. This means 25 | * that a supply mechanism has to be added in a derived contract using {_mint}. 26 | * For a generic mechanism see {ERC20PresetMinterPauser}. 27 | * 28 | * TIP: For a detailed writeup see our guide 29 | * https://forum.zeppelin.solutions/t/how-to-implement-ERC20-supply-mechanisms/226[How 30 | * to implement supply mechanisms]. 31 | * 32 | * We have followed general OpenZeppelin guidelines: functions revert instead 33 | * of returning `false` on failure. This behavior is nonetheless conventional 34 | * and does not conflict with the expectations of ERC20 applications. 35 | * 36 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 37 | * This allows applications to reconstruct the allowance for all accounts just 38 | * by listening to said events. Other implementations of the EIP may not emit 39 | * these events, as it isn't required by the specification. 40 | * 41 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 42 | * functions have been added to mitigate the well-known issues around setting 43 | * allowances. See {IERC20-approve}. 44 | */ 45 | contract ERC20Token is Context, IERC20, Ownable { 46 | using SafeMath for uint256; 47 | using Address for address; 48 | 49 | mapping(address => uint256) private _balances; 50 | 51 | // mapping (address => UserInfo) todo lock 52 | 53 | mapping(address => mapping(address => uint256)) private _allowances; 54 | 55 | uint256 private _totalSupply; 56 | 57 | string private _name; 58 | string private _symbol; 59 | uint256 private _cap; 60 | uint256 private _transferBurnRate; 61 | mapping(address => uint256) private _transferBurnAddresses; 62 | uint8 private _decimals; 63 | uint256 private _enableFee; 64 | address public devaddr; 65 | 66 | address public LOCK_CONTRACT; 67 | mapping(address => bool) private whiteList; 68 | /** 69 | * @dev Sets the values for {name} and {symbol}, initializes {decimals} with 70 | * a default value of 18. 71 | * 72 | * To select a different value for {decimals}, use {_setupDecimals}. 73 | * 74 | * All three of these values are immutable: they can only be set once during 75 | * construction. 76 | */ 77 | constructor(string memory name, string memory symbol) public { 78 | _name = name; 79 | _symbol = symbol; 80 | _decimals = 18; 81 | _transferBurnRate = 0; 82 | devaddr = msg.sender; 83 | } 84 | 85 | // Update dev address by the previous dev. 86 | function dev(address _devaddr) virtual public { 87 | require(msg.sender == devaddr, "dev: wut?"); 88 | devaddr = _devaddr; 89 | } 90 | 91 | /** 92 | * @dev Returns the bep token owner. 93 | */ 94 | function getOwner() external override view returns (address) { 95 | return owner(); 96 | } 97 | 98 | /** 99 | * @dev Returns the token name. 100 | */ 101 | function name() public override view returns (string memory) { 102 | return _name; 103 | } 104 | 105 | /** 106 | * @dev Returns the token decimals. 107 | */ 108 | function decimals() public override view returns (uint8) { 109 | return _decimals; 110 | } 111 | 112 | /** 113 | * @dev Returns the token symbol. 114 | */ 115 | function symbol() public override view returns (string memory) { 116 | return _symbol; 117 | } 118 | 119 | /** 120 | * @dev See {ERC20-totalSupply}. 121 | */ 122 | function totalSupply() public override view returns (uint256) { 123 | return _totalSupply; 124 | } 125 | 126 | /** 127 | * @dev See {ERC20-balanceOf}. 128 | */ 129 | function balanceOf(address account) public override view returns (uint256) { 130 | return _balances[account]; 131 | } 132 | 133 | /** 134 | * @dev Returns the transfer burn rate. 135 | */ 136 | function transferBurnRate() public view returns (uint256) { 137 | return _transferBurnRate; 138 | } 139 | 140 | /** 141 | * @dev Returns fee state. 142 | */ 143 | function enableFee() public view returns (uint256) { 144 | return _enableFee; 145 | } 146 | 147 | /** 148 | * @dev See {ERC20-transfer}. 149 | * 150 | * Requirements: 151 | * 152 | * - `recipient` cannot be the zero address. 153 | * - the caller must have a balance of at least `amount`. 154 | */ 155 | function transfer(address recipient, uint256 amount) public override returns (bool) { 156 | _transfer(_msgSender(), recipient, amount); 157 | return true; 158 | } 159 | 160 | /** 161 | * @dev See {ERC20-allowance}. 162 | */ 163 | function allowance(address owner, address spender) public override view returns (uint256) { 164 | return _allowances[owner][spender]; 165 | } 166 | 167 | /** 168 | * @dev See {ERC20-approve}. 169 | * 170 | * Requirements: 171 | * 172 | * - `spender` cannot be the zero address. 173 | */ 174 | function approve(address spender, uint256 amount) public override returns (bool) { 175 | _approve(_msgSender(), spender, amount); 176 | return true; 177 | } 178 | 179 | /** 180 | * @dev See {ERC20-transferFrom}. 181 | * 182 | * Emits an {Approval} event indicating the updated allowance. This is not 183 | * required by the EIP. See the note at the beginning of {ERC20}; 184 | * 185 | * Requirements: 186 | * - `sender` and `recipient` cannot be the zero address. 187 | * - `sender` must have a balance of at least `amount`. 188 | * - the caller must have allowance for `sender`'s tokens of at least 189 | * `amount`. 190 | */ 191 | function transferFrom( 192 | address sender, 193 | address recipient, 194 | uint256 amount 195 | ) public override returns (bool) { 196 | _transfer(sender, recipient, amount); 197 | _approve( 198 | sender, 199 | _msgSender(), 200 | _allowances[sender][_msgSender()].sub(amount, 'ERC20: transfer amount exceeds allowance') 201 | ); 202 | return true; 203 | } 204 | 205 | /** 206 | * @dev Atomically increases the allowance granted to `spender` by the caller. 207 | * 208 | * This is an alternative to {approve} that can be used as a mitigation for 209 | * problems described in {ERC20-approve}. 210 | * 211 | * Emits an {Approval} event indicating the updated allowance. 212 | * 213 | * Requirements: 214 | * 215 | * - `spender` cannot be the zero address. 216 | */ 217 | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { 218 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 219 | return true; 220 | } 221 | 222 | /** 223 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 224 | * 225 | * This is an alternative to {approve} that can be used as a mitigation for 226 | * problems described in {ERC20-approve}. 227 | * 228 | * Emits an {Approval} event indicating the updated allowance. 229 | * 230 | * Requirements: 231 | * 232 | * - `spender` cannot be the zero address. 233 | * - `spender` must have allowance for the caller of at least 234 | * `subtractedValue`. 235 | */ 236 | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { 237 | _approve( 238 | _msgSender(), 239 | spender, 240 | _allowances[_msgSender()][spender].sub(subtractedValue, 'ERC20: decreased allowance below zero') 241 | ); 242 | return true; 243 | } 244 | 245 | /** 246 | * @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing 247 | * the total supply. 248 | * 249 | * Requirements 250 | * 251 | * - `msg.sender` must be the token owner 252 | */ 253 | function deploy(uint256 amount) public onlyOwner returns (bool) { 254 | //this mints the initial tokens required for project startup, minting is called just once and is never possible to call again 255 | _mint(_msgSender(), amount); 256 | return true; 257 | } 258 | 259 | function setLockContract(address lockContract) public onlyOwner returns (bool) { 260 | LOCK_CONTRACT = lockContract; //address to distribute bounty tokens. tokens will not be allowed to send or transfer until unlock date. 261 | return true; 262 | } 263 | 264 | function burn(uint256 amount) public returns (bool) { 265 | _burn(_msgSender(), amount); 266 | return true; 267 | } 268 | 269 | /** 270 | * @dev Moves tokens `amount` from `sender` to `recipient`. 271 | * 272 | * This is internal function is equivalent to {transfer}, and can be used to 273 | * e.g. implement automatic token fees, slashing mechanisms, etc. 274 | * 275 | * Emits a {Transfer} event. 276 | * 277 | * Requirements: 278 | * 279 | * - `sender` cannot be the zero address. 280 | * - `recipient` cannot be the zero address. 281 | * - `sender` must have a balance of at least `amount`. 282 | */ 283 | function _transfer( 284 | address sender, 285 | address recipient, 286 | uint256 amount 287 | ) internal virtual { 288 | require(sender != address(0), 'ERC20: transfer from the zero address'); 289 | require(recipient != address(0), 'ERC20: transfer to the zero address'); 290 | 291 | if (_enableFee == 1 || (_transferBurnAddresses[recipient] == 1 && recipient != address(0))) { 292 | uint256 _feeAmount = amount.mul(_transferBurnRate).div(10000); 293 | _burn(sender, _feeAmount); 294 | amount = amount.sub(_feeAmount); 295 | } 296 | if (!whiteList[msg.sender]) { 297 | if (LOCK_CONTRACT != address(0)) { 298 | uint256 receiedAmount = ILockContract(LOCK_CONTRACT).lockedAmount(sender); 299 | if (_balances[sender].sub(amount).sub(receiedAmount) < 0) { 300 | revert(); 301 | } 302 | } 303 | } 304 | 305 | 306 | _balances[sender] = _balances[sender].sub(amount, 'ERC20: transfer amount exceeds balance'); 307 | _balances[recipient] = _balances[recipient].add(amount); 308 | emit Transfer(sender, recipient, amount); 309 | } 310 | 311 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 312 | * the total supply. 313 | * 314 | * Emits a {Transfer} event with `from` set to the zero address. 315 | * 316 | * Requirements 317 | * 318 | * - `to` cannot be the zero address. 319 | */ 320 | function _mint(address account, uint256 amount) internal { 321 | require(account != address(0), 'ERC20: mint to the zero address'); 322 | require(_totalSupply <= 0, 'Tokens have already been minted'); //prevents the dev from minting more tokens. after initial mint. 323 | _totalSupply = _totalSupply.add(amount); 324 | _balances[account] = _balances[account].add(amount); 325 | emit Transfer(address(0), account, amount); 326 | } 327 | 328 | /** 329 | * @dev Destroys `amount` tokens from `account`, reducing the 330 | * total supply. 331 | * 332 | * Emits a {Transfer} event with `to` set to the zero address. 333 | * 334 | * Requirements 335 | * 336 | * - `account` cannot be the zero address. 337 | * - `account` must have at least `amount` tokens. 338 | */ 339 | function _burn(address account, uint256 amount) internal { 340 | require(account != address(0), 'ERC20: burn from the zero address'); 341 | _balances[account] = _balances[account].sub(amount, 'ERC20: burn amount exceeds balance'); 342 | _totalSupply = _totalSupply.sub(amount); 343 | emit Transfer(account, address(0), amount); 344 | } 345 | 346 | /** 347 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 348 | * 349 | * This is internal function is equivalent to `approve`, and can be used to 350 | * e.g. set automatic allowances for certain subsystems, etc. 351 | * 352 | * Emits an {Approval} event. 353 | * 354 | * Requirements: 355 | * 356 | * - `owner` cannot be the zero address. 357 | * - `spender` cannot be the zero address. 358 | */ 359 | function _approve( 360 | address owner, 361 | address spender, 362 | uint256 amount 363 | ) internal { 364 | require(owner != address(0), 'ERC20: approve from the zero address'); 365 | require(spender != address(0), 'ERC20: approve to the zero address'); 366 | 367 | _allowances[owner][spender] = amount; 368 | emit Approval(owner, spender, amount); 369 | } 370 | 371 | /** 372 | * @dev Destroys `amount` tokens from `account`.`amount` is then deducted 373 | * from the caller's allowance. 374 | * 375 | * See {_burn} and {_approve}. 376 | */ 377 | function _burnFrom(address account, uint256 amount) internal { 378 | _burn(account, amount); 379 | _approve( 380 | account, 381 | _msgSender(), 382 | _allowances[account][_msgSender()].sub(amount, 'ERC20: burn amount exceeds allowance') 383 | ); 384 | } 385 | 386 | function _setName(string memory newName) internal { 387 | _name = newName; 388 | } 389 | 390 | function _setSymbol(string memory newSymbol) internal { 391 | _symbol = newSymbol; 392 | } 393 | 394 | function _setDecimals(uint8 newDecimals) internal { 395 | _decimals = newDecimals; 396 | } 397 | 398 | function _setDevAddr(address devAdd) internal { 399 | devaddr = devAdd; 400 | } 401 | 402 | function _setTransferBurnRate(uint8 newTransferBurnRate) internal { 403 | _transferBurnRate = newTransferBurnRate; 404 | } 405 | } -------------------------------------------------------------------------------- /IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | █▀▄▀█ █▀▀ ▀█▀ ▄▀█ █▄▀ █ █▄░█ █▀▀ █▀ 4 | █░▀░█ ██▄ ░█░ █▀█ █░█ █ █░▀█ █▄█ ▄█ 5 | 6 | Welcome to MetaKings 7 | > 100%Unmintable contract 8 | > 100%Unruggable contract 9 | > Website:https://Metakings.ai 10 | > Telegram:https://t.me/metakings 11 | */ 12 | 13 | pragma solidity >=0.4.0; 14 | 15 | interface IERC20 { 16 | /** 17 | * @dev Returns the amount of tokens in existence. 18 | */ 19 | function totalSupply() external view returns (uint256); 20 | 21 | /** 22 | * @dev Returns the token decimals. 23 | */ 24 | function decimals() external view returns (uint8); 25 | 26 | /** 27 | * @dev Returns the token symbol. 28 | */ 29 | function symbol() external view returns (string memory); 30 | 31 | /** 32 | * @dev Returns the token name. 33 | */ 34 | function name() external view returns (string memory); 35 | 36 | /** 37 | * @dev Returns the bep token owner. 38 | */ 39 | function getOwner() external view returns (address); 40 | 41 | /** 42 | * @dev Returns the amount of tokens owned by `account`. 43 | */ 44 | function balanceOf(address account) external view returns (uint256); 45 | 46 | /** 47 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 48 | * 49 | * Returns a boolean value indicating whether the operation succeeded. 50 | * 51 | * Emits a {Transfer} event. 52 | */ 53 | function transfer(address recipient, uint256 amount) external returns (bool); 54 | 55 | /** 56 | * @dev Returns the remaining number of tokens that `spender` will be 57 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 58 | * zero by default. 59 | * 60 | * This value changes when {approve} or {transferFrom} are called. 61 | */ 62 | function allowance(address _owner, address spender) external view returns (uint256); 63 | 64 | /** 65 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 66 | * 67 | * Returns a boolean value indicating whether the operation succeeded. 68 | * 69 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 70 | * that someone may use both the old and the new allowance by unfortunate 71 | * transaction ordering. One possible solution to mitigate this race 72 | * condition is to first reduce the spender's allowance to 0 and set the 73 | * desired value afterwards: 74 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 75 | * 76 | * Emits an {Approval} event. 77 | */ 78 | function approve(address spender, uint256 amount) external returns (bool); 79 | 80 | /** 81 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 82 | * allowance mechanism. `amount` is then deducted from the caller's 83 | * allowance. 84 | * 85 | * Returns a boolean value indicating whether the operation succeeded. 86 | * 87 | * Emits a {Transfer} event. 88 | */ 89 | function transferFrom( 90 | address sender, 91 | address recipient, 92 | uint256 amount 93 | ) external returns (bool); 94 | 95 | /** 96 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 97 | * another (`to`). 98 | * 99 | * Note that `value` may be zero. 100 | */ 101 | event Transfer(address indexed from, address indexed to, uint256 value); 102 | 103 | /** 104 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 105 | * a call to {approve}. `value` is the new allowance. 106 | */ 107 | event Approval(address indexed owner, address indexed spender, uint256 value); 108 | } -------------------------------------------------------------------------------- /ILockContract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | █▀▄▀█ █▀▀ ▀█▀ ▄▀█ █▄▀ █ █▄░█ █▀▀ █▀ 4 | █░▀░█ ██▄ ░█░ █▀█ █░█ █ █░▀█ █▄█ ▄█ 5 | 6 | Welcome to MetaKings 7 | > 100%Unmintable contract 8 | > 100%Unruggable contract 9 | > Website:https://Metakings.ai 10 | > Telegram:https://t.me/metakings 11 | */ 12 | pragma solidity 0.6.12; 13 | 14 | /** 15 | * @dev Interface of the SellToken standard as defined in the EIP. 16 | * From https://github.com/OpenZeppelin/openzeppelin-contracts 17 | */ 18 | interface ILockContract { 19 | /** 20 | * @dev Returns the amount of tokens in existence. 21 | */ 22 | function lockedAmount(address _address) external view returns (uint256); 23 | function updateStakeAirdrop(address _user, uint256 stakeAmount) external; 24 | } -------------------------------------------------------------------------------- /ISellToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | █▀▄▀█ █▀▀ ▀█▀ ▄▀█ █▄▀ █ █▄░█ █▀▀ █▀ 4 | █░▀░█ ██▄ ░█░ █▀█ █░█ █ █░▀█ █▄█ ▄█ 5 | 6 | Welcome to MetaKings 7 | > 100%Unmintable contract 8 | > 100%Unruggable contract 9 | > Website:https://Metakings.ai 10 | > Telegram:https://t.me/metakings 11 | */ 12 | pragma solidity 0.6.12; 13 | 14 | /** 15 | * @dev Interface of the SellToken standard as defined in the EIP. 16 | * From https://github.com/OpenZeppelin/openzeppelin-contracts 17 | */ 18 | interface ISellToken { 19 | /** 20 | * @dev Returns the amount of tokens in existence. 21 | */ 22 | function receivedAmount(address recipient) external view returns (uint256); 23 | 24 | } -------------------------------------------------------------------------------- /Initializable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | █▀▄▀█ █▀▀ ▀█▀ ▄▀█ █▄▀ █ █▄░█ █▀▀ █▀ 4 | █░▀░█ ██▄ ░█░ █▀█ █░█ █ █░▀█ █▄█ ▄█ 5 | 6 | Welcome to MetaKings 7 | > 100%Unmintable contract 8 | > 100%Unruggable contract 9 | > Website:https://Metakings.ai 10 | > Telegram:https://t.me/metakings 11 | */ 12 | 13 | // solhint-disable-next-line compiler-version 14 | pragma solidity >=0.4.24 <0.8.0; 15 | 16 | import "./Address.sol"; 17 | 18 | /** 19 | * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed 20 | * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an 21 | * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer 22 | * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. 23 | * 24 | * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as 25 | * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. 26 | * 27 | * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure 28 | * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. 29 | */ 30 | abstract contract Initializable { 31 | 32 | /** 33 | * @dev Indicates that the contract has been initialized. 34 | */ 35 | bool private _initialized; 36 | 37 | /** 38 | * @dev Indicates that the contract is in the process of being initialized. 39 | */ 40 | bool private _initializing; 41 | 42 | /** 43 | * @dev Modifier to protect an initializer function from being invoked twice. 44 | */ 45 | modifier initializer() { 46 | require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); 47 | 48 | bool isTopLevelCall = !_initializing; 49 | if (isTopLevelCall) { 50 | _initializing = true; 51 | _initialized = true; 52 | } 53 | 54 | _; 55 | 56 | if (isTopLevelCall) { 57 | _initializing = false; 58 | } 59 | } 60 | 61 | /// @dev Returns true if and only if the function is running in the constructor 62 | function _isConstructor() private view returns (bool) { 63 | return !Address.isContract(address(this)); 64 | } 65 | } -------------------------------------------------------------------------------- /MetaKings.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | ░██╗░░░░░░░██╗███████╗  ░█████╗░██████╗░███████╗ 4 | ░██║░░██╗░░██║██╔════╝  ██╔══██╗██╔══██╗██╔════╝ 5 | ░╚██╗████╗██╔╝█████╗░░  ███████║██████╔╝█████╗░░ 6 | ░░████╔═████║░██╔══╝░░  ██╔══██║██╔══██╗██╔══╝░░ 7 | ░░╚██╔╝░╚██╔╝░███████╗  ██║░░██║██║░░██║███████╗ 8 | ░░░╚═╝░░░╚═╝░░╚══════╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚══════╝ 9 | 10 | 11 | ███╗░░░███╗███████╗████████╗░█████╗░██╗░░██╗██╗███╗░░██╗░██████╗░░██████╗ 12 | ████╗░████║██╔════╝╚══██╔══╝██╔══██╗██║░██╔╝██║████╗░██║██╔════╝░██╔════╝ 13 | ██╔████╔██║█████╗░░░░░██║░░░███████║█████═╝░██║██╔██╗██║██║░░██╗░╚█████╗░ 14 | ██║╚██╔╝██║██╔══╝░░░░░██║░░░██╔══██║██╔═██╗░██║██║╚████║██║░░╚██╗░╚═══██╗ 15 | ██║░╚═╝░██║███████╗░░░██║░░░██║░░██║██║░╚██╗██║██║░╚███║╚██████╔╝██████╔╝ 16 | ╚═╝░░░░░╚═╝╚══════╝░░░╚═╝░░░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝╚═╝░░╚══╝░╚═════╝░╚═════╝░ 17 | 18 | Welcome to MetaKings 19 | > 100%Unmintable contract 20 | > 100%Unruggable contract 21 | > Website:https://Metakings.ai 22 | > Telegram:https://t.me/metakings 23 | */ 24 | 25 | pragma solidity 0.6.12; 26 | 27 | import "./ERC20Token.sol"; 28 | import "./ISellToken.sol"; 29 | import "./Initializable.sol"; 30 | 31 | // Token with Governance. 32 | contract MetaKings is ERC20Token, Initializable { 33 | /// @dev owner => next valid nonce to submit with permit() 34 | mapping(address => uint) public _nonces; 35 | bytes32 public constant PERMIT_TYPEHASH = keccak256( 36 | 'Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)' 37 | ); 38 | bytes32 public DOMAIN_SEPARATOR; 39 | 40 | constructor() public ERC20Token('METAKINGS', 'MTK') { 41 | } 42 | 43 | function bootswitch() public initializer { 44 | //We are the Metakings 45 | _setName('METAKINGS'); 46 | _setSymbol('MTK'); 47 | _setDecimals(18); 48 | _setTransferBurnRate(100); 49 | //assign the deployer as the Dev 50 | _setDevAddr(msg.sender); 51 | _setOwner(msg.sender); 52 | 53 | DOMAIN_SEPARATOR = keccak256( 54 | abi.encode( 55 | DOMAIN_TYPEHASH, 56 | keccak256(bytes(name())), 57 | keccak256(bytes('1')), 58 | getChainId(), 59 | address(this) 60 | ) 61 | ); 62 | } 63 | 64 | /** 65 | * @dev Withdraw Token in contract to an address, revert if it fails. 66 | * @param recipient recipient of the transfer 67 | * @param token token withdraw 68 | */ 69 | function withdrawFunc(address recipient, address token) public onlyOwner { 70 | ERC20Token(token).transfer(recipient, ERC20Token(token).balanceOf(address(this))); 71 | } 72 | 73 | 74 | /** 75 | * @dev Withdraw BNB to an address, revert if it fails. 76 | * @param recipient recipient of the transfer 77 | * @param amountBNB amount of the transfer 78 | */ 79 | function withdrawBNB(address recipient, uint256 amountBNB) public onlyOwner { 80 | if (amountBNB > 0) { 81 | _safeTransferBNB(recipient, amountBNB); 82 | } else { 83 | _safeTransferBNB(recipient, address(this).balance); 84 | } 85 | } 86 | 87 | /** 88 | * @dev transfer ETH to an address, revert if it fails. 89 | * @param to recipient of the transfer 90 | * @param value the amount to send 91 | */ 92 | function _safeTransferBNB(address to, uint256 value) internal { 93 | (bool success, ) = to.call{value: value}(new bytes(0)); 94 | require(success, 'BNB_TRANSFER_FAILED'); 95 | } 96 | 97 | // Copied and modified from YAM code: 98 | // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol 99 | // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol 100 | // Which is copied and modified from COMPOUND: 101 | // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol 102 | 103 | /// @dev A record of each accounts delegate 104 | mapping (address => address) internal _delleggates; 105 | 106 | /// @notice A checkpoint for marking number of votes from a given block 107 | struct Checkpoint { 108 | uint32 fromBlock; 109 | uint256 votes; 110 | } 111 | 112 | /// @notice A record of votes checkpoints for each account, by index 113 | mapping (address => mapping (uint32 => Checkpoint)) public checkpoints; 114 | 115 | /// @notice The number of checkpoints for each account 116 | mapping (address => uint32) public numCheckpoints; 117 | 118 | /// @notice The EIP-712 typehash for the contract's domain 119 | bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); 120 | 121 | /// @notice The EIP-712 typehash for the delegation struct used by the contract 122 | bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); 123 | 124 | /// @notice A record of states for signing / validating signatures 125 | mapping (address => uint) public nonces; 126 | 127 | /// @notice An event thats emitted when an account changes its delegate 128 | event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); 129 | 130 | /// @notice An event thats emitted when a delegate account's vote balance changes 131 | event DelegateVotesChangedd(address indexed delegate, uint previousBalance, uint newBalance); 132 | 133 | /** 134 | * @notice Delegate votes from `msg.sender` to `delegatee` 135 | * @param delegator The address to get delegatee for 136 | */ 137 | function delegates(address delegator) 138 | external 139 | view 140 | returns (address) 141 | { 142 | return _delleggates[delegator]; 143 | } 144 | 145 | /** 146 | * @notice Gets the current votes balance for `account` 147 | * @param account The address to get votes balance 148 | * @return The number of current votes for `account` 149 | */ 150 | function getCurrentVotes(address account) 151 | external 152 | view 153 | returns (uint256) 154 | { 155 | uint32 nCheckpoints = numCheckpoints[account]; 156 | return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; 157 | } 158 | 159 | /** 160 | * @notice Determine the prior number of votes for an account as of a block number 161 | * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. 162 | * @param account The address of the account to check 163 | * @param blockNumber The block number to get the vote balance at 164 | * @return The number of votes the account had as of the given block 165 | */ 166 | function getPriorVotes(address account, uint blockNumber) 167 | external 168 | view 169 | returns (uint256) 170 | { 171 | require(blockNumber < block.number, "METAKINGS::getPriorVotes: not yet determined"); 172 | 173 | uint32 nCheckpoints = numCheckpoints[account]; 174 | if (nCheckpoints == 0) { 175 | return 0; 176 | } 177 | 178 | // First check most recent balance 179 | if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { 180 | return checkpoints[account][nCheckpoints - 1].votes; 181 | } 182 | 183 | // Next check implicit zero balance 184 | if (checkpoints[account][0].fromBlock > blockNumber) { 185 | return 0; 186 | } 187 | 188 | uint32 lower = 0; 189 | uint32 upper = nCheckpoints - 1; 190 | while (upper > lower) { 191 | uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow 192 | Checkpoint memory cp = checkpoints[account][center]; 193 | if (cp.fromBlock == blockNumber) { 194 | return cp.votes; 195 | } else if (cp.fromBlock < blockNumber) { 196 | lower = center; 197 | } else { 198 | upper = center - 1; 199 | } 200 | } 201 | return checkpoints[account][lower].votes; 202 | } 203 | 204 | function _delleggate(address delegator, address delegatee) 205 | internal 206 | { 207 | address currentDelegate = _delleggates[delegator]; 208 | uint256 delegatorBalance = balanceOf(delegator); 209 | _delleggates[delegator] = delegatee; 210 | 211 | emit DelegateChanged(delegator, currentDelegate, delegatee); 212 | 213 | _movePreviousDelegates(currentDelegate, delegatee, delegatorBalance); 214 | } 215 | 216 | function _movePreviousDelegates(address srcRep, address dstRep, uint256 amount) internal { 217 | if (srcRep != dstRep && amount > 0) { 218 | if (srcRep != address(0)) { 219 | // decrease old representative 220 | uint32 srcRepNum = numCheckpoints[srcRep]; 221 | uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; 222 | uint256 srcRepNew = srcRepOld.sub(amount); 223 | _writenewCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); 224 | } 225 | 226 | if (dstRep != address(0)) { 227 | // increase new representative 228 | uint32 dstRepNum = numCheckpoints[dstRep]; 229 | uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; 230 | uint256 dstRepNew = dstRepOld.add(amount); 231 | _writenewCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); 232 | } 233 | } 234 | } 235 | 236 | function _writenewCheckpoint( 237 | address delegatee, 238 | uint32 nCheckpoints, 239 | uint256 oldVotes, 240 | uint256 newVotes 241 | ) 242 | internal 243 | { 244 | //Throw error if exceeds 245 | uint32 blockNumber = safe32(block.number, "METAKINGS::_writenewCheckpoint: block number exceeds 32 bits"); 246 | 247 | 248 | if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { 249 | //assign votes deligate, MTK 250 | checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; 251 | } else { 252 | checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); 253 | numCheckpoints[delegatee] = nCheckpoints + 1; 254 | } 255 | //Delegate voting will not be used 256 | emit DelegateVotesChangedd(delegatee, oldVotes, newVotes); 257 | } 258 | 259 | function safe32(uint n, string memory errorMessage) internal pure returns (uint32) { 260 | require(n < 2**32, errorMessage); 261 | return uint32(n); 262 | } 263 | 264 | function getChainId() internal pure returns (uint) { 265 | //generate chainID Internal function not publicly called 266 | uint256 chainId; 267 | //generate chainID Internal function not publicly called 268 | assembly { chainId := chainid() } 269 | 270 | return chainId; 271 | } 272 | 273 | } -------------------------------------------------------------------------------- /Ownable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | █▀▄▀█ █▀▀ ▀█▀ ▄▀█ █▄▀ █ █▄░█ █▀▀ █▀ 4 | █░▀░█ ██▄ ░█░ █▀█ █░█ █ █░▀█ █▄█ ▄█ 5 | 6 | Welcome to MetaKings 7 | > 100%Unmintable contract 8 | > 100%Unruggable contract 9 | > Website:https://Metakings.ai 10 | > Telegram:https://t.me/metakings 11 | */ 12 | pragma solidity >=0.4.0; 13 | 14 | import "./Context.sol"; 15 | 16 | /** 17 | * @dev Contract module which provides a basic access control mechanism, where 18 | * there is an account (an owner) that can be granted exclusive access to 19 | * specific functions. 20 | * 21 | * By default, the owner account will be the one that deploys the contract. This 22 | * can later be changed with {transferOwnership}. 23 | * 24 | * This module is used through inheritance. It will make available the modifier 25 | * `onlyOwner`, which can be applied to your functions to restrict their use to 26 | * the owner. 27 | */ 28 | contract Ownable is Context { 29 | address private _owner; 30 | 31 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 32 | 33 | /** 34 | * @dev Initializes the contract setting the deployer as the initial owner. 35 | */ 36 | constructor() internal { 37 | address msgSender = _msgSender(); 38 | _owner = msgSender; 39 | emit OwnershipTransferred(address(0), msgSender); 40 | } 41 | 42 | function _setOwner(address msgSender) internal { 43 | _owner = msgSender; 44 | emit OwnershipTransferred(address(0), msgSender); 45 | } 46 | 47 | /** 48 | * @dev Returns the address of the current owner. 49 | */ 50 | function owner() public view returns (address) { 51 | return _owner; 52 | } 53 | 54 | /** 55 | * @dev Throws if called by any account other than the owner. 56 | */ 57 | modifier onlyOwner() { 58 | require(_owner == _msgSender(), 'Ownable: caller is not the owner'); 59 | _; 60 | } 61 | 62 | /** 63 | * @dev Leaves the contract without owner. It will not be possible to call 64 | * `onlyOwner` functions anymore. Can only be called by the current owner. 65 | * 66 | * NOTE: Renouncing ownership will leave the contract without an owner, 67 | * thereby removing any functionality that is only available to the owner. 68 | */ 69 | function renounceOwnership() public onlyOwner { 70 | emit OwnershipTransferred(_owner, address(0)); 71 | _owner = address(0); 72 | } 73 | 74 | /** 75 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 76 | * Can only be called by the current owner. 77 | */ 78 | function transferOwnership(address newOwner) public onlyOwner { 79 | _transferOwnership(newOwner); 80 | } 81 | 82 | /** 83 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 84 | */ 85 | function _transferOwnership(address newOwner) internal { 86 | require(newOwner != address(0), 'Ownable: new owner is the zero address'); 87 | emit OwnershipTransferred(_owner, newOwner); 88 | _owner = newOwner; 89 | } 90 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | "# MetaKings-Token-Smart-Contract" 2 | -------------------------------------------------------------------------------- /SafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | /* 3 | █▀▄▀█ █▀▀ ▀█▀ ▄▀█ █▄▀ █ █▄░█ █▀▀ █▀ 4 | █░▀░█ ██▄ ░█░ █▀█ █░█ █ █░▀█ █▄█ ▄█ 5 | 6 | Welcome to MetaKings 7 | > 100%Unmintable contract 8 | > 100%Unruggable contract 9 | > Website:https://Metakings.ai 10 | > Telegram:https://t.me/metakings 11 | */ 12 | 13 | pragma solidity >=0.4.0; 14 | 15 | /** 16 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 17 | * checks. 18 | * 19 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 20 | * in bugs, because programmers usually assume that an overflow raises an 21 | * error, which is the standard behavior in high level programming languages. 22 | * `SafeMath` restores this intuition by reverting the transaction when an 23 | * operation overflows. 24 | * 25 | * Using this library instead of the unchecked operations eliminates an entire 26 | * class of bugs, so it's recommended to use it always. 27 | */ 28 | library SafeMath { 29 | /** 30 | * @dev Returns the addition of two unsigned integers, reverting on 31 | * overflow. 32 | * 33 | * Counterpart to Solidity's `+` operator. 34 | * 35 | * Requirements: 36 | * 37 | * - Addition cannot overflow. 38 | */ 39 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 40 | uint256 c = a + b; 41 | require(c >= a, 'SafeMath: addition overflow'); 42 | 43 | return c; 44 | } 45 | 46 | /** 47 | * @dev Returns the subtraction of two unsigned integers, reverting on 48 | * overflow (when the result is negative). 49 | * 50 | * Counterpart to Solidity's `-` operator. 51 | * 52 | * Requirements: 53 | * 54 | * - Subtraction cannot overflow. 55 | */ 56 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 57 | return sub(a, b, 'SafeMath: subtraction overflow'); 58 | } 59 | 60 | /** 61 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 62 | * overflow (when the result is negative). 63 | * 64 | * Counterpart to Solidity's `-` operator. 65 | * 66 | * Requirements: 67 | * 68 | * - Subtraction cannot overflow. 69 | */ 70 | function sub( 71 | uint256 a, 72 | uint256 b, 73 | string memory errorMessage 74 | ) internal pure returns (uint256) { 75 | require(b <= a, errorMessage); 76 | uint256 c = a - b; 77 | 78 | return c; 79 | } 80 | 81 | /** 82 | * @dev Returns the multiplication of two unsigned integers, reverting on 83 | * overflow. 84 | * 85 | * Counterpart to Solidity's `*` operator. 86 | * 87 | * Requirements: 88 | * 89 | * - Multiplication cannot overflow. 90 | */ 91 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 92 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 93 | // benefit is lost if 'b' is also tested. 94 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 95 | if (a == 0) { 96 | return 0; 97 | } 98 | 99 | uint256 c = a * b; 100 | require(c / a == b, 'SafeMath: multiplication overflow'); 101 | 102 | return c; 103 | } 104 | 105 | /** 106 | * @dev Returns the integer division of two unsigned integers. Reverts on 107 | * division by zero. The result is rounded towards zero. 108 | * 109 | * Counterpart to Solidity's `/` operator. Note: this function uses a 110 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 111 | * uses an invalid opcode to revert (consuming all remaining gas). 112 | * 113 | * Requirements: 114 | * 115 | * - The divisor cannot be zero. 116 | */ 117 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 118 | return div(a, b, 'SafeMath: division by zero'); 119 | } 120 | 121 | /** 122 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 123 | * division by zero. The result is rounded towards zero. 124 | * 125 | * Counterpart to Solidity's `/` operator. Note: this function uses a 126 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 127 | * uses an invalid opcode to revert (consuming all remaining gas). 128 | * 129 | * Requirements: 130 | * 131 | * - The divisor cannot be zero. 132 | */ 133 | function div( 134 | uint256 a, 135 | uint256 b, 136 | string memory errorMessage 137 | ) internal pure returns (uint256) { 138 | require(b > 0, errorMessage); 139 | uint256 c = a / b; 140 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 141 | 142 | return c; 143 | } 144 | 145 | /** 146 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 147 | * Reverts when dividing by zero. 148 | * 149 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 150 | * opcode (which leaves remaining gas untouched) while Solidity uses an 151 | * invalid opcode to revert (consuming all remaining gas). 152 | * 153 | * Requirements: 154 | * 155 | * - The divisor cannot be zero. 156 | */ 157 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 158 | return mod(a, b, 'SafeMath: modulo by zero'); 159 | } 160 | 161 | /** 162 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 163 | * Reverts with custom message when dividing by zero. 164 | * 165 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 166 | * opcode (which leaves remaining gas untouched) while Solidity uses an 167 | * invalid opcode to revert (consuming all remaining gas). 168 | * 169 | * Requirements: 170 | * 171 | * - The divisor cannot be zero. 172 | */ 173 | function mod( 174 | uint256 a, 175 | uint256 b, 176 | string memory errorMessage 177 | ) internal pure returns (uint256) { 178 | require(b != 0, errorMessage); 179 | return a % b; 180 | } 181 | 182 | function min(uint256 x, uint256 y) internal pure returns (uint256 z) { 183 | z = x < y ? x : y; 184 | } 185 | 186 | // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method) 187 | function sqrt(uint256 y) internal pure returns (uint256 z) { 188 | if (y > 3) { 189 | z = y; 190 | uint256 x = y / 2 + 1; 191 | while (x < z) { 192 | z = x; 193 | x = (y / x + x) / 2; 194 | } 195 | } else if (y != 0) { 196 | z = 1; 197 | } 198 | } 199 | } --------------------------------------------------------------------------------