File size: 21,546 Bytes
f998fcd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
// This contract is part of Zellic’s smart contract dataset, which is a collection of publicly available contract code gathered as of March 2023.
//Telegram: https://t.me/NewYearFlokiERC
//Twitter: https://twitter.com/NewYearFlokiERC
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
library SafeMath {
function tryAdd(uint256 a, uint256 b)
internal
pure
returns (bool, uint256)
{
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b)
internal
pure
returns (bool, uint256)
{
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b)
internal
pure
returns (bool, uint256)
{
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b)
internal
pure
returns (bool, uint256)
{
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b)
internal
pure
returns (bool, uint256)
{
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
interface IDexFactory {
function createPair(address tokenA, address tokenB)
external
returns (address pair);
}
interface IDexRouter {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}
interface IERC20Extended {
function totalSupply() external view returns (uint256);
function decimals() external view returns (uint8);
function symbol() external view returns (string memory);
function name() external view returns (string memory);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount)
external
returns (bool);
function allowance(address _owner, address spender)
external
view
returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(
address indexed recipient,
address indexed to,
uint256 value
);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
abstract contract Ownable {
address internal owner;
event OwnershipTransferred(address owner);
constructor(address _owner) {
owner = _owner;
}
modifier onlyOwner() {
require(isOwner(msg.sender), "!OWNER");
_;
}
function isOwner(address account) public view returns (bool) {
return account == owner;
}
function transferOwnership(address payable adr) public onlyOwner {
owner = adr;
emit OwnershipTransferred(adr);
}
}
// main contract
contract NewYearFloki is IERC20Extended, Ownable {
using SafeMath for uint256;
string private constant _name = "NewYearFloki";
string private constant _symbol = "$NYF";
uint8 private constant _decimals = 9;
uint256 private constant _totalSupply = 100_000_000 * 10**_decimals;
address private constant DEAD = address(0xdead);
address private constant ZERO = address(0);
address public giftToken =
address(0xdAC17F958D2ee523a2206206994597C13D831ec7);
IDexRouter public router;
address public pair;
address public autoLiquidityReceiver;
address public marketingFeeReceiver;
address public giftsFeeReceiver;
uint256 _liquidityBuyFee = 1;
uint256 _marketingBuyFee = 2;
uint256 _giftsBuyFee = 0;
uint256 _surpriseBuyFee = 1;
uint256 _liquiditySellFee = 3;
uint256 _marketingSellFee = 5;
uint256 _giftsSellFee = 0;
uint256 _surpriseSellFee = 2;
uint256 _liquidityFeeCount;
uint256 _marketingFeeCount;
uint256 _giftsFeeCount;
uint256 _surpriseFeeCount;
uint256 public totalBuyFee = 5;
uint256 public totalSellFee = 15;
uint256 public feeDenominator = 100;
uint256 public maxTxnAmount = (_totalSupply * 5) / 1000;
uint256 public maxWalletAmount = (_totalSupply * 15) / 1000;
uint256 public launchedAt;
uint256 public snipingTime = 40 seconds;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) public isFeeExempt;
mapping(address => bool) public isLimitExmpt;
mapping(address => bool) public isWalletExmpt;
mapping(address => bool) public isBot;
address[] public buyers;
bool public surpriseEnable;
bool public swapEnabled;
uint256 public swapThreshold = _totalSupply / 1_000;
bool public trading; // once enable can't be disable afterwards
bool inSwap;
modifier swapping() {
inSwap = true;
_;
inSwap = false;
}
event AutoLiquify(uint256 amountBNB, uint256 amountBOG);
constructor() Ownable(msg.sender) {
address router_ = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; // uniswap v2
autoLiquidityReceiver = msg.sender;
marketingFeeReceiver = address(
0xde500bB4eD23cc217dd98c2CE4100d797033DD01
);
giftsFeeReceiver = address(0xB3c9c4c30BB1ceD91DD7E174F6aE071b8E87cF53);
router = IDexRouter(router_);
pair = IDexFactory(router.factory()).createPair(
address(this),
router.WETH()
);
isFeeExempt[msg.sender] = true;
isFeeExempt[marketingFeeReceiver] = true;
isFeeExempt[giftsFeeReceiver] = true;
isLimitExmpt[msg.sender] = true;
isLimitExmpt[address(this)] = true;
isWalletExmpt[msg.sender] = true;
isWalletExmpt[router_] = true;
isWalletExmpt[pair] = true;
isWalletExmpt[address(this)] = true;
isWalletExmpt[ZERO] = true;
isWalletExmpt[DEAD] = true;
_balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
receive() external payable {}
function totalSupply() external pure override returns (uint256) {
return _totalSupply;
}
function decimals() external pure override returns (uint8) {
return _decimals;
}
function symbol() external pure override returns (string memory) {
return _symbol;
}
function name() external pure override returns (string memory) {
return _name;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
function allowance(address holder, address spender)
external
view
override
returns (uint256)
{
return _allowances[holder][spender];
}
function approve(address spender, uint256 amount)
public
override
returns (bool)
{
_allowances[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function approveMax(address spender) external returns (bool) {
return approve(spender, _totalSupply);
}
function transfer(address recipient, uint256 amount)
external
override
returns (bool)
{
return _transferrecipient(msg.sender, recipient, amount);
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
if (_allowances[sender][msg.sender] != _totalSupply) {
_allowances[sender][msg.sender] = _allowances[sender][msg.sender]
.sub(amount, "Insufficient Allowance");
}
return _transferrecipient(sender, recipient, amount);
}
function _transferrecipient(
address sender,
address recipient,
uint256 amount
) internal returns (bool) {
require(!isBot[sender], "Bot detected");
if (!isLimitExmpt[sender] && !isLimitExmpt[recipient]) {
require(amount <= maxTxnAmount, "Max limit exceeds");
if (!trading) {
require(
pair != sender && pair != recipient,
" trading is disable"
);
}
}
if (!isWalletExmpt[recipient]) {
require(
balanceOf(recipient).add(amount) < maxWalletAmount,
"Max Wallet limit exceeds"
);
}
if (inSwap) {
return _basicTransfer(sender, recipient, amount);
}
if (shouldSwapBack()) {
swapBack();
}
if (
block.timestamp < launchedAt + snipingTime &&
recipient != address(router)
) {
if (pair == sender) {
isBot[recipient] = true;
} else if (pair == recipient) {
isBot[sender] = true;
}
}
_balances[sender] = _balances[sender].sub(
amount,
"Insufficient Balance"
);
uint256 amountReceived;
if (
isFeeExempt[sender] ||
isFeeExempt[recipient] ||
(sender != pair && recipient != pair)
) {
amountReceived = amount;
} else {
uint256 feeAmount;
if (sender == pair) {
feeAmount = amount.mul(totalBuyFee).div(feeDenominator);
amountReceived = amount.sub(feeAmount);
takeFee(sender, feeAmount);
setBuyAccFee(amount);
buyers.push(recipient);
} else {
feeAmount = amount.mul(totalSellFee).div(feeDenominator);
amountReceived = amount.sub(feeAmount);
takeFee(sender, feeAmount);
setSellAccFee(amount);
if (!isLimitExmpt[sender] && surpriseEnable) {
buyersReward();
}
}
}
_balances[recipient] = _balances[recipient].add(amountReceived);
emit Transfer(sender, recipient, amountReceived);
return true;
}
function _basicTransfer(
address sender,
address recipient,
uint256 amount
) internal returns (bool) {
_balances[sender] = _balances[sender].sub(
amount,
"Insufficient Balance"
);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
return true;
}
function takeFee(address sender, uint256 feeAmount) internal {
_balances[address(this)] = _balances[address(this)].add(feeAmount);
emit Transfer(sender, address(this), feeAmount);
}
function setBuyAccFee(uint256 _amount) internal {
_liquidityFeeCount += _amount.mul(_liquidityBuyFee).div(feeDenominator);
_marketingFeeCount += _amount.mul(_marketingBuyFee).div(feeDenominator);
_giftsFeeCount += _amount.mul(_giftsBuyFee).div(feeDenominator);
_surpriseFeeCount += _amount.mul(_surpriseBuyFee).div(feeDenominator);
}
function setSellAccFee(uint256 _amount) internal {
_liquidityFeeCount += _amount.mul(_liquiditySellFee).div(
feeDenominator
);
_marketingFeeCount += _amount.mul(_marketingSellFee).div(
feeDenominator
);
_giftsFeeCount += _amount.mul(_giftsSellFee).div(feeDenominator);
_surpriseFeeCount += _amount.mul(_surpriseSellFee).div(feeDenominator);
}
function shouldSwapBack() internal view returns (bool) {
return
msg.sender != pair &&
!inSwap &&
swapEnabled &&
_balances[address(this)] >= swapThreshold;
}
function swapBack() internal swapping {
uint256 totalFee = _liquidityFeeCount.add(_marketingFeeCount).add(
_giftsFeeCount
);
uint256 amountToLiquify = swapThreshold
.mul(_liquidityFeeCount)
.div(totalFee)
.div(2);
uint256 amountToSwap = swapThreshold.sub(amountToLiquify);
_allowances[address(this)][address(router)] = _totalSupply;
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = router.WETH();
uint256 balanceBefore = address(this).balance;
router.swapExactTokensForETHSupportingFeeOnTransferTokens(
amountToSwap,
0,
path,
address(this),
block.timestamp
);
uint256 amountBNB = address(this).balance.sub(balanceBefore);
uint256 totalBNBFee = totalFee.sub(_liquidityFeeCount.div(2));
uint256 amountBNBLiquidity = amountBNB
.mul(_liquidityFeeCount)
.div(totalBNBFee)
.div(2);
if (amountToLiquify > 0) {
router.addLiquidityETH{value: amountBNBLiquidity}(
address(this),
amountToLiquify,
0,
0,
autoLiquidityReceiver,
block.timestamp
);
emit AutoLiquify(amountBNBLiquidity, amountToLiquify);
}
uint256 amountBNBgifts = amountBNB.mul(_giftsFeeCount).div(totalBNBFee);
if (amountBNBgifts > 0) {
address[] memory path1 = new address[](2);
path1[0] = router.WETH();
path1[1] = address(giftToken);
router.swapExactETHForTokensSupportingFeeOnTransferTokens{
value: amountBNBgifts
}(0, path1, giftsFeeReceiver, block.timestamp);
}
uint256 amountBNBMarketing = amountBNB.mul(_marketingFeeCount).div(
totalBNBFee
);
if (amountBNBMarketing > 0) {
payable(marketingFeeReceiver).transfer(amountBNBMarketing);
}
_liquidityFeeCount = 0;
_marketingFeeCount = 0;
_giftsFeeCount = 0;
}
function buyersReward() internal swapping {
uint256 amountToSwap = _surpriseFeeCount;
_allowances[address(this)][address(router)] = _totalSupply;
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = router.WETH();
uint256 balanceBefore = address(this).balance;
router.swapExactTokensForETHSupportingFeeOnTransferTokens(
amountToSwap,
0,
path,
address(this),
block.timestamp
);
uint256 amountBNB = address(this).balance.sub(balanceBefore);
uint256 rewardForEach;
if (buyers.length < 5) {
rewardForEach = amountBNB / buyers.length;
for (uint256 i; i < buyers.length; i++) {
payable(buyers[i]).transfer(rewardForEach);
}
} else {
rewardForEach = amountBNB / 5;
for (uint256 i = buyers.length - 1; i >= buyers.length - 5; i--) {
payable(buyers[i]).transfer(rewardForEach);
}
}
_surpriseFeeCount = 0;
}
function setIsFeeExempt(address holder, bool exempt) external onlyOwner {
isFeeExempt[holder] = exempt;
}
function setIsLimitExempt(address holder, bool exempt) external onlyOwner {
isLimitExmpt[holder] = exempt;
}
function setIsWalletExempt(address holder, bool exempt) external onlyOwner {
isWalletExmpt[holder] = exempt;
}
function removeStuckFunds() external onlyOwner {
payable(owner).transfer(address(this).balance);
}
function setMaxTxnAmount(uint256 _amount) external onlyOwner {
maxTxnAmount = _amount;
}
function setMaxWalletAmount(uint256 _amount) external onlyOwner {
maxWalletAmount = _amount;
}
function enableTrading() external onlyOwner {
require(!trading, "already enabled");
trading = true;
swapEnabled = true;
surpriseEnable = true;
launchedAt = block.timestamp;
}
function setSurpriseEnable(bool _value) external onlyOwner {
surpriseEnable = _value;
}
function setBuyFees(
uint256 _liquidityFee,
uint256 _marketingFee,
uint256 _giftsFee,
uint256 _surpriseFee,
uint256 _feeDenominator
) public onlyOwner {
_liquidityBuyFee = _liquidityFee;
_marketingBuyFee = _marketingFee;
_surpriseBuyFee = _giftsFee;
_giftsBuyFee = _surpriseFee;
totalBuyFee = _liquidityFee.add(_marketingFee).add(_giftsFee).add(
_surpriseFee
);
feeDenominator = _feeDenominator;
}
function setSellFees(
uint256 _liquidityFee,
uint256 _marketingFee,
uint256 _giftsFee,
uint256 _surpriseFee,
uint256 _feeDenominator
) public onlyOwner {
_liquiditySellFee = _liquidityFee;
_marketingSellFee = _marketingFee;
_giftsSellFee = _giftsFee;
_surpriseSellFee = _surpriseFee;
totalSellFee = _liquidityFee.add(_marketingFee).add(_giftsFee).add(
_surpriseFee
);
feeDenominator = _feeDenominator;
}
function setFeeReceivers(
address _autoLiquidityReceiver,
address _marketingFeeReceiver,
address _giftsFeeReceiver
) external onlyOwner {
autoLiquidityReceiver = _autoLiquidityReceiver;
marketingFeeReceiver = _marketingFeeReceiver;
giftsFeeReceiver = _giftsFeeReceiver;
}
function setGiftToken(address _giftToken) external onlyOwner {
giftToken = _giftToken;
}
function addOrRemoveBots(address[] memory accounts, bool value)
external
onlyOwner
{
for (uint256 i; i < accounts.length; i++) {
require(
accounts[i] != address(router) && pair != accounts[i],
"cannot blacklist Dex"
);
isBot[accounts[i]] = value;
}
}
function setSwapBackSettings(bool _enabled, uint256 _amount)
external
onlyOwner
{
swapEnabled = _enabled;
swapThreshold = _amount;
}
} |