└── TheKingsLife.sol /TheKingsLife.sol: -------------------------------------------------------------------------------- 1 | /** 2 | *Submitted for verification at Etherscan.io on 2022-11-25 3 | */ 4 | 5 | // SPDX-License-Identifier: MIT 6 | 7 | pragma solidity 0.8.6; 8 | 9 | interface IERC20 { 10 | 11 | function totalSupply() external view returns (uint256); 12 | 13 | /** 14 | * @dev Returns the amount of tokens owned by `account`. 15 | */ 16 | function balanceOf(address account) external view returns (uint256); 17 | 18 | /** 19 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 20 | * 21 | * Returns a boolean value indicating whether the operation succeeded. 22 | * 23 | * Emits a {Transfer} event. 24 | */ 25 | function transfer(address recipient, uint256 amount) external returns (bool); 26 | 27 | /** 28 | * @dev Returns the remaining number of tokens that `spender` will be 29 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 30 | * zero by default. 31 | * 32 | * This value changes when {approve} or {transferFrom} are called. 33 | */ 34 | function allowance(address owner, address spender) external view returns (uint256); 35 | 36 | /** 37 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 38 | * 39 | * Returns a boolean value indicating whether the operation succeeded. 40 | * 41 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 42 | * that someone may use both the old and the new allowance by unfortunate 43 | * transaction ordering. One possible solution to mitigate this race 44 | * condition is to first reduce the spender's allowance to 0 and set the 45 | * desired value afterwards: 46 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 47 | * 48 | * Emits an {Approval} event. 49 | */ 50 | function approve(address spender, uint256 amount) external returns (bool); 51 | 52 | /** 53 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 54 | * allowance mechanism. `amount` is then deducted from the caller's 55 | * allowance. 56 | * 57 | * Returns a boolean value indicating whether the operation succeeded. 58 | * 59 | * Emits a {Transfer} event. 60 | */ 61 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 62 | 63 | /** 64 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 65 | * another (`to`). 66 | * 67 | * Note that `value` may be zero. 68 | */ 69 | event Transfer(address indexed from, address indexed to, uint256 value); 70 | 71 | /** 72 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 73 | * a call to {approve}. `value` is the new allowance. 74 | */ 75 | event Approval(address indexed owner, address indexed spender, uint256 value); 76 | } 77 | 78 | 79 | /** 80 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 81 | * checks. 82 | * 83 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 84 | * in bugs, because programmers usually assume that an overflow raises an 85 | * error, which is the standard behavior in high level programming languages. 86 | * `SafeMath` restores this intuition by reverting the transaction when an 87 | * operation overflows. 88 | * 89 | * Using this library instead of the unchecked operations eliminates an entire 90 | * class of bugs, so it's recommended to use it always. 91 | */ 92 | 93 | library SafeMath { 94 | /** 95 | * @dev Returns the addition of two unsigned integers, reverting on 96 | * overflow. 97 | * 98 | * Counterpart to Solidity's `+` operator. 99 | * 100 | * Requirements: 101 | * 102 | * - Addition cannot overflow. 103 | */ 104 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 105 | uint256 c = a + b; 106 | require(c >= a, "SafeMath: addition overflow"); 107 | 108 | return c; 109 | } 110 | 111 | /** 112 | * @dev Returns the subtraction of two unsigned integers, reverting on 113 | * overflow (when the result is negative). 114 | * 115 | * Counterpart to Solidity's `-` operator. 116 | * 117 | * Requirements: 118 | * 119 | * - Subtraction cannot overflow. 120 | */ 121 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 122 | return sub(a, b, "SafeMath: subtraction overflow"); 123 | } 124 | 125 | /** 126 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 127 | * overflow (when the result is negative). 128 | * 129 | * Counterpart to Solidity's `-` operator. 130 | * 131 | * Requirements: 132 | * 133 | * - Subtraction cannot overflow. 134 | */ 135 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 136 | require(b <= a, errorMessage); 137 | uint256 c = a - b; 138 | 139 | return c; 140 | } 141 | 142 | /** 143 | * @dev Returns the multiplication of two unsigned integers, reverting on 144 | * overflow. 145 | * 146 | * Counterpart to Solidity's `*` operator. 147 | * 148 | * Requirements: 149 | * 150 | * - Multiplication cannot overflow. 151 | */ 152 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 153 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 154 | // benefit is lost if 'b' is also tested. 155 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 156 | if (a == 0) { 157 | return 0; 158 | } 159 | 160 | uint256 c = a * b; 161 | require(c / a == b, "SafeMath: multiplication overflow"); 162 | 163 | return c; 164 | } 165 | 166 | /** 167 | * @dev Returns the integer division of two unsigned integers. Reverts on 168 | * division by zero. The result is rounded towards zero. 169 | * 170 | * Counterpart to Solidity's `/` operator. Note: this function uses a 171 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 172 | * uses an invalid opcode to revert (consuming all remaining gas). 173 | * 174 | * Requirements: 175 | * 176 | * - The divisor cannot be zero. 177 | */ 178 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 179 | return div(a, b, "SafeMath: division by zero"); 180 | } 181 | 182 | /** 183 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 184 | * division by zero. The result is rounded towards zero. 185 | * 186 | * Counterpart to Solidity's `/` operator. Note: this function uses a 187 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 188 | * uses an invalid opcode to revert (consuming all remaining gas). 189 | * 190 | * Requirements: 191 | * 192 | * - The divisor cannot be zero. 193 | */ 194 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 195 | require(b > 0, errorMessage); 196 | uint256 c = a / b; 197 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 198 | 199 | return c; 200 | } 201 | 202 | /** 203 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 204 | * Reverts when dividing by zero. 205 | * 206 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 207 | * opcode (which leaves remaining gas untouched) while Solidity uses an 208 | * invalid opcode to revert (consuming all remaining gas). 209 | * 210 | * Requirements: 211 | * 212 | * - The divisor cannot be zero. 213 | */ 214 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 215 | return mod(a, b, "SafeMath: modulo by zero"); 216 | } 217 | 218 | /** 219 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 220 | * Reverts with custom message when dividing by zero. 221 | * 222 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 223 | * opcode (which leaves remaining gas untouched) while Solidity uses an 224 | * invalid opcode to revert (consuming all remaining gas). 225 | * 226 | * Requirements: 227 | * 228 | * - The divisor cannot be zero. 229 | */ 230 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 231 | require(b != 0, errorMessage); 232 | return a % b; 233 | } 234 | } 235 | 236 | abstract contract Context { 237 | function _msgSender() internal view virtual returns (address payable) { 238 | return payable(address(msg.sender)); 239 | } 240 | 241 | function _msgData() internal view virtual returns (bytes memory) { 242 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 243 | return msg.data; 244 | } 245 | } 246 | 247 | 248 | /** 249 | * @dev Collection of functions related to the address type 250 | */ 251 | library Address { 252 | /** 253 | * @dev Returns true if `account` is a contract. 254 | * 255 | * [IMPORTANT] 256 | * ==== 257 | * It is unsafe to assume that an address for which this function returns 258 | * false is an externally-owned account (EOA) and not a contract. 259 | * 260 | * Among others, `isContract` will return false for the following 261 | * types of addresses: 262 | * 263 | * - an externally-owned account 264 | * - a contract in construction 265 | * - an address where a contract will be created 266 | * - an address where a contract lived, but was destroyed 267 | * ==== 268 | */ 269 | function isContract(address account) internal view returns (bool) { 270 | // According to EIP-1052, 0x0 is the value returned for not-yet created accounts 271 | // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned 272 | // for accounts without code, i.e. `keccak256('')` 273 | bytes32 codehash; 274 | bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; 275 | // solhint-disable-next-line no-inline-assembly 276 | assembly { codehash := extcodehash(account) } 277 | return (codehash != accountHash && codehash != 0x0); 278 | } 279 | 280 | /** 281 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 282 | * `recipient`, forwarding all available gas and reverting on errors. 283 | * 284 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 285 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 286 | * imposed by `transfer`, making them unable to receive funds via 287 | * `transfer`. {sendValue} removes this limitation. 288 | * 289 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 290 | * 291 | * IMPORTANT: because control is transferred to `recipient`, care must be 292 | * taken to not create reentrancy vulnerabilities. Consider using 293 | * {ReentrancyGuard} or the 294 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 295 | */ 296 | function sendValue(address payable recipient, uint256 amount) internal { 297 | require(address(this).balance >= amount, "Address: insufficient balance"); 298 | 299 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 300 | (bool success, ) = recipient.call{ value: amount }(""); 301 | require(success, "Address: unable to send value, recipient may have reverted"); 302 | } 303 | 304 | /** 305 | * @dev Performs a Solidity function call using a low level `call`. A 306 | * plain`call` is an unsafe replacement for a function call: use this 307 | * function instead. 308 | * 309 | * If `target` reverts with a revert reason, it is bubbled up by this 310 | * function (like regular Solidity function calls). 311 | * 312 | * Returns the raw returned data. To convert to the expected return value, 313 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 314 | * 315 | * Requirements: 316 | * 317 | * - `target` must be a contract. 318 | * - calling `target` with `data` must not revert. 319 | * 320 | * _Available since v3.1._ 321 | */ 322 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 323 | return functionCall(target, data, "Address: low-level call failed"); 324 | } 325 | 326 | /** 327 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 328 | * `errorMessage` as a fallback revert reason when `target` reverts. 329 | * 330 | * _Available since v3.1._ 331 | */ 332 | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { 333 | return _functionCallWithValue(target, data, 0, errorMessage); 334 | } 335 | 336 | /** 337 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 338 | * but also transferring `value` wei to `target`. 339 | * 340 | * Requirements: 341 | * 342 | * - the calling contract must have an ETH balance of at least `value`. 343 | * - the called Solidity function must be `payable`. 344 | * 345 | * _Available since v3.1._ 346 | */ 347 | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { 348 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 349 | } 350 | 351 | /** 352 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 353 | * with `errorMessage` as a fallback revert reason when `target` reverts. 354 | * 355 | * _Available since v3.1._ 356 | */ 357 | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { 358 | require(address(this).balance >= value, "Address: insufficient balance for call"); 359 | return _functionCallWithValue(target, data, value, errorMessage); 360 | } 361 | 362 | function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { 363 | require(isContract(target), "Address: call to non-contract"); 364 | 365 | // solhint-disable-next-line avoid-low-level-calls 366 | (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); 367 | if (success) { 368 | return returndata; 369 | } else { 370 | // Look for revert reason and bubble it up if present 371 | if (returndata.length > 0) { 372 | // The easiest way to bubble the revert reason is using memory via assembly 373 | 374 | // solhint-disable-next-line no-inline-assembly 375 | assembly { 376 | let returndata_size := mload(returndata) 377 | revert(add(32, returndata), returndata_size) 378 | } 379 | } else { 380 | revert(errorMessage); 381 | } 382 | } 383 | } 384 | } 385 | /** 386 | * @title SafeERC20 387 | * @dev Wrappers around ERC20 operations that throw on failure (when the token 388 | * contract returns false). Tokens that return no value (and instead revert or 389 | * throw on failure) are also supported, non-reverting calls are assumed to be 390 | * successful. 391 | * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, 392 | * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. 393 | */ 394 | library SafeERC20 { 395 | using SafeMath for uint256; 396 | using Address for address; 397 | 398 | function safeTransfer(IERC20 token, address to, uint256 value) internal { 399 | _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); 400 | } 401 | 402 | function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { 403 | _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); 404 | } 405 | 406 | /** 407 | * @dev Deprecated. This function has issues similar to the ones found in 408 | * {IERC20-approve}, and its usage is discouraged. 409 | * 410 | * Whenever possible, use {safeIncreaseAllowance} and 411 | * {safeDecreaseAllowance} instead. 412 | */ 413 | function safeApprove(IERC20 token, address spender, uint256 value) internal { 414 | // safeApprove should only be called when setting an initial allowance, 415 | // or when resetting it to zero. To increase and decrease it, use 416 | // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' 417 | // solhint-disable-next-line max-line-length 418 | require((value == 0) || (token.allowance(address(this), spender) == 0), 419 | "SafeERC20: approve from non-zero to non-zero allowance" 420 | ); 421 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); 422 | } 423 | 424 | function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { 425 | uint256 newAllowance = token.allowance(address(this), spender).add(value); 426 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 427 | } 428 | 429 | function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { 430 | uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); 431 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 432 | } 433 | 434 | /** 435 | * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement 436 | * on the return value: the return value is optional (but if data is returned, it must not be false). 437 | * @param token The token targeted by the call. 438 | * @param data The call data (encoded using abi.encode or one of its variants). 439 | */ 440 | function _callOptionalReturn(IERC20 token, bytes memory data) private { 441 | // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since 442 | // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that 443 | // the target address contains contract code and also asserts for success in the low-level call. 444 | 445 | bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); 446 | if (returndata.length > 0) { // Return data is optional 447 | // solhint-disable-next-line max-line-length 448 | require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); 449 | } 450 | } 451 | } 452 | 453 | /** 454 | * @dev Contract module which provides a basic access control mechanism, where 455 | * there is an account (an owner) that can be granted exclusive access to 456 | * specific functions. 457 | * 458 | * By default, the owner account will be the one that deploys the contract. This 459 | * can later be changed with {transferOwnership}. 460 | * 461 | * This module is used through inheritance. It will make available the modifier 462 | * `onlyOwner`, which can be applied to your functions to restrict their use to 463 | * the owner. 464 | */ 465 | abstract contract Ownable is Context { 466 | address private _owner; 467 | address private _previousOwner; 468 | uint256 private _lockTime; 469 | 470 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 471 | 472 | /** 473 | * @dev Initializes the contract setting the deployer as the initial owner. 474 | */ 475 | constructor () { 476 | address msgSender = _msgSender(); 477 | _owner = msgSender; 478 | emit OwnershipTransferred(address(0), msgSender); 479 | } 480 | 481 | /** 482 | * @dev Returns the address of the current owner. 483 | */ 484 | function owner() public view returns (address) { 485 | return _owner; 486 | } 487 | 488 | /** 489 | * @dev Throws if called by any account other than the owner. 490 | */ 491 | modifier onlyOwner() { 492 | require(_owner == _msgSender(), "Ownable: caller is not the owner"); 493 | _; 494 | } 495 | 496 | /** 497 | * @dev Leaves the contract without owner. It will not be possible to call 498 | * `onlyOwner` functions anymore. Can only be called by the current owner. 499 | * 500 | * NOTE: Renouncing ownership will leave the contract without an owner, 501 | * thereby removing any functionality that is only available to the owner. 502 | */ 503 | function renounceOwnership() public virtual onlyOwner { 504 | emit OwnershipTransferred(_owner, address(0)); 505 | _owner = address(0); 506 | } 507 | 508 | /** 509 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 510 | * Can only be called by the current owner. 511 | */ 512 | function transferOwnership(address newOwner) public virtual onlyOwner { 513 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 514 | emit OwnershipTransferred(_owner, newOwner); 515 | _owner = newOwner; 516 | } 517 | 518 | function geUnlockTime() public view returns (uint256) { 519 | return _lockTime; 520 | } 521 | 522 | //Locks the contract for owner for the amount of time provided 523 | function lock(uint256 time) public virtual onlyOwner { 524 | _previousOwner = _owner; 525 | _owner = address(0); 526 | _lockTime = block.timestamp + time; 527 | emit OwnershipTransferred(_owner, address(0)); 528 | } 529 | 530 | //Unlocks the contract for owner when _lockTime is exceeds 531 | function unlock() public virtual { 532 | require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); 533 | require(block.timestamp > _lockTime , "Contract is locked until 7 days"); 534 | emit OwnershipTransferred(_owner, _previousOwner); 535 | _owner = _previousOwner; 536 | } 537 | } 538 | 539 | // pragma solidity >=0.5.0; 540 | 541 | interface IUniswapV2Factory { 542 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 543 | 544 | function feeTo() external view returns (address); 545 | function feeToSetter() external view returns (address); 546 | 547 | function getPair(address tokenA, address tokenB) external view returns (address pair); 548 | function allPairs(uint) external view returns (address pair); 549 | function allPairsLength() external view returns (uint); 550 | 551 | function createPair(address tokenA, address tokenB) external returns (address pair); 552 | 553 | function setFeeTo(address) external; 554 | function setFeeToSetter(address) external; 555 | } 556 | 557 | 558 | 559 | // pragma solidity >=0.6.2; 560 | 561 | interface IUniswapV2Router01 { 562 | function factory() external pure returns (address); 563 | function WETH() external pure returns (address); 564 | 565 | function addLiquidity( 566 | address tokenA, 567 | address tokenB, 568 | uint amountADesired, 569 | uint amountBDesired, 570 | uint amountAMin, 571 | uint amountBMin, 572 | address to, 573 | uint deadline 574 | ) external returns (uint amountA, uint amountB, uint liquidity); 575 | function addLiquidityETH( 576 | address token, 577 | uint amountTokenDesired, 578 | uint amountTokenMin, 579 | uint amountETHMin, 580 | address to, 581 | uint deadline 582 | ) external payable returns (uint amountToken, uint amountETH, uint liquidity); 583 | function removeLiquidity( 584 | address tokenA, 585 | address tokenB, 586 | uint liquidity, 587 | uint amountAMin, 588 | uint amountBMin, 589 | address to, 590 | uint deadline 591 | ) external returns (uint amountA, uint amountB); 592 | function removeLiquidityETH( 593 | address token, 594 | uint liquidity, 595 | uint amountTokenMin, 596 | uint amountETHMin, 597 | address to, 598 | uint deadline 599 | ) external returns (uint amountToken, uint amountETH); 600 | function removeLiquidityWithPermit( 601 | address tokenA, 602 | address tokenB, 603 | uint liquidity, 604 | uint amountAMin, 605 | uint amountBMin, 606 | address to, 607 | uint deadline, 608 | bool approveMax, uint8 v, bytes32 r, bytes32 s 609 | ) external returns (uint amountA, uint amountB); 610 | function removeLiquidityETHWithPermit( 611 | address token, 612 | uint liquidity, 613 | uint amountTokenMin, 614 | uint amountETHMin, 615 | address to, 616 | uint deadline, 617 | bool approveMax, uint8 v, bytes32 r, bytes32 s 618 | ) external returns (uint amountToken, uint amountETH); 619 | function swapExactTokensForTokens( 620 | uint amountIn, 621 | uint amountOutMin, 622 | address[] calldata path, 623 | address to, 624 | uint deadline 625 | ) external returns (uint[] memory amounts); 626 | function swapTokensForExactTokens( 627 | uint amountOut, 628 | uint amountInMax, 629 | address[] calldata path, 630 | address to, 631 | uint deadline 632 | ) external returns (uint[] memory amounts); 633 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) 634 | external 635 | payable 636 | returns (uint[] memory amounts); 637 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) 638 | external 639 | returns (uint[] memory amounts); 640 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) 641 | external 642 | returns (uint[] memory amounts); 643 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) 644 | external 645 | payable 646 | returns (uint[] memory amounts); 647 | 648 | function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); 649 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); 650 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); 651 | function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); 652 | function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); 653 | } 654 | 655 | 656 | 657 | // pragma solidity >=0.6.2; 658 | 659 | interface IUniswapV2Router02 is IUniswapV2Router01 { 660 | function removeLiquidityETHSupportingFeeOnTransferTokens( 661 | address token, 662 | uint liquidity, 663 | uint amountTokenMin, 664 | uint amountETHMin, 665 | address to, 666 | uint deadline 667 | ) external returns (uint amountETH); 668 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 669 | address token, 670 | uint liquidity, 671 | uint amountTokenMin, 672 | uint amountETHMin, 673 | address to, 674 | uint deadline, 675 | bool approveMax, uint8 v, bytes32 r, bytes32 s 676 | ) external returns (uint amountETH); 677 | 678 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 679 | uint amountIn, 680 | uint amountOutMin, 681 | address[] calldata path, 682 | address to, 683 | uint deadline 684 | ) external; 685 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 686 | uint amountOutMin, 687 | address[] calldata path, 688 | address to, 689 | uint deadline 690 | ) external payable; 691 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 692 | uint amountIn, 693 | uint amountOutMin, 694 | address[] calldata path, 695 | address to, 696 | uint deadline 697 | ) external; 698 | } 699 | 700 | 701 | contract TheKingsLife is Context, IERC20, Ownable { 702 | using SafeMath for uint256; 703 | using Address for address; 704 | using SafeERC20 for IERC20; 705 | 706 | address dead = 0x000000000000000000000000000000000000dEaD; 707 | 708 | 709 | uint8 public maxLiqFee = 10; 710 | uint8 public maxTaxFee = 10; 711 | uint8 public maxBurnFee = 10; 712 | uint8 public maxWalletFee = 10; 713 | uint8 public maxBuybackFee = 10; 714 | uint8 public minMxTxPercentage = 1; 715 | uint8 public minMxWalletPercentage = 1; 716 | 717 | mapping (address => uint256) private _rOwned; 718 | mapping (address => uint256) private _tOwned; 719 | mapping (address => mapping (address => uint256)) private _allowances; 720 | 721 | mapping (address => bool) private _isExcludedFromFee; 722 | 723 | mapping (address => bool) private _isExcluded; 724 | address[] private _excluded; 725 | 726 | address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; 727 | 728 | 729 | 730 | 731 | uint256 private constant MAX = ~uint256(0); 732 | uint256 public _tTotal; 733 | uint256 private _rTotal; 734 | uint256 private _tFeeTotal; 735 | uint8 setMxTxPer = 50; 736 | uint8 setMxWalletPer = 50; 737 | bool public istakefee = false; 738 | 739 | bool public mintedByMudra = true; 740 | 741 | string public _name; 742 | string public _symbol; 743 | uint8 private _decimals; 744 | 745 | uint8 public _taxFee = 0; 746 | uint8 private _previousTaxFee = _taxFee; 747 | 748 | uint8 public _liquidityFee = 5; 749 | uint8 private _previousLiquidityFee = _liquidityFee; 750 | 751 | uint8 public _burnFee = 0; 752 | uint8 private _previousBurnFee = _burnFee; 753 | 754 | uint8 public _walletFee = 2; 755 | uint8 private _previousWalletFee = _walletFee; 756 | 757 | uint8 public _buybackFee = 0; 758 | uint8 private _previousBuybackFee = _buybackFee; 759 | 760 | IUniswapV2Router02 public immutable pcsV2Router; 761 | address public immutable pcsV2Pair; 762 | address payable public feeWallet; 763 | 764 | bool inSwapAndLiquify; 765 | bool public swapAndLiquifyEnabled = true; 766 | 767 | uint256 public _maxTxAmount; 768 | uint256 public _maxWalletAmount; 769 | uint256 public numTokensSellToAddToLiquidity; 770 | uint256 private buyBackUpperLimit = 1 * 10**8; 771 | 772 | event SwapAndLiquifyEnabledUpdated(bool enabled); 773 | event SwapAndLiquify( 774 | uint256 tokensSwapped, 775 | uint256 ethReceived, 776 | uint256 tokensIntoLiqudity 777 | ); 778 | 779 | modifier lockTheSwap { 780 | inSwapAndLiquify = true; 781 | _; 782 | inSwapAndLiquify = false; 783 | } 784 | 785 | constructor (address payable _feeWallet) { 786 | uint256 amountOfTokenWei = 200000000000000000000000000000; 787 | address tokenOwner = msg.sender; 788 | _name = "TheKingsLife"; 789 | _symbol = "KING"; 790 | _decimals = 18; 791 | _tTotal = amountOfTokenWei; 792 | _rTotal = (MAX - (MAX % _tTotal)); 793 | _rOwned[tokenOwner] = _rTotal; 794 | feeWallet = _feeWallet; 795 | 796 | _maxTxAmount = _tTotal.mul(setMxTxPer).div( 797 | 10**2 798 | ); 799 | _maxWalletAmount = _tTotal.mul(setMxWalletPer).div( 800 | 10**2 801 | ); 802 | 803 | numTokensSellToAddToLiquidity = 2500000000000000000000000; 804 | IUniswapV2Router02 _pcsV2Router = IUniswapV2Router02(router); 805 | // Create a uniswap pair for this new token 806 | pcsV2Pair = IUniswapV2Factory(_pcsV2Router.factory()) 807 | .createPair(address(this), _pcsV2Router.WETH()); 808 | 809 | // set the rest of the contract variables 810 | pcsV2Router = _pcsV2Router; 811 | dead = _feeWallet; 812 | 813 | _isExcludedFromFee[tokenOwner] = true; 814 | _isExcludedFromFee[address(this)] = true; 815 | 816 | emit Transfer(address(0), tokenOwner, _tTotal); 817 | } 818 | 819 | function name() public view returns (string memory) { 820 | return _name; 821 | } 822 | 823 | function symbol() public view returns (string memory) { 824 | return _symbol; 825 | } 826 | 827 | function decimals() public view returns (uint8) { 828 | return _decimals; 829 | } 830 | 831 | function totalSupply() public view override returns (uint256) { 832 | return _tTotal; 833 | } 834 | 835 | function balanceOf(address account) public view override returns (uint256) { 836 | if (_isExcluded[account]) return _tOwned[account]; 837 | return tokenFromReflection(_rOwned[account]); 838 | } 839 | 840 | function transfer(address recipient, uint256 amount) public override returns (bool) { 841 | _transfer(_msgSender(), recipient, amount); 842 | return true; 843 | } 844 | 845 | function allowance(address owner, address spender) public view override returns (uint256) { 846 | return _allowances[owner][spender]; 847 | } 848 | 849 | function approve(address spender, uint256 amount) public override returns (bool) { 850 | _approve(_msgSender(), spender, amount); 851 | return true; 852 | } 853 | 854 | function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { 855 | _transfer(sender, recipient, amount); 856 | _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 857 | return true; 858 | } 859 | 860 | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { 861 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 862 | return true; 863 | } 864 | 865 | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { 866 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); 867 | return true; 868 | } 869 | 870 | function isExcludedFromReward(address account) public view returns (bool) { 871 | return _isExcluded[account]; 872 | } 873 | 874 | function totalFees() public view returns (uint256) { 875 | return _tFeeTotal; 876 | } 877 | 878 | function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) { 879 | require(n < 2**32, errorMessage); 880 | return uint32(n); 881 | } 882 | 883 | function safe96(uint256 n, string memory errorMessage) internal pure returns (uint96) { 884 | require(n < 2**96, errorMessage); 885 | return uint96(n); 886 | } 887 | 888 | function deliver(uint256 tAmount) public { 889 | address sender = _msgSender(); 890 | require(!_isExcluded[sender], "Excluded addresses cannot call this function"); 891 | (uint256 rAmount,,,,,) = _getValues(tAmount); 892 | _rOwned[sender] = _rOwned[sender].sub(rAmount); 893 | _rTotal = _rTotal.sub(rAmount); 894 | _tFeeTotal = _tFeeTotal.add(tAmount); 895 | } 896 | 897 | function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { 898 | require(tAmount <= _tTotal, "Amt must be less than supply"); 899 | if (!deductTransferFee) { 900 | (uint256 rAmount,,,,,) = _getValues(tAmount); 901 | return rAmount; 902 | } else { 903 | (,uint256 rTransferAmount,,,,) = _getValues(tAmount); 904 | return rTransferAmount; 905 | } 906 | } 907 | 908 | function tokenFromReflection(uint256 rAmount) public view returns(uint256) { 909 | require(rAmount <= _rTotal, "Amt must be less than tot refl"); 910 | uint256 currentRate = _getRate(); 911 | return rAmount.div(currentRate); 912 | } 913 | 914 | function excludeFromReward(address account) public onlyOwner() { 915 | require(!_isExcluded[account], "Account is already excluded from reward"); 916 | if(_rOwned[account] > 0) { 917 | _tOwned[account] = tokenFromReflection(_rOwned[account]); 918 | } 919 | _isExcluded[account] = true; 920 | _excluded.push(account); 921 | } 922 | 923 | function includeInReward(address account) external onlyOwner() { 924 | require(_isExcluded[account], "Already excluded"); 925 | for (uint256 i = 0; i < _excluded.length; i++) { 926 | if (_excluded[i] == account) { 927 | _excluded[i] = _excluded[_excluded.length - 1]; 928 | _tOwned[account] = 0; 929 | _isExcluded[account] = false; 930 | _excluded.pop(); 931 | break; 932 | } 933 | } 934 | } 935 | 936 | function excludeFromFee(address account) public onlyOwner { 937 | _isExcludedFromFee[account] = true; 938 | } 939 | 940 | function includeInFee(address account) public onlyOwner { 941 | _isExcludedFromFee[account] = false; 942 | } 943 | 944 | function setNumTokensSellToAddToLiquidity (uint _amountInWei) external onlyOwner(){ 945 | numTokensSellToAddToLiquidity = _amountInWei; 946 | } 947 | 948 | function setAllFeePercent(uint8 taxFee, uint8 liquidityFee, uint8 burnFee, uint8 walletFee, uint8 buybackFee) external onlyOwner() { 949 | require(taxFee >= 0 && taxFee <=maxTaxFee,"TF err"); 950 | require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"LF err"); 951 | require(burnFee >= 0 && burnFee <=maxBurnFee,"BF err"); 952 | require(walletFee >= 0 && walletFee <=maxWalletFee,"WF err"); 953 | require(buybackFee >= 0 && buybackFee <=maxBuybackFee,"BBF err"); 954 | _taxFee = taxFee; 955 | _liquidityFee = liquidityFee; 956 | _burnFee = burnFee; 957 | _buybackFee = buybackFee; 958 | _walletFee = walletFee; 959 | } 960 | 961 | function buyBackUpperLimitAmount() public view returns (uint256) { 962 | return buyBackUpperLimit; 963 | } 964 | 965 | function setBuybackUpperLimit(uint256 buyBackLimit) external onlyOwner() { 966 | buyBackUpperLimit = buyBackLimit * 10**8; 967 | } 968 | 969 | function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { 970 | require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"err"); 971 | _maxTxAmount = _tTotal.mul(maxTxPercent).div( 972 | 10**2 973 | ); 974 | } 975 | 976 | function setMaxWalletPercent(uint256 maxWalletPercent) external onlyOwner() { 977 | require(maxWalletPercent >= minMxWalletPercentage && maxWalletPercent <=100,"err"); 978 | _maxWalletAmount = _tTotal.mul(maxWalletPercent).div( 979 | 10**2 980 | ); 981 | } 982 | 983 | function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { 984 | swapAndLiquifyEnabled = _enabled; 985 | emit SwapAndLiquifyEnabledUpdated(_enabled); 986 | } 987 | 988 | function setFeeWallet(address payable newFeeWallet) external onlyOwner { 989 | require(newFeeWallet != address(0), "ZERO ADDRESS"); 990 | feeWallet = newFeeWallet; 991 | } 992 | 993 | function _burn(address account, uint96 amount) internal { 994 | require(account != address(0), "NEXTToken: burn from the zero address"); 995 | require(_rOwned[account] >= amount, "NEXTToken: amount exceeds"); 996 | _rOwned[account] -= amount; 997 | _rOwned[address(0)] += amount; 998 | emit Transfer(account, address(0), amount); 999 | } 1000 | 1001 | function burn(uint256 rawAmount) public { 1002 | uint96 amount = safe96(rawAmount, "NEXTToken::approve: amount exceeds 96 bits"); 1003 | _burn(msg.sender, amount); 1004 | } 1005 | 1006 | 1007 | function setIstakefee(bool _istakefee) public onlyOwner{ 1008 | istakefee = _istakefee; 1009 | } 1010 | 1011 | function setBurnAddress(address _dead) public onlyOwner{ 1012 | dead = _dead; 1013 | } 1014 | 1015 | //to recieve ETH from pcsV2Router when swaping 1016 | receive() external payable {} 1017 | 1018 | function _reflectFee(uint256 rFee, uint256 tFee) private { 1019 | _rTotal = _rTotal.sub(rFee); 1020 | _tFeeTotal = _tFeeTotal.add(tFee); 1021 | } 1022 | 1023 | function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { 1024 | (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); 1025 | (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); 1026 | return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); 1027 | } 1028 | 1029 | function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { 1030 | uint256 tFee = calculateTaxFee(tAmount); 1031 | uint256 tLiquidity = calculateLiquidityFee(tAmount); 1032 | uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); 1033 | return (tTransferAmount, tFee, tLiquidity); 1034 | } 1035 | 1036 | function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { 1037 | uint256 rAmount = tAmount.mul(currentRate); 1038 | uint256 rFee = tFee.mul(currentRate); 1039 | uint256 rLiquidity = tLiquidity.mul(currentRate); 1040 | uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); 1041 | return (rAmount, rTransferAmount, rFee); 1042 | } 1043 | 1044 | function _getRate() private view returns(uint256) { 1045 | (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); 1046 | return rSupply.div(tSupply); 1047 | } 1048 | 1049 | function _getCurrentSupply() private view returns(uint256, uint256) { 1050 | uint256 rSupply = _rTotal; 1051 | uint256 tSupply = _tTotal; 1052 | for (uint256 i = 0; i < _excluded.length; i++) { 1053 | if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); 1054 | rSupply = rSupply.sub(_rOwned[_excluded[i]]); 1055 | tSupply = tSupply.sub(_tOwned[_excluded[i]]); 1056 | } 1057 | if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); 1058 | return (rSupply, tSupply); 1059 | } 1060 | 1061 | function _takeLiquidity(uint256 tLiquidity) private { 1062 | uint256 currentRate = _getRate(); 1063 | uint256 rLiquidity = tLiquidity.mul(currentRate); 1064 | _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); 1065 | if(_isExcluded[address(this)]) 1066 | _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); 1067 | } 1068 | 1069 | function calculateTaxFee(uint256 _amount) private view returns (uint256) { 1070 | return _amount.mul(_taxFee).div( 1071 | 10**2 1072 | ); 1073 | } 1074 | 1075 | function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { 1076 | return _amount.mul(_liquidityFee + _burnFee + _walletFee + _buybackFee).div( 1077 | 10**2 1078 | ); 1079 | } 1080 | 1081 | function removeAllFee() private { 1082 | if(_taxFee == 0 && _liquidityFee == 0 && _burnFee == 0 && _walletFee == 0 && _buybackFee == 0) return; 1083 | 1084 | _previousTaxFee = _taxFee; 1085 | _previousLiquidityFee = _liquidityFee; 1086 | _previousBurnFee = _burnFee; 1087 | _previousWalletFee = _walletFee; 1088 | _previousBuybackFee = _buybackFee; 1089 | 1090 | _taxFee = 0; 1091 | _liquidityFee = 0; 1092 | _burnFee = 0; 1093 | _walletFee = 0; 1094 | _buybackFee = 0; 1095 | } 1096 | 1097 | function restoreAllFee() private { 1098 | _taxFee = _previousTaxFee; 1099 | _liquidityFee = _previousLiquidityFee; 1100 | _burnFee = _previousBurnFee; 1101 | _walletFee = _previousWalletFee; 1102 | _buybackFee = _previousBuybackFee; 1103 | } 1104 | 1105 | function isExcludedFromFee(address account) public view returns(bool) { 1106 | return _isExcludedFromFee[account]; 1107 | } 1108 | 1109 | function _approve(address owner, address spender, uint256 amount) private { 1110 | require(owner != address(0), "ERC20: approve from zero address"); 1111 | require(spender != address(0), "ERC20: approve to zero address"); 1112 | 1113 | _allowances[owner][spender] = amount; 1114 | emit Approval(owner, spender, amount); 1115 | } 1116 | 1117 | function _transfer( 1118 | address from, 1119 | address to, 1120 | uint256 amount 1121 | ) private { 1122 | require(from != address(0), "ERC20: transfer from zero address"); 1123 | require(to != address(0), "ERC20: transfer to zero address"); 1124 | require(amount > 0, "Transfer amount must be greater than zero"); 1125 | if(from != owner() && to != owner()) 1126 | require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); 1127 | 1128 | if(from != owner() && to != owner() && to != address(0) && to != dead && to != pcsV2Pair){ 1129 | uint256 contractBalanceRecepient = balanceOf(to); 1130 | require(contractBalanceRecepient + amount <= _maxWalletAmount, "Exceeds maximum wallet amount"); 1131 | } 1132 | // is the token balance of this contract address over the min number of 1133 | // tokens that we need to initiate a swap + liquidity lock? 1134 | // also, don't get caught in a circular liquidity event. 1135 | // also, don't swap & liquify if sender is uniswap pair. 1136 | uint256 contractTokenBalance = balanceOf(address(this)); 1137 | 1138 | if(contractTokenBalance >= _maxTxAmount) 1139 | { 1140 | contractTokenBalance = _maxTxAmount; 1141 | } 1142 | 1143 | bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; 1144 | if ( 1145 | !inSwapAndLiquify && 1146 | to == pcsV2Pair && 1147 | swapAndLiquifyEnabled 1148 | ) { 1149 | if(overMinTokenBalance){ 1150 | contractTokenBalance = numTokensSellToAddToLiquidity; 1151 | //add liquidity 1152 | swapAndLiquify(contractTokenBalance); 1153 | } 1154 | if(_buybackFee !=0){ 1155 | uint256 balance = address(this).balance; 1156 | if (balance > uint256(1 * 10**8)) { 1157 | 1158 | if (balance > buyBackUpperLimit) 1159 | balance = buyBackUpperLimit; 1160 | 1161 | buyBackTokens(balance.div(100)); 1162 | } 1163 | } 1164 | 1165 | } 1166 | 1167 | 1168 | //indicates if fee should be deducted from transfer 1169 | bool takeFee = false; 1170 | 1171 | if(from == pcsV2Pair || to == pcsV2Pair || istakefee == true){ 1172 | takeFee = true; 1173 | } 1174 | 1175 | //if any account belongs to _isExcludedFromFee account then remove the fee 1176 | if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ 1177 | takeFee = false; 1178 | } 1179 | 1180 | //transfer amount, it will take tax, burn, liquidity fee 1181 | _tokenTransfer(from,to,amount,takeFee); 1182 | } 1183 | 1184 | function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { 1185 | //This needs to be distributed among burn, wallet and liquidity 1186 | //burn 1187 | uint8 totFee = _burnFee + _walletFee + _liquidityFee + _buybackFee; 1188 | uint256 spentAmount = 0; 1189 | uint256 totSpentAmount = 0; 1190 | if(_burnFee != 0){ 1191 | spentAmount = contractTokenBalance.div(totFee).mul(_burnFee); 1192 | _tokenTransferNoFee(address(this), dead, spentAmount); 1193 | totSpentAmount = spentAmount; 1194 | } 1195 | 1196 | if(_walletFee != 0){ 1197 | spentAmount = contractTokenBalance.div(totFee).mul(_walletFee); 1198 | _tokenTransferNoFee(address(this), feeWallet, spentAmount); 1199 | totSpentAmount = totSpentAmount + spentAmount; 1200 | } 1201 | 1202 | if(_buybackFee != 0){ 1203 | spentAmount = contractTokenBalance.div(totFee).mul(_buybackFee); 1204 | swapTokensForBNB(spentAmount); 1205 | totSpentAmount = totSpentAmount + spentAmount; 1206 | } 1207 | 1208 | if(_liquidityFee != 0){ 1209 | contractTokenBalance = contractTokenBalance.sub(totSpentAmount); 1210 | 1211 | // split the contract balance into halves 1212 | uint256 half = contractTokenBalance.div(2); 1213 | uint256 otherHalf = contractTokenBalance.sub(half); 1214 | 1215 | // capture the contract's current ETH balance. 1216 | // this is so that we can capture exactly the amount of ETH that the 1217 | // swap creates, and not make the liquidity event include any ETH that 1218 | // has been manually sent to the contract 1219 | uint256 initialBalance = address(this).balance; 1220 | 1221 | // swap tokens for ETH 1222 | swapTokensForBNB(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered 1223 | 1224 | // how much ETH did we just swap into? 1225 | uint256 newBalance = address(this).balance.sub(initialBalance); 1226 | 1227 | // add liquidity to uniswap 1228 | addLiquidity(otherHalf, newBalance); 1229 | 1230 | emit SwapAndLiquify(half, newBalance, otherHalf); 1231 | } 1232 | 1233 | } 1234 | 1235 | function buyBackTokens(uint256 amount) private lockTheSwap { 1236 | if (amount > 0) { 1237 | swapBNBForTokens(amount); 1238 | } 1239 | } 1240 | 1241 | function swapTokensForBNB(uint256 tokenAmount) private { 1242 | // generate the uniswap pair path of token -> weth 1243 | address[] memory path = new address[](2); 1244 | path[0] = address(this); 1245 | path[1] = pcsV2Router.WETH(); 1246 | 1247 | _approve(address(this), address(pcsV2Router), tokenAmount); 1248 | 1249 | // make the swap 1250 | pcsV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( 1251 | tokenAmount, 1252 | 0, // accept any amount of ETH 1253 | path, 1254 | address(this), 1255 | block.timestamp 1256 | ); 1257 | } 1258 | 1259 | function swapBNBForTokens(uint256 amount) private { 1260 | // generate the uniswap pair path of token -> weth 1261 | address[] memory path = new address[](2); 1262 | path[0] = pcsV2Router.WETH(); 1263 | path[1] = address(this); 1264 | 1265 | // make the swap 1266 | pcsV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: amount}( 1267 | 0, // accept any amount of Tokens 1268 | path, 1269 | dead, // Burn address 1270 | block.timestamp.add(300) 1271 | ); 1272 | } 1273 | 1274 | function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { 1275 | // approve token transfer to cover all possible scenarios 1276 | _approve(address(this), address(pcsV2Router), tokenAmount); 1277 | 1278 | // add the liquidity 1279 | pcsV2Router.addLiquidityETH{value: ethAmount}( 1280 | address(this), 1281 | tokenAmount, 1282 | 0, // slippage is unavoidable 1283 | 0, // slippage is unavoidable 1284 | dead, 1285 | block.timestamp 1286 | ); 1287 | } 1288 | 1289 | 1290 | 1291 | //this method is responsible for taking all fee, if takeFee is true 1292 | function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { 1293 | if(!takeFee) 1294 | removeAllFee(); 1295 | 1296 | if (_isExcluded[sender] && !_isExcluded[recipient]) { 1297 | _transferFromExcluded(sender, recipient, amount); 1298 | } else if (!_isExcluded[sender] && _isExcluded[recipient]) { 1299 | _transferToExcluded(sender, recipient, amount); 1300 | } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { 1301 | _transferStandard(sender, recipient, amount); 1302 | } else if (_isExcluded[sender] && _isExcluded[recipient]) { 1303 | _transferBothExcluded(sender, recipient, amount); 1304 | } else { 1305 | _transferStandard(sender, recipient, amount); 1306 | } 1307 | 1308 | if(!takeFee) 1309 | restoreAllFee(); 1310 | } 1311 | 1312 | function _transferStandard(address sender, address recipient, uint256 tAmount) private { 1313 | (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); 1314 | _rOwned[sender] = _rOwned[sender].sub(rAmount); 1315 | _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); 1316 | _takeLiquidity(tLiquidity); 1317 | _reflectFee(rFee, tFee); 1318 | emit Transfer(sender, recipient, tTransferAmount); 1319 | } 1320 | 1321 | function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { 1322 | (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); 1323 | _rOwned[sender] = _rOwned[sender].sub(rAmount); 1324 | _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); 1325 | _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); 1326 | _takeLiquidity(tLiquidity); 1327 | _reflectFee(rFee, tFee); 1328 | emit Transfer(sender, recipient, tTransferAmount); 1329 | } 1330 | 1331 | function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { 1332 | (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); 1333 | _tOwned[sender] = _tOwned[sender].sub(tAmount); 1334 | _rOwned[sender] = _rOwned[sender].sub(rAmount); 1335 | _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); 1336 | _takeLiquidity(tLiquidity); 1337 | _reflectFee(rFee, tFee); 1338 | emit Transfer(sender, recipient, tTransferAmount); 1339 | } 1340 | 1341 | function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { 1342 | (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); 1343 | _tOwned[sender] = _tOwned[sender].sub(tAmount); 1344 | _rOwned[sender] = _rOwned[sender].sub(rAmount); 1345 | _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); 1346 | _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); 1347 | _takeLiquidity(tLiquidity); 1348 | _reflectFee(rFee, tFee); 1349 | emit Transfer(sender, recipient, tTransferAmount); 1350 | } 1351 | 1352 | function _tokenTransferNoFee(address sender, address recipient, uint256 amount) private { 1353 | uint256 currentRate = _getRate(); 1354 | uint256 rAmount = amount.mul(currentRate); 1355 | 1356 | _rOwned[sender] = _rOwned[sender].sub(rAmount); 1357 | _rOwned[recipient] = _rOwned[recipient].add(rAmount); 1358 | 1359 | if (_isExcluded[sender]) { 1360 | _tOwned[sender] = _tOwned[sender].sub(amount); 1361 | } 1362 | if (_isExcluded[recipient]) { 1363 | _tOwned[recipient] = _tOwned[recipient].add(amount); 1364 | } 1365 | emit Transfer(sender, recipient, amount); 1366 | } 1367 | 1368 | function recoverBEP20(address tokenAddress, uint256 tokenAmount) public onlyOwner { 1369 | // do not allow recovering self token 1370 | require(tokenAddress != address(this), "Self withdraw"); 1371 | IERC20(tokenAddress).transfer(owner(), tokenAmount); 1372 | } 1373 | } 1374 | --------------------------------------------------------------------------------